index.php 102 KB

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