agenda.inc.php 192 KB

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