PageRenderTime 82ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/action/fiche.php

https://github.com/asterix14/dolibarr
PHP | 1092 lines | 819 code | 151 blank | 122 comment | 202 complexity | 4cb7c6b97988f52a1db139d71f5dd540 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  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 2 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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/comm/action/fiche.php
  23. * \ingroup agenda
  24. * \brief Page for event card
  25. */
  26. require("../../main.inc.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/agenda.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php");
  30. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/cactioncomm.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
  32. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formactions.class.php");
  33. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  34. require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  35. $langs->load("companies");
  36. $langs->load("commercial");
  37. $langs->load("other");
  38. $langs->load("bills");
  39. $langs->load("orders");
  40. $langs->load("agenda");
  41. $action=GETPOST("action");
  42. // Security check
  43. $socid = GETPOST('socid');
  44. $id = GETPOST('id');
  45. if ($user->societe_id) $socid=$user->societe_id;
  46. //$result = restrictedArea($user, 'agenda', $id, 'actioncomm', 'actions', '', 'id');
  47. if (isset($_GET["error"])) $error=$_GET["error"];
  48. $cactioncomm = new CActionComm($db);
  49. $actioncomm = new ActionComm($db);
  50. $contact = new Contact($db);
  51. //var_dump($_POST);
  52. /*
  53. * Action creation de l'action
  54. */
  55. if ($action == 'add_action')
  56. {
  57. $error=0;
  58. $backtopage='';
  59. if (! empty($_POST["backtopage"])) $backtopage=$_POST["backtopage"];
  60. if (! $backtopage)
  61. {
  62. if ($socid > 0) $backtopage = DOL_URL_ROOT.'/societe/agenda.php?socid='.$socid;
  63. else $backtopage=DOL_URL_ROOT.'/comm/action/index.php';
  64. }
  65. if ($_POST["contactid"])
  66. {
  67. $result=$contact->fetch($_POST["contactid"]);
  68. }
  69. if ($_POST['cancel'])
  70. {
  71. header("Location: ".$backtopage);
  72. exit;
  73. }
  74. $fulldayevent=$_POST["fullday"];
  75. // Clean parameters
  76. $datep=dol_mktime(
  77. $fulldayevent?'00':$_POST["aphour"],
  78. $fulldayevent?'00':$_POST["apmin"],
  79. 0,
  80. $_POST["apmonth"],
  81. $_POST["apday"],
  82. $_POST["apyear"]);
  83. $datef=dol_mktime(
  84. $fulldayevent?'23':$_POST["p2hour"],
  85. $fulldayevent?'59':$_POST["p2min"],
  86. $fulldayevent?'59':'0',
  87. $_POST["p2month"],
  88. $_POST["p2day"],
  89. $_POST["p2year"]);
  90. // Check parameters
  91. if (! $datef && $_POST["percentage"] == 100)
  92. {
  93. $error++;
  94. $action = 'create';
  95. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd")).'</div>';
  96. }
  97. // Initialisation objet cactioncomm
  98. if (! $_POST["actioncode"])
  99. {
  100. $error++;
  101. $action = 'create';
  102. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Type")).'</div>';
  103. }
  104. else
  105. {
  106. $result=$cactioncomm->fetch($_POST["actioncode"]);
  107. }
  108. // Initialisation objet actioncomm
  109. $actioncomm->type_id = $cactioncomm->id;
  110. $actioncomm->type_code = $cactioncomm->code;
  111. $actioncomm->priority = isset($_POST["priority"])?$_POST["priority"]:0;
  112. $actioncomm->fulldayevent = $_POST["fullday"]?1:0;
  113. $actioncomm->location = isset($_POST["location"])?$_POST["location"]:'';
  114. $actioncomm->label = trim($_POST["label"]);
  115. if (! $_POST["label"])
  116. {
  117. if ($_POST["actioncode"] == 'AC_RDV' && $contact->getFullName($langs))
  118. {
  119. $actioncomm->label = $langs->transnoentitiesnoconv("TaskRDVWith",$contact->getFullName($langs));
  120. }
  121. else
  122. {
  123. if ($langs->trans("Action".$actioncomm->type_code) != "Action".$actioncomm->type_code)
  124. {
  125. $actioncomm->label = $langs->transnoentitiesnoconv("Action".$actioncomm->type_code)."\n";
  126. }
  127. else $actioncomm->label = $cactioncomm->libelle;
  128. }
  129. }
  130. $actioncomm->fk_project = isset($_POST["projectid"])?$_POST["projectid"]:0;
  131. $actioncomm->datep = $datep;
  132. $actioncomm->datef = $datef;
  133. $actioncomm->percentage = isset($_POST["percentage"])?$_POST["percentage"]:0;
  134. $actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60;
  135. $usertodo=new User($db);
  136. if ($_POST["affectedto"] > 0)
  137. {
  138. $usertodo->fetch($_POST["affectedto"]);
  139. }
  140. $actioncomm->usertodo = $usertodo;
  141. $userdone=new User($db);
  142. if ($_POST["doneby"] > 0)
  143. {
  144. $userdone->fetch($_POST["doneby"]);
  145. }
  146. $actioncomm->userdone = $userdone;
  147. $actioncomm->note = trim($_POST["note"]);
  148. if (isset($_POST["contactid"])) $actioncomm->contact = $contact;
  149. if (GETPOST("socid") > 0)
  150. {
  151. $societe = new Societe($db);
  152. $societe->fetch(GETPOST("socid"));
  153. $actioncomm->societe = $societe;
  154. }
  155. // Special for module webcal and phenix
  156. if ($_POST["add_webcal"] == 'on' && $conf->webcalendar->enabled) $actioncomm->use_webcal=1;
  157. if ($_POST["add_phenix"] == 'on' && $conf->phenix->enabled) $actioncomm->use_phenix=1;
  158. // Check parameters
  159. if ($actioncomm->type_code == 'AC_RDV' && ($datep == '' || $datef == ''))
  160. {
  161. $error++;
  162. $action = 'create';
  163. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")).'</div>';
  164. }
  165. if ($datea && $_POST["percentage"] == 0)
  166. {
  167. $error++;
  168. $action = 'create';
  169. $mesg='<div class="error">'.$langs->trans("ErrorStatusCantBeZeroIfStarted").'</div>';
  170. }
  171. if (! $_POST["apyear"] && ! $_POST["adyear"])
  172. {
  173. $error++;
  174. $action = 'create';
  175. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'</div>';
  176. }
  177. if (! $error)
  178. {
  179. $db->begin();
  180. // On cree l'action
  181. $idaction=$actioncomm->add($user);
  182. if ($idaction > 0)
  183. {
  184. if (! $actioncomm->error)
  185. {
  186. $db->commit();
  187. if (! empty($backtopage))
  188. {
  189. dol_syslog("Back to ".$backtopage);
  190. Header("Location: ".$backtopage);
  191. }
  192. elseif($idaction)
  193. {
  194. Header("Location: ".DOL_URL_ROOT.'/comm/action/fiche.php?id='.$idaction);
  195. }
  196. else
  197. {
  198. Header("Location: ".DOL_URL_ROOT.'/comm/action/index.php');
  199. }
  200. exit;
  201. }
  202. else
  203. {
  204. // Si erreur
  205. $db->rollback();
  206. $id=$idaction;
  207. $langs->load("errors");
  208. $error=$langs->trans($actioncomm->error);
  209. }
  210. }
  211. else
  212. {
  213. $db->rollback();
  214. $id=$idaction;
  215. $langs->load("errors");
  216. $error=$langs->trans($actioncomm->error);
  217. }
  218. }
  219. }
  220. /*
  221. * Action suppression de l'action
  222. */
  223. if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
  224. {
  225. $actioncomm = new ActionComm($db);
  226. $actioncomm->fetch($id);
  227. if ($user->rights->agenda->myactions->delete
  228. || $user->rights->agenda->allactions->delete)
  229. {
  230. $result=$actioncomm->delete();
  231. if ($result >= 0)
  232. {
  233. Header("Location: index.php");
  234. exit;
  235. }
  236. else
  237. {
  238. $mesg=$actioncomm->error;
  239. }
  240. }
  241. }
  242. /*
  243. * Action mise a jour de l'action
  244. */
  245. if ($action == 'update')
  246. {
  247. if (! $_POST["cancel"])
  248. {
  249. $fulldayevent=$_POST["fullday"];
  250. // Clean parameters
  251. if ($_POST["aphour"] == -1) $_POST["aphour"]='0';
  252. if ($_POST["apmin"] == -1) $_POST["apmin"]='0';
  253. if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0';
  254. if ($_POST["p2min"] == -1) $_POST["p2min"]='0';
  255. //if ($_POST["adhour"] == -1) $_POST["adhour"]='0';
  256. //if ($_POST["admin"] == -1) $_POST["admin"]='0';
  257. $actioncomm = new Actioncomm($db);
  258. $actioncomm->fetch($id);
  259. $datep=dol_mktime(
  260. $fulldayevent?'00':$_POST["aphour"],
  261. $fulldayevent?'00':$_POST["apmin"],
  262. 0,
  263. $_POST["apmonth"],
  264. $_POST["apday"],
  265. $_POST["apyear"]);
  266. $datef=dol_mktime(
  267. $fulldayevent?'23':$_POST["p2hour"],
  268. $fulldayevent?'59':$_POST["p2min"],
  269. $fulldayevent?'59':'0',
  270. $_POST["p2month"],
  271. $_POST["p2day"],
  272. $_POST["p2year"]);
  273. $actioncomm->label = $_POST["label"];
  274. $actioncomm->datep = $datep;
  275. $actioncomm->datef = $datef;
  276. //$actioncomm->date = $datea;
  277. //$actioncomm->dateend = $datea2;
  278. $actioncomm->percentage = $_POST["percentage"];
  279. $actioncomm->priority = $_POST["priority"];
  280. $actioncomm->fulldayevent= $_POST["fullday"]?1:0;
  281. $actioncomm->location = isset($_POST["location"])?$_POST["location"]:'';
  282. $actioncomm->societe->id = $_POST["socid"];
  283. $actioncomm->contact->id = $_POST["contactid"];
  284. $actioncomm->fk_project = $_POST["projectid"];
  285. $actioncomm->note = $_POST["note"];
  286. $actioncomm->pnote = $_POST["note"];
  287. if (! $datef && $_POST["percentage"] == 100)
  288. {
  289. $error=$langs->trans("ErrorFieldRequired",$langs->trans("DateEnd"));
  290. $action = 'edit';
  291. }
  292. // Users
  293. $usertodo=new User($db);
  294. if ($_POST["affectedto"])
  295. {
  296. $usertodo->fetch($_POST["affectedto"]);
  297. }
  298. $actioncomm->usertodo = $usertodo;
  299. $userdone=new User($db);
  300. if ($_POST["doneby"])
  301. {
  302. $userdone->fetch($_POST["doneby"]);
  303. }
  304. $actioncomm->userdone = $userdone;
  305. if (! $error)
  306. {
  307. $db->begin();
  308. $result=$actioncomm->update($user);
  309. if ($result > 0)
  310. {
  311. $db->commit();
  312. }
  313. else
  314. {
  315. $db->rollback();
  316. }
  317. }
  318. }
  319. if ($result < 0)
  320. {
  321. $langs->load("errors");
  322. $mesg='<div class="error">'.$langs->trans($actioncomm->error).'</div>';
  323. }
  324. else
  325. {
  326. if (! empty($_POST["from"])) // deprecated. Use backtopage instead
  327. {
  328. header("Location: ".$_POST["from"]);
  329. exit;
  330. }
  331. if (! empty($_POST["backtopage"]))
  332. {
  333. header("Location: ".$_POST["backtopage"]);
  334. exit;
  335. }
  336. }
  337. }
  338. /*
  339. * View
  340. */
  341. $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
  342. llxHeader('',$langs->trans("Agenda"),$help_url);
  343. $form = new Form($db);
  344. $htmlactions = new FormActions($db);
  345. if ($action == 'create')
  346. {
  347. $contact = new Contact($db);
  348. if (GETPOST("contactid"))
  349. {
  350. $result=$contact->fetch(GETPOST("contactid"));
  351. if ($result < 0) dol_print_error($db,$contact->error);
  352. }
  353. if ($conf->use_javascript_ajax)
  354. {
  355. print "\n".'<script type="text/javascript" language="javascript">';
  356. print 'jQuery(document).ready(function () {
  357. function setdatefields()
  358. {
  359. if (jQuery("#fullday:checked").val() == null)
  360. {
  361. jQuery(".fulldaystarthour").attr(\'disabled\', false);
  362. jQuery(".fulldaystartmin").attr(\'disabled\', false);
  363. jQuery(".fulldayendhour").attr(\'disabled\', false);
  364. jQuery(".fulldayendmin").attr(\'disabled\', false);
  365. }
  366. else
  367. {
  368. jQuery(".fulldaystarthour").attr(\'disabled\', true);
  369. jQuery(".fulldaystartmin").attr(\'disabled\', true);
  370. jQuery(".fulldayendhour").attr(\'disabled\', true);
  371. jQuery(".fulldayendmin").attr(\'disabled\', true);
  372. jQuery(".fulldaystarthour").val("00");
  373. jQuery(".fulldaystartmin").val("00");
  374. //jQuery(".fulldayendhour").val("00");
  375. //jQuery(".fulldayendmin").val("00");
  376. jQuery(".fulldayendhour").val("23");
  377. jQuery(".fulldayendmin").val("59");
  378. }
  379. }
  380. setdatefields();
  381. jQuery("#fullday").change(function() {
  382. setdatefields();
  383. });
  384. jQuery("#selectcomplete").change(function() {
  385. if (jQuery("#selectcomplete").val() == 100)
  386. {
  387. if (jQuery("#doneby").val() <= 0) jQuery("#doneby").val(\''.$user->id.'\');
  388. }
  389. if (jQuery("#selectcomplete").val() == 0)
  390. {
  391. jQuery("#doneby").val(-1);
  392. }
  393. });
  394. jQuery("#actioncode").change(function() {
  395. if (jQuery("#actioncode").val() == \'AC_RDV\') jQuery("#dateend").addClass("fieldrequired");
  396. else jQuery("#dateend").removeClass("fieldrequired");
  397. });
  398. })';
  399. print '</script>'."\n";
  400. }
  401. print '<form name="formaction" action="'.DOL_URL_ROOT.'/comm/action/fiche.php" method="POST">';
  402. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  403. print '<input type="hidden" name="action" value="add_action">';
  404. if (GETPOST("backtopage")) print '<input type="hidden" name="backtopage" value="'.(GETPOST("backtopage") != 1 ? GETPOST("backtopage") : $_SERVER["HTTP_REFERER"]).'">';
  405. if (GETPOST("actioncode") == 'AC_RDV') print_fiche_titre ($langs->trans("AddActionRendezVous"));
  406. else print_fiche_titre ($langs->trans("AddAnAction"));
  407. dol_htmloutput_mesg($mesg);
  408. print '<table class="border" width="100%">';
  409. // Type d'action actifs
  410. print '<tr><td width="30%"><span class="fieldrequired">'.$langs->trans("Type").'</span></b></td><td>';
  411. if (GETPOST("actioncode"))
  412. {
  413. print '<input type="hidden" name="actioncode" value="'.GETPOST("actioncode").'">'."\n";
  414. $cactioncomm->fetch(GETPOST("actioncode"));
  415. print $cactioncomm->getNomUrl();
  416. }
  417. else
  418. {
  419. $htmlactions->select_type_actions($actioncomm->type_code, "actioncode");
  420. }
  421. print '</td></tr>';
  422. // Title
  423. print '<tr><td>'.$langs->trans("Title").'</td><td><input type="text" name="label" size="60" value="'.GETPOST('label').'"></td></tr>';
  424. // Full day
  425. print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td><input type="checkbox" id="fullday" name="fullday" '.(GETPOST('fullday')?' checked="checked"':'').'></td></tr>';
  426. // Date start
  427. $datep=$actioncomm->datep;
  428. if (GETPOST('datep','int',1)) $datep=dol_stringtotime(GETPOST('datep','int',1),0);
  429. print '<tr><td width="30%" nowrap="nowrap"><span class="fieldrequired">'.$langs->trans("DateActionStart").'</span></td><td>';
  430. if (GETPOST("afaire") == 1) $form->select_date($datep,'ap',1,1,0,"action",1,1,0,0,'fulldayend');
  431. else if (GETPOST("afaire") == 2) $form->select_date($datep,'ap',1,1,1,"action",1,1,0,0,'fulldayend');
  432. else $form->select_date($datep,'ap',1,1,1,"action",1,1,0,0,'fulldaystart');
  433. print '</td></tr>';
  434. // Date end
  435. $datef=$actioncomm->datef;
  436. if (GETPOST('datef','int',1)) $datef=dol_stringtotime(GETPOST('datef','int',1),0);
  437. print '<tr><td><span id="dateend"'.(GETPOST("actioncode") == 'AC_RDV'?' class="fieldrequired"':'').'>'.$langs->trans("DateActionEnd").'</span></td><td>';
  438. if (GETPOST("afaire") == 1) $form->select_date($datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend');
  439. else if (GETPOST("afaire") == 2) $form->select_date($datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend');
  440. else $form->select_date($datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend');
  441. print '</td></tr>';
  442. // Status
  443. print '<tr><td width="10%">'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td>';
  444. print '<td>';
  445. $percent=-1;
  446. if (isset($_GET['percentage']) || isset($_POST['percentage']))
  447. {
  448. $percent=GETPOST('percentage');
  449. }
  450. else
  451. {
  452. if (GETPOST("afaire") == 1) $percent=0;
  453. if (GETPOST("afaire") == 2) $percent=100;
  454. }
  455. print $htmlactions->form_select_status_action('formaction',$percent,1,'complete');
  456. print '</td></tr>';
  457. // Location
  458. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3"><input type="text" name="location" size="50" value="'.$act->location.'"></td></tr>';
  459. print '</table>';
  460. print '<br>';
  461. print '<table class="border" width="100%">';
  462. // Affected by
  463. print '<tr><td width="30%" nowrap="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>';
  464. $form->select_users(GETPOST("affectedto")?GETPOST("affectedto"):($actioncomm->usertodo->id > 0 ? $actioncomm->usertodo : $user),'affectedto',1);
  465. print '</td></tr>';
  466. // Realised by
  467. print '<tr><td nowrap>'.$langs->trans("ActionDoneBy").'</td><td>';
  468. $form->select_users(GETPOST("doneby")?GETPOST("doneby"):($percent==100?$actioncomm->userdone:0),'doneby',1);
  469. print '</td></tr>';
  470. print '</table>';
  471. print '<br>';
  472. print '<table class="border" width="100%">';
  473. // Societe, contact
  474. print '<tr><td width="30%" nowrap="nowrap">'.$langs->trans("ActionOnCompany").'</td><td>';
  475. if (GETPOST("socid") > 0)
  476. {
  477. $societe = new Societe($db);
  478. $societe->fetch(GETPOST("socid"));
  479. print $societe->getNomUrl(1);
  480. print '<input type="hidden" name="socid" value="'.GETPOST("socid").'">';
  481. }
  482. else
  483. {
  484. print $form->select_societes('','socid','',1,1);
  485. }
  486. print '</td></tr>';
  487. // If company is forced, we propose contacts (may be contact is also forced)
  488. if (GETPOST("contactid") > 0 || GETPOST("socid") > 0)
  489. {
  490. print '<tr><td nowrap>'.$langs->trans("ActionOnContact").'</td><td>';
  491. $form->select_contacts(GETPOST("socid"),GETPOST('contactid'),'contactid',1);
  492. print '</td></tr>';
  493. }
  494. // Project
  495. if ($conf->projet->enabled)
  496. {
  497. // Projet associe
  498. $langs->load("project");
  499. print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
  500. $numproject=select_projects($societe->id,GETPOST("projectid")?GETPOST("projectid"):$projectid,'projectid');
  501. if ($numproject==0)
  502. {
  503. print ' &nbsp; <a href="../../projet/fiche.php?socid='.$societe->id.'&action=create">'.$langs->trans("AddProject").'</a>';
  504. }
  505. print '</td></tr>';
  506. }
  507. if (GETPOST("datep") && preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$/',GETPOST("datep"),$reg))
  508. {
  509. $actioncomm->datep=dol_mktime(0,0,0,$reg[2],$reg[3],$reg[1]);
  510. }
  511. // Priority
  512. print '<tr><td nowrap>'.$langs->trans("Priority").'</td><td colspan="3">';
  513. print '<input type="text" name="priority" value="'.($_POST["priority"]?$_POST["priority"]:($actioncomm->priority?$actioncomm->priority:'')).'" size="5">';
  514. print '</td></tr>';
  515. add_row_for_calendar_link();
  516. // Description
  517. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
  518. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  519. $doleditor=new DolEditor('note',($_POST["note"]?$_POST["note"]:$actioncomm->note),'',280,'dolibarr_notes','In',true,true,$conf->fckeditor->enabled,ROWS_7,90);
  520. $doleditor->Create();
  521. print '</td></tr>';
  522. print '</table>';
  523. print '<center><br>';
  524. print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
  525. print ' &nbsp; &nbsp; ';
  526. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  527. print '</center>';
  528. print "</form>";
  529. }
  530. // View or edit
  531. if ($id)
  532. {
  533. if ($error)
  534. {
  535. print '<div class="error">'.$error.'</div><br>';
  536. }
  537. if ($mesg)
  538. {
  539. print $mesg.'<br>';
  540. }
  541. $act = new ActionComm($db);
  542. $result=$act->fetch($id);
  543. if ($result < 0)
  544. {
  545. dol_print_error($db,$act->error);
  546. exit;
  547. }
  548. $societe = new Societe($db);
  549. if ($act->societe->id)
  550. {
  551. $result=$societe->fetch($act->societe->id);
  552. }
  553. $act->societe = $societe;
  554. if ($act->author->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($act->author->id); $act->author=$tmpuser; }
  555. if ($act->usermod->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($act->usermod->id); $act->usermod=$tmpuser; }
  556. if ($act->usertodo->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($act->usertodo->id); $act->usertodo=$tmpuser; }
  557. if ($act->userdone->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($act->userdone->id); $act->userdone=$tmpuser; }
  558. $contact = new Contact($db);
  559. if ($act->contact->id)
  560. {
  561. $result=$contact->fetch($act->contact->id,$user);
  562. }
  563. $act->contact = $contact;
  564. /*
  565. * Affichage onglets
  566. */
  567. $head=actions_prepare_head($act);
  568. dol_fiche_head($head, 'card', $langs->trans("Action"),0,'action');
  569. $now=dol_now();
  570. $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
  571. // Confirmation suppression action
  572. if ($action == 'delete')
  573. {
  574. $ret=$form->form_confirm("fiche.php?id=".$id,$langs->trans("DeleteAction"),$langs->trans("ConfirmDeleteAction"),"confirm_delete",'','',1);
  575. if ($ret == 'html') print '<br>';
  576. }
  577. if ($action == 'edit')
  578. {
  579. if ($conf->use_javascript_ajax)
  580. {
  581. print "\n".'<script type="text/javascript" language="javascript">';
  582. print 'jQuery(document).ready(function () {
  583. function setdatefields()
  584. {
  585. if (jQuery("#fullday:checked").val() == null)
  586. {
  587. jQuery(".fulldaystarthour").attr(\'disabled\', false);
  588. jQuery(".fulldaystartmin").attr(\'disabled\', false);
  589. jQuery(".fulldayendhour").attr(\'disabled\', false);
  590. jQuery(".fulldayendmin").attr(\'disabled\', false);
  591. }
  592. else
  593. {
  594. jQuery(".fulldaystarthour").attr(\'disabled\', true);
  595. jQuery(".fulldaystartmin").attr(\'disabled\', true);
  596. jQuery(".fulldayendhour").attr(\'disabled\', true);
  597. jQuery(".fulldayendmin").attr(\'disabled\', true);
  598. jQuery(".fulldaystarthour").val("00");
  599. jQuery(".fulldaystartmin").val("00");
  600. //jQuery(".fulldayendhour").val("00");
  601. //jQuery(".fulldayendmin").val("00");
  602. jQuery(".fulldayendhour").val("23");
  603. jQuery(".fulldayendmin").val("59");
  604. }
  605. }
  606. setdatefields();
  607. jQuery("#fullday").change(function() {
  608. setdatefields();
  609. });
  610. })';
  611. print '</script>'."\n";
  612. }
  613. // Fiche action en mode edition
  614. print '<form name="formaction" action="'.DOL_URL_ROOT.'/comm/action/fiche.php" method="post">';
  615. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  616. print '<input type="hidden" name="action" value="update">';
  617. print '<input type="hidden" name="id" value="'.$id.'">';
  618. print '<input type="hidden" name="ref_ext" value="'.$act->ref_ext.'">';
  619. if (GETPOST("backtopage")) print '<input type="hidden" name="backtopage" value="'.(GETPOST("backtopage") ? GETPOST("backtopage") : $_SERVER["HTTP_REFERER"]).'">';
  620. print '<table class="border" width="100%">';
  621. // Ref
  622. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">'.$act->id.'</td></tr>';
  623. // Type
  624. print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
  625. // Title
  626. print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3"><input type="text" name="label" size="50" value="'.$act->label.'"></td></tr>';
  627. // Full day event
  628. print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3"><input type="checkbox" id="fullday" name="fullday" '.($act->fulldayevent?' checked="checked"':'').'></td></tr>';
  629. // Date start
  630. print '<tr><td nowrap="nowrap" class="fieldrequired">'.$langs->trans("DateActionStart").'</td><td colspan="3">';
  631. if (GETPOST("afaire") == 1) $form->select_date($act->datep,'ap',1,1,0,"action",1,1,0,0,'fulldaystart');
  632. else if (GETPOST("afaire") == 2) $form->select_date($act->datep,'ap',1,1,1,"action",1,1,0,0,'fulldaystart');
  633. else $form->select_date($act->datep,'ap',1,1,1,"action",1,1,0,0,'fulldaystart');
  634. print '</td></tr>';
  635. // Date end
  636. print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
  637. if (GETPOST("afaire") == 1) $form->select_date($act->datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend');
  638. else if (GETPOST("afaire") == 2) $form->select_date($act->datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend');
  639. else $form->select_date($act->datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend');
  640. print '</td></tr>';
  641. // Status
  642. print '<tr><td nowrap>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td colspan="3">';
  643. $percent=GETPOST("percentage")?GETPOST("percentage"):$act->percentage;
  644. print $htmlactions->form_select_status_action('formaction',$percent,1);
  645. print '</td></tr>';
  646. // Location
  647. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3"><input type="text" name="location" size="50" value="'.$act->location.'"></td></tr>';
  648. print '</table><br><table class="border" width="100%">';
  649. // Input by
  650. print '<tr><td width="30%" nowrap>'.$langs->trans("ActionAskedBy").'</td><td colspan="3">';
  651. print $act->author->getNomUrl(1);
  652. print '</td></tr>';
  653. // Affected to
  654. print '<tr><td nowrap>'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
  655. print $form->select_dolusers($act->usertodo->id>0?$act->usertodo->id:-1,'affectedto',1);
  656. print '</td></tr>';
  657. // Realised by
  658. print '<tr><td nowrap>'.$langs->trans("ActionDoneBy").'</td><td colspan="3">';
  659. print $form->select_dolusers($act->userdone->id> 0?$act->userdone->id:-1,'doneby',1);
  660. print '</td></tr>';
  661. print '</table><br>';
  662. print '<table class="border" width="100%">';
  663. // Company
  664. print '<tr><td width="30%">'.$langs->trans("ActionOnCompany").'</td>';
  665. print '<td>';
  666. print $form->select_societes($act->societe->id,'socid','',1,1);
  667. print '</td>';
  668. // Contact
  669. print '<td>'.$langs->trans("Contact").'</td><td width="30%">';
  670. print $form->selectarray("contactid", $act->societe->contact_array(), $act->contact->id, 1);
  671. print '</td></tr>';
  672. // Project
  673. if ($conf->projet->enabled)
  674. {
  675. // Projet associe
  676. $langs->load("project");
  677. print '<tr><td valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
  678. $numprojet=select_projects($act->societe->id,$act->fk_project,'projectid');
  679. if ($numprojet==0)
  680. {
  681. print ' &nbsp; <a href="../../projet/fiche.php?socid='.$societe->id.'&action=create">'.$langs->trans("AddProject").'</a>';
  682. }
  683. print '</td></tr>';
  684. }
  685. // Priority
  686. print '<tr><td nowrap>'.$langs->trans("Priority").'</td><td colspan="3">';
  687. print '<input type="text" name="priority" value="'.($act->priority?$act->priority:'').'" size="5">';
  688. print '</td></tr>';
  689. // Object linked
  690. if (! empty($act->fk_element) && ! empty($act->elementtype))
  691. {
  692. print '<tr><td>'.$langs->trans("LinkedObject").'</td>';
  693. print '<td colspan="3">'.$act->getElementUrl($act->fk_element,$act->elementtype,1).'</td></tr>';
  694. }
  695. // Description
  696. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
  697. // Editeur wysiwyg
  698. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  699. $doleditor=new DolEditor('note',$act->note,'',240,'dolibarr_notes','In',true,true,$conf->fckeditor->enabled,ROWS_5,90);
  700. $doleditor->Create();
  701. print '</td></tr>';
  702. print '</table>';
  703. print '<center><br><input type="submit" class="button" name="edit" value="'.$langs->trans("Save").'">';
  704. print ' &nbsp; &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  705. print '</center>';
  706. print '</form>';
  707. }
  708. else
  709. {
  710. // Affichage fiche action en mode visu
  711. print '<table class="border" width="100%">';
  712. // Ref
  713. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  714. print $form->showrefnav($act,'id','',($user->societe_id?0:1),'id','ref','');
  715. print '</td></tr>';
  716. // Type
  717. print '<tr><td>'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
  718. // Title
  719. print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$act->label.'</td></tr>';
  720. // Full day event
  721. print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent).'</td></tr>';
  722. // Date start
  723. print '<tr><td width="30%">'.$langs->trans("DateActionStart").'</td><td colspan="2">';
  724. if (! $act->fulldayevent) print dol_print_date($act->datep,'dayhour');
  725. else print dol_print_date($act->datep,'day');
  726. if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) print img_warning($langs->trans("Late"));
  727. print '</td>';
  728. print '<td rowspan="3" align="center" valign="middle" width="180">'."\n";
  729. print '<form name="listactionsfiltermonth" action="'.DOL_URL_ROOT.'/comm/action/index.php" method="POST">';
  730. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  731. print '<input type="hidden" name="action" value="show_month">';
  732. print '<input type="hidden" name="year" value="'.dol_print_date($act->datep,'%Y').'">';
  733. print '<input type="hidden" name="month" value="'.dol_print_date($act->datep,'%m').'">';
  734. print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
  735. //print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
  736. print img_picto($langs->trans("ViewCal"),'object_calendar').' <input type="submit" style="width: 120px" class="button" name="viewcal" value="'.$langs->trans("ViewCal").'">';
  737. print '</form>'."\n";
  738. print '<form name="listactionsfilterweek" action="'.DOL_URL_ROOT.'/comm/action/index.php" method="POST">';
  739. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  740. print '<input type="hidden" name="action" value="show_week">';
  741. print '<input type="hidden" name="year" value="'.dol_print_date($act->datep,'%Y').'">';
  742. print '<input type="hidden" name="month" value="'.dol_print_date($act->datep,'%m').'">';
  743. print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
  744. //print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
  745. print img_picto($langs->trans("ViewCal"),'object_calendarweek').' <input type="submit" style="width: 120px" class="button" name="viewweek" value="'.$langs->trans("ViewWeek").'">';
  746. print '</form>'."\n";
  747. print '<form name="listactionsfilterday" action="'.DOL_URL_ROOT.'/comm/action/index.php" method="POST">';
  748. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  749. print '<input type="hidden" name="action" value="show_day">';
  750. print '<input type="hidden" name="year" value="'.dol_print_date($act->datep,'%Y').'">';
  751. print '<input type="hidden" name="month" value="'.dol_print_date($act->datep,'%m').'">';
  752. print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
  753. //print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
  754. print img_picto($langs->trans("ViewCal"),'object_calendarday').' <input type="submit" style="width: 120px" class="button" name="viewday" value="'.$langs->trans("ViewDay").'">';
  755. print '</form>'."\n";
  756. print '</td>';
  757. print '</tr>';
  758. // Date end
  759. print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="2">';
  760. if (! $act->fulldayevent) print dol_print_date($act->datef,'dayhour');
  761. else print dol_print_date($act->datef,'day');
  762. if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now- $delay_warning)) print img_warning($langs->trans("Late"));
  763. print '</td></tr>';
  764. // Status
  765. print '<tr><td nowrap>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td colspan="2">';
  766. print $act->getLibStatut(4);
  767. print '</td></tr>';
  768. // Location
  769. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
  770. print '</table><br><table class="border" width="100%">';
  771. // Input by
  772. print '<tr><td width="30%" nowrap>'.$langs->trans("ActionAskedBy").'</td><td colspan="3">';
  773. if ($act->author->id > 0) print $act->author->getNomUrl(1);
  774. else print '&nbsp;';
  775. print '</td></tr>';
  776. // Affecte a
  777. print '<tr><td nowrap>'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
  778. if ($act->usertodo->id > 0) print $act->usertodo->getNomUrl(1);
  779. print '</td></tr>';
  780. // Done by
  781. print '<tr><td nowrap>'.$langs->trans("ActionDoneBy").'</td><td colspan="3">';
  782. if ($act->userdone->id > 0) print $act->userdone->getNomUrl(1);
  783. print '</td></tr>';
  784. print '</table><br><table class="border" width="100%">';
  785. // Third party - Contact
  786. print '<tr><td width="30%">'.$langs->trans("ActionOnCompany").'</td><td>'.($act->societe->id?$act->societe->getNomUrl(1):$langs->trans("None"));
  787. if ($act->societe->id && $act->type_code == 'AC_TEL')
  788. {
  789. if ($act->societe->fetch($act->societe->id))
  790. {
  791. print "<br>".dol_print_phone($act->societe->tel);
  792. }
  793. }
  794. print '</td>';
  795. print '<td>'.$langs->trans("Contact").'</td>';
  796. print '<td>';
  797. if ($act->contact->id > 0)
  798. {
  799. print $act->contact->getNomUrl(1);
  800. if ($act->contact->id && $act->type_code == 'AC_TEL')
  801. {
  802. if ($act->contact->fetch($act->contact->id))
  803. {
  804. print "<br>".dol_print_phone($act->contact->phone_pro);
  805. }
  806. }
  807. }
  808. else
  809. {
  810. print $langs->trans("None");
  811. }
  812. print '</td></tr>';
  813. // Project
  814. if ($conf->projet->enabled)
  815. {
  816. print '<tr><td valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
  817. if ($act->fk_project)
  818. {
  819. $project=new Project($db);
  820. $project->fetch($act->fk_project);
  821. print $project->getNomUrl(1);
  822. }
  823. print '</td></tr>';
  824. }
  825. // Priority
  826. print '<tr><td nowrap>'.$langs->trans("Priority").'</td><td colspan="3">';
  827. print ($act->priority?$act->priority:'');
  828. print '</td></tr>';
  829. // Object linked
  830. if (! empty($act->fk_element) && ! empty($act->elementtype))
  831. {
  832. print '<tr><td>'.$langs->trans("LinkedObject").'</td>';
  833. print '<td colspan="3">'.$act->getElementUrl($act->fk_element,$act->elementtype,1).'</td></tr>';
  834. }
  835. // Description
  836. print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
  837. print dol_htmlentitiesbr($act->note);
  838. print '</td></tr>';
  839. print '</table>';
  840. }
  841. print "</div>\n";
  842. /*
  843. * Barre d'actions
  844. *
  845. */
  846. print '<div class="tabsAction">';
  847. if ($action != 'edit')
  848. {
  849. if ($user->rights->agenda->allactions->create ||
  850. (($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->create))
  851. {
  852. print '<a class="butAction" href="fiche.php?action=edit&id='.$act->id.'">'.$langs->trans("Modify").'</a>';
  853. }
  854. else
  855. {
  856. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Modify").'</a>';
  857. }
  858. if ($user->rights->agenda->allactions->delete ||
  859. (($act->author->id == $user->id || $act->usertodo->id == $user->id) && $user->rights->agenda->myactions->delete))
  860. {
  861. print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$act->id.'">'.$langs->trans("Delete").'</a>';
  862. }
  863. else
  864. {
  865. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a>';
  866. }
  867. }
  868. print '</div>';
  869. }
  870. $db->close();
  871. llxFooter();
  872. /**
  873. * \brief Ajoute une ligne de tableau a 2 colonnes pour avoir l'option synchro calendrier
  874. * \return int Retourne le nombre de lignes ajoutees
  875. */
  876. function add_row_for_calendar_link()
  877. {
  878. global $conf,$langs,$user;
  879. $nbtr=0;
  880. // Lien avec calendrier si module active
  881. if ($conf->webcalendar->enabled)
  882. {
  883. if ($conf->global->PHPWEBCALENDAR_SYNCRO != 'never')
  884. {
  885. $langs->load("other");
  886. print '<tr><td width="25%" nowrap>'.$langs->trans("AddCalendarEntry","Webcalendar").'</td>';
  887. if (! $user->webcal_login)
  888. {
  889. print '<td><input type="checkbox" disabled name="add_webcal">';
  890. print ' '.$langs->transnoentities("ErrorWebcalLoginNotDefined","<a href=\"".DOL_URL_ROOT."/user/fiche.php?id=".$user->id."\">".$user->login."</a>");
  891. print '</td>';
  892. print '</tr>';
  893. $nbtr++;
  894. }
  895. else
  896. {
  897. if ($conf->global->PHPWEBCALENDAR_SYNCRO == 'always')
  898. {
  899. print '<input type="hidden" name="add_webcal" value="on">';
  900. }
  901. else
  902. {
  903. print '<td><input type="checkbox" name="add_webcal"'.(($conf->global->PHPWEBCALENDAR_SYNCRO=='always' || $conf->global->PHPWEBCALENDAR_SYNCRO=='yesbydefault')?' checked':'').'></td>';
  904. print '</tr>';
  905. $nbtr++;
  906. }
  907. }
  908. }
  909. }
  910. if ($conf->phenix->enabled)
  911. {
  912. if ($conf->global->PHPPHENIX_SYNCRO != 'never')
  913. {
  914. $langs->load("other");
  915. print '<tr><td width="25%" nowrap>'.$langs->trans("AddCalendarEntry","Phenix").'</td>';
  916. if (! $user->phenix_login)
  917. {
  918. print '<td><input type="checkbox" disabled name="add_phenix">';
  919. print ' '.$langs->transnoentities("ErrorPhenixLoginNotDefined","<a href=\"".DOL_URL_ROOT."/user/fiche.php?id=".$user->id."\">".$user->login."</a>");
  920. print '</td>';
  921. print '</tr>';
  922. $nbtr++;
  923. }
  924. else
  925. {
  926. if ($conf->global->PHPPHENIX_SYNCRO == 'always')
  927. {
  928. print '<input type="hidden" name="add_phenix" value="on">';
  929. }
  930. else
  931. {
  932. print '<td><input type="checkbox" name="add_phenix"'.(($conf->global->PHPPHENIX_SYNCRO=='always' || $conf->global->PHPPHENIX_SYNCRO=='yesbydefault')?' checked':'').'></td>';
  933. print '</tr>';
  934. $nbtr++;
  935. }
  936. }
  937. }
  938. }
  939. return $nbtr;
  940. }
  941. ?>