agenda.inc.php 217 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author: Julio Montoya <gugli100@gmail.com> BeezNest 2011 - Lots of fixes - UI improvements, security fixes,
  5. * @author: Patrick Cool, patrick.cool@UGent.be
  6. * @todo this code should be clean as well as the myagenda.inc.php - jmontoya
  7. * @package chamilo.calendar
  8. */
  9. /**
  10. * Code
  11. */
  12. // the variables for the days and the months
  13. // Defining the shorts for the days
  14. $DaysShort = api_get_week_days_short();
  15. // Defining the days of the week to allow translation of the days
  16. $DaysLong = api_get_week_days_long();
  17. // Defining the months of the year to allow translation of the months
  18. $MonthsLong = api_get_months_long();
  19. $htmlHeadXtra[] = to_javascript();
  20. $htmlHeadXtra[] = '<script>
  21. function setFocus(){
  22. $("#agenda_title").focus();
  23. }
  24. $(function() {
  25. setFocus();
  26. $("#selected_form_id_search").change(function() {
  27. var temp ="&user_id="+$("#selected_form_id_search").val();
  28. var position =String(window.location).indexOf("&user");
  29. var url_length = String(window.location).length;
  30. var url = String(window.location).substring(0,position)+temp;
  31. if (position > 0){
  32. window.location.replace(url);
  33. } else {
  34. url = String(window.location)+temp;
  35. window.location.replace(url);
  36. }
  37. });
  38. });
  39. </script>';
  40. /**
  41. * Retrieves all the agenda items from the table
  42. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  43. * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
  44. * @author Julio Montoya - Refactoring
  45. * @param integer $month: the integer value of the month we are viewing
  46. * @param integer $year: the 4-digit year indication e.g. 2005
  47. * @return array
  48. */
  49. function get_calendar_items($select_month, $select_year, $select_day = false)
  50. {
  51. $course_info = api_get_course_info();
  52. $select_month = intval($select_month);
  53. $select_year = intval($select_year);
  54. if ($select_day)
  55. $select_day = intval($select_day);
  56. if (!empty($select_month) && !empty($select_year)) {
  57. $show_all_current = " AND MONTH(start_date) = $select_month AND year(start_date) = $select_year";
  58. if ($select_day) {
  59. $show_all_current .= ' AND DAY(start_date) = '.$select_day;
  60. }
  61. $show_all_current_personal = " AND MONTH(date) = $select_month AND year(date) = $select_year";
  62. if ($select_day) {
  63. $show_all_current_personal .= ' AND DAY(date) = '.$select_day;
  64. }
  65. } else {
  66. $show_all_current = '';
  67. $show_all_current_personal = '';
  68. }
  69. // database variables
  70. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  71. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  72. $group_memberships = GroupManager::get_group_ids($course_info['real_id'], api_get_user_id());
  73. $repeats = array();
  74. /* CONSTRUCT THE SQL STATEMENT */
  75. // by default we use the id of the current user. The course administrator can see the agenda of other users by using the user / group filter
  76. $user_id = api_get_user_id();
  77. if (isset($_SESSION['user'])) {
  78. $user_id = intval($_SESSION['user']);
  79. }
  80. $group_id = api_get_group_id();
  81. $session_condition = api_get_session_condition(api_get_session_id());
  82. if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  83. // A.1. you are a course admin with a USER filter
  84. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  85. if (!empty($_SESSION['user'])) {
  86. $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $_SESSION['user']);
  87. $show_user = true;
  88. $new_group_memberships = array();
  89. foreach ($group_memberships as $id) {
  90. // did i have access to the same
  91. $has_access = GroupManager::user_has_access(api_get_user_id(), $id, GroupManager::GROUP_TOOL_CALENDAR);
  92. $result = GroupManager::get_group_properties($id);
  93. if ($has_access && $result['calendar_state'] != '0') {
  94. $new_group_memberships[] = $id;
  95. }
  96. }
  97. $group_memberships = $new_group_memberships;
  98. if (is_array($group_memberships) && count($group_memberships) > 0) {
  99. $sql = "SELECT
  100. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  101. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  102. WHERE agenda.id = ip.ref ".$show_all_current."
  103. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  104. AND ( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  105. AND ip.visibility='1'
  106. $session_condition";
  107. } else {
  108. //AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
  109. $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  110. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  111. WHERE agenda.id = ip.ref ".$show_all_current."
  112. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  113. AND ( ip.to_user_id = $user_id )
  114. AND ip.visibility='1'
  115. $session_condition";
  116. }
  117. }
  118. // A.2. you are a course admin with a GROUP filter
  119. // => see only the messages of this specific group
  120. elseif (!empty($_SESSION['group'])) {
  121. if (!empty($group_id)) {
  122. $result = GroupManager::get_group_properties($group_id);
  123. $has_access = GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR);
  124. //echo '<pre>';print_R($result);
  125. // lastedit
  126. if (!$has_access || $result['calendar_state'] == '0') {
  127. $group_id = 0;
  128. }
  129. }
  130. $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  131. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  132. WHERE agenda.id = ip.ref ".$show_all_current."
  133. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  134. AND ( ip.to_group_id=$group_id)
  135. AND ip.lastedit_type<>'CalendareventDeleted'
  136. $session_condition
  137. GROUP BY ip.ref";
  138. //removed - > AND toolitemproperties.visibility='1'
  139. }
  140. // A.3 you are a course admin without any group or user filter
  141. else {
  142. // A.3.a you are a course admin without user or group filter but WITH studentview
  143. // => see all the messages of all the users and groups without editing possibilities
  144. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  145. $sql = "SELECT
  146. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  147. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  148. WHERE agenda.id = ip.ref ".$show_all_current."
  149. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  150. AND ip.visibility='1'
  151. $session_condition
  152. GROUP BY ip.ref
  153. ORDER $sort_item $sort";
  154. }
  155. // A.3.b you are a course admin or a student
  156. else {
  157. // A.3.b.1 you are a course admin without user or group filter and WITHOUT studentview (= the normal course admin view)
  158. // => see all the messages of all the users and groups with editing possibilities
  159. if (api_is_course_admin()) {
  160. $sql = "SELECT
  161. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  162. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  163. WHERE agenda.id = ip.ref ".$show_all_current."
  164. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  165. AND ( ip.visibility='0' OR ip.visibility='1')
  166. $session_condition
  167. GROUP BY ip.ref";
  168. } else {
  169. // A.3.b.2 you are a student with no group filter possibly showall
  170. //when showing all the events we do not show the group events
  171. //todo showing ALL events including the groups events that are available
  172. $sql = "SELECT
  173. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  174. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  175. WHERE agenda.id = ip.ref ".$show_all_current."
  176. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  177. AND ( ip.visibility='0' OR ip.visibility='1')
  178. $session_condition
  179. GROUP BY ip.ref";
  180. /*
  181. if (is_array($group_memberships) && count($group_memberships)>0)
  182. {
  183. echo $sql="SELECT
  184. agenda.*, toolitemproperties.*
  185. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  186. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  187. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  188. AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).")
  189. $session_condition
  190. GROUP BY toolitemproperties.ref
  191. ORDER BY start_date ".$sort;
  192. }
  193. else
  194. {
  195. $sql="SELECT
  196. agenda.*, toolitemproperties.*
  197. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  198. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  199. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  200. AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id='0'
  201. $session_condition
  202. GROUP BY toolitemproperties.ref
  203. ORDER BY start_date ".$sort;
  204. }
  205. */
  206. }
  207. }
  208. }
  209. } //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  210. // B. you are a student
  211. else {
  212. if (is_array($group_memberships) && count($group_memberships) > 0) {
  213. $sql = "SELECT
  214. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  215. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  216. WHERE agenda.id = ip.ref ".$show_all_current."
  217. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  218. AND ( ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  219. AND ip.visibility='1'
  220. $session_condition";
  221. } else {
  222. if (api_get_user_id()) {
  223. $sql = "SELECT
  224. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  225. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  226. WHERE agenda.id = ip.ref ".$show_all_current."
  227. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  228. AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
  229. AND ip.visibility='1'
  230. $session_condition";
  231. } else {
  232. $sql = "SELECT
  233. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  234. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  235. WHERE agenda.id = ip.ref ".$show_all_current."
  236. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  237. AND ip.to_group_id='0'
  238. AND ip.visibility='1'
  239. $session_condition";
  240. }
  241. }
  242. } // you are a student
  243. $my_events = array();
  244. $avoid_doubles = array();
  245. $result = Database::query($sql);
  246. //Course venets
  247. while ($row = Database::fetch_array($result, 'ASSOC')) {
  248. $row['calendar_type'] = 'course';
  249. if (!in_array($row['id'], $avoid_doubles)) {
  250. if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
  251. $row['start_date'] = api_get_local_time($row['start_date']);
  252. $row['start_date_tms'] = api_strtotime($row['start_date']);
  253. }
  254. if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
  255. $row['end_date'] = api_get_local_time($row['end_date']);
  256. $row['end_date_tms'] = api_strtotime($row['end_date']);
  257. }
  258. $my_events[] = $row;
  259. $avoid_doubles[] = $row['id'];
  260. }
  261. }
  262. //Check my personal calendar items
  263. if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) && empty($_SESSION['group'])) {
  264. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  265. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  266. $sql = "SELECT id, title, text as content , date as start_date, enddate as end_date, parent_event_id FROM ".$tbl_personal_agenda."
  267. WHERE user='".api_get_user_id()."' ".$show_all_current_personal;
  268. $result = Database::query($sql);
  269. while ($row = Database::fetch_array($result, 'ASSOC')) {
  270. $row['calendar_type'] = 'personal';
  271. if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
  272. $row['start_date'] = api_get_local_time($row['start_date']);
  273. $row['start_date_tms'] = api_strtotime($row['start_date']);
  274. }
  275. if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
  276. $row['end_date'] = api_get_local_time($row['end_date']);
  277. $row['end_date_tms'] = api_strtotime($row['end_date']);
  278. }
  279. $my_events[] = $row;
  280. }
  281. }
  282. //Check global agenda events
  283. if (empty($_SESSION['user']) && empty($_SESSION['group'])) {
  284. $table_agenda_system = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  285. $current_access_url_id = api_get_current_access_url_id();
  286. $sql = "SELECT DISTINCT id, title, content , start_date, end_date FROM ".$table_agenda_system."
  287. WHERE 1=1 ".$show_all_current." AND access_url_id = $current_access_url_id";
  288. $result = Database::query($sql);
  289. while ($row = Database::fetch_array($result, 'ASSOC')) {
  290. if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
  291. $row['start_date'] = api_get_local_time($row['start_date']);
  292. $row['start_date_tms'] = api_strtotime($row['start_date']);
  293. }
  294. if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
  295. $row['end_date'] = api_get_local_time($row['end_date']);
  296. $row['end_date_tms'] = api_strtotime($row['end_date']);
  297. }
  298. $row['calendar_type'] = 'global';
  299. $my_events[] = $row;
  300. }
  301. }
  302. return $my_events;
  303. }
  304. /**
  305. * show the mini calender of the given month
  306. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  307. * @param array an array containing all the agenda items for the given month
  308. * @param integer $month: the integer value of the month we are viewing
  309. * @param integer $year: the 4-digit year indication e.g. 2005
  310. * @param string $monthName: the language variable for the mont name
  311. * @return html code
  312. * @todo refactor this so that $monthName is no longer needed as a parameter
  313. */
  314. function display_minimonthcalendar($agenda_items, $month, $year)
  315. {
  316. global $DaysShort, $MonthsLong;
  317. if (empty($month)) {
  318. $month = intval(date('m'));
  319. }
  320. if (empty($year)) {
  321. $month = date('Y');
  322. }
  323. $month_name = $MonthsLong[$month - 1];
  324. //Handle leap year
  325. $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  326. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  327. $numberofdays[2] = 29;
  328. //Get the first day of the month
  329. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  330. //Start the week on monday
  331. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  332. $backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year);
  333. $forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year);
  334. $month_link = Display::url($month_name." ".$year, api_get_self()."?".api_get_cidreq()."&month=".($month)."&year=".$year);
  335. $new_items = array();
  336. foreach ($agenda_items as $item) {
  337. $day = intval(substr($item["start_date"], 8, 2));
  338. $my_month = intval(substr($item["start_date"], 5, 2));
  339. if ($my_month == $month) {
  340. $new_items[$day][] = 1;
  341. }
  342. }
  343. $agenda_items = $new_items;
  344. echo "<table class=\"data_table\">",
  345. "<tr>",
  346. "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png', get_lang('Previous'))." </a></th>",
  347. "<th width=\"80%\" colspan=\"5\">".$month_link."</th>",
  348. "<th width=\"10%\"><a href=\"", $forewardsURL, "\"> ".Display::return_icon('action_next.png', get_lang('Next'))." </a></th></tr>";
  349. echo "<tr>";
  350. for ($ii = 1; $ii < 8; $ii++) {
  351. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
  352. }
  353. echo "</tr>";
  354. $curday = -1;
  355. $today = getdate();
  356. while ($curday <= $numberofdays[$month]) {
  357. echo "<tr>";
  358. for ($ii = 0; $ii < 7; $ii++) {
  359. if (($curday == -1) && ($ii == $startdayofweek)) {
  360. $curday = 1;
  361. }
  362. if (($curday > 0) && ($curday <= $numberofdays[$month])) {
  363. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  364. $dayheader = "$curday";
  365. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
  366. $dayheader = "$curday";
  367. $class = "class=\"days_today\"";
  368. }
  369. echo "<td ".$class.">";
  370. if (!empty($agenda_items[$curday])) {
  371. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&amp;action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."#".$curday."\">".$dayheader."</a>";
  372. } else {
  373. echo $dayheader;
  374. }
  375. // "a".$dayheader." <span class=\"agendaitem\">".$agenda_items[$curday]."</span>";
  376. echo "</td>";
  377. $curday++;
  378. } else {
  379. echo "<td></td>";
  380. }
  381. }
  382. echo "</tr>";
  383. }
  384. echo "</table>";
  385. }
  386. /**
  387. * show the calender of the given month
  388. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  389. * @author Julio Montoya - adding some nice styles
  390. * @param integer $month: the integer value of the month we are viewing
  391. * @param integer $year: the 4-digit year indication e.g. 2005
  392. * @return html code
  393. */
  394. function display_monthcalendar($month, $year, $agenda_items)
  395. {
  396. global $MonthsLong;
  397. global $DaysShort;
  398. global $origin;
  399. //Handle leap year
  400. $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  401. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  402. $numberofdays[2] = 29;
  403. //Get the first day of the month
  404. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  405. //Start the week on monday
  406. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  407. $backwardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&amp;month=".($month == 1 ? 12 : $month - 1)."&amp;year=".($month == 1 ? $year - 1 : $year);
  408. $forewardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&amp;month=".($month == 12 ? 1 : $month + 1)."&amp;year=".($month == 12 ? $year + 1 : $year);
  409. $new_month = $month - 1;
  410. echo '<table id="agenda_list">';
  411. echo '<tr>';
  412. echo '<th width="10%"><a href="'.$backwardsURL.'">'.Display::return_icon('action_prev.png', get_lang('Previous'), array(), 32).'</a></th>';
  413. echo '<th width="80%" colspan="5"><br /><h3>'.$MonthsLong[$new_month].' '.$year.'</h3></th>';
  414. echo '<th width="10%"><a href="'.$forewardsURL.'"> '.Display::return_icon('action_next.png', get_lang('Next'), array(), 32).'</a></th>';
  415. echo '</tr>';
  416. echo '<tr>';
  417. for ($ii = 1; $ii < 8; $ii++) {
  418. echo '<td class="weekdays" width="14%">'.$DaysShort[$ii % 7].'</td>';
  419. }
  420. echo '</tr>';
  421. $curday = -1;
  422. $today = getdate();
  423. $new_items = array();
  424. foreach ($agenda_items as $item) {
  425. $day = intval(substr($item["start_date"], 8, 2));
  426. $my_month = intval(substr($item["start_date"], 5, 2));
  427. if ($my_month == $month) {
  428. $new_items[$day][] = $item;
  429. }
  430. }
  431. $agenda_items = $new_items;
  432. while ($curday <= $numberofdays[$month]) {
  433. echo '<tr>';
  434. //week
  435. for ($ii = 0; $ii < 7; $ii++) {
  436. if (($curday == -1) && ($ii == $startdayofweek)) {
  437. $curday = 1;
  438. }
  439. if (($curday > 0) && ($curday <= $numberofdays[$month])) {
  440. $bgcolor = $ii < 5 ? 'class="row_odd"' : 'class="row_even"';
  441. $dayheader = Display::div($curday, array('class' => 'agenda_day'));
  442. if (key_exists($curday, $agenda_items)) {
  443. $dayheader = Display::div($curday, array('class' => 'agenda_day'));
  444. $events_in_day = msort($agenda_items[$curday], 'start_date_tms');
  445. foreach ($events_in_day as $value) {
  446. $some_content = false;
  447. $month_start_date = (int) substr($value['start_date'], 5, 2);
  448. if ($month == $month_start_date) {
  449. $some_content = true;
  450. $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT);
  451. $end_time = '';
  452. if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') {
  453. $end_time = '-&nbsp;<i>'.api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG).'</i>';
  454. }
  455. $complete_time = '<i>'.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).'</i>&nbsp;'.$end_time;
  456. $time = '<i>'.$start_time.'</i>';
  457. switch ($value['calendar_type']) {
  458. case 'personal':
  459. $bg_color = '#D0E7F4';
  460. $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), 22);
  461. break;
  462. case 'global':
  463. $bg_color = '#FFBC89';
  464. $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22);
  465. break;
  466. case 'course':
  467. $bg_color = '#CAFFAA';
  468. $value['course_name'] = isset($value['course_name']) ? $value['course_name'] : null;
  469. $value['url'] = isset($value['url']) ? $value['url'] : null;
  470. $icon = Display::url(Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22), $value['url']);
  471. break;
  472. default:
  473. break;
  474. }
  475. $icon = Display::div($icon, array('style' => 'float:right'));
  476. //Setting a personal event to green
  477. $dayheader.= '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">';
  478. //Link to bubble
  479. $url = Display::url(cut($value['title'], 40), '#', array('id' => $value['calendar_type'].'_'.$value['id'], 'class' => 'opener'));
  480. $dayheader .= $time.' '.$icon.' '.Display::div($url);
  481. //Hidden content
  482. $content = Display::div($icon.Display::tag('h1', $value['title']).$complete_time.'<hr />'.$value['content']);
  483. //Main div
  484. $dayheader .= Display::div($content, array('id' => 'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog', 'style' => 'display:none'));
  485. $dayheader .= '</div>';
  486. }
  487. //Do not show links with no content
  488. if (!$some_content) {
  489. $dayheader = Display::div($curday, array('class' => 'agenda_day'));
  490. }
  491. }
  492. }
  493. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
  494. echo '<td class="days_today"'.$bgcolor.' style="height:122px;width:10%">'.$dayheader;
  495. } else {
  496. $class = 'days_week';
  497. echo '<td class="'.$class.'" '.$bgcolor.' style="height:122px;width:10%">'.$dayheader;
  498. }
  499. echo '</td>';
  500. $curday++;
  501. } else {
  502. echo '<td>&nbsp;</td>';
  503. }
  504. }
  505. echo '</tr>';
  506. } // end while
  507. echo '</table>';
  508. }
  509. /**
  510. * returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array
  511. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  512. * @return javascript code
  513. */
  514. function to_javascript()
  515. {
  516. return "<script type=\"text/javascript\" language=\"javascript\">
  517. $(function() {
  518. //js used when generating images on the fly see function Tracking::show_course_detail()
  519. $(\".dialog\").dialog(\"destroy\");
  520. $(\".dialog\").dialog({
  521. autoOpen: false,
  522. show: \"blind\",
  523. resizable: false,
  524. height:300,
  525. width:550,
  526. modal: true
  527. });
  528. $(\".opener\").click(function() {
  529. var my_id = $(this).attr('id');
  530. var big_image = '#main_' + my_id;
  531. $( big_image ).dialog(\"open\");
  532. return false;
  533. });
  534. });
  535. <!-- Begin javascript menu swapper
  536. function move(fbox, tbox)
  537. {
  538. // @todo : change associative arrays arrLookup and arrLookupTitle that use firstname/lastnam as key
  539. // so, pb with homonyms
  540. var arrFbox = new Array();
  541. var arrTbox = new Array();
  542. var arrLookup = new Array();
  543. var arrLookupTitle = new Array();
  544. var i;
  545. for (i = 0; i < tbox.options.length; i++)
  546. {
  547. arrLookup[tbox.options[i].text] = tbox.options[i].value;
  548. arrLookupTitle[tbox.options[i].text] = tbox.options[i].title;
  549. arrTbox[i] = tbox.options[i].text;
  550. }
  551. var fLength = 0;
  552. var tLength = arrTbox.length;
  553. for(i = 0; i < fbox.options.length; i++)
  554. {
  555. arrLookup[fbox.options[i].text] = fbox.options[i].value;
  556. arrLookupTitle[fbox.options[i].text] = fbox.options[i].title;
  557. if (fbox.options[i].selected && fbox.options[i].value != \"\")
  558. {
  559. arrTbox[tLength] = fbox.options[i].text;
  560. tLength++;
  561. }
  562. else
  563. {
  564. arrFbox[fLength] = fbox.options[i].text;
  565. fLength++;
  566. }
  567. }
  568. //arrFbox.sort();
  569. //arrTbox.sort()
  570. var arrFboxGroup = new Array();
  571. var arrFboxUser = new Array();
  572. var prefix_x;
  573. for (x = 0; x < arrFbox.length; x++) {
  574. prefix_x = arrFbox[x].substring(0,2);
  575. if (prefix_x == 'G:') {
  576. arrFboxGroup.push(arrFbox[x]);
  577. } else {
  578. arrFboxUser.push(arrFbox[x]);
  579. }
  580. }
  581. arrFboxGroup.sort();
  582. arrFboxUser.sort();
  583. arrFbox = arrFboxGroup.concat(arrFboxUser);
  584. var arrTboxGroup = new Array();
  585. var arrTboxUser = new Array();
  586. var prefix_y;
  587. for (y = 0; y < arrTbox.length; y++) {
  588. prefix_y = arrTbox[y].substring(0,2);
  589. if (prefix_y == 'G:') {
  590. arrTboxGroup.push(arrTbox[y]);
  591. } else {
  592. arrTboxUser.push(arrTbox[y]);
  593. }
  594. }
  595. arrTboxGroup.sort();
  596. arrTboxUser.sort();
  597. arrTbox = arrTboxGroup.concat(arrTboxUser);
  598. fbox.length = 0;
  599. tbox.length = 0;
  600. var c;
  601. for(c = 0; c < arrFbox.length; c++)
  602. {
  603. var no = new Option();
  604. no.value = arrLookup[arrFbox[c]];
  605. no.text = arrFbox[c];
  606. no.title = arrLookupTitle[arrFbox[c]];
  607. fbox[c] = no;
  608. }
  609. for(c = 0; c < arrTbox.length; c++)
  610. {
  611. var no = new Option();
  612. no.value = arrLookup[arrTbox[c]];
  613. no.text = arrTbox[c];
  614. no.title = arrLookupTitle[arrTbox[c]];
  615. tbox[c] = no;
  616. }
  617. }
  618. function checkDate(month, day, year)
  619. {
  620. var monthLength =
  621. new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  622. if (!day || !month || !year)
  623. return false;
  624. // check for bisestile year
  625. if (year/4 == parseInt(year/4))
  626. monthLength[1] = 29;
  627. if (month < 1 || month > 12)
  628. return false;
  629. if (day > monthLength[month-1])
  630. return false;
  631. return true;
  632. }
  633. function mktime() {
  634. var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
  635. d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  636. var dateManip = {
  637. 0: function(tt){ return d.setHours(tt); },
  638. 1: function(tt){ return d.setMinutes(tt); },
  639. 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
  640. 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
  641. 4: function(tt){ return d.setDate(tt+mb); },
  642. 5: function(tt){ return d.setYear(tt+ma); }
  643. };
  644. for( i = 0; i < argc; i++ ){
  645. no = parseInt(argv[i]*1);
  646. if (isNaN(no)) {
  647. return false;
  648. } else {
  649. // arg is number, lets manipulate date object
  650. if(!dateManip[i](no)){
  651. // failed
  652. return false;
  653. }
  654. }
  655. }
  656. return Math.floor(d.getTime()/1000);
  657. }
  658. function validate() {
  659. var f = document.new_calendar_item;
  660. f.submit();
  661. return true;
  662. }
  663. function selectAll(cbList,bSelect,showwarning) {
  664. var start_day = document.new_calendar_item.fday.value;
  665. var start_month = document.new_calendar_item.fmonth.value;
  666. var start_year = document.new_calendar_item.fyear.value;
  667. var start_hour = document.new_calendar_item.fhour.value;
  668. var start_minute = document.new_calendar_item.fminute.value;
  669. var start_date = mktime(start_hour,start_minute,0,start_month,start_day,start_year)
  670. var ends_day = document.new_calendar_item.end_fday.value;
  671. var ends_month = document.new_calendar_item.end_fmonth.value;
  672. var ends_year = document.new_calendar_item.end_fyear.value;
  673. var ends_hour = document.new_calendar_item.end_fhour.value;
  674. var ends_minute = document.new_calendar_item.end_fminute.value;
  675. var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year)
  676. msg_err1 = document.getElementById(\"err_date\");
  677. msg_err2 = document.getElementById(\"err_start_date\");
  678. msg_err3 = document.getElementById(\"err_end_date\");
  679. msg_err4 = document.getElementById(\"err_title\");
  680. var error = false;
  681. if (start_date > ends_date) {
  682. if ($('#empty_end_date').is(':checked')) {
  683. msg_err1.innerHTML=\"\";
  684. msg_err2.innerHTML=\"\";
  685. msg_err3.innerHTML=\"\";
  686. } else {
  687. error = true;
  688. msg_err1.style.display =\"block\";
  689. msg_err1.innerHTML=\"".get_lang('EndDateCannotBeBeforeTheStartDate')."\";
  690. msg_err2.innerHTML=\"\";
  691. msg_err3.innerHTML=\"\";
  692. }
  693. }
  694. if (!checkDate(start_month,start_day,start_year)) {
  695. msg_err2.style.display =\"block\";
  696. msg_err2.innerHTML=\"".get_lang('InvalidDate')."\";
  697. msg_err1.innerHTML=\"\";
  698. msg_err3.innerHTML=\"\";
  699. error = true;
  700. }
  701. if (!checkDate(ends_month,ends_day,ends_year)) {
  702. msg_err3.style.display =\"block\";
  703. msg_err3.innerHTML=\"".get_lang('InvalidDate')."\";
  704. msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";
  705. error = true;
  706. }
  707. if (document.new_calendar_item.title.value == '') {
  708. msg_err4.style.display =\"block\";
  709. msg_err4.innerHTML=\"".get_lang('FieldRequired')."\";
  710. msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\";
  711. error = true;
  712. }
  713. if (error == false) {
  714. if (cbList) {
  715. if (cbList.length < 1) {
  716. if (!confirm(\"".get_lang('Send2All')."\")) {
  717. return false;
  718. }
  719. }
  720. for (var i=0; i<cbList.length; i++)
  721. cbList[i].selected = cbList[i].checked = bSelect;
  722. }
  723. document.new_calendar_item.submit();
  724. }
  725. }
  726. function reverseAll(cbList)
  727. {
  728. for (var i=0; i<cbList.length; i++)
  729. {
  730. cbList[i].checked = !(cbList[i].checked)
  731. cbList[i].selected = !(cbList[i].selected)
  732. }
  733. }
  734. function plus_attachment() {
  735. if (document.getElementById('options').style.display == 'none') {
  736. document.getElementById('options').style.display = 'block';
  737. document.getElementById('plus').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_hide.gif\" alt=\"\" />&nbsp;".get_lang('AddAnAttachment')."';
  738. } else {
  739. document.getElementById('options').style.display = 'none';
  740. document.getElementById('plus').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_show.gif\" alt=\"\" />&nbsp;".get_lang('AddAnAttachment')."';
  741. }
  742. }
  743. function plus_repeated_event() {
  744. if (document.getElementById('options2').style.display == 'none') {
  745. document.getElementById('options2').style.display = 'block';
  746. document.getElementById('plus2').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_hide.gif\" alt=\"\" />&nbsp;".get_lang('RepeatEvent')."';
  747. } else {
  748. document.getElementById('options2').style.display = 'none';
  749. document.getElementById('plus2').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_show.gif\" alt=\"\" />&nbsp;".get_lang('RepeatEvent')."';
  750. }
  751. }
  752. /*
  753. function plus_ical() {
  754. if (document.getElementById('icalform').style.display == 'none') {
  755. document.getElementById('icalform').style.display = 'block';
  756. document.getElementById('plusical').innerHTML='';
  757. }
  758. }
  759. */
  760. // End -->
  761. </script>";
  762. }
  763. /**
  764. * returns the javascript for setting a filter. This is a jump menu
  765. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  766. * @return javascript code
  767. */
  768. function user_group_filter_javascript()
  769. {
  770. return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  771. <!--
  772. function MM_jumpMenu(targ,selObj,restore){
  773. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  774. if (restore) selObj.selectedIndex=0;
  775. }
  776. //-->
  777. </script>
  778. ";
  779. }
  780. /**
  781. * this function gets all the users of the current course
  782. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  783. * @return array: associative array where the key is the id of the user and the value is an array containing
  784. the first name, the last name, the user id
  785. */
  786. function get_course_users()
  787. {
  788. global $_cid;
  789. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  790. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  791. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  792. // not 100% if this is necessary, this however prevents a notice
  793. if (!isset($courseadmin_filter)) {
  794. $courseadmin_filter = '';
  795. }
  796. //
  797. $order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
  798. $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName, u.username
  799. FROM $tbl_user as u, $tbl_courseUser as cu
  800. WHERE cu.course_code = '".api_get_course_id()."'
  801. AND cu.user_id = u.user_id $courseadmin_filter".$order_clause;
  802. $result = Database::query($sql);
  803. while ($user = Database::fetch_array($result)) {
  804. $users[$user[0]] = $user;
  805. }
  806. $session_id = api_get_session_id();
  807. if (!empty($session_id)) {
  808. $users = array();
  809. $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName, u.username
  810. FROM $tbl_session_course_user AS session_course_user
  811. INNER JOIN $tbl_user u ON u.user_id = session_course_user.id_user
  812. WHERE id_session = ".$session_id."
  813. AND course_code = '".api_get_course_id()."'";
  814. $result = Database::query($sql);
  815. while ($user = Database::fetch_array($result)) {
  816. $users[$user[0]] = $user;
  817. }
  818. }
  819. return $users;
  820. }
  821. /**
  822. * this function gets all the groups of the course
  823. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  824. * @return array
  825. */
  826. function get_course_groups()
  827. {
  828. $group_list = array();
  829. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  830. return $group_list;
  831. }
  832. /**
  833. * this function shows the form for sending a message to a specific group or user.
  834. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  835. *
  836. * @return html code
  837. */
  838. function show_to_form($to_already_selected)
  839. {
  840. $order = 'lastname';
  841. if (api_is_western_name_order()) {
  842. $order = 'firstname';
  843. }
  844. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  845. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  846. construct_not_selected_select_form($group_list, $user_list, $to_already_selected);
  847. }
  848. /**
  849. * this function shows the form with the user that were not selected
  850. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  851. * @return html code
  852. */
  853. function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array())
  854. {
  855. echo '<select data-placeholder="'.get_lang('Select').'" style="width:150px;" class="chzn-select" id="selected_form_id" name="selected_form[]" multiple="multiple">';
  856. // Adding the groups to the select form
  857. if (isset($to_already_selected) && $to_already_selected === 'everyone') {
  858. echo '<option selected="selected" value="everyone">'.get_lang('Everyone').'</option>';
  859. //} else {
  860. } else {
  861. echo '<option value="everyone">'.get_lang('Everyone').'</option>';
  862. }
  863. if (is_array($group_list)) {
  864. echo '<optgroup label="'.get_lang('Groups').'">';
  865. foreach ($group_list as $this_group) {
  866. //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
  867. if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) {
  868. // $to_already_selected is the array containing the groups (and users) that are already selected
  869. echo "<option value=\"GROUP:".$this_group['id']."\">",
  870. "G: ", $this_group['name'], " &ndash; ".$this_group['userNb']." ".get_lang('Users').
  871. "</option>";
  872. }
  873. }
  874. // a divider
  875. }
  876. echo "</optgroup>";
  877. // adding the individual users to the select form
  878. if (!empty($user_list)) {
  879. echo '<optgroup label="'.get_lang('Users').'">';
  880. foreach ($user_list as $this_user) {
  881. // $to_already_selected is the array containing the users (and groups) that are already selected
  882. if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'], $to_already_selected)) {
  883. $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
  884. $user_info = api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].')';
  885. echo "<option title='$username' value='USER:".$this_user['user_id']."'>$user_info</option>";
  886. }
  887. }
  888. echo "</optgroup>";
  889. }
  890. echo "</select>";
  891. }
  892. function show_to($filter = 0, $id = null)
  893. {
  894. $order = 'lastname';
  895. if (api_is_western_name_order()) {
  896. $order = 'firstname';
  897. }
  898. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  899. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  900. return construct_to_select_form($group_list, $user_list, $filter, $id);
  901. }
  902. function construct_to_select_form($group_list = null, $user_list = null, $filter = 0, $id = null)
  903. {
  904. $result = '<form class="form-search" margin-top:3px;>';
  905. $result .= '<select data-placeholder= "'.get_lang('FilterAll').'" name="sel_to" class="chzn-select" id="selected_form_id_search">';
  906. // adding the groups to the select form
  907. $result .= '<option value=""></option>';
  908. $result .= '<option value="0">'.get_lang('FilterAll').'</option>';
  909. if (is_array($group_list)) {
  910. $result .= '<optgroup label="'.get_lang('FilterByGroup').'">';
  911. $this_group_name = count($group_list);
  912. foreach ($group_list as $this_group) {
  913. $group_filter = 'G:'.$this_group['id'];
  914. $selected = $group_filter == $filter ? "selected" : null;
  915. $result .= "<option value=G:".$this_group['id']." ".$selected.">".$this_group['name']."</option>";
  916. }
  917. $result .= "</optgroup>";
  918. }
  919. // adding the individual users to the select form
  920. if (!empty($user_list)) {
  921. $result .= '<optgroup label="'.get_lang('FilterByUser').'">';
  922. foreach ($user_list as $this_user) {
  923. $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
  924. $user_info = api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].')';
  925. $selected = $this_user['user_id'] == $filter ? "selected" : null;
  926. $result .= "<option title='$username' value=".$this_user['user_id']." ".$selected.">$user_info</option>";
  927. }
  928. $result .= "</optgroup>";
  929. }
  930. $result .= "</select>";
  931. $result .= "</form>";
  932. return $result;
  933. }
  934. /**
  935. * This function shows the form with the user that were selected
  936. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  937. * @return html code
  938. */
  939. function construct_selected_select_form($group_list = null, $user_list = null, $to_already_selected)
  940. {
  941. // we separate the $to_already_selected array (containing groups AND users into
  942. // two separate arrays
  943. if (is_array($to_already_selected)) {
  944. $groupuser = separate_users_groups($to_already_selected);
  945. }
  946. $groups_to_already_selected = $groupuser['groups'];
  947. $users_to_already_selected = $groupuser['users'];
  948. // we load all the groups and all the users into a reference array that we use to search the name of the group / user
  949. $ref_array_groups = get_course_groups();
  950. $ref_array_users = get_course_users();
  951. // we construct the form of the already selected groups / users
  952. echo "<select id=\"selected_form2\" name=\"selectedform2[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">";
  953. if (is_array($to_already_selected)) {
  954. $select_options_group = array();
  955. $select_options_user = array();
  956. $select_options_groupuser = array();
  957. foreach ($to_already_selected as $groupuser) {
  958. list($type, $id) = explode(":", $groupuser);
  959. if ($type == "GROUP") {
  960. $select_options_group[] = "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  961. //echo "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  962. } else {
  963. $username = api_htmlentities(sprintf(get_lang('LoginX'), $ref_array_users[$id]['username']), ENT_QUOTES);
  964. $user_info = api_get_person_name($ref_array_users[$id]['firstName'], $ref_array_users[$id]['lastName']);
  965. $select_options_user[] = "<option title='$username' value='".$groupuser."'>$user_info</option>";
  966. //echo "<option value=\"".$groupuser."\">".api_get_person_name($ref_array_users[$id]['firstName'], $ref_array_users[$id]['lastName'])."</option>";
  967. }
  968. }
  969. $select_options_group[] = "<option value=\"\">--------------------------------------------</option>";
  970. $select_options_groupuser = array_merge($select_options_group, $select_options_user);
  971. foreach ($select_options_groupuser as $select_options) {
  972. echo $select_options;
  973. }
  974. } else {
  975. if ($to_already_selected == 'everyone') {
  976. // adding the groups to the select form
  977. if (is_array($group_list)) {
  978. foreach ($group_list as $this_group) {
  979. //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
  980. if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) { // $to_already_selected is the array containing the groups (and users) that are already selected
  981. echo "<option value=\"GROUP:".$this_group['id']."\">",
  982. "G: ", $this_group['name'], " &ndash; ".$this_group['userNb']." ".get_lang('Users').
  983. "</option>";
  984. }
  985. }
  986. }
  987. echo "<option value=\"\">--------------------------------------------</option>";
  988. // adding the individual users to the select form
  989. foreach ($user_list as $this_user) {
  990. if (!is_array($to_already_selected) || !in_array("USER:".$this_user['uid'], $to_already_selected)) { // $to_already_selected is the array containing the users (and groups) that are already selected
  991. echo "<option value=\"USER:", $this_user['uid'], "\">",
  992. "", api_get_person_name($this_user['firstName'], $this_user['lastName']),
  993. "</option>";
  994. }
  995. }
  996. }
  997. }
  998. echo "</select>";
  999. }
  1000. /**
  1001. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also
  1002. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1003. * @return integer the id of the last added agenda item
  1004. */
  1005. function store_new_agenda_item()
  1006. {
  1007. global $_course;
  1008. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1009. $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT);
  1010. $course_id = api_get_course_int_id();
  1011. // some filtering of the input data
  1012. $title = trim($_POST['title']); // no html allowed in the title
  1013. $content = trim($_POST['content']);
  1014. $start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
  1015. $end_date = (int) $_POST['end_fyear']."-".(int) $_POST['end_fmonth']."-".(int) $_POST['end_fday']." ".(int) $_POST['end_fhour'].":".(int) $_POST['end_fminute'].":00";
  1016. $title = Database::escape_string($title);
  1017. $content = Database::escape_string($content);
  1018. $start_date = Database::escape_string($start_date);
  1019. $end_date = Database::escape_string($end_date);
  1020. if ($_POST['empty_end_date'] == 'on') {
  1021. $end_date = "0000-00-00 00:00:00";
  1022. }
  1023. // store in the table calendar_event
  1024. $sql = "INSERT INTO ".$TABLEAGENDA." (c_id, title,content, start_date, end_date)
  1025. VALUES ($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."')";
  1026. $result = Database::query($sql);
  1027. $last_id = Database::insert_id();
  1028. // store in last_tooledit (first the groups, then the users
  1029. $to = $_POST['selectedform'];
  1030. if ((!is_null($to)) || (!empty($_SESSION['toolgroup']))) { // !is_null($to): when no user is selected we send it to everyone
  1031. //$send_to=separate_users_groups($to);
  1032. $send_to = separate_users_groups(explode('|', $to));
  1033. // storing the selected groups
  1034. if (is_array($send_to['groups'])) {
  1035. foreach ($send_to['groups'] as $group) {
  1036. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), $group, '', $start_date, $end_date);
  1037. }
  1038. }
  1039. // storing the selected users
  1040. if (is_array($send_to['users'])) {
  1041. foreach ($send_to['users'] as $user) {
  1042. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', $user, $start_date, $end_date);
  1043. }
  1044. }
  1045. } else { // the message is sent to everyone, so we set the group to 0
  1046. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', '', $start_date, $end_date);
  1047. }
  1048. // storing the resources
  1049. store_resources($_SESSION['source_type'], $last_id);
  1050. $course_id = api_get_course_int_id();
  1051. //if repetitive, insert element into agenda_repeat table
  1052. if (!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) {
  1053. if (!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) {
  1054. $end_y = intval($_POST['repeat_end_year']);
  1055. $end_m = intval($_POST['repeat_end_month']);
  1056. $end_d = intval($_POST['repeat_end_day']);
  1057. $end = mktime((int) $_POST['fhour'], (int) $_POST['fminute'], 0, $end_m, $end_d, $end_y);
  1058. $now = time();
  1059. $type = Database::escape_string($_POST['repeat_type']);
  1060. if ($end > $now && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) {
  1061. $sql = "INSERT INTO $t_agenda_repeat (c_id, cal_id, cal_type, cal_end)".
  1062. " VALUES ($course_id, $last_id,'$type',$end)";
  1063. $res = Database::query($sql);
  1064. }
  1065. }
  1066. }
  1067. return $last_id;
  1068. }
  1069. /**
  1070. * Stores the given agenda item as an announcement (unlinked copy)
  1071. * @param integer Agenda item's ID
  1072. * @return integer New announcement item's ID
  1073. */
  1074. function store_agenda_item_as_announcement($item_id)
  1075. {
  1076. $table_agenda = Database::get_course_table(TABLE_AGENDA);
  1077. $table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1078. //check params
  1079. if (empty($item_id) or $item_id != strval(intval($item_id))) {
  1080. return -1;
  1081. }
  1082. //get the agenda item
  1083. $item_id = Database::escape_string($item_id);
  1084. $sql = "SELECT * FROM $table_agenda WHERE id = ".$item_id;
  1085. $res = Database::query($sql);
  1086. $course_id = api_get_course_int_id();
  1087. if (Database::num_rows($res) > 0) {
  1088. $row = Database::fetch_array($res);
  1089. //we have the agenda event, copy it
  1090. //get the maximum value for display order in announcement table
  1091. $sql_max = "SELECT MAX(display_order) FROM $table_ann WHERE c_id = $course_id ";
  1092. $res_max = Database::query($sql_max);
  1093. $row_max = Database::fetch_array($res_max);
  1094. $max = intval($row_max[0]) + 1;
  1095. //build the announcement text
  1096. $content = $row['content'];
  1097. //insert announcement
  1098. $session_id = api_get_session_id();
  1099. $sql_ins = "INSERT INTO $table_ann (c_id, title,content,end_date,display_order,session_id) ".
  1100. "VALUES ($course_id, '".Database::escape_string($row['title'])."','".Database::escape_string($content)."','".Database::escape_string($row['end_date'])."','$max','$session_id')";
  1101. $res_ins = Database::query($sql_ins);
  1102. if ($res > 0) {
  1103. $ann_id = Database::insert_id();
  1104. //Now also get the list of item_properties rows for this agenda_item (calendar_event)
  1105. //and copy them into announcement item_properties
  1106. $table_props = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1107. $sql_props = "SELECT * FROM $table_props WHERE tool = 'calendar_event' AND ref='$item_id'";
  1108. $res_props = Database::query($sql_props);
  1109. if (Database::num_rows($res_props) > 0) {
  1110. while ($row_props = Database::fetch_array($res_props)) {
  1111. //insert into announcement item_property
  1112. $time = api_get_utc_datetime();
  1113. $sql_ins_props = "INSERT INTO $table_props ".
  1114. "(c_id, tool, insert_user_id, insert_date, ".
  1115. "lastedit_date, ref, lastedit_type,".
  1116. "lastedit_user_id, to_group_id, to_user_id, ".
  1117. "visibility, start_visible, end_visible)".
  1118. " VALUES ".
  1119. "($course_id, 'announcement','".$row_props['insert_user_id']."','".$time."',".
  1120. "'$time','$ann_id','AnnouncementAdded',".
  1121. "'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."',".
  1122. "'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')";
  1123. $res_ins_props = Database::query($sql_ins_props);
  1124. if ($res_ins_props <= 0) {
  1125. return -1;
  1126. } else {
  1127. //copy was a success
  1128. return $ann_id;
  1129. }
  1130. }
  1131. }
  1132. } else {
  1133. return -1;
  1134. }
  1135. }
  1136. return -1;
  1137. }
  1138. /**
  1139. * This function separates the users from the groups
  1140. * users have a value USER:XXX (with XXX the dokeos id
  1141. * groups have a value GROUP:YYY (with YYY the group id)
  1142. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1143. * @return array
  1144. */
  1145. function separate_users_groups($to)
  1146. {
  1147. $grouplist = array();
  1148. $userlist = array();
  1149. $send_to = null;
  1150. $send_to['everyone'] = false;
  1151. if (is_array($to) && count($to) > 0) {
  1152. foreach ($to as $to_item) {
  1153. list($type, $id) = explode(':', $to_item);
  1154. switch ($type) {
  1155. case 'everyone':
  1156. $send_to['everyone'] = true;
  1157. case 'GROUP':
  1158. $grouplist[] = $id;
  1159. break;
  1160. case 'USER':
  1161. $userlist[] = $id;
  1162. break;
  1163. }
  1164. }
  1165. $send_to['groups'] = $grouplist;
  1166. $send_to['users'] = $userlist;
  1167. }
  1168. return $send_to;
  1169. }
  1170. /**
  1171. * returns all the users and all the groups a specific Agenda item has been sent to
  1172. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1173. * @return array
  1174. */
  1175. function sent_to($tool, $id)
  1176. {
  1177. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1178. $tool = Database::escape_string($tool);
  1179. $id = Database::escape_string($id);
  1180. $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'";
  1181. $result = Database::query($sql);
  1182. while ($row = Database::fetch_array($result)) {
  1183. // if to_group_id is null then it is sent to a specific user
  1184. // if to_group_id = 0 then it is sent to everybody
  1185. if (!is_null($row['to_group_id'])) {
  1186. $sent_to_group[] = $row['to_group_id'];
  1187. //echo $row['to_group_id'];
  1188. }
  1189. // if to_user_id <> 0 then it is sent to a specific user
  1190. if ($row['to_user_id'] <> 0) {
  1191. $sent_to_user[] = $row['to_user_id'];
  1192. }
  1193. }
  1194. if (isset($sent_to_group)) {
  1195. $sent_to['groups'] = $sent_to_group;
  1196. }
  1197. if (isset($sent_to_user)) {
  1198. $sent_to['users'] = $sent_to_user;
  1199. }
  1200. return $sent_to;
  1201. }
  1202. /**
  1203. * constructs the form to display all the groups and users the message has been sent to
  1204. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1205. * @param array $sent_to_array: a 2 dimensional array containing the groups and the users
  1206. * the first level is a distinction between groups and users: $sent_to_array['groups'] and $sent_to_array['users']
  1207. * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array containing all the id's of the
  1208. * groups (resp. users) who have received this message.
  1209. * @return html
  1210. */
  1211. function sent_to_form($sent_to_array)
  1212. {
  1213. // we find all the names of the groups
  1214. $group_names = get_course_groups();
  1215. // we count the number of users and the number of groups
  1216. if (isset($sent_to_array['users'])) {
  1217. $number_users = count($sent_to_array['users']);
  1218. } else {
  1219. $number_users = 0;
  1220. }
  1221. if (isset($sent_to_array['groups'])) {
  1222. $number_groups = count($sent_to_array['groups']);
  1223. } else {
  1224. $number_groups = 0;
  1225. }
  1226. $total_numbers = $number_users + $number_groups;
  1227. $output = array();
  1228. // starting the form if there is more than one user/group
  1229. if ($total_numbers > 1) {
  1230. //$output.="<option>".get_lang("SentTo")."</option>";
  1231. // outputting the name of the groups
  1232. if (is_array($sent_to_array['groups'])) {
  1233. foreach ($sent_to_array['groups'] as $group_id) {
  1234. if (isset($group_names[$group_id]['name'])) {
  1235. $output[] = $group_names[$group_id]['name'];
  1236. }
  1237. }
  1238. }
  1239. if (isset($sent_to_array['users'])) {
  1240. if (is_array($sent_to_array['users'])) {
  1241. foreach ($sent_to_array['users'] as $user_id) {
  1242. // @todo add username as tooltip - is this fucntion still used ?
  1243. // $user_info= api_get_user_info($user_id);
  1244. // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
  1245. $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
  1246. }
  1247. }
  1248. }
  1249. } else {
  1250. // there is only one user/group
  1251. if (is_array($sent_to_array['users'])) {
  1252. // @todo add username as tooltip - is this fucntion still used ?
  1253. // $user_info = api_get_user_info($sent_to_array['users'][0]);
  1254. // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
  1255. $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
  1256. }
  1257. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] !== 0) {
  1258. $group_id = $sent_to_array['groups'][0];
  1259. $output[] = $group_names[$group_id]['name'];
  1260. }
  1261. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] == 0) {
  1262. $output[] = get_lang("Everybody");
  1263. }
  1264. }
  1265. if (!empty($output)) {
  1266. $output = array_filter($output);
  1267. if (count($output) > 0) {
  1268. $output = implode(', ', $output);
  1269. }
  1270. return $output;
  1271. }
  1272. }
  1273. /**
  1274. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  1275. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1276. */
  1277. function show_group_filter_form()
  1278. {
  1279. $group_list = get_course_groups();
  1280. echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
  1281. echo "<option value=\"agenda.php?group=none\">".get_lang('ShowAll')."</option>";
  1282. foreach ($group_list as $this_group) {
  1283. echo "<option value=\"agenda.php?action=view&group=".$this_group['id']."\" ";
  1284. echo ($this_group['id'] == $_SESSION['group']) ? " selected" : "";
  1285. echo ">".$this_group['name']."</option>";
  1286. }
  1287. echo "</select>";
  1288. }
  1289. /**
  1290. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  1291. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1292. */
  1293. function show_user_filter_form()
  1294. {
  1295. $user_list = get_course_users();
  1296. echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
  1297. echo "<option value=\"agenda.php?user=none\">".get_lang('ShowAll')."</option>";
  1298. foreach ($user_list as $this_user) {
  1299. // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
  1300. echo "<option value=\"agenda.php?action=view&user=".$this_user['uid']."\" ";
  1301. echo ($this_user['uid'] == $_SESSION['user']) ? " selected" : "";
  1302. echo ">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
  1303. }
  1304. echo "</select>";
  1305. }
  1306. /**
  1307. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  1308. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1309. */
  1310. function show_user_group_filter_form()
  1311. {
  1312. echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
  1313. echo "<option value=\"agenda.php?user=none&action=view\">".get_lang("ShowAll")."</option>";
  1314. // Groups
  1315. $group_list = get_course_groups();
  1316. $group_available_to_access = array();
  1317. $option = '';
  1318. if (!empty($group_list)) {
  1319. $option = "<optgroup label=\"".get_lang("Groups")."\">";
  1320. foreach ($group_list as $this_group) {
  1321. // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
  1322. $has_access = GroupManager::user_has_access(api_get_user_id(), $this_group['id'], GroupManager::GROUP_TOOL_CALENDAR);
  1323. $result = GroupManager::get_group_properties($this_group['id']);
  1324. if ($result['calendar_state'] != '0') {
  1325. $group_available_to_access[] = $this_group['id'];
  1326. }
  1327. // lastedit
  1328. if ($has_access || $result['calendar_state'] == '1') {
  1329. $option.= "<option value=\"agenda.php?action=view&group=".$this_group['id']."\" ";
  1330. $option.= ($this_group['id'] == $_SESSION['group']) ? " selected" : "";
  1331. $option.= ">".$this_group['name']."</option>";
  1332. }
  1333. }
  1334. $option.= "</optgroup>";
  1335. }
  1336. echo $option;
  1337. // Users
  1338. $user_list = get_course_users();
  1339. if (!empty($user_list)) {
  1340. echo "<optgroup label=\"".get_lang("Users")."\">";
  1341. foreach ($user_list as $this_user) {
  1342. echo "<option value=\"agenda.php?action=view&user=".$this_user['uid']."\" ";
  1343. echo (isset($_SESSION['user']) && $this_user['uid'] == $_SESSION['user']) ? " selected" : "";
  1344. echo ">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
  1345. }
  1346. echo "</optgroup>";
  1347. }
  1348. echo "</select>";
  1349. }
  1350. /**
  1351. * This tools loads all the users and all the groups who have received a specific item (in this case an agenda item)
  1352. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1353. */
  1354. function load_edit_users($tool, $id)
  1355. {
  1356. $tool = Database::escape_string($tool);
  1357. $id = Database::escape_string($id);
  1358. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1359. $course_id = api_get_course_int_id();
  1360. $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE c_id = $course_id AND tool='$tool' AND ref='$id'";
  1361. $result = Database::query($sql) or die(Database::error());
  1362. while ($row = Database::fetch_array($result)) {
  1363. $to_group = $row['to_group_id'];
  1364. switch ($to_group) {
  1365. // it was send to one specific user
  1366. case null:
  1367. $to[] = "USER:".$row['to_user_id'];
  1368. break;
  1369. // it was sent to everyone
  1370. case 0:
  1371. return "everyone";
  1372. exit;
  1373. break;
  1374. default:
  1375. $to[] = "GROUP:".$row['to_group_id'];
  1376. }
  1377. }
  1378. return $to;
  1379. }
  1380. /**
  1381. * This functions swithes the visibility a course resource using the visible field in 'last_tooledit' values: 0 = invisible
  1382. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1383. */
  1384. function change_visibility($tool, $id, $visibility)
  1385. {
  1386. global $_course;
  1387. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1388. $tool = Database::escape_string($tool);
  1389. $id = Database::escape_string($id);
  1390. /*
  1391. $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".TOOL_CALENDAR_EVENT."' AND ref='$id'";
  1392. $result=Database::query($sql) or die (Database::error());
  1393. $row=Database::fetch_array($result);
  1394. */
  1395. if ($visibility == 0) {
  1396. $sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='0' WHERE tool='$tool' AND ref='$id'";
  1397. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "invisible", api_get_user_id());
  1398. } else {
  1399. $sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='1' WHERE tool='$tool' AND ref='$id'";
  1400. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "visible", api_get_user_id());
  1401. }
  1402. }
  1403. /**
  1404. * The links that allows the course administrator to add a new agenda item, to filter on groups or users
  1405. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1406. */
  1407. function display_courseadmin_links($filter = 0)
  1408. {
  1409. if (!api_get_course_int_id()) {
  1410. $type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : 'personal';
  1411. if ($type == 'platform') {
  1412. $type = 'admin';
  1413. }
  1414. return "<a href='agenda_js.php?type=$type'>".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1415. }
  1416. $form = null;
  1417. if (!isset($_GET['action'])) {
  1418. $form = show_to($filter, 'selected_form_id_search');
  1419. $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar_na.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1420. } else {
  1421. $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1422. }
  1423. $actions .= "<a href='agenda.php?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&action=add'>".Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM)."</a>";
  1424. $actions .= "<a href='agenda.php?".api_get_cidreq()."&action=importical'>".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM)."</a>";
  1425. $actions .= $form;
  1426. return $actions;
  1427. }
  1428. /**
  1429. * The links that allows the student AND course administrator to show all agenda items and sort up/down
  1430. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1431. * @author Julio Montoya removing options, changing to a simple agenda tool
  1432. */
  1433. function display_student_links()
  1434. {
  1435. global $show;
  1436. $month = isset($_GET['month']) ? intval($_GET['month']) : null;
  1437. $year = isset($_GET['year']) ? intval($_GET['year']) : null;
  1438. $day_url = '&month='.$month.'&year='.$year;
  1439. if ($_SESSION['view'] <> 'month') {
  1440. echo "<a href=\"".api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id()."&amp;view=month\">".Display::return_icon('month_empty.png', get_lang('MonthView'), '', ICON_SIZE_MEDIUM)."</a> ";
  1441. } else {
  1442. echo "<a href=\"".api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id()."&amp;view=list\">".Display::return_icon('week.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM)."</a> ";
  1443. }
  1444. $day_url = '&month='.date('m').'&year='.date('Y').'&view='.Security::remove_XSS($_GET['view']);
  1445. $today_url = api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id();
  1446. echo Display::url(get_lang('Today'), $today_url, array('class' => 'btn'));
  1447. }
  1448. /**
  1449. * get all the information of the agenda_item from the database
  1450. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1451. * @param integer the id of the agenda item we are getting all the information of
  1452. * @return array an associative array that contains all the information of the agenda item. The keys are the database fields
  1453. */
  1454. function get_agenda_item($id)
  1455. {
  1456. global $TABLEAGENDA;
  1457. $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
  1458. $id = Database::escape_string($id);
  1459. $item = array();
  1460. if (empty($id)) {
  1461. $id = intval(Database::escape_string(($_GET['id'])));
  1462. } else {
  1463. $id = (int) $id;
  1464. }
  1465. $course_id = api_get_course_int_id();
  1466. if (empty($id)) {
  1467. return $item;
  1468. }
  1469. $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."' AND c_id = $course_id ";
  1470. $result = Database::query($sql);
  1471. $entry_to_edit = Database::fetch_array($result);
  1472. $item['title'] = $entry_to_edit["title"];
  1473. $item['content'] = $entry_to_edit["content"];
  1474. $item['start_date'] = $entry_to_edit["start_date"];
  1475. $item['end_date'] = $entry_to_edit["end_date"];
  1476. $item['to'] = load_edit_users(TOOL_CALENDAR_EVENT, $id);
  1477. // if the item has been sent to everybody then we show the compact to form
  1478. if ($item['to'] == "everyone") {
  1479. $_SESSION['allow_individual_calendar'] = "hide";
  1480. } else {
  1481. $_SESSION['allow_individual_calendar'] = "show";
  1482. }
  1483. $item['repeat'] = false;
  1484. $sql = "SELECT * FROM $t_agenda_repeat WHERE c_id = $course_id AND cal_id = $id";
  1485. $res = Database::query($sql);
  1486. if (Database::num_rows($res) > 0) {
  1487. //this event is repetitive
  1488. $row = Database::fetch_array($res);
  1489. $item['repeat'] = true;
  1490. $item['repeat_type'] = $row['cal_type'];
  1491. $item['repeat_end'] = $row['cal_end'];
  1492. $item['repeat_frequency'] = $row['cal_frequency']; //unused in 1.8.5 RC1 - will be used later to say if once every 2 or 3 weeks, for example
  1493. $item['repeat_days'] = $row['cal_days']; //unused in 1.8.5 RC1 - will be used later
  1494. }
  1495. //TODO - add management of repeat exceptions
  1496. return $item;
  1497. }
  1498. /**
  1499. * This is the function that updates an agenda item. It does 3 things
  1500. * 1. storethe start_date, end_date, title and message in the calendar_event table
  1501. * 2. store the groups/users who this message is meant for in the item_property table
  1502. * 3. modify the attachments (if needed)
  1503. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1504. * @author Julio Montoya Adding UTC support
  1505. */
  1506. function store_edited_agenda_item($event_id, $id_attach, $file_comment)
  1507. {
  1508. // STEP 1: editing the calendar_event table
  1509. // 1.a. some filtering of the input data
  1510. $id = $event_id;
  1511. $title = strip_tags(trim($_POST['title'])); // no html allowed in the title
  1512. $content = trim($_POST['content']);
  1513. $start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
  1514. $end_date = (int) $_POST['end_fyear']."-".(int) $_POST['end_fmonth']."-".(int) $_POST['end_fday']." ".(int) $_POST['end_fhour'].":".(int) $_POST['end_fminute'].":00";
  1515. $to = $_POST['selectedform'];
  1516. if ($_POST['empty_end_date'] == 'on') {
  1517. $end_date = "0000-00-00 00:00:00";
  1518. }
  1519. $course_info = api_get_course_info();
  1520. $agendaObj = new Agenda();
  1521. if (empty($course_info)) {
  1522. $agendaObj->type = 'personal';
  1523. } else {
  1524. $agendaObj->set_course($course_info);
  1525. $agendaObj->type = 'course';
  1526. if (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id)) {
  1527. return false;
  1528. }
  1529. if (!api_is_allowed_to_edit(null, true)) {
  1530. return false;
  1531. }
  1532. }
  1533. $all_day = isset($_REQUEST['all_day']) && !empty($_REQUEST['all_day']) ? 1 : 0;
  1534. $agendaObj->edit_event($id, $start_date, $end_date, $all_day, null, $title, $content);
  1535. if (empty($id_attach)) {
  1536. add_agenda_attachment_file($file_comment, $id);
  1537. } else {
  1538. edit_agenda_attachment_file($file_comment, $id, $id_attach);
  1539. }
  1540. // step 2: editing the item_property table (=delete all and add the new destination users/groups)
  1541. /*if ($edit_result = true) {
  1542. // 2.a. delete everything for the users
  1543. $sql_delete = "DELETE FROM ".$TABLE_ITEM_PROPERTY." WHERE c_id = $course_id AND ref='$id' AND tool='".TOOL_CALENDAR_EVENT."'";
  1544. $result = Database::query($sql_delete) or die(Database::error());
  1545. // 2.b. storing the new users/groups
  1546. if (!is_null($to)) { // !is_null($to): when no user is selected we send it to everyone
  1547. $send_to = separate_users_groups($to);
  1548. // storing the selected groups
  1549. if (is_array($send_to['groups'])) {
  1550. foreach ($send_to['groups'] as $group) {
  1551. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), $group, '', $start_date, $end_date);
  1552. }
  1553. }
  1554. // storing the selected users
  1555. if (is_array($send_to['users'])) {
  1556. foreach ($send_to['users'] as $user) {
  1557. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), '', $user, $start_date, $end_date);
  1558. }
  1559. }
  1560. } else {
  1561. // the message is sent to everyone, so we set the group to 0
  1562. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), '', '', $start_date, $end_date);
  1563. }
  1564. }*/
  1565. // step 3: update the attachments (=delete all and add those in the session
  1566. update_added_resources("Agenda", $id);
  1567. // return the message;
  1568. Display::display_confirmation_message(get_lang("EditSuccess"));
  1569. }
  1570. /**
  1571. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit)
  1572. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1573. */
  1574. function save_edit_agenda_item($id, $title, $content, $start_date, $end_date)
  1575. {
  1576. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1577. $id = Database::escape_string($id);
  1578. $title = Database::escape_string($title);
  1579. $content = Database::escape_string($content);
  1580. $start_date = Database::escape_string($start_date);
  1581. $end_date = Database::escape_string($end_date);
  1582. // store the modifications in the table calendar_event
  1583. $sql = "UPDATE ".$TABLEAGENDA."
  1584. SET title ='".$title."',
  1585. content ='".$content."',
  1586. start_date ='".$start_date."',
  1587. end_date ='".$end_date."'
  1588. WHERE id='".$id."'";
  1589. $result = Database::query($sql);
  1590. return true;
  1591. }
  1592. /**
  1593. * This is the function that deletes an agenda item.
  1594. * The agenda item is no longer physically deleted but the visibility in the item_property table is set to 2
  1595. * which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
  1596. * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
  1597. * by the course administrator
  1598. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1599. * @param integer the id of the agenda item wa are deleting
  1600. */
  1601. function delete_agenda_item($id)
  1602. {
  1603. global $_course;
  1604. $id = Database::escape_string($id);
  1605. if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  1606. if (!empty($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "delete") {
  1607. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  1608. $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
  1609. $id = intval($_GET['id']);
  1610. $sql = "SELECT * FROM $t_agenda_r WHERE cal_id = $id";
  1611. $res = Database::query($sql);
  1612. if (Database::num_rows($res) > 0) {
  1613. $sql_children = "SELECT * FROM $t_agenda WHERE parent_event_id = $id";
  1614. $res_children = Database::query($sql_children);
  1615. if (Database::num_rows($res_children) > 0) {
  1616. while ($row_child = Database::fetch_array($res_children)) {
  1617. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $row_child['id'], 'delete', api_get_user_id());
  1618. }
  1619. }
  1620. $sql_del = "DELETE FROM $t_agenda_r WHERE cal_id = $id";
  1621. $res_del = Database::query($sql_del);
  1622. }
  1623. //$sql = "DELETE FROM ".$TABLEAGENDA." WHERE id='$id'";
  1624. //$sql= "UPDATE ".$TABLE_ITEM_PROPERTY." SET visibility='2' WHERE tool='Agenda' and ref='$id'";
  1625. //$result = Database::query($sql) or die (Database::error());
  1626. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, 'delete', api_get_user_id());
  1627. // delete the resources that were added to this agenda item
  1628. // 2DO: as we no longer fysically delete the agenda item (to make it possible to 'restore'
  1629. // deleted items, we should not delete the added resources either.
  1630. // delete_added_resource("Agenda", $id); // -> this is no longer needed as the message is not really deleted but only visibility=2 (only platform admin can see it)
  1631. //resetting the $id;
  1632. $id = null;
  1633. // displaying the result message in the yellow box
  1634. Display::display_confirmation_message(get_lang("AgendaDeleteSuccess"));
  1635. } // if (isset($id)&&$id&&isset($action)&&$action=="delete")
  1636. } // if ($is_allowed_to_edit)
  1637. }
  1638. /**
  1639. * Makes an agenda item visible or invisible for a student
  1640. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1641. * @param integer id the id of the agenda item we are changing the visibility of
  1642. */
  1643. function showhide_agenda_item($id)
  1644. {
  1645. global $nameTools;
  1646. /*
  1647. SHOW / HIDE A CALENDAR ITEM
  1648. */
  1649. // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following:
  1650. // change visibility -> studentview -> course manager view
  1651. if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) and $_GET['isStudentView'] <> "false") {
  1652. if (isset($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "showhide") {
  1653. $id = (int) addslashes($_GET['id']);
  1654. if (isset($_GET['next_action']) && $_GET['next_action'] == strval(intval($_GET['next_action']))) {
  1655. $visibility = $_GET['next_action'];
  1656. change_visibility($nameTools, $id, $visibility);
  1657. Display::display_confirmation_message(get_lang("VisibilityChanged"));
  1658. }
  1659. }
  1660. }
  1661. }
  1662. /**
  1663. * Displays all the agenda items
  1664. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1665. * @author Yannick Warnier <yannick.warnier@beeznest.com> - cleanup
  1666. * @author Julio Montoya <gugli100@gmail.com> - Refactoring
  1667. */
  1668. function display_agenda_items($agenda_items, $day = false)
  1669. {
  1670. global $charset;
  1671. if (isset($day) && $day) {
  1672. $new_items = array();
  1673. foreach ($agenda_items as $item) {
  1674. if (substr($item['start_date'], 8, 2) == $day) {
  1675. $new_items[] = $item;
  1676. }
  1677. }
  1678. $agenda_items = $new_items;
  1679. }
  1680. if (isset($_GET['sort']) && $_GET['sort'] == 'asc') {
  1681. $sort_inverse = 'desc';
  1682. $sort = 'asc';
  1683. } else {
  1684. $sort_inverse = 'asc';
  1685. $sort = 'desc';
  1686. }
  1687. if (isset($_GET['col']) && $_GET['col'] == 'end') {
  1688. $sort_item = 'end_date_tms';
  1689. $col = 'end';
  1690. } else {
  1691. $sort_item = 'start_date_tms';
  1692. $col = 'start';
  1693. }
  1694. $agenda_items = msort($agenda_items, $sort_item, $sort);
  1695. //DISPLAY: NO ITEMS
  1696. if (empty($agenda_items)) {
  1697. echo Display::display_warning_message(get_lang('NoAgendaItems'));
  1698. } else {
  1699. echo '<table class="data_table">';
  1700. $th = Display::tag('th', get_lang('Title'));
  1701. $month = isset($_GET['month']) ? intval($_GET['month']) : null;
  1702. $year = isset($_GET['year']) ? intval($_GET['year']) : null;
  1703. $day = isset($_GET['day']) ? intval($_GET['day']) : null;
  1704. $url = api_get_self().'?'.api_get_cidreq().'&month='.$month.'&year='.$year.'&day='.$day;
  1705. $th .= Display::tag('th', Display::url(get_lang('StartTimeWindow'), $url.'&sort='.$sort_inverse.'&col=start'));
  1706. $th .= Display::tag('th', Display::url(get_lang('EndTimeWindow'), $url.'&sort='.$sort_inverse.'&col=end'));
  1707. if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  1708. $th .= Display::tag('th', get_lang('Modify'));
  1709. }
  1710. echo Display::tag('tr', $th);
  1711. $counter = 0;
  1712. foreach ($agenda_items as $myrow) {
  1713. $is_repeated = !empty($myrow['parent_event_id']);
  1714. $class = 'row_even';
  1715. if ($counter % 2) {
  1716. $class = 'row_odd';
  1717. }
  1718. /* display: the icon, title, destinees of the item */
  1719. echo '<tr class="'.$class.'">';
  1720. //Title
  1721. echo "<td>";
  1722. $attach_icon = '';
  1723. // attachment list
  1724. $attachment_list = get_attachment($myrow['id']);
  1725. if (!empty($attachment_list)) {
  1726. $attach_icon = ' '.Display::return_icon('attachment.gif', get_lang('Attachment'));
  1727. }
  1728. $title_class = '';
  1729. if (isset($myrow['visibility']) && $myrow['visibility'] == 0) {
  1730. $title_class = 'invisible';
  1731. }
  1732. switch ($myrow['calendar_type']) {
  1733. case 'global':
  1734. $icon_type = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22);
  1735. echo $icon_type.' '.$myrow['title'].$attach_icon;
  1736. break;
  1737. case 'personal':
  1738. $icon_type = Display::return_icon('user.png', get_lang(' '), array(), 22);
  1739. echo $icon_type.' '.$myrow['title'].$attach_icon;
  1740. break;
  1741. case 'course':
  1742. $icon_type = Display::return_icon('course.png', get_lang('Course'), array(), 22);
  1743. $agenda_url = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?agenda_id='.$myrow['id'].'&action=view';
  1744. echo Display::url($icon_type.' '.$myrow['title'].$attach_icon, $agenda_url, array('class' => $title_class));
  1745. break;
  1746. }
  1747. echo '</td>';
  1748. //Start date
  1749. echo '<td>';
  1750. if (!empty($myrow['start_date']) && $myrow['start_date'] != '0000-00-00 00:00:00') {
  1751. echo api_format_date($myrow['start_date']);
  1752. }
  1753. echo '</td>';
  1754. //End date
  1755. echo '<td>';
  1756. if (!empty($myrow['end_date']) && $myrow['end_date'] != '0000-00-00 00:00:00') {
  1757. echo api_format_date($myrow['end_date']);
  1758. }
  1759. echo '</td>';
  1760. /* Display: edit delete button (course admin only) */
  1761. if (!$is_repeated && (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) && $myrow['calendar_type'] == 'course') {
  1762. echo '<td align="center">';
  1763. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
  1764. // a coach can only delete an element belonging to his session
  1765. $mylink = api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&id='.$myrow['id'].'&sort='.$sort.'&col='.$col.'&';
  1766. // edit
  1767. echo '<a href="'.$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action=edit&id_attach='.$attachment_list['id'].'" title="'.get_lang("ModifyCalendarItem").'">';
  1768. echo Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL)."</a>";
  1769. echo '<a href="'.$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action=announce" title="'.get_lang("AddAnnouncement").'">';
  1770. echo Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), array(), ICON_SIZE_SMALL)."</a> ";
  1771. if ($myrow['visibility'] == 1) {
  1772. $image_visibility = "visible";
  1773. $text_visibility = get_lang("Hide");
  1774. $next_action = 0;
  1775. } else {
  1776. $image_visibility = "invisible";
  1777. $text_visibility = get_lang("Show");
  1778. $next_action = 1;
  1779. }
  1780. echo '<a href="'.$mylink.api_get_cidreq().'&toolgroup='.Security::remove_XSS($_GET['toolgroup']).'&action=showhide&next_action='.$next_action.'" title="'.$text_visibility.'">'.Display::return_icon($image_visibility.'.png', $text_visibility, '', ICON_SIZE_SMALL).'</a> ';
  1781. echo "<a href=\"".$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup'])."&action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."')) return false;\" title=\"".get_lang("Delete")."\"> ";
  1782. echo Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL)."&nbsp;</a>";
  1783. }
  1784. $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'];
  1785. //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
  1786. //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
  1787. //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
  1788. echo '<a href="#" onclick="javascript:win_print=window.open(\'print.php?id='.$myrow['id'].'\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">'.Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL).'</a>&nbsp;';
  1789. echo '</td>';
  1790. } else {
  1791. if ($is_repeated && (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() )) {
  1792. echo '<td align="center">';
  1793. echo get_lang('RepeatedEvent'), ' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $myrow['parent_event_id'], '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>';
  1794. echo '</td>';
  1795. }
  1796. if ((api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) ) && ($myrow['calendar_type'] == 'personal' OR $myrow['calendar_type'] == 'global')) {
  1797. echo '<td align="center">';
  1798. echo '</td>';
  1799. }
  1800. }
  1801. $counter++;
  1802. echo "</tr>";
  1803. } // end while ($myrow=Database::fetch_array($result))
  1804. echo "</table><br /><br />";
  1805. }
  1806. if (!empty($event_list)) {
  1807. $event_list = api_substr($event_list, 0, -1);
  1808. } else {
  1809. $event_list = '0';
  1810. }
  1811. echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"$event_list\" /></form>";
  1812. // closing the layout table
  1813. echo "</td>",
  1814. "</tr>",
  1815. "</table>";
  1816. }
  1817. /**
  1818. * Show a list with all the attachments according to the post's id
  1819. * @param the post's id
  1820. * @return array with the post info
  1821. * @author Christian Fasanando
  1822. * @version November 2008, dokeos 1.8.6
  1823. */
  1824. function get_attachment($agenda_id, $course_id = null)
  1825. {
  1826. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  1827. if (empty($course_id)) {
  1828. $course_id = api_get_course_int_id();
  1829. } else {
  1830. $course_id = intval($course_id);
  1831. }
  1832. $agenda_id = Database::escape_string($agenda_id);
  1833. $row = array();
  1834. $sql = 'SELECT id,path, filename,comment FROM '.$agenda_table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.(int) $agenda_id.'';
  1835. $result = Database::query($sql);
  1836. if (Database::num_rows($result) != 0) {
  1837. $row = Database::fetch_array($result);
  1838. }
  1839. return $row;
  1840. }
  1841. /**
  1842. * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
  1843. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1844. */
  1845. function display_one_agenda_item($agenda_id)
  1846. {
  1847. global $TABLEAGENDA;
  1848. global $TABLE_ITEM_PROPERTY;
  1849. global $select_month, $select_year;
  1850. global $DaysShort, $DaysLong, $MonthsLong;
  1851. global $is_courseAdmin;
  1852. global $dateFormatLong, $timeNoSecFormat, $charset;
  1853. // getting the name of the groups
  1854. $group_names = get_course_groups();
  1855. $agenda_id = intval($agenda_id);
  1856. if (!(api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  1857. $visibility_condition = " AND ip.visibility='1' ";
  1858. }
  1859. $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  1860. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  1861. WHERE agenda.id = ip.ref
  1862. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  1863. $visibility_condition
  1864. AND agenda.id='$agenda_id'";
  1865. $result = Database::query($sql);
  1866. $number_items = Database::num_rows($result);
  1867. $myrow = Database::fetch_array($result, 'ASSOC'); // there should be only one item so no need for a while loop
  1868. $sql_rep = "SELECT * FROM $TABLEAGENDA WHERE id = $agenda_id AND parent_event_id IS NOT NULL AND parent_event_id !=0";
  1869. $res_rep = Database::query($sql_rep);
  1870. $repeat = false;
  1871. $repeat_id = 0;
  1872. if (Database::num_rows($res_rep) > 0) {
  1873. $repeat = true;
  1874. $row_rep = Database::fetch_array($res_rep);
  1875. $repeat_id = $row_rep['parent_event_id'];
  1876. }
  1877. // DISPLAY: NO ITEMS
  1878. if ($number_items == 0) {
  1879. Display::display_warning_message(get_lang("NoAgendaItems"));
  1880. return false;
  1881. }
  1882. // DISPLAY: THE ITEMS
  1883. echo "<table id=\"data_table\" class=\"data_table\">";
  1884. // DISPLAY : the icon, title, destinees of the item
  1885. $myrow["start_date"] = api_get_local_time($myrow["start_date"]);
  1886. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  1887. $db_date = (int) api_format_date($myrow["start_date"], "%d").intval(api_format_date($myrow["start_date"], "%m")).api_format_date($myrow["start_date"], "%Y");
  1888. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
  1889. if ($myrow['visibility'] == '0') {
  1890. $style = "data_hidden";
  1891. $stylenotbold = "datanotbold_hidden";
  1892. $text_style = "text_hidden";
  1893. } else {
  1894. $style = "data";
  1895. $stylenotbold = "datanotbold";
  1896. $text_style = "text";
  1897. }
  1898. } else {
  1899. $style = "datanow";
  1900. $stylenotbold = "datanotboldnow";
  1901. $text_style = "textnow";
  1902. }
  1903. echo Display::tag('h2', $myrow['title']);
  1904. echo "<tr>";
  1905. if (api_is_allowed_to_edit(false, true)) {
  1906. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
  1907. // a coach can only delete an element belonging to his session
  1908. // DISPLAY: edit delete button (course admin only)
  1909. $export_icon = '../img/export.png';
  1910. $export_icon_low = '../img/export_low_fade.png';
  1911. $export_icon_high = '../img/export_high_fade.png';
  1912. echo '<th style="text-align:right">';
  1913. if (!$repeat && api_is_allowed_to_edit(false, true)) {
  1914. // edit
  1915. $mylink = api_get_self()."?".api_get_cidreq()."&origin=".Security::remove_XSS($_GET['origin'])."&id=".$myrow['id'];
  1916. if (!empty($_GET['agenda_id'])) {
  1917. // rather ugly hack because the id parameter is already set above but below we set it again
  1918. $mylink .= '&agenda_id='.Security::remove_XSS($_GET['agenda_id']).'&id='.Security::remove_XSS($_GET['agenda_id']);
  1919. }
  1920. if ($myrow['visibility'] == 1) {
  1921. $image_visibility = "visible";
  1922. $next_action = 0;
  1923. } else {
  1924. $image_visibility = "invisible";
  1925. $next_action = 1;
  1926. }
  1927. echo '<a href="'.$mylink.'&action=showhide&next_action='.$next_action.'">'.Display::return_icon($image_visibility.'.png', get_lang('Visible'), '', ICON_SIZE_SMALL).'</a>';
  1928. echo "<a href=\"".$mylink."&action=edit\">",
  1929. Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL), "</a>",
  1930. "<a href=\"".$mylink."&action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."')) return false;\">",
  1931. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL), "</a>";
  1932. }
  1933. $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'];
  1934. //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
  1935. //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
  1936. //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
  1937. echo '<a href="javascript: void(0);" onclick="javascript:win_print=window.open(\'print.php?id='.$myrow['id'].'\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">'.Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL).'</a>&nbsp;';
  1938. echo "</th>";
  1939. }
  1940. }
  1941. // title
  1942. echo "<tr class='row_odd'>";
  1943. echo '<td colspan="2">'.get_lang("StartTime").": ";
  1944. echo api_format_date($myrow['start_date']);
  1945. echo "</td>";
  1946. echo "</td>";
  1947. echo "<tr class='row_odd'>";
  1948. echo '<td colspan="2">'.get_lang("EndTime").": ";
  1949. echo api_convert_and_format_date($myrow['end_date']);
  1950. echo "</td>";
  1951. // Content
  1952. $content = $myrow['content'];
  1953. $content = make_clickable($content);
  1954. echo '<tr class="row_even">';
  1955. echo '<td '.(api_is_allowed_to_edit() ? 'colspan="3"' : 'colspan="2"').'>';
  1956. echo $content;
  1957. echo '</td></tr>';
  1958. //Attachments
  1959. $attachment_list = get_attachment($agenda_id);
  1960. if (!empty($attachment_list)) {
  1961. echo '<tr class="row_even"><td colspan="2">';
  1962. $realname = $attachment_list['path'];
  1963. $user_filename = $attachment_list['filename'];
  1964. $full_file_name = 'download.php?file='.$realname;
  1965. echo Display::return_icon('attachment.gif', get_lang('Attachment'));
  1966. echo '<a href="'.$full_file_name.'"> '.$user_filename.'</a>';
  1967. if (api_is_allowed_to_edit()) {
  1968. echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&action=delete_attach&id_attach='.$attachment_list['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a><br />';
  1969. }
  1970. echo '<br /><span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  1971. echo '</td></tr>';
  1972. }
  1973. // the message has been sent to
  1974. echo '<tr>';
  1975. echo "<td class='announcements_datum'>".get_lang("SentTo").": ";
  1976. $sent_to = sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
  1977. $sent_to_form = sent_to_form($sent_to);
  1978. echo $sent_to_form;
  1979. echo "</td></tr>";
  1980. if ($repeat) {
  1981. echo '<tr>';
  1982. echo '<td colspan="2">';
  1983. echo get_lang('RepeatedEvent').' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $repeat_id, '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>';
  1984. echo '</td>';
  1985. echo '</tr>';
  1986. }
  1987. /* Added resources */
  1988. if (check_added_resources("Agenda", $myrow["id"])) {
  1989. echo "<tr><td colspan='3'>";
  1990. echo "<i>".get_lang("AddedResources")."</i><br/>";
  1991. if ($myrow['visibility'] == 0) {
  1992. $addedresource_style = "invisible";
  1993. }
  1994. display_added_resources("Agenda", $myrow["id"], $addedresource_style);
  1995. echo "</td></tr>";
  1996. }
  1997. // closing the layout table
  1998. echo "</td>",
  1999. "</tr>",
  2000. "</table>";
  2001. }
  2002. /**
  2003. * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
  2004. * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
  2005. * we have to retrieve the information that is in the database and use this information in the forms.
  2006. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  2007. * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
  2008. * agenda item.
  2009. */
  2010. function show_add_form($id = '', $type = null)
  2011. {
  2012. global $MonthsLong;
  2013. $htmlHeadXtra[] = to_javascript();
  2014. // the default values for the forms
  2015. if ($_GET['originalresource'] !== 'no') {
  2016. $day = date('d');
  2017. $month = date('m');
  2018. $year = date('Y');
  2019. $hours = 9;
  2020. $minutes = '00';
  2021. $end_day = date('d');
  2022. $end_month = date('m');
  2023. $end_year = date('Y');
  2024. $end_hours = 17;
  2025. $end_minutes = '00';
  2026. $repeat = false;
  2027. } else {
  2028. // we are coming from the resource linker so there might already have been some information in the form.
  2029. // When we clicked on the button to add resources we stored every form information into a session and now we
  2030. // are doing the opposite thing: getting the information out of the session and putting it into variables to
  2031. // display it in the forms.
  2032. $form_elements = $_SESSION['formelements'];
  2033. $day = $form_elements['day'];
  2034. $month = $form_elements['month'];
  2035. $year = $form_elements['year'];
  2036. $hours = $form_elements['hour'];
  2037. $minutes = $form_elements['minutes'];
  2038. $end_day = $form_elements['end_day'];
  2039. $end_month = $form_elements['end_month'];
  2040. $end_year = $form_elements['end_year'];
  2041. $end_hours = $form_elements['end_hours'];
  2042. $end_minutes = $form_elements['end_minutes'];
  2043. $title = $form_elements['title'];
  2044. $content = $form_elements['content'];
  2045. $id = $form_elements['id'];
  2046. $to = $form_elements['to'];
  2047. $repeat = $form_elements['repeat'];
  2048. }
  2049. // switching the send to all/send to groups/send to users
  2050. if (isset($_POST['To']) && $_POST['To']) {
  2051. $day = $_POST['fday'];
  2052. $month = $_POST['fmonth'];
  2053. $year = $_POST['fyear'];
  2054. $hours = $_POST['fhour'];
  2055. $minutes = $_POST['fminute'];
  2056. $end_day = $_POST['end_fday'];
  2057. $end_month = $_POST['end_fmonth'];
  2058. $end_year = $_POST['end_fyear'];
  2059. $end_hours = $_POST['end_fhour'];
  2060. $end_minutes = $_POST['end_fminute'];
  2061. $title = $_POST['title'];
  2062. $content = $_POST['content'];
  2063. // the invisible fields
  2064. $action = $_POST['action'];
  2065. $id = $_POST['id'];
  2066. $repeat = !empty($_POST['repeat']) ? true : false;
  2067. }
  2068. $default_no_empty_end_date = 0;
  2069. $course_info = null;
  2070. // if the id is set then we are editing an agenda item
  2071. if (!empty($id)) {
  2072. $course_info = api_get_course_info();
  2073. $agendaObj = new Agenda();
  2074. if (!empty($course_info)) {
  2075. $agendaObj->set_course($course_info);
  2076. $agendaObj->type = 'course';
  2077. } else {
  2078. if (api_is_platform_admin() && $type == 'platform') {
  2079. $agendaObj->type = 'admin';
  2080. } else {
  2081. $agendaObj->type = 'personal';
  2082. }
  2083. }
  2084. $agendaItem = $agendaObj->get_event($id);
  2085. $title = $agendaItem['title'];
  2086. $content = $agendaItem['description'];
  2087. // start date
  2088. if ($agendaItem['start_date'] != '0000-00-00 00:00:00') {
  2089. $agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']);
  2090. list($datepart, $timepart) = explode(" ", $agendaItem['start_date']);
  2091. list($year, $month, $day) = explode("-", $datepart);
  2092. list($hours, $minutes, $seconds) = explode(":", $timepart);
  2093. }
  2094. // end date
  2095. if (!empty($agendaItem['end_date']) && $agendaItem['end_date'] != '0000-00-00 00:00:00') {
  2096. $agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']);
  2097. list($datepart, $timepart) = explode(" ", $agendaItem['end_date']);
  2098. list($end_year, $end_month, $end_day) = explode("-", $datepart);
  2099. list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
  2100. } else {
  2101. if ($agendaItem['all_day']) {
  2102. $end_year = $year;
  2103. $end_month = $month;
  2104. $end_day = $day;
  2105. $end_hours = $hours;
  2106. $end_minutes = $minutes;
  2107. $end_seconds = $seconds;
  2108. }
  2109. }
  2110. // attachments
  2111. //edit_added_resources("Agenda", $id);
  2112. //$to = $item_2_edit['to'];
  2113. } else {
  2114. $to = load_edit_users(TOOL_CALENDAR_EVENT, $id);
  2115. }
  2116. $content = stripslashes($content);
  2117. $title = stripslashes($title);
  2118. // we start a completely new item, we do not come from the resource linker
  2119. if (isset($_GET['originalresource']) && $_GET['originalresource'] !== "no" and $_GET['action'] == "add") {
  2120. $_SESSION["formelements"] = null;
  2121. unset_session_resources();
  2122. }
  2123. $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
  2124. $course_url = empty($course_info) ? null : api_get_cidreq();
  2125. ?>
  2126. <!-- START OF THE FORM -->
  2127. <form class="form-horizontal" enctype="multipart/form-data" action="<?php echo api_get_self().'?type='.Security::remove_XSS($type).'&origin='.$origin.'&'.$course_url."&sort=asc&toolgroup=".api_get_group_id().'&action='.Security::remove_XSS($_GET['action']); ?>" method="post" name="new_calendar_item">
  2128. <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
  2129. <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo $_GET['action']; ?>" />
  2130. <input type="hidden" name="id_attach" value="<?php echo isset($_REQUEST['id_attach']) ? intval($_REQUEST['id_attach']) : null; ?>" />
  2131. <input type="hidden" name="sort" value="asc" />
  2132. <input type="hidden" name="submit_event" value="ok" />
  2133. <?php
  2134. // The form title
  2135. if (isset($id) AND $id <> '') {
  2136. $form_title = get_lang('ModifyCalendarItem');
  2137. } else {
  2138. $form_title = get_lang('AddCalendarItem');
  2139. }
  2140. echo '<legend>'.$form_title.'</legend>';
  2141. // the title of the agenda item
  2142. echo '<div class="control-group">
  2143. <label class="control-label">
  2144. <span class="form_required">*</span>'.get_lang('ItemTitle').'
  2145. </label>
  2146. <div class="controls">
  2147. <div id="err_title" style="display:none;color:red"></div>
  2148. <input type="text" id="agenda_title" class="span5" name="title" value="';
  2149. if (isset($title))
  2150. echo $title;
  2151. echo '" />
  2152. </div>
  2153. </div>';
  2154. // selecting the users / groups
  2155. $group_id = api_get_group_id();
  2156. if (empty($id)) {
  2157. if (isset($group_id) && !empty($group_id)) {
  2158. echo '<input type="hidden" name="selected_form[0]" value="GROUP:'.$group_id.'"/>';
  2159. echo '<input type="hidden" name="To" value="true"/>';
  2160. } else {
  2161. echo '<div class="control-group">
  2162. <label class="control-label">
  2163. '.Display::return_icon('group.png', get_lang('To'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).' '.get_lang('To').'</a>
  2164. </label>
  2165. <div class="controls">';
  2166. show_to_form($to);
  2167. echo '</div>
  2168. </div>';
  2169. }
  2170. }
  2171. // start date and time
  2172. echo '<div class="control-group">';
  2173. echo '<label class="control-label">'.get_lang('StartDate').'</label>
  2174. <div class="controls">
  2175. <div id="err_date" style="display:none;color:red"></div>
  2176. <div id="err_start_date" style="display:none;color:red"></div>';
  2177. ?>
  2178. <select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
  2179. <?php
  2180. // small loop for filling all the dates
  2181. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  2182. foreach (range(1, 31) as $i) {
  2183. // values have to have double digits
  2184. $value = ($i <= 9 ? '0'.$i : $i );
  2185. // the current day is indicated with [] around the date
  2186. if ($value == $day) {
  2187. echo "<option value=\"".$value."\" selected> ".$i." </option>";
  2188. } else {
  2189. echo "<option value=\"$value\">$i</option>";
  2190. }
  2191. }
  2192. ?>
  2193. </select>
  2194. <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
  2195. <?php
  2196. for ($i = 1; $i <= 12; $i++) {
  2197. // values have to have double digits
  2198. if ($i <= 9) {
  2199. $value = "0".$i;
  2200. } else {
  2201. $value = $i;
  2202. }
  2203. if ($value == $month) {
  2204. echo "<option value=\"".$value."\" selected>".$MonthsLong[$i - 1]."</option>";
  2205. } else {
  2206. echo "<option value=\"".$value."\">".$MonthsLong[$i - 1]."</option>";
  2207. }
  2208. }
  2209. ?>
  2210. </select>
  2211. <select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
  2212. <option value="<?php echo ($year - 1); ?>"><?php echo ($year - 1); ?></option>
  2213. <option value="<?php echo $year; ?>" selected="selected"><?php echo $year; ?></option>
  2214. <?php
  2215. for ($i = 1; $i <= 5; $i++) {
  2216. $value = $year + $i;
  2217. echo "<option value=\"$value\">$value</option>";
  2218. }
  2219. ?>
  2220. </select>
  2221. <a href="javascript:openCalendar('new_calendar_item', 'f')">
  2222. <?php Display::display_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')); ?>
  2223. </a>
  2224. &nbsp;<?php echo get_lang('StartTime').": "; ?>&nbsp;
  2225. <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
  2226. <!-- <option value="--">--</option> -->
  2227. <?php
  2228. foreach (range(0, 23) as $i) {
  2229. // values have to have double digits
  2230. $value = ($i <= 9 ? '0'.$i : $i );
  2231. // the current hour is indicated with [] around the hour
  2232. if ($hours == $value) {
  2233. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2234. } else {
  2235. echo "<option value=\"$value\">$value</option>";
  2236. }
  2237. }
  2238. ?>
  2239. </select>
  2240. <select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
  2241. <!-- <option value="<?php echo $minutes ?>"><?php echo $minutes; ?></option> -->
  2242. <?php
  2243. foreach (range(0, 59) as $i) {
  2244. // values have to have double digits
  2245. $value = ($i <= 9 ? '0'.$i : $i );
  2246. if ($minutes == $value) {
  2247. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2248. } else {
  2249. echo "<option value=\"$value\">$value</option>";
  2250. }
  2251. }
  2252. ?>
  2253. </select>
  2254. <?php
  2255. echo ' </div>
  2256. </div>';
  2257. echo '<script>
  2258. $(function() {
  2259. $("#empty_end_date").click(function(){
  2260. if ($("#empty_end_date").is(":checked")) {
  2261. $("#end_date_span").hide();
  2262. } else {
  2263. $("#end_date_span").show();
  2264. }
  2265. });';
  2266. if (isset($item_2_edit['end_date']) && $item_2_edit['end_date'] == '0000-00-00 00:00:00') {
  2267. echo '$("#end_date_span").hide();';
  2268. } echo '
  2269. });
  2270. </script>';
  2271. // end date and time
  2272. echo '<span id="end_date_span">';
  2273. echo '<div class="control-group">
  2274. <label class="control-label">
  2275. '.get_lang('EndDate').'
  2276. </label>
  2277. <div class="controls">
  2278. <div id="err_end_date" style="display:none;color:red"></div>';
  2279. ?>
  2280. <select id="end_fday" name="end_fday">
  2281. <?php
  2282. // small loop for filling all the dates
  2283. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  2284. foreach (range(1, 31) as $i) {
  2285. // values have to have double digits
  2286. $value = ($i <= 9 ? '0'.$i : $i );
  2287. // the current day is indicated with [] around the date
  2288. if ($value == $end_day) {
  2289. echo "<option value=\"".$value."\" selected> ".$i." </option>";
  2290. } else {
  2291. echo "<option value=\"".$value."\">".$i."</option>";
  2292. }
  2293. }
  2294. ?>
  2295. </select>
  2296. <!-- month: january -> december -->
  2297. <select id="end_fmonth" name="end_fmonth">
  2298. <?php
  2299. foreach (range(1, 12) as $i) {
  2300. // values have to have double digits
  2301. $value = ($i <= 9 ? '0'.$i : $i );
  2302. if ($value == $end_month) {
  2303. echo "<option value=\"".$value."\" selected>".$MonthsLong[$i - 1]."</option>";
  2304. } else {
  2305. echo "<option value=\"".$value."\">".$MonthsLong[$i - 1]."</option>";
  2306. }
  2307. }
  2308. ?>
  2309. </select>
  2310. <select id="end_fyear" name="end_fyear">
  2311. <option value="<?php echo ($end_year - 2) ?>"><?php echo ($end_year - 2) ?></option>
  2312. <option value="<?php echo ($end_year - 1) ?>"><?php echo ($end_year - 1) ?></option>
  2313. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  2314. <?php
  2315. for ($i = 1; $i <= 5; $i++) {
  2316. $value = $end_year + $i;
  2317. echo "<option value=\"$value\">$value</option>";
  2318. }
  2319. ?>
  2320. </select>
  2321. <a href="javascript:openCalendar('new_calendar_item', 'end_f')">
  2322. <?php echo Display::span(Display::return_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')), array('id' => 'end_date_calendar_icon')); ?>
  2323. </a>
  2324. &nbsp;<?php echo get_lang('EndTime').": "; ?>&nbsp;
  2325. <select id="end_fhour" name="end_fhour">
  2326. <!-- <option value="--">--</option> -->
  2327. <?php
  2328. foreach (range(0, 23) as $i) {
  2329. // values have to have double digits
  2330. $value = ($i <= 9 ? '0'.$i : $i );
  2331. // the current hour is indicated with [] around the hour
  2332. if ($end_hours == $value) {
  2333. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2334. } else {
  2335. echo "<option value=\"".$value."\"> ".$value." </option>";
  2336. }
  2337. }
  2338. ?>
  2339. </select>
  2340. <select id="end_fminute" name="end_fminute">
  2341. <!-- <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option> -->
  2342. <!-- <option value="--">--</option> -->
  2343. <?php
  2344. foreach (range(0, 59) as $i) {
  2345. // values have to have double digits
  2346. //$value = ($i <= 9 ? '0'.$i : $i );
  2347. $value = ($i <= 9 ? '0'.$i : $i );
  2348. if ($end_minutes == $value) {
  2349. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2350. } else {
  2351. echo "<option value=\"$value\">$value</option>";
  2352. }
  2353. }
  2354. ?>
  2355. </select>
  2356. <?php
  2357. echo ' </div>
  2358. </div> </span>';
  2359. // Repeating the calendar item
  2360. if (empty($id)) {
  2361. //only show repeat fields when adding, not for editing an calendar item
  2362. echo '<div class="control-group">
  2363. <label class="control-label"></label>
  2364. <div class="controls">
  2365. <a href="javascript://" onclick="return plus_repeated_event();"><span id="plus2">
  2366. <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('RepeatEvent').'</span>
  2367. </a>';
  2368. ?>
  2369. <table id="options2" style="display: none;">
  2370. <tr>
  2371. <td>
  2372. <label for="repeat_id">
  2373. <input id="repeat_id" type="checkbox" name="repeat" <?php echo ($repeat ? 'checked="checked"' : ''); ?>/>
  2374. <?php echo get_lang('RepeatEvent'); ?>
  2375. </label></td>
  2376. <td>
  2377. </td>
  2378. </tr>
  2379. <tr>
  2380. <td><label><?php echo get_lang('RepeatType'); ?></label></td>
  2381. <td>
  2382. <select name="repeat_type">
  2383. <option value="daily"><?php echo get_lang('RepeatDaily'); ?></option>
  2384. <option value="weekly"><?php echo get_lang('RepeatWeekly'); ?></option>
  2385. <option value="monthlyByDate"><?php echo get_lang('RepeatMonthlyByDate'); ?></option>
  2386. <!--option value="monthlyByDay"><?php echo get_lang('RepeatMonthlyByDay'); ?></option>
  2387. <option value="monthlyByDayR"><?php echo get_lang('RepeatMonthlyByDayR'); ?></option-->
  2388. <option value="yearly"><?php echo get_lang('RepeatYearly'); ?></option>
  2389. </select>
  2390. </td>
  2391. </tr>
  2392. <tr>
  2393. <td><label><?php echo get_lang('RepeatEnd'); ?></label></td>
  2394. <td>
  2395. <select name="repeat_end_day">
  2396. <?php
  2397. // small loop for filling all the dates
  2398. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  2399. foreach (range(1, 31) as $i) {
  2400. // values have to have double digits
  2401. $value = ($i <= 9 ? '0'.$i : $i );
  2402. // the current day is indicated with [] around the date
  2403. if ($value == $end_day) {
  2404. echo "<option value=\"".$value."\" selected> ".$i." </option>";
  2405. } else {
  2406. echo "<option value=\"".$value."\">".$i."</option>";
  2407. }
  2408. }
  2409. ?>
  2410. </select>
  2411. <!-- month: january -> december -->
  2412. <select name="repeat_end_month">
  2413. <?php
  2414. foreach (range(1, 12) as $i) {
  2415. // values have to have double digits
  2416. $value = ($i <= 9 ? '0'.$i : $i );
  2417. if ($value == $end_month + 1) {
  2418. echo '<option value="', $value, '" selected="selected">', $MonthsLong[$i - 1], "</option>";
  2419. } else {
  2420. echo '<option value="', $value, '">', $MonthsLong[$i - 1], "</option>";
  2421. }
  2422. }
  2423. ?>
  2424. </select>
  2425. <select name="repeat_end_year">
  2426. <option value="<?php echo ($end_year - 1) ?>"><?php echo ($end_year - 1) ?></option>
  2427. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  2428. <?php
  2429. for ($i = 1; $i <= 5; $i++) {
  2430. $value = $end_year + $i;
  2431. echo "<option value=\"$value\">$value</option>";
  2432. }
  2433. ?>
  2434. </select>
  2435. <a href="javascript:openCalendar('new_calendar_item', 'repeat_end_')">
  2436. <?php Display::display_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')); ?>
  2437. </a>
  2438. </td>
  2439. </tr>
  2440. </table>
  2441. <?php
  2442. echo ' </div>
  2443. </div>';
  2444. }
  2445. if (isset($agendaItem['all_day'])) {
  2446. $checked = null;
  2447. if ($agendaItem['all_day']) {
  2448. $checked = 'checked';
  2449. }
  2450. echo ' <div class="control-group">
  2451. <label class="control-label"></label>
  2452. <div class="controls">
  2453. <input type="checkbox" '.$checked.' name="all_day"/> '.get_lang('AllDay').'
  2454. </div>
  2455. </div>';
  2456. }
  2457. //only show repeat fields if adding, not if editing
  2458. // the main area of the agenda item: the wysiwyg editor
  2459. echo ' <div class="control-group">
  2460. <label class="control-label">
  2461. <span class="form_required">*</span>'.get_lang('Description').'
  2462. </label>
  2463. <div class="controls">';
  2464. require_once api_get_path(LIBRARY_PATH)."/fckeditor/fckeditor.php";
  2465. $oFCKeditor = new FCKeditor('content');
  2466. $oFCKeditor->Width = '100%';
  2467. $oFCKeditor->Height = '200';
  2468. if (!api_is_allowed_to_edit(null, true)) {
  2469. $oFCKeditor->ToolbarSet = 'AgendaStudent';
  2470. } else {
  2471. $oFCKeditor->ToolbarSet = 'Agenda';
  2472. }
  2473. $oFCKeditor->Value = $content;
  2474. $return = $oFCKeditor->CreateHtml();
  2475. echo $return;
  2476. //echo '<textarea class="span5" rows="4" name="content">'.$content.'</textarea>';
  2477. echo '</div>
  2478. </div>';
  2479. if ($agendaObj->type == 'course') {
  2480. // File attachment
  2481. echo ' <div class="control-group">
  2482. <label class="control-label">
  2483. '.get_lang('AddAnAttachment').'&nbsp;</label>
  2484. <div class="controls">
  2485. <input type="file" name="user_upload"/> '.get_lang('Comment').' <input name="file_comment" type="text" size="20" />
  2486. </div>
  2487. </div>';
  2488. }
  2489. // the submit button for storing the calendar item
  2490. echo ' <div class="control-group">
  2491. <label class="control-label">
  2492. </label>
  2493. <div class="controls">';
  2494. if (isset($_GET['id'])) {
  2495. $class = 'save';
  2496. $text = get_lang('ModifyEvent');
  2497. } else {
  2498. $class = 'add';
  2499. $text = get_lang('AgendaAdd');
  2500. }
  2501. echo '<button class="'.$class.'" type="button" name="name" onclick="selectAll(document.getElementById(\'selected_form\'),true)">'.$text.'</button>';
  2502. echo ' </div>
  2503. </div>';
  2504. ?>
  2505. </form>
  2506. <?php
  2507. }
  2508. function get_agendaitems($month, $year)
  2509. {
  2510. $items = array();
  2511. $month = Database::escape_string($month);
  2512. $year = Database::escape_string($year);
  2513. //databases of the courses
  2514. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2515. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2516. $course_info = api_get_course_info();
  2517. $group_memberships = GroupManager :: get_group_ids($course_info['real_id'], api_get_user_id());
  2518. // if the user is administrator of that course we show all the agenda items
  2519. if (api_is_allowed_to_edit(false, true)) {
  2520. //echo "course admin";
  2521. $sqlquery = "SELECT
  2522. DISTINCT agenda.*, item_property.*
  2523. FROM ".$TABLEAGENDA." agenda,
  2524. ".$TABLE_ITEMPROPERTY." item_property
  2525. WHERE agenda.id = item_property.ref
  2526. AND MONTH(agenda.start_date)='".$month."'
  2527. AND YEAR(agenda.start_date)='".$year."'
  2528. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2529. AND item_property.visibility='1'
  2530. GROUP BY agenda.id
  2531. ORDER BY start_date ";
  2532. }
  2533. // if the user is not an administrator of that course
  2534. else {
  2535. //echo "GEEN course admin";
  2536. if (is_array($group_memberships) && count($group_memberships) > 0) {
  2537. $sqlquery = "SELECT
  2538. agenda.*, item_property.*
  2539. FROM ".$TABLEAGENDA." agenda,
  2540. ".$TABLE_ITEMPROPERTY." item_property
  2541. WHERE agenda.id = item_property.ref
  2542. AND MONTH(agenda.start_date)='".$month."'
  2543. AND YEAR(agenda.start_date)='".$year."'
  2544. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2545. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  2546. AND item_property.visibility='1'
  2547. ORDER BY start_date ";
  2548. } else {
  2549. $sqlquery = "SELECT
  2550. agenda.*, item_property.*
  2551. FROM ".$TABLEAGENDA." agenda,
  2552. ".$TABLE_ITEMPROPERTY." item_property
  2553. WHERE agenda.id = item_property.ref
  2554. AND MONTH(agenda.start_date)='".$month."'
  2555. AND YEAR(agenda.start_date)='".$year."'
  2556. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2557. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0')
  2558. AND item_property.visibility='1'
  2559. ORDER BY start_date ";
  2560. }
  2561. }
  2562. $mycourse = api_get_course_info();
  2563. $result = Database::query($sqlquery);
  2564. while ($item = Database::fetch_array($result)) {
  2565. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  2566. $agendaday = intval($agendaday_string);
  2567. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  2568. $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.$mycourse['id']."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  2569. $items[$agendaday][$item['start_time']] .= '<i>'.$time.'</i> <a href="'.$URL.'" title="'.$mycourse['name'].'">'.$mycourse['official_code'].'</a> '.$item['title'].'<br />';
  2570. }
  2571. // sorting by hour for every day
  2572. $agendaitems = array();
  2573. while (list ($agendaday, $tmpitems) = each($items)) {
  2574. sort($tmpitems);
  2575. while (list ($key, $val) = each($tmpitems)) {
  2576. $agendaitems[$agendaday] .= $val;
  2577. }
  2578. }
  2579. return $agendaitems;
  2580. }
  2581. function display_upcoming_events()
  2582. {
  2583. $number_of_items_to_show = (int) api_get_setting('number_of_upcoming_events');
  2584. //databases of the courses
  2585. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2586. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2587. $mycourse = api_get_course_info();
  2588. $myuser = api_get_user_info();
  2589. $session_id = api_get_session_id();
  2590. $course_id = $mycourse['real_id'];
  2591. $group_memberships = GroupManager :: get_group_ids($mycourse['real_id'], $myuser['user_id']);
  2592. // if the user is administrator of that course we show all the agenda items
  2593. if (api_is_allowed_to_edit(false, true)) {
  2594. //echo "course admin";
  2595. $sqlquery = "SELECT
  2596. DISTINCT agenda.*, item_property.*
  2597. FROM ".$TABLEAGENDA." agenda,
  2598. ".$TABLE_ITEMPROPERTY." item_property
  2599. WHERE
  2600. agenda.c_id = $course_id AND
  2601. item_property.c_id = $course_id AND
  2602. agenda.id = item_property.ref
  2603. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2604. AND item_property.visibility='1'
  2605. AND agenda.start_date > NOW()
  2606. AND session_id = '".$session_id."'
  2607. GROUP BY agenda.id
  2608. ORDER BY start_date ";
  2609. }
  2610. // if the user is not an administrator of that course
  2611. else {
  2612. //echo "GEEN course admin";
  2613. if (is_array($group_memberships) and count($group_memberships) > 0) {
  2614. $sqlquery = "SELECT
  2615. agenda.*, item_property.*
  2616. FROM ".$TABLEAGENDA." agenda,
  2617. ".$TABLE_ITEMPROPERTY." item_property
  2618. WHERE
  2619. agenda.c_id = $course_id AND
  2620. item_property.c_id = $course_id AND
  2621. agenda.id = item_property.ref
  2622. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2623. AND ( item_property.to_user_id='".$myuser['user_id']."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  2624. AND item_property.visibility='1'
  2625. AND agenda.start_date > NOW()
  2626. AND session_id = '".$session_id."'
  2627. ORDER BY start_date ";
  2628. } else {
  2629. $sqlquery = "SELECT
  2630. agenda.*, item_property.*
  2631. FROM ".$TABLEAGENDA." agenda,
  2632. ".$TABLE_ITEMPROPERTY." item_property
  2633. WHERE
  2634. agenda.c_id = $course_id AND
  2635. item_property.c_id = $course_id AND
  2636. agenda.id = item_property.ref
  2637. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2638. AND ( item_property.to_user_id='".$myuser['user_id']."' OR item_property.to_group_id='0')
  2639. AND item_property.visibility='1'
  2640. AND agenda.start_date > NOW()
  2641. AND session_id = '".$session_id."'
  2642. ORDER BY start_date ";
  2643. }
  2644. }
  2645. $result = Database::query($sqlquery);
  2646. $counter = 0;
  2647. if (Database::num_rows($result) > 0) {
  2648. echo '<h4>'.get_lang('UpcomingEvent').'</h4><br />';
  2649. while ($item = Database::fetch_array($result, 'ASSOC')) {
  2650. if ($counter < $number_of_items_to_show) {
  2651. echo api_get_local_time($item['start_date']), ' - ', $item['title'], '<br />';
  2652. $counter++;
  2653. }
  2654. }
  2655. }
  2656. }
  2657. /**
  2658. * This function calculates the startdate of the week (monday)
  2659. * and the enddate of the week (sunday)
  2660. * and returns it as an array
  2661. * @todo check if this function is correct
  2662. */
  2663. function calculate_start_end_of_week($week_number, $year)
  2664. {
  2665. // determine the start and end date
  2666. // step 1: we calculate a timestamp for a day in this week
  2667. //@todo Why ($week_number - 1) ?
  2668. //$random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number-1) * (7 * 24 * 60 * 60); // we calculate a random day in this week
  2669. $random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week
  2670. // step 2: we which day this is (0=sunday, 1=monday, ...)
  2671. $number_day_in_week = date('w', $random_day_in_week);
  2672. // step 3: we calculate the timestamp of the monday of the week we are in
  2673. $start_timestamp = $random_day_in_week - (($number_day_in_week - 1) * 24 * 60 * 60);
  2674. // step 4: we calculate the timestamp of the sunday of the week we are in
  2675. $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week + 1) * 24 * 60 * 60) - 3600;
  2676. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  2677. $start_day = date('j', $start_timestamp);
  2678. $start_month = date('n', $start_timestamp);
  2679. $start_year = date('Y', $start_timestamp);
  2680. $end_day = date('j', $end_timestamp);
  2681. $end_month = date('n', $end_timestamp);
  2682. $end_year = date('Y', $end_timestamp);
  2683. $start_end_array['start']['day'] = $start_day;
  2684. $start_end_array['start']['month'] = $start_month;
  2685. $start_end_array['start']['year'] = $start_year;
  2686. $start_end_array['end']['day'] = $end_day;
  2687. $start_end_array['end']['month'] = $end_month;
  2688. $start_end_array['end']['year'] = $end_year;
  2689. return $start_end_array;
  2690. }
  2691. /**
  2692. * Show the mini calendar of the given month
  2693. */
  2694. function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName)
  2695. {
  2696. global $DaysShort, $DaysLong, $course_path;
  2697. global $MonthsLong;
  2698. global $query;
  2699. // timestamp of today
  2700. $today = mktime();
  2701. $nextday = $today + (24 * 60 * 60);
  2702. $previousday = $today - (24 * 60 * 60);
  2703. // the week number of the year
  2704. $week_number = date("W", $today);
  2705. // if we moved to the next / previous day we have to recalculate the $today variable
  2706. if (isset($_GET['day'])) {
  2707. $today = mktime(0, 0, 0, $month, $day, $year);
  2708. $nextday = $today + (24 * 60 * 60);
  2709. $previousday = $today - (24 * 60 * 60);
  2710. $week_number = date("W", $today);
  2711. }
  2712. // calculating the start date of the week
  2713. // the date of the monday of this week is the timestamp of today minus
  2714. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  2715. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  2716. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  2717. // we are loading all the calendar items of all the courses for today
  2718. echo "<table class=\"data_table\">";
  2719. // the forward and backwards url
  2720. $course_code = isset($_GET['courseCode']) ? Security::remove_XSS($_GET['courseCode']) : null;
  2721. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday);
  2722. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday);
  2723. // The title row containing the day
  2724. echo "<tr>", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png', get_lang('Previous'))."</a></th>", "<th>";
  2725. echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
  2726. echo "</th>";
  2727. echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png', get_lang('Next'))."</a></th>";
  2728. echo "</tr>";
  2729. // From 0 to 5h
  2730. $class = "class=\"row_even\"";
  2731. echo "<tr $class>";
  2732. echo ("<td valign=\"top\" width=\"75\">0:00 ".get_lang("HourShort")." - 4:30 ".get_lang("HourShort")."</td>");
  2733. echo "<td $class valign=\"top\" colspan=\"2\">";
  2734. for ($i = 0; $i < 10; $i++) {
  2735. if (isset($agendaitems[$i])) {
  2736. if (is_array($agendaitems[$i])) {
  2737. foreach ($agendaitems[$i] as $key => $value) {
  2738. echo $value;
  2739. }
  2740. } else {
  2741. echo $agendaitems[$i];
  2742. }
  2743. }
  2744. }
  2745. echo "</td>";
  2746. echo "</tr>";
  2747. // the rows for each half an hour
  2748. for ($i = 10; $i < 48; $i++) {
  2749. if ($i % 2 == 0) {
  2750. $class = "class=\"row_even\"";
  2751. } else {
  2752. $class = "class=\"row_odd\"";
  2753. }
  2754. echo "<tr $class>";
  2755. echo "";
  2756. if ($i % 2 == 0) {
  2757. echo ("<td valign=\"top\" width=\"75\">".(($i) / 2)." ".get_lang("HourShort")." 00</td>");
  2758. } else {
  2759. echo ("<td valign=\"top\" width=\"75\">".((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>");
  2760. }
  2761. echo "<td $class valign=\"top\" colspan=\"2\">";
  2762. if (isset($agendaitems[$i])) {
  2763. if (is_array($agendaitems[$i])) {
  2764. foreach ($agendaitems[$i] as $key => $value) {
  2765. echo $value;
  2766. }
  2767. } else {
  2768. echo $agendaitems[$i];
  2769. }
  2770. }
  2771. echo "</td>";
  2772. echo "</tr>";
  2773. }
  2774. echo "</table>";
  2775. }
  2776. /**
  2777. * Display the weekly view of the calendar
  2778. */
  2779. function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  2780. {
  2781. global $DaysShort, $course_path;
  2782. global $MonthsLong;
  2783. // timestamp of today
  2784. $today = time();
  2785. $day_of_the_week = date("w", $today);
  2786. $thisday_of_the_week = date("w", $today);
  2787. // the week number of the year
  2788. $week_number = date("W", $today);
  2789. $thisweek_number = $week_number;
  2790. // if we moved to the next / previous week we have to recalculate the $today variable
  2791. if (!isset($_GET['week'])) {
  2792. $week_number = date("W", $today);
  2793. } else {
  2794. $week_number = intval($_GET['week']);
  2795. }
  2796. // calculating the start date of the week
  2797. // the date of the monday of this week is the timestamp of today minus
  2798. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  2799. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  2800. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  2801. //Using the same script to calculate the start/end of a week
  2802. $start_end = calculate_start_end_of_week($week_number, $year);
  2803. $timestamp_first_date_of_week = mktime(0, 0, 0, $start_end['start']['month'], $start_end['start']['day'], $start_end['start']['year']);
  2804. $timestamp_last_date_of_week = mktime(0, 0, 0, $start_end['end']['month'], $start_end['end']['day'], $start_end['end']['year']);
  2805. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=".($week_number - 1);
  2806. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=".($week_number + 1);
  2807. echo '<table class="data_table">';
  2808. // The title row containing the the week information (week of the year (startdate of week - enddate of week)
  2809. echo '<tr>';
  2810. echo "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png', get_lang('Previous'))."</a></th>";
  2811. echo "<th colspan=\"5\">".get_lang("Week")." ".$week_number;
  2812. echo " (".$DaysShort['1']." ".date("j", $timestamp_first_date_of_week)." ".$MonthsLong[date("n", $timestamp_first_date_of_week) - 1]." ".date("Y", $timestamp_first_date_of_week)." - ".$DaysShort['0']." ".date("j", $timestamp_last_date_of_week)." ".$MonthsLong[date("n", $timestamp_last_date_of_week) - 1]." ".date("Y", $timestamp_last_date_of_week).')';
  2813. echo "</th>";
  2814. echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png', get_lang('Next'))."</a></th>", "</tr>";
  2815. // The second row containing the short names of the days of the week
  2816. echo "<tr>";
  2817. //Printing the week days
  2818. // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
  2819. $tmp_timestamp = $timestamp_first_date_of_week;
  2820. for ($ii = 1; $ii < 8; $ii++) {
  2821. $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week'] == $thisweek_number));
  2822. echo "<td class=\"weekdays\">";
  2823. if ($is_today) {
  2824. echo "<font color=#CC3300>";
  2825. }
  2826. echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
  2827. if ($is_today) {
  2828. echo "</font>";
  2829. }
  2830. echo "</td>";
  2831. // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
  2832. $array_tmp_timestamp[] = $tmp_timestamp;
  2833. $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
  2834. }
  2835. echo "</tr>";
  2836. // The table cells containing all the entries for that day
  2837. echo "<tr>";
  2838. $counter = 0;
  2839. foreach ($array_tmp_timestamp as $key => $value) {
  2840. if ($counter < 5) {
  2841. $class = "class=\"days_week\"";
  2842. } else {
  2843. $class = "class=\"days_weekend\"";
  2844. }
  2845. if ($counter == $thisday_of_the_week - 1 AND (!isset($_GET['week']) OR $_GET['week'] == $thisweek_number)) {
  2846. $class = "class=\"days_today\"";
  2847. }
  2848. echo "<td ".$class.">";
  2849. $data = isset($agendaitems[date('j', $value)]) ? $agendaitems[date('j', $value)] : null;
  2850. echo "<span class=\"agendaitem\">".$data."&nbsp;</span> ";
  2851. echo "</td>";
  2852. $counter++;
  2853. }
  2854. echo "</tr>";
  2855. echo "</table>";
  2856. }
  2857. /**
  2858. * Show the monthcalender of the given month
  2859. */
  2860. function get_day_agendaitems($courses_dbs, $month, $year, $day)
  2861. {
  2862. global $setting_agenda_link;
  2863. $items = array();
  2864. // get agenda-items for every course
  2865. //$query=Database::query($sql_select_courses);
  2866. foreach ($courses_dbs as $key => $array_course_info) {
  2867. //echo $array_course_info['db'];
  2868. //databases of the courses
  2869. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2870. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2871. // getting all the groups of the user for the current course
  2872. $group_memberships = GroupManager :: get_group_ids($array_course_info['real_id'], api_get_user_id());
  2873. $course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info['code']);
  2874. $start_filter = $year."-".$month."-".$day." 00:00:00";
  2875. $start_filter = api_get_utc_datetime($start_filter);
  2876. $end_filter = $year."-".$month."-".$day." 23:59:59";
  2877. $end_filter = api_get_utc_datetime($end_filter);
  2878. // if the user is administrator of that course we show all the agenda items
  2879. if ($course_user_status == '1') {
  2880. //echo "course admin";
  2881. $sqlquery = "SELECT
  2882. DISTINCT agenda.*, item_property.*
  2883. FROM ".$TABLEAGENDA." agenda,
  2884. ".$TABLE_ITEMPROPERTY." item_property
  2885. WHERE agenda.id = item_property.ref
  2886. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  2887. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2888. AND item_property.visibility='1'
  2889. GROUP BY agenda.id
  2890. ORDER BY start_date ";
  2891. }
  2892. // if the user is not an administrator of that course
  2893. else {
  2894. //echo "course admin";
  2895. if (is_array($group_memberships) && count($group_memberships) > 0) {
  2896. $sqlquery = "SELECT
  2897. agenda.*, item_property.*
  2898. FROM ".$TABLEAGENDA." agenda,
  2899. ".$TABLE_ITEMPROPERTY." item_property
  2900. WHERE agenda.id = item_property.ref
  2901. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  2902. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2903. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  2904. AND item_property.visibility='1'
  2905. ORDER BY start_date ";
  2906. } else {
  2907. $sqlquery = "SELECT
  2908. agenda.*, item_property.*
  2909. FROM ".$TABLEAGENDA." agenda,
  2910. ".$TABLE_ITEMPROPERTY." item_property
  2911. WHERE agenda.id = item_property.ref
  2912. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  2913. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2914. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0')
  2915. AND item_property.visibility='1'
  2916. ORDER BY start_date ";
  2917. }
  2918. }
  2919. $result = Database::query($sqlquery);
  2920. while ($item = Database::fetch_array($result)) {
  2921. // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
  2922. // we want to know for each agenda item for this day to wich halfhour it must be assigned
  2923. $item['start_date'] = api_get_local_time($item['start_date']);
  2924. $time_minute = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  2925. list ($datepart, $timepart) = explode(" ", $item['start_date']);
  2926. list ($year, $month, $day) = explode("-", $datepart);
  2927. list ($hours, $minutes, $seconds) = explode(":", $timepart);
  2928. $halfhour = 2 * $hours;
  2929. if ($minutes >= '30') {
  2930. $halfhour = $halfhour + 1;
  2931. }
  2932. if ($setting_agenda_link == 'coursecode') {
  2933. $title = $array_course_info['title'];
  2934. $agenda_link = cut($title, 14, true);
  2935. } else {
  2936. $agenda_link = Display::return_icon('course_home.png', '&nbsp;', '', ICON_SIZE_SMALL);
  2937. }
  2938. $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.urlencode($array_course_info["code"])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  2939. $items[$halfhour][] .= "<i>$time_minute</i> <a href=\"$URL\" title=\"".$array_course_info['title']."\">".$agenda_link."</a> ".$item['title']."<br />";
  2940. }
  2941. }
  2942. // sorting by hour for every day
  2943. $agendaitems = array();
  2944. while (list($agendaday, $tmpitems) = each($items)) {
  2945. sort($tmpitems);
  2946. while (list($key, $val) = each($tmpitems)) {
  2947. $agendaitems[$agendaday].=$val;
  2948. }
  2949. }
  2950. return $agendaitems;
  2951. }
  2952. /**
  2953. * Return agenda items of the week
  2954. */
  2955. function get_week_agendaitems($courses_dbs, $month, $year, $week = '')
  2956. {
  2957. global $setting_agenda_link;
  2958. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2959. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2960. $items = array();
  2961. // The default value of the week
  2962. if ($week == '') {
  2963. $week_number = date("W", time());
  2964. } else {
  2965. $week_number = $week;
  2966. }
  2967. $start_end = calculate_start_end_of_week($week_number, $year);
  2968. $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']." 00:00:00";
  2969. $start_filter = api_get_utc_datetime($start_filter);
  2970. $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']." 23:59:59";
  2971. $end_filter = api_get_utc_datetime($end_filter);
  2972. // get agenda-items for every course
  2973. foreach ($courses_dbs as $key => $array_course_info) {
  2974. //databases of the courses
  2975. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2976. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2977. // getting all the groups of the user for the current course
  2978. $group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], api_get_user_id());
  2979. $user_course_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info["code"]);
  2980. // if the user is administrator of that course we show all the agenda items
  2981. if ($user_course_status == '1') {
  2982. //echo "course admin";
  2983. $sqlquery = "SELECT
  2984. DISTINCT a.*, i.*
  2985. FROM ".$TABLEAGENDA." a,
  2986. ".$TABLE_ITEMPROPERTY." i
  2987. WHERE a.id = i.ref
  2988. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  2989. AND i.tool='".TOOL_CALENDAR_EVENT."'
  2990. AND i.visibility='1'
  2991. GROUP BY a.id
  2992. ORDER BY a.start_date";
  2993. }
  2994. // if the user is not an administrator of that course
  2995. else {
  2996. //echo "GEEN course admin";
  2997. if (is_array($group_memberships) && count($group_memberships) > 0) {
  2998. $sqlquery = "SELECT
  2999. a.*, i.*
  3000. FROM ".$TABLEAGENDA." a,
  3001. ".$TABLE_ITEMPROPERTY." i
  3002. WHERE a.id = i.ref
  3003. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  3004. AND i.tool='".TOOL_CALENDAR_EVENT."'
  3005. AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  3006. AND i.visibility='1'
  3007. ORDER BY a.start_date";
  3008. } else {
  3009. $sqlquery = "SELECT
  3010. a.*, i.*
  3011. FROM ".$TABLEAGENDA." a,
  3012. ".$TABLE_ITEMPROPERTY." i
  3013. WHERE a.id = i.ref
  3014. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  3015. AND i.tool='".TOOL_CALENDAR_EVENT."'
  3016. AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id='0')
  3017. AND i.visibility='1'
  3018. ORDER BY a.start_date";
  3019. }
  3020. }
  3021. //echo "<pre>".$sqlquery."</pre>";
  3022. // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
  3023. // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
  3024. // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
  3025. //var_dump($sqlquery);
  3026. $result = Database::query($sqlquery);
  3027. while ($item = Database::fetch_array($result)) {
  3028. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  3029. $agendaday = intval($agendaday_string);
  3030. $start_time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  3031. $end_time = api_convert_and_format_date($item['end_date'], DATE_TIME_FORMAT_LONG);
  3032. if ($setting_agenda_link == 'coursecode') {
  3033. $title = $array_course_info['title'];
  3034. $agenda_link = cut($title, 14, true);
  3035. } else {
  3036. $agenda_link = Display::return_icon('course_home.png', '&nbsp;', '', ICON_SIZE_SMALL);
  3037. }
  3038. $URL = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  3039. //Display the events in agenda
  3040. $content = "<i>$start_time - $end_time</i> <a href=\"$URL\" title=\"".$array_course_info["title"]."\"> <br />".$agenda_link."</a>";
  3041. $content .= "<div>".$item['title']."</div><br>";
  3042. $items[$agendaday][$item['start_date']] .= $content;
  3043. }
  3044. }
  3045. $agendaitems = array();
  3046. // sorting by hour for every day
  3047. while (list ($agendaday, $tmpitems) = each($items)) {
  3048. sort($tmpitems);
  3049. while (list ($key, $val) = each($tmpitems)) {
  3050. $agendaitems[$agendaday] .= $val;
  3051. }
  3052. }
  3053. return $agendaitems;
  3054. }
  3055. /**
  3056. * Get repeated events of a course between two dates (timespan of a day).
  3057. * Returns an array containing the events
  3058. * @param string Course info array (as returned by api_get_course_info())
  3059. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3060. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3061. * @param array A set of parameters to alter the SQL query
  3062. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3063. */
  3064. function get_repeated_events_day_view($course_info, $start = 0, $end = 0, $params)
  3065. {
  3066. $events = array();
  3067. //initialise all values
  3068. $y = 0;
  3069. $m = 0;
  3070. $d = 0;
  3071. //block $end if higher than 2038 -- PHP doesn't go past that
  3072. if ($end > 2145934800) {
  3073. $end = 2145934800;
  3074. }
  3075. if ($start == 0 or $end == 0) {
  3076. $y = date('Y');
  3077. $m = date('m');
  3078. $d = date('j');
  3079. }
  3080. if ($start == 0) {
  3081. $start = mktime(0, 0, 0, $m, $d, $y);
  3082. }
  3083. $db_start = date('Y-m-d H:i:s', $start);
  3084. if ($end == 0) {
  3085. $end = mktime(23, 59, 59, $m, $d, $y);
  3086. }
  3087. //$db_end = date('Y-m-d H:i:s',$end);
  3088. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3089. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3090. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3091. $sql = "SELECT c.id, c.title, c.content, ".
  3092. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3093. " cr.cal_type, cr.cal_end ".
  3094. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3095. " WHERE cr.cal_end >= $start ".
  3096. " AND cr.cal_id = c.id ".
  3097. " AND item_property.ref = c.id ".
  3098. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3099. " AND c.start_date <= '$db_start' "
  3100. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3101. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3102. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3103. $res = Database::query($sql);
  3104. if (Database::num_rows($res) > 0) {
  3105. while ($row = Database::fetch_array($res)) {
  3106. $orig_start = $row['orig_start'];
  3107. $orig_end = $row['orig_end'];
  3108. $repeat_type = $row['cal_type'];
  3109. switch ($repeat_type) {
  3110. case 'daily':
  3111. //we are in the daily view, so if this element is repeated daily and
  3112. //the repetition is still active today (which is a condition of the SQL query)
  3113. //then the event happens today. Just build today's timestamp for start and end
  3114. $time_orig_h = date('H', $orig_start);
  3115. $time_orig_m = date('i', $orig_start);
  3116. $time_orig_s = date('s', $orig_start);
  3117. $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00
  3118. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3119. $current_start = $start + $int_time; //unixtimestamp start of today's event
  3120. $current_stop = $start + $int_time + $span; //unixtimestamp stop of today's event
  3121. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3122. break;
  3123. case 'weekly':
  3124. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3125. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3126. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3127. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3128. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) && ($dw_orig == $dw_now)) { //if the event is after the original (at least one week) and the day of the week is the same
  3129. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3130. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3131. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3132. }
  3133. break;
  3134. case 'monthlyByDate':
  3135. $time_orig = date('Y/n/j/G/i/s', $orig_start);
  3136. list($y_orig, $m_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3137. $time_now = date('Y/n/j/G/i/s', $end);
  3138. list($y_now, $m_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3139. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($d_orig == $d_now)) {
  3140. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3141. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3142. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3143. }
  3144. break;
  3145. case 'monthlyByDayR':
  3146. //not implemented yet
  3147. break;
  3148. case 'monthlyByDay':
  3149. //not implemented yet
  3150. break;
  3151. case 'yearly':
  3152. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3153. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3154. $time_now = date('Y/n/j/z/G/i/s', $end);
  3155. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3156. if (($y_now > $y_orig) && ($dy_orig == $dy_now)) {
  3157. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3158. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3159. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3160. }
  3161. break;
  3162. default:
  3163. break;
  3164. }
  3165. }
  3166. }
  3167. return $events;
  3168. }
  3169. /**
  3170. * (This function is not been use in the code)
  3171. * Get repeated events of a course between two dates (timespan of a week).
  3172. * Returns an array containing the events
  3173. * @param string Course info array (as returned by api_get_course_info())
  3174. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3175. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3176. * @param array A set of parameters to alter the SQL query
  3177. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3178. */
  3179. function get_repeated_events_week_view($course_info, $start = 0, $end = 0, $params)
  3180. {
  3181. $events = array();
  3182. //block $end if higher than 2038 -- PHP doesn't go past that
  3183. if ($end > 2145934800) {
  3184. $end = 2145934800;
  3185. }
  3186. //initialise all values
  3187. $y = 0;
  3188. $m = 0;
  3189. $d = 0;
  3190. if ($start == 0 or $end == 0) {
  3191. $time = time();
  3192. $dw = date('w', $time);
  3193. $week_start = $time - (($dw - 1) * 86400);
  3194. $y = date('Y', $week_start);
  3195. $m = date('m', $week_start);
  3196. $d = date('j', $week_start);
  3197. $w = date('W', $week_start);
  3198. }
  3199. if ($start == 0) {
  3200. $start = mktime(0, 0, 0, $m, $d, $y);
  3201. }
  3202. $db_start = date('Y-m-d H:i:s', $start);
  3203. if ($end == 0) {
  3204. $end = $start + (86400 * 7) - 1; //start of week, more 7 days, minus 1 second to get back to the previoyus day
  3205. }
  3206. //$db_end = date('Y-m-d H:i:s',$end);
  3207. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3208. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3209. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3210. $sql = "SELECT c.id, c.title, c.content, ".
  3211. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3212. " cr.cal_type, cr.cal_end ".
  3213. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3214. " WHERE cr.cal_end >= $start ".
  3215. " AND cr.cal_id = c.id ".
  3216. " AND item_property.ref = c.id ".
  3217. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3218. " AND c.start_date <= '$db_start' "
  3219. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3220. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3221. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3222. $res = Database::query($sql);
  3223. if (Database::num_rows($res) > 0) {
  3224. while ($row = Database::fetch_array($res)) {
  3225. $orig_start = $row['orig_start'];
  3226. $orig_end = $row['orig_end'];
  3227. $repeat_type = $row['cal_type'];
  3228. switch ($repeat_type) {
  3229. case 'daily':
  3230. $time_orig_h = date('H', $orig_start);
  3231. $time_orig_m = date('i', $orig_start);
  3232. $time_orig_s = date('s', $orig_start);
  3233. $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00
  3234. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3235. for ($i = 0; $i < 7; $i++) {
  3236. $current_start = $start + ($i * 86400) + $int_time; //unixtimestamp start of today's event
  3237. $current_stop = $start + ($i * 86400) + $int_time + $span; //unixtimestamp stop of today's event
  3238. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3239. }
  3240. break;
  3241. case 'weekly':
  3242. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3243. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3244. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3245. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3246. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig)))) { //if the event is after the original (at least one week) and the day of the week is the same
  3247. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3248. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3249. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3250. }
  3251. break;
  3252. case 'monthlyByDate':
  3253. $time_orig = date('Y/n/W/j/G/i/s', $orig_start);
  3254. list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3255. $time_now = date('Y/n/W/j/G/i/s', $end);
  3256. list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3257. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3258. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($start < $event_repetition_time && $event_repetition_time < $end)) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week
  3259. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3260. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3261. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3262. }
  3263. break;
  3264. case 'monthlyByDayR':
  3265. //not implemented yet
  3266. break;
  3267. case 'monthlyByDay':
  3268. //not implemented yet
  3269. break;
  3270. case 'yearly':
  3271. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3272. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3273. $time_now = date('Y/n/j/z/G/i/s', $end);
  3274. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3275. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3276. if ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end))) {
  3277. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3278. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3279. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3280. }
  3281. break;
  3282. default:
  3283. break;
  3284. }
  3285. }
  3286. }
  3287. return $events;
  3288. }
  3289. /**
  3290. * Get repeated events of a course between two dates (timespan of a month).
  3291. * Returns an array containing the events
  3292. * @param string Course info array (as returned by api_get_course_info())
  3293. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3294. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3295. * @param array A set of parameters to alter the SQL query
  3296. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3297. */
  3298. function get_repeated_events_month_view($course_info, $start = 0, $end = 0, $params)
  3299. {
  3300. $events = array();
  3301. //block $end if higher than 2038 -- PHP doesn't go past that
  3302. if ($end > 2145934800) {
  3303. $end = 2145934800;
  3304. }
  3305. //initialise all values
  3306. $y = 0;
  3307. $m = 0;
  3308. $d = 0;
  3309. if ($start == 0 or $end == 0) {
  3310. $time = time();
  3311. $y = date('Y');
  3312. $m = date('m');
  3313. }
  3314. if ($start == 0) {
  3315. $start = mktime(0, 0, 0, $m, 1, $y);
  3316. }
  3317. $db_start = date('Y-m-d H:i:s', $start);
  3318. if ($end == 0) {
  3319. if ($m == 12) {
  3320. $end = mktime(0, 0, 0, 1, 1, $y + 1) - 1; //start of next month, minus 1 second to get back to the previoyus day
  3321. } else {
  3322. $end = mktime(0, 0, 0, $m + 1, 1, $y) - 1;
  3323. }
  3324. }
  3325. //$db_end = date('Y-m-d H:i:s',$end);
  3326. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3327. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3328. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3329. $sql = "SELECT c.id, c.title, c.content, ".
  3330. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3331. " cr.cal_type, cr.cal_end ".
  3332. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3333. " WHERE cr.cal_end >= $start ".
  3334. " AND cr.cal_id = c.id ".
  3335. " AND item_property.ref = c.id ".
  3336. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3337. " AND c.start_date <= '$db_start' "
  3338. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3339. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3340. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3341. $res = Database::query($sql);
  3342. if (Database::num_rows($res) > 0) {
  3343. while ($row = Database::fetch_array($res)) {
  3344. $orig_start = $row['orig_start'];
  3345. $orig_end = $row['orig_end'];
  3346. $repeat_type = $row['cal_type'];
  3347. switch ($repeat_type) {
  3348. case 'daily':
  3349. $time_orig_h = date('H', $orig_start);
  3350. $time_orig_m = date('i', $orig_start);
  3351. $time_orig_s = date('s', $orig_start);
  3352. $month_last_day = date('d', $end);
  3353. $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00
  3354. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3355. for ($i = 0; $i < $month_last_day; $i++) {
  3356. $current_start = $start + ($i * 86400) + $int_time; //unixtimestamp start of today's event
  3357. $current_stop = $start + ($i * 86400) + $int_time + $span; //unixtimestamp stop of today's event
  3358. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3359. }
  3360. break;
  3361. case 'weekly':
  3362. //A weekly repeated event is very difficult to catch in a month view,
  3363. //because weeks start before or at the same time as the first day of the month
  3364. //The same can be said for the end of the month.
  3365. // The idea is thus to get all possible events by enlarging the scope of
  3366. // the month to get complete weeks covering the complete month, and then take out
  3367. // the events that start before the 1st ($start) or after the last day of the month ($end)
  3368. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3369. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3370. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3371. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3372. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3373. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3374. $month_first_week = date('W', $start);
  3375. $month_last_week = date('W', $end);
  3376. if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) { //if the event is after the original (at least one week) and the day of the week is the same
  3377. for ($i = $month_first_week; $i <= $month_last_week; $i++) {
  3378. //the "day of the week" of repetition is the same as the $dw_orig,
  3379. //so to get the "day of the month" from the "day of the week", we have
  3380. //to get the first "day of the week" for this week and add the number
  3381. //of days (in seconds) to reach the $dw_orig
  3382. //example: the first week spans between the 28th of April (Monday) to the
  3383. // 4th of May (Sunday). The event occurs on the 2nd day of each week.
  3384. // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  3385. // We want to get all of these, and then reject 29/4 because it is out
  3386. // of the month itself.
  3387. //First, to get the start time of the first day of the month view (even if
  3388. // the day is from the past month), we get the month start date (1/5) and
  3389. // see which day of the week it is, and subtract the number of days necessary
  3390. // to get back to the first day of the week.
  3391. $month_first_day_weekday = date('N', $start);
  3392. $first_week_start = $start - (($month_first_day_weekday - 1) * 86400);
  3393. //Second, we add the week day of the original event, so that we have an
  3394. // absolute time that represents the first repetition of the event in
  3395. // our 4- or 5-weeks timespan
  3396. $first_event_repeat_start = $first_week_start + (($dw_orig - 1) * 86400) + ($h_orig * 3600) + ($n_orig * 60) + $s_orig;
  3397. //Third, we start looping through the repetitions and see if they are between
  3398. // $start and $end
  3399. for ($i = $first_event_repeat_start; $i <= $end; $i+=604800) {
  3400. if ($start < $i && $i < $end) {
  3401. list($y_repeat, $m_repeat, $d_repeat, $h_repeat, $n_repeat, $s_repeat) = split('/', date('Y/m/j/H/i/s', $i));
  3402. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3403. }
  3404. }
  3405. }
  3406. }
  3407. break;
  3408. case 'monthlyByDate':
  3409. $time_orig = date('Y/n/W/j/G/i/s', $orig_start);
  3410. list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3411. $time_now = date('Y/n/W/j/G/i/s', $end);
  3412. list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3413. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3414. if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week
  3415. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3416. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3417. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3418. }
  3419. break;
  3420. case 'monthlyByDayR':
  3421. //not implemented yet
  3422. break;
  3423. case 'monthlyByDay':
  3424. //not implemented yet
  3425. break;
  3426. case 'yearly':
  3427. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3428. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3429. $time_now = date('Y/n/j/z/G/i/s', $end);
  3430. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3431. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3432. if ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end))) {
  3433. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3434. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3435. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3436. }
  3437. break;
  3438. default:
  3439. break;
  3440. }
  3441. }
  3442. }
  3443. return $events;
  3444. }
  3445. /**
  3446. * Get repeated events of a course between two dates (1 year timespan). Used for the list display.
  3447. * This is virtually unlimited but by default it shortens to 100 years from now (even a birthday shouldn't be useful more than this time - except for turtles)
  3448. * Returns an array containing the events
  3449. * @param string Course info array (as returned by api_get_course_info())
  3450. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3451. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3452. * @param array A set of parameters to alter the SQL query
  3453. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3454. */
  3455. function get_repeated_events_list_view($course_info, $start = 0, $end = 0, $params)
  3456. {
  3457. $events = array();
  3458. //block $end if higher than 2038 -- PHP doesn't go past that
  3459. if ($end > 2145934800) {
  3460. $end = 2145934800;
  3461. }
  3462. //initialise all values
  3463. $y = 0;
  3464. $m = 0;
  3465. $d = 0;
  3466. if (empty($start) or empty($end)) {
  3467. $time = time();
  3468. $y = date('Y');
  3469. $m = date('m');
  3470. }
  3471. if (empty($start)) {
  3472. $start = mktime(0, 0, 0, $m, 1, $y);
  3473. }
  3474. $db_start = date('Y-m-d H:i:s', $start);
  3475. if (empty($end)) {
  3476. $end = mktime(0, 0, 0, 1, 1, 2037);
  3477. }
  3478. //$db_end = date('Y-m-d H:i:s',$end);
  3479. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3480. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3481. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3482. $sql = "SELECT c.id, c.title, c.content, ".
  3483. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3484. " cr.cal_type, cr.cal_end ".
  3485. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3486. " WHERE cr.cal_end >= $start ".
  3487. " AND cr.cal_id = c.id ".
  3488. " AND item_property.ref = c.id ".
  3489. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3490. " AND c.start_date <= '$db_start' "
  3491. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3492. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3493. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3494. $res = Database::query($sql);
  3495. if (Database::num_rows($res) > 0) {
  3496. while ($row = Database::fetch_array($res)) {
  3497. $orig_start = $row['orig_start'];
  3498. $orig_end = $row['orig_end'];
  3499. $repeat_type = $row['cal_type'];
  3500. $repeat_end = $row['cal_end'];
  3501. switch ($repeat_type) {
  3502. case 'daily':
  3503. $time_orig_h = date('H', $orig_start);
  3504. $time_orig_m = date('i', $orig_start);
  3505. $time_orig_s = date('s', $orig_start);
  3506. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3507. for ($i = $orig_start + 86400; ($i < $end && $i <= $repeat_end); $i+=86400) {
  3508. $current_start = $i; //unixtimestamp start of today's event
  3509. $current_stop = $i + $span; //unixtimestamp stop of today's event
  3510. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3511. }
  3512. break;
  3513. case 'weekly':
  3514. //A weekly repeated event is very difficult to catch in a month view,
  3515. // because weeks start before or at the same time as the first day of the month
  3516. //The same can be said for the end of the month.
  3517. // The idea is thus to get all possible events by enlarging the scope of
  3518. // the month to get complete weeks covering the complete month, and then take out
  3519. // the events that start before the 1st ($start) or after the last day of the month ($end)
  3520. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3521. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3522. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3523. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3524. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3525. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3526. if ($w_now == 52) {
  3527. ++$y_now;
  3528. $w_now = 1;
  3529. } else {
  3530. ++$w_now;
  3531. }
  3532. $month_first_week = date('W', $start);
  3533. $total_weeks = ((date('Y', $end) - $y_orig) - 1) * 52;
  3534. $month_last_week = $month_first_week + $total_weeks;
  3535. if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) { //if the event is after the original (at least one week) and the day of the week is the same
  3536. //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++)
  3537. //{
  3538. /*
  3539. The "day of the week" of repetition is the same as the $dw_orig,
  3540. so to get the "day of the month" from the "day of the week", we have
  3541. to get the first "day of the week" for this week and add the number
  3542. of days (in seconds) to reach the $dw_orig
  3543. example: the first week spans between the 28th of April (Monday) to the
  3544. 4th of May (Sunday). The event occurs on the 2nd day of each week.
  3545. This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  3546. We want to get all of these, and then reject 29/4 because it is out
  3547. of the month itself.
  3548. First, to get the start time of the first day of the month view (even if
  3549. the day is from the past month), we get the month start date (1/5) and
  3550. see which day of the week it is, and subtract the number of days necessary
  3551. to get back to the first day of the week.
  3552. */
  3553. $month_first_day_weekday = date('N', $start);
  3554. $first_week_start = $start - (($month_first_day_weekday - 1) * 86400);
  3555. //Second, we add the week day of the original event, so that we have an
  3556. // absolute time that represents the first repetition of the event in
  3557. // our 4- or 5-weeks timespan
  3558. $first_event_repeat_start = $first_week_start + (($dw_orig - 1) * 86400) + ($h_orig * 3600) + ($n_orig * 60) + $s_orig;
  3559. //Third, we start looping through the repetitions and see if they are between
  3560. // $start and $end
  3561. for ($i = $first_event_repeat_start; ($i <= $end && $i <= $repeat_end); $i+=604800) {
  3562. if ($start < $i && $i <= $end && $i <= $repeat_end) {
  3563. list($y_repeat, $m_repeat, $d_repeat, $h_repeat, $n_repeat, $s_repeat) = split('/', date('Y/m/j/H/i/s', $i));
  3564. $new_start_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3565. $new_stop_time = mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now);
  3566. $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
  3567. }
  3568. $time_now = date('Y/n/W/j/N/G/i/s', $i + 604800);
  3569. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3570. }
  3571. //}
  3572. }
  3573. break;
  3574. case 'monthlyByDate':
  3575. $time_orig = date('Y/n/W/j/G/i/s', $orig_start);
  3576. list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3577. $time_now = date('Y/n/W/j/G/i/s', $start);
  3578. list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3579. //make sure we are one month ahead (to avoid being the same month as the original event)
  3580. if ($m_now == 12) {
  3581. ++$y_now;
  3582. $m_now = 1;
  3583. } else {
  3584. ++$m_now;
  3585. }
  3586. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3587. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3588. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3589. $diff = $orig_end - $orig_start;
  3590. while ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end)) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week
  3591. $new_start_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3592. $new_stop_time = mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now);
  3593. $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
  3594. if ($m_now == 12) {
  3595. ++$y_now;
  3596. $m_now = 1;
  3597. } else {
  3598. ++$m_now;
  3599. }
  3600. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3601. }
  3602. break;
  3603. case 'monthlyByDayR':
  3604. //not implemented yet
  3605. break;
  3606. case 'monthlyByDay':
  3607. //not implemented yet
  3608. break;
  3609. case 'yearly':
  3610. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3611. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3612. $time_now = date('Y/n/j/z/G/i/s', $end);
  3613. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3614. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3615. while ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end && $event_repetition_time < $repeat_end))) {
  3616. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3617. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3618. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3619. ++$y_now;
  3620. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3621. }
  3622. break;
  3623. default:
  3624. break;
  3625. }
  3626. }
  3627. }
  3628. return $events;
  3629. }
  3630. /**
  3631. * Tells if an agenda item is repeated
  3632. * @param string Course database
  3633. * @param int The agenda item
  3634. * @return boolean True if repeated, false otherwise
  3635. */
  3636. function is_repeated_event($id, $course = null)
  3637. {
  3638. if (empty($course)) {
  3639. $course_info = api_get_course_info();
  3640. $course = $course_info['dbName'];
  3641. }
  3642. $id = (int) $id;
  3643. $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course);
  3644. $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
  3645. $res = Database::query($sql);
  3646. if (Database::num_rows($res) > 0) {
  3647. return true;
  3648. }
  3649. return false;
  3650. }
  3651. /**
  3652. * Adds x weeks to a UNIX timestamp
  3653. * @param int The timestamp
  3654. * @param int The number of weeks to add
  3655. * @return int The new timestamp
  3656. */
  3657. function add_week($timestamp, $num = 1)
  3658. {
  3659. return $timestamp + $num * 604800;
  3660. }
  3661. /**
  3662. * Adds x months to a UNIX timestamp
  3663. * @param int The timestamp
  3664. * @param int The number of years to add
  3665. * @return int The new timestamp
  3666. */
  3667. function add_month($timestamp, $num = 1)
  3668. {
  3669. list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp));
  3670. if ($m + $num > 12) {
  3671. $y += floor($num / 12);
  3672. $m += $num % 12;
  3673. } else {
  3674. $m += $num;
  3675. }
  3676. return mktime($h, $n, $s, $m, $d, $y);
  3677. }
  3678. /**
  3679. * Adds x years to a UNIX timestamp
  3680. * @param int The timestamp
  3681. * @param int The number of years to add
  3682. * @return int The new timestamp
  3683. */
  3684. function add_year($timestamp, $num = 1)
  3685. {
  3686. list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp));
  3687. return mktime($h, $n, $s, $m, $d, $y + $num);
  3688. }
  3689. /**
  3690. * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
  3691. * @param array Course info
  3692. * @param string Event title
  3693. * @param string Event content/description
  3694. * @param string Start date
  3695. * @param string End date
  3696. * @param array List of groups to which this event is added
  3697. * @param int Parent id (optional)
  3698. * @return int The new item's DB ID
  3699. */
  3700. function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to = array(), $parent_id = null, $file_comment = '')
  3701. {
  3702. $user_id = api_get_user_id();
  3703. // database table definitions
  3704. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  3705. $item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  3706. // some filtering of the input data
  3707. $title = Database::escape_string($title);
  3708. $content = Database::escape_string($content);
  3709. $db_start_date = api_get_utc_datetime($db_start_date);
  3710. $start_date = Database::escape_string($db_start_date);
  3711. if (!empty($db_end_date)) {
  3712. $db_end_date = api_get_utc_datetime($db_end_date);
  3713. }
  3714. $end_date = Database::escape_string($db_end_date);
  3715. $id_session = api_get_session_id();
  3716. $course_id = api_get_course_int_id();
  3717. $group_id = api_get_group_id();
  3718. // check if exists in calendar_event table and if it is not deleted!
  3719. $sql = "SELECT * FROM $t_agenda agenda, $item_property item_property
  3720. WHERE
  3721. agenda.c_id = $course_id AND
  3722. item_property.c_id = $course_id AND
  3723. agenda.title = '$title'
  3724. AND agenda.content = '$content'
  3725. AND agenda.start_date = '$start_date'
  3726. AND agenda.end_date = '$end_date' ".(!empty($parent_id) ? "
  3727. AND agenda.parent_event_id = '$parent_id'" : "")."
  3728. AND agenda.session_id = '$id_session'
  3729. AND item_property.tool = '".TOOL_CALENDAR_EVENT."'
  3730. AND item_property.ref = agenda.id
  3731. AND item_property.visibility <> 2";
  3732. $result = Database::query($sql);
  3733. $count = Database::num_rows($result);
  3734. if ($count > 0) {
  3735. return false;
  3736. }
  3737. $course_id = api_get_course_int_id();
  3738. $sql = "INSERT INTO ".$t_agenda." (c_id, title,content, start_date, end_date".(!empty($parent_id) ? ',parent_event_id' : '').", session_id)
  3739. VALUES($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."'".(!empty($parent_id) ? ','.((int) $parent_id) : '').", '".$id_session."')";
  3740. $result = Database::query($sql);
  3741. $last_id = Database::insert_id();
  3742. // add a attachment file in agenda
  3743. add_agenda_attachment_file($file_comment, $last_id);
  3744. // store in last_tooledit (first the groups, then the users
  3745. if (!empty($to)) {
  3746. $send_to = separate_users_groups($to);
  3747. // storing the selected groups
  3748. if (is_array($send_to['groups'])) {
  3749. foreach ($send_to['groups'] as $group) {
  3750. api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group, 0, $start_date, $end_date);
  3751. $done = true;
  3752. }
  3753. }
  3754. // storing the selected users
  3755. if (is_array($send_to['users'])) {
  3756. foreach ($send_to['users'] as $user) {
  3757. api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, $user, $start_date, $end_date);
  3758. $done = true;
  3759. }
  3760. }
  3761. if (isset($send_to['everyone']) && $send_to['everyone']) {
  3762. api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, 0, $start_date, $end_date);
  3763. }
  3764. }
  3765. // storing the resources
  3766. if (!empty($_SESSION['source_type']) && !empty($last_id)) {
  3767. store_resources($_SESSION['source_type'], $last_id);
  3768. }
  3769. return $last_id;
  3770. }
  3771. /**
  3772. * This function delete a attachment file by id
  3773. * @param integer attachment file Id
  3774. *
  3775. */
  3776. function delete_attachment_file($id_attach)
  3777. {
  3778. global $_course;
  3779. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  3780. $id_attach = intval($id_attach);
  3781. $sql = "DELETE FROM $agenda_table_attachment WHERE id = ".$id_attach;
  3782. $result = Database::query($sql);
  3783. $last_id_file = Database::insert_id();
  3784. // update item_property
  3785. api_item_property_update($_course, 'calendar_event_attachment', $id_attach, 'AgendaAttachmentDeleted', api_get_user_id());
  3786. if (!empty($result)) {
  3787. Display::display_confirmation_message(get_lang("AttachmentFileDeleteSuccess"));
  3788. }
  3789. }
  3790. /**
  3791. * This function add a attachment file into agenda
  3792. * @param string a comment about file
  3793. * @param int last id from calendar table
  3794. *
  3795. */
  3796. function add_agenda_attachment_file($file_comment, $last_id)
  3797. {
  3798. global $_course;
  3799. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  3800. $last_id = intval($last_id);
  3801. // Storing the attachments
  3802. if (!empty($_FILES['user_upload']['name'])) {
  3803. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  3804. }
  3805. if (!empty($upload_ok)) {
  3806. $courseDir = $_course['path'].'/upload/calendar';
  3807. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  3808. $updir = $sys_course_path.$courseDir;
  3809. // Try to add an extension to the file if it hasn't one
  3810. $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
  3811. // user's file name
  3812. $file_name = $_FILES['user_upload']['name'];
  3813. if (!filter_extension($new_file_name)) {
  3814. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  3815. } else {
  3816. $new_file_name = uniqid('');
  3817. $new_path = $updir.'/'.$new_file_name;
  3818. $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
  3819. $safe_file_comment = Database::escape_string($file_comment);
  3820. $safe_file_name = Database::escape_string($file_name);
  3821. $safe_new_file_name = Database::escape_string($new_file_name);
  3822. $course_id = api_get_course_int_id();
  3823. // Storing the attachments if any
  3824. if ($result) {
  3825. $sql = 'INSERT INTO '.$agenda_table_attachment.'(c_id, filename,comment, path,agenda_id,size) '.
  3826. "VALUES ($course_id, '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".intval($_FILES['user_upload']['size'])."' )";
  3827. Database::query($sql);
  3828. //$message.=' / '.get_lang('FileUploadSucces').'<br />';
  3829. $last_id_file = Database::insert_id();
  3830. api_item_property_update($_course, 'calendar_event_attachment', $last_id_file, 'AgendaAttachmentAdded', api_get_user_id());
  3831. }
  3832. }
  3833. }
  3834. }
  3835. /**
  3836. * This function edit a attachment file into agenda
  3837. * @param string a comment about file
  3838. * @param int Agenda Id
  3839. * @param int attachment file Id
  3840. */
  3841. function edit_agenda_attachment_file($file_comment, $agenda_id, $id_attach)
  3842. {
  3843. global $_course;
  3844. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  3845. // Storing the attachments
  3846. if (!empty($_FILES['user_upload']['name'])) {
  3847. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  3848. }
  3849. if (!empty($upload_ok)) {
  3850. $courseDir = $_course['path'].'/upload/calendar';
  3851. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  3852. $updir = $sys_course_path.$courseDir;
  3853. // Try to add an extension to the file if it hasn't one
  3854. $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
  3855. // user's file name
  3856. $file_name = $_FILES['user_upload']['name'];
  3857. if (!filter_extension($new_file_name)) {
  3858. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  3859. } else {
  3860. $new_file_name = uniqid('');
  3861. $new_path = $updir.'/'.$new_file_name;
  3862. $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
  3863. $safe_file_comment = Database::escape_string($file_comment);
  3864. $safe_file_name = Database::escape_string($file_name);
  3865. $safe_new_file_name = Database::escape_string($new_file_name);
  3866. $safe_agenda_id = (int) $agenda_id;
  3867. $safe_id_attach = (int) $id_attach;
  3868. // Storing the attachments if any
  3869. if ($result) {
  3870. $sql = "UPDATE $agenda_table_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', agenda_id = '$safe_agenda_id', size ='".intval($_FILES['user_upload']['size'])."'
  3871. WHERE id = '$safe_id_attach'";
  3872. Database::query($sql);
  3873. api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach, 'AgendaAttachmentUpdated', api_get_user_id());
  3874. }
  3875. }
  3876. }
  3877. }
  3878. /**
  3879. * Adds a repetitive item to the database
  3880. * @param array Course info
  3881. * @param int The original event's id
  3882. * @param string Type of repetition
  3883. * @param int Timestamp of end of repetition (repeating until that date)
  3884. * @param array Original event's destination (users list)
  3885. * @param string a comment about a attachment file into agenda
  3886. * @return boolean False if error, True otherwise
  3887. */
  3888. function agenda_add_repeat_item($course_info, $orig_id, $type, $end, $orig_dest, $file_comment = '')
  3889. {
  3890. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  3891. $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
  3892. $course_id = $course_info['real_id'];
  3893. $sql = 'SELECT title, content, start_date as sd, end_date as ed FROM '.$t_agenda.' WHERE c_id = '.$course_id.' AND id ="'.intval($orig_id).'" ';
  3894. $res = Database::query($sql);
  3895. if (Database::num_rows($res) !== 1) {
  3896. return false;
  3897. }
  3898. $row = Database::fetch_array($res);
  3899. $orig_start = api_strtotime(api_get_local_time($row['sd']));
  3900. $orig_end = api_strtotime(api_get_local_time($row['ed']));
  3901. $diff = $orig_end - $orig_start;
  3902. $orig_title = $row['title'];
  3903. $orig_content = $row['content'];
  3904. $now = time();
  3905. $type = Database::escape_string($type);
  3906. $end = intval($end);
  3907. if (1 <= $end && $end <= 500) {
  3908. //we assume that, with this type of value, the user actually gives a count of repetitions
  3909. //and that he wants us to calculate the end date with that (particularly in case of imports from ical)
  3910. switch ($type) {
  3911. case 'daily':
  3912. $end = $orig_start + (86400 * $end);
  3913. break;
  3914. case 'weekly':
  3915. $end = add_week($orig_start, $end);
  3916. break;
  3917. case 'monthlyByDate':
  3918. $end = add_month($orig_start, $end);
  3919. break;
  3920. case 'monthlyByDay':
  3921. //TODO
  3922. break;
  3923. case 'monthlyByDayR':
  3924. //TODO
  3925. break;
  3926. case 'yearly':
  3927. $end = add_year($orig_start, $end);
  3928. break;
  3929. }
  3930. }
  3931. if ($end > $now
  3932. && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) {
  3933. $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end) VALUES ($course_id, '$orig_id','$type',$end)";
  3934. $res = Database::query($sql);
  3935. switch ($type) {
  3936. case 'daily':
  3937. for ($i = $orig_start + 86400; ($i <= $end); $i += 86400) {
  3938. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment);
  3939. }
  3940. break;
  3941. case 'weekly':
  3942. for ($i = $orig_start + 604800; ($i <= $end); $i += 604800) {
  3943. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment);
  3944. }
  3945. break;
  3946. case 'monthlyByDate':
  3947. $next_start = add_month($orig_start);
  3948. while ($next_start <= $end) {
  3949. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment);
  3950. $next_start = add_month($next_start);
  3951. }
  3952. break;
  3953. case 'monthlyByDay':
  3954. //not yet implemented
  3955. break;
  3956. case 'monthlyByDayR':
  3957. //not yet implemented
  3958. break;
  3959. case 'yearly':
  3960. $next_start = add_year($orig_start);
  3961. while ($next_start <= $end) {
  3962. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment);
  3963. $next_start = add_year($next_start);
  3964. }
  3965. break;
  3966. }
  3967. }
  3968. return true;
  3969. }
  3970. /**
  3971. * Import an iCal file into the database
  3972. * @param array Course info
  3973. * @return boolean True on success, false otherwise
  3974. */
  3975. function agenda_import_ical($course_info, $file)
  3976. {
  3977. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  3978. $charset = api_get_system_encoding();
  3979. $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
  3980. if (!@move_uploaded_file($file['tmp_name'], $filepath)) {
  3981. error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__);
  3982. return false;
  3983. }
  3984. require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php';
  3985. $ical = new vcalendar();
  3986. $ical->setConfig('directory', dirname($filepath));
  3987. $ical->setConfig('filename', basename($filepath));
  3988. $return = $ical->parse();
  3989. //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name),
  3990. /*
  3991. $ve = $ical->getComponent(VEVENT);
  3992. $ttitle = $ve->getProperty('summary');
  3993. $title = api_convert_encoding($ttitle,$charset,'UTF-8');
  3994. $tdesc = $ve->getProperty('description');
  3995. $desc = api_convert_encoding($tdesc,$charset,'UTF-8');
  3996. $start_date = $ve->getProperty('dtstart');
  3997. $start_date_string = $start_date['year'].'-'.$start_date['month'].'-'.$start_date['day'].' '.$start_date['hour'].':'.$start_date['min'].':'.$start_date['sec'];
  3998. $ts = $ve->getProperty('dtend');
  3999. if ($ts) {
  4000. $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  4001. } else {
  4002. //Check duration if dtend does not exist
  4003. $duration = $ve->getProperty('duration');
  4004. if ($duration) {
  4005. $duration = $ve->getProperty('duration');
  4006. $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec'];
  4007. $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year']));
  4008. //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year']));
  4009. //echo date('d-m-Y - h:i:s', $start_date_tms);
  4010. $end_date_string = mktime(intval($start_date['hour']) +$duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day'])+$duration['day'], intval($start_date['year']) + $duration['year']);
  4011. $end_date_string = date('Y-m-d H:i:s', $end_date_string);
  4012. //echo date('d-m-Y - h:i:s', $end_date_string);
  4013. }
  4014. }
  4015. //echo $start_date.' - '.$end_date;
  4016. $organizer = $ve->getProperty('organizer');
  4017. $attendee = $ve->getProperty('attendee');
  4018. $course_name = $ve->getProperty('location');
  4019. //insert the event in our database
  4020. //var_dump($title,$desc,$start_date,$end_date);
  4021. $id = agenda_add_item($course_info,$title,$desc,$start_date_string,$end_date_string,$_POST['selectedform']);
  4022. $repeat = $ve->getProperty('rrule');
  4023. if(is_array($repeat) && !empty($repeat['FREQ'])) {
  4024. $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly');
  4025. $freq = $trans[$repeat['FREQ']];
  4026. $interval = $repeat['INTERVAL'];
  4027. if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) {
  4028. $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']);
  4029. $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']);
  4030. } */
  4031. $eventcount = 0;
  4032. $message = array();
  4033. $agenda_obj = new Agenda();
  4034. while (true) {
  4035. //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name)
  4036. $ve = $ical->getComponent('VEVENT', $eventcount);
  4037. if (!$ve) {
  4038. break;
  4039. }
  4040. $ttitle = $ve->getProperty('summary');
  4041. $title = api_convert_encoding($ttitle, $charset, 'UTF-8');
  4042. $tdesc = $ve->getProperty('description');
  4043. $desc = api_convert_encoding($tdesc, $charset, 'UTF-8');
  4044. $start_date = $ve->getProperty('dtstart', false, true);
  4045. if (isset($start_date['params']['VALUE'])) {
  4046. $start_date_value = $start_date['value'];
  4047. if ($start_date['params']['VALUE'] == 'DATE') {
  4048. $start_date_string = $start_date_value['year'].'-'.$start_date_value['month'].'-'.$start_date_value['day'].'';
  4049. } else {
  4050. $start_date_string = $start_date_value['year'].'-'.$start_date_value['month'].'-'.$start_date_value['day'].' '.$start_date_value['hour'].':'.$start_date_value['min'].':'.$start_date_value['sec'];
  4051. }
  4052. } else {
  4053. continue;
  4054. }
  4055. $ts = $ve->getProperty('dtend');
  4056. if ($ts) {
  4057. $end_date = $ve->getProperty('dtend', false, true);
  4058. if (isset($end_date['params']['VALUE'])) {
  4059. $end_date_value = $end_date['value'];
  4060. if ($end_date['params']['VALUE'] == 'DATE') {
  4061. $end_date_string = $end_date_value['year'].'-'.$end_date_value['month'].'-'.$end_date_value['day'].'';
  4062. } else {
  4063. $end_date_string = $end_date_value['year'].'-'.$end_date_value['month'].'-'.$end_date_value['day'].' '.$end_date_value['hour'].':'.$end_date_value['min'].':'.$end_date_value['sec'];
  4064. }
  4065. } else {
  4066. //Default behaviour
  4067. $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  4068. }
  4069. } else {
  4070. //Check duration if dtend does not exist
  4071. $duration = $ve->getProperty('duration');
  4072. if ($duration) {
  4073. $duration = $ve->getProperty('duration');
  4074. $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec'];
  4075. $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year']));
  4076. //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year']));
  4077. //echo date('d-m-Y - h:i:s', $start_date_tms);
  4078. $end_date_string = mktime(intval($start_date['hour']) + $duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day']) + $duration['day'], intval($start_date['year']) + $duration['year']);
  4079. $end_date_string = api_get_utc_datetime($end_date_string);
  4080. //echo date('d-m-Y - h:i:s', $end_date_string);
  4081. }
  4082. }
  4083. //echo $start_date.' - '.$end_date;
  4084. $organizer = $ve->getProperty('organizer');
  4085. $attendee = $ve->getProperty('attendee');
  4086. $course_name = $ve->getProperty('location');
  4087. //insert the event in our database
  4088. $agenda_obj->type = 'course';
  4089. $all_day = 'false';
  4090. if ($start_date_string == $end_date_string) {
  4091. $all_day = 'true';
  4092. }
  4093. $date = new DateTime($start_date_string);
  4094. $date->add(new DateInterval('P1D'));
  4095. if ($start_date_string == $date->format('Y-m-d h:i:s')) {
  4096. $all_day = 'true';
  4097. }
  4098. //var_dump($start_date_string, $end_date_string, $all_day);
  4099. $id = $agenda_obj->add_event($start_date_string, $end_date_string, $all_day, null, $title, $desc, array('everyone'));
  4100. $message[] = " $title - ".$start_date_string." - ".$end_date_string;
  4101. $repeat = $ve->getProperty('rrule');
  4102. if (is_array($repeat) && !empty($repeat['FREQ'])) {
  4103. $trans = array(
  4104. 'DAILY' => 'daily',
  4105. 'WEEKLY' => 'weekly',
  4106. 'MONTHLY' => 'monthlyByDate',
  4107. 'YEARLY' => 'yearly'
  4108. );
  4109. $freq = $trans[$repeat['FREQ']];
  4110. $interval = $repeat['INTERVAL'];
  4111. if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) {
  4112. $until = mktime(23, 59, 59, $repeat['UNTIL']['month'], $repeat['UNTIL']['day'], $repeat['UNTIL']['year']);
  4113. $res = agenda_add_repeat_item($course_info, $id, $freq, $until, $attendee);
  4114. }
  4115. //TODO: deal with count
  4116. if (!empty($repeat['COUNT'])) {
  4117. $count = $repeat['COUNT'];
  4118. $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $attendee);
  4119. }
  4120. }
  4121. $eventcount++;
  4122. }
  4123. if (!empty($message)) {
  4124. $message = implode('<br /> ', $message);
  4125. }
  4126. return $message;
  4127. }
  4128. /**
  4129. * This function retrieves one personal agenda item returns it.
  4130. * @param array The array containing existing events. We add to this array.
  4131. * @param int Day
  4132. * @param int Month
  4133. * @param int Year (4 digits)
  4134. * @param int Week number
  4135. * @param string Type of view (month_view, week_view, day_view)
  4136. * @return array The results of the database query, or null if not found
  4137. */
  4138. function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type)
  4139. {
  4140. $tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  4141. $month = Database::escape_string($month);
  4142. $year = Database::escape_string($year);
  4143. $week = Database::escape_string($week);
  4144. $day = Database::escape_string($day);
  4145. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  4146. $current_access_url_id = api_get_current_access_url_id();
  4147. if ($type == "month_view" or $type == "") {
  4148. // We are in month view
  4149. $sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date)='".$month."' AND YEAR(start_date) = '".$year."' AND access_url_id = $current_access_url_id ORDER BY start_date ASC";
  4150. }
  4151. // 2. creating the SQL statement for getting the personal agenda items in WEEK view
  4152. if ($type == "week_view") { // we are in week view
  4153. $start_end_day_of_week = calculate_start_end_of_week($week, $year);
  4154. $start_day = $start_end_day_of_week['start']['day'];
  4155. $start_month = $start_end_day_of_week['start']['month'];
  4156. $start_year = $start_end_day_of_week['start']['year'];
  4157. $end_day = $start_end_day_of_week['end']['day'];
  4158. $end_month = $start_end_day_of_week['end']['month'];
  4159. $end_year = $start_end_day_of_week['end']['year'];
  4160. // in sql statements you have to use year-month-day for date calculations
  4161. $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
  4162. $start_filter = api_get_utc_datetime($start_filter);
  4163. $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
  4164. $end_filter = api_get_utc_datetime($end_filter);
  4165. $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id ";
  4166. }
  4167. // 3. creating the SQL statement for getting the personal agenda items in DAY view
  4168. if ($type == "day_view") { // we are in day view
  4169. // we could use mysql date() function but this is only available from 4.1 and higher
  4170. $start_filter = $year."-".$month."-".$day." 00:00:00";
  4171. $start_filter = api_get_utc_datetime($start_filter);
  4172. $end_filter = $year."-".$month."-".$day." 23:59:59";
  4173. $end_filter = api_get_utc_datetime($end_filter);
  4174. $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id";
  4175. }
  4176. $result = Database::query($sql);
  4177. while ($item = Database::fetch_array($result)) {
  4178. if ($item['start_date'] != '0000-00-00 00:00:00') {
  4179. $item['start_date'] = api_get_local_time($item['start_date']);
  4180. $item['start_date_tms'] = api_strtotime($item['start_date']);
  4181. }
  4182. if ($item['end_date'] != '0000-00-00 00:00:00') {
  4183. $item['end_date'] = api_get_local_time($item['end_date']);
  4184. }
  4185. // we break the date field in the database into a date and a time part
  4186. $agenda_db_date = explode(" ", $item['start_date']);
  4187. $date = $agenda_db_date[0];
  4188. $time = $agenda_db_date[1];
  4189. // we divide the date part into a day, a month and a year
  4190. $agendadate = explode("-", $date);
  4191. $year = intval($agendadate[0]);
  4192. $month = intval($agendadate[1]);
  4193. $day = intval($agendadate[2]);
  4194. // we divide the time part into hour, minutes, seconds
  4195. $agendatime = explode(":", $time);
  4196. $hour = $agendatime[0];
  4197. $minute = $agendatime[1];
  4198. $second = $agendatime[2];
  4199. if ($type == 'month_view') {
  4200. $item['calendar_type'] = 'global';
  4201. $agendaitems[$day][] = $item;
  4202. continue;
  4203. }
  4204. $start_time = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  4205. $end_time = '';
  4206. if ($item['end_date'] != '0000-00-00 00:00:00') {
  4207. $end_time = ' - '.api_format_date($item['end_date'], DATE_TIME_FORMAT_LONG);
  4208. }
  4209. // if the student has specified a course we a add a link to that course
  4210. if ($item['course'] <> "") {
  4211. $url = api_get_path(WEB_CODE_PATH)."admin/agenda.php?cidReq=".urlencode($item['course'])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  4212. $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
  4213. } else {
  4214. $course_link = "";
  4215. }
  4216. // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
  4217. // if we have a day_view we use a half hour as index => key 33 = 16h30
  4218. if ($type !== "day_view") {
  4219. // This is the array construction for the WEEK or MONTH view
  4220. //Display the Agenda global in the tab agenda (administrator)
  4221. $agendaitems[$day] .= "<i>$start_time $end_time</i>&nbsp;-&nbsp;";
  4222. $agendaitems[$day] .= "<b>".get_lang('GlobalEvent')."</b>";
  4223. $agendaitems[$day] .= "<div>".$item['title']."</div><br>";
  4224. } else {
  4225. // this is the array construction for the DAY view
  4226. $halfhour = 2 * $agendatime['0'];
  4227. if ($agendatime['1'] >= '30') {
  4228. $halfhour = $halfhour + 1;
  4229. }
  4230. if (!is_array($agendaitems[$halfhour]))
  4231. $content = $agendaitems[$halfhour];
  4232. $agendaitems[$halfhour] = $content."<div><i>$hour:$minute</i> <b>".get_lang('GlobalEvent').": </b>".$item['title']."</div>";
  4233. }
  4234. }
  4235. return $agendaitems;
  4236. }
  4237. function display_ical_import_form()
  4238. {
  4239. $form = new FormValidator('frm_import_ical', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']), array('enctype' => 'multipart/form-data'));
  4240. $form->addElement('header', get_lang('ICalFileImport'));
  4241. $form->addElement('file', 'ical_import', get_lang('ICalFileImport'));
  4242. $form->addRule('ical_import', get_lang('ThisFieldIsRequired'), 'required');
  4243. $form->addElement('button', 'ical_submit', get_lang('Import'));
  4244. $form->display();
  4245. }