index.php 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  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-2016 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) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/comm/action/index.php
  26. * \ingroup agenda
  27. * \brief Home page of calendar events
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  35. if (! empty($conf->projet->enabled)) {
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  37. }
  38. if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
  39. if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5;
  40. $MAXAGENDA=$conf->global->AGENDA_EXT_NB;
  41. $filter = GETPOST("filter",'',3);
  42. $filtert = GETPOST("filtert","int",3);
  43. $usergroup = GETPOST("usergroup","int",3);
  44. $showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
  45. // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
  46. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
  47. {
  48. $filtert=$user->id;
  49. }
  50. $sortfield = GETPOST("sortfield",'alpha');
  51. $sortorder = GETPOST("sortorder",'alpha');
  52. $page = GETPOST("page","int");
  53. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  54. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  55. $offset = $limit * $page;
  56. if (! $sortorder) $sortorder="ASC";
  57. if (! $sortfield) $sortfield="a.datec";
  58. // Security check
  59. $socid = GETPOST("socid","int");
  60. if ($user->societe_id) $socid=$user->societe_id;
  61. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  62. if ($socid < 0) $socid='';
  63. $canedit=1;
  64. if (! $user->rights->agenda->myactions->read) accessforbidden();
  65. if (! $user->rights->agenda->allactions->read) $canedit=0;
  66. if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no permission to see all, we show only affected to me
  67. {
  68. $filtert=$user->id;
  69. }
  70. $action=GETPOST('action','alpha');
  71. $resourceid=GETPOST("resourceid","int");
  72. $year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
  73. $month=GETPOST("month","int")?GETPOST("month","int"):date("m");
  74. $week=GETPOST("week","int")?GETPOST("week","int"):date("W");
  75. $day=GETPOST("day","int")?GETPOST("day","int"):0;
  76. $pid=GETPOST("projectid","int",3);
  77. $status=GETPOST("status");
  78. $type=GETPOST("type");
  79. $maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
  80. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  81. if (GETPOST('actioncode','array'))
  82. {
  83. $actioncode=GETPOST('actioncode','array',3);
  84. if (! count($actioncode)) $actioncode='0';
  85. }
  86. else
  87. {
  88. $actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  89. }
  90. if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE);
  91. if ($status == '' && ! isset($_GET['status']) && ! isset($_POST['status'])) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  92. if (empty($action) && ! isset($_GET['action']) && ! isset($_POST['action'])) $action=(empty($conf->global->AGENDA_DEFAULT_VIEW)?'show_month':$conf->global->AGENDA_DEFAULT_VIEW);
  93. if (GETPOST('viewcal') && $action != 'show_day' && $action != 'show_week') {
  94. $action='show_month'; $day='';
  95. } // View by month
  96. if (GETPOST('viewweek') || $action == 'show_week') {
  97. $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d"));
  98. } // View by week
  99. if (GETPOST('viewday') || $action == 'show_day') {
  100. $action='show_day'; $day=($day?$day:date("d"));
  101. } // View by day
  102. $langs->load("agenda");
  103. $langs->load("other");
  104. $langs->load("commercial");
  105. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  106. $hookmanager->initHooks(array('agenda'));
  107. /*
  108. * Actions
  109. */
  110. if (GETPOST("viewlist") || $action == 'show_list')
  111. {
  112. $param='';
  113. foreach($_POST as $key => $val)
  114. {
  115. if ($key=='token') continue;
  116. $param.='&'.$key.'='.urlencode($val);
  117. }
  118. //print $param;
  119. header("Location: ".DOL_URL_ROOT.'/comm/action/listactions.php?'.$param);
  120. exit;
  121. }
  122. if (GETPOST("viewperuser") || $action == 'show_peruser')
  123. {
  124. $param='';
  125. foreach($_POST as $key => $val)
  126. {
  127. if ($key=='token') continue;
  128. $param.='&'.$key.'='.urlencode($val);
  129. }
  130. //print $param;
  131. header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
  132. exit;
  133. }
  134. if ($action =='delete_action')
  135. {
  136. $event = new ActionComm($db);
  137. $event->fetch($actionid);
  138. $result=$event->delete();
  139. }
  140. /*
  141. * View
  142. */
  143. $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  144. llxHeader('',$langs->trans("Agenda"),$help_url);
  145. $form=new Form($db);
  146. $companystatic=new Societe($db);
  147. $contactstatic=new Contact($db);
  148. $now=dol_now();
  149. $nowarray=dol_getdate($now);
  150. $nowyear=$nowarray['year'];
  151. $nowmonth=$nowarray['mon'];
  152. $nowday=$nowarray['mday'];
  153. $listofextcals=array();
  154. // Define list of external calendars (global admin setup)
  155. if (empty($conf->global->AGENDA_DISABLE_EXT))
  156. {
  157. $i=0;
  158. while($i < $MAXAGENDA)
  159. {
  160. $i++;
  161. $source='AGENDA_EXT_SRC'.$i;
  162. $name='AGENDA_EXT_NAME'.$i;
  163. $offsettz='AGENDA_EXT_OFFSETTZ'.$i;
  164. $color='AGENDA_EXT_COLOR'.$i;
  165. $buggedfile='AGENDA_EXT_BUGGEDFILE'.$i;
  166. if (! empty($conf->global->$source) && ! empty($conf->global->$name))
  167. {
  168. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  169. $listofextcals[]=array('src'=>$conf->global->$source,'name'=>$conf->global->$name,'offsettz'=>$conf->global->$offsettz,'color'=>$conf->global->$color,'buggedfile'=>(isset($conf->global->buggedfile)?$conf->global->buggedfile:0));
  170. }
  171. }
  172. }
  173. // Define list of external calendars (user setup)
  174. if (empty($user->conf->AGENDA_DISABLE_EXT))
  175. {
  176. $i=0;
  177. while($i < $MAXAGENDA)
  178. {
  179. $i++;
  180. $source='AGENDA_EXT_SRC_'.$user->id.'_'.$i;
  181. $name='AGENDA_EXT_NAME_'.$user->id.'_'.$i;
  182. $offsettz='AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
  183. $color='AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
  184. $enabled='AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
  185. $buggedfile='AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
  186. if (! empty($user->conf->$source) && ! empty($user->conf->$name))
  187. {
  188. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  189. $listofextcals[]=array('src'=>$user->conf->$source,'name'=>$user->conf->$name,'offsettz'=>$user->conf->$offsettz,'color'=>$user->conf->$color,'buggedfile'=>(isset($user->conf->buggedfile)?$user->conf->buggedfile:0));
  190. }
  191. }
  192. }
  193. if (empty($action) || $action=='show_month')
  194. {
  195. $prev = dol_get_prev_month($month, $year);
  196. $prev_year = $prev['year'];
  197. $prev_month = $prev['month'];
  198. $next = dol_get_next_month($month, $year);
  199. $next_year = $next['year'];
  200. $next_month = $next['month'];
  201. $max_day_in_prev_month = date("t",dol_mktime(0,0,0,$prev_month,1,$prev_year)); // Nb of days in previous month
  202. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year)); // Nb of days in next month
  203. // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
  204. $tmpday = -date("w",dol_mktime(12,0,0,$month,1,$year,true))+2; // date('w') is 0 fo sunday
  205. $tmpday+=((isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)-1);
  206. if ($tmpday >= 1) $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
  207. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  208. $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$prev_year);
  209. $next_day=7 - ($max_day_in_month+1-$tmpday) % 7;
  210. if ($next_day < 6) $next_day+=7;
  211. $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
  212. }
  213. if ($action=='show_week')
  214. {
  215. $prev = dol_get_first_day_week($day, $month, $year);
  216. $prev_year = $prev['prev_year'];
  217. $prev_month = $prev['prev_month'];
  218. $prev_day = $prev['prev_day'];
  219. $first_day = $prev['first_day'];
  220. $first_month= $prev['first_month'];
  221. $first_year = $prev['first_year'];
  222. $week = $prev['week'];
  223. $day = (int) $day;
  224. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  225. $next_year = $next['year'];
  226. $next_month = $next['month'];
  227. $next_day = $next['day'];
  228. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  229. $firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
  230. $lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
  231. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
  232. $tmpday = $first_day;
  233. }
  234. if ($action == 'show_day')
  235. {
  236. $prev = dol_get_prev_day($day, $month, $year);
  237. $prev_year = $prev['year'];
  238. $prev_month = $prev['month'];
  239. $prev_day = $prev['day'];
  240. $next = dol_get_next_day($day, $month, $year);
  241. $next_year = $next['year'];
  242. $next_month = $next['month'];
  243. $next_day = $next['day'];
  244. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  245. $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$prev_day,$prev_year);
  246. $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
  247. }
  248. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  249. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  250. //print dol_print_date($firstdaytoshow,'day');
  251. //print dol_print_date($lastdaytoshow,'day');
  252. $title=$langs->trans("DoneAndToDoActions");
  253. if ($status == 'done') $title=$langs->trans("DoneActions");
  254. if ($status == 'todo') $title=$langs->trans("ToDoActions");
  255. $param='';
  256. if ($actioncode || isset($_GET['actioncode']) || isset($_POST['actioncode'])) $param.="&actioncode=".$actioncode;
  257. if ($resourceid > 0) $param.="&resourceid=".$resourceid;
  258. if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status;
  259. if ($filter) $param.="&filter=".$filter;
  260. if ($filtert) $param.="&filtert=".$filtert;
  261. if ($socid) $param.="&socid=".$socid;
  262. if ($showbirthday) $param.="&showbirthday=1";
  263. if ($pid) $param.="&projectid=".$pid;
  264. if ($type) $param.="&type=".$type;
  265. if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month') $param.='&action='.$action;
  266. $param.="&maxprint=".$maxprint;
  267. // Show navigation bar
  268. if (empty($action) || $action=='show_month')
  269. {
  270. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  271. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%b %Y");
  272. $nav.=" </span>\n";
  273. $nav.=" &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  274. $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth.$param."\">".$langs->trans("Today")."</a>)";
  275. $picto='calendar';
  276. }
  277. if ($action=='show_week')
  278. {
  279. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> &nbsp;\n";
  280. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
  281. $nav.=" </span>\n";
  282. $nav.=" &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
  283. $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
  284. $picto='calendarweek';
  285. }
  286. if ($action=='show_day')
  287. {
  288. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  289. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,$day,$year),"daytextshort");
  290. $nav.=" </span>\n";
  291. $nav.=" &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  292. $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
  293. $picto='calendarday';
  294. }
  295. // Must be after the nav definition
  296. $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
  297. //print 'x'.$param;
  298. $tabactive='';
  299. if ($action == 'show_month') $tabactive='cardmonth';
  300. if ($action == 'show_week') $tabactive='cardweek';
  301. if ($action == 'show_day') $tabactive='cardday';
  302. if ($action == 'show_list') $tabactive='cardlist';
  303. $paramnoaction=preg_replace('/action=[a-z_]+/','',$param);
  304. $head = calendars_prepare_head($paramnoaction);
  305. dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  306. print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup,'', $resourceid);
  307. dol_fiche_end();
  308. // Define the legend/list of calendard to show
  309. $s=''; $link='';
  310. $showextcals=$listofextcals;
  311. if (! empty($conf->use_javascript_ajax)) // If javascript on
  312. {
  313. $s.='<!-- Div to calendars selectors -->'."\n";
  314. $s.='<script type="text/javascript">' . "\n";
  315. $s.='jQuery(document).ready(function () {' . "\n";
  316. $s.='jQuery("#check_birthday").click(function() { console.log("Toggle birthday"); jQuery(".family_birthday").toggle(); });' . "\n";
  317. $s.='jQuery(".family_birthday").toggle();' . "\n";
  318. if ($action=="show_week" || $action=="show_month" || empty($action))
  319. {
  320. // Code to enable drag and drop
  321. $s.='jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {';
  322. // Code to submit form
  323. $s.='console.log("submit form to record new event");';
  324. //$s.='console.log(event.target);';
  325. $s.='var newval = jQuery(event.target).closest("div.dayevent").attr("id");';
  326. $s.='console.log("found parent div.dayevent with id = "+newval);';
  327. $s.='var frm=jQuery("#move_event"); frm.attr("action",ui.item.find("a.cal_event").attr("href")).children("#newdate").val(newval);frm.submit();}';
  328. $s.='});'."\n";
  329. }
  330. $s.='});' . "\n";
  331. $s.='</script>' . "\n";
  332. // Local calendar
  333. $s.='<div class="nowrap clear float minheight20"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' &nbsp; </div>';
  334. // External calendars
  335. if (is_array($showextcals) && count($showextcals) > 0)
  336. {
  337. $s.='<script type="text/javascript">' . "\n";
  338. $s.='jQuery(document).ready(function () {
  339. jQuery("table input[name^=\"check_ext\"]").click(function() {
  340. var name = $(this).attr("name");
  341. jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
  342. });
  343. });' . "\n";
  344. $s.='</script>' . "\n";
  345. foreach ($showextcals as $val)
  346. {
  347. $htmlname = md5($val['name']);
  348. $s.='<div class="nowrap float"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val['name'] . ' &nbsp; </div>';
  349. }
  350. }
  351. // Birthdays
  352. $s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
  353. // Calendars from hooks
  354. $parameters=array(); $object=null;
  355. $reshook=$hookmanager->executeHooks('addCalendarChoice',$parameters,$object,$action);
  356. if (empty($reshook))
  357. {
  358. $s.= $hookmanager->resPrint;
  359. }
  360. elseif ($reshook > 1)
  361. {
  362. $s = $hookmanager->resPrint;
  363. }
  364. }
  365. else // If javascript off
  366. {
  367. $newparam=$param; // newparam is for birthday links
  368. $newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
  369. if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1';
  370. $link='<a href="'.$_SERVER['PHP_SELF'];
  371. $link.='?'.$newparam;
  372. $link.='">';
  373. if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents");
  374. else $link.=$langs->trans("AgendaHideBirthdayEvents");
  375. $link.='</a>';
  376. }
  377. print load_fiche_titre($s, $link.' &nbsp; &nbsp; '.$nav, '', 0, 0, 'tablelistofcalendars');
  378. // Load events from database into $eventarray
  379. $eventarray=array();
  380. $sql = 'SELECT ';
  381. if ($usergroup > 0) $sql.=" DISTINCT";
  382. $sql.= ' a.id, a.label,';
  383. $sql.= ' a.datep,';
  384. $sql.= ' a.datep2,';
  385. $sql.= ' a.percent,';
  386. $sql.= ' a.fk_user_author,a.fk_user_action,';
  387. $sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  388. $sql.= ' a.fk_soc, a.fk_contact,';
  389. $sql.= ' a.fk_element, a.elementtype,';
  390. $sql.= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color';
  391. $sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
  392. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  393. // We must filter on resource table
  394. if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r";
  395. // We must filter on assignement table
  396. if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  397. if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  398. $sql.= ' WHERE a.fk_action = ca.id';
  399. $sql.= ' AND a.entity IN ('.getEntity('agenda').')';
  400. // Condition on actioncode
  401. if (! empty($actioncode))
  402. {
  403. if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
  404. {
  405. if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
  406. elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
  407. else
  408. {
  409. if ($actioncode == 'AC_OTH') $sql.= " AND ca.type != 'systemauto'";
  410. if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND ca.type = 'systemauto'";
  411. }
  412. }
  413. else
  414. {
  415. if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
  416. elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
  417. else
  418. {
  419. $sql.=" AND ca.code IN ('".implode("','", explode(',',$actioncode))."')";
  420. }
  421. }
  422. }
  423. if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
  424. if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
  425. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
  426. if ($socid > 0) $sql.= ' AND a.fk_soc = '.$socid;
  427. // We must filter on assignement table
  428. if ($filtert > 0 || $usergroup > 0) $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  429. if ($action == 'show_day')
  430. {
  431. $sql.= " AND (";
  432. $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  433. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  434. $sql.= " OR ";
  435. $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  436. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  437. $sql.= " OR ";
  438. $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  439. $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  440. $sql.= ')';
  441. }
  442. else
  443. {
  444. // To limit array
  445. $sql.= " AND (";
  446. $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'"; // Start 7 days before
  447. $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
  448. $sql.= " OR ";
  449. $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
  450. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
  451. $sql.= " OR ";
  452. $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
  453. $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
  454. $sql.= ')';
  455. }
  456. if ($type) $sql.= " AND ca.id = ".$type;
  457. if ($status == '0') { $sql.= " AND a.percent = 0"; }
  458. if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable
  459. if ($status == '50') { $sql.= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
  460. if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; }
  461. if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; }
  462. // We must filter on assignement table
  463. if ($filtert > 0 || $usergroup > 0)
  464. {
  465. $sql.= " AND (";
  466. if ($filtert > 0) $sql.= "ar.fk_element = ".$filtert;
  467. if ($usergroup > 0) $sql.= ($filtert>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup;
  468. $sql.= ")";
  469. }
  470. // Sort on date
  471. $sql.= ' ORDER BY datep';
  472. //print $sql;
  473. dol_syslog("comm/action/index.php", LOG_DEBUG);
  474. $resql=$db->query($sql);
  475. if ($resql)
  476. {
  477. $num = $db->num_rows($resql);
  478. $i=0;
  479. while ($i < $num)
  480. {
  481. $obj = $db->fetch_object($resql);
  482. // Discard auto action if option is on
  483. if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO')
  484. {
  485. $i++;
  486. continue;
  487. }
  488. // Create a new object action
  489. $event=new ActionComm($db);
  490. $event->id=$obj->id;
  491. $event->datep=$db->jdate($obj->datep); // datep and datef are GMT date. Example: 1970-01-01 01:00:00, jdate will return 0 if TZ of PHP server is Europe/Berlin
  492. $event->datef=$db->jdate($obj->datep2);
  493. //var_dump($obj->datep);
  494. //var_dump($event->datep);
  495. $event->type_code=$obj->type_code;
  496. $event->type_label=$obj->type_label;
  497. $event->type_color=$obj->type_color;
  498. $event->libelle=$obj->label;
  499. $event->percentage=$obj->percent;
  500. $event->authorid=$obj->fk_user_author; // user id of creator
  501. $event->userownerid=$obj->fk_user_action; // user id of owner
  502. $event->fetch_userassigned(); // This load $event->userassigned
  503. $event->priority=$obj->priority;
  504. $event->fulldayevent=$obj->fulldayevent;
  505. $event->location=$obj->location;
  506. $event->transparency=$obj->transparency;
  507. $event->fk_element=$obj->fk_element;
  508. $event->elementtype=$obj->elementtype;
  509. $event->societe->id=$obj->fk_soc;
  510. $event->contact->id=$obj->fk_contact;
  511. // Defined date_start_in_calendar and date_end_in_calendar property
  512. // They are date start and end of action but modified to not be outside calendar view.
  513. if ($event->percentage <= 0)
  514. {
  515. $event->date_start_in_calendar=$event->datep;
  516. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  517. else $event->date_end_in_calendar=$event->datep;
  518. }
  519. else
  520. {
  521. $event->date_start_in_calendar=$event->datep;
  522. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  523. else $event->date_end_in_calendar=$event->datep;
  524. }
  525. // Define ponctual property
  526. if ($event->date_start_in_calendar == $event->date_end_in_calendar)
  527. {
  528. $event->ponctuel=1;
  529. }
  530. // Check values
  531. if ($event->date_end_in_calendar < $firstdaytoshow ||
  532. $event->date_start_in_calendar >= $lastdaytoshow)
  533. {
  534. // This record is out of visible range
  535. }
  536. else
  537. {
  538. if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  539. if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
  540. // Add an entry in actionarray for each day
  541. $daycursor=$event->date_start_in_calendar;
  542. $annee = date('Y',$daycursor);
  543. $mois = date('m',$daycursor);
  544. $jour = date('d',$daycursor);
  545. // Loop on each day covered by action to prepare an index to show on calendar
  546. $loop=true; $j=0;
  547. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  548. do
  549. {
  550. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  551. $eventarray[$daykey][]=$event;
  552. $j++;
  553. $daykey+=60*60*24;
  554. if ($daykey > $event->date_end_in_calendar) $loop=false;
  555. }
  556. while ($loop);
  557. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  558. //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>';
  559. }
  560. $i++;
  561. }
  562. }
  563. else
  564. {
  565. dol_print_error($db);
  566. }
  567. // Complete $eventarray with birthdates
  568. if ($showbirthday)
  569. {
  570. // Add events in array
  571. $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
  572. $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
  573. $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
  574. $sql.= " AND sp.entity IN (".getEntity('societe').")";
  575. if ($action == 'show_day')
  576. {
  577. $sql.= ' AND MONTH(birthday) = '.$month;
  578. $sql.= ' AND DAY(birthday) = '.$day;
  579. }
  580. else
  581. {
  582. $sql.= ' AND MONTH(birthday) = '.$month;
  583. }
  584. $sql.= ' ORDER BY birthday';
  585. dol_syslog("comm/action/index.php", LOG_DEBUG);
  586. $resql=$db->query($sql);
  587. if ($resql)
  588. {
  589. $num = $db->num_rows($resql);
  590. $i=0;
  591. while ($i < $num)
  592. {
  593. $obj = $db->fetch_object($resql);
  594. $event=new ActionComm($db);
  595. $event->id=$obj->rowid; // We put contact id in action id for birthdays events
  596. $datebirth=dol_stringtotime($obj->birthday,1);
  597. //print 'ee'.$obj->birthday.'-'.$datebirth;
  598. $datearray=dol_getdate($datebirth,true);
  599. $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
  600. $event->datef=$event->datep;
  601. $event->type_code='BIRTHDAY';
  602. $event->libelle=$langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname,$obj->lastname);
  603. $event->percentage=100;
  604. $event->fulldayevent=true;
  605. $event->date_start_in_calendar=$event->datep;
  606. $event->date_end_in_calendar=$event->datef;
  607. $event->ponctuel=0;
  608. // Add an entry in actionarray for each day
  609. $daycursor=$event->date_start_in_calendar;
  610. $annee = date('Y',$daycursor);
  611. $mois = date('m',$daycursor);
  612. $jour = date('d',$daycursor);
  613. $loop=true;
  614. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  615. do
  616. {
  617. $eventarray[$daykey][]=$event;
  618. $daykey+=60*60*24;
  619. if ($daykey > $event->date_end_in_calendar) $loop=false;
  620. }
  621. while ($loop);
  622. $i++;
  623. }
  624. }
  625. else
  626. {
  627. dol_print_error($db);
  628. }
  629. }
  630. // Complete $eventarray with external import Ical
  631. if (count($listofextcals))
  632. {
  633. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
  634. foreach($listofextcals as $extcal)
  635. {
  636. $url=$extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
  637. $namecal = $extcal['name'];
  638. $offsettz = $extcal['offsettz'];
  639. $colorcal = $extcal['color'];
  640. $buggedfile = $extcal['buggedfile'];
  641. //print "url=".$url." namecal=".$namecal." colorcal=".$colorcal." buggedfile=".$buggedfile;
  642. $ical=new ICal();
  643. $ical->parse($url);
  644. // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
  645. //var_dump($ical->cal); exit;
  646. $icalevents=array();
  647. if (is_array($ical->get_event_list())) $icalevents=array_merge($icalevents,$ical->get_event_list()); // Add $ical->cal['VEVENT']
  648. if (is_array($ical->get_freebusy_list())) $icalevents=array_merge($icalevents,$ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
  649. if (count($icalevents)>0)
  650. {
  651. // Duplicate all repeatable events into new entries
  652. $moreicalevents=array();
  653. foreach($icalevents as $icalevent)
  654. {
  655. if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) //repeatable event
  656. {
  657. //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  658. //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
  659. if ($icalevent['DTSTART;VALUE=DATE']) //fullday event
  660. {
  661. $datecurstart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
  662. $datecurend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
  663. }
  664. else if (is_array($icalevent['DTSTART']) && ! empty($icalevent['DTSTART']['unixtime']))
  665. {
  666. $datecurstart=$icalevent['DTSTART']['unixtime'];
  667. $datecurend=$icalevent['DTEND']['unixtime'];
  668. if (! empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart)
  669. {
  670. //var_dump($ical->cal);
  671. $tmpcurstart=$datecurstart;
  672. $tmpcurend=$datecurend;
  673. $tmpdaylightstart=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
  674. $tmpdaylightend=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['STANDARD']['DTSTART'];
  675. //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
  676. // Edit datecurstart and datecurend
  677. if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurstart-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
  678. else $datecurstart-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
  679. if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurend-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
  680. else $datecurend-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
  681. }
  682. // datecurstart and datecurend are now GMT date
  683. //var_dump($datecurstart); var_dump($datecurend); exit;
  684. }
  685. else
  686. {
  687. // Not a recongized record
  688. dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
  689. continue;
  690. }
  691. //print 'xx'.$datecurstart;exit;
  692. $interval=(empty($icalevent['RRULE']['INTERVAL'])?1:$icalevent['RRULE']['INTERVAL']);
  693. $until=empty($icalevent['RRULE']['UNTIL'])?0:dol_stringtotime($icalevent['RRULE']['UNTIL'],1);
  694. $maxrepeat=empty($icalevent['RRULE']['COUNT'])?0:$icalevent['RRULE']['COUNT'];
  695. if ($until && ($until+($datecurend-$datecurstart)) < $firstdaytoshow) continue; // We discard repeatable event that end before start date to show
  696. if ($datecurstart >= $lastdaytoshow) continue; // We discard repeatable event that start after end date to show
  697. $numofevent=0;
  698. while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)))
  699. {
  700. if ($datecurend >= $firstdaytoshow) // We add event
  701. {
  702. $newevent=$icalevent;
  703. unset($newevent['RRULE']);
  704. if ($icalevent['DTSTART;VALUE=DATE'])
  705. {
  706. $newevent['DTSTART;VALUE=DATE']=dol_print_date($datecurstart,'%Y%m%d');
  707. $newevent['DTEND;VALUE=DATE']=dol_print_date($datecurend+1,'%Y%m%d');
  708. }
  709. else
  710. {
  711. $newevent['DTSTART']=$datecurstart;
  712. $newevent['DTEND']=$datecurend;
  713. }
  714. $moreicalevents[]=$newevent;
  715. }
  716. // Jump on next occurence
  717. $numofevent++;
  718. $savdatecurstart=$datecurstart;
  719. if ($icalevent['RRULE']['FREQ']=='DAILY')
  720. {
  721. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'd');
  722. $datecurend=dol_time_plus_duree($datecurend, $interval, 'd');
  723. }
  724. if ($icalevent['RRULE']['FREQ']=='WEEKLY')
  725. {
  726. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'w');
  727. $datecurend=dol_time_plus_duree($datecurend, $interval, 'w');
  728. }
  729. elseif ($icalevent['RRULE']['FREQ']=='MONTHLY')
  730. {
  731. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'm');
  732. $datecurend=dol_time_plus_duree($datecurend, $interval, 'm');
  733. }
  734. elseif ($icalevent['RRULE']['FREQ']=='YEARLY')
  735. {
  736. $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'y');
  737. $datecurend=dol_time_plus_duree($datecurend, $interval, 'y');
  738. }
  739. // Test to avoid infinite loop ($datecurstart must increase)
  740. if ($savdatecurstart >= $datecurstart)
  741. {
  742. dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
  743. $datecurstart+=3600*24*7;
  744. $datecurend+=3600*24*7;
  745. }
  746. }
  747. }
  748. }
  749. $icalevents=array_merge($icalevents,$moreicalevents);
  750. // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
  751. foreach($icalevents as $icalevent)
  752. {
  753. //var_dump($icalevent);
  754. //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
  755. if (! empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
  756. // Create a new object action
  757. $event=new ActionComm($db);
  758. $addevent = false;
  759. if (isset($icalevent['DTSTART;VALUE=DATE'])) // fullday event
  760. {
  761. // For full day events, date are also GMT but they wont but converted using tz during output
  762. $datestart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
  763. $dateend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
  764. //print 'x'.$datestart.'-'.$dateend;exit;
  765. //print dol_print_date($dateend,'dayhour','gmt');
  766. $event->fulldayevent=true;
  767. $addevent=true;
  768. }
  769. elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
  770. {
  771. $datestart=$icalevent['DTSTART'];
  772. $dateend=$icalevent['DTEND'];
  773. $datestart+=+($offsettz * 3600);
  774. $dateend+=+($offsettz * 3600);
  775. $addevent=true;
  776. //var_dump($offsettz);
  777. //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
  778. }
  779. elseif (isset($icalevent['DTSTART']['unixtime'])) // File contains a local timezone + a TZ (for example when using bluemind)
  780. {
  781. $datestart=$icalevent['DTSTART']['unixtime'];
  782. $dateend=$icalevent['DTEND']['unixtime'];
  783. $datestart+=+($offsettz * 3600);
  784. $dateend+=+($offsettz * 3600);
  785. // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
  786. if ($buggedfile === 'uselocalandtznodaylight') // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
  787. {
  788. // TODO
  789. }
  790. // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
  791. if ($buggedfile === 'uselocalandtzdaylight') // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
  792. {
  793. $localtzs = new DateTimeZone(preg_replace('/"/','',$icalevent['DTSTART']['TZID']));
  794. $localtze = new DateTimeZone(preg_replace('/"/','',$icalevent['DTEND']['TZID']));
  795. $localdts = new DateTime(dol_print_date($datestart,'dayrfc','gmt'), $localtzs);
  796. $localdte = new DateTime(dol_print_date($dateend,'dayrfc','gmt'), $localtze);
  797. $tmps=-1*$localtzs->getOffset($localdts);
  798. $tmpe=-1*$localtze->getOffset($localdte);
  799. $datestart+=$tmps;
  800. $dateend+=$tmpe;
  801. //var_dump($datestart);
  802. }
  803. $addevent=true;
  804. }
  805. if ($addevent)
  806. {
  807. $event->id=$icalevent['UID'];
  808. $event->icalname=$namecal;
  809. $event->icalcolor=$colorcal;
  810. $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.
  811. $event->datep=$datestart+$usertime;
  812. $event->datef=$dateend+$usertime;
  813. $event->type_code="ICALEVENT";
  814. if($icalevent['SUMMARY']) $event->libelle=$icalevent['SUMMARY'];
  815. elseif($icalevent['DESCRIPTION']) $event->libelle=dol_nl2br($icalevent['DESCRIPTION'],1);
  816. else $event->libelle = $langs->trans("ExtSiteNoLabel");
  817. $event->date_start_in_calendar=$event->datep;
  818. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  819. else $event->date_end_in_calendar=$event->datep;
  820. // Define ponctual property
  821. if ($event->date_start_in_calendar == $event->date_end_in_calendar)
  822. {
  823. $event->ponctuel=1;
  824. //print 'x'.$datestart.'-'.$dateend;exit;
  825. }
  826. // Add event into $eventarray if date range are ok.
  827. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow)
  828. {
  829. //print 'x'.$datestart.'-'.$dateend;exit;
  830. //print 'x'.$datestart.'-'.$dateend;exit;
  831. //print 'x'.$datestart.'-'.$dateend;exit;
  832. // This record is out of visible range
  833. }
  834. else
  835. {
  836. if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  837. if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow - 1);
  838. // Add an entry in actionarray for each day
  839. $daycursor=$event->date_start_in_calendar;
  840. $annee = date('Y',$daycursor);
  841. $mois = date('m',$daycursor);
  842. $jour = date('d',$daycursor);
  843. // Loop on each day covered by action to prepare an index to show on calendar
  844. $loop=true; $j=0;
  845. // daykey must be date that represent day box in calendar so must be a user time
  846. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  847. $daykeygmt=dol_mktime(0,0,0,$mois,$jour,$annee,true,0);
  848. do
  849. {
  850. //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').' ';
  851. $eventarray[$daykey][]=$event;
  852. $daykey+=60*60*24; $daykeygmt+=60*60*24; // Add one day
  853. if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) $loop=false;
  854. }
  855. while ($loop);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. // Complete $eventarray with events coming from external module
  863. $parameters=array(); $object=null;
  864. $reshook=$hookmanager->executeHooks('getCalendarEvents',$parameters,$object,$action);
  865. if (! empty($hookmanager->resArray['eventarray'])) {
  866. foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
  867. if (!isset($eventarray[$keyDate])) {
  868. $eventarray[$keyDate]=array();
  869. }
  870. $eventarray[$keyDate]=array_merge($eventarray[$keyDate], $events);
  871. }
  872. }
  873. $maxnbofchar=0;
  874. $cachethirdparties=array();
  875. $cachecontacts=array();
  876. $cacheusers=array();
  877. // Define theme_datacolor array
  878. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
  879. if (is_readable($color_file))
  880. {
  881. include_once $color_file;
  882. }
  883. if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220));
  884. if (empty($action) || $action == 'show_month') // View by month
  885. {
  886. $newparam=$param; // newparam is for birthday links
  887. $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
  888. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  889. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  890. $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
  891. $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
  892. $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
  893. $newparam=preg_replace('/viewcal=[0-9]+&?/i','',$newparam);
  894. $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
  895. $newparam.='&viewcal=1';
  896. echo '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
  897. echo ' <tr class="liste_titre">';
  898. $i=0;
  899. while ($i < 7)
  900. {
  901. print ' <td align="center">';
  902. $numdayinweek=(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7);
  903. if (! empty($conf->dol_optimize_smallscreen))
  904. {
  905. $labelshort=array(0=>'SundayMin',1=>'MondayMin',2=>'TuesdayMin',3=>'WednesdayMin',4=>'ThursdayMin',5=>'FridayMin',6=>'SaturdayMin');
  906. print $langs->trans($labelshort[$numdayinweek]);
  907. }
  908. else print $langs->trans("Day".$numdayinweek);
  909. print ' </td>'."\n";
  910. $i++;
  911. }
  912. echo ' </tr>'."\n";
  913. $todayarray=dol_getdate($now,'fast');
  914. $todaytms=dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
  915. // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
  916. //var_dump($eventarray);
  917. for ($iter_week = 0; $iter_week < 6 ; $iter_week++)
  918. {
  919. echo " <tr>\n";
  920. for ($iter_day = 0; $iter_day < 7; $iter_day++)
  921. {
  922. /* Show days before the beginning of the current month (previous month) */
  923. if ($tmpday <= 0)
  924. {
  925. $style='cal_other_month cal_past';
  926. if ($iter_day == 6) $style.=' cal_other_month_right';
  927. echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
  928. show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  929. echo " </td>\n";
  930. }
  931. /* Show days of the current month */
  932. elseif ($tmpday <= $max_day_in_month)
  933. {
  934. $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
  935. $style='cal_current_month';
  936. if ($iter_day == 6) $style.=' cal_current_month_right';
  937. $today=0;
  938. if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
  939. if ($today) $style='cal_today';
  940. if ($curtime < $todaytms) $style.=' cal_past';
  941. //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
  942. echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
  943. show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  944. echo " </td>\n";
  945. }
  946. /* Show days after the current month (next month) */
  947. else
  948. {
  949. $style='cal_other_month';
  950. if ($iter_day == 6) $style.=' cal_other_month_right';
  951. echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
  952. show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  953. echo "</td>\n";
  954. }
  955. $tmpday++;
  956. }
  957. echo " </tr>\n";
  958. }
  959. echo "</table>\n";
  960. echo '<form id="move_event" action="" method="POST"><input type="hidden" name="action" value="mupdate">';
  961. echo '<input type="hidden" name="backtopage" value="'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'">';
  962. echo '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  963. echo '<input type="hidden" name="newdate" id="newdate">' ;
  964. echo '</form>';
  965. }
  966. elseif ($action == 'show_week') // View by week
  967. {
  968. $newparam=$param; // newparam is for birthday links
  969. $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
  970. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  971. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  972. $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
  973. $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
  974. $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
  975. $newparam=preg_replace('/viewweek=[0-9]+&?/i','',$newparam);
  976. $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
  977. $newparam.='&viewweek=1';
  978. echo '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
  979. echo ' <tr class="liste_titre">';
  980. $i=0;
  981. while ($i < 7)
  982. {
  983. echo ' <td align="center">'.$langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7))."</td>\n";
  984. $i++;
  985. }
  986. echo " </tr>\n";
  987. echo " <tr>\n";
  988. for ($iter_day = 0; $iter_day < 7; $iter_day++)
  989. {
  990. // Show days of the current week
  991. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
  992. $tmparray = dol_getdate($curtime, true);
  993. $tmpday = $tmparray['mday'];
  994. $tmpmonth = $tmparray['mon'];
  995. $tmpyear = $tmparray['year'];
  996. $style='cal_current_month';
  997. if ($iter_day == 6) $style.=' cal_other_month_right';
  998. $today=0;
  999. $todayarray=dol_getdate($now,'fast');
  1000. if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
  1001. if ($today) $style='cal_today';
  1002. echo ' <td class="'.$style.'" width="14%" valign="top">';
  1003. show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  1004. echo " </td>\n";
  1005. }
  1006. echo " </tr>\n";
  1007. echo "</table>\n";
  1008. echo '<form id="move_event" action="" method="POST"><input type="hidden" name="action" value="mupdate">';
  1009. echo '<input type="hidden" name="backtopage" value="'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'">';
  1010. echo '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1011. echo '<input type="hidden" name="newdate" id="newdate">' ;
  1012. echo '</form>';
  1013. }
  1014. else // View by day
  1015. {
  1016. $newparam=$param; // newparam is for birthday links
  1017. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  1018. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  1019. $newparam=preg_replace('/viewday=[0-9]+&?/i','',$newparam);
  1020. $newparam.='&viewday=1';
  1021. // Code to show just one day
  1022. $style='cal_current_month cal_current_month_oneday';
  1023. $today=0;
  1024. $todayarray=dol_getdate($now,'fast');
  1025. if ($todayarray['mday']==$day && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
  1026. //if ($today) $style='cal_today';
  1027. $timestamp=dol_mktime(12,0,0,$month,$day,$year);
  1028. $arraytimestamp=dol_getdate($timestamp);
  1029. echo '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
  1030. echo ' <tr class="liste_titre">';
  1031. echo ' <td align="center">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
  1032. echo " </tr>\n";
  1033. echo " <tr>\n";
  1034. echo ' <td class="'.$style.'" width="14%" valign="top">';
  1035. $maxnbofchar=80;
  1036. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  1037. echo "</td>\n";
  1038. echo " </tr>\n";
  1039. echo '</table>';
  1040. }
  1041. llxFooter();
  1042. $db->close();
  1043. /**
  1044. * Show event of a particular day
  1045. *
  1046. * @param DoliDB $db Database handler
  1047. * @param int $day Day
  1048. * @param int $month Month
  1049. * @param int $year Year
  1050. * @param int $monthshown Current month shown in calendar view
  1051. * @param string $style Style to use for this day
  1052. * @param array $eventarray Array of events
  1053. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  1054. * @param int $maxnbofchar Nb of characters to show for event line
  1055. * @param string $newparam Parameters on current URL
  1056. * @param int $showinfo Add extended information (used by day and week view)
  1057. * @param int $minheight Minimum height for each event. 60px by default.
  1058. * @return void
  1059. */
  1060. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60)
  1061. {
  1062. global $user, $conf, $langs;
  1063. global $action, $filter, $filtert, $status, $actioncode; // Filters used into search form
  1064. global $theme_datacolor;
  1065. global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
  1066. $dateint = sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
  1067. print "\n";
  1068. // Line with title of day
  1069. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  1070. print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding">'."\n";
  1071. print '<div class="tagtr"><div class="nowrap float">';
  1072. print '<a style="color: #666" href="'.DOL_URL_ROOT.'/comm/action/index.php?';
  1073. print 'action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
  1074. print $newparam;
  1075. print '">';
  1076. if ($showinfo) print dol_print_date($curtime,'daytextshort');
  1077. else print dol_print_date($curtime,'%d');
  1078. print '</a>';
  1079. print '</div><div class="floatright nowrap">';
  1080. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
  1081. {
  1082. $newparam.='&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
  1083. //$param='month='.$monthshown.'&year='.$year;
  1084. $hourminsec='100000';
  1085. print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d",$year,$month,$day).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam?'?'.$newparam:'')).'">';
  1086. print img_picto($langs->trans("NewAction"),'edit_add.png');
  1087. print '</a>';
  1088. }
  1089. print '</div></div>'."\n";
  1090. // Line with td contains all div of each events
  1091. print '<div class="tagtr">';
  1092. print '<div class="tagtd centpercent agendacell sortable">';
  1093. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  1094. $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array();
  1095. $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
  1096. $nextindextouse=count($colorindexused); // At first run this is 0, so fist user has 0, next 1, ...
  1097. //print $nextindextouse;
  1098. foreach ($eventarray as $daykey => $notused)
  1099. {
  1100. $annee = date('Y',$daykey);
  1101. $mois = date('m',$daykey);
  1102. $jour = date('d',$daykey);
  1103. if ($day==$jour && $month==$mois && $year==$annee)
  1104. {
  1105. foreach ($eventarray[$daykey] as $index => $event)
  1106. {
  1107. if ($i < $maxprint || $maxprint == 0 || ! empty($conf->global->MAIN_JS_SWITCH_AGENDA))
  1108. {
  1109. $keysofuserassigned=array_keys($event->userassigned);
  1110. $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar);
  1111. // Define $color (Hex string like '0088FF') and $cssclass of event
  1112. $color=-1; $colorindex=-1;
  1113. if (in_array($user->id, $keysofuserassigned))
  1114. {
  1115. $nummytasks++; $cssclass='family_mytasks';
  1116. if (empty($cacheusers[$event->userownerid]))
  1117. {
  1118. $newuser=new User($db);
  1119. $newuser->fetch($event->userownerid);
  1120. $cacheusers[$event->userownerid]=$newuser;
  1121. }
  1122. //var_dump($cacheusers[$event->userownerid]->color);
  1123. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1124. if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color;
  1125. }
  1126. else if ($event->type_code == 'ICALEVENT') // Event come from external ical file
  1127. {
  1128. $numical++;
  1129. if (! empty($event->icalname)) {
  1130. if (! isset($numicals[dol_string_nospecial($event->icalname)])) {
  1131. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1132. }
  1133. $numicals[dol_string_nospecial($event->icalname)]++;
  1134. }
  1135. $color=($event->icalcolor?$event->icalcolor:-1);
  1136. $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other');
  1137. }
  1138. else if ($event->type_code == 'BIRTHDAY')
  1139. {
  1140. $numbirthday++; $colorindex=2; $cssclass='family_birthday unmovable'; $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  1141. }
  1142. else
  1143. {
  1144. $numother++;
  1145. $color=($event->icalcolor?$event->icalcolor:-1);
  1146. $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other');
  1147. if (empty($cacheusers[$event->userownerid]))
  1148. {
  1149. $newuser=new User($db);
  1150. $newuser->fetch($event->userownerid);
  1151. $cacheusers[$event->userownerid]=$newuser;
  1152. }
  1153. //var_dump($cacheusers[$event->userownerid]->color);
  1154. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1155. if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color;
  1156. }
  1157. if ($color == -1) // Color was not forced. Set color according to color index.
  1158. {
  1159. // Define color index if not yet defined
  1160. $idusertouse=($event->userownerid?$event->userownerid:0);
  1161. if (isset($colorindexused[$idusertouse]))
  1162. {
  1163. $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user
  1164. }
  1165. else
  1166. {
  1167. $colorindex=$nextindextouse;
  1168. $colorindexused[$idusertouse]=$colorindex;
  1169. if (! empty($theme_datacolor[$nextindextouse+1])) $nextindextouse++; // Prepare to use next color
  1170. }
  1171. //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
  1172. // Define color
  1173. $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  1174. }
  1175. $cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
  1176. // Defined style to disable drag and drop feature
  1177. if ($event->type_code =='AC_OTH_AUTO')
  1178. {
  1179. $cssclass.= " unmovable";
  1180. }
  1181. else if ($event->type_code == 'ICALEVENT')
  1182. {
  1183. $cssclass.= " unmovable";
  1184. }
  1185. else if ($event->date_end_in_calendar && date('Ymd',$event->date_start_in_calendar) != date('Ymd',$event->date_end_in_calendar))
  1186. {
  1187. $tmpyearend = date('Y',$event->date_end_in_calendar);
  1188. $tmpmonthend = date('m',$event->date_end_in_calendar);
  1189. $tmpdayend = date('d',$event->date_end_in_calendar);
  1190. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
  1191. {
  1192. $cssclass.= " unmovable";
  1193. }
  1194. }
  1195. else{
  1196. if ($user->rights->agenda->allactions->create ||
  1197. (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create))
  1198. {
  1199. $cssclass.= " movable cursormove";
  1200. }else{
  1201. $cssclass.= " unmovable";
  1202. }
  1203. }
  1204. $h=''; $nowrapontd=1;
  1205. if ($action == 'show_day') { $h='height: 100%; '; $nowrapontd=0; }
  1206. if ($action == 'show_week') { $h='height: 100%; '; $nowrapontd=0; }
  1207. // Show rect of event
  1208. print "\n";
  1209. print '<!-- start event '.$i.' -->'."\n";
  1210. print '<div id="event_'.$ymd.'_'.$i.'" class="event '.$cssclass.'"';
  1211. //print ' style="height: 100px;';
  1212. //print ' position: absolute; top: 40px; width: 50%;';
  1213. //print '"';
  1214. print '>';
  1215. print '<table class="centpercent cal_event'.(empty($event->transparency)?'':' cal_event_busy').'" style="'.$h;
  1216. print 'background: #'.$color.';';
  1217. print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, 0).'), to(#'.dol_color_minus($color, 1).'));';
  1218. //if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
  1219. //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
  1220. //print ' -moz-border-radius:4px;"';
  1221. //print 'border: 1px solid #ccc" width="100%"';
  1222. print '">';
  1223. print '<tr>';
  1224. print '<td class="tdoverflow nobottom centpercent '.($nowrapontd?'nowrap ':'').'cal_event'.($event->type_code == 'BIRTHDAY'?' cal_event_birthday':'').'">';
  1225. $daterange='';
  1226. if ($event->type_code == 'BIRTHDAY') // It's a birthday
  1227. {
  1228. print $event->getNomUrl(1,$maxnbofchar,'cal_event','birthday','contact');
  1229. }
  1230. if ($event->type_code != 'BIRTHDAY')
  1231. {
  1232. // Picto
  1233. if (empty($event->fulldayevent))
  1234. {
  1235. //print $event->getNomUrl(2).' ';
  1236. }
  1237. // Date
  1238. if (empty($event->fulldayevent))
  1239. {
  1240. // Show hours (start ... end)
  1241. $tmpyearstart = date('Y',$event->date_start_in_calendar);
  1242. $tmpmonthstart = date('m',$event->date_start_in_calendar);
  1243. $tmpdaystart = date('d',$event->date_start_in_calendar);
  1244. $tmpyearend = date('Y',$event->date_end_in_calendar);
  1245. $tmpmonthend = date('m',$event->date_end_in_calendar);
  1246. $tmpdayend = date('d',$event->date_end_in_calendar);
  1247. // Hour start
  1248. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
  1249. {
  1250. $daterange.=dol_print_date($event->date_start_in_calendar,'%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
  1251. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
  1252. {
  1253. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
  1254. $daterange.='-';
  1255. //else
  1256. //print '...';
  1257. }
  1258. }
  1259. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
  1260. {
  1261. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
  1262. {
  1263. $daterange.='...';
  1264. }
  1265. }
  1266. // Hour end
  1267. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
  1268. {
  1269. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
  1270. $daterange.=dol_print_date($event->date_end_in_calendar,'%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
  1271. }
  1272. }
  1273. else
  1274. {
  1275. if ($showinfo)
  1276. {
  1277. print $langs->trans("EventOnFullDay")."<br>\n";
  1278. }
  1279. }
  1280. // Show title
  1281. $titletoshow = $daterange;
  1282. $titletoshow.=($titletoshow?' ':'').$event->libelle;
  1283. if ($event->type_code == 'ICALEVENT') print $titletoshow;
  1284. else
  1285. {
  1286. $savlabel=$event->libelle;
  1287. $event->libelle=$titletoshow;
  1288. print $event->getNomUrl(0,$maxnbofchar,'cal_event','',0,1);
  1289. $event->libelle=$savlabel;
  1290. }
  1291. // Loop on each assigned user
  1292. $listofusertoshow='';
  1293. $posuserassigned=0;
  1294. foreach($event->userassigned as $tmpid => $tmpdata)
  1295. {
  1296. if (! $posuserassigned && $titletoshow) $listofusertoshow.='<br>';
  1297. $posuserassigned++;
  1298. if (empty($cacheusers[$tmpid]))
  1299. {
  1300. $newuser=new User($db);
  1301. $newuser->fetch($tmpid);
  1302. $cacheusers[$tmpid]=$newuser;
  1303. }
  1304. $listofusertoshow.=$cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'valigntextbottom');
  1305. }
  1306. print $listofusertoshow;
  1307. if ($event->type_code == 'ICALEVENT') print '<br>('.dol_trunc($event->icalname,$maxnbofchar).')';
  1308. // If action related to company / contact
  1309. $linerelatedto='';
  1310. if (! empty($event->societe->id) && $event->societe->id > 0)
  1311. {
  1312. if (! isset($cachethirdparties[$event->societe->id]) || ! is_object($cachethirdparties[$event->societe->id]))
  1313. {
  1314. $thirdparty=new Societe($db);
  1315. $thirdparty->fetch($event->societe->id);
  1316. $cachethirdparties[$event->societe->id]=$thirdparty;
  1317. }
  1318. else $thirdparty=$cachethirdparties[$event->societe->id];
  1319. if (! empty($thirdparty->id)) $linerelatedto.=$thirdparty->getNomUrl(1,'',0);
  1320. }
  1321. if (! empty($event->contact->id) && $event->contact->id > 0)
  1322. {
  1323. if (! is_object($cachecontacts[$event->contact->id]))
  1324. {
  1325. $contact=new Contact($db);
  1326. $contact->fetch($event->contact->id);
  1327. $cachecontacts[$event->contact->id]=$contact;
  1328. }
  1329. else $contact=$cachecontacts[$event->contact->id];
  1330. if ($linerelatedto) $linerelatedto.=' / ';
  1331. if (! empty($contact->id)) $linerelatedto.=$contact->getNomUrl(1,'',0);
  1332. }
  1333. if (! empty($event->fk_element) && $event->fk_element > 0 && ! empty($event->elementtype) && ! empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))
  1334. {
  1335. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1336. if ($linerelatedto) $linerelatedto.=' / ';
  1337. $linerelatedto.=dolGetElementUrl($event->fk_element,$event->elementtype,1);
  1338. }
  1339. if ($linerelatedto) print '<br>'.$linerelatedto;
  1340. }
  1341. // Show location
  1342. if ($showinfo)
  1343. {
  1344. if ($event->location)
  1345. {
  1346. print '<br>';
  1347. print $langs->trans("Location").': '.$event->location;
  1348. }
  1349. }
  1350. print '</td>';
  1351. // Status - Percent
  1352. $withstatus=0;
  1353. if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT')
  1354. {
  1355. $withstatus=1;
  1356. if ($event->percentage >= 0) $withstatus=2;
  1357. }
  1358. print '<td class="nobottom right nowrap cal_event_right'.($withstatus >= 2 ?' cal_event_right_status':'').'">';
  1359. if ($withstatus) print $event->getLibStatut(3,1);
  1360. else print '&nbsp;';
  1361. print '</td></tr></table>';
  1362. print '</div><!-- end event '.$i.' -->'."\n";
  1363. $i++;
  1364. }
  1365. else
  1366. {
  1367. print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action='.$action.'&maxprint=0&month='.$monthshown.'&year='.$year;
  1368. print ($status?'&status='.$status:'').($filter?'&filter='.$filter:'');
  1369. print ($filtert?'&filtert='.$filtert:'');
  1370. print ($actioncode!=''?'&actioncode='.$actioncode:'');
  1371. print '">'.img_picto("all","1downarrow_selected.png").' ...';
  1372. print ' +'.(count($eventarray[$daykey])-$maxprint);
  1373. print '</a>';
  1374. break;
  1375. //$ok=false; // To avoid to show twice the link
  1376. }
  1377. }
  1378. break;
  1379. }
  1380. }
  1381. if (! $i) print '&nbsp;';
  1382. if (! empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint)
  1383. {
  1384. print '<div id="more_'.$ymd.'">'.img_picto("all","1downarrow_selected.png").' +'.$langs->trans("More").'...</div>';
  1385. //print ' +'.(count($eventarray[$daykey])-$maxprint);
  1386. print '<script type="text/javascript">'."\n";
  1387. print 'jQuery(document).ready(function () {'."\n";
  1388. print 'jQuery("#more_'.$ymd.'").click(function() { reinit_day_'.$ymd.'(); });'."\n";
  1389. print 'function reinit_day_'.$ymd.'() {'."\n";
  1390. print 'var nb=0;'."\n";
  1391. // TODO Loop on each element of day $ymd and start to toggle once $maxprint has been reached
  1392. print 'jQuery(".family_mytasks_day_'.$ymd.'").toggle();';
  1393. print '}'."\n";
  1394. print '});'."\n";
  1395. print '</script>'."\n";
  1396. }
  1397. print '</div></div>'; // td tr
  1398. print '</div>'; // table
  1399. print "\n";
  1400. }
  1401. /**
  1402. * Change color with a delta
  1403. *
  1404. * @param string $color Color
  1405. * @param int $minus Delta (1 = 16 unit)
  1406. * @param int $minusunit Minus unit
  1407. * @return string New color
  1408. */
  1409. function dol_color_minus($color, $minus, $minusunit = 16)
  1410. {
  1411. $newcolor=$color;
  1412. if ($minusunit == 16)
  1413. {
  1414. $newcolor[0]=dechex(max(min(hexdec($newcolor[0])-$minus, 15), 0));
  1415. $newcolor[2]=dechex(max(min(hexdec($newcolor[2])-$minus, 15), 0));
  1416. $newcolor[4]=dechex(max(min(hexdec($newcolor[4])-$minus, 15), 0));
  1417. }
  1418. else
  1419. {
  1420. // Not yet implemented
  1421. }
  1422. return $newcolor;
  1423. }