index.php 78 KB

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