agenda.inc.php 192 KB

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