PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/agenda/class/agenda.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 1510 lines | 992 code | 148 blank | 370 comment | 212 complexity | b4323952a19ae9baf77c9b5990587b65 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2011-2012 Herve Prot <herve.prot@symeos.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 <http://www.gnu.org/licenses/>.
  20. */
  21. require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
  22. /**
  23. * \class ActionComm
  24. * \brief Class to manage agenda events (actions)
  25. */
  26. class Agenda extends nosqlDocument {
  27. public $element = 'action';
  28. public $table_element = 'actioncomm';
  29. protected $ismultientitymanaged = 2; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  30. var $id;
  31. var $type_id;
  32. var $type_code;
  33. var $type;
  34. var $label;
  35. var $datec; // Date creation record (datec)
  36. var $datem; // Date modification record (tms)
  37. var $author; // Object user that create action
  38. var $usermod; // Object user that modified action
  39. var $datep; // Date action start (datep)
  40. var $datef; // Date action end (datep2)
  41. var $durationp = -1; // -1=Unkown duration
  42. var $fulldayevent = 0; // 1=Event on full day
  43. var $punctual = 1; // Milestone
  44. var $percentage; // Percentage
  45. var $location; // Location
  46. var $priority; // Free text ('' By default)
  47. var $notes; // Description
  48. var $usertodo; // Object user that must do action
  49. var $userdone; // Object user that did action
  50. var $societe; // Company linked to action (optionnal)
  51. var $contact; // Contact linked tot action (optionnal)
  52. var $fk_project; // Id of project (optionnal)
  53. var $fk_lead; // Id of lead (optionnal)
  54. var $fk_task; // Id of mother task (optionnal)
  55. // Properties for links to other objects
  56. var $fk_element; // Id of record
  57. var $elementtype; // Type of record. This if property ->element of object linked to.
  58. // Ical
  59. var $icalname;
  60. var $icalcolor;
  61. var $actions = array();
  62. var $Status = "TODO"; // Status of the action
  63. /**
  64. * Constructor
  65. *
  66. * @param DoliDB $db Database handler
  67. */
  68. function __construct($db = null) {
  69. parent::__construct($db);
  70. $this->fk_extrafields = new ExtraFields($db);
  71. $this->fk_extrafields->fetch(get_class($this));
  72. $this->Status = "TODO";
  73. $this->author = null;
  74. $this->usermod = null;
  75. $this->usertodo = null;
  76. $this->userdone = null;
  77. $this->societe = new stdClass();
  78. $this->contact = new stdClass();
  79. }
  80. /**
  81. * Add an action/event into database
  82. *
  83. * @param User $user Object user making action
  84. * @param int $notrigger 1 = disable triggers, 0 = enable triggers
  85. * @return int Id of created event, < 0 if KO
  86. */
  87. function add($user, $notrigger = 0) {
  88. global $langs, $conf;
  89. $error = 0;
  90. $now = dol_now();
  91. // Clean parameters
  92. $this->label = dol_trunc(trim($this->label), 128);
  93. $this->location = dol_trunc(trim($this->location), 128);
  94. $this->notes = dol_htmlcleanlastbr(trim($this->notes));
  95. if (empty($this->percentage))
  96. $this->percentage = 0;
  97. if (empty($this->priority))
  98. $this->priority = 0;
  99. if (empty($this->fulldayevent))
  100. $this->fuldayevent = 0;
  101. if (empty($this->punctual))
  102. $this->punctual = 0;
  103. if ($this->percentage > 100)
  104. $this->percentage = 100;
  105. if ($this->percentage == 100 && !$this->dateend)
  106. $this->dateend = $this->date;
  107. if ($this->datep && $this->datef)
  108. $this->durationp = ($this->datef - $this->datep);
  109. if ($this->date && $this->dateend)
  110. $this->durationa = ($this->dateend - $this->date);
  111. if ($this->datep && $this->datef && $this->datep > $this->datef)
  112. $this->datef = $this->datep;
  113. if ($this->date && $this->dateend && $this->date > $this->dateend)
  114. $this->dateend = $this->date;
  115. if ($this->fk_project < 0)
  116. $this->fk_project = 0;
  117. if ($this->fk_lead < 0)
  118. $this->fk_lead = 0;
  119. if ($this->fk_task < 0)
  120. $this->fk_task = 0;
  121. if ($this->elementtype == 'facture')
  122. $this->elementtype = 'invoice';
  123. if ($this->elementtype == 'commande')
  124. $this->elementtype = 'order';
  125. if ($this->elementtype == 'contrat')
  126. $this->elementtype = 'contract';
  127. if ($this->type == 2 && $this->percentage == 100) //ACTION
  128. $this->datef = dol_now();
  129. if ($this->percentage == 100 && !$this->userdone->id > 0) {
  130. $this->userdone->id = $user->id;
  131. }
  132. $this->datec = $now;
  133. $this->record();
  134. /*
  135. $sql = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm";
  136. $sql.= "(datec,";
  137. $sql.= "datep,";
  138. $sql.= "datep2,";
  139. //$sql.= "datea,";
  140. //$sql.= "datea2,";
  141. $sql.= "durationp,";
  142. //$sql.= "durationa,";
  143. $sql.= "fk_action,";
  144. $sql.= "fk_soc,";
  145. $sql.= "fk_project,";
  146. $sql.= "fk_lead,";
  147. $sql.= "fk_task,";
  148. $sql.= "note,";
  149. $sql.= "fk_contact,";
  150. $sql.= "fk_user_author,";
  151. $sql.= "fk_user_action,";
  152. $sql.= "fk_user_done,";
  153. $sql.= "label,percent,priority,fulldayevent,location,punctual,";
  154. $sql.= "fk_element,";
  155. $sql.= "elementtype,";
  156. $sql.= "entity";
  157. $sql.= ") VALUES (";
  158. $sql.= "'" . $this->db->idate($now) . "',";
  159. $sql.= (strval($this->datep) != '' ? "'" . $this->db->idate($this->datep) . "'" : "null") . ",";
  160. $sql.= (strval($this->datef) != '' ? "'" . $this->db->idate($this->datef) . "'" : "null") . ",";
  161. //$sql.= (strval($this->date)!=''?"'".$this->db->idate($this->date)."'":"null").",";
  162. //$sql.= (strval($this->dateend)!=''?"'".$this->db->idate($this->dateend)."'":"null").",";
  163. $sql.= ($this->durationp >= 0 && $this->durationp != '' ? "'" . $this->durationp . "'" : "null") . ",";
  164. //$sql.= ($this->durationa >= 0 && $this->durationa != ''?"'".$this->durationa."'":"null").",";
  165. $sql.= " '" . $this->type_id . "',";
  166. $sql.= ($this->societe->id > 0 ? " '" . $this->societe->id . "'" : "null") . ",";
  167. $sql.= ($this->fk_project > 0 ? " '" . $this->fk_project . "'" : "null") . ",";
  168. $sql.= ($this->fk_lead > 0 ? " '" . $this->fk_lead . "'" : "null") . ",";
  169. $sql.= ($this->fk_task > 0 ? " '" . $this->fk_task . "'" : "null") . ",";
  170. $sql.= " '" . $this->db->escape($this->note) . "',";
  171. $sql.= ($this->contact->id > 0 ? "'" . $this->contact->id . "'" : "null") . ",";
  172. $sql.= ($user->id > 0 ? "'" . $user->id . "'" : "null") . ",";
  173. $sql.= ($this->usertodo->id > 0 ? "'" . $this->usertodo->id . "'" : "null") . ",";
  174. $sql.= ($this->userdone->id > 0 ? "'" . $this->userdone->id . "'" : "null") . ",";
  175. $sql.= "'" . $this->db->escape($this->label) . "','" . $this->percentage . "','" . $this->priority . "','" . $this->fulldayevent . "','" . $this->db->escape($this->location) . "','" . $this->punctual . "',";
  176. $sql.= ($this->fk_element ? $this->fk_element : "null") . ",";
  177. $sql.= ($this->elementtype ? "'" . $this->elementtype . "'" : "null") . ",";
  178. $sql.= $conf->entity;
  179. $sql.= ")";
  180. dol_syslog(get_class($this) . "::add sql=" . $sql);
  181. */
  182. if (!$notrigger) {
  183. // Appel des triggers
  184. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  185. $interface = new Interfaces($this->db);
  186. $result = $interface->run_triggers('ACTION_CREATE', $this, $user, $langs, $conf);
  187. if ($result < 0) {
  188. $error++;
  189. $this->errors = $interface->errors;
  190. }
  191. // Fin appel triggers
  192. }
  193. return $this->id;
  194. }
  195. /**
  196. * Load object from database
  197. *
  198. * @param int $id Id of action to get
  199. * @return int <0 if KO, >0 if OK
  200. */
  201. function fetch($id) {
  202. global $langs;
  203. try {
  204. $this->load($id);
  205. return 1;
  206. } catch (Exception $e) {
  207. $this->error = $e->getMessage();
  208. return -1;
  209. }
  210. }
  211. /**
  212. * Delete event from database
  213. *
  214. * @param int $notrigger 1 = disable triggers, 0 = enable triggers
  215. * @return int <0 if KO, >0 if OK
  216. */
  217. function delete($notrigger = 0) {
  218. global $user, $langs, $conf;
  219. $error = 0;
  220. $this->deleteDoc();
  221. /*
  222. $this->db->begin();
  223. $sql = "DELETE FROM " . MAIN_DB_PREFIX . "actioncomm";
  224. $sql.= " WHERE id=" . $this->id;
  225. */
  226. //dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
  227. //if ($this->db->query($sql)) {
  228. if (!$notrigger) {
  229. // Appel des triggers
  230. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  231. $interface = new Interfaces($this->db);
  232. $result = $interface->run_triggers('ACTION_DELETE', $this, $user, $langs, $conf);
  233. if ($result < 0) {
  234. $error++;
  235. $this->errors = $interface->errors;
  236. }
  237. // Fin appel triggers
  238. }
  239. if (!$error) {
  240. //$this->db->commit();
  241. return 1;
  242. } else {
  243. //$this->db->rollback();
  244. return -2;
  245. }
  246. /* } else {
  247. $this->db->rollback();
  248. $this->error = $this->db->lasterror();
  249. dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
  250. return -1;
  251. } */
  252. }
  253. /**
  254. * Update action into database
  255. * If percentage = 100, on met a jour date 100%
  256. *
  257. * @param User $user Object user making change
  258. * @param int $notrigger 1 = disable triggers, 0 = enable triggers
  259. * @return int <0 if KO, >0 if OK
  260. */
  261. function update($user, $notrigger = 0) {
  262. global $langs, $conf;
  263. // Clean parameters
  264. $this->label = trim($this->label);
  265. $this->notes = trim($this->notes);
  266. if (empty($this->percentage))
  267. $this->percentage = 0;
  268. if (empty($this->fulldayevent))
  269. $this->fulldayevent = 0;
  270. if ($this->percentage > 100)
  271. $this->percentage = 100;
  272. if ($this->percentage == 100 && !$this->dateend)
  273. $this->dateend = $this->date;
  274. //if ($this->datep && $this->datef)
  275. // $this->durationp = ($this->datef - $this->datep);
  276. if ($this->date && $this->dateend)
  277. $this->durationa = ($this->dateend - $this->date);
  278. if ($this->datep && $this->datef && $this->datep > $this->datef)
  279. $this->datef = $this->datep;
  280. if ($this->date && $this->dateend && $this->date > $this->dateend)
  281. $this->dateend = $this->date;
  282. if ($this->fk_project < 0)
  283. $this->fk_project = 0;
  284. if ($this->fk_lead < 0)
  285. $this->fk_lead = 0;
  286. if ($this->fk_task < 0)
  287. $this->fk_task = 0;
  288. if (empty($this->label))
  289. $this->label = $cact->libelle;
  290. if ($this->type == 2 && $this->percentage == 100) //ACTION
  291. $this->datef = dol_now();
  292. if ($this->percentage > 0 && $this->percentage < 100)
  293. $this->Status = "ON";
  294. if ($this->percentage == 100)
  295. $this->Status = "DONE";
  296. if ($this->Status == "ON" && !$this->userdone->id) {
  297. $this->userdone->id = $user->id;
  298. $this->userdone->name = $user->name;
  299. }
  300. // Check parameters
  301. if ($this->Status == "TODO" && $this->userdone->id) {
  302. //$this->error="ErrorCantSaveADoneUserWithZeroPercentage";
  303. //return -1;
  304. unset($this->userdone->id);
  305. unset($this->userdone->name);
  306. }
  307. if ($this->Status == "DONE" && !$this->userdone->id) {
  308. $this->userdone->id = $user->id;
  309. $this->userdone->name = $user->name;
  310. }
  311. if ($this->Status == "DONE")
  312. $this->percentage = 100;
  313. elseif ($this->Status == "TODO")
  314. $this->percentage = 0;
  315. if (!empty($this->societe->id)) {
  316. $object = new Societe($this->db);
  317. $object->load($this->societe->id);
  318. $this->societe->name = $object->name;
  319. } else {
  320. unset($this->societe->name);
  321. }
  322. if (!empty($this->contact->id)) {
  323. $object = new Contact($this->db);
  324. $object->load($this->contact->id);
  325. $this->contact->name = $object->name;
  326. } else {
  327. unset($this->contact->name);
  328. }
  329. if (!empty($this->usertodo->id)) {
  330. $object = new User($this->db);
  331. $object->load($this->usertodo->id);
  332. $this->usertodo->name = $object->name;
  333. } else {
  334. unset($this->usertodo->name);
  335. }
  336. if (!empty($this->userdone->id)) {
  337. $object = new User($this->db);
  338. $object->load($this->userdone->id);
  339. $this->userdone->name = $object->name;
  340. } else {
  341. unset($this->userdone->name);
  342. }
  343. $this->record();
  344. dol_delcache(get_class($this) . ":countTODO"); //Reset stats cache for agenda
  345. if (!$notrigger) {
  346. // Appel des triggers
  347. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  348. $interface = new Interfaces($this->db);
  349. $result = $interface->run_triggers('ACTION_MODIFY', $this, $user, $langs, $conf);
  350. if ($result < 0) {
  351. $error++;
  352. $this->errors = $interface->errors;
  353. }
  354. // Fin appel triggers
  355. }
  356. return 1;
  357. }
  358. /**
  359. * Load all objects with filters
  360. *
  361. * @param int $socid Filter by thirdparty
  362. * @param int $fk_element Id of element action is linked to
  363. * @param string $elementtype Type of element action is linked to
  364. * @param string $filter Other filter
  365. * @return int <0 if KO, >0 if OK
  366. */
  367. function getActions($socid = 0, $fk_element = 0, $elementtype = '', $filter = '') {
  368. global $conf, $langs;
  369. $sql = "SELECT a.id";
  370. $sql.= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
  371. $sql.= " WHERE a.entity = " . $conf->entity;
  372. if (!empty($socid))
  373. $sql.= " AND a.fk_soc = " . $socid;
  374. if (!empty($elementtype)) {
  375. if ($elementtype == 'project')
  376. $sql.= ' AND a.fk_project = ' . $fk_element;
  377. else
  378. $sql.= " AND a.fk_element = " . $fk_element . " AND a.elementtype = '" . $elementtype . "'";
  379. }
  380. if (!empty($filter))
  381. $sql.= $filter;
  382. dol_syslog(get_class($this) . "::getActions sql=" . $sql);
  383. $resql = $this->db->query($sql);
  384. if ($resql) {
  385. $num = $this->db->num_rows($resql);
  386. if ($num) {
  387. for ($i = 0; $i < $num; $i++) {
  388. $obj = $this->db->fetch_object($resql);
  389. $actioncommstatic = new ActionComm($this->db);
  390. $actioncommstatic->fetch($obj->id);
  391. $this->actions[$i] = $actioncommstatic;
  392. }
  393. }
  394. $this->db->free($resql);
  395. return 1;
  396. } else {
  397. $this->error = $this->db->lasterror();
  398. return -1;
  399. }
  400. }
  401. /**
  402. * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
  403. *
  404. * @param User $user Objet user
  405. * @return int <0 if KO, >0 if OK
  406. */
  407. function load_board($user) {
  408. global $conf, $user;
  409. $now = dol_now();
  410. $this->nbtodo = $this->nbtodolate = 0;
  411. $sql = "SELECT a.id, a.datep as dp";
  412. $sql.= " FROM (" . MAIN_DB_PREFIX . "actioncomm as a";
  413. if (!$user->rights->societe->client->voir && !$user->societe_id)
  414. $sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
  415. $sql.= ")";
  416. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON a.fk_soc = s.rowid";
  417. $sql.= " WHERE a.percent >= 0 AND a.percent < 100";
  418. $sql.= " AND a.entity = " . $conf->entity;
  419. if (!$user->rights->societe->client->voir && !$user->societe_id)
  420. $sql.= " AND a.fk_soc = sc.fk_soc AND sc.fk_user = " . $user->id;
  421. if ($user->societe_id)
  422. $sql.=" AND a.fk_soc = " . $user->societe_id;
  423. //print $sql;
  424. $resql = $this->db->query($sql);
  425. if ($resql) {
  426. while ($obj = $this->db->fetch_object($resql)) {
  427. $this->nbtodo++;
  428. if (isset($obj->dp) && $this->db->jdate($obj->dp) < ($now - $conf->actions->warning_delay))
  429. $this->nbtodolate++;
  430. }
  431. return 1;
  432. }
  433. else {
  434. $this->error = $this->db->error();
  435. return -1;
  436. }
  437. }
  438. /**
  439. * Charge les informations d'ordre info dans l'objet facture
  440. *
  441. * @param int $id Id de la facture a charger
  442. * @return void
  443. */
  444. function info($id) {
  445. $sql = 'SELECT ';
  446. $sql.= ' a.id,';
  447. $sql.= ' datec,';
  448. $sql.= ' tms as datem,';
  449. $sql.= ' fk_user_author,';
  450. $sql.= ' fk_user_mod';
  451. $sql.= ' FROM ' . MAIN_DB_PREFIX . 'actioncomm as a';
  452. $sql.= ' WHERE a.id = ' . $id;
  453. dol_syslog(get_class($this) . "::info sql=" . $sql);
  454. $result = $this->db->query($sql);
  455. if ($result) {
  456. if ($this->db->num_rows($result)) {
  457. $obj = $this->db->fetch_object($result);
  458. $this->id = $obj->id;
  459. if ($obj->fk_user_author) {
  460. $cuser = new User($this->db);
  461. $cuser->fetch($obj->fk_user_author);
  462. $this->user_creation = $cuser;
  463. }
  464. if ($obj->fk_user_mod) {
  465. $muser = new User($this->db);
  466. $muser->fetch($obj->fk_user_mod);
  467. $this->user_modification = $muser;
  468. }
  469. $this->date_creation = $this->db->jdate($obj->datec);
  470. $this->date_modification = $this->db->jdate($obj->datem);
  471. }
  472. $this->db->free($result);
  473. } else {
  474. dol_print_error($this->db);
  475. }
  476. }
  477. /**
  478. * Return label of status
  479. *
  480. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  481. * @param int $hidenastatus 1=Show nothing if status is "Not applicable"
  482. * @return string String with status
  483. */
  484. /* function getLibStatut($mode, $hidenastatus = 0) {
  485. return $this->LibStatut($this->percentage, $mode, $hidenastatus);
  486. } */
  487. /**
  488. * Return label of action status
  489. *
  490. * @param int $percent Percent
  491. * @param int $mode 0=Long label, 1=Short label, 2=Picto+Short label, 3=Picto, 4=Picto+Short label, 5=Short label+Picto, 6=Very short label+Picto
  492. * @param int $hidenastatus 1=Show nothing if status is "Not applicable"
  493. * @return string Label
  494. */
  495. /* function LibStatut($percent, $mode, $hidenastatus = 0) {
  496. global $langs;
  497. if ($mode == 0) {
  498. if ($percent == -1 && !$hidenastatus)
  499. return $langs->trans('StatusNotApplicable');
  500. else if ($percent == 0)
  501. return $langs->trans('StatusActionToDo') . ' (0%)';
  502. else if ($percent > 0 && $percent < 100)
  503. return $langs->trans('StatusActionInProcess') . ' (' . $percent . '%)';
  504. else if ($percent >= 100)
  505. return $langs->trans('StatusActionDone') . ' (100%)';
  506. }
  507. else if ($mode == 1) {
  508. if ($percent == -1 && !$hidenastatus)
  509. return $langs->trans('StatusNotApplicable');
  510. else if ($percent == 0)
  511. return $langs->trans('StatusActionToDo');
  512. else if ($percent > 0 && $percent < 100)
  513. return $percent . '%';
  514. else if ($percent >= 100)
  515. return $langs->trans('StatusActionDone');
  516. }
  517. else if ($mode == 2) {
  518. if ($percent == -1 && !$hidenastatus)
  519. return img_picto($langs->trans('StatusNotApplicable'), 'statut9') . ' ' . $langs->trans('StatusNotApplicable');
  520. else if ($percent == 0)
  521. return img_picto($langs->trans('StatusActionToDo'), 'statut1') . ' ' . $langs->trans('StatusActionToDo');
  522. else if ($percent > 0 && $percent < 100)
  523. return img_picto($langs->trans('StatusActionInProcess'), 'statut3') . ' ' . $percent . '%';
  524. else if ($percent >= 100)
  525. return img_picto($langs->trans('StatusActionDone'), 'statut6') . ' ' . $langs->trans('StatusActionDone');
  526. }
  527. else if ($mode == 3) {
  528. if ($percent == -1 && !$hidenastatus)
  529. return img_picto($langs->trans("Status") . ': ' . $langs->trans('StatusNotApplicable'), 'statut9');
  530. else if ($percent == 0)
  531. return img_picto($langs->trans("Status") . ': ' . $langs->trans('StatusActionToDo') . ' (0%)', 'statut1');
  532. else if ($percent > 0 && $percent < 100)
  533. return img_picto($langs->trans("Status") . ': ' . $langs->trans('StatusActionInProcess') . ' (' . $percent . '%)', 'statut3');
  534. else if ($percent >= 100)
  535. return img_picto($langs->trans("Status") . ': ' . $langs->trans('StatusActionDone') . ' (100%)', 'statut6');
  536. }
  537. else if ($mode == 4) {
  538. if ($percent == -1 && !$hidenastatus)
  539. return img_picto($langs->trans('StatusNotApplicable'), 'statut9') . ' ' . $langs->trans('StatusNotApplicable');
  540. else if ($percent == 0)
  541. return img_picto($langs->trans('StatusActionToDo'), 'statut1') . ' ' . $langs->trans('StatusActionToDo') . ' (0%)';
  542. else if ($percent > 0 && $percent < 100)
  543. return img_picto($langs->trans('StatusActionInProcess'), 'statut3') . ' ' . $langs->trans('StatusActionInProcess') . ' (' . $percent . '%)';
  544. else if ($percent >= 100)
  545. return img_picto($langs->trans('StatusActionDone'), 'statut6') . ' ' . $langs->trans('StatusActionDone') . ' (100%)';
  546. }
  547. else if ($mode == 5) {
  548. if ($percent == -1 && !$hidenastatus)
  549. return img_picto($langs->trans('StatusNotApplicable'), 'statut9');
  550. else if ($percent == 0)
  551. return '0% ' . img_picto($langs->trans('StatusActionToDo'), 'statut1');
  552. else if ($percent > 0 && $percent < 100)
  553. return $percent . '% ' . img_picto($langs->trans('StatusActionInProcess') . ' - ' . $percent . '%', 'statut3');
  554. else if ($percent >= 100)
  555. return $langs->trans('StatusActionDone') . ' ' . img_picto($langs->trans('StatusActionDone'), 'statut6');
  556. }
  557. else if ($mode == 6) {
  558. if ($percent == -1 && !$hidenastatus)
  559. return img_picto($langs->trans('StatusNotApplicable'), 'statut9');
  560. else if ($percent == 0)
  561. return '0% ' . img_picto($langs->trans('StatusActionToDo'), 'statut1');
  562. else if ($percent > 0 && $percent < 100)
  563. return $percent . '% ' . img_picto($langs->trans('StatusActionInProcess') . ' - ' . $percent . '%', 'statut3');
  564. else if ($percent >= 100)
  565. return img_picto($langs->trans('StatusActionDone'), 'statut6');
  566. }
  567. return '';
  568. } */
  569. /**
  570. * Renvoie nom clicable (avec eventuellement le picto)
  571. * Utilise $this->id, $this->code et $this->label
  572. *
  573. * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
  574. * @param int $maxlength Nombre de caracteres max dans libelle
  575. * @param string $classname Force style class on a link
  576. * @param string $option ''=Link to action,'birthday'=Link to contact
  577. * @param int $overwritepicto 1=Overwrite picto
  578. * @return string Chaine avec URL
  579. */
  580. function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = '') {
  581. global $langs;
  582. $result = '';
  583. if ($option == 'birthday')
  584. $lien = '<a ' . ($classname ? 'class="' . $classname . '" ' : '') . 'href="' . DOL_URL_ROOT . '/contact/perso.php?id=' . $this->id . '">';
  585. else
  586. $lien = '<a ' . ($classname ? 'class="' . $classname . '" ' : '') . 'href="' . DOL_URL_ROOT . '/comm/action/fiche.php?id=' . $this->id . '">';
  587. $lienfin = '</a>';
  588. //print $this->libelle;
  589. if ($withpicto == 2) {
  590. $libelle = $langs->trans("Action" . $this->type_code);
  591. $libelleshort = '';
  592. } else if (empty($this->libelle)) {
  593. $libelle = $langs->trans("Action" . $this->type_code);
  594. $libelleshort = $langs->trans("Action" . $this->type_code, '', '', '', '', $maxlength);
  595. } else {
  596. $libelle = $this->libelle;
  597. $libelleshort = dol_trunc($this->libelle, $maxlength);
  598. }
  599. if ($withpicto) {
  600. $libelle.=(($this->type_code && $libelle != $langs->trans("Action" . $this->type_code) && $langs->trans("Action" . $this->type_code) != "Action" . $this->type_code) ? ' (' . $langs->trans("Action" . $this->type_code) . ')' : '');
  601. $result.=$lien . img_object($langs->trans("ShowAction") . ': ' . $libelle, ($overwritepicto ? $overwritepicto : 'action')) . $lienfin;
  602. }
  603. if ($withpicto == 1)
  604. $result.=' ';
  605. $result.=$lien . $libelleshort . $lienfin;
  606. return $result;
  607. }
  608. /*
  609. * Ajouter une tache automatisé suite a une action. Exemple validation d'une facture, création d'une commande, ...
  610. * param type
  611. * param
  612. *
  613. */
  614. function addAutoTask($type, $label, $socid, $leadid, $projetid, $contactid = '') {
  615. global $user;
  616. $now = dol_now();
  617. $this->fk_lead = $leadid;
  618. $this->fk_project = $projectid;
  619. $this->label = $label;
  620. $this->type_code = $type;
  621. $this->datep = $now;
  622. $this->datef = $now;
  623. $this->societe->id = $socid;
  624. $this->contact = $contactid;
  625. $this->percentage = 100;
  626. $this->userdone = $user;
  627. $this->usertodo = $user;
  628. $this->type = 2;
  629. $this->add($user);
  630. }
  631. /**
  632. * Export events from database into a cal file.
  633. *
  634. * @param string $format 'vcal', 'ical/ics', 'rss'
  635. * @param string $type 'event' or 'journal'
  636. * @param int $cachedelay Do not rebuild file if date older than cachedelay seconds
  637. * @param string $filename Force filename
  638. * @param array $filters Array of filters
  639. * @return int <0 if error, nb of events in new file if ok
  640. */
  641. function build_exportfile($format, $type, $cachedelay, $filename, $filters) {
  642. global $conf, $langs, $dolibarr_main_url_root, $mysoc;
  643. require_once (DOL_DOCUMENT_ROOT . "/core/lib/xcal.lib.php");
  644. require_once (DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php");
  645. dol_syslog(get_class($this) . "::build_exportfile Build export file format=" . $format . ", type=" . $type . ", cachedelay=" . $cachedelay . ", filename=" . $filename . ", filters size=" . count($filters), LOG_DEBUG);
  646. // Check parameters
  647. if (empty($format))
  648. return -1;
  649. // Clean parameters
  650. if (!$filename) {
  651. $extension = 'vcs';
  652. if ($format == 'ical')
  653. $extension = 'ics';
  654. $filename = $format . '.' . $extension;
  655. }
  656. // Create dir and define output file (definitive and temporary)
  657. $result = dol_mkdir($conf->agenda->dir_temp);
  658. $outputfile = $conf->agenda->dir_temp . '/' . $filename;
  659. $result = 0;
  660. $buildfile = true;
  661. $login = '';
  662. $logina = '';
  663. $logind = '';
  664. $logint = '';
  665. $now = dol_now();
  666. if ($cachedelay) {
  667. $nowgmt = dol_now();
  668. include_once(DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php');
  669. if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay)) {
  670. dol_syslog(get_class($this) . "::build_exportfile file " . $outputfile . " is not older than now - cachedelay (" . $nowgmt . " - " . $cachedelay . "). Build is canceled");
  671. $buildfile = false;
  672. }
  673. }
  674. if ($buildfile) {
  675. // Build event array
  676. $eventarray = array();
  677. $sql = "SELECT a.id,";
  678. $sql.= " a.datep,"; // Start
  679. $sql.= " a.datep2,"; // End
  680. $sql.= " a.durationp,";
  681. $sql.= " a.datec, a.tms as datem,";
  682. $sql.= " a.note, a.label, a.fk_action as type_id,";
  683. $sql.= " a.fk_soc,";
  684. $sql.= " a.fk_user_author, a.fk_user_mod,";
  685. $sql.= " a.fk_user_action, a.fk_user_done,";
  686. $sql.= " a.fk_contact, a.percent as percentage,";
  687. $sql.= " a.fk_element, a.elementtype,";
  688. $sql.= " a.priority, a.fulldayevent, a.location,";
  689. $sql.= " u.firstname, u.name,";
  690. $sql.= " s.nom as socname,";
  691. $sql.= " c.id as type_id, c.code as type_code, c.libelle";
  692. $sql.= " FROM (" . MAIN_DB_PREFIX . "c_actioncomm as c, " . MAIN_DB_PREFIX . "actioncomm as a)";
  693. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on u.rowid = a.fk_user_author";
  694. $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s on s.rowid = a.fk_soc";
  695. $sql.= " WHERE a.fk_action=c.id";
  696. $sql.= " AND a.entity = " . $conf->entity;
  697. foreach ($filters as $key => $value) {
  698. if ($key == 'notolderthan')
  699. $sql.=" AND a.datep >= '" . $this->db->idate($now - ($value * 24 * 60 * 60)) . "'";
  700. if ($key == 'year')
  701. $sql.=" AND a.datep BETWEEN '" . $this->db->idate(dol_get_first_day($value, 1)) . "' AND '" . $this->db->idate(dol_get_last_day($value, 12)) . "'";
  702. if ($key == 'id')
  703. $sql.=" AND a.id=" . (is_numeric($value) ? $value : 0);
  704. if ($key == 'idfrom')
  705. $sql.=" AND a.id >= " . (is_numeric($value) ? $value : 0);
  706. if ($key == 'idto')
  707. $sql.=" AND a.id <= " . (is_numeric($value) ? $value : 0);
  708. if ($key == 'login') {
  709. $login = $value;
  710. $userforfilter = new User($this->db);
  711. $result = $userforfilter->fetch('', $value);
  712. $sql.= " AND (";
  713. $sql.= " a.fk_user_author = " . $userforfilter->id;
  714. $sql.= " OR a.fk_user_action = " . $userforfilter->id;
  715. $sql.= " OR a.fk_user_done = " . $userforfilter->id;
  716. $sql.= ")";
  717. }
  718. if ($key == 'logina') {
  719. $logina = $value;
  720. $userforfilter = new User($this->db);
  721. $result = $userforfilter->fetch('', $value);
  722. $sql.= " AND a.fk_user_author = " . $userforfilter->id;
  723. }
  724. if ($key == 'logint') {
  725. $logint = $value;
  726. $userforfilter = new User($this->db);
  727. $result = $userforfilter->fetch('', $value);
  728. $sql.= " AND a.fk_user_action = " . $userforfilter->id;
  729. }
  730. if ($key == 'logind') {
  731. $logind = $value;
  732. $userforfilter = new User($this->db);
  733. $result = $userforfilter->fetch('', $value);
  734. $sql.= " AND a.fk_user_done = " . $userforfilter->id;
  735. }
  736. }
  737. $sql.= " AND a.datep IS NOT NULL"; // To exclude corrupted events and avoid errors in lightning/sunbird import
  738. $sql.= " ORDER by datep";
  739. //print $sql;exit;
  740. dol_syslog(get_class($this) . "::build_exportfile select events sql=" . $sql);
  741. $resql = $this->db->query($sql);
  742. if ($resql) {
  743. // Note: Output of sql request is encoded in $conf->file->character_set_client
  744. while ($obj = $this->db->fetch_object($resql)) {
  745. $qualified = true;
  746. // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
  747. $event = array();
  748. $event['uid'] = 'dolibarragenda-' . $this->db->database_name . '-' . $obj->id . "@" . $_SERVER["SERVER_NAME"];
  749. $event['type'] = $type;
  750. //$datestart=$obj->datea?$obj->datea:$obj->datep;
  751. //$dateend=$obj->datea2?$obj->datea2:$obj->datep2;
  752. //$duration=$obj->durationa?$obj->durationa:$obj->durationp;
  753. $datestart = $this->db->jdate($obj->datep);
  754. //print $datestart.'x'; exit;
  755. $dateend = $this->db->jdate($obj->datep2);
  756. $duration = $obj->durationp;
  757. $event['summary'] = $obj->label . ($obj->socname ? " (" . $obj->socname . ")" : "");
  758. $event['desc'] = $obj->notes;
  759. $event['startdate'] = $datestart;
  760. $event['duration'] = $duration; // Not required with type 'journal'
  761. $event['enddate'] = $dateend; // Not required with type 'journal'
  762. $event['author'] = $obj->firstname . ($obj->name ? " " . $obj->name : "");
  763. $event['priority'] = $obj->priority;
  764. $event['fulldayevent'] = $obj->fulldayevent;
  765. $event['location'] = $obj->location;
  766. $event['transparency'] = 'TRANSPARENT'; // OPAQUE (busy) or TRANSPARENT (not busy)
  767. $event['category'] = $obj->libelle; // libelle type action
  768. $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
  769. $url = $urlwithouturlroot . DOL_URL_ROOT . '/comm/action/fiche.php?id=' . $obj->id;
  770. $event['url'] = $url;
  771. $event['created'] = $this->db->jdate($obj->datec);
  772. $event['modified'] = $this->db->jdate($obj->datem);
  773. if ($qualified && $datestart) {
  774. $eventarray[$datestart] = $event;
  775. }
  776. }
  777. } else {
  778. $this->error = $this->db->lasterror();
  779. dol_syslog(get_class($this) . "::build_exportfile " . $this->db->lasterror(), LOG_ERR);
  780. return -1;
  781. }
  782. $langs->load("agenda");
  783. // Define title and desc
  784. $more = '';
  785. if ($login)
  786. $more = $langs->transnoentities("User") . ' ' . $login;
  787. if ($logina)
  788. $more = $langs->transnoentities("ActionsAskedBy") . ' ' . $logina;
  789. if ($logint)
  790. $more = $langs->transnoentities("ActionsToDoBy") . ' ' . $logint;
  791. if ($logind)
  792. $more = $langs->transnoentities("ActionsDoneBy") . ' ' . $logind;
  793. if ($more) {
  794. $title = 'Dolibarr actions ' . $mysoc->name . ' - ' . $more;
  795. $desc = $more;
  796. $desc.=' (' . $mysoc->name . ' - built by Dolibarr)';
  797. } else {
  798. $title = 'Dolibarr actions ' . $mysoc->name;
  799. $desc = $langs->transnoentities('ListOfActions');
  800. $desc.=' (' . $mysoc->name . ' - built by Dolibarr)';
  801. }
  802. // Create temp file
  803. $outputfiletmp = tempnam($conf->agenda->dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
  804. @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
  805. // Write file
  806. if ($format == 'vcal')
  807. $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
  808. if ($format == 'ical')
  809. $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
  810. if ($format == 'rss')
  811. $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
  812. if ($result >= 0) {
  813. if (rename($outputfiletmp, $outputfile))
  814. $result = 1;
  815. else {
  816. dol_syslog(get_class($this) . "::build_exportfile failed to rename " . $outputfiletmp . " to " . $outputfile, LOG_ERR);
  817. dol_delete_file($outputfiletmp, 0, 1);
  818. $result = -1;
  819. }
  820. } else {
  821. dol_syslog(get_class($this) . "::build_exportfile build_xxxfile function fails to for format=" . $format . " outputfiletmp=" . $outputfile, LOG_ERR);
  822. dol_delete_file($outputfiletmp, 0, 1);
  823. $langs->load("errors");
  824. $this->error = $langs->trans("ErrorFailToCreateFile", $outputfile);
  825. }
  826. }
  827. return $result;
  828. }
  829. /**
  830. * Show actions
  831. *
  832. * @param int $id Object id
  833. * @param int $max Max nb of records
  834. * @return void
  835. */
  836. function show($id, $max = 5) {
  837. global $langs, $conf, $user, $db, $bc;
  838. $langs->load("agenda");
  839. $titre = $langs->trans("Actions");
  840. $h = 0;
  841. if ($user->rights->agenda->myactions->write || $user->rights->agenda->allactions->write) {
  842. $head[$h] = new stdClass();
  843. $head[$h]->href = 'agenda/fiche.php?action=create&socid=' . $id;
  844. $head[$h]->title = $langs->trans("NewAction");
  845. $head[$h]->icon = "icon-pencil";
  846. $h++;
  847. }
  848. $head[$h] = new stdClass();
  849. $head[$h]->title = $langs->trans("StatusActionToDo");
  850. $head[$h]->id = "TODO";
  851. $head[$h]->onclick = "var oTable = $('#actions_datatable').dataTable(); oTable.fnReloadAjax('" . DOL_URL_ROOT . "/core/ajax/listdatatables.php?json=actionsTODO&class=Agenda&key=" . $id . "'); return false;";
  852. $head[$h]->icon = "icon-clock";
  853. $h++;
  854. $head[$h] = new stdClass();
  855. $head[$h]->title = $langs->trans("StatusActionDone");
  856. $head[$h]->id = "DONE";
  857. $head[$h]->onclick = "var oTable = $('#actions_datatable').dataTable(); oTable.fnReloadAjax('" . DOL_URL_ROOT . "/core/ajax/listdatatables.php?json=actionsDONE&class=Agenda&key=" . $id . "'); return false;";
  858. $head[$h]->icon = "icon-calendar";
  859. $h++;
  860. print start_box($titre, "icon-calendar", $head);
  861. $i = 0;
  862. $obj = new stdClass();
  863. $societe = new Societe($this->db);
  864. /*
  865. * Barre d'actions
  866. *
  867. */
  868. //print $this->datatablesEdit("actions_datatable", $langs->trans("NewAction"));
  869. print '<table class="display dt_act" id="actions_datatable" >';
  870. // Ligne des titres
  871. print '<thead>';
  872. print'<tr>';
  873. print'<th>';
  874. print'</th>';
  875. $obj->aoColumns[$i] = new stdClass();
  876. $obj->aoColumns[$i]->mDataProp = "_id";
  877. $obj->aoColumns[$i]->bUseRendered = false;
  878. $obj->aoColumns[$i]->bSearchable = false;
  879. $obj->aoColumns[$i]->bVisible = false;
  880. $i++;
  881. print'<th class="essential">';
  882. print $langs->trans("Titre");
  883. print'</th>';
  884. $obj->aoColumns[$i] = new stdClass();
  885. $obj->aoColumns[$i]->mDataProp = "label";
  886. $obj->aoColumns[$i]->bUseRendered = false;
  887. $obj->aoColumns[$i]->bSearchable = true;
  888. $obj->aoColumns[$i]->fnRender = $this->datatablesFnRender("label", "url");
  889. $i++;
  890. print'<th class="essential">';
  891. print $langs->trans('DateEchAction');
  892. print'</th>';
  893. $obj->aoColumns[$i] = new stdClass();
  894. $obj->aoColumns[$i]->mDataProp = "datep";
  895. $obj->aoColumns[$i]->sClass = "center";
  896. $obj->aoColumns[$i]->sDefaultContent = "";
  897. $obj->aoColumns[$i]->bUseRendered = false;
  898. $obj->aoColumns[$i]->fnRender = $this->datatablesFnRender("datep", "date");
  899. $i++;
  900. print'<th class="essential">';
  901. print $langs->trans('Company');
  902. print'</th>';
  903. $obj->aoColumns[$i] = new stdClass();
  904. $obj->aoColumns[$i]->mDataProp = "societe.name";
  905. $obj->aoColumns[$i]->sDefaultContent = "";
  906. $obj->aoColumns[$i]->fnRender = $societe->datatablesFnRender("societe.name", "url", array('id' => "societe.id"));
  907. $i++;
  908. print'<th class="essential">';
  909. print $langs->trans('AffectedTo');
  910. print'</th>';
  911. $obj->aoColumns[$i] = new stdClass();
  912. $obj->aoColumns[$i]->mDataProp = "usertodo.name";
  913. $obj->aoColumns[$i]->sDefaultContent = "";
  914. $i++;
  915. print'<th class="essential">';
  916. print $langs->trans("Status");
  917. print'</th>';
  918. $obj->aoColumns[$i] = new stdClass();
  919. $obj->aoColumns[$i]->mDataProp = "Status";
  920. $obj->aoColumns[$i]->sClass = "center";
  921. $obj->aoColumns[$i]->sDefaultContent = "TODO";
  922. $obj->aoColumns[$i]->fnRender = $this->datatablesFnRender("Status", "status", array("dateEnd" => "datep"));
  923. $i++;
  924. print '</tr>';
  925. print '</thead>';
  926. print'<tfoot>';
  927. print'</tfoot>';
  928. print'<tbody>';
  929. print'</tbody>';
  930. print "</table>";
  931. $obj->iDisplayLength = $max;
  932. $obj->aaSorting = array(array(2, 'desc'));
  933. $obj->sAjaxSource = DOL_URL_ROOT . "/core/ajax/listdatatables.php?json=actionsTODO&class=" . get_class($this) . "&key=" . $id;
  934. $this->datatablesCreate($obj, "actions_datatable", true);
  935. /* foreach ($head as $aRow) {
  936. ?>
  937. <script>
  938. $(document).ready(function() {
  939. var js = "var oTable = $('#actions_datatable').dataTable(); oTable.fnReloadAjax(\"<?php echo DOL_URL_ROOT . "/core/ajax/listdatatables.php?json=actions" . $aRow->id . "&class=" . get_class($this) . "&key=" . $id; ?>\")";
  940. $("#<?php echo $aRow->id; ?>").attr("onclick", js);
  941. });
  942. </script>
  943. <?php
  944. } */
  945. print end_box();
  946. }
  947. /**
  948. * Initialise an instance with random values.
  949. * Used to build previews or test instances.
  950. * id must be 0 if object instance is a specimen.
  951. *
  952. * @return void
  953. */
  954. function initAsSpecimen() {
  955. global $user, $langs, $conf;
  956. $now = dol_now();
  957. // Initialise parametres
  958. $this->id = 0;
  959. $this->specimen = 1;
  960. $this->type_code = 'AC_OTH';
  961. $this->label = 'Label of event Specimen';
  962. $this->datec = $now;
  963. $this->datem = $now;
  964. $this->datep = $now;
  965. $this->datef = $now;
  966. $this->author = $user;
  967. $this->usermod = $user;
  968. $this->fulldayevent = 0;
  969. $this->punctual = 0;
  970. $this->percentage = 0;
  971. $this->location = 'Location';
  972. $this->priority = 'Priority X';
  973. $this->notes = 'Note';
  974. }
  975. function print_calendar($date) {
  976. global $db, $langs, $user;
  977. $date = strtotime($date);
  978. $nbDaysInMonth = date('t', $date);
  979. $firstDayTimestamp = mktime(-1, -1, -1, date('n', $date), 1, date('Y', $date));
  980. $lastDayTimestamp = mktime(23, 59, 59, date('n', $date), $nbDaysInMonth, date('Y', $date));
  981. $todayTimestamp = dol_mktime(-1, -1, -1, date('n'), date('j'), date('Y'));
  982. $firstDayOfMonth = date('w', $firstDayTimestamp);
  983. $object = new Agenda($db);
  984. //if($user->right->)
  985. if ($user->rights->agenda->allactions->read)
  986. $events = $object->getView("calendarTasks", array("startkey" => array(intval(date('Y', $date)), intval(date('m', $date)), 0, 0, 0), "endkey" => array(intval(date('Y', $date)), intval(date('m', $date)), 100, 100, 100)));
  987. else
  988. $events = $object->getView("calendarMyTasks", array("startkey" => array($user->id, intval(date('Y', $date)), intval(date('m', $date)), 0, 0, 0), "endkey" => array($user->id, intval(date('Y', $date)), intval(date('m', $date)), 100, 100, 100)));
  989. print '<table class="calendar fluid with-events large-margin-bottom with-events">';
  990. // Month an scroll arrows
  991. print '<caption>';
  992. print '<a class="cal-prev" href="' . $_SERVER["PHP_SELF"] . '?date=' . mktime(0, 0, 0, date('n', $date) - 1, 1, date('Y', $date)) . '">â—„</a>';
  993. print '<a class="cal-next" href="' . $_SERVER["PHP_SELF"] . '?date=' . mktime(0, 0, 0, date('n', $date) + 1, 1, date('Y', $date)) . '">â–º</a>';
  994. print $langs->trans(date('F', $date)) . ' ' . date('Y', $date);
  995. print '</caption>';
  996. // Days names
  997. print '<thead>';
  998. print '<tr>';
  999. print '<th scope="col">' . $langs->trans('MondayMin') . '</th>';
  1000. print '<th scope="col">' . $langs->trans('TuesdayMin') . '</th>';
  1001. print '<th scope="col">' . $langs->trans('WednesdayMin') . '</th>';
  1002. print '<th scope="col">' . $langs->trans('ThursdayMin') . '</th>';
  1003. print '<th scope="col">' . $langs->trans('FridayMin') . '</th>';
  1004. print '<th scope="col">' . $langs->trans('SaturdayMin') . '</th>';
  1005. print '<th scope="col">' . $langs->trans('SundayMin') . '</th>';
  1006. print '</tr>';
  1007. print '</thead>';
  1008. print '<tbody>';
  1009. print '<tr>';
  1010. $calendarCounter = 1;
  1011. for ($i = $firstDayOfMonth; $i > 0; $i--, $calendarCounter++) {
  1012. $previousTimestamp = strtotime($i . " day ago", $firstDayTimestamp);
  1013. print '<td class="prev-month"><span class="cal-day">' . date('d', $previousTimestamp) . '</span></td>';
  1014. }
  1015. //$cursor = 0;
  1016. for ($i = 1; $i <= $nbDaysInMonth; $i++, $calendarCounter++) {
  1017. $dayTimestamp = dol_mktime(-1, -1, -1, date('n', $date), $i, date('Y', $date));
  1018. if ($calendarCounter > 1 && ($calendarCounter - 1) % 7 == 0)
  1019. print '</tr><tr>';
  1020. print '<td class="' . ((date('w', $dayTimestamp) == 0 || date('w', $dayTimestamp) == 6) ? 'week-end ' : '') . ' ' . (($dayTimestamp == $todayTimestamp) ? 'today ' : '') . '"><span class="cal-day">' . $i . '</span>';
  1021. print '<ul class="cal-events">';
  1022. //if (!empty($events->rows[$cursor])) {
  1023. for ($j = 0; $j < count($events->rows); $j++) {
  1024. if ($events->rows[$j]->key[3 - $user->rights->agenda->allactions->read] == $i) {
  1025. $user_tmp = new User();
  1026. $user_tmp->id = $events->rows[$j]->value->usertodo->id;
  1027. $user_tmp->name = $events->rows[$j]->value->usertodo->name;
  1028. print '<li ' . ($events->rows[$j]->value->usertodo->id == $user->id ? 'class="important"' : "") . '><a href="agenda/fiche.php?id=' . $events->rows[$j]->id . '" >' . "[" . $events->rows[$j]->value->societe->name . "] " . $events->rows[$j]->value->label . ($events->rows[$j]->value->usertodo->id != $user->id ? '<br><i>' . $user_tmp->getNomUrl(1) . '</i>' : '') . '</a></li>';
  1029. }
  1030. }
  1031. //}
  1032. print '</ul>';
  1033. print '</td>';
  1034. }
  1035. $calendarCounter--;
  1036. $i = 1;
  1037. while ($calendarCounter++ % 7 != 0) {
  1038. print '<td class="next-month"><span class="cal-day">' . $i++ . '</span></td>';
  1039. }
  1040. print '</tr>';
  1041. print '</tbody>';
  1042. print '</table>';
  1043. }
  1044. function print_week($date) {
  1045. global $db, $langs, $user;
  1046. //$timestamps = array();
  1047. $date = strtotime($date);
  1048. //$dayOfWeek = date('w', $date);
  1049. /* for ($i = 0, $d = -$dayOfWeek; $i < 7; $i++, $d++) {
  1050. $tmpTimestamp = strtotime($d . " day", $date);
  1051. $timestamps[$i] = array(
  1052. 'start' => mktime(0, 0, 0, date('n', $tmpTimestamp), date('j', $tmpTimestamp), date('Y', $tmpTimestamp)),
  1053. 'end' => mktime(23, 59, 59, date('n', $tmpTimestamp), date('j', $tmpTimestamp), date('Y', $tmpTimestamp)),
  1054. );
  1055. } */
  1056. //print date('j', strtotime(-date('w', $date)+1 . " day", $date));
  1057. $object = new Agenda($db);
  1058. $events = $object->getView("calendarMyTasks", array("startkey" => array($user->id, intval(date('Y', $date)), intval(date('m', $date)), 0, 0, 0), "endkey" => array($user->id, intval(date('Y', $date)), intval(date('m', $date)), 100, 100, 100)));
  1059. //print_r($events);
  1060. $styles = array(
  1061. 0 => 'left: 0%; right: 85.7143%; margin-left: -1px;',
  1062. 1 => 'left: 14.2857%; right: 71.4286%; margin-left: 0px;',
  1063. 2 => 'left: 28.5714%; right: 57.1429%; margin-left: 0px;',
  1064. 3 => 'left: 42.8571%; right: 42.8571%; margin-left: 0px;',
  1065. 4 => 'left: 57.1429%; right: 28.5714%; margin-left: 0px;',
  1066. 5 => 'left: 71.4286%; right: 14.2857%; margin-left: 0px;',
  1067. 6 => 'left: 85.7143%; right: 0%; margin-left: 0px;'
  1068. );
  1069. $days = array(
  1070. 0 => 'Sunday',
  1071. 1 => 'Monday',
  1072. 2 => 'Tuesday',
  1073. 3 => 'Wednesday',
  1074. 4 => 'Thursday',
  1075. 5 => 'Friday',
  1076. 6 => 'Saturday'
  1077. );
  1078. $first = date('j', $date) - date('j', strtotime(-date('w', $date) . " day", $date));
  1079. print '<div class="block">
  1080. <div class="block-title">
  1081. <h3 id="agenda-day">Tuesday</h3>
  1082. <div class="button-group absolute-right compact">
  1083. <a href="#" class="button" id="agenda-previous"><span class="icon-left-fat"></span></a>
  1084. <a href="#" class="button" id="agenda-today">' . $langs->trans("Today") . '</a>
  1085. <a href="#" class="button" id="agenda-next"><span class="icon-right-fat"></span></a>
  1086. </div>
  1087. </div>';
  1088. print '<div class="agenda" id="agenda">';
  1089. print '<ul class="agenda-time">
  1090. <li class="from-7 to-8"><span>7 AM</span></li>
  1091. <li class="from-8 to-9"><span>8 AM</span></li>
  1092. <li class="from-9 to-10"><span>9 AM</span></li>
  1093. <li class="from-10 to-11"><span>10 AM</span></li>
  1094. <li class="from-11 to-12"><span>11 AM</span></li>
  1095. <li class="from-12 to-13 blue"><span>12 AM</span></li>
  1096. <li class="from-13 to-14"><span>1 PM</span></li>
  1097. <li class="from-14 to-15"><span>2 PM</span></li>
  1098. <li class="from-15 to-16"><span>3 PM</span></li>
  1099. <li class="from-16 to-17"><span>4 PM</span></li>
  1100. <li class="from-17 to-18"><span>5 PM</span></li>
  1101. <li class="from-18 to-19"><span>6 PM</span></li>
  1102. <li class="from-19 to-20"><span>7 PM</span></li>
  1103. <li class="at-20"><span>8 PM</span></li>
  1104. </ul>';
  1105. print '<div class="agenda-wrapper">';
  1106. //$cursor = 0;
  1107. for ($i = 0; $i < 7; $i++) {
  1108. $extraClass = '';
  1109. //if ($i == 0)
  1110. // $extraClass = 'agenda-visible-first';
  1111. //else if ($i == 6)
  1112. // $extraClass = 'agenda-visible-last';
  1113. print '<div class="agenda-events agenda-day' . ($i + 1) . '" style="' . $styles[$i] . '">';
  1114. print '<div class="agenda-header">';
  1115. print $langs->trans($days[$i]);
  1116. print '</div>';
  1117. //if (!empty($events->rows[$cursor])) {
  1118. for ($j = 0; $j < count($events->rows); $j++) {
  1119. if ($events->rows[$j]->key[3] == date('j', strtotime(-date('w', $date) . " day", $date)) + $i) {
  1120. //$dateStart = $events->rows[$j]->value->datep;
  1121. //$dateEnd = $events->rows[$j]->value->datef;
  1122. //if ($events->rows[$j]->value->type_code != 'AC_RDV')
  1123. // $dateEnd = $dateStart + $events->rows[$j]->value->durationp;
  1124. $hourStart = $events->rows[$j]->key[4];
  1125. if ($events->rows[$j]->value->type_code != 'AC_RDV')
  1126. $hourEnd = $events->rows[$j]->key[4] + $events->rows[$j]->value->durationp / 3600;
  1127. else
  1128. $hourEnd = date('G', strtotime($events->rows[$j]->value->datef) + 1);
  1129. print '<a class="agenda-event from-' . $hourStart . ' to-' . $hourEnd . ($events->rows[$j]->value->usertodo->id == $user->id ? ' red-gradient' : '') . '" href="agenda/fiche.php?id=' . $events->rows[$j]->id . '">';
  1130. print '<time>' . $hourStart . 'h - ' . $hourEnd . 'h</time>';
  1131. if (isset($events->rows[$j]->value->societe->name))
  1132. print "[" . $events->rows[$j]->value->societe->name . "] ";
  1133. print $events->rows[$j]->value->label;
  1134. if ($events->rows[$j]->value->usertodo->id != $user->id) {
  1135. $user_tmp = new User();
  1136. $user_tmp->id = $events->rows[$j]->value->usertodo->id;
  1137. $user_tmp->name = $events->rows[$j]->value->usertodo->name;
  1138. print '<br><i>' . $user_tmp->getNomUrl(1, 'span') . '</i>';
  1139. }
  1140. print '</a>';
  1141. }
  1142. //else
  1143. // break;
  1144. }
  1145. //}
  1146. print '</div>';
  1147. }
  1148. print '</div>';
  1149. print '</div>';
  1150. ?>
  1151. <script>
  1152. $(document).ready(function() {
  1153. // Days
  1154. var daysName = ['<?php echo $langs->trans('Sunday'); ?>', '<?php echo $langs->trans('Monday'); ?>', '<?php echo $langs->trans('Tuesday'); ?>', '<?php echo $langs->trans('Wednesday'); ?>', '<?php echo $langs->trans('Thursday'); ?>', '<?php echo $langs->trans('Friday'); ?>', '<?php echo $langs->trans('Saturday'); ?>'],
  1155. // Name display
  1156. agendaDay = $('#agenda-day'),
  1157. // Agenda scrolling
  1158. agenda = $('#agenda').scrollAgenda({
  1159. first: <?php echo $first; ?>,
  1160. onRangeChange: function(start, end)
  1161. {
  1162. if (start != end)
  1163. {
  1164. agendaDay.text(daysName[start].substr(0, 3) + ' - ' + daysName[end].substr(0, 3));
  1165. }
  1166. else
  1167. {
  1168. agendaDay.text(daysName[start]);
  1169. }
  1170. }
  1171. });
  1172. // Remote controls
  1173. $('#agenda-previous').click(function(event)
  1174. {
  1175. event.preventDefault();
  1176. agenda.scrollAgendaToPrevious();
  1177. });
  1178. $('#agenda-today').click(function(event)
  1179. {
  1180. event.preventDefault();
  1181. agenda.scrollAgendaFirstColumn(<?php echo $first; ?>);
  1182. });
  1183. $('#agenda-next').click(function(event)
  1184. {
  1185. event.preventDefault();
  1186. agenda.scrollAgendaToNext();
  1187. });
  1188. });
  1189. </script>
  1190. <?php
  1191. }
  1192. /*
  1193. * Graph Eisenhower matrix
  1194. *
  1195. */
  1196. function graphEisenhower($json = false) {
  1197. global $user, $conf, $langs;
  1198. $langs->load("companies");
  1199. if ($json) {
  1200. // For Data see viewgraph.php
  1201. $params = array('startkey' => array($user->id, date("c", mktime(0, 0, 0, date("m") - 1, date("d"), date("Y")))),
  1202. 'endkey' => array($user->id, date("c", mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")))));
  1203. $result = $this->getView("list" . $_GET["name"], $params);
  1204. //error_log(print_r($result,true));
  1205. $output = array();
  1206. if (count($result->rows))
  1207. foreach ($result->rows as $aRow) {
  1208. $type_code = $aRow->value->type_code;
  1209. $priority = $this->fk_extrafields->fields->type_code->values->$type_code->priority;
  1210. $obj = new stdClass();
  1211. $obj->x = strtotime($aRow->value->datep) * 1000;
  1212. $obj->y = $priority;
  1213. $obj->name = $aRow->value->label;
  1214. $obj->id = $aRow->value->_id;
  1215. if (!isset($aRow->value->societe->name))
  1216. $obj->soc = $langs->trans("None");
  1217. else
  1218. $obj->soc = $aRow->value->societe->name;
  1219. $obj->usertodo = $aRow->value->usertodo->name;
  1220. $output[] = clone $obj;
  1221. }
  1222. return $output;
  1223. } else {
  1224. $total = 0;
  1225. $i = 0;
  1226. ?>
  1227. <div id="eisenhower" style="min-width: 100px; height: 280px; margin: 0 auto"></div>
  1228. <script type="text/javascript">
  1229. $(document).ready(function() {
  1230. (function($) { // encapsulate jQuery
  1231. $(function() {
  1232. var seriesOptions = [],
  1233. yAxisOptions = [],
  1234. seriesCounter = 0,
  1235. names = ['MyTasks', 'MyDelegatedTasks'],
  1236. colors = Highcharts.getOptions().colors;
  1237. var translate = [];
  1238. translate['MyTasks'] = "<?php echo $langs->trans('MyTasks'); ?>";
  1239. translate['MyDelegatedTasks'] = "<?php echo $langs->trans('MyDelegatedTasks'); ?>";
  1240. $.each(names, function(i, name) {
  1241. $.getJSON('<?php echo DOL_URL_ROOT . '/core/ajax/viewgraph.php'; ?>?json=graphEisenhower&class=<?php echo get_class($this); ?>&name=' + name.toString() + '&callback=?', function(data) {
  1242. seriesOptions[i] = {
  1243. type: 'scatter',
  1244. name: translate[name],
  1245. data: data
  1246. };
  1247. // As we're loading the data asynchronously, we don't…

Large files files are truncated, but you can click here to view the full file