PageRenderTime 79ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/agenda/index.old.php

https://bitbucket.org/speedealing/speedealing
PHP | 1164 lines | 885 code | 116 blank | 163 comment | 270 complexity | e552204f84de3d1f68b07a92c3c48735 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) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2010-2011 Herve Prot <herve.prot@symeos.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/comm/action/index.php
  24. * \ingroup agenda
  25. * \brief Home page of calendar events
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  33. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  34. if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
  35. $filter=GETPOST("filter",'',3);
  36. $filtera = GETPOST("userasked","int",3)?GETPOST("userasked","int",3):GETPOST("filtera","int",3);
  37. $filtert = GETPOST("usertodo","int",3)?GETPOST("usertodo","int",3):GETPOST("filtert","int",3);
  38. $filterd = GETPOST("userdone","int",3)?GETPOST("userdone","int",3):GETPOST("filterd","int",3);
  39. $showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
  40. $sortfield = GETPOST("sortfield",'alpha');
  41. $sortorder = GETPOST("sortorder",'alpha');
  42. $page = GETPOST("page","int");
  43. if ($page == -1) { $page = 0; }
  44. $limit = $conf->liste_limit;
  45. $offset = $limit * $page;
  46. if (! $sortorder) $sortorder="ASC";
  47. if (! $sortfield) $sortfield="a.datec";
  48. // Security check
  49. $socid = GETPOST("socid","int",1);
  50. if ($user->societe_id) $socid=$user->societe_id;
  51. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  52. $canedit=1;
  53. if (! $user->rights->agenda->myactions->read) accessforbidden();
  54. if (! $user->rights->agenda->allactions->read) $canedit=0;
  55. if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no permission to see all, we show only affected to me
  56. {
  57. $filtera=$user->id;
  58. $filtert=$user->id;
  59. $filterd=$user->id;
  60. }
  61. $action=GETPOST('action','alpha');
  62. //$year=GETPOST("year");
  63. $year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
  64. $month=GETPOST("month","int")?GETPOST("month","int"):date("m");
  65. $week=GETPOST("week","int")?GETPOST("week","int"):date("W");
  66. $day=GETPOST("day","int")?GETPOST("day","int"):0;
  67. $actioncode=GETPOST("actioncode","alpha",3);
  68. $pid=GETPOST("projectid","int",3);
  69. $status=GETPOST("status");
  70. $type=GETPOST("type");
  71. $maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
  72. if (GETPOST('viewcal')) {
  73. $action='show_month'; $day='';
  74. } // View by month
  75. if (GETPOST('viewweek')) {
  76. $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d"));
  77. } // View by week
  78. if (GETPOST('viewday')) {
  79. $action='show_day'; $day=($day?$day:date("d"));
  80. } // View by day
  81. $langs->load("other");
  82. $langs->load("commercial");
  83. /*
  84. * Actions
  85. */
  86. if (GETPOST("viewlist"))
  87. {
  88. $param='';
  89. foreach($_POST as $key => $val)
  90. {
  91. if ($key=='token') continue;
  92. $param.='&'.$key.'='.urlencode($val);
  93. }
  94. //print $param;
  95. header("Location: ".DOL_URL_ROOT.'/comm/action/listactions.php?'.$param);
  96. exit;
  97. }
  98. if ($action=='delete_action')
  99. {
  100. $event = new ActionComm($db);
  101. $event->fetch($actionid);
  102. $result=$event->delete();
  103. }
  104. /*
  105. * View
  106. */
  107. llxHeader('',$langs->trans("Agenda"));
  108. $form=new Form($db);
  109. $companystatic=new Societe($db);
  110. $contactstatic=new Contact($db);
  111. $now=dol_now();
  112. // Define list of all external calendars
  113. $listofextcals=array();
  114. if (empty($conf->global->AGENDA_DISABLE_EXT) && $conf->global->AGENDA_EXT_NB > 0)
  115. {
  116. $i=0;
  117. while($i < $conf->global->AGENDA_EXT_NB)
  118. {
  119. $i++;
  120. $source='AGENDA_EXT_SRC'.$i;
  121. $name='AGENDA_EXT_NAME'.$i;
  122. $color='AGENDA_EXT_COLOR'.$i;
  123. if (! empty($conf->global->$source) && ! empty($conf->global->$name))
  124. {
  125. $listofextcals[]=array('src'=>$conf->global->$source,'name'=>$conf->global->$name,'color'=>$conf->global->$color);
  126. }
  127. }
  128. }
  129. if (empty($action) || $action=='show_month')
  130. {
  131. $prev = dol_get_prev_month($month, $year);
  132. $prev_year = $prev['year'];
  133. $prev_month = $prev['month'];
  134. $next = dol_get_next_month($month, $year);
  135. $next_year = $next['year'];
  136. $next_month = $next['month'];
  137. $max_day_in_prev_month = date("t",dol_mktime(0,0,0,$prev_month,1,$prev_year)); // Nb of days in previous month
  138. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year)); // Nb of days in next month
  139. // tmpday is a negative or null cursor to know how many days before the 1 to show on month view (if tmpday=0 we start on monday)
  140. $tmpday = -date("w",dol_mktime(0,0,0,$month,1,$year))+2;
  141. $tmpday+=((isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)-1);
  142. if ($tmpday >= 1) $tmpday -= 7;
  143. // Define firstdaytoshow and lastdaytoshow
  144. $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$prev_year);
  145. $next_day=7-($max_day_in_month+1-$tmpday)%7;
  146. if ($next_day < 6) $next_day+=7;
  147. $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
  148. }
  149. if ($action=='show_week')
  150. {
  151. $prev = dol_get_first_day_week($day, $month, $year);
  152. $prev_year = $prev['prev_year'];
  153. $prev_month = $prev['prev_month'];
  154. $prev_day = $prev['prev_day'];
  155. $first_day = $prev['first_day'];
  156. $week = $prev['week'];
  157. $day = (int) $day;
  158. $next = dol_get_next_week($day, $week, $month, $year);
  159. $next_year = $next['year'];
  160. $next_month = $next['month'];
  161. $next_day = $next['day'];
  162. // Define firstdaytoshow and lastdaytoshow
  163. $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$first_day,$prev_year);
  164. $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
  165. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
  166. $tmpday = $first_day;
  167. }
  168. if ($action == 'show_day')
  169. {
  170. $prev = dol_get_prev_day($day, $month, $year);
  171. $prev_year = $prev['year'];
  172. $prev_month = $prev['month'];
  173. $prev_day = $prev['day'];
  174. $next = dol_get_next_day($day, $month, $year);
  175. $next_year = $next['year'];
  176. $next_month = $next['month'];
  177. $next_day = $next['day'];
  178. // Define firstdaytoshow and lastdaytoshow
  179. $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$prev_day,$prev_year);
  180. $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
  181. }
  182. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  183. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  184. //print dol_print_date($firstdaytoshow,'day');
  185. //print dol_print_date($lastdaytoshow,'day');
  186. $title=$langs->trans("DoneAndToDoActions");
  187. if ($status == 'done') $title=$langs->trans("DoneActions");
  188. if ($status == 'todo') $title=$langs->trans("ToDoActions");
  189. $param='';
  190. $region='';
  191. if ($status) $param="&status=".$status;
  192. if ($filter) $param.="&filter=".$filter;
  193. if ($filtera) $param.="&filtera=".$filtera;
  194. if ($filtert) $param.="&filtert=".$filtert;
  195. if ($filterd) $param.="&filterd=".$filterd;
  196. if ($socid) $param.="&socid=".$socid;
  197. if ($showbirthday) $param.="&showbirthday=1";
  198. if ($pid) $param.="&projectid=".$pid;
  199. if ($actioncode) $param.="&actioncode=".$actioncode;
  200. if ($type) $param.="&type=".$type;
  201. if ($action == 'show_day' || $action == 'show_week') $param.='&action='.$action;
  202. $param.="&maxprint=".$maxprint;
  203. // Show navigation bar
  204. if (empty($action) || $action=='show_month')
  205. {
  206. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;region=".$region.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
  207. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%b %Y");
  208. $nav.=" </span>\n";
  209. $nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;region=".$region.$param."\">".img_next($langs->trans("Next"))."</a>\n";
  210. $picto='calendar';
  211. }
  212. if ($action=='show_week')
  213. {
  214. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day."&amp;region=".$region.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
  215. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%Y").", ".$langs->trans("Week")." ".$week;
  216. $nav.=" </span>\n";
  217. $nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day."&amp;region=".$region.$param."\">".img_next($langs->trans("Next"))."</a>\n";
  218. $picto='calendarweek';
  219. }
  220. if ($action=='show_day')
  221. {
  222. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day."&amp;region=".$region.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
  223. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,$day,$year),"daytextshort");
  224. $nav.=" </span>\n";
  225. $nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day."&amp;region=".$region.$param."\">".img_next($langs->trans("Next"))."</a>\n";
  226. $picto='calendarday';
  227. }
  228. // Must be after the nav definition
  229. $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
  230. //print 'x'.$param;
  231. $head = calendars_prepare_head('');
  232. dol_fiche_head($head, 'card', $langs->trans('Events'), 0, $picto);
  233. print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,$filtera,$filtert,$filterd,$pid,$socid,$listofextcals);
  234. dol_fiche_end();
  235. $link='';
  236. // Add link to show birthdays
  237. if (empty($conf->use_javascript_ajax))
  238. {
  239. $newparam=$param; // newparam is for birthday links
  240. $newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
  241. if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1';
  242. $link='<a href="'.$_SERVER['PHP_SELF'];
  243. $link.='?'.$newparam;
  244. $link.='">';
  245. if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents");
  246. else $link.=$langs->trans("AgendaHideBirthdayEvents");
  247. $link.='</a>';
  248. }
  249. print_fiche_titre($title,$link.' &nbsp; &nbsp; '.$nav, '');
  250. // Get event in an array
  251. $eventarray=array();
  252. $sql = 'SELECT a.id,a.label,';
  253. $sql.= ' a.datep,';
  254. $sql.= ' a.datep2,';
  255. $sql.= ' a.datea,';
  256. $sql.= ' a.datea2,';
  257. $sql.= ' a.percent,';
  258. $sql.= ' a.fk_user_author,a.fk_user_action,a.fk_user_done,';
  259. $sql.= ' a.priority, a.fulldayevent, a.location,';
  260. $sql.= ' a.fk_soc, a.fk_contact,';
  261. $sql.= ' ca.code';
  262. $sql.= ' FROM ('.MAIN_DB_PREFIX.'c_actioncomm as ca,';
  263. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  264. $sql.= " ".MAIN_DB_PREFIX.'user as u,';
  265. $sql.= " ".MAIN_DB_PREFIX."actioncomm as a)";
  266. $sql.= ' WHERE a.fk_action = ca.id';
  267. $sql.= ' AND a.fk_user_author = u.rowid';
  268. $sql.= ' AND a.entity IN ('.getEntity().')';
  269. if ($actioncode) $sql.=" AND ca.code='".$db->escape($actioncode)."'";
  270. if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
  271. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND a.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
  272. if ($user->societe_id) $sql.= ' AND a.fk_soc = '.$user->societe_id; // To limit to external user company
  273. if ($action == 'show_day')
  274. {
  275. $sql.= " AND (";
  276. $sql.= " (datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  277. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  278. $sql.= " OR ";
  279. $sql.= " (datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  280. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  281. $sql.= " OR ";
  282. $sql.= " (datep < '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  283. $sql.= " AND datep2 > '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  284. $sql.= ')';
  285. }
  286. else
  287. {
  288. // To limit array
  289. $sql.= " AND (";
  290. $sql.= " (datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'"; // Start 7 days before
  291. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')"; // End 7 days after + 3 to go from 28 to 31
  292. $sql.= " OR ";
  293. $sql.= " (datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
  294. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
  295. $sql.= " OR ";
  296. $sql.= " (datep < '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
  297. $sql.= " AND datep2 > '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
  298. $sql.= ')';
  299. }
  300. if ($type) $sql.= " AND ca.id = ".$type;
  301. if ($status == 'done') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; }
  302. if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; }
  303. if ($filtera > 0 || $filtert > 0 || $filterd > 0)
  304. {
  305. $sql.= " AND (";
  306. if ($filtera > 0) $sql.= " a.fk_user_author = ".$filtera;
  307. if ($filtert > 0) $sql.= ($filtera>0?" OR ":"")." a.fk_user_action = ".$filtert;
  308. if ($filterd > 0) $sql.= ($filtera>0||$filtert>0?" OR ":"")." a.fk_user_done = ".$filterd;
  309. $sql.= ")";
  310. }
  311. // Sort on date
  312. $sql.= ' ORDER BY datep';
  313. //print $sql;
  314. dol_syslog("comm/action/index.php sql=".$sql, LOG_DEBUG);
  315. $resql=$db->query($sql);
  316. if ($resql)
  317. {
  318. $num = $db->num_rows($resql);
  319. $i=0;
  320. while ($i < $num)
  321. {
  322. $obj = $db->fetch_object($resql);
  323. // Create a new object action
  324. $event=new ActionComm($db);
  325. $event->id=$obj->id;
  326. $event->datep=$db->jdate($obj->datep); // datep and datef are GMT date
  327. $event->datef=$db->jdate($obj->datep2);
  328. $event->type_code=$obj->code;
  329. $event->libelle=$obj->label;
  330. $event->percentage=$obj->percent;
  331. $event->author->id=$obj->fk_user_author;
  332. $event->usertodo->id=$obj->fk_user_action;
  333. $event->userdone->id=$obj->fk_user_done;
  334. $event->priority=$obj->priority;
  335. $event->fulldayevent=$obj->fulldayevent;
  336. $event->location=$obj->location;
  337. $event->societe->id=$obj->fk_soc;
  338. $event->contact->id=$obj->fk_contact;
  339. // Defined date_start_in_calendar and date_end_in_calendar property
  340. // They are date start and end of action but modified to not be outside calendar view.
  341. if ($event->percentage <= 0)
  342. {
  343. $event->date_start_in_calendar=$event->datep;
  344. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  345. else $event->date_end_in_calendar=$event->datep;
  346. }
  347. else
  348. {
  349. $event->date_start_in_calendar=$event->datep;
  350. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  351. else $event->date_end_in_calendar=$event->datep;
  352. }
  353. // Define ponctual property
  354. if ($event->date_start_in_calendar == $event->date_end_in_calendar)
  355. {
  356. $event->ponctuel=1;
  357. }
  358. // Check values
  359. if ($event->date_end_in_calendar < $firstdaytoshow ||
  360. $event->date_start_in_calendar > $lastdaytoshow)
  361. {
  362. // This record is out of visible range
  363. }
  364. else
  365. {
  366. if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  367. if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow;
  368. // Add an entry in actionarray for each day
  369. $daycursor=$event->date_start_in_calendar;
  370. $annee = date('Y',$daycursor);
  371. $mois = date('m',$daycursor);
  372. $jour = date('d',$daycursor);
  373. // Loop on each day covered by action to prepare an index to show on calendar
  374. $loop=true; $j=0;
  375. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  376. do
  377. {
  378. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  379. $eventarray[$daykey][]=$event;
  380. $j++;
  381. $daykey+=60*60*24;
  382. if ($daykey > $event->date_end_in_calendar) $loop=false;
  383. }
  384. while ($loop);
  385. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  386. //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
  387. }
  388. $i++;
  389. }
  390. }
  391. else
  392. {
  393. dol_print_error($db);
  394. }
  395. if ($showbirthday)
  396. {
  397. // Add events in array
  398. $sql = 'SELECT sp.rowid, sp.name, sp.firstname, sp.birthday';
  399. $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
  400. $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
  401. $sql.= " AND sp.entity IN (".getEntity('societe', 1).")";
  402. if ($action == 'show_day')
  403. {
  404. $sql.= ' AND MONTH(birthday) = '.$month;
  405. $sql.= ' AND DAY(birthday) = '.$day;
  406. }
  407. else
  408. {
  409. $sql.= ' AND MONTH(birthday) = '.$month;
  410. }
  411. $sql.= ' ORDER BY birthday';
  412. dol_syslog("comm/action/index.php sql=".$sql, LOG_DEBUG);
  413. $resql=$db->query($sql);
  414. if ($resql)
  415. {
  416. $num = $db->num_rows($resql);
  417. $i=0;
  418. while ($i < $num)
  419. {
  420. $obj = $db->fetch_object($resql);
  421. $event=new ActionComm($db);
  422. $event->id=$obj->rowid; // We put contact id in action id for birthdays events
  423. $datebirth=dol_stringtotime($obj->birthday,1);
  424. //print 'ee'.$obj->birthday.'-'.$datebirth;
  425. $datearray=dol_getdate($datebirth,true);
  426. $event->datep=dol_mktime(0,0,0,$datearray['mon'],$datearray['mday'],$year,true); // For full day events, date are also GMT but they wont but converted during output
  427. $event->datef=$event->datep;
  428. $event->type_code='BIRTHDAY';
  429. $event->libelle=$langs->trans("Birthday").' '.$obj->firstname.' '.$obj->name;
  430. $event->percentage=100;
  431. $event->fulldayevent=true;
  432. $event->date_start_in_calendar=$event->datep;
  433. $event->date_end_in_calendar=$event->datef;
  434. $event->ponctuel=0;
  435. // Add an entry in actionarray for each day
  436. $daycursor=$event->date_start_in_calendar;
  437. $annee = date('Y',$daycursor);
  438. $mois = date('m',$daycursor);
  439. $jour = date('d',$daycursor);
  440. $loop=true;
  441. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  442. do
  443. {
  444. $eventarray[$daykey][]=$event;
  445. $daykey+=60*60*24;
  446. if ($daykey > $event->date_end_in_calendar) $loop=false;
  447. }
  448. while ($loop);
  449. $i++;
  450. }
  451. }
  452. else
  453. {
  454. dol_print_error($db);
  455. }
  456. }
  457. if (count($listofextcals))
  458. {
  459. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
  460. foreach($listofextcals as $extcal)
  461. {
  462. $url=$extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
  463. $namecal = $extcal['name'];
  464. $colorcal = $extcal['color'];
  465. //print "url=".$url." namecal=".$namecal." colorcal=".$colorcal;
  466. $ical=new ICal();
  467. $ical->parse($url);
  468. // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
  469. //var_dump($ical->cal); exit;
  470. $icalevents=array();
  471. if (is_array($ical->get_event_list())) $icalevents=array_merge($icalevents,$ical->get_event_list()); // Add $ical->cal['VEVENT']
  472. if (is_array($ical->get_freebusy_list())) $icalevents=array_merge($icalevents,$ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
  473. if (count($icalevents)>0)
  474. {
  475. // Duplicate all repeatable events into new entries
  476. $moreicalevents=array();
  477. foreach($icalevents as $icalevent)
  478. {
  479. if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) //repeatable event
  480. {
  481. //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  482. //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow;
  483. if ($icalevent['DTSTART;VALUE=DATE']) //fullday event
  484. {
  485. $datecurstart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
  486. $datecurend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
  487. }
  488. else if (is_array($icalevent['DTSTART']) && ! empty($icalevent['DTSTART']['unixtime']))
  489. {
  490. $datecurstart=$icalevent['DTSTART']['unixtime'];
  491. $datecurend=$icalevent['DTEND']['unixtime'];
  492. if (! empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart)
  493. {
  494. //var_dump($ical->cal);
  495. $tmpcurstart=$datecurstart;
  496. $tmpcurend=$datecurend;
  497. $tmpdaylightstart=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
  498. $tmpdaylightend=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['STANDARD']['DTSTART'];
  499. //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
  500. // Edit datecurstart and datecurend
  501. if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurstart-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
  502. else $datecurstart-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
  503. if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurend-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
  504. else $datecurend-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
  505. }
  506. // datecurstart and datecurend are now GMT date
  507. //var_dump($datecurstart); var_dump($datecurend); exit;
  508. }
  509. else
  510. {
  511. // Not a recongized record
  512. dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
  513. continue;
  514. }
  515. //print 'xx'.$datecurstart;exit;
  516. $interval=(empty($icalevent['RRULE']['INTERVAL'])?1:$icalevent['RRULE']['INTERVAL']);
  517. $until=empty($icalevent['RRULE']['UNTIL'])?0:dol_stringtotime($icalevent['RRULE']['UNTIL'],1);
  518. $maxrepeat=empty($icalevent['RRULE']['COUNT'])?0:$icalevent['RRULE']['COUNT'];
  519. if ($until && ($until+($datecurend-$datecurstart)) < $firstdaytoshow) continue; // We discard repeatable event that end before start date to show
  520. if ($datecurstart > $lastdaytoshow) continue; // We discard repeatable event that start after end date to show
  521. $numofevent=0;
  522. while (($datecurstart <= $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)))
  523. {
  524. if ($datecurend >= $firstdaytoshow) // We add event
  525. {
  526. $newevent=$icalevent;
  527. unset($newevent['RRULE']);
  528. if ($icalevent['DTSTART;VALUE=DATE'])
  529. {
  530. $newevent['DTSTART;VALUE=DATE']=dol_print_date($datecurstart,'%Y%m%d');
  531. $newevent['DTEND;VALUE=DATE']=dol_print_date($datecurend+1,'%Y%m%d');
  532. }
  533. else
  534. {
  535. $newevent['DTSTART']=$datecurstart;
  536. $newevent['DTEND']=$datecurend;
  537. }
  538. $moreicalevents[]=$newevent;
  539. }
  540. // Jump on next occurence
  541. $numofevent++;
  542. $savdatecurstart=$datecurstart;
  543. if ($icalevent['RRULE']['FREQ']=='DAILY')
  544. {
  545. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'd');
  546. $datecurend=dol_time_plus_duree($datecurend, $interval, 'd');
  547. }
  548. if ($icalevent['RRULE']['FREQ']=='WEEKLY')
  549. {
  550. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'w');
  551. $datecurend=dol_time_plus_duree($datecurend, $interval, 'w');
  552. }
  553. elseif ($icalevent['RRULE']['FREQ']=='MONTHLY')
  554. {
  555. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'm');
  556. $datecurend=dol_time_plus_duree($datecurend, $interval, 'm');
  557. }
  558. elseif ($icalevent['RRULE']['FREQ']=='YEARLY')
  559. {
  560. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'y');
  561. $datecurend=dol_time_plus_duree($datecurend, $interval, 'y');
  562. }
  563. // Test to avoid infinite loop ($datecurstart must increase)
  564. if ($savdatecurstart >= $datecurstart)
  565. {
  566. dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
  567. $datecurstart+=3600*24*7;
  568. $datecurend+=3600*24*7;
  569. }
  570. }
  571. }
  572. }
  573. $icalevents=array_merge($icalevents,$moreicalevents);
  574. // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
  575. foreach($icalevents as $icalevent)
  576. {
  577. //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
  578. if (! empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
  579. // Create a new object action
  580. $event=new ActionComm($db);
  581. $addevent = false;
  582. if (isset($icalevent['DTSTART;VALUE=DATE'])) // fullday event
  583. {
  584. // For full day events, date are also GMT but they wont but converted using tz during output
  585. $datestart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
  586. $dateend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
  587. //print 'x'.$datestart.'-'.$dateend;exit;
  588. //print dol_print_date($dateend,'dayhour','gmt');
  589. $event->fulldayevent=true;
  590. $addevent=true;
  591. }
  592. elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array)
  593. {
  594. $datestart=$icalevent['DTSTART'];
  595. $dateend=$icalevent['DTEND'];
  596. $addevent=true;
  597. }
  598. if ($addevent)
  599. {
  600. $event->id=$icalevent['UID'];
  601. $event->icalname=$namecal;
  602. $event->icalcolor=$colorcal;
  603. $usertime=0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
  604. $event->datep=$datestart+$usertime;
  605. $event->datef=$dateend+$usertime;
  606. $event->type_code="ICALEVENT";
  607. if($icalevent['SUMMARY']) $event->libelle=$icalevent['SUMMARY'];
  608. elseif($icalevent['DESCRIPTION']) $event->libelle=dol_nl2br($icalevent['DESCRIPTION'],1);
  609. else $event->libelle = $langs->trans("ExtSiteNoLabel");
  610. $event->date_start_in_calendar=$event->datep;
  611. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  612. else $event->date_end_in_calendar=$event->datep;
  613. // Define ponctual property
  614. if ($event->date_start_in_calendar == $event->date_end_in_calendar)
  615. {
  616. $event->ponctuel=1;
  617. //print 'x'.$datestart.'-'.$dateend;exit;
  618. }
  619. // Add event into $eventarray if date range are ok.
  620. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar > $lastdaytoshow)
  621. {
  622. //print 'x'.$datestart.'-'.$dateend;exit;
  623. //print 'x'.$datestart.'-'.$dateend;exit;
  624. //print 'x'.$datestart.'-'.$dateend;exit;
  625. // This record is out of visible range
  626. }
  627. else
  628. {
  629. if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  630. if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow;
  631. // Add an entry in actionarray for each day
  632. $daycursor=$event->date_start_in_calendar;
  633. $annee = date('Y',$daycursor);
  634. $mois = date('m',$daycursor);
  635. $jour = date('d',$daycursor);
  636. // Loop on each day covered by action to prepare an index to show on calendar
  637. $loop=true; $j=0;
  638. // daykey must be date that represent day box in calendar so must be a user time
  639. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  640. $daykeygmt=dol_mktime(0,0,0,$mois,$jour,$annee,true,0);
  641. do
  642. //print 'x'.$datestart.'-'.$dateend;exit;
  643. {
  644. //if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
  645. $eventarray[$daykey][]=$event;
  646. $daykey+=60*60*24; $daykeygmt+=60*60*24; // Add one day
  647. if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) $loop=false;
  648. }
  649. while ($loop);
  650. }
  651. }
  652. }
  653. }
  654. }
  655. }
  656. $maxnbofchar=18;
  657. $cachethirdparties=array();
  658. $cachecontacts=array();
  659. // Define theme_datacolor array
  660. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
  661. if (is_readable($color_file))
  662. {
  663. include_once $color_file;
  664. }
  665. if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220));
  666. if (empty($action) || $action == 'show_month') // View by month
  667. {
  668. $newparam=$param; // newparam is for birthday links
  669. $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
  670. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  671. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  672. $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
  673. $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
  674. $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
  675. $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
  676. echo '<table width="100%" class="nocellnopadd">';
  677. echo ' <tr class="liste_titre">';
  678. $i=0;
  679. while ($i < 7)
  680. {
  681. echo ' <td align="center">'.$langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7))."</td>\n";
  682. $i++;
  683. }
  684. echo " </tr>\n";
  685. $todayarray=dol_getdate($now,'fast');
  686. $todaytms=dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
  687. // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
  688. //var_dump($eventarray);
  689. //print $tmpday;
  690. for ($iter_week = 0; $iter_week < 6 ; $iter_week++)
  691. {
  692. echo " <tr>\n";
  693. for ($iter_day = 0; $iter_day < 7; $iter_day++)
  694. {
  695. /* Show days before the beginning of the current month (previous month) */
  696. if ($tmpday <= 0)
  697. {
  698. $style='cal_other_month cal_past';
  699. echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
  700. show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  701. echo " </td>\n";
  702. }
  703. /* Show days of the current month */
  704. elseif ($tmpday <= $max_day_in_month)
  705. {
  706. $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
  707. $style='cal_current_month';
  708. $today=0;
  709. if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
  710. if ($today) $style='cal_today';
  711. if ($curtime < $todaytms) $style.=' cal_past';
  712. echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
  713. show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  714. echo " </td>\n";
  715. }
  716. /* Show days after the current month (next month) */
  717. else
  718. {
  719. $style='cal_other_month';
  720. echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
  721. show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  722. echo "</td>\n";
  723. }
  724. $tmpday++;
  725. }
  726. echo " </tr>\n";
  727. }
  728. echo "</table>\n";
  729. }
  730. elseif ($action == 'show_week') // View by week
  731. {
  732. $newparam=$param; // newparam is for birthday links
  733. $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
  734. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  735. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  736. $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
  737. $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
  738. $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
  739. $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
  740. echo '<table width="100%" class="nocellnopadd">';
  741. echo ' <tr class="liste_titre">';
  742. $i=0;
  743. while ($i < 7)
  744. {
  745. echo ' <td align="center">'.$langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7))."</td>\n";
  746. $i++;
  747. }
  748. echo " </tr>\n";
  749. // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
  750. //var_dump($eventarray);
  751. //print $tmpday;
  752. echo " <tr>\n";
  753. for($iter_day = 0; $iter_day < 7; $iter_day++)
  754. {
  755. if(($tmpday <= $max_day_in_month))
  756. {
  757. // Show days of the current week
  758. $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
  759. $style='cal_current_month';
  760. $today=0;
  761. $todayarray=dol_getdate($now,'fast');
  762. if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
  763. if ($today) $style='cal_today';
  764. echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
  765. show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  766. echo " </td>\n";
  767. }
  768. else
  769. {
  770. $style='cal_current_month';
  771. echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
  772. show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  773. echo "</td>\n";
  774. }
  775. $tmpday++;
  776. }
  777. echo " </tr>\n";
  778. echo "</table>\n";
  779. }
  780. else // View by day
  781. {
  782. $newparam=$param; // newparam is for birthday links
  783. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  784. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  785. // Code to show just one day
  786. $style='cal_current_month';
  787. $today=0;
  788. $todayarray=dol_getdate($now,'fast');
  789. if ($todayarray['mday']==$day && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
  790. if ($today) $style='cal_today';
  791. $timestamp=dol_mktime(12,0,0,$month,$day,$year);
  792. $arraytimestamp=dol_getdate($timestamp);
  793. echo '<table width="100%" class="nocellnopadd">';
  794. echo ' <tr class="liste_titre">';
  795. echo ' <td align="center">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
  796. echo " </tr>\n";
  797. echo " <tr>\n";
  798. echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
  799. $maxnbofchar=80;
  800. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  801. echo "</td>\n";
  802. echo " </tr>\n";
  803. echo '</table>';
  804. }
  805. $db->close();
  806. /* TODO Export
  807. print '
  808. <a href="" id="actionagenda_ical_link"><img src="'.DOL_URL_ROOT.'/theme/common/ical.gif" border="0"/></a>
  809. <a href="" id="actionagenda_vcal_link"><img src="'.DOL_URL_ROOT.'/theme/common/vcal.gif" border="0"/></a>
  810. <a href="" id="actionagenda_rss_link"><img src="'.DOL_URL_ROOT.'/theme/common/rss.gif" border="0"/></a>
  811. <script>
  812. $("#actionagenda_rss_link").attr("href","/public/agenda/agendaexport.php?format=rss&type=ActionAgenda&exportkey=dolibarr&token="+getToken()+"&status="+getStatus()+"&userasked="+getUserasked()+"&usertodo="+getUsertodo()+"&userdone="+getUserdone()+"&year="+getYear()+"&month="+getMonth()+"&day="+getDay()+"&showbirthday="+getShowbirthday()+"&action="+getAction()+"&projectid="+getProjectid()+"");
  813. $("#actionagenda_ical_link").attr("href","/public/agenda/agendaexport.php?format=ical&type=ActionAgenda&exportkey=dolibarr&token="+getToken()+"&status="+getStatus()+"&userasked="+getUserasked()+"&usertodo="+getUsertodo()+"&userdone="+getUserdone()+"&year="+getYear()+"&month="+getMonth()+"&day="+getDay()+"&showbirthday="+getShowbirthday()+"&action="+getAction()+"&projectid="+getProjectid()+"");
  814. $("#actionagenda_vcal_link").attr("href","/public/agenda/agendaexport.php?format=vcal&type=ActionAgenda&exportkey=dolibarr&token="+getToken()+"&status="+getStatus()+"&userasked="+getUserasked()+"&usertodo="+getUsertodo()+"&userdone="+getUserdone()+"&year="+getYear()+"&month="+getMonth()+"&day="+getDay()+"&showbirthday="+getShowbirthday()+"&action="+getAction()+"&projectid="+getProjectid()+"");
  815. </script>
  816. ';
  817. */
  818. llxFooter();
  819. /**
  820. * Show event of a particular day
  821. *
  822. * @param DoliDB $db Database handler
  823. * @param int $day Day
  824. * @param int $month Month
  825. * @param int $year Year
  826. * @param int $monthshown Current month shown in calendar view
  827. * @param string $style Style to use for this day
  828. * @param array &$eventarray Array of events
  829. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  830. * @param int $maxnbofchar Nb of characters to show for event line
  831. * @param string $newparam Parameters on current URL
  832. * @param int $showinfo Add extended information (used by day view)
  833. * @param int $minheight Minimum height for each event. 60px by default.
  834. * @return void
  835. */
  836. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60)
  837. {
  838. global $user, $conf, $langs;
  839. global $filter, $filtera, $filtert, $filterd, $status;
  840. global $theme_datacolor;
  841. global $cachethirdparties, $cachecontacts;
  842. print '<div id="dayevent_'.sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day).'" class="dayevent">'."\n";
  843. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  844. print '<table class="nobordernopadding" width="100%">';
  845. print '<tr style="background: #EEEEEE"><td align="left" nowrap="nowrap">';
  846. print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?';
  847. print 'action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
  848. print $newparam;
  849. //.'&month='.$month.'&year='.$year;
  850. print '">';
  851. if ($showinfo) print dol_print_date($curtime,'daytext');
  852. else print dol_print_date($curtime,'%d');
  853. print '</a>';
  854. print '</td><td align="right" nowrap="nowrap">';
  855. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
  856. {
  857. //$param='month='.$monthshown.'&year='.$year;
  858. $hourminsec='100000';
  859. print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&datep='.sprintf("%04d%02d%02d",$year,$month,$day).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam?'?'.$newparam:'')).'">';
  860. print img_picto($langs->trans("NewAction"),'edit_add.png');
  861. print '</a>';
  862. }
  863. print '</td></tr>';
  864. print '<tr height="'.$minheight.'"><td valign="top" colspan="2" nowrap="nowrap">';
  865. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  866. $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array();
  867. $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
  868. foreach ($eventarray as $daykey => $notused)
  869. {
  870. $annee = date('Y',$daykey);
  871. $mois = date('m',$daykey);
  872. $jour = date('d',$daykey);
  873. if ($day==$jour && $month==$mois && $year==$annee)
  874. {
  875. foreach ($eventarray[$daykey] as $index => $event)
  876. {
  877. if ($i < $maxprint || $maxprint == 0 || ! empty($conf->global->MAIN_JS_SWITCH_AGENDA))
  878. {
  879. $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar);
  880. // Define $color and $cssclass of event
  881. $color=-1; $cssclass=''; $colorindex=-1;
  882. if ($event->author->id == $user->id || $event->usertodo->id == $user->id || $event->userdone->id == $user->id) { $nummytasks++; $colorindex=1; $cssclass='family_mytasks'; }
  883. else if ($event->type_code == 'ICALEVENT') { $numical++; $numicals[dol_string_nospecial($event->icalname)]++; $color=$event->icalcolor; $cssclass=($event->icalname?'family_'.dol_string_nospecial($event->icalname):'family_other'); }
  884. else if ($event->type_code == 'BIRTHDAY') { $numbirthday++; $colorindex=2; $cssclass='family_birthday'; }
  885. else { $numother++; $colorindex=2; $cssclass='family_other'; }
  886. if ($color == -1) $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  887. $cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
  888. // Show rect of event
  889. print '<div id="event_'.$ymd.'_'.$i.'" class="event '.$cssclass.'">';
  890. print '<table class="cal_event" style="background: #'.$color.'; -moz-border-radius:4px;" width="100%"><tr>';
  891. print '<td nowrap="nowrap">';
  892. if ($event->type_code == 'BIRTHDAY') // It's a birthday
  893. {
  894. print $event->getNomUrl(1,$maxnbofchar,'cal_event','birthday','contact');
  895. }
  896. if ($event->type_code != 'BIRTHDAY')
  897. {
  898. // Picto
  899. if (empty($event->fulldayevent))
  900. {
  901. //print $event->getNomUrl(2).' ';
  902. }
  903. // Date
  904. if (empty($event->fulldayevent))
  905. {
  906. //print '<strong>';
  907. $daterange='';
  908. // Show hours (start ... end)
  909. $tmpyearstart = date('Y',$event->date_start_in_calendar);
  910. $tmpmonthstart = date('m',$event->date_start_in_calendar);
  911. $tmpdaystart = date('d',$event->date_start_in_calendar);
  912. $tmpyearend = date('Y',$event->date_end_in_calendar);
  913. $tmpmonthend = date('m',$event->date_end_in_calendar);
  914. $tmpdayend = date('d',$event->date_end_in_calendar);
  915. // Hour start
  916. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
  917. {
  918. $daterange.=dol_print_date($event->date_start_in_calendar,'%H:%M');
  919. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
  920. {
  921. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
  922. $daterange.='-';
  923. //else
  924. //print '...';
  925. }
  926. }
  927. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
  928. {
  929. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
  930. {
  931. $daterange.='...';
  932. }
  933. }
  934. // Hour end
  935. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
  936. {
  937. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
  938. $daterange.=dol_print_date($event->date_end_in_calendar,'%H:%M');
  939. }
  940. //print $daterange;
  941. if ($event->type_code != 'ICALEVENT')
  942. {
  943. $savlabel=$event->libelle;
  944. $event->libelle=$daterange;
  945. print $event->getNomUrl(0);
  946. $event->libelle=$savlabel;
  947. }
  948. else
  949. {
  950. print $daterange;
  951. }
  952. //print '</strong> ';
  953. print "<br>\n";
  954. }
  955. else
  956. {
  957. if ($showinfo)
  958. {
  959. print $langs->trans("EventOnFullDay")."<br>\n";
  960. }
  961. }
  962. // Show title
  963. if ($event->type_code == 'ICALEVENT') print dol_trunc($event->libelle,$maxnbofchar);
  964. else print $event->getNomUrl(0,$maxnbofchar,'cal_event');
  965. if ($event->type_code == 'ICALEVENT') print '<br>('.dol_trunc($event->icalname,$maxnbofchar).')';

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