agenda.inc.php 194 KB

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