agenda.inc.php 194 KB

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