agenda.inc.php 195 KB

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