agenda.inc.php 192 KB

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