index.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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-2021 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 <https://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. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/lib/agenda.lib.php';
  37. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/agendaplus.class.php';
  38. if (isModEnabled('project')) {
  39. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  40. }
  41. if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
  42. $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
  43. }
  44. if (empty($conf->global->AGENDA_EXT_NB)) {
  45. $conf->global->AGENDA_EXT_NB = 5;
  46. }
  47. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  48. $disabledefaultvalues = GETPOST('disabledefaultvalues', 'int');
  49. //print_r($_REQUEST);
  50. $check_holiday = GETPOST('check_holiday', 'int');
  51. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  52. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  53. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  54. $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1;
  55. $agendaplus = new AgendaPlus();
  56. // new filters (event_details, event products, event location from)
  57. $eventdetails = $agendaplus->getSearchedElement('eventdetails');
  58. $eventproduct = $agendaplus->getSearchedElement('eventproduct');
  59. $eventlocation = $agendaplus->getSearchedElement('eventlocation');
  60. // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
  61. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
  62. //$filtert = $user->id;
  63. }
  64. $newparam = '';
  65. $sortfield = GETPOST('sortfield', 'aZ09comma');
  66. $sortorder = GETPOST('sortorder', 'aZ09comma');
  67. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  68. if (empty($page) || $page == -1) {
  69. $page = 0;
  70. } // If $page is not defined, or '' or -1
  71. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  72. $offset = $limit * $page;
  73. if (!$sortorder) {
  74. $sortorder = "ASC";
  75. }
  76. if (!$sortfield) {
  77. $sortfield = "a.datec";
  78. }
  79. // Security check
  80. $socid = GETPOST("search_socid", "int") ? GETPOST("search_socid", "int") : GETPOST("socid", "int");
  81. if ($user->socid) {
  82. $socid = $user->socid;
  83. }
  84. if ($socid < 0) {
  85. $socid = '';
  86. }
  87. $canedit = 1;
  88. if (empty($user->rights->agenda->myactions->read)) {
  89. accessforbidden();
  90. }
  91. if (empty($user->rights->agenda->allactions->read)) {
  92. $canedit = 0;
  93. }
  94. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  95. //$filtert = $user->id;
  96. }
  97. $action = GETPOST('action', 'aZ09');
  98. $mode = GETPOST('mode', 'aZ09');
  99. if (empty($mode) && preg_match('/show_/', $action)) {
  100. $mode = $action; // For backward compatibility
  101. }
  102. $resourceid = GETPOST("search_resourceid", "int");
  103. $year = GETPOST("year", "int") ? GETPOST("year", "int") : date("Y");
  104. $month = GETPOST("month", "int") ? GETPOST("month", "int") : date("m");
  105. $week = GETPOST("week", "int") ? GETPOST("week", "int") : date("W");
  106. $day = GETPOST("day", "int") ? GETPOST("day", "int") : date("d");
  107. $pid = GETPOST("search_projectid", "int", 3) ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
  108. $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1
  109. $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
  110. $maxprint = GETPOSTISSET("maxprint") ? GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW;
  111. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  112. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
  113. if ($dateselect > 0) {
  114. $day = GETPOST('dateselectday', 'int');
  115. $month = GETPOST('dateselectmonth', 'int');
  116. $year = GETPOST('dateselectyear', 'int');
  117. }
  118. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  119. if (GETPOST('search_actioncode', 'array:aZ09')) {
  120. $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
  121. if (!count($actioncode)) {
  122. $actioncode = '0';
  123. }
  124. } else {
  125. $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : ((empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  126. }
  127. if ($status == '' && !GETPOSTISSET('search_status')) {
  128. $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  129. }
  130. $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  131. $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
  132. if (empty($mode) && !GETPOSTISSET('mode')) {
  133. $mode = $defaultview;
  134. }
  135. if ($mode == 'default') { // When action is default, we want a calendar view and not the list
  136. $mode = (($defaultview != 'show_list') ? $defaultview : 'show_month');
  137. }
  138. if (GETPOST('viewcal', 'int') && GETPOST('mode', 'alpha') != 'show_day' && GETPOST('mode', 'alpha') != 'show_week') {
  139. $mode = 'show_month';
  140. $day = '';
  141. } // View by month
  142. if (GETPOST('viewweek', 'int') || GETPOST('mode', 'alpha') == 'show_week') {
  143. $mode = 'show_week';
  144. $week = ($week ? $week : date("W"));
  145. $day = ($day ? $day : date("d"));
  146. } // View by week
  147. if (GETPOST('viewday', 'int') || GETPOST('mode', 'alpha') == 'show_day') {
  148. $mode = 'show_day';
  149. $day = ($day ? $day : date("d"));
  150. } // View by day
  151. $object = new ActionComm($db);
  152. // Load translation files required by the page
  153. $langs->loadLangs(array('agenda', 'other', 'commercial'));
  154. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  155. $hookmanager->initHooks(array('agenda'));
  156. $result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  157. if ($user->socid && $socid) {
  158. $result = restrictedArea($user, 'societe', $socid);
  159. }
  160. /*
  161. * Actions
  162. */
  163. if (GETPOST("viewlist", 'alpha') || $mode == 'show_list') {
  164. $param = '';
  165. if (is_array($_POST)) {
  166. foreach ($_POST as $key => $val) {
  167. if ($key == 'token') {
  168. continue;
  169. }
  170. $param .= '&' . $key . '=' . urlencode($val);
  171. }
  172. }
  173. if (!preg_match('/action=/', $param)) {
  174. $param .= ($param ? '&' : '') . 'mode=show_list';
  175. }
  176. //print $param;
  177. header("Location: " . DOL_URL_ROOT . '/comm/action/list.php?' . $param);
  178. exit;
  179. }
  180. if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
  181. $param = '';
  182. if (is_array($_POST)) {
  183. foreach ($_POST as $key => $val) {
  184. if ($key == 'token') {
  185. continue;
  186. }
  187. $param .= '&' . $key . '=' . urlencode($val);
  188. }
  189. }
  190. //print $param;
  191. header("Location: " . DOL_URL_ROOT . '/comm/action/peruser.php?' . $param);
  192. exit;
  193. }
  194. /*
  195. if ($action == 'delete_action' && $user->rights->agenda->delete) {
  196. $event = new ActionComm($db);
  197. $event->fetch($actionid);
  198. $event->fetch_optionals();
  199. $event->fetch_userassigned();
  200. $event->oldcopy = dol_clone($event);
  201. $result = $event->delete();
  202. }
  203. */
  204. /*
  205. * View
  206. */
  207. $parameters = array(
  208. 'socid' => $socid,
  209. 'status' => $status,
  210. 'year' => $year,
  211. 'month' => $month,
  212. 'day' => $day,
  213. 'type' => $type,
  214. 'maxprint' => $maxprint,
  215. 'filter' => $filter,
  216. 'filtert' => $filtert,
  217. 'showbirthday' => $showbirthday,
  218. 'canedit' => $canedit,
  219. 'optioncss' => $optioncss,
  220. 'actioncode' => $actioncode,
  221. 'pid' => $pid,
  222. 'resourceid' => $resourceid,
  223. 'usergroup' => $usergroup,
  224. );
  225. $parameters = $agendaplus->completeParametersArray($parameters, $eventdetails, $eventproduct, $eventlocation);
  226. $reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  227. if ($reshook < 0) {
  228. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  229. }
  230. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  231. llxHeader('', $langs->trans("Agenda"), $help_url);
  232. $form = new Form($db);
  233. $companystatic = new Societe($db);
  234. $contactstatic = new Contact($db);
  235. $userstatic = new User($db);
  236. $now = dol_now();
  237. $nowarray = dol_getdate($now);
  238. $nowyear = $nowarray['year'];
  239. $nowmonth = $nowarray['mon'];
  240. $nowday = $nowarray['mday'];
  241. $listofextcals = array();
  242. // Define list of external calendars (global admin setup)
  243. if (empty($conf->global->AGENDA_DISABLE_EXT)) {
  244. $i = 0;
  245. while ($i < $MAXAGENDA) {
  246. $i++;
  247. $source = 'AGENDA_EXT_SRC' . $i;
  248. $name = 'AGENDA_EXT_NAME' . $i;
  249. $offsettz = 'AGENDA_EXT_OFFSETTZ' . $i;
  250. $color = 'AGENDA_EXT_COLOR' . $i;
  251. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $i;
  252. $buggedfile = 'AGENDA_EXT_BUGGEDFILE' . $i;
  253. if (getDolGlobalString($source) && getDolGlobalString($name)) {
  254. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  255. $listofextcals[] = array(
  256. 'src' => getDolGlobalString($source),
  257. 'name' => dol_string_nohtmltag(getDolGlobalString($name)),
  258. 'offsettz' => (int) getDolGlobalInt($offsettz, 0),
  259. 'color' => dol_string_nohtmltag(getDolGlobalString($color)),
  260. 'default' => dol_string_nohtmltag(getDolGlobalString($default)),
  261. 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', ''))
  262. );
  263. }
  264. }
  265. }
  266. // Define list of external calendars (user setup)
  267. if (empty($user->conf->AGENDA_DISABLE_EXT)) {
  268. $i = 0;
  269. while ($i < $MAXAGENDA) {
  270. $i++;
  271. $source = 'AGENDA_EXT_SRC_' . $user->id . '_' . $i;
  272. $name = 'AGENDA_EXT_NAME_' . $user->id . '_' . $i;
  273. $offsettz = 'AGENDA_EXT_OFFSETTZ_' . $user->id . '_' . $i;
  274. $color = 'AGENDA_EXT_COLOR_' . $user->id . '_' . $i;
  275. $enabled = 'AGENDA_EXT_ENABLED_' . $user->id . '_' . $i;
  276. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_' . $user->id . '_' . $i;
  277. $buggedfile = 'AGENDA_EXT_BUGGEDFILE_' . $user->id . '_' . $i;
  278. if (getDolUserString($source) && getDolUserString($name)) {
  279. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  280. $listofextcals[] = array(
  281. 'src' => getDolUserString($source),
  282. 'name' => dol_string_nohtmltag(getDolUserString($name)),
  283. 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
  284. 'color' => dol_string_nohtmltag(getDolUserString($color)),
  285. 'default' => dol_string_nohtmltag(getDolUserString($default)),
  286. 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '')
  287. );
  288. }
  289. }
  290. }
  291. if (empty($mode) || $mode == 'show_month') {
  292. $prev = dol_get_prev_month($month, $year);
  293. $prev_year = $prev['year'];
  294. $prev_month = $prev['month'];
  295. $next = dol_get_next_month($month, $year);
  296. $next_year = $next['year'];
  297. $next_month = $next['month'];
  298. $max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
  299. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
  300. // 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)
  301. $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 fo sunday
  302. $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
  303. if ($tmpday >= 1) {
  304. $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
  305. }
  306. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  307. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
  308. $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
  309. if ($next_day < 6) {
  310. $next_day += 7;
  311. }
  312. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  313. }
  314. if ($mode == 'show_week') {
  315. $prev = dol_get_first_day_week($day, $month, $year);
  316. $prev_year = $prev['prev_year'];
  317. $prev_month = $prev['prev_month'];
  318. $prev_day = $prev['prev_day'];
  319. $first_day = $prev['first_day'];
  320. $first_month = $prev['first_month'];
  321. $first_year = $prev['first_year'];
  322. $week = $prev['week'];
  323. $day = (int) $day;
  324. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  325. $next_year = $next['year'];
  326. $next_month = $next['month'];
  327. $next_day = $next['day'];
  328. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  329. $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
  330. $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
  331. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
  332. $tmpday = $first_day;
  333. }
  334. if ($mode == 'show_day') {
  335. $prev = dol_get_prev_day($day, $month, $year);
  336. $prev_year = $prev['year'];
  337. $prev_month = $prev['month'];
  338. $prev_day = $prev['day'];
  339. $next = dol_get_next_day($day, $month, $year);
  340. $next_year = $next['year'];
  341. $next_month = $next['month'];
  342. $next_day = $next['day'];
  343. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  344. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
  345. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  346. }
  347. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  348. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  349. //print dol_print_date($firstdaytoshow,'dayhour').' '.dol_print_date($lastdaytoshow,'dayhour');
  350. /*$title = $langs->trans("DoneAndToDoActions");
  351. if ($status == 'done') $title = $langs->trans("DoneActions");
  352. if ($status == 'todo') $title = $langs->trans("ToDoActions");
  353. */
  354. $param = '';
  355. if ($actioncode || GETPOSTISSET('search_actioncode')) {
  356. if (is_array($actioncode)) {
  357. foreach ($actioncode as $str_action) {
  358. $param .= "&search_actioncode[]=" . urlencode($str_action);
  359. }
  360. } else {
  361. $param .= "&search_actioncode=" . urlencode($actioncode);
  362. }
  363. }
  364. if ($resourceid > 0) {
  365. $param .= "&search_resourceid=" . urlencode($resourceid);
  366. }
  367. if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
  368. $param .= "&search_status=" . urlencode($status);
  369. }
  370. if ($filter) {
  371. $param .= "&search_filter=" . urlencode($filter);
  372. }
  373. if ($filtert) {
  374. $param .= "&search_filtert=" . urlencode($filtert);
  375. }
  376. if ($usergroup > 0) {
  377. $param .= "&search_usergroup=" . urlencode($usergroup);
  378. }
  379. if ($socid > 0) {
  380. $param .= "&search_socid=" . urlencode($socid);
  381. }
  382. if ($showbirthday) {
  383. $param .= "&search_showbirthday=1";
  384. }
  385. if ($pid) {
  386. $param .= "&search_projectid=" . urlencode($pid);
  387. }
  388. if ($type) {
  389. $param .= "&search_type=" . urlencode($type);
  390. }
  391. // new filters (event_details, event products, event location from)
  392. $param .= $agendaplus->completeParamString($eventdetails, $eventproduct, $eventlocation);
  393. $param .= "&maxprint=" . urlencode($maxprint);
  394. if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') {
  395. $param .= '&mode=' . urlencode($mode);
  396. }
  397. // Show navigation bar
  398. if (empty($mode) || $mode == 'show_month') {
  399. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . $param . "\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  400. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
  401. $nav .= " </span>\n";
  402. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . $param . "\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  403. if (empty($conf->dol_optimize_smallscreen)) {
  404. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&month=" . $nowmonth . $param . "\">" . $langs->trans("Today") . "</a> ";
  405. }
  406. $picto = 'calendar';
  407. }
  408. if ($mode == 'show_week') {
  409. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . "&day=" . $prev_day . $param . "\"><i class=\"fa fa-chevron-left\" title=\"" . dol_escape_htmltag($langs->trans("Previous")) . "\"></i></a> &nbsp;\n";
  410. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y") . ", " . $langs->trans("Week") . " " . $week;
  411. $nav .= " </span>\n";
  412. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . "&day=" . $next_day . $param . "\"><i class=\"fa fa-chevron-right\" title=\"" . dol_escape_htmltag($langs->trans("Next")) . "\"></i></a>\n";
  413. if (empty($conf->dol_optimize_smallscreen)) {
  414. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&month=" . $nowmonth . "&day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a> ";
  415. }
  416. $picto = 'calendarweek';
  417. }
  418. if ($mode == 'show_day') {
  419. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . "&day=" . $prev_day . $param . "\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  420. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
  421. $nav .= " </span>\n";
  422. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . "&day=" . $next_day . $param . "\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  423. if (empty($conf->dol_optimize_smallscreen)) {
  424. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&amp;month=" . $nowmonth . "&amp;day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a> ";
  425. }
  426. $picto = 'calendarday';
  427. }
  428. $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
  429. //$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
  430. $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
  431. // Must be after the nav definition
  432. $paramnodate = $param;
  433. $param .= '&year=' . $year . '&month=' . $month . ($day ? '&day=' . $day : '');
  434. //print 'x'.$param;
  435. /*$tabactive = '';
  436. if ($mode == 'show_month') $tabactive = 'cardmonth';
  437. if ($mode == 'show_week') $tabactive = 'cardweek';
  438. if ($mode == 'show_day') $tabactive = 'cardday';
  439. if ($mode == 'show_list') $tabactive = 'cardlist';
  440. if ($mode == 'show_pertuser') $tabactive = 'cardperuser';
  441. if ($mode == 'show_pertype') $tabactive = 'cardpertype';
  442. */
  443. $paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
  444. $paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
  445. $head = calendars_prepare_head($paramnoaction);
  446. print '<form method="POST" id="searchFormList" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  447. if ($optioncss != '') {
  448. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  449. }
  450. print '<input type="hidden" name="token" value="' . newToken() . '">';
  451. print '<input type="hidden" name="mode" value="' . $mode . '">';
  452. //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  453. //print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
  454. //print dol_get_fiche_end();
  455. $viewmode = '';
  456. $viewmode .= '<a class="btnTitle reposition" href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&restore_lastsearch_values=1' . $paramnoactionodate . '">';
  457. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  458. $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
  459. //$viewmode .= '</span>';
  460. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewList") . '</span></a>';
  461. $viewmode .= '<a class="btnTitle' . ($mode == 'show_month' ? ' btnTitleSelected' : '') . ' reposition" href="' . DOL_URL_ROOT . '/comm/action/index.php?mode=show_month&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  462. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  463. $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
  464. //$viewmode .= '</span>';
  465. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewCal") . '</span></a>';
  466. $viewmode .= '<a class="btnTitle' . ($mode == 'show_week' ? ' btnTitleSelected' : '') . ' reposition" href="' . DOL_URL_ROOT . '/comm/action/index.php?mode=show_week&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  467. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  468. $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
  469. //$viewmode .= '</span>';
  470. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewWeek") . '</span></a>';
  471. $viewmode .= '<a class="btnTitle' . ($mode == 'show_day' ? ' btnTitleSelected' : '') . ' reposition" href="' . DOL_URL_ROOT . '/comm/action/index.php?mode=show_day&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  472. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  473. $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
  474. //$viewmode .= '</span>';
  475. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewDay") . '</span></a>';
  476. $viewmode .= '<a class="btnTitle reposition" href="' . DOL_URL_ROOT . '/comm/action/peruser.php?mode=show_peruser&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  477. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  478. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  479. //$viewmode .= '</span>';
  480. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewPerUser") . '</span></a>';
  481. // Add more views from hooks
  482. $parameters = array();
  483. $object = null;
  484. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  485. if (empty($reshook)) {
  486. $viewmode .= $hookmanager->resPrint;
  487. } elseif ($reshook > 1) {
  488. $viewmode = $hookmanager->resPrint;
  489. }
  490. $viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
  491. $newcardbutton = '';
  492. $newparam = '';
  493. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  494. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  495. $newparam .= '&month=' . ((int) $month) . '&year=' . ((int) $tmpforcreatebutton['year']) . '&mode=' . urlencode($mode);
  496. //$param='month='.$monthshown.'&year='.$year;
  497. $hourminsec = dol_print_date(dol_mktime(10, 0, 0, 1, 1, 1970, 'gmt'), '%H', 'gmt') . '0000'; // Set $hourminsec to '100000' to auto set hour to 10:00 at creation
  498. //$newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/comm/action/card.php?action=create&datep=' . sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']) . $hourminsec . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . ($newparam ? '?' . $newparam : '')));
  499. }
  500. // Define the legend/list of calendard to show
  501. $s = '';
  502. $link = '';
  503. $showextcals = $listofextcals;
  504. if (!empty($conf->use_javascript_ajax)) { // If javascript on
  505. $s .= "\n" . '<!-- Div to calendars selectors -->' . "\n";
  506. $s .= '<script type="text/javascript">' . "\n";
  507. $s .= 'jQuery(document).ready(function () {' . "\n";
  508. $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });' . "\n";
  509. $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });' . "\n";
  510. if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
  511. // Code to enable drag and drop
  512. $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {' . "\n";
  513. // Code to submit form
  514. $s .= 'console.log("submit form to record new event");' . "\n";
  515. //$s.='console.log(event.target);';
  516. $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");' . "\n";
  517. $s .= 'console.log("found parent div.dayevent with id = "+newval);' . "\n";
  518. $s .= 'var frm=jQuery("#searchFormList");' . "\n";
  519. $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");' . "\n";
  520. $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");' . "\n";
  521. $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}' . "\n";
  522. $s .= '});' . "\n";
  523. }
  524. $s .= '});' . "\n";
  525. $s .= '</script>' . "\n";
  526. // Local calendar
  527. //$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
  528. // Holiday calendar
  529. //$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="check_holiday"'.($check_holiday ? ' checked' : '').'><label for="check_holiday"> <span class="check_holiday_text">'.$langs->trans("Holidays").'</span></label> &nbsp; </div>';
  530. // External calendars
  531. if (is_array($showextcals) && count($showextcals) > 0) {
  532. $s .= '<script type="text/javascript">' . "\n";
  533. $s .= 'jQuery(document).ready(function () {
  534. jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
  535. var name = jQuery(elem).attr("name");
  536. if (jQuery(elem).is(":checked")) {
  537. jQuery(".family_ext" + name.replace("check_ext", "")).show();
  538. } else {
  539. jQuery(".family_ext" + name.replace("check_ext", "")).hide();
  540. }
  541. });
  542. jQuery("div input[name^=\"check_ext\"]").click(function() {
  543. var name = $(this).attr("name");
  544. jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
  545. });
  546. });' . "\n";
  547. $s .= '</script>' . "\n";
  548. foreach ($showextcals as $val) {
  549. $htmlname = md5($val['name']);
  550. if (!empty($val['default']) || GETPOST('check_ext' . $htmlname, 'int')) {
  551. $default = "checked";
  552. } else {
  553. $default = '';
  554. }
  555. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" value="1" ' . $default . '> <label for="check_ext' . $htmlname . '">' . dol_escape_htmltag($val['name']) . '</label> &nbsp; </div>';
  556. }
  557. }
  558. // Birthdays
  559. //$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
  560. // Calendars from hooks
  561. $parameters = array();
  562. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  563. if (empty($reshook)) {
  564. $s .= $hookmanager->resPrint;
  565. } elseif ($reshook > 1) {
  566. $s = $hookmanager->resPrint;
  567. }
  568. $s .= "\n" . '<!-- End div to calendars selectors -->' . "\n";
  569. } else { // If javascript off
  570. $newparam = $param; // newparam is for birthday links
  571. $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday=' . (empty($showbirthday) ? 1 : 0), $newparam);
  572. if (!preg_match('/showbirthday=/i', $newparam)) {
  573. $newparam .= '&showbirthday=1';
  574. }
  575. $link = '<a href="' . $_SERVER['PHP_SELF'] . '?' . dol_escape_htmltag($newparam);
  576. $link .= '">';
  577. if (empty($showbirthday)) {
  578. $link .= $langs->trans("AgendaShowBirthdayEvents");
  579. } else {
  580. $link .= $langs->trans("AgendaHideBirthdayEvents");
  581. }
  582. $link .= '</a>';
  583. }
  584. // Load events from database into $eventarray
  585. $eventarray = array();
  586. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  587. $sql = 'SELECT ';
  588. if ($usergroup > 0) {
  589. $sql .= " DISTINCT";
  590. }
  591. $sql .= $agendaplus->completeSqlSelectString($eventdetails, $eventproduct, $eventlocation);
  592. $sql .= ' a.id, a.label,';
  593. $sql .= ' a.datep,';
  594. $sql .= ' a.datep2,';
  595. $sql .= ' a.percent,';
  596. $sql .= ' a.fk_user_author,a.fk_user_action,';
  597. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  598. $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
  599. $sql .= ' a.fk_element, a.elementtype,';
  600. $sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
  601. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_actioncomm as ca, ' . MAIN_DB_PREFIX . "actioncomm as a";
  602. $sql .= $agendaplus->completeSqlFromString($eventlocation);
  603. if (empty($user->rights->societe->client->voir) && !$socid) {
  604. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  605. }
  606. // We must filter on resource table
  607. if ($resourceid > 0) {
  608. $sql .= ", " . MAIN_DB_PREFIX . "element_resources as r";
  609. }
  610. // We must filter on assignement table
  611. if ($filtert > 0 || $usergroup > 0) {
  612. $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar";
  613. }
  614. if ($usergroup > 0) {
  615. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  616. }
  617. $sql .= ' WHERE a.fk_action = ca.id';
  618. $sql .= ' AND a.entity IN (' . getEntity('agenda') . ')';
  619. // Condition on actioncode
  620. if (!empty($actioncode)) {
  621. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  622. if ($actioncode == 'AC_NON_AUTO') {
  623. $sql .= " AND ca.type != 'systemauto'";
  624. } elseif ($actioncode == 'AC_ALL_AUTO') {
  625. $sql .= " AND ca.type = 'systemauto'";
  626. } else {
  627. if ($actioncode == 'AC_OTH') {
  628. $sql .= " AND ca.type != 'systemauto'";
  629. }
  630. if ($actioncode == 'AC_OTH_AUTO') {
  631. $sql .= " AND ca.type = 'systemauto'";
  632. }
  633. }
  634. } else {
  635. if ($actioncode == 'AC_NON_AUTO') {
  636. $sql .= " AND ca.type != 'systemauto'";
  637. } elseif ($actioncode == 'AC_ALL_AUTO') {
  638. $sql .= " AND ca.type = 'systemauto'";
  639. } else {
  640. if (is_array($actioncode)) {
  641. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", $actioncode) . "'", 1) . ")";
  642. } else {
  643. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", explode(',', $actioncode)) . "'", 1) . ")";
  644. }
  645. }
  646. }
  647. }
  648. if ($resourceid > 0) {
  649. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . ((int) $resourceid);
  650. }
  651. if ($pid) {
  652. $sql .= " AND a.fk_project=" . ((int) $pid);
  653. }
  654. if (empty($user->rights->societe->client->voir) && !$socid) {
  655. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . ((int) $user->id) . ")";
  656. }
  657. if ($socid > 0) {
  658. $sql .= " AND a.fk_soc = " . ((int) $socid);
  659. }
  660. // We must filter on assignement table
  661. if ($filtert > 0 || $usergroup > 0) {
  662. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  663. }
  664. //var_dump($day.' '.$month.' '.$year);
  665. if ($mode == 'show_day') {
  666. $sql .= " AND (";
  667. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  668. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  669. $sql .= " OR ";
  670. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  671. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  672. $sql .= " OR ";
  673. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  674. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  675. $sql .= ')';
  676. } else {
  677. // To limit array
  678. $sql .= " AND (";
  679. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'"; // Start 7 days before
  680. $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
  681. $sql .= " OR ";
  682. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  683. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  684. $sql .= " OR ";
  685. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  686. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  687. $sql .= ')';
  688. }
  689. if ($type) {
  690. $sql .= " AND ca.id = " . ((int) $type);
  691. }
  692. if ($status == '0') {
  693. // To do (not started)
  694. $sql .= " AND a.percent = 0";
  695. }
  696. if ($status == 'na') {
  697. // Not applicable
  698. $sql .= " AND a.percent = -1";
  699. }
  700. if ($status == '50') {
  701. // Running already started
  702. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  703. }
  704. if ($status == 'done' || $status == '100') {
  705. $sql .= " AND (a.percent = 100)";
  706. }
  707. if ($status == 'todo') {
  708. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  709. }
  710. // We must filter on assignement table
  711. if ($filtert > 0 || $usergroup > 0) {
  712. $sql .= " AND (";
  713. if ($filtert > 0) {
  714. $sql .= "ar.fk_element = " . ((int) $filtert);
  715. }
  716. if ($usergroup > 0) {
  717. $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . ((int) $usergroup);
  718. }
  719. $sql .= ")";
  720. }
  721. // Sort on date
  722. $sql .= " AND ca.code = 'AC_EVENT'";
  723. $sql .= $agendaplus->completeSqlWhereString($eventdetails, $eventproduct, $eventlocation);
  724. $sql .= ' ORDER BY datep';
  725. //print $sql;
  726. //print_r($_REQUEST);
  727. //exit;
  728. dol_syslog("comm/action/index.php", LOG_DEBUG);
  729. $resql = $db->query($sql);
  730. if ($resql) {
  731. $num = $db->num_rows($resql);
  732. $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
  733. $i = 0;
  734. while ($i < $num && $i < $MAXONSAMEPAGE) {
  735. $obj = $db->fetch_object($resql);
  736. // Discard auto action if option is on
  737. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
  738. $i++;
  739. continue;
  740. }
  741. // Create a new object action
  742. $event = new ActionComm($db);
  743. $event->id = $obj->id;
  744. $event->ref = $event->id;
  745. $event->fulldayevent = $obj->fulldayevent;
  746. // event->datep and event->datef must be GMT date.
  747. if ($event->fulldayevent) {
  748. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  749. $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
  750. $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
  751. } else {
  752. // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
  753. $event->datep = $db->jdate($obj->datep, 'tzserver');
  754. $event->datef = $db->jdate($obj->datep2, 'tzserver');
  755. }
  756. //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
  757. //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
  758. //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
  759. $event->type_code = $obj->type_code;
  760. $event->type_label = $obj->type_label;
  761. $event->type_color = $obj->type_color;
  762. $event->type = $obj->type_type;
  763. $event->type_picto = $obj->type_picto;
  764. $event->libelle = $obj->label; // deprecated
  765. $event->label = $obj->label;
  766. $event->percentage = $obj->percent;
  767. $event->authorid = $obj->fk_user_author; // user id of creator
  768. $event->userownerid = $obj->fk_user_action; // user id of owner
  769. $event->fetch_userassigned(); // This load $event->userassigned
  770. $event->priority = $obj->priority;
  771. $event->location = $obj->location;
  772. $event->transparency = $obj->transparency;
  773. $event->fk_element = $obj->fk_element;
  774. $event->elementtype = $obj->elementtype;
  775. $event->fk_project = $obj->fk_project;
  776. $event->socid = $obj->fk_soc;
  777. $event->contact_id = $obj->fk_contact;
  778. // Defined date_start_in_calendar and date_end_in_calendar property
  779. // They are date start and end of action but modified to not be outside calendar view.
  780. $event->date_start_in_calendar = $event->datep;
  781. if ($event->datef != '' && $event->datef >= $event->datep) {
  782. $event->date_end_in_calendar = $event->datef;
  783. } else {
  784. $event->date_end_in_calendar = $event->datep;
  785. }
  786. // Check values
  787. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  788. // This record is out of visible range
  789. } else {
  790. if ($event->date_start_in_calendar < $firstdaytoshow) {
  791. $event->date_start_in_calendar = $firstdaytoshow;
  792. }
  793. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  794. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  795. }
  796. // Add an entry in actionarray for each day
  797. $daycursor = $event->date_start_in_calendar;
  798. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  799. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  800. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  801. $daycursorend = $event->date_end_in_calendar;
  802. $anneeend = dol_print_date($daycursorend, '%Y', 'tzuserrel');
  803. $moisend = dol_print_date($daycursorend, '%m', 'tzuserrel');
  804. $jourend = dol_print_date($daycursorend, '%d', 'tzuserrel');
  805. //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
  806. //var_dump($annee.'-'.$mois.'-'.$jour);
  807. //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
  808. // Loop on each day covered by action to prepare an index to show on calendar
  809. $loop = true;
  810. $j = 0;
  811. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
  812. $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
  813. /*
  814. print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
  815. print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
  816. print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  817. print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
  818. print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
  819. print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  820. */
  821. do {
  822. //if ($event->id==408)
  823. //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'gmt').' - '.dol_print_date($event->datep, 'dayhour', 'gmt').' '.dol_print_date($event->datef, 'dayhour', 'gmt').'<br>';
  824. //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'tzuserrel').' - '.dol_print_date($event->datep, 'dayhour', 'tzuserrel').' '.dol_print_date($event->datef, 'dayhour', 'tzuserrel').'<br>';
  825. $eventarray[$daykey][] = $event;
  826. $j++;
  827. $daykey += 60 * 60 * 24;
  828. //if ($daykey > $event->date_end_in_calendar) {
  829. if ($daykey > $daykeyend) {
  830. $loop = false;
  831. }
  832. } while ($loop);
  833. //var_dump($eventarray);
  834. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  835. //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>';
  836. }
  837. $i++;
  838. }
  839. } else {
  840. dol_print_error($db);
  841. }
  842. //var_dump($eventarray);
  843. // LEAVE CALENDAR
  844. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
  845. $sql .= " FROM " . MAIN_DB_PREFIX . "holiday as x, " . MAIN_DB_PREFIX . "user as u";
  846. $sql .= " WHERE u.rowid = x.fk_user";
  847. $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
  848. $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
  849. if ($mode == 'show_day') {
  850. // Request only leaves for the current selected day
  851. $sql .= " AND '" . $db->escape($year) . "-" . $db->escape($month) . "-" . $db->escape($day) . "' BETWEEN x.date_debut AND x.date_fin"; // date_debut and date_fin are date without time
  852. } elseif ($mode == 'show_week') {
  853. // TODO: Add filter to reduce database request
  854. } elseif ($mode == 'show_month') {
  855. // TODO: Add filter to reduce database request
  856. }
  857. //print $sql;
  858. $resql = $db->query($sql);
  859. if ($resql) {
  860. $num = $db->num_rows($resql);
  861. $i = 0;
  862. while ($i < $num) {
  863. $obj = $db->fetch_object($resql);
  864. $event = new ActionComm($db);
  865. // Need the id of the leave object for link to it
  866. $event->id = $obj->rowid;
  867. $event->ref = $event->id;
  868. $event->type_code = 'HOLIDAY';
  869. $event->type_label = '';
  870. $event->type_color = '';
  871. $event->type = 'holiday';
  872. $event->type_picto = 'holiday';
  873. $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
  874. $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
  875. $event->date_start_in_calendar = $event->datep;
  876. $event->date_end_in_calendar = $event->datef;
  877. if ($obj->status == 3) {
  878. // Show no symbol for leave with state "leave approved"
  879. $event->percentage = -1;
  880. } elseif ($obj->status == 2) {
  881. // Show TO-DO symbol for leave with state "leave wait for approval"
  882. $event->percentage = 0;
  883. }
  884. if ($obj->halfday == 1) {
  885. $event->label = $obj->lastname . ' (' . $langs->trans("Morning") . ')';
  886. } elseif ($obj->halfday == -1) {
  887. $event->label = $obj->lastname . ' (' . $langs->trans("Afternoon") . ')';
  888. } else {
  889. $event->label = $obj->lastname;
  890. }
  891. $daycursor = $event->date_start_in_calendar;
  892. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  893. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  894. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  895. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  896. do {
  897. $eventarray[$daykey][] = $event;
  898. $daykey += 60 * 60 * 24;
  899. } while ($daykey <= $event->date_end_in_calendar);
  900. $i++;
  901. }
  902. }
  903. // EXTERNAL CALENDAR
  904. // Complete $eventarray with external import Ical
  905. if (count($listofextcals)) {
  906. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/ical.class.php';
  907. foreach ($listofextcals as $extcal) {
  908. $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
  909. $namecal = $extcal['name'];
  910. $offsettz = $extcal['offsettz'];
  911. $colorcal = $extcal['color'];
  912. $buggedfile = $extcal['buggedfile'];
  913. $ical = new ICal();
  914. $ical->parse($url);
  915. // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
  916. //var_dump($ical->cal); exit;
  917. $icalevents = array();
  918. if (is_array($ical->get_event_list())) {
  919. $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
  920. }
  921. if (is_array($ical->get_freebusy_list())) {
  922. $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
  923. }
  924. if (count($icalevents) > 0) {
  925. // Duplicate all repeatable events into new entries
  926. $moreicalevents = array();
  927. foreach ($icalevents as $icalevent) {
  928. if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) { //repeatable event
  929. //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  930. //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
  931. if ($icalevent['DTSTART;VALUE=DATE']) { //fullday event
  932. $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
  933. $datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
  934. } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) {
  935. $datecurstart = $icalevent['DTSTART']['unixtime'];
  936. $datecurend = $icalevent['DTEND']['unixtime'];
  937. if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
  938. //var_dump($ical->cal);
  939. $tmpcurstart = $datecurstart;
  940. $tmpcurend = $datecurend;
  941. $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
  942. $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
  943. //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
  944. // Edit datecurstart and datecurend
  945. if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
  946. $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
  947. } else {
  948. $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
  949. }
  950. if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
  951. $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
  952. } else {
  953. $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
  954. }
  955. }
  956. // datecurstart and datecurend are now GMT date
  957. //var_dump($datecurstart); var_dump($datecurend); exit;
  958. } else {
  959. // Not a recongized record
  960. dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
  961. continue;
  962. }
  963. //print 'xx'.$datecurstart;exit;
  964. $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
  965. $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
  966. $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
  967. if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
  968. continue; // We discard repeatable event that end before start date to show
  969. }
  970. if ($datecurstart >= $lastdaytoshow) {
  971. continue; // We discard repeatable event that start after end date to show
  972. }
  973. $numofevent = 0;
  974. while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
  975. if ($datecurend >= $firstdaytoshow) { // We add event
  976. $newevent = $icalevent;
  977. unset($newevent['RRULE']);
  978. if ($icalevent['DTSTART;VALUE=DATE']) {
  979. $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
  980. $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
  981. } else {
  982. $newevent['DTSTART'] = $datecurstart;
  983. $newevent['DTEND'] = $datecurend;
  984. }
  985. $moreicalevents[] = $newevent;
  986. }
  987. // Jump on next occurence
  988. $numofevent++;
  989. $savdatecurstart = $datecurstart;
  990. if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
  991. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
  992. $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
  993. }
  994. if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
  995. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
  996. $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
  997. } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
  998. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
  999. $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
  1000. } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
  1001. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
  1002. $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
  1003. }
  1004. // Test to avoid infinite loop ($datecurstart must increase)
  1005. if ($savdatecurstart >= $datecurstart) {
  1006. dol_syslog("Found a rule freq " . $icalevent['RRULE']['FREQ'] . " not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
  1007. $datecurstart += 3600 * 24 * 7;
  1008. $datecurend += 3600 * 24 * 7;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. $icalevents = array_merge($icalevents, $moreicalevents);
  1014. // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
  1015. foreach ($icalevents as $icalevent) {
  1016. //var_dump($icalevent);
  1017. //print $icalevent['SUMMARY'].'->';
  1018. //var_dump($icalevent);exit;
  1019. if (!empty($icalevent['RRULE'])) {
  1020. continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
  1021. }
  1022. // Create a new object action
  1023. $event = new ActionComm($db);
  1024. $addevent = false;
  1025. if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
  1026. // For full day events, date are also GMT but they wont but converted using tz during output
  1027. $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
  1028. if (empty($icalevent['DTEND;VALUE=DATE'])) {
  1029. $dateend = $datestart + 86400 - 1;
  1030. } else {
  1031. $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
  1032. }
  1033. //print 'x'.$datestart.'-'.$dateend;exit;
  1034. //print dol_print_date($dateend,'dayhour','gmt');
  1035. $event->fulldayevent = 1;
  1036. $addevent = true;
  1037. } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
  1038. $datestart = $icalevent['DTSTART'];
  1039. $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
  1040. $datestart += + ($offsettz * 3600);
  1041. $dateend += + ($offsettz * 3600);
  1042. $addevent = true;
  1043. //var_dump($offsettz);
  1044. //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
  1045. } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
  1046. $datestart = $icalevent['DTSTART']['unixtime'];
  1047. $dateend = $icalevent['DTEND']['unixtime'];
  1048. $datestart += + ($offsettz * 3600);
  1049. $dateend += + ($offsettz * 3600);
  1050. // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
  1051. 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
  1052. // TODO
  1053. }
  1054. // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
  1055. if ($buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
  1056. $localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
  1057. $localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
  1058. $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
  1059. $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
  1060. $tmps = -1 * $localtzs->getOffset($localdts);
  1061. $tmpe = -1 * $localtze->getOffset($localdte);
  1062. $datestart += $tmps;
  1063. $dateend += $tmpe;
  1064. //var_dump($datestart);
  1065. }
  1066. $addevent = true;
  1067. }
  1068. if ($addevent) {
  1069. $event->id = $icalevent['UID'];
  1070. $event->ref = $event->id;
  1071. $userId = $userstatic->findUserIdByEmail($namecal);
  1072. if (!empty($userId) && $userId > 0) {
  1073. $event->userassigned[$userId] = $userId;
  1074. $event->percentage = -1;
  1075. }
  1076. $event->type_code = "ICALEVENT";
  1077. $event->type_label = $namecal;
  1078. $event->type_color = $colorcal;
  1079. $event->type = 'icalevent';
  1080. $event->type_picto = 'rss';
  1081. $event->icalname = $namecal;
  1082. $event->icalcolor = $colorcal;
  1083. $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.
  1084. $event->datep = $datestart + $usertime;
  1085. $event->datef = $dateend + $usertime;
  1086. if ($icalevent['SUMMARY']) {
  1087. $event->label = dol_string_nohtmltag($icalevent['SUMMARY']);
  1088. } elseif ($icalevent['DESCRIPTION']) {
  1089. $event->label = dol_nl2br(dol_string_nohtmltag($icalevent['DESCRIPTION']), 1);
  1090. } else {
  1091. $event->label = $langs->trans("ExtSiteNoLabel");
  1092. }
  1093. // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
  1094. // LOW = 0 to 4
  1095. // MEDIUM = 5
  1096. // HIGH = 6 to 9
  1097. if (!empty($icalevent['PRIORITY'])) {
  1098. $event->priority = $icalevent['PRIORITY'];
  1099. }
  1100. // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
  1101. if (!empty($icalevent['TRANSP'])) {
  1102. if ($icalevent['TRANSP'] == "TRANSPARENT") {
  1103. $event->transparency = 0; // 0 = available / free
  1104. }
  1105. if ($icalevent['TRANSP'] == "OPAQUE") {
  1106. $event->transparency = 1; // 1 = busy
  1107. }
  1108. // TODO: MS outlook states
  1109. // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
  1110. // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
  1111. // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
  1112. // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
  1113. // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
  1114. }
  1115. if (!empty($icalevent['LOCATION'])) {
  1116. $event->location = $icalevent['LOCATION'];
  1117. }
  1118. $event->date_start_in_calendar = $event->datep;
  1119. if ($event->datef != '' && $event->datef >= $event->datep) {
  1120. $event->date_end_in_calendar = $event->datef;
  1121. } else {
  1122. $event->date_end_in_calendar = $event->datep;
  1123. }
  1124. // Add event into $eventarray if date range are ok.
  1125. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  1126. //print 'x'.$datestart.'-'.$dateend;exit;
  1127. //print 'x'.$datestart.'-'.$dateend;exit;
  1128. //print 'x'.$datestart.'-'.$dateend;exit;
  1129. // This record is out of visible range
  1130. } else {
  1131. if ($event->date_start_in_calendar < $firstdaytoshow) {
  1132. $event->date_start_in_calendar = $firstdaytoshow;
  1133. }
  1134. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  1135. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  1136. }
  1137. // Add an entry in actionarray for each day
  1138. $daycursor = $event->date_start_in_calendar;
  1139. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  1140. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  1141. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  1142. // Loop on each day covered by action to prepare an index to show on calendar
  1143. $loop = true;
  1144. $j = 0;
  1145. // daykey must be date that represent day box in calendar so must be a user time
  1146. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  1147. $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  1148. do {
  1149. //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').' ';
  1150. $eventarray[$daykey][] = $event;
  1151. $daykey += 60 * 60 * 24;
  1152. $daykeygmt += 60 * 60 * 24; // Add one day
  1153. if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
  1154. $loop = false;
  1155. }
  1156. } while ($loop);
  1157. }
  1158. }
  1159. }
  1160. }
  1161. }
  1162. }
  1163. // Complete $eventarray with events coming from external module
  1164. $parameters = array();
  1165. $object = null;
  1166. $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
  1167. if (!empty($hookmanager->resArray['eventarray'])) {
  1168. foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
  1169. if (!isset($eventarray[$keyDate])) {
  1170. $eventarray[$keyDate] = array();
  1171. }
  1172. $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
  1173. }
  1174. }
  1175. // Sort events
  1176. foreach ($eventarray as $keyDate => &$dateeventarray) {
  1177. usort($dateeventarray, 'sort_events_by_date');
  1178. }
  1179. $maxnbofchar = 0;
  1180. $cachethirdparties = array();
  1181. $cachecontacts = array();
  1182. $cacheusers = array();
  1183. // Define theme_datacolor array
  1184. $color_file = DOL_DOCUMENT_ROOT . "/theme/" . $conf->theme . "/theme_vars.inc.php";
  1185. if (is_readable($color_file)) {
  1186. include $color_file;
  1187. }
  1188. if (!is_array($theme_datacolor)) {
  1189. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  1190. }
  1191. $massactionbutton = '';
  1192. print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav . '<span class="marginleftonly"></span>' . $newcardbutton, '', $limit, 1, 0, 1, $viewmode);
  1193. // Show div with list of calendars
  1194. print $s;
  1195. if (empty($mode) || $mode == 'show_month') { // View by month
  1196. $newparam = $param; // newparam is for birthday links
  1197. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  1198. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1199. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1200. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  1201. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  1202. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  1203. $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
  1204. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  1205. $newparam .= '&viewcal=1';
  1206. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1207. //print_r($_REQUEST);
  1208. $agendaplus->new_print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, $eventdetails, $eventproduct, $eventlocation, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1209. print '</div>';
  1210. print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
  1211. print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
  1212. print ' <tr class="liste_titre">';
  1213. // Column title of weeks numbers
  1214. echo ' <td class="center">#</td>';
  1215. $i = 0;
  1216. while ($i < 7) {
  1217. print ' <td class="center bold uppercase tdfordaytitle' . ($i == 0 ? ' borderleft' : '') . '">';
  1218. $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
  1219. if (!empty($conf->dol_optimize_smallscreen)) {
  1220. $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
  1221. print $langs->trans($labelshort[$numdayinweek]);
  1222. } else {
  1223. print $langs->trans("Day" . $numdayinweek);
  1224. }
  1225. print ' </td>' . "\n";
  1226. $i++;
  1227. }
  1228. echo ' </tr>' . "\n";
  1229. $todayarray = dol_getdate($now, 'fast');
  1230. $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
  1231. // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
  1232. //var_dump($eventarray);
  1233. for ($iter_week = 0; $iter_week < 6; $iter_week++) {
  1234. echo " <tr>\n";
  1235. // Get date of the current day, format 'yyyy-mm-dd'
  1236. if ($tmpday <= 0) { // If number of the current day is in previous month
  1237. $currdate0 = sprintf("%04d", $prev_year) . sprintf("%02d", $prev_month) . sprintf("%02d", $max_day_in_prev_month + $tmpday);
  1238. } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
  1239. $currdate0 = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $tmpday);
  1240. } else // If number of the current day is in next month
  1241. {
  1242. $currdate0 = sprintf("%04d", $next_year) . sprintf("%02d", $next_month) . sprintf("%02d", $tmpday - $max_day_in_month);
  1243. }
  1244. // Get week number for the targeted date '$currdate0'
  1245. $numweek0 = date("W", strtotime(date($currdate0)));
  1246. // Show the week number, and define column width
  1247. echo ' <td class="center weeknumber opacitymedium" width="2%">' . $numweek0 . '</td>';
  1248. for ($iter_day = 0; $iter_day < 7; $iter_day++) {
  1249. if ($tmpday <= 0) {
  1250. /* Show days before the beginning of the current month (previous month) */
  1251. $style = 'cal_other_month cal_past';
  1252. if ($iter_day == 6) {
  1253. $style .= ' cal_other_month_right';
  1254. }
  1255. echo ' <td class="' . $style . ' nowrap tdtop" width="14%">';
  1256. show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1257. echo " </td>\n";
  1258. } elseif ($tmpday <= $max_day_in_month) {
  1259. /* Show days of the current month */
  1260. $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
  1261. $style = 'cal_current_month';
  1262. if ($iter_day == 6) {
  1263. $style .= ' cal_current_month_right';
  1264. }
  1265. $today = 0;
  1266. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  1267. $today = 1;
  1268. }
  1269. if ($today) {
  1270. $style = 'cal_today';
  1271. }
  1272. if ($curtime < $todaytms) {
  1273. $style .= ' cal_past';
  1274. }
  1275. //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
  1276. echo ' <td class="' . $style . ' nowrap tdtop" width="14%">';
  1277. show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1278. echo "</td>\n";
  1279. } else {
  1280. /* Show days after the current month (next month) */
  1281. $style = 'cal_other_month';
  1282. if ($iter_day == 6) {
  1283. $style .= ' cal_other_month_right';
  1284. }
  1285. echo ' <td class="' . $style . ' nowrap tdtop" width="14%">';
  1286. show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1287. echo "</td>\n";
  1288. }
  1289. $tmpday++;
  1290. }
  1291. echo " </tr>\n";
  1292. }
  1293. print "</table>\n";
  1294. print '</div>';
  1295. print '<input type="hidden" name="actionmove" value="mupdate">';
  1296. print '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?mode=show_month&' . dol_escape_htmltag($_SERVER['QUERY_STRING']) . '">';
  1297. print '<input type="hidden" name="newdate" id="newdate">';
  1298. } elseif ($mode == 'show_week') {
  1299. // View by week
  1300. $newparam = $param; // newparam is for birthday links
  1301. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  1302. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1303. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1304. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  1305. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  1306. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  1307. $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
  1308. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  1309. $newparam .= '&viewweek=1';
  1310. print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  1311. $agendaplus->new_print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, $eventdetails, $eventproduct, $eventlocation, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1312. print '</div></div>';
  1313. print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
  1314. print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
  1315. print ' <tr class="liste_titre">';
  1316. $i = 0;
  1317. while ($i < 7) {
  1318. echo ' <td class="center bold uppercase tdfordaytitle">' . $langs->trans("Day" . (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7)) . "</td>\n";
  1319. $i++;
  1320. }
  1321. echo " </tr>\n";
  1322. echo " <tr>\n";
  1323. for ($iter_day = 0; $iter_day < 7; $iter_day++) {
  1324. // Show days of the current week
  1325. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
  1326. $tmpday = dol_print_date($curtime, '%d', 'tzuserrel');
  1327. $tmpmonth = dol_print_date($curtime, '%m', 'tzuserrel');
  1328. $tmpyear = dol_print_date($curtime, '%Y', 'tzuserrel');
  1329. $style = 'cal_current_month';
  1330. if ($iter_day == 6) {
  1331. $style .= ' cal_other_month_right';
  1332. }
  1333. $today = 0;
  1334. $todayarray = dol_getdate($now, 'fast');
  1335. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
  1336. $today = 1;
  1337. }
  1338. if ($today) {
  1339. $style = 'cal_today';
  1340. }
  1341. echo ' <td class="' . $style . '" width="14%" valign="top">';
  1342. show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  1343. echo " </td>\n";
  1344. }
  1345. echo " </tr>\n";
  1346. print "</table>\n";
  1347. print '</div>';
  1348. echo '<input type="hidden" name="actionmove" value="mupdate">';
  1349. echo '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?mode=show_week&' . dol_escape_htmltag($_SERVER['QUERY_STRING']) . '">';
  1350. echo '<input type="hidden" name="newdate" id="newdate">';
  1351. } else { // View by day
  1352. $newparam = $param; // newparam is for birthday links
  1353. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1354. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1355. $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
  1356. $newparam .= '&viewday=1';
  1357. // Code to show just one day
  1358. $style = 'cal_current_month cal_current_month_oneday';
  1359. $today = 0;
  1360. $todayarray = dol_getdate($now, 'fast');
  1361. if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  1362. $today = 1;
  1363. }
  1364. //if ($today) $style='cal_today';
  1365. $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
  1366. $arraytimestamp = dol_getdate($timestamp);
  1367. print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  1368. $agendaplus->new_print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, $eventdetails, $eventproduct, $eventlocation, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1369. print '</div></div>';
  1370. print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
  1371. echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
  1372. echo ' <tr class="tagtr liste_titre">';
  1373. echo ' <td class="tagtd center bold uppercase">' . $langs->trans("Day" . $arraytimestamp['wday']) . "</td>\n";
  1374. echo " </td>\n";
  1375. /*
  1376. echo ' <div class="tagtr">';
  1377. echo ' <div class="tagtd width100"></div>';
  1378. echo ' <div class="tagtd center">';
  1379. echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
  1380. echo ' </div>'."\n";
  1381. echo " </div>\n";
  1382. */
  1383. echo '</table>';
  1384. print '</div>';
  1385. /* WIP View per hour */
  1386. $useviewhour = 0;
  1387. if ($useviewhour) {
  1388. 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
  1389. $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
  1390. echo '<div style="max-height: ' . $maxheightwin . 'px;">';
  1391. echo '<div class="tagtable centpercent calendarviewcontainer">';
  1392. $maxnbofchar = 80;
  1393. $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
  1394. $minhour = round($tmp[0], 0);
  1395. $maxhour = round($tmp[1], 0);
  1396. if ($minhour > 23) {
  1397. $minhour = 23;
  1398. }
  1399. if ($maxhour < 1) {
  1400. $maxhour = 1;
  1401. }
  1402. if ($maxhour <= $minhour) {
  1403. $maxhour = $minhour + 1;
  1404. }
  1405. $i = 0;
  1406. $j = 0;
  1407. while ($i < 24) {
  1408. echo ' <div class="tagtr calendarviewcontainertr">' . "\n";
  1409. echo ' <div class="tagtd width100 tdtop">' . dol_print_date($i * 3600, 'hour', 'gmt') . '</div>';
  1410. echo ' <div class="tagtd ' . $style . ' tdtop"></div>' . "\n";
  1411. echo ' </div>' . "\n";
  1412. $i++;
  1413. $j++;
  1414. }
  1415. echo '</div></div>';
  1416. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
  1417. print '</div>';
  1418. } else {
  1419. 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
  1420. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
  1421. print '</div>';
  1422. }
  1423. }
  1424. print "\n" . '</form>';
  1425. // End of page
  1426. llxFooter();
  1427. $db->close();
  1428. /**
  1429. * Show event of a particular day
  1430. *
  1431. * @param DoliDB $db Database handler
  1432. * @param int $day Day
  1433. * @param int $month Month
  1434. * @param int $year Year
  1435. * @param int $monthshown Current month shown in calendar view
  1436. * @param string $style Style to use for this day
  1437. * @param array $eventarray Array of events
  1438. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  1439. * @param int $maxnbofchar Nb of characters to show for event line
  1440. * @param string $newparam Parameters on current URL
  1441. * @param int $showinfo Add extended information (used by day and week view)
  1442. * @param int $minheight Minimum height for each event. 60px by default.
  1443. * @param string $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
  1444. * @return void
  1445. */
  1446. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
  1447. {
  1448. global $user, $conf, $langs;
  1449. global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
  1450. global $theme_datacolor;
  1451. global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
  1452. if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
  1453. $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
  1454. }
  1455. $dateint = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1456. //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
  1457. print "\n";
  1458. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  1459. $urltoshow = DOL_URL_ROOT . '/comm/action/index.php?mode=show_day&day=' . str_pad($day, 2, "0", STR_PAD_LEFT) . '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year . $newparam;
  1460. $urltocreate = '';
  1461. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1462. $newparam .= '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year;
  1463. $hourminsec = '100000';
  1464. $urltocreate = 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 : ''));
  1465. }
  1466. // Line with title of day
  1467. print '<div id="dayevent_' . $dateint . '" class="dayevent tagtable centpercent nobordernopadding">' . "\n";
  1468. if ($nonew <= 0) {
  1469. print '<div class="tagtr cursorpointer" onclick="window.location=\'' . $urltocreate . '\';"><div class="nowrap tagtd"><div class="left inline-block">';
  1470. print '<a class="dayevent-aday" style="color: #666" href="' . $urltoshow . '">';
  1471. if ($showinfo) {
  1472. print dol_print_date($curtime, 'daytextshort');
  1473. } else {
  1474. print dol_print_date($curtime, '%d');
  1475. }
  1476. print '</a>';
  1477. print '</div><div class="nowrap floatright inline-block marginrightonly">';
  1478. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1479. print '<a class="cursoradd" href="' . $urltocreate . '">'; // Explicit link, usefull for nojs interfaces
  1480. print img_picto($langs->trans("NewAction"), 'edit_add.png');
  1481. print '</a>';
  1482. }
  1483. print '</div></div></div>' . "\n";
  1484. }
  1485. if ($nonew < 0) {
  1486. print '</div>';
  1487. return;
  1488. }
  1489. // Line with td contains all div of each events
  1490. print '<div class="tagtr">';
  1491. print '<div class="tagtd centpercent agendacell sortable">';
  1492. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  1493. $i = 0;
  1494. $ireallyshown = 0;
  1495. $itoshow = 0;
  1496. $numother = 0;
  1497. $numbirthday = 0;
  1498. $numical = 0;
  1499. $numicals = array();
  1500. $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1501. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  1502. $nextindextouse = is_array($colorindexused) ? count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
  1503. //var_dump($colorindexused);
  1504. include_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php';
  1505. $tmpholiday = new Holiday($db);
  1506. foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
  1507. $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1508. $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1509. $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1510. //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
  1511. if ($day == $jour && $month == $mois && $year == $annee) {
  1512. foreach ($eventarray[$daykey] as $index => $event) {
  1513. if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
  1514. $keysofuserassigned = array_keys($event->userassigned);
  1515. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1516. // Define $color (Hex string like '0088FF') and $cssclass of event
  1517. $color = -1;
  1518. $cssclass = '';
  1519. $colorindex = -1;
  1520. if (in_array($user->id, $keysofuserassigned)) {
  1521. $cssclass = 'family_mytasks';
  1522. if (empty($cacheusers[$event->userownerid])) {
  1523. $newuser = new User($db);
  1524. $newuser->fetch($event->userownerid);
  1525. $cacheusers[$event->userownerid] = $newuser;
  1526. }
  1527. //var_dump($cacheusers[$event->userownerid]->color);
  1528. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1529. if (!empty($cacheusers[$event->userownerid]->color)) {
  1530. $color = $cacheusers[$event->userownerid]->color;
  1531. }
  1532. } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
  1533. $numical++;
  1534. if (!empty($event->icalname)) {
  1535. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1536. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1537. }
  1538. $numicals[dol_string_nospecial($event->icalname)]++;
  1539. }
  1540. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1541. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1542. } elseif ($event->type_code == 'BIRTHDAY') {
  1543. $numbirthday++;
  1544. $colorindex = 2;
  1545. $cssclass = 'family_birthday ';
  1546. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1547. } else {
  1548. $numother++;
  1549. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1550. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1551. if (empty($cacheusers[$event->userownerid])) {
  1552. $newuser = new User($db);
  1553. $newuser->fetch($event->userownerid);
  1554. $cacheusers[$event->userownerid] = $newuser;
  1555. }
  1556. //var_dump($cacheusers[$event->userownerid]->color);
  1557. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1558. if (!empty($cacheusers[$event->userownerid]->color)) {
  1559. $color = $cacheusers[$event->userownerid]->color;
  1560. }
  1561. }
  1562. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1563. // Define color index if not yet defined
  1564. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1565. if (isset($colorindexused[$idusertouse])) {
  1566. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1567. } else {
  1568. $colorindex = $nextindextouse;
  1569. $colorindexused[$idusertouse] = $colorindex;
  1570. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1571. $nextindextouse++; // Prepare to use next color
  1572. }
  1573. }
  1574. //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
  1575. // Define color
  1576. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1577. }
  1578. $cssclass = $cssclass . ' eventday_' . $ymd;
  1579. // Defined style to disable drag and drop feature
  1580. if ($event->type_code == 'AC_OTH_AUTO') {
  1581. $cssclass .= " unmovable";
  1582. } elseif ($event->type_code == 'HOLIDAY') {
  1583. $cssclass .= " unmovable";
  1584. } elseif ($event->type_code == 'BIRTHDAY') {
  1585. $cssclass .= " unmovable";
  1586. } elseif ($event->type_code == 'ICALEVENT') {
  1587. $cssclass .= " unmovable";
  1588. } elseif ($event->date_start_in_calendar && $event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
  1589. // If the event is on several days
  1590. $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1591. $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1592. $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1593. //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
  1594. if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
  1595. $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
  1596. } else {
  1597. $cssclass .= ' movable cursormove';
  1598. }
  1599. } else {
  1600. if (
  1601. $user->rights->agenda->allactions->create ||
  1602. (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)
  1603. ) {
  1604. $cssclass .= " movable cursormove";
  1605. } else {
  1606. $cssclass .= " unmovable";
  1607. }
  1608. }
  1609. $h = '';
  1610. $nowrapontd = 1;
  1611. if ($mode == 'show_day') {
  1612. $h = 'height: 100%; ';
  1613. $nowrapontd = 0;
  1614. }
  1615. if ($mode == 'show_week') {
  1616. $h = 'height: 100%; ';
  1617. $nowrapontd = 0;
  1618. }
  1619. // Show event box
  1620. print "\n";
  1621. print '<!-- start event ' . $i . ' -->' . "\n";
  1622. $morecss = '';
  1623. if ($maxprint && $ireallyshown >= $maxprint) {
  1624. $morecss = 'showifmore';
  1625. }
  1626. if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
  1627. $morecss = 'hidden';
  1628. }
  1629. if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
  1630. $morecss = 'hidden';
  1631. }
  1632. if ($morecss != 'hidden') {
  1633. $itoshow++;
  1634. }
  1635. if ($morecss != 'showifmore' && $morecss != 'hidden') {
  1636. $ireallyshown++;
  1637. }
  1638. //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
  1639. print '<div id="event_' . $ymd . '_' . $i . '" class="event family_' . $event->type . ' ' . $cssclass . ($morecss ? ' ' . $morecss : '') . '"';
  1640. //print ' style="height: 100px;';
  1641. //print ' position: absolute; top: 40px; width: 50%;';
  1642. //print '"';
  1643. print '>';
  1644. //var_dump($event->userassigned);
  1645. //var_dump($event->transparency);
  1646. print '<table class="centpercent cal_event cal_event_ac_event';
  1647. print(empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
  1648. //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
  1649. print '" style="' . $h;
  1650. $colortouse = $color;
  1651. // If colortouse is similar than background, we force to change it.
  1652. if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1653. print 'background: #f0f0f0;';
  1654. print 'border-left: 5px solid #' . $colortouse . ';';
  1655. } else {
  1656. print 'background: #f0f0f0;';
  1657. print 'border-left: 5px solid #' . dol_color_minus($colortouse, -3) . ';';
  1658. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
  1659. }
  1660. //print 'background: #'.$colortouse.';';
  1661. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
  1662. //if (!empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
  1663. //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
  1664. //print ' -moz-border-radius:4px;"';
  1665. //print 'border: 1px solid #ccc" width="100%"';
  1666. print '">';
  1667. print '<tr>';
  1668. print '<td class="tdoverflow nobottom centpercent ' . ($nowrapontd ? 'nowrap ' : '') . 'cal_event' . ($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '') . '">';
  1669. $daterange = '';
  1670. $fulldaterange = '';
  1671. if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
  1672. print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
  1673. } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
  1674. $tmpholiday->fetch($event->id);
  1675. print $tmpholiday->getNomUrl(1);
  1676. $tmpid = $tmpholiday->fk_user;
  1677. if (empty($cacheusers[$tmpid])) {
  1678. $newuser = new User($db);
  1679. $newuser->fetch($tmpid);
  1680. $cacheusers[$tmpid] = $newuser;
  1681. }
  1682. $listofusertoshow = '';
  1683. $listofusertoshow .= '<br>' . $cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1684. print $listofusertoshow;
  1685. } else { // Other calendar
  1686. // Picto
  1687. if (empty($event->fulldayevent)) {
  1688. //print $event->getNomUrl(2).' ';
  1689. }
  1690. // Date
  1691. if (empty($event->fulldayevent)) {
  1692. // Show hours (start ... end)
  1693. $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1694. $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1695. $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1696. $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
  1697. $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
  1698. $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
  1699. // Hour start
  1700. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
  1701. $daterange .= dol_print_date($event->date_start_in_calendar, 'H:i', 'tzuserrel');
  1702. $fulldaterange .= dol_print_date($event->date_start_in_calendar, 'Y-m-d H:i', 'tzuserrel');
  1703. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1704. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
  1705. $daterange .= ' - ';
  1706. $fulldaterange .= ' - ';
  1707. }
  1708. //else
  1709. //print '...';
  1710. }
  1711. }
  1712. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1713. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
  1714. $daterange .= '...';
  1715. }
  1716. }
  1717. // Hour end
  1718. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1719. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
  1720. $daterange .= dol_print_date($event->date_end_in_calendar, 'H:i', 'tzuserrel');
  1721. $fulldaterange .= dol_print_date($event->date_end_in_calendar, 'Y-m-d H:i', 'tzuserrel');
  1722. }
  1723. }
  1724. } else {
  1725. if ($showinfo) {
  1726. print $langs->trans("EventOnFullDay") . "<br>\n";
  1727. }
  1728. }
  1729. // Show title
  1730. //$titletoshow = $daterange;
  1731. $titletoshow = $event->label;
  1732. //$titletoshow .= ($titletoshow ? ' ' : '').dol_escape_htmltag($event->label ? $event->label : $event->libelle);
  1733. if ($event->type_code != 'ICALEVENT') {
  1734. $savlabel = $event->label ? $event->label : $event->libelle;
  1735. $event->label = $titletoshow;
  1736. $event->libelle = $titletoshow; // deprecatd
  1737. // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
  1738. //$titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
  1739. $titletoshow = '';
  1740. $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
  1741. $event->label = $savlabel;
  1742. $event->libelle = $savlabel;
  1743. }
  1744. // Loop on each assigned user
  1745. $listofusertoshow = '';
  1746. $posuserassigned = 0;
  1747. foreach ($event->userassigned as $tmpid => $tmpdata) {
  1748. if (!$posuserassigned && $titletoshow) {
  1749. $listofusertoshow .= '<br>';
  1750. }
  1751. $posuserassigned++;
  1752. if (empty($cacheusers[$tmpid])) {
  1753. $newuser = new User($db);
  1754. $newuser->fetch($tmpid);
  1755. $cacheusers[$tmpid] = $newuser;
  1756. }
  1757. $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1758. }
  1759. print $titletoshow;
  1760. print '<br>';
  1761. print '<a class="cal_event cal_event_title classfortooltip" href="" title="' . $fulldaterange . '">' . $daterange . '</a>';
  1762. print $listofusertoshow;
  1763. if ($event->type_code == 'ICALEVENT') {
  1764. print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')';
  1765. }
  1766. $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
  1767. $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
  1768. // If action related to company / contact
  1769. $linerelatedto = '';
  1770. if ($thirdparty_id > 0) {
  1771. if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
  1772. $thirdparty = new Societe($db);
  1773. $thirdparty->fetch($thirdparty_id);
  1774. $cachethirdparties[$thirdparty_id] = $thirdparty;
  1775. } else {
  1776. $thirdparty = $cachethirdparties[$thirdparty_id];
  1777. }
  1778. if (!empty($thirdparty->id)) {
  1779. $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
  1780. }
  1781. }
  1782. if (!empty($contact_id) && $contact_id > 0) {
  1783. if (!is_object($cachecontacts[$contact_id])) {
  1784. $contact = new Contact($db);
  1785. $contact->fetch($contact_id);
  1786. $cachecontacts[$contact_id] = $contact;
  1787. } else {
  1788. $contact = $cachecontacts[$contact_id];
  1789. }
  1790. if ($linerelatedto) {
  1791. $linerelatedto .= '&nbsp;';
  1792. }
  1793. if (!empty($contact->id)) {
  1794. $linerelatedto .= $contact->getNomUrl(1, '', 0);
  1795. }
  1796. }
  1797. if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
  1798. include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  1799. if ($linerelatedto) {
  1800. $linerelatedto .= '<br>';
  1801. }
  1802. $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
  1803. }
  1804. if ($linerelatedto) {
  1805. print '<br>' . $linerelatedto;
  1806. }
  1807. }
  1808. // Show location
  1809. if ($showinfo) {
  1810. if ($event->location) {
  1811. print '<br>';
  1812. print $langs->trans("Location") . ': ' . $event->location;
  1813. }
  1814. }
  1815. print '</td>';
  1816. // Status - Percent
  1817. $withstatus = 0;
  1818. if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
  1819. $withstatus = 1;
  1820. if ($event->percentage >= 0) {
  1821. $withstatus = 2;
  1822. }
  1823. }
  1824. print '<td class="nobottom right nowrap cal_event_right' . ($withstatus >= 2 ? ' cal_event_right_status' : '') . '">';
  1825. if ($withstatus) {
  1826. print $event->getLibStatut(3, 1);
  1827. } else {
  1828. print '&nbsp;';
  1829. }
  1830. print '</td></tr></table>';
  1831. print '</div><!-- end event ' . $i . ' -->' . "\n";
  1832. $i++;
  1833. } else {
  1834. print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?mode=' . $mode . '&maxprint=0&month=' . ((int) $monthshown) . '&year=' . ((int) $year);
  1835. print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . urlencode($filter) : '');
  1836. print($filtert ? '&search_filtert=' . urlencode($filtert) : '');
  1837. print($usergroup ? '&search_usergroup=' . urlencode($usergroup) : '');
  1838. print($actioncode != '' ? '&search_actioncode=' . urlencode($actioncode) : '');
  1839. print '">' . img_picto("all", "1downarrow_selected.png") . ' ...';
  1840. print ' +' . (count($eventarray[$daykey]) - $maxprint);
  1841. print '</a>';
  1842. break;
  1843. //$ok=false; // To avoid to show twice the link
  1844. }
  1845. }
  1846. break;
  1847. }
  1848. }
  1849. if (!$i) { // No events
  1850. print '&nbsp;';
  1851. }
  1852. if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
  1853. print '<div class="center cursorpointer" id="more_' . $ymd . '">' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '</div>';
  1854. //print ' +'.(count($eventarray[$daykey])-$maxprint);
  1855. print '<script type="text/javascript">' . "\n";
  1856. print 'jQuery(document).ready(function () {' . "\n";
  1857. print ' var open=0;' . "\n";
  1858. print ' jQuery("#more_' . $ymd . '").click(function() { console.log("Click on showmore for ' . $ymd . '"); reinit_day_' . $ymd . '(); event.stopImmediatePropagation(); });' . "\n";
  1859. print ' function reinit_day_' . $ymd . '() {' . "\n";
  1860. print ' jQuery(".eventday_' . $ymd . '.showifmore").toggle();' . "\n";
  1861. print ' open = open + 1; if (open > 1) { open = 0; }' . "\n";
  1862. print ' if (open) { ';
  1863. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-up", 'class="warning"') . '\');' . "\n";
  1864. print ' } else { ';
  1865. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '\');' . "\n";
  1866. print ' }' . "\n";
  1867. print ' }' . "\n";
  1868. print '});' . "\n";
  1869. print '</script>' . "\n";
  1870. }
  1871. print '</div></div>'; // td tr
  1872. print '</div>'; // table
  1873. print "\n";
  1874. }
  1875. /**
  1876. * Change color with a delta
  1877. *
  1878. * @param string $color Color
  1879. * @param int $minus Delta (1 = 16 unit). Positive value = darker color, Negative value = brighter color.
  1880. * @param int $minusunit Minus unit
  1881. * @return string New color
  1882. */
  1883. function dol_color_minus($color, $minus, $minusunit = 16)
  1884. {
  1885. $newcolor = $color;
  1886. if ($minusunit == 16) {
  1887. $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
  1888. $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
  1889. $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
  1890. } else {
  1891. // Not yet implemented
  1892. }
  1893. return $newcolor;
  1894. }
  1895. /**
  1896. * Sort events by date
  1897. *
  1898. * @param object $a Event A
  1899. * @param object $b Event B
  1900. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same time slot
  1901. */
  1902. function sort_events_by_date($a, $b)
  1903. {
  1904. // Sort holidays at first
  1905. if ($a->type_code === 'HOLIDAY') {
  1906. return -1;
  1907. }
  1908. if ($b->type_code === 'HOLIDAY') {
  1909. return 1;
  1910. }
  1911. // datep => Event start time
  1912. // datef => Event end time
  1913. // Events have different start time
  1914. if ($a->datep !== $b->datep) {
  1915. return $a->datep - $b->datep;
  1916. }
  1917. // Events have same start time and no end time
  1918. if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
  1919. return sort_events_by_percentage($a, $b);
  1920. }
  1921. // Events have the same start time and same end time
  1922. if ($b->datef === $a->datef) {
  1923. return sort_events_by_percentage($a, $b);
  1924. }
  1925. // Events have the same start time, but have different end time -> longest event first
  1926. return $b->datef - $a->datef;
  1927. }
  1928. /**
  1929. * Sort events by percentage
  1930. *
  1931. * @param object $a Event A
  1932. * @param object $b Event B
  1933. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same percentage
  1934. */
  1935. function sort_events_by_percentage($a, $b)
  1936. {
  1937. // Sort events with no percentage before each other
  1938. // (usefull to sort holidays, sick days or similar on the top)
  1939. if ($a->percentage < 0) {
  1940. return -1;
  1941. }
  1942. if ($b->percentage < 0) {
  1943. return 1;
  1944. }
  1945. return $b->percentage - $a->percentage;
  1946. }
  1947. ?>
  1948. <style>
  1949. .cal_event_ac_event {
  1950. min-height: 100px !important;
  1951. }
  1952. </style>