agenda.inc.php 192 KB

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