comment.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/tasks/comment.php
  21. * \ingroup project
  22. * \brief Page of a project task comment
  23. */
  24. require "../../main.inc.php";
  25. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('projects', 'companies'));
  36. $id = GETPOST('id', 'int');
  37. $idcomment = GETPOST('idcomment', 'int');
  38. $ref = GETPOST("ref", 'alpha', 1); // task ref
  39. $objectref = GETPOST("taskref", 'alpha'); // task ref
  40. $action = GETPOST('action', 'aZ09');
  41. $confirm = GETPOST('confirm', 'alpha');
  42. $withproject = GETPOST('withproject', 'int');
  43. $project_ref = GETPOST('project_ref', 'alpha');
  44. $planned_workload = ((GETPOST('planned_workloadhour', 'int') != '' || GETPOST('planned_workloadmin', 'int') != '') ? (GETPOST('planned_workloadhour', 'int') > 0 ?GETPOST('planned_workloadhour', 'int') * 3600 : 0) + (GETPOST('planned_workloadmin', 'int') > 0 ?GETPOST('planned_workloadmin', 'int') * 60 : 0) : '');
  45. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  46. $hookmanager->initHooks(array('projecttaskcommentcard', 'globalcard'));
  47. $object = new Task($db);
  48. $extrafields = new ExtraFields($db);
  49. $projectstatic = new Project($db);
  50. // fetch optionals attributes and labels
  51. $extrafields->fetch_name_optionals_label($object->table_element);
  52. // include comment actions
  53. include DOL_DOCUMENT_ROOT.'/core/actions_comments.inc.php';
  54. // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
  55. if (!empty($project_ref) && !empty($withproject)) {
  56. if ($projectstatic->fetch('', $project_ref) > 0) {
  57. $objectsarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  58. if (count($objectsarray) > 0) {
  59. $id = $objectsarray[0]->id;
  60. } else {
  61. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode) ? '' : '&mode='.$mode));
  62. }
  63. }
  64. }
  65. if ($id > 0 || $ref) {
  66. $object->fetch($id, $ref);
  67. }
  68. // Security check
  69. $socid = 0;
  70. restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
  71. /*
  72. * View
  73. */
  74. llxHeader('', $langs->trans("CommentPage"));
  75. $form = new Form($db);
  76. $formother = new FormOther($db);
  77. $formfile = new FormFile($db);
  78. if ($id > 0 || !empty($ref)) {
  79. if ($object->fetch($id, $ref) > 0) {
  80. $result = $object->fetch_optionals();
  81. $result = $object->fetchComments();
  82. if ($result < 0) {
  83. setEventMessages($object->error, $object->errors, 'errors');
  84. }
  85. $result = $projectstatic->fetch($object->fk_project);
  86. if (!empty($projectstatic->socid)) {
  87. $projectstatic->fetch_thirdparty();
  88. }
  89. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
  90. $projectstatic->fetchComments();
  91. }
  92. $object->project = clone $projectstatic;
  93. $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
  94. if (!empty($withproject)) {
  95. // Tabs for project
  96. $tab = 'tasks';
  97. $head = project_prepare_head($projectstatic);
  98. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
  99. $param = ($mode == 'mine' ? '&mode=mine' : '');
  100. // Project card
  101. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  102. $morehtmlref = '<div class="refidno">';
  103. // Title
  104. $morehtmlref .= $projectstatic->title;
  105. // Thirdparty
  106. if ($projectstatic->thirdparty->id > 0) {
  107. $morehtmlref .= '<br>'.$projectstatic->thirdparty->getNomUrl(1, 'project');
  108. }
  109. $morehtmlref .= '</div>';
  110. // Define a complementary filter for search of next/prev ref.
  111. if (!$user->hasRight('projet', 'all', 'lire')) {
  112. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
  113. $projectstatic->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  114. }
  115. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  116. print '<div class="fichecenter">';
  117. print '<div class="fichehalfleft">';
  118. print '<div class="underbanner clearboth"></div>';
  119. print '<table class="border centpercent">';
  120. // Usage
  121. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
  122. print '<tr><td class="tdtop">';
  123. print $langs->trans("Usage");
  124. print '</td>';
  125. print '<td>';
  126. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  127. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  128. $htmltext = $langs->trans("ProjectFollowOpportunity");
  129. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  130. print '<br>';
  131. }
  132. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  133. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
  134. $htmltext = $langs->trans("ProjectFollowTasks");
  135. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  136. print '<br>';
  137. }
  138. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  139. print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> ';
  140. $htmltext = $langs->trans("ProjectBillTimeDescription");
  141. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  142. print '<br>';
  143. }
  144. if (isModEnabled('eventorganization')) {
  145. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  146. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  147. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  148. }
  149. print '</td></tr>';
  150. }
  151. // Visibility
  152. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  153. if ($projectstatic->public) {
  154. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  155. print $langs->trans('SharedProject');
  156. } else {
  157. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  158. print $langs->trans('PrivateProject');
  159. }
  160. print '</td></tr>';
  161. // Opportunities
  162. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) {
  163. // Opportunity status
  164. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  165. $code = dol_getIdFromCode($db, $projectstatic->opp_status, 'c_lead_status', 'rowid', 'code');
  166. if ($code) {
  167. print $langs->trans("OppStatus".$code);
  168. }
  169. print '</td></tr>';
  170. // Opportunity percent
  171. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  172. if (strcmp($projectstatic->opp_percent, '')) {
  173. print price($projectstatic->opp_percent, 0, $langs, 1, 0).' %';
  174. }
  175. print '</td></tr>';
  176. // Opportunity Amount
  177. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  178. if (strcmp($projectstatic->opp_amount, '')) {
  179. print price($projectstatic->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  180. if (strcmp($projectstatic->opp_percent, '')) {
  181. print ' &nbsp; &nbsp; &nbsp; <span title="'.dol_escape_htmltag($langs->trans('OpportunityWeightedAmount')).'"><span class="opacitymedium">'.$langs->trans("Weighted").'</span>: <span class="amount">'.price($projectstatic->opp_amount * $projectstatic->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span></span>';
  182. }
  183. }
  184. print '</td></tr>';
  185. }
  186. // Budget
  187. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  188. if (strcmp($projectstatic->budget_amount, '')) {
  189. print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
  190. }
  191. print '</td></tr>';
  192. // Date start - end project
  193. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  194. $start = dol_print_date($projectstatic->date_start, 'day');
  195. print ($start ? $start : '?');
  196. $end = dol_print_date($projectstatic->date_end, 'day');
  197. print ' - ';
  198. print ($end ? $end : '?');
  199. if ($projectstatic->hasDelay()) {
  200. print img_warning("Late");
  201. }
  202. print '</td></tr>';
  203. // Other attributes
  204. $cols = 2;
  205. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  206. print '</table>';
  207. print '</div>';
  208. print '<div class="fichehalfright">';
  209. print '<div class="underbanner clearboth"></div>';
  210. print '<table class="border centpercent">';
  211. // Description
  212. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  213. print nl2br($projectstatic->description);
  214. print '</td></tr>';
  215. // Categories
  216. if (isModEnabled('categorie')) {
  217. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  218. print $form->showCategories($projectstatic->id, 'project', 1);
  219. print "</td></tr>";
  220. }
  221. print '</table>';
  222. print '</div>';
  223. print '</div>';
  224. print '<div class="clearboth"></div>';
  225. print dol_get_fiche_end();
  226. print '<br>';
  227. }
  228. $head = task_prepare_head($object);
  229. /*
  230. * Fiche tache en mode visu
  231. */
  232. $param = ($withproject ? '&withproject=1' : '');
  233. $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>' : '';
  234. print dol_get_fiche_head($head, 'task_comment', $langs->trans("Task"), -1, 'projecttask');
  235. if ($action == 'delete') {
  236. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".GETPOST("id", "int").'&withproject='.$withproject, $langs->trans("DeleteATask"), $langs->trans("ConfirmDeleteATask"), "confirm_delete");
  237. }
  238. if (!GETPOST('withproject') || empty($projectstatic->id)) {
  239. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
  240. $object->next_prev_filter = "fk_projet IN (".$db->sanitize($projectsListId).")";
  241. } else {
  242. $object->next_prev_filter = "fk_projet = ".((int) $projectstatic->id);
  243. }
  244. $morehtmlref = '';
  245. // Project
  246. if (empty($withproject)) {
  247. $morehtmlref .= '<div class="refidno">';
  248. $morehtmlref .= $langs->trans("Project").': ';
  249. $morehtmlref .= $projectstatic->getNomUrl(1);
  250. $morehtmlref .= '<br>';
  251. // Third party
  252. $morehtmlref .= $langs->trans("ThirdParty").': ';
  253. if (!empty($projectstatic->thirdparty)) {
  254. $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
  255. }
  256. $morehtmlref .= '</div>';
  257. }
  258. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  259. print '<div class="fichecenter">';
  260. print '<div class="underbanner clearboth"></div>';
  261. print '<table class="border centpercent">';
  262. // Nb comments
  263. print '<td class="titlefield">'.$langs->trans("NbComments").'</td><td>';
  264. print $object->getNbComments();
  265. print '</td></tr>';
  266. // Other attributes
  267. $cols = 3;
  268. $parameters = array('socid'=>$socid);
  269. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  270. print '</table>';
  271. print '</div>';
  272. print dol_get_fiche_end();
  273. // Include comment tpl view
  274. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_comment.tpl.php';
  275. }
  276. }
  277. // End of page
  278. llxFooter();
  279. $db->close();