12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * @author: Julio Montoya <gugli100@gmail.com> BeezNest 2011 - Lots of fixes - UI improvements, security fixes,
- * @author: Patrick Cool, patrick.cool@UGent.be
- * @todo this code should be clean as well as the myagenda.inc.php - jmontoya
- * @package chamilo.calendar
- */
- /**
- * Code
- */
- // the variables for the days and the months
- // Defining the shorts for the days
- $DaysShort = api_get_week_days_short();
- // Defining the days of the week to allow translation of the days
- $DaysLong = api_get_week_days_long();
- // Defining the months of the year to allow translation of the months
- $MonthsLong = api_get_months_long();
- $htmlHeadXtra[] = to_javascript();
- $htmlHeadXtra[] = '<script type="text/javascript">
- function setFocus(){
- $("#agenda_title").focus();
- }
- $(document).ready(function () {
- setFocus();
- });
- </script>';
- require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
- /**
- * Retrieves all the agenda items from the table
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
- * @author Julio Montoya - Refactoring
- * @param integer $month: the integer value of the month we are viewing
- * @param integer $year: the 4-digit year indication e.g. 2005
- * @return array
- */
- function get_calendar_items($select_month, $select_year, $select_day = false) {
- $course_info = api_get_course_info();
- $select_month = intval($select_month);
- $select_year = intval($select_year);
- if ($select_day)
- $select_day = intval($select_day);
-
- if (!empty($select_month) && !empty($select_year)) {
-
- $show_all_current = " AND MONTH(start_date) = $select_month AND year(start_date) = $select_year";
- if ($select_day) {
- $show_all_current .= ' AND DAY(start_date) = '.$select_day;
- }
- $show_all_current_personal =" AND MONTH(date) = $select_month AND year(date) = $select_year";
-
- if ($select_day) {
- $show_all_current_personal .= ' AND DAY(date) = '.$select_day;
- }
- } else {
- $show_all_current = '';
- $show_all_current_personal = '';
- }
- // database variables
- $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
-
- $group_memberships = GroupManager::get_group_ids($course_info['real_id'], api_get_user_id());
- $repeats = array();
- /* CONSTRUCT THE SQL STATEMENT */
- // 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
- $user_id = api_get_user_id();
- if (isset($_SESSION['user'])) {
- $user_id = intval($_SESSION['user']);
- }
-
- $group_id = api_get_group_id();
-
-
- $session_condition = api_get_session_condition(api_get_session_id());
- if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
- // A.1. you are a course admin with a USER filter
- // => see only the messages of this specific user + the messages of the group (s)he is member of.
-
- if (!empty($_SESSION['user'])) {
- $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $_SESSION['user']);
- $show_user =true;
- $new_group_memberships=array();
- foreach($group_memberships as $id) {
- // did i have access to the same
- $has_access = GroupManager::user_has_access(api_get_user_id(),$id,GROUP_TOOL_CALENDAR);
- $result = GroupManager::get_group_properties($id);
- if ($has_access && $result['calendar_state']!='0' ) {
- $new_group_memberships[]=$id;
- }
- }
- $group_memberships = $new_group_memberships;
- if (is_array($group_memberships) && count($group_memberships)>0) {
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
- AND ip.visibility='1'
- $session_condition";
- } else {
- //AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
- $sql="SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_user_id = $user_id )
- AND ip.visibility='1'
- $session_condition";
- }
- }
- // A.2. you are a course admin with a GROUP filter
- // => see only the messages of this specific group
- elseif (!empty($_SESSION['group'])) {
- if (!empty($group_id)) {
- $result = GroupManager::get_group_properties($group_id);
- $has_access = GroupManager::user_has_access(api_get_user_id(),$group_id,GROUP_TOOL_CALENDAR);
- //echo '<pre>';print_R($result);
- // lastedit
- if (!$has_access || $result['calendar_state']=='0' ) {
- $group_id=0;
- }
- }
- $sql="SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_group_id=$group_id)
- AND ip.lastedit_type<>'CalendareventDeleted'
- $session_condition
- GROUP BY ip.ref";
- //removed - > AND toolitemproperties.visibility='1'
- }
- // A.3 you are a course admin without any group or user filter
- else {
- // A.3.a you are a course admin without user or group filter but WITH studentview
- // => see all the messages of all the users and groups without editing possibilities
- if (isset($_GET['isStudentView']) && $_GET['isStudentView'] =='true') {
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ip.visibility='1'
- $session_condition
- GROUP BY ip.ref
- ORDER $sort_item $sort";
- }
- // A.3.b you are a course admin or a student
- else {
- // A.3.b.1 you are a course admin without user or group filter and WITHOUT studentview (= the normal course admin view)
- // => see all the messages of all the users and groups with editing possibilities
- if (api_is_course_admin()) {
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.visibility='0' OR ip.visibility='1')
- $session_condition
- GROUP BY ip.ref";
- } else {
- // A.3.b.2 you are a student with no group filter possibly showall
- //when showing all the events we do not show the group events
- //todo showing ALL events including the groups events that are available
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.visibility='0' OR ip.visibility='1')
- $session_condition
- GROUP BY ip.ref";
- /*
- if (is_array($group_memberships) && count($group_memberships)>0)
- {
- echo $sql="SELECT
- agenda.*, toolitemproperties.*
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
- WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
- AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
- AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).")
- $session_condition
- GROUP BY toolitemproperties.ref
- ORDER BY start_date ".$sort;
- }
- else
- {
- $sql="SELECT
- agenda.*, toolitemproperties.*
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
- WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
- AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
- AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id='0'
- $session_condition
- GROUP BY toolitemproperties.ref
- ORDER BY start_date ".$sort;
- }
- */
- }
- }
- }
- } //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
- // B. you are a student
- else {
- if (is_array($group_memberships) && count($group_memberships)>0) {
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
- AND ip.visibility='1'
- $session_condition";
- } else {
- if (api_get_user_id()) {
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
- AND ip.visibility='1'
- $session_condition";
- } else {
- $sql="SELECT
- agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref ".$show_all_current."
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ip.to_group_id='0'
- AND ip.visibility='1'
- $session_condition";
- }
- }
- } // you are a student
-
- $my_events = array();
- $avoid_doubles = array();
- $result = Database::query($sql);
-
- //Course venets
- while($row = Database::fetch_array($result,'ASSOC')) {
- $row['calendar_type'] = 'course';
- if (!in_array($row['id'], $avoid_doubles)) {
- if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
- $row['start_date'] = api_get_local_time($row['start_date']);
- $row['start_date_tms'] = api_strtotime($row['start_date']);
- }
-
- if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
- $row['end_date'] = api_get_local_time($row['end_date']);
- $row['end_date_tms'] = api_strtotime($row['end_date']);
- }
-
- $my_events[] = $row;
- $avoid_doubles[] = $row['id'];
- }
- }
- //Check my personal calendar items
- if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) && empty($_SESSION['group'])) {
- $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
- // 1. creating the SQL statement for getting the personal agenda items in MONTH view
- $sql = "SELECT id, title, text as content , date as start_date, enddate as end_date, parent_event_id FROM ".$tbl_personal_agenda."
- WHERE user='".api_get_user_id()."' ".$show_all_current_personal;
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $row['calendar_type'] = 'personal';
- if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
- $row['start_date'] = api_get_local_time($row['start_date']);
- $row['start_date_tms'] = api_strtotime($row['start_date']);
- }
-
- if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
- $row['end_date'] = api_get_local_time($row['end_date']);
- $row['end_date_tms'] = api_strtotime($row['end_date']);
- }
- $my_events[] = $row;
- }
- }
-
- //Check global agenda events
- if (empty($_SESSION['user']) && empty($_SESSION['group'])) {
- $table_agenda_system = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
- $current_access_url_id = api_get_current_access_url_id();
-
- $sql = "SELECT DISTINCT id, title, content , start_date, end_date FROM ".$table_agenda_system."
- WHERE 1=1 ".$show_all_current." AND access_url_id = $current_access_url_id";
- $result=Database::query($sql);
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
- $row['start_date'] = api_get_local_time($row['start_date']);
- $row['start_date_tms'] = api_strtotime($row['start_date']);
- }
-
- if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
- $row['end_date'] = api_get_local_time($row['end_date']);
- $row['end_date_tms'] = api_strtotime($row['end_date']);
- }
-
- $row['calendar_type'] = 'global';
- $my_events[] = $row;
- }
- }
- return $my_events;
- }
- /**
- * show the mini calender of the given month
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @param array an array containing all the agenda items for the given month
- * @param integer $month: the integer value of the month we are viewing
- * @param integer $year: the 4-digit year indication e.g. 2005
- * @param string $monthName: the language variable for the mont name
- * @return html code
- * @todo refactor this so that $monthName is no longer needed as a parameter
- */
- function display_minimonthcalendar($agenda_items, $month, $year) {
- global $DaysShort, $MonthsLong;
- if (empty($month)) {
- $month = intval(date('m'));
- }
- if (empty($year)) {
- $month = date('Y');
- }
-
- $month_name = $MonthsLong[$month -1];
-
-
- //Handle leap year
- $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
- if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
- $numberofdays[2] = 29;
- //Get the first day of the month
- $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
- //Start the week on monday
- $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
- $backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath'])?'':Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode'])?'':Security::remove_XSS($_GET['courseCode']))."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
- $forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath'])?'':Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode'])?'':Security::remove_XSS($_GET['courseCode']))."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
-
- $month_link = Display::url($month_name. " ".$year, api_get_self()."?".api_get_cidreq()."&month=". ($month)."&year=".$year);
-
- $new_items = array();
- foreach($agenda_items as $item) {
- $day = intval(substr($item["start_date"],8,2));
- $my_month = intval(substr($item["start_date"],5,2));
- if ($my_month == $month) {
- $new_items[$day][] = 1;
- }
- }
-
- $agenda_items = $new_items;
-
- echo "<table class=\"data_table\">",
- "<tr>",
- "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))." </a></th>",
- "<th width=\"80%\" colspan=\"5\">".$month_link. "</th>",
- "<th width=\"10%\"><a href=\"", $forewardsURL, "\"> ".Display::return_icon('action_next.png',get_lang('Next'))." </a></th></tr>";
- echo "<tr>";
- for ($ii = 1; $ii < 8; $ii ++) {
- echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
- }
- echo "</tr>";
- $curday = -1;
- $today = getdate();
- while ($curday <= $numberofdays[$month]) {
- echo "<tr>";
- for ($ii = 0; $ii < 7; $ii ++) {
- if (($curday == -1) && ($ii == $startdayofweek)) {
- $curday = 1;
- }
- if (($curday > 0) && ($curday <= $numberofdays[$month])) {
- $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
- $dayheader = "$curday";
- if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
- $dayheader = "$curday";
- $class = "class=\"days_today\"";
- }
- echo "<td ".$class.">";
- if (!empty($agenda_items[$curday])) {
- echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&sort=asc&toolgroup=".api_get_group_id()."&action=view&view=day&day=".$curday."&month=".$month."&year=".$year."#".$curday."\">".$dayheader."</a>";
- } else {
- echo $dayheader;
- }
- // "a".$dayheader." <span class=\"agendaitem\">".$agenda_items[$curday]."</span>";
- echo "</td>";
- $curday ++;
- } else {
- echo "<td></td>";
- }
- }
- echo "</tr>";
- }
- echo "</table>";
- }
- /**
- * show the calender of the given month
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya - adding some nice styles
- * @param integer $month: the integer value of the month we are viewing
- * @param integer $year: the 4-digit year indication e.g. 2005
- * @return html code
- */
- function display_monthcalendar($month, $year, $agenda_items) {
- global $MonthsLong;
- global $DaysShort;
- global $origin;
- //Handle leap year
- $numberofdays = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
- if (($year%400 == 0) or ($year%4==0 and $year%100<>0)) $numberofdays[2] = 29;
- //Get the first day of the month
- $dayone = getdate(mktime(0,0,0,$month,1,$year));
-
- //Start the week on monday
- $startdayofweek = $dayone['wday']<>0 ? ($dayone['wday']-1) : 6;
- $backwardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&month=".($month==1 ? 12 : $month-1)."&year=".($month==1 ? $year-1 : $year);
- $forewardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&month=".($month==12 ? 1 : $month+1)."&year=".($month==12 ? $year+1 : $year);
- $new_month = $month-1;
- echo '<table id="agenda_list">';
- echo '<tr>';
- echo '<th width="10%"><a href="'.$backwardsURL.'">'.Display::return_icon('action_prev.png',get_lang('Previous'), array(), 32).'</a></th>';
- echo '<th width="80%" colspan="5"><br /><h3>'.$MonthsLong[$new_month].' '.$year.'</h3></th>';
- echo '<th width="10%"><a href="'.$forewardsURL.'"> '.Display::return_icon('action_next.png',get_lang('Next'), array(), 32).'</a></th>';
- echo '</tr>';
- echo '<tr>';
- for ($ii=1;$ii<8; $ii++) {
- echo '<td class="weekdays" width="14%">'.$DaysShort[$ii%7].'</td>';
- }
- echo '</tr>';
- $curday = -1;
- $today = getdate();
-
- $new_items = array();
- foreach($agenda_items as $item) {
- $day = intval(substr($item["start_date"],8,2));
- $my_month = intval(substr($item["start_date"],5,2));
- if ($my_month == $month) {
- $new_items[$day][] = $item;
- }
- }
- $agenda_items = $new_items;
- while ($curday <= $numberofdays[$month]) {
- echo '<tr>';
- //week
- for ($ii=0; $ii<7; $ii++) {
- if (($curday == -1) && ($ii==$startdayofweek)) {
- $curday = 1;
- }
- if (($curday>0) && ($curday<=$numberofdays[$month])) {
- $bgcolor = $ii<5 ? 'class="row_odd"' : 'class="row_even"';
- $dayheader = Display::div($curday, array('class'=>'agenda_day'));
- if (key_exists($curday, $agenda_items)) {
- $dayheader = Display::div($curday, array('class'=>'agenda_day'));
- $events_in_day = msort($agenda_items[$curday], 'start_date_tms');
- foreach ($events_in_day as $value) {
-
- $some_content = false;
- $month_start_date = (int)substr($value['start_date'],5,2);
-
- if ($month == $month_start_date) {
- $some_content = true;
-
- $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT);
- $end_time = '';
- if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') {
- $end_time = '- <i>'.api_format_date($value['end_date'],DATE_TIME_FORMAT_LONG).'</i>';
- }
- $complete_time = '<i>'.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).'</i> '.$end_time;
- $time = '<i>'.$start_time.'</i>';
-
- switch($value['calendar_type']) {
- case 'personal':
- $bg_color = '#D0E7F4';
- $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), 22);
- break;
- case 'global':
- $bg_color = '#FFBC89';
- $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22);
- break;
- case 'course':
- $bg_color = '#CAFFAA';
- $value['course_name'] = isset($value['course_name']) ? $value['course_name'] : null;
- $value['url'] = isset($value['url']) ? $value['url'] : null;
- $icon = Display::url(Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22), $value['url']);
- break;
- default:
- break;
- }
- $icon = Display::div($icon, array('style'=>'float:right'));
-
- //Setting a personal event to green
- $dayheader.= '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">';
-
- //Link to bubble
- $url = Display::url(cut($value['title'], 40), '#', array('id'=>$value['calendar_type'].'_'.$value['id'], 'class'=>'opener'));
- $dayheader .= $time.' '.$icon.' '.Display::div($url);
-
- //Hidden content
- $content = Display::div($icon.Display::tag('h1', $value['title']).$complete_time.'<hr />'.$value['content']);
-
- //Main div
- $dayheader .= Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog', 'style' => 'display:none'));
-
- $dayheader .= '</div>';
- }
-
- //Do not show links with no content
- if (!$some_content) {
- $dayheader = Display::div($curday, array('class'=>'agenda_day'));
- }
- }
- }
- if (($curday==$today['mday']) && ($year ==$today['year'])&&($month == $today['mon'])) {
- echo '<td class="days_today"'.$bgcolor.' style="height:122px;width:10%">'.$dayheader;
- } else {
- $class = 'days_week';
- echo '<td class="'.$class.'" '.$bgcolor.' style="height:122px;width:10%">'.$dayheader;
- }
- echo '</td>';
- $curday++;
- } else {
- echo '<td> </td>';
- }
- }
- echo '</tr>';
- } // end while
- echo '</table>';
- }
- /**
- * returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return javascript code
- */
- function to_javascript() {
- return "<script type=\"text/javascript\" language=\"javascript\">
- $(function() {
- //js used when generating images on the fly see function Tracking::show_course_detail()
- $(\".dialog\").dialog(\"destroy\");
- $(\".dialog\").dialog({
- autoOpen: false,
- show: \"blind\",
- resizable: false,
- height:300,
- width:550,
- modal: true
- });
- $(\".opener\").click(function() {
- var my_id = $(this).attr('id');
- var big_image = '#main_' + my_id;
- $( big_image ).dialog(\"open\");
- return false;
- });
- });
- <!-- Begin javascript menu swapper
- function move(fbox, tbox)
- {
- // @todo : change associative arrays arrLookup and arrLookupTitle that use firstname/lastnam as key
- // so, pb with homonyms
- var arrFbox = new Array();
- var arrTbox = new Array();
- var arrLookup = new Array();
- var arrLookupTitle = new Array();
- var i;
- for (i = 0; i < tbox.options.length; i++)
- {
- arrLookup[tbox.options[i].text] = tbox.options[i].value;
- arrLookupTitle[tbox.options[i].text] = tbox.options[i].title;
- arrTbox[i] = tbox.options[i].text;
- }
- var fLength = 0;
- var tLength = arrTbox.length;
- for(i = 0; i < fbox.options.length; i++)
- {
- arrLookup[fbox.options[i].text] = fbox.options[i].value;
- arrLookupTitle[fbox.options[i].text] = fbox.options[i].title;
- if (fbox.options[i].selected && fbox.options[i].value != \"\")
- {
- arrTbox[tLength] = fbox.options[i].text;
- tLength++;
- }
- else
- {
- arrFbox[fLength] = fbox.options[i].text;
- fLength++;
- }
- }
- //arrFbox.sort();
- //arrTbox.sort()
- var arrFboxGroup = new Array();
- var arrFboxUser = new Array();
- var prefix_x;
- for (x = 0; x < arrFbox.length; x++) {
- prefix_x = arrFbox[x].substring(0,2);
- if (prefix_x == 'G:') {
- arrFboxGroup.push(arrFbox[x]);
- } else {
- arrFboxUser.push(arrFbox[x]);
- }
- }
- arrFboxGroup.sort();
- arrFboxUser.sort();
- arrFbox = arrFboxGroup.concat(arrFboxUser);
- var arrTboxGroup = new Array();
- var arrTboxUser = new Array();
- var prefix_y;
- for (y = 0; y < arrTbox.length; y++) {
- prefix_y = arrTbox[y].substring(0,2);
- if (prefix_y == 'G:') {
- arrTboxGroup.push(arrTbox[y]);
- } else {
- arrTboxUser.push(arrTbox[y]);
- }
- }
- arrTboxGroup.sort();
- arrTboxUser.sort();
- arrTbox = arrTboxGroup.concat(arrTboxUser);
- fbox.length = 0;
- tbox.length = 0;
- var c;
- for(c = 0; c < arrFbox.length; c++)
- {
- var no = new Option();
- no.value = arrLookup[arrFbox[c]];
- no.text = arrFbox[c];
- no.title = arrLookupTitle[arrFbox[c]];
- fbox[c] = no;
- }
- for(c = 0; c < arrTbox.length; c++)
- {
- var no = new Option();
- no.value = arrLookup[arrTbox[c]];
- no.text = arrTbox[c];
- no.title = arrLookupTitle[arrTbox[c]];
- tbox[c] = no;
- }
- }
- function checkDate(month, day, year)
- {
- var monthLength =
- new Array(31,28,31,30,31,30,31,31,30,31,30,31);
- if (!day || !month || !year)
- return false;
- // check for bisestile year
- if (year/4 == parseInt(year/4))
- monthLength[1] = 29;
- if (month < 1 || month > 12)
- return false;
- if (day > monthLength[month-1])
- return false;
- return true;
- }
- function mktime() {
- var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
- d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
- var dateManip = {
- 0: function(tt){ return d.setHours(tt); },
- 1: function(tt){ return d.setMinutes(tt); },
- 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
- 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
- 4: function(tt){ return d.setDate(tt+mb); },
- 5: function(tt){ return d.setYear(tt+ma); }
- };
- for( i = 0; i < argc; i++ ){
- no = parseInt(argv[i]*1);
- if (isNaN(no)) {
- return false;
- } else {
- // arg is number, lets manipulate date object
- if(!dateManip[i](no)){
- // failed
- return false;
- }
- }
- }
- return Math.floor(d.getTime()/1000);
- }
- function validate() {
- var f = document.new_calendar_item;
- f.submit();
- return true;
- }
- function selectAll(cbList,bSelect,showwarning) {
- var start_day = document.new_calendar_item.fday.value;
- var start_month = document.new_calendar_item.fmonth.value;
- var start_year = document.new_calendar_item.fyear.value;
- var start_hour = document.new_calendar_item.fhour.value;
- var start_minute = document.new_calendar_item.fminute.value;
- var start_date = mktime(start_hour,start_minute,0,start_month,start_day,start_year)
- var ends_day = document.new_calendar_item.end_fday.value;
- var ends_month = document.new_calendar_item.end_fmonth.value;
- var ends_year = document.new_calendar_item.end_fyear.value;
- var ends_hour = document.new_calendar_item.end_fhour.value;
- var ends_minute = document.new_calendar_item.end_fminute.value;
- var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year)
- msg_err1 = document.getElementById(\"err_date\");
- msg_err2 = document.getElementById(\"err_start_date\");
- msg_err3 = document.getElementById(\"err_end_date\");
- msg_err4 = document.getElementById(\"err_title\");
-
-
- var error = false;
- if (start_date > ends_date) {
- if ($('#empty_end_date').is(':checked')) {
- msg_err1.innerHTML=\"\";
- msg_err2.innerHTML=\"\";
- msg_err3.innerHTML=\"\";
-
- } else {
- error = true;
- msg_err1.style.display =\"block\";
- msg_err1.innerHTML=\"".get_lang('EndDateCannotBeBeforeTheStartDate')."\";
- msg_err2.innerHTML=\"\";
- msg_err3.innerHTML=\"\";
- }
- }
-
- if (!checkDate(start_month,start_day,start_year)) {
- msg_err2.style.display =\"block\";
- msg_err2.innerHTML=\"".get_lang('InvalidDate')."\";
- msg_err1.innerHTML=\"\";
- msg_err3.innerHTML=\"\";
- error = true;
- }
-
- if (!checkDate(ends_month,ends_day,ends_year)) {
- msg_err3.style.display =\"block\";
- msg_err3.innerHTML=\"".get_lang('InvalidDate')."\";
- msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";
- error = true;
- }
-
- if (document.new_calendar_item.title.value == '') {
- msg_err4.style.display =\"block\";
- msg_err4.innerHTML=\"".get_lang('FieldRequired')."\";
- msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\";
- error = true;
- }
- if (error == false) {
- if (cbList) {
- if (cbList.length < 1) {
- if (!confirm(\"".get_lang('Send2All')."\")) {
- return false;
- }
- }
- for (var i=0; i<cbList.length; i++)
- cbList[i].selected = cbList[i].checked = bSelect;
- }
- document.new_calendar_item.submit();
- }
-
-
- }
- function reverseAll(cbList)
- {
- for (var i=0; i<cbList.length; i++)
- {
- cbList[i].checked = !(cbList[i].checked)
- cbList[i].selected = !(cbList[i].selected)
- }
- }
- function plus_attachment() {
- if (document.getElementById('options').style.display == 'none') {
- document.getElementById('options').style.display = 'block';
- document.getElementById('plus').innerHTML=' <img style=\"vertical-align:middle;\" src=\"../img/div_hide.gif\" alt=\"\" /> ".get_lang('AddAnAttachment')."';
- } else {
- document.getElementById('options').style.display = 'none';
- document.getElementById('plus').innerHTML=' <img style=\"vertical-align:middle;\" src=\"../img/div_show.gif\" alt=\"\" /> ".get_lang('AddAnAttachment')."';
- }
- }
- function plus_repeated_event() {
- if (document.getElementById('options2').style.display == 'none') {
- document.getElementById('options2').style.display = 'block';
- document.getElementById('plus2').innerHTML=' <img style=\"vertical-align:middle;\" src=\"../img/div_hide.gif\" alt=\"\" /> ".get_lang('RepeatEvent')."';
- } else {
- document.getElementById('options2').style.display = 'none';
- document.getElementById('plus2').innerHTML=' <img style=\"vertical-align:middle;\" src=\"../img/div_show.gif\" alt=\"\" /> ".get_lang('RepeatEvent')."';
- }
- }
- /*
- function plus_ical() {
- if (document.getElementById('icalform').style.display == 'none') {
- document.getElementById('icalform').style.display = 'block';
- document.getElementById('plusical').innerHTML='';
- }
- }
- */
- // End -->
- </script>";
- }
- /**
- * returns the javascript for setting a filter. This is a jump menu
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return javascript code
- */
- function user_group_filter_javascript() {
- return "<script language=\"JavaScript\" type=\"text/JavaScript\">
- <!--
- function MM_jumpMenu(targ,selObj,restore){
- eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
- if (restore) selObj.selectedIndex=0;
- }
- //-->
- </script>
- ";
- }
- /**
- * this function gets all the users of the current course
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return array: associative array where the key is the id of the user and the value is an array containing
- the first name, the last name, the user id
- */
- function get_course_users() {
- global $_cid;
- $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
- $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- // not 100% if this is necessary, this however prevents a notice
- if (!isset($courseadmin_filter))
- {$courseadmin_filter='';}
- //
- $order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
- $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName, u.username
- FROM $tbl_user as u, $tbl_courseUser as cu
- WHERE cu.course_code = '".api_get_course_id()."'
- AND cu.user_id = u.user_id $courseadmin_filter".$order_clause;
- $result = Database::query($sql);
- while($user=Database::fetch_array($result)){
- $users[$user[0]] = $user;
- }
-
- $session_id = api_get_session_id();
- if (!empty($session_id)) {
- $users = array();
- $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName, u.username
- FROM $tbl_session_course_user AS session_course_user
- INNER JOIN $tbl_user u ON u.user_id = session_course_user.id_user
- WHERE id_session = ".$session_id."
- AND course_code = '".api_get_course_id()."'";
- $result = Database::query($sql);
- while($user=Database::fetch_array($result)){
- $users[$user[0]] = $user;
- }
- }
- return $users;
- }
- /**
- * this function gets all the groups of the course
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return array
- */
- function get_course_groups() {
- $group_list = array();
- $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
- return $group_list;
- }
- /**
- * this function shows the form for sending a message to a specific group or user.
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return html code
- */
- function show_to_form($to_already_selected) {
- /*$user_list = get_course_users();
- $group_list = get_course_groups();*/
- $order = 'lastname';
- if (api_is_western_name_order) {
- $order = 'firstname';
- }
-
- $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
- $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
-
- construct_not_selected_select_form($group_list, $user_list, $to_already_selected);
- }
- /**
- * this function shows the form with the user that were not selected
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return html code
- */
- function construct_not_selected_select_form($group_list=null, $user_list=null, $to_already_selected=array()) {
- echo '<select data-placeholder="'.get_lang('Select').'" style="width:350px;" class="chzn-select" id="selected_form_id" name="selected_form[]" multiple="multiple">';
- // adding the groups to the select form
- echo '<option value="everyone">'.get_lang('Everyone').'</option>';
-
- if (isset($to_already_selected) && $to_already_selected==='everyone') {
- } else {
- if (is_array($group_list)) {
- echo '<optgroup label="'.get_lang('Groups').'">';
- foreach($group_list as $this_group) {
- //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
- 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
- echo "<option value=\"GROUP:".$this_group['id']."\">",
- "G: ",$this_group['name']," – " . $this_group['userNb'] . " " . get_lang('Users') .
- "</option>";
- }
- }
- // a divider
- }
- echo "</optgroup>";
- // adding the individual users to the select form
- if (!empty($user_list)) {
- echo '<optgroup label="'.get_lang('Users').'">';
- foreach($user_list as $this_user) {
- // $to_already_selected is the array containing the users (and groups) that are already selected
- if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'],$to_already_selected)) {
- $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
- $user_info = api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].')';
- echo "<option title='$username' value='USER:".$this_user['user_id']."'>$user_info</option>";
- }
- }
- echo "</optgroup>";
- }
- }
- echo "</select>";
- }
- /**
- * This function shows the form with the user that were selected
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return html code
- */
- function construct_selected_select_form($group_list=null, $user_list=null,$to_already_selected)
- {
- // we separate the $to_already_selected array (containing groups AND users into
- // two separate arrays
- if (is_array($to_already_selected)) {
- $groupuser=separate_users_groups($to_already_selected);
- }
- $groups_to_already_selected=$groupuser['groups'];
- $users_to_already_selected=$groupuser['users'];
- // we load all the groups and all the users into a reference array that we use to search the name of the group / user
- $ref_array_groups = get_course_groups();
- $ref_array_users = get_course_users();
- // we construct the form of the already selected groups / users
- echo "<select id=\"selected_form2\" name=\"selectedform2[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">";
- if(is_array($to_already_selected))
- {
- $select_options_group = array();
- $select_options_user = array();
- $select_options_groupuser = array();
- foreach($to_already_selected as $groupuser)
- {
- list($type,$id)=explode(":",$groupuser);
- if ($type=="GROUP")
- {
- $select_options_group[] = "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
- //echo "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
- }
- else
- {
- $username = api_htmlentities(sprintf(get_lang('LoginX'), $ref_array_users[$id]['username']), ENT_QUOTES);
- $user_info = api_get_person_name($ref_array_users[$id]['firstName'], $ref_array_users[$id]['lastName']);
- $select_options_user[] = "<option title='$username' value='".$groupuser."'>$user_info</option>";
- //echo "<option value=\"".$groupuser."\">".api_get_person_name($ref_array_users[$id]['firstName'], $ref_array_users[$id]['lastName'])."</option>";
- }
- }
- $select_options_group[] = "<option value=\"\">--------------------------------------------</option>";
- $select_options_groupuser = array_merge($select_options_group,$select_options_user);
- foreach($select_options_groupuser as $select_options) {
- echo $select_options;
- }
- } else {
- if($to_already_selected=='everyone'){
- // adding the groups to the select form
- if (is_array($group_list))
- {
- foreach($group_list as $this_group)
- {
- //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
- 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
- {
- echo "<option value=\"GROUP:".$this_group['id']."\">",
- "G: ",$this_group['name']," – " . $this_group['userNb'] . " " . get_lang('Users') .
- "</option>";
- }
- }
- }
- echo "<option value=\"\">--------------------------------------------</option>";
- // adding the individual users to the select form
- foreach($user_list as $this_user)
- {
- 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
- {
- echo "<option value=\"USER:",$this_user['uid'],"\">",
- "",api_get_person_name($this_user['firstName'], $this_user['lastName']),
- "</option>";
- }
- }
- }
- }
- echo "</select>";
- }
- /**
- * This function stores the Agenda Item in the table calendar_event and updates the item_property table also
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return integer the id of the last added agenda item
- */
- function store_new_agenda_item() {
- global $_course;
- $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
- $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT);
-
- $course_id = api_get_course_int_id();
- // some filtering of the input data
- $title = trim($_POST['title']); // no html allowed in the title
- $content = trim($_POST['content']);
- $start_date = (int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00";
- $end_date = (int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00";
-
-
- $title = Database::escape_string($title);
- $content = Database::escape_string($content);
- $start_date = Database::escape_string($start_date);
- $end_date = Database::escape_string($end_date);
-
- if ($_POST['empty_end_date'] == 'on') {
- $end_date = "0000-00-00 00:00:00";
- }
- // store in the table calendar_event
- $sql = "INSERT INTO ".$TABLEAGENDA." (c_id, title,content, start_date, end_date)
- VALUES ($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."')";
- $result = Database::query($sql);
- $last_id = Database::insert_id();
- // store in last_tooledit (first the groups, then the users
- $to=$_POST['selectedform'];
- if ((!is_null($to)) || (!empty($_SESSION['toolgroup']))) // !is_null($to): when no user is selected we send it to everyone
- {
- //$send_to=separate_users_groups($to);
- $send_to=separate_users_groups(explode('|', $to));
- // storing the selected groups
- if (is_array($send_to['groups'])) {
- foreach ($send_to['groups'] as $group) {
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", api_get_user_id(), $group,'',$start_date, $end_date);
- }
- }
- // storing the selected users
- if (is_array($send_to['users'])) {
- foreach ($send_to['users'] as $user) {
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", api_get_user_id(),'',$user, $start_date,$end_date);
- }
- }
- }
- else // the message is sent to everyone, so we set the group to 0
- {
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", api_get_user_id(), '','',$start_date,$end_date);
- }
- // storing the resources
- store_resources($_SESSION['source_type'],$last_id);
- $course_id = api_get_course_int_id();
- //if repetitive, insert element into agenda_repeat table
- if(!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) {
- if(!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) {
- $end_y = intval($_POST['repeat_end_year']);
- $end_m = intval($_POST['repeat_end_month']);
- $end_d = intval($_POST['repeat_end_day']);
- $end = mktime((int)$_POST['fhour'],(int)$_POST['fminute'],0,$end_m,$end_d,$end_y);
- $now = time();
- $type = Database::escape_string($_POST['repeat_type']);
- if ($end > $now && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly'))) {
- $sql = "INSERT INTO $t_agenda_repeat (c_id, cal_id, cal_type, cal_end)" .
- " VALUES ($course_id, $last_id,'$type',$end)";
- $res = Database::query($sql);
- }
- }
- }
- return $last_id;
- }
- /**
- * Stores the given agenda item as an announcement (unlinked copy)
- * @param integer Agenda item's ID
- * @return integer New announcement item's ID
- */
- function store_agenda_item_as_announcement($item_id){
- $table_agenda = Database::get_course_table(TABLE_AGENDA);
- $table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT);
- //check params
- if(empty($item_id) or $item_id != strval(intval($item_id))) {return -1;}
- //get the agenda item
- $item_id = Database::escape_string($item_id);
- $sql = "SELECT * FROM $table_agenda WHERE id = ".$item_id;
- $res = Database::query($sql);
- $course_id = api_get_course_int_id();
-
- if (Database::num_rows($res)>0) {
- $row = Database::fetch_array($res);
-
- //we have the agenda event, copy it
- //get the maximum value for display order in announcement table
- $sql_max = "SELECT MAX(display_order) FROM $table_ann WHERE c_id = $course_id ";
- $res_max = Database::query($sql_max);
- $row_max = Database::fetch_array($res_max);
- $max = intval($row_max[0])+1;
- //build the announcement text
- $content = $row['content'];
- //insert announcement
- $session_id = api_get_session_id();
-
-
- $sql_ins = "INSERT INTO $table_ann (c_id, title,content,end_date,display_order,session_id) " .
- "VALUES ($course_id, '".Database::escape_string($row['title'])."','".Database::escape_string($content)."','".Database::escape_string($row['end_date'])."','$max','$session_id')";
- $res_ins = Database::query($sql_ins);
- if ($res > 0) {
- $ann_id = Database::insert_id();
- //Now also get the list of item_properties rows for this agenda_item (calendar_event)
- //and copy them into announcement item_properties
- $table_props = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $sql_props = "SELECT * FROM $table_props WHERE tool = 'calendar_event' AND ref='$item_id'";
- $res_props = Database::query($sql_props);
- if(Database::num_rows($res_props)>0) {
- while($row_props = Database::fetch_array($res_props)) {
- //insert into announcement item_property
- $time = api_get_utc_datetime();
- $sql_ins_props = "INSERT INTO $table_props " .
- "(c_id, tool, insert_user_id, insert_date, " .
- "lastedit_date, ref, lastedit_type," .
- "lastedit_user_id, to_group_id, to_user_id, " .
- "visibility, start_visible, end_visible)" .
- " VALUES " .
- "($course_id, 'announcement','".$row_props['insert_user_id']."','".$time."'," .
- "'$time','$ann_id','AnnouncementAdded'," .
- "'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."'," .
- "'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')";
- $res_ins_props = Database::query($sql_ins_props);
- if($res_ins_props <= 0){
- return -1;
- } else {
- //copy was a success
- return $ann_id;
- }
- }
- }
- } else {
- return -1;
- }
- }
- return -1;
- }
- /**
- * This function separates the users from the groups
- * users have a value USER:XXX (with XXX the dokeos id
- * groups have a value GROUP:YYY (with YYY the group id)
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return array
- */
- function separate_users_groups($to) {
- $grouplist = array();
- $userlist = array();
- $send_to = null;
-
- $send_to['everyone'] = false;
-
- if (is_array($to) && count($to)>0) {
- foreach ($to as $to_item) {
-
- list($type, $id) = explode(':', $to_item);
- switch($type) {
- case 'everyone':
- $send_to['everyone'] = true;
- case 'GROUP':
- $grouplist[] =$id;
- break;
- case 'USER':
- $userlist[] =$id;
- break;
- }
- }
- $send_to['groups'] = $grouplist;
- $send_to['users'] = $userlist;
- }
- return $send_to;
- }
- /**
- * returns all the users and all the groups a specific Agenda item has been sent to
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @return array
- */
- function sent_to($tool, $id) {
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $tool = Database::escape_string($tool);
- $id = Database::escape_string($id);
- $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'";
- $result=Database::query($sql);
- while ($row=Database::fetch_array($result)) {
- // if to_group_id is null then it is sent to a specific user
- // if to_group_id = 0 then it is sent to everybody
- if (!is_null($row['to_group_id']) ) {
- $sent_to_group[]=$row['to_group_id'];
- //echo $row['to_group_id'];
- }
- // if to_user_id <> 0 then it is sent to a specific user
- if ($row['to_user_id']<>0) {
- $sent_to_user[]=$row['to_user_id'];
- }
- }
- if (isset($sent_to_group)) {
- $sent_to['groups']=$sent_to_group;
- }
- if (isset($sent_to_user)) {
- $sent_to['users']=$sent_to_user;
- }
- return $sent_to;
- }
- /**
- * constructs the form to display all the groups and users the message has been sent to
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @param array $sent_to_array: a 2 dimensional array containing the groups and the users
- * the first level is a distinction between groups and users: $sent_to_array['groups'] and $sent_to_array['users']
- * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array containing all the id's of the
- * groups (resp. users) who have received this message.
- * @return html
- */
- function sent_to_form($sent_to_array) {
- // we find all the names of the groups
- $group_names = get_course_groups();
-
- // we count the number of users and the number of groups
- if (isset($sent_to_array['users'])) {
- $number_users=count($sent_to_array['users']);
- } else {
- $number_users=0;
- }
- if (isset($sent_to_array['groups'])) {
- $number_groups=count($sent_to_array['groups']);
- } else {
- $number_groups=0;
- }
- $total_numbers = $number_users + $number_groups;
- $output = array();
- // starting the form if there is more than one user/group
- if ($total_numbers > 1 ) {
- //$output.="<option>".get_lang("SentTo")."</option>";
- // outputting the name of the groups
- if (is_array($sent_to_array['groups'])) {
- foreach ($sent_to_array['groups'] as $group_id) {
- if (isset($group_names[$group_id]['name'])) {
- $output[]= $group_names[$group_id]['name'];
- }
- }
- }
- if (isset($sent_to_array['users'])) {
- if (is_array($sent_to_array['users'])) {
- foreach ($sent_to_array['users'] as $user_id) {
- // @todo add username as tooltip - is this fucntion still used ?
- // $user_info= api_get_user_info($user_id);
- // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
- $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
- }
- }
- }
- } else {
- // there is only one user/group
- if (is_array($sent_to_array['users'])) {
- // @todo add username as tooltip - is this fucntion still used ?
- // $user_info = api_get_user_info($sent_to_array['users'][0]);
- // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
- $output[]= api_get_person_name($user_info['firstName'], $user_info['lastName']);
- }
- if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]!==0) {
- $group_id = $sent_to_array['groups'][0];
- $output[]= $group_names[$group_id]['name'];
- }
- if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]==0) {
- $output[]= get_lang("Everybody");
- }
- }
- if (!empty($output)) {
- $output = array_filter($output);
- if (count($output) > 0) {
- $output = implode(', ', $output);
- }
- return $output;
- }
- }
- /**
- * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function show_group_filter_form() {
- $group_list = get_course_groups();
- echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
- echo "<option value=\"agenda.php?group=none\">".get_lang('ShowAll')."</option>";
- foreach($group_list as $this_group) {
- echo "<option value=\"agenda.php?action=view&group=".$this_group['id']."\" ";
- echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
- echo ">".$this_group['name']."</option>";
- }
- echo "</select>";
- }
- /**
- * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function show_user_filter_form()
- {
- $user_list=get_course_users();
- echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
- echo "<option value=\"agenda.php?user=none\">".get_lang('ShowAll')."</option>";
- foreach($user_list as $this_user) {
- // echo "<option value=\"agenda.php?isStudentView=true&user=".$this_user['uid']."\">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
- echo "<option value=\"agenda.php?action=view&user=".$this_user['uid']."\" ";
- echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
- echo ">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
- }
- echo "</select>";
- }
- /**
- * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function show_user_group_filter_form() {
- echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
- echo "<option value=\"agenda.php?user=none&action=view\">".get_lang("ShowAll")."</option>";
-
- // Groups
- $group_list = get_course_groups();
- $group_available_to_access =array();
- $option = '';
- if (!empty($group_list)) {
- $option = "<optgroup label=\"".get_lang("Groups")."\">";
- foreach($group_list as $this_group) {
- // echo "<option value=\"agenda.php?isStudentView=true&group=".$this_group['id']."\">".$this_group['name']."</option>";
- $has_access = GroupManager::user_has_access(api_get_user_id(),$this_group['id'],GROUP_TOOL_CALENDAR);
- $result = GroupManager::get_group_properties($this_group['id']);
- if ($result['calendar_state']!='0') {
- $group_available_to_access[]=$this_group['id'];
- }
- // lastedit
- if ($has_access || $result['calendar_state']=='1') {
- $option.= "<option value=\"agenda.php?action=view&group=".$this_group['id']."\" ";
- $option.= ($this_group['id']==$_SESSION['group'])? " selected":"" ;
- $option.= ">".$this_group['name']."</option>";
- }
- }
- $option.= "</optgroup>";
- }
-
- echo $option;
-
- // Users
-
- $user_list = get_course_users();
- if (!empty($user_list)) {
- echo "<optgroup label=\"".get_lang("Users")."\">";
- foreach($user_list as $this_user) {
- echo "<option value=\"agenda.php?action=view&user=".$this_user['uid']."\" ";
- echo (isset($_SESSION['user']) && $this_user['uid']==$_SESSION['user']) ? " selected":"" ;
- echo ">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
- }
- echo "</optgroup>";
- }
- echo "</select>";
- }
- /**
- * This tools loads all the users and all the groups who have received a specific item (in this case an agenda item)
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function load_edit_users($tool, $id) {
- $tool=Database::escape_string($tool);
- $id=Database::escape_string($id);
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='$tool' AND ref='$id'";
- $result=Database::query($sql) or die (Database::error());
- while ($row=Database::fetch_array($result))
- {
- $to_group=$row['to_group_id'];
- switch ($to_group)
- {
- // it was send to one specific user
- case null:
- $to[]="USER:".$row['to_user_id'];
- break;
- // it was sent to everyone
- case 0:
- return "everyone";
- exit;
- break;
- default:
- $to[]="GROUP:".$row['to_group_id'];
- }
- }
- return $to;
- }
- /**
- * This functions swithes the visibility a course resource using the visible field in 'last_tooledit' values: 0 = invisible
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function change_visibility($tool,$id,$visibility)
- {
- global $_course;
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $tool=Database::escape_string($tool);
- $id=Database::escape_string($id);
- /*
- $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".TOOL_CALENDAR_EVENT."' AND ref='$id'";
- $result=Database::query($sql) or die (Database::error());
- $row=Database::fetch_array($result);
- */
- if ($visibility == 0) {
- $sql_visibility="UPDATE $TABLE_ITEM_PROPERTY SET visibility='0' WHERE tool='$tool' AND ref='$id'";
- api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,"invisible",api_get_user_id());
- } else {
- $sql_visibility="UPDATE $TABLE_ITEM_PROPERTY SET visibility='1' WHERE tool='$tool' AND ref='$id'";
- api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,"visible",api_get_user_id());
- }
- }
- /**
- * The links that allows the course administrator to add a new agenda item, to filter on groups or users
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function display_courseadmin_links() {
- if (!isset($_GET['action'])) {
- $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar_na.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM)."</a>";
- } else {
- $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM)."</a>";
- }
- $actions .= "<a href='agenda.php?".api_get_cidreq()."&sort=asc&toolgroup=".api_get_group_id()."&action=add&view=".(($_SESSION['view']=='month')?"list":Security::remove_XSS($_SESSION['view'])."&origin=".Security::remove_XSS($_GET['origin']))."'>".Display::return_icon('new_event.png', get_lang('AgendaAdd'),'',ICON_SIZE_MEDIUM)."</a>";
- $actions .= "<a href='agenda.php?".api_get_cidreq()."&action=importical&view=".(($_SESSION['view']=='month')?"list":Security::remove_XSS($_SESSION['view'])."&origin=".Security::remove_XSS($_GET['origin']))."'>".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'),'',ICON_SIZE_MEDIUM)."</a>";
-
- return $actions;
- /*
- if (empty ($_SESSION['toolgroup'])) {
- echo get_lang('SentTo');
- echo " <form name=\"filter\" style=\"display:inline;\">";
- show_user_group_filter_form();
- echo "</form> ";
- }*/
- }
- /**
- * The links that allows the student AND course administrator to show all agenda items and sort up/down
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya removing options, changing to a simple agenda tool
- */
- function display_student_links() {
- global $show;
- $month = isset($_GET['month']) ? intval($_GET['month']) : null;
- $year = isset($_GET['year']) ? intval($_GET['year']) : null;
-
- $day_url = '&month='.$month.'&year='.$year;
- if ($_SESSION['view'] <> 'month') {
- echo "<a href=\"".api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id()."&view=month\">".Display::return_icon('month_empty.png', get_lang('MonthView'),'',ICON_SIZE_MEDIUM)."</a> ";
- } else {
- echo "<a href=\"".api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id()."&view=list\">".Display::return_icon('week.png', get_lang('ListView'),'',ICON_SIZE_MEDIUM)."</a> ";
- }
- $day_url = '&month='.date('m').'&year='.date('Y').'&view='.Security::remove_XSS($_GET['view']);
- $today_url = api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id();
- echo Display::url(get_lang('Today'), $today_url, array('class'=>'a_button white medium'));
-
- //@todo Add next events and all events? ...
-
- //echo Display::url(get_lang('AllEvents'), $all_url, array('class'=>'a_button white medium'));
- //echo Display::url(get_lang('Next events'), $all_url, array('class'=>'a_button white medium'));
- }
- /**
- * get all the information of the agenda_item from the database
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @param integer the id of the agenda item we are getting all the information of
- * @return an associative array that contains all the information of the agenda item. The keys are the database fields
- */
- function get_agenda_item($id)
- {
- global $TABLEAGENDA;
- $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
- $id=Database::escape_string($id);
- $item = array();
- if(empty($id)) {
- $id=intval(Database::escape_string(($_GET['id'])));
- } else {
- $id = (int) $id;
- }
- $course_id = api_get_course_int_id();
- if(empty($id)){return $item;}
- $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."' AND c_id = $course_id ";
- $result = Database::query($sql);
- $entry_to_edit = Database::fetch_array($result);
- $item['title'] = $entry_to_edit["title"];
- $item['content'] = $entry_to_edit["content"];
- $item['start_date'] = $entry_to_edit["start_date"];
- $item['end_date'] = $entry_to_edit["end_date"];
- $item['to'] = load_edit_users(TOOL_CALENDAR_EVENT, $id);
- // if the item has been sent to everybody then we show the compact to form
- if ($item['to']=="everyone")
- {
- $_SESSION['allow_individual_calendar']="hide";
- }
- else
- {
- $_SESSION['allow_individual_calendar']="show";
- }
- $item['repeat'] = false;
- $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- //this event is repetitive
- $row = Database::fetch_array($res);
- $item['repeat'] = true;
- $item['repeat_type'] = $row['cal_type'];
- $item['repeat_end'] = $row['cal_end'];
- $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
- $item['repeat_days'] = $row['cal_days']; //unused in 1.8.5 RC1 - will be used later
- }
- //TODO - add management of repeat exceptions
- return $item;
- }
- /**
- * This is the function that updates an agenda item. It does 3 things
- * 1. storethe start_date, end_date, title and message in the calendar_event table
- * 2. store the groups/users who this message is meant for in the item_property table
- * 3. modify the attachments (if needed)
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya Adding UTC support
- */
- function store_edited_agenda_item($id_attach, $file_comment) {
- global $_course;
- // database definitions
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- // STEP 1: editing the calendar_event table
- // 1.a. some filtering of the input data
- $id = (int)$_POST['id'];
- $title = strip_tags(trim($_POST['title'])); // no html allowed in the title
- $content = trim($_POST['content']);
- $start_date = (int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00";
- $end_date = (int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00";
- $to = $_POST['selectedform'];
-
- $start_date = api_get_utc_datetime($start_date);
- $end_date = api_get_utc_datetime($end_date);
-
- if ($_POST['empty_end_date'] == 'on') {
- $end_date = "0000-00-00 00:00:00";
- }
-
- // 1.b. the actual saving in calendar_event table
- $edit_result = save_edit_agenda_item($id, $title, $content, $start_date, $end_date);
-
- if (empty($id_attach)) {
- add_agenda_attachment_file($file_comment, $id);
- } else {
- edit_agenda_attachment_file($file_comment,$id,$id_attach);
- }
- // step 2: editing the item_propery table (=delete all and add the new destination users/groups)
- if ($edit_result=true) {
- // 2.a. delete everything for the users
- $sql_delete="DELETE FROM ".$TABLE_ITEM_PROPERTY." WHERE ref='$id' AND tool='".TOOL_CALENDAR_EVENT."'";
- $result = Database::query($sql_delete) or die (Database::error());
- // 2.b. storing the new users/groups
- if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
- {
- $send_to=separate_users_groups($to);
- // storing the selected groups
- if (is_array($send_to['groups'])) {
- foreach ($send_to['groups'] as $group)
- {
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", api_get_user_id(), $group,'',$start_date, $end_date);
- }
- }
- // storing the selected users
- if (is_array($send_to['users'])) {
- foreach ($send_to['users'] as $user) {
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", api_get_user_id(),'',$user, $start_date,$end_date);
- }
- }
- } else {
- // the message is sent to everyone, so we set the group to 0
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", api_get_user_id(), '','',$start_date,$end_date);
- }
- } //if ($edit_result=true)
- // step 3: update the attachments (=delete all and add those in the session
- update_added_resources("Agenda", $id);
- // return the message;
- Display::display_confirmation_message(get_lang("EditSuccess"));
- }
- /**
- * This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit)
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function save_edit_agenda_item($id,$title,$content,$start_date,$end_date) {
- $TABLEAGENDA= Database::get_course_table(TABLE_AGENDA);
- $id = Database::escape_string($id);
- $title = Database::escape_string($title);
- $content = Database::escape_string($content);
- $start_date = Database::escape_string($start_date);
- $end_date = Database::escape_string($end_date);
- // store the modifications in the table calendar_event
- $sql = "UPDATE ".$TABLEAGENDA."
- SET title ='".$title."',
- content ='".$content."',
- start_date ='".$start_date."',
- end_date ='".$end_date."'
- WHERE id='".$id."'";
- $result = Database::query($sql);
- return true;
- }
- /**
- * This is the function that deletes an agenda item.
- * The agenda item is no longer fycically deleted but the visibility in the item_property table is set to 2
- * which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
- * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
- * by the course administrator
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @param integer the id of the agenda item wa are deleting
- */
- function delete_agenda_item($id) {
- global $_course;
- $id=Database::escape_string($id);
- if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
- if (!empty($_GET['id']) && isset($_GET['action']) && $_GET['action']=="delete") {
- $t_agenda = Database::get_course_table(TABLE_AGENDA);
- $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
- $id=intval($_GET['id']);
- $sql = "SELECT * FROM $t_agenda_r WHERE cal_id = $id";
- $res = Database::query($sql);
- if(Database::num_rows($res)>0) {
- $sql_children = "SELECT * FROM $t_agenda WHERE parent_event_id = $id";
- $res_children = Database::query($sql_children);
- if(Database::num_rows($res_children)>0) {
- while ($row_child = Database::fetch_array($res_children)) {
- api_item_property_update($_course,TOOL_CALENDAR_EVENT,$row_child['id'],'delete',api_get_user_id());
- }
- }
- $sql_del = "DELETE FROM $t_agenda_r WHERE cal_id = $id";
- $res_del = Database::query($sql_del);
- }
- //$sql = "DELETE FROM ".$TABLEAGENDA." WHERE id='$id'";
- //$sql= "UPDATE ".$TABLE_ITEM_PROPERTY." SET visibility='2' WHERE tool='Agenda' and ref='$id'";
- //$result = Database::query($sql) or die (Database::error());
- api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,'delete',api_get_user_id());
- // delete the resources that were added to this agenda item
- // 2DO: as we no longer fysically delete the agenda item (to make it possible to 'restore'
- // deleted items, we should not delete the added resources either.
- // 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)
- //resetting the $id;
- $id=null;
- // displaying the result message in the yellow box
- Display::display_confirmation_message(get_lang("AgendaDeleteSuccess"));
- } // if (isset($id)&&$id&&isset($action)&&$action=="delete")
- } // if ($is_allowed_to_edit)
- }
- /**
- * Makes an agenda item visible or invisible for a student
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @param integer id the id of the agenda item we are changing the visibility of
- */
- function showhide_agenda_item($id) {
- global $nameTools;
- /*
- SHOW / HIDE A CALENDAR ITEM
- */
- // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following:
- // change visibility -> studentview -> course manager view
- if ((api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) and $_GET['isStudentView']<>"false") {
- if (isset($_GET['id']) && isset($_GET['action']) && $_GET['action']=="showhide") {
- $id=(int)addslashes($_GET['id']);
- if (isset($_GET['next_action']) && $_GET['next_action'] == strval(intval($_GET['next_action']))) {
- $visibility = $_GET['next_action'];
- change_visibility($nameTools,$id,$visibility);
- Display::display_confirmation_message(get_lang("VisibilityChanged"));
- }
- }
- }
- }
- /**
- * Displays all the agenda items
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Yannick Warnier <yannick.warnier@beeznest.com> - cleanup
- * @author Julio Montoya <gugli100@gmail.com> - Refactoring
- */
- function display_agenda_items($agenda_items, $day = false) {
- global $charset;
- if (isset($day) && $day) {
- $new_items = array();
- foreach($agenda_items as $item) {
- if (substr($item['start_date'],8,2) == $day) {
- $new_items[] = $item;
- }
- }
- $agenda_items = $new_items;
- }
-
- if (isset($_GET['sort']) && $_GET['sort'] == 'asc') {
- $sort_inverse = 'desc';
- $sort = 'asc';
- } else {
- $sort_inverse = 'asc';
- $sort = 'desc';
- }
-
- if (isset($_GET['col']) && $_GET['col'] == 'end') {
- $sort_item = 'end_date_tms';
- $col = 'end';
- } else {
- $sort_item = 'start_date_tms';
- $col = 'start';
- }
- $agenda_items = msort($agenda_items, $sort_item, $sort);
-
- //DISPLAY: NO ITEMS
- if (empty($agenda_items)) {
- echo Display::display_warning_message(get_lang('NoAgendaItems'));
- } else {
- echo '<table class="data_table">';
- $th = Display::tag('th', get_lang('Title'));
- $month = isset($_GET['month']) ? intval($_GET['month']) : null;
- $year = isset($_GET['year']) ? intval($_GET['year']) : null;
- $day = isset($_GET['day']) ? intval($_GET['day']) : null;
-
-
- $url = api_get_self().'?'.api_get_cidreq().'&month='.$month.'&year='.$year.'&day='.$day;
-
- $th .= Display::tag('th', Display::url(get_lang('StartTimeWindow'), $url.'&sort='.$sort_inverse.'&col=start'));
- $th .= Display::tag('th', Display::url(get_lang('EndTimeWindow'), $url.'&sort='.$sort_inverse.'&col=end'));
-
- if ((api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
- $th .= Display::tag('th', get_lang('Modify'));
- }
-
- echo Display::tag('tr', $th);
- $counter = 0;
- foreach ($agenda_items as $myrow) {
- $is_repeated = !empty($myrow['parent_event_id']);
-
- $class = 'row_even';
- if ($counter % 2) {
- $class = 'row_odd';
- }
- /* display: the icon, title, destinees of the item */
- echo '<tr class="'.$class.'">';
-
- //Title
- echo "<td>";
- $attach_icon = '';
-
- // attachment list
- $attachment_list = get_attachment($myrow['id']);
-
- if (!empty($attachment_list)) {
- $attach_icon = ' '.Display::return_icon('attachment.gif', get_lang('Attachment'));
- }
- $title_class = '';
- if (isset($myrow['visibility']) && $myrow['visibility'] == 0) {
- $title_class = 'invisible';
- }
-
- switch($myrow['calendar_type']) {
- case 'global':
- $icon_type = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22);
- echo $icon_type.' '.$myrow['title'].$attach_icon;
- break;
- case 'personal':
- $icon_type = Display::return_icon('user.png', get_lang(' '), array(), 22);
- echo $icon_type.' '.$myrow['title'].$attach_icon;
- break;
- case 'course':
- $icon_type = Display::return_icon('course.png',get_lang('Course'), array(), 22);
- $agenda_url = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?agenda_id='.$myrow['id'].'&action=view';
- echo Display::url($icon_type.' '.$myrow['title'].$attach_icon, $agenda_url, array('class' => $title_class));
- break;
- }
- echo '</td>';
-
- //Start date
- echo '<td>';
- if (!empty($myrow['start_date']) && $myrow['start_date'] != '0000-00-00 00:00:00') {
- echo api_format_date($myrow['start_date']);
- }
- echo '</td>';
-
- //End date
- echo '<td>';
- if (!empty($myrow['end_date']) && $myrow['end_date'] != '0000-00-00 00:00:00') {
- echo api_format_date($myrow['end_date']);
- }
- echo '</td>';
-
- /*Display: edit delete button (course admin only) */
- if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) && $myrow['calendar_type'] == 'course') {
- echo '<td align="center">';
- if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
-
- // a coach can only delete an element belonging to his session
- $mylink = api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&id='.$myrow['id'].'&sort='.$sort.'&col='.$col.'&';
-
- // edit
- echo '<a href="'.$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action=edit&id_attach='.$attachment_list['id'].'" title="'.get_lang("ModifyCalendarItem").'">';
- echo Display::return_icon('edit.png', get_lang('ModifyCalendarItem'),'',ICON_SIZE_SMALL)."</a>";
-
- echo '<a href="'.$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action=announce" title="'.get_lang("AddAnnouncement").'">';
- echo Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), array (),ICON_SIZE_SMALL)."</a> ";
-
- if ($myrow['visibility'] == 1) {
- $image_visibility = "visible";
- $text_visibility = get_lang("Hide");
- $next_action = 0;
- } else {
- $image_visibility = "invisible";
- $text_visibility = get_lang("Show");
- $next_action = 1;
- }
- echo '<a href="'.$mylink.api_get_cidreq().'&toolgroup='.Security::remove_XSS($_GET['toolgroup']).'&action=showhide&next_action='.$next_action.'" title="'.$text_visibility.'">'.Display::return_icon($image_visibility.'.png', $text_visibility,'',ICON_SIZE_SMALL).'</a> ';
- echo "<a href=\"".$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup'])."&action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."')) return false;\" title=\"".get_lang("Delete")."\"> ";
- echo Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL)." </a>";
- }
-
- $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'];
- //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
- //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
- //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
- 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('printer.png', get_lang('Print'),'',ICON_SIZE_SMALL).'</a> ';
- echo '</td>';
- } else {
- if ($is_repeated && (api_is_allowed_to_edit(false,true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() )) {
- echo '<td align="center">';
- echo get_lang('RepeatedEvent'),' <a href="',api_get_self(),'?',api_get_cidreq(),'&agenda_id=',$myrow['parent_event_id'],'" alt="',get_lang('RepeatedEventViewOriginalEvent'),'">',get_lang('RepeatedEventViewOriginalEvent'),'</a>';
- echo '</td>';
- }
- if ((api_is_allowed_to_edit(false,true) || (api_get_course_setting('allow_user_edit_agenda')&& !api_is_anonymous()) ) && ($myrow['calendar_type'] == 'personal' OR $myrow['calendar_type'] == 'global') ) {
- echo '<td align="center">';
- echo '</td>';
- }
- }
- $counter++;
- echo "</tr>";
- } // end while ($myrow=Database::fetch_array($result))
- echo "</table><br /><br />";
- }
-
- if(!empty($event_list)) {
- $event_list=api_substr($event_list,0,-1);
- } else {
- $event_list='0';
- }
- echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"$event_list\" /></form>";
- // closing the layout table
- echo "</td>",
- "</tr>",
- "</table>";
- }
- /**
- * Show a list with all the attachments according to the post's id
- * @param the post's id
- * @return array with the post info
- * @author Christian Fasanando
- * @version November 2008, dokeos 1.8.6
- */
- function get_attachment($agenda_id, $course_id = null) {
- $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
- if (empty($course_id)) {
- $course_id = api_get_course_int_id();
- } else {
- $course_id = intval($course_id);
- }
- $agenda_id=Database::escape_string($agenda_id);
- $row=array();
- $sql = 'SELECT id,path, filename,comment FROM '. $agenda_table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.(int)$agenda_id.'';
- $result=Database::query($sql);
- if (Database::num_rows($result)!=0) {
- $row=Database::fetch_array($result);
- }
- return $row;
- }
- /**
- * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function display_one_agenda_item($agenda_id) {
- global $TABLEAGENDA;
- global $TABLE_ITEM_PROPERTY;
- global $select_month, $select_year;
- global $DaysShort, $DaysLong, $MonthsLong;
- global $is_courseAdmin;
- global $dateFormatLong, $timeNoSecFormat, $charset;
- // getting the name of the groups
- $group_names = get_course_groups();
-
- $agenda_id = intval($agenda_id);
- if (!(api_is_allowed_to_edit(false,true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
- $visibility_condition = " AND ip.visibility='1' ";
- }
-
- $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
- WHERE agenda.id = ip.ref
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- $visibility_condition
- AND agenda.id='$agenda_id'";
-
- $result=Database::query($sql);
- $number_items=Database::num_rows($result);
- $myrow = Database::fetch_array($result,'ASSOC'); // there should be only one item so no need for a while loop
- $sql_rep = "SELECT * FROM $TABLEAGENDA WHERE id = $agenda_id AND parent_event_id IS NOT NULL AND parent_event_id !=0";
- $res_rep = Database::query($sql_rep);
- $repeat = false;
- $repeat_id = 0;
- if (Database::num_rows($res_rep) > 0) {
- $repeat=true;
- $row_rep = Database::fetch_array($res_rep);
- $repeat_id = $row_rep['parent_event_id'];
- }
- // DISPLAY: NO ITEMS
- if ($number_items==0) {
- Display::display_warning_message(get_lang("NoAgendaItems"));
- return false;
- }
- // DISPLAY: THE ITEMS
- echo "<table id=\"data_table\" class=\"data_table\">";
- // DISPLAY : the icon, title, destinees of the item
- $myrow["start_date"] = api_get_local_time($myrow["start_date"]);
- // highlight: if a date in the small calendar is clicked we highlight the relevant items
- $db_date = (int)api_format_date($myrow["start_date"], "%d").intval(api_format_date($myrow["start_date"], "%m")).api_format_date($myrow["start_date"], "%Y");
- if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
- if ($myrow['visibility']=='0') {
- $style="data_hidden";
- $stylenotbold="datanotbold_hidden";
- $text_style="text_hidden";
- } else {
- $style="data";
- $stylenotbold="datanotbold";
- $text_style="text";
- }
- } else {
- $style="datanow";
- $stylenotbold="datanotboldnow";
- $text_style="textnow";
- }
- echo Display::tag('h2', $myrow['title']);
- echo "<tr>";
-
- if (api_is_allowed_to_edit(false,true)) {
- if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
-
- // a coach can only delete an element belonging to his session
- // DISPLAY: edit delete button (course admin only)
- $export_icon = '../img/export.png';
- $export_icon_low = '../img/export_low_fade.png';
- $export_icon_high = '../img/export_high_fade.png';
-
- echo '<th style="text-align:right">';
- if (!$repeat && api_is_allowed_to_edit(false,true)) {
- // edit
- $mylink = api_get_self()."?".api_get_cidreq()."&origin=".Security::remove_XSS($_GET['origin'])."&id=".$myrow['id'];
- if (!empty($_GET['agenda_id'])) {
- // rather ugly hack because the id parameter is already set above but below we set it again
- $mylink .= '&agenda_id='.Security::remove_XSS($_GET['agenda_id']).'&id='.Security::remove_XSS($_GET['agenda_id']);
- }
- if ($myrow['visibility'] == 1) {
- $image_visibility="visible";
- $next_action = 0;
- } else {
- $image_visibility="invisible";
- $next_action = 1;
- }
-
- echo '<a href="'.$mylink.'&action=showhide&next_action='.$next_action.'">'.Display::return_icon($image_visibility.'.png', get_lang('Visible'),'',ICON_SIZE_SMALL).'</a>';
-
- echo "<a href=\"".$mylink."&action=edit\">",
- Display::return_icon('edit.png', get_lang('ModifyCalendarItem'),'',ICON_SIZE_SMALL), "</a>",
- "<a href=\"".$mylink."&action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."')) return false;\">",
- Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL),"</a>";
-
- }
- $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'];
- //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
- //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
- //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
- echo '<a href="javascript: void(0);" onclick="javascript:win_print=window.open(\'print.php?id='.$myrow['id'].'\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">'.Display::return_icon('printer.png', get_lang('Print'),'',ICON_SIZE_SMALL).'</a> ';
- echo "</th>";
- }
- }
-
- // title
- echo "<tr class='row_odd'>";
- echo '<td colspan="2">'.get_lang("StartTime").": ";
- echo api_format_date($myrow['start_date']);
- echo "</td>";
- echo "</td>";
- echo "<tr class='row_odd'>";
- echo '<td colspan="2">'.get_lang("EndTime").": ";
- echo api_convert_and_format_date($myrow['end_date']);
- echo "</td>";
-
- // Content
- $content = $myrow['content'];
- $content = make_clickable($content);
- $content = text_filter($content);
- echo '<tr class="row_even">';
- echo '<td '.(api_is_allowed_to_edit()?'colspan="3"':'colspan="2"'). '>';
- echo $content;
- echo '</td></tr>';
-
- //Attachments
- $attachment_list = get_attachment($agenda_id);
-
- if (!empty($attachment_list)) {
- echo '<tr class="row_even"><td colspan="2">';
- $realname=$attachment_list['path'];
- $user_filename=$attachment_list['filename'];
- $full_file_name = 'download.php?file='.$realname;
- echo Display::return_icon('attachment.gif',get_lang('Attachment'));
- echo '<a href="'.$full_file_name.'"> '.$user_filename.'</a>';
- if (api_is_allowed_to_edit()) {
- echo ' <a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&action=delete_attach&id_attach='.$attachment_list['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a><br />';
- }
- echo '<br /><span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
- echo '</td></tr>';
- }
-
- // the message has been sent to
- echo '<tr>';
- echo "<td class='announcements_datum'>".get_lang("SentTo").": ";
- $sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
- $sent_to_form=sent_to_form($sent_to);
- echo $sent_to_form;
- echo "</td></tr>";
-
- if ($repeat) {
- echo '<tr>';
- echo '<td colspan="2">';
- echo get_lang('RepeatedEvent').' <a href="',api_get_self(),'?',api_get_cidreq(),'&agenda_id=',$repeat_id,'" alt="',get_lang('RepeatedEventViewOriginalEvent'),'">',get_lang('RepeatedEventViewOriginalEvent'),'</a>';
- echo '</td>';
- echo '</tr>';
- }
-
- /* Added resources */
- if (check_added_resources("Agenda", $myrow["id"])) {
- echo "<tr><td colspan='3'>";
- echo "<i>".get_lang("AddedResources")."</i><br/>";
- if ($myrow['visibility'] == 0 ) {
- $addedresource_style="invisible";
- }
- display_added_resources("Agenda", $myrow["id"], $addedresource_style);
- echo "</td></tr>";
- }
- // closing the layout table
- echo "</td>",
- "</tr>",
- "</table>";
- }
- /**
- * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
- * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
- * we have to retrieve the information that is in the database and use this information in the forms.
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
- * agenda item.
- */
- function show_add_form($id = '') {
- global $MonthsLong;
- $htmlHeadXtra[] = to_javascript();
- // the default values for the forms
- if ($_GET['originalresource'] !== 'no') {
- $day = date('d');
- $month = date('m');
- $year = date('Y');
- $hours = 9;
- $minutes= '00';
- $end_day = date('d');
- $end_month = date('m');
- $end_year = date('Y');
- $end_hours = 17;
- $end_minutes= '00';
- $repeat = false;
- } else {
- // we are coming from the resource linker so there might already have been some information in the form.
- // When we clicked on the button to add resources we stored every form information into a session and now we
- // are doing the opposite thing: getting the information out of the session and putting it into variables to
- // display it in the forms.
- $form_elements=$_SESSION['formelements'];
- $day=$form_elements['day'];
- $month=$form_elements['month'];
- $year=$form_elements['year'];
- $hours=$form_elements['hour'];
- $minutes=$form_elements['minutes'];
- $end_day=$form_elements['end_day'];
- $end_month=$form_elements['end_month'];
- $end_year=$form_elements['end_year'];
- $end_hours=$form_elements['end_hours'];
- $end_minutes=$form_elements['end_minutes'];
- $title=$form_elements['title'];
- $content=$form_elements['content'];
- $id=$form_elements['id'];
-
- $to=$form_elements['to'];
- $repeat = $form_elements['repeat'];
- }
- // switching the send to all/send to groups/send to users
- if (isset($_POST['To']) && $_POST['To']) {
- $day = $_POST['fday'];
- $month = $_POST['fmonth'];
- $year = $_POST['fyear'];
- $hours = $_POST['fhour'];
- $minutes = $_POST['fminute'];
- $end_day = $_POST['end_fday'];
- $end_month = $_POST['end_fmonth'];
- $end_year = $_POST['end_fyear'];
- $end_hours = $_POST['end_fhour'];
- $end_minutes = $_POST['end_fminute'];
- $title = $_POST['title'];
- $content = $_POST['content'];
- // the invisible fields
- $action = $_POST['action'];
- $id = $_POST['id'];
- $repeat = !empty($_POST['repeat'])?true:false;
- }
-
- $default_no_empty_end_date = 0;
-
- // if the id is set then we are editing an agenda item
- if (!empty($id)) {
- //echo "before get_agenda_item".$_SESSION['allow_individual_calendar'];
- $item_2_edit = get_agenda_item($id);
- $title = $item_2_edit['title'];
- $content= $item_2_edit['content'];
- // start date
- if ($item_2_edit['start_date'] != '0000-00-00 00:00:00') {
- $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']);
- list($datepart, $timepart) = split(" ", $item_2_edit['start_date']);
- list($year, $month, $day) = explode("-", $datepart);
- list($hours, $minutes, $seconds) = explode(":", $timepart);
- }
- // end date
- if ($item_2_edit['end_date'] != '0000-00-00 00:00:00') {
- $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']);
-
- list($datepart, $timepart) = split(" ", $item_2_edit['end_date']);
- list($end_year, $end_month, $end_day) = explode("-", $datepart);
-
- list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
- } elseif($item_2_edit['end_date'] == '0000-00-00 00:00:00') {
- $default_no_empty_end_date = 1;
- }
- // attachments
- edit_added_resources("Agenda", $id);
- $to=$item_2_edit['to'];
- }
- $content = stripslashes($content);
- $title = stripslashes($title);
- // we start a completely new item, we do not come from the resource linker
- if (isset($_GET['originalresource']) && $_GET['originalresource']!=="no" and $_GET['action']=="add") {
- $_SESSION["formelements"]=null;
- unset_session_resources();
- }
- $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
- ?>
- <!-- START OF THE FORM -->
- <form enctype="multipart/form-data" action="<?php echo api_get_self().'?origin='.$origin.'&'.api_get_cidreq()."&sort=asc&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action='.Security::remove_XSS($_GET['action']); ?>" method="post" name="new_calendar_item">
- <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
- <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo $_GET['action']; ?>" />
- <input type="hidden" name="id_attach" value="<?php echo isset($_REQUEST['id_attach']) ? intval($_REQUEST['id_attach']) : null; ?>" />
- <input type="hidden" name="sort" value="asc" />
- <input type="hidden" name="submit_event" value="ok" />
- <?php
- // The form title
- if (isset($id) AND $id<>'') {
- $form_title = get_lang('ModifyCalendarItem');
- } else {
- $form_title = get_lang('AddCalendarItem');
- }
- echo '<legend>'.$form_title.'</legend>';
-
- // the title of the agenda item
- echo '<div class="row">
- <div class="label">
- <span class="form_required">*</span>'.get_lang('ItemTitle').'
- </div>
- <div class="formw">
- <div id="err_title" style="display:none;color:red"></div>
- <input type="text" id="agenda_title" size="50" name="title" value="';
- if (isset($title)) echo $title;
- echo '" />
- </div>
- </div>';
-
-
-
- // selecting the users / groups
- $group_id = api_get_group_id();
- if (isset ($group_id) && !empty($group_id)) {
- echo '<input type="hidden" name="selected_form[0]" value="GROUP:'.$group_id.'"/>' ;
- echo '<input type="hidden" name="To" value="true"/>' ;
- } else {
- echo '<div class="row">
- <div class="label">
- '.Display::return_icon('group.png', get_lang('To'), array ('align' => 'absmiddle'),ICON_SIZE_SMALL).' '.get_lang('To').'</a>
- </div>
- <div class="formw">';
- /*if ((isset($_GET['id']) && $to=='everyone') || !isset($_GET['id'])) {
- echo get_lang('Everybody').' ';
- }*/
- show_to_form($to);
- /*if (isset($_GET['id']) && $to!='everyone') {
- echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
- }*/
- echo '</div>
- </div>';
- }
-
- // start date and time
- echo '<div class="row">';
- echo '<div class="label">'.get_lang('StartDate').'</div>
- <div class="formw">
- <div id="err_date" style="display:none;color:red"></div>
- <div id="err_start_date" style="display:none;color:red"></div>';
- ?>
- <select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
- <?php
- // small loop for filling all the dates
- // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
- foreach (range(1, 31) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- // the current day is indicated with [] around the date
- if ($value==$day) {
- echo "<option value=\"".$value."\" selected> ".$i." </option>";
- } else {
- echo "<option value=\"$value\">$i</option>";
- }
- }
- ?>
- </select>
- <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
- <?php
- for ($i=1; $i<=12; $i++) {
- // values have to have double digits
- if ($i<=9) {
- $value="0".$i;
- } else {
- $value=$i;
- }
- if ($value==$month) {
- echo "<option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>";
- } else {
- echo "<option value=\"".$value."\">".$MonthsLong[$i-1]."</option>";
- }
- } ?>
- </select>
- <select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
- <option value="<?php echo ($year-1); ?>"><?php echo ($year-1); ?></option>
- <option value="<?php echo $year; ?>" selected="selected"><?php echo $year; ?></option>
- <?php
- for ($i=1; $i<=5; $i++) {
- $value=$year+$i;
- echo "<option value=\"$value\">$value</option>";
- } ?>
- </select>
- <a href="javascript:openCalendar('new_calendar_item', 'f')">
- <?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?>
- </a>
-
- <?php echo get_lang('StartTime').": "; ?>
- <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
- <!-- <option value="--">--</option> -->
- <?php
- foreach (range(0, 23) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- // the current hour is indicated with [] around the hour
- if ($hours==$value) {
- echo "<option value=\"".$value."\" selected> ".$value." </option>";
- } else {
- echo "<option value=\"$value\">$value</option>";
- }
- } ?>
- </select>
- <select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
- <!-- <option value="<?php echo $minutes ?>"><?php echo $minutes; ?></option> -->
- <!-- <option value="--">--</option> -->
- <?php
- foreach (range(0, 59) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- if ($minutes == $value) {
- echo "<option value=\"".$value."\" selected> ".$value." </option>";
- } else {
- echo "<option value=\"$value\">$value</option>";
- }
- } ?>
- </select>
- <?php
- echo ' </div>
- </div>';
-
- echo '<script>
- $(function() {
- $("#empty_end_date").click(function(){
- if ($("#empty_end_date").is(":checked")) {
- $("#end_date_span").hide();
- } else {
- $("#end_date_span").show();
- }
- });';
- if (isset($item_2_edit['end_date']) && $item_2_edit['end_date'] == '0000-00-00 00:00:00') {
- echo '$("#end_date_span").hide();';
- } echo '
- });
- </script>';
- // end date and time
- echo '<span id="end_date_span">';
- echo '<div class="row">
- <div class="label">
- '.get_lang('EndDate').'
- </div>
- <div class="formw">
- <div id="err_end_date" style="display:none;color:red"></div>';
- ?>
-
- <select id="end_fday" name="end_fday">
- <?php
- // small loop for filling all the dates
- // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
- foreach (range(1, 31) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- // the current day is indicated with [] around the date
- if ($value==$end_day)
- { echo "<option value=\"".$value."\" selected> ".$i." </option>";}
- else
- { echo "<option value=\"".$value."\">".$i."</option>"; }
- }?>
- </select>
- <!-- month: january -> december -->
- <select id="end_fmonth" name="end_fmonth">
- <?php
- foreach (range(1, 12) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- if ($value==$end_month)
- { echo "<option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>"; }
- else
- { echo "<option value=\"".$value."\">".$MonthsLong[$i-1]."</option>"; }
- }?>
- </select>
- <select id="end_fyear" name="end_fyear">
- <option value="<?php echo ($end_year-1) ?>"><?php echo ($end_year-1) ?></option>
- <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
- <?php
- for ($i=1; $i<=5; $i++) {
- $value=$end_year+$i;
- echo "<option value=\"$value\">$value</option>";
- } ?>
- </select>
- <a href="javascript:openCalendar('new_calendar_item', 'end_f')">
- <?php echo Display::span(Display::return_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')), array ('id'=>'end_date_calendar_icon')); ?>
- </a>
- <?php echo get_lang('EndTime').": "; ?>
- <select id="end_fhour" name="end_fhour">
- <!-- <option value="--">--</option> -->
- <?php
- foreach (range(0, 23) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- // the current hour is indicated with [] around the hour
- if ($end_hours==$value)
- { echo "<option value=\"".$value."\" selected> ".$value." </option>"; }
- else
- { echo "<option value=\"".$value."\"> ".$value." </option>"; }
- } ?>
- </select>
- <select id="end_fminute" name="end_fminute">
- <!-- <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option> -->
- <!-- <option value="--">--</option> -->
- <?php
- foreach (range(0, 59) as $i) {
- // values have to have double digits
- //$value = ($i <= 9 ? '0'.$i : $i );
- $value = ($i <= 9 ? '0'.$i : $i );
- if ($end_minutes == $value) {
- echo "<option value=\"".$value."\" selected> ".$value." </option>";
- } else {
- echo "<option value=\"$value\">$value</option>";
- }
- } ?>
- </select>
-
- <?php
- echo ' </div>
- </div> </span>';
-
-
- // Repeating the calendar item
- if (empty($id)) {
- //only show repeat fields when adding, not for editing an calendar item
- echo '<div class="row">
- <div class="label">
- </div>
- <div class="formw">
- <a href="javascript://" onclick="return plus_repeated_event();"><span id="plus2">
- <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> '.get_lang('RepeatEvent').'</span>
- </a>';
- ?>
- <table id="options2" style="display: none;">
- <tr>
- <td><input id="repeat_id" type="checkbox" name="repeat" <?php echo ($repeat?'checked="checked"':'');?>/>
- <label for="repeat_id"><?php echo get_lang('RepeatEvent');?></label></td>
- <td>
- </td>
- </tr>
- <tr>
- <td><label for="repeat_type"><?php echo get_lang('RepeatType');?></label></td>
- <td>
- <select name="repeat_type">
- <option value="daily"><?php echo get_lang('RepeatDaily');?></option>
- <option value="weekly"><?php echo get_lang('RepeatWeekly');?></option>
- <option value="monthlyByDate"><?php echo get_lang('RepeatMonthlyByDate');?></option>
- <!--option value="monthlyByDay"><?php echo get_lang('RepeatMonthlyByDay');?></option>
- <option value="monthlyByDayR"><?php echo get_lang('RepeatMonthlyByDayR');?></option-->
- <option value="yearly"><?php echo get_lang('RepeatYearly');?></option>
- </select>
- </td>
- </tr>
- <tr>
- <td><label for="repeat_end_day"><?php echo get_lang('RepeatEnd');?></label></td>
- <td>
- <select name="repeat_end_day">
- <?php
- // small loop for filling all the dates
- // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
-
- foreach (range(1, 31) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- // the current day is indicated with [] around the date
- if ($value==$end_day)
- { echo "<option value=\"".$value."\" selected> ".$i." </option>";}
- else
- { echo "<option value=\"".$value."\">".$i."</option>"; }
- }?>
- </select>
- <!-- month: january -> december -->
- <select name="repeat_end_month">
- <?php
- foreach (range(1, 12) as $i) {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- if ($value==$end_month+1)
- { echo '<option value="',$value,'" selected="selected">',$MonthsLong[$i-1],"</option>"; }
- else
- { echo '<option value="',$value,'">',$MonthsLong[$i-1],"</option>"; }
- }?>
- </select>
- <select name="repeat_end_year">
- <option value="<?php echo ($end_year-1) ?>"><?php echo ($end_year-1) ?></option>
- <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
- <?php
- for ($i=1; $i<=5; $i++) {
- $value=$end_year+$i;
- echo "<option value=\"$value\">$value</option>";
- } ?>
- </select>
- <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>
- </td>
- </tr>
- </table>
- <?php
- echo ' </div>
- </div>';
- }//only show repeat fields if adding, not if editing
-
- // the main area of the agenda item: the wysiwyg editor
- echo ' <div class="row">
- <div class="label" >
- <span class="form_required">*</span>'.get_lang('Description').'
- </div>
- <div class="formw">';
- /*require_once api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php";
- $oFCKeditor = new FCKeditor('content') ;
- $oFCKeditor->Width = '100%';
- $oFCKeditor->Height = '200';
- if(!api_is_allowed_to_edit(null,true)) {
- $oFCKeditor->ToolbarSet = 'AgendaStudent';
- } else {
- $oFCKeditor->ToolbarSet = 'Agenda';
- }
- $oFCKeditor->Value = $content;
- $return = $oFCKeditor->CreateHtml();
- echo $return;*/
- echo '<textarea cols="50" rows="4" name="content">'.$content.'</textarea>';
- echo '</div>
- </div>';
- // the added resources
- /*echo ' <div class="row">
- <div class="label">
- '.get_lang('AddedResources').'
- </div>
- <div class="formw">';
- if ($_SESSION['allow_individual_calendar']=='show')
- show_addresource_button('onclick="selectAll(this.form.elements[6],true)"');
- else
- show_addresource_button();
- $form_elements=$_SESSION['formelements'];
- echo display_resources(0);
- $test=$_SESSION['addedresource'];
- echo ' </div>
- </div>';
- */
- // File attachment
- echo ' <div class="row">
- <div class="label"><label for="file_name">'.get_lang('AddAnAttachment').' </label></div>
- <div class="formw">
- <input type="file" name="user_upload"/> '.get_lang('Comment').' <input name="file_comment" type="text" size="20" />
- </div>
- </div>';
-
- // the submit button for storing the calendar item
- echo ' <div class="row">
- <div class="label">
- </div>
- <div class="formw">';
- if(isset($_GET['id']) ) {
- $class='save';
- $text=get_lang('ModifyEvent');
- } else {
- $class='add';
- $text=get_lang('AgendaAdd');
- }
- echo '<button class="'.$class.'" type="button" name="name" onclick="selectAll(document.getElementById(\'selected_form\'),true)">'.$text.'</button>';
- echo ' </div>
- </div>';
- ?>
- </form>
- <?php
- }
- function get_agendaitems($month, $year) {
- $items = array ();
- $month = Database::escape_string($month);
- $year = Database::escape_string($year);
- //databases of the courses
- $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
- $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $course_info = api_get_course_info();
- $group_memberships = GroupManager :: get_group_ids($course_info['real_id'], api_get_user_id());
- // if the user is administrator of that course we show all the agenda items
- if (api_is_allowed_to_edit(false,true)) {
- //echo "course admin";
- $sqlquery = "SELECT
- DISTINCT agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE agenda.id = item_property.ref
- AND MONTH(agenda.start_date)='".$month."'
- AND YEAR(agenda.start_date)='".$year."'
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND item_property.visibility='1'
- GROUP BY agenda.id
- ORDER BY start_date ";
- }
- // if the user is not an administrator of that course
- else
- {
- //echo "GEEN course admin";
- if (is_array($group_memberships) && count($group_memberships)>0)
- {
- $sqlquery = "SELECT
- agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE agenda.id = item_property.ref
- AND MONTH(agenda.start_date)='".$month."'
- AND YEAR(agenda.start_date)='".$year."'
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
- AND item_property.visibility='1'
- ORDER BY start_date ";
- }
- else
- {
- $sqlquery = "SELECT
- agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE agenda.id = item_property.ref
- AND MONTH(agenda.start_date)='".$month."'
- AND YEAR(agenda.start_date)='".$year."'
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0')
- AND item_property.visibility='1'
- ORDER BY start_date ";
- }
- }
- $mycourse = api_get_course_info();
- $result = Database::query($sqlquery);
-
- while ($item = Database::fetch_array($result)) {
- $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
- $agendaday = intval($agendaday_string);
- $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
- $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.$mycourse['id']."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
- $items[$agendaday][$item['start_time']] .= '<i>'.$time.'</i> <a href="'.$URL.'" title="'.$mycourse['name'].'">'.$mycourse['official_code'].'</a> '.$item['title'].'<br />';
- }
- // sorting by hour for every day
- $agendaitems = array ();
- while (list ($agendaday, $tmpitems) = each($items))
- {
- sort($tmpitems);
- while (list ($key, $val) = each($tmpitems))
- {
- $agendaitems[$agendaday] .= $val;
- }
- }
- return $agendaitems;
- }
- function display_upcoming_events() {
-
- $number_of_items_to_show = (int)api_get_setting('number_of_upcoming_events');
- //databases of the courses
- $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
- $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $mycourse = api_get_course_info();
- $myuser = api_get_user_info();
- $session_id = api_get_session_id();
-
- $course_id = $mycourse['real_id'];
- $group_memberships = GroupManager :: get_group_ids($mycourse['real_id'], $myuser['user_id']);
- // if the user is administrator of that course we show all the agenda items
- if (api_is_allowed_to_edit(false,true)) {
- //echo "course admin";
- $sqlquery = "SELECT
- DISTINCT agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE
- agenda.c_id = $course_id AND
- item_property.c_id = $course_id AND
- agenda.id = item_property.ref
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND item_property.visibility='1'
- AND agenda.start_date > NOW()
- AND session_id = '".$session_id."'
- GROUP BY agenda.id
- ORDER BY start_date ";
- }
- // if the user is not an administrator of that course
- else {
- //echo "GEEN course admin";
- if (is_array($group_memberships) and count($group_memberships)>0) {
- $sqlquery = "SELECT
- agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE
- agenda.c_id = $course_id AND
- item_property.c_id = $course_id AND
- agenda.id = item_property.ref
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND ( item_property.to_user_id='".$myuser['user_id']."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
- AND item_property.visibility='1'
- AND agenda.start_date > NOW()
- AND session_id = '".$session_id."'
- ORDER BY start_date ";
- } else {
- $sqlquery = "SELECT
- agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE
- agenda.c_id = $course_id AND
- item_property.c_id = $course_id AND
- agenda.id = item_property.ref
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND ( item_property.to_user_id='".$myuser['user_id']."' OR item_property.to_group_id='0')
- AND item_property.visibility='1'
- AND agenda.start_date > NOW()
- AND session_id = '".$session_id."'
- ORDER BY start_date ";
- }
- }
- $result = Database::query($sqlquery);
- $counter = 0;
-
- if (Database::num_rows($result) > 0 ) {
- echo '<h4>'.get_lang('UpcomingEvent').'</h4><br />';
- while ($item = Database::fetch_array($result,'ASSOC')) {
- if ($counter < $number_of_items_to_show) {
- echo api_get_local_time($item['start_date']),' - ',$item['title'],'<br />';
- $counter++;
- }
- }
- }
- }
- /**
- * This function calculates the startdate of the week (monday)
- * and the enddate of the week (sunday)
- * and returns it as an array
- * @todo check if this function is correct
- */
- function calculate_start_end_of_week($week_number, $year) {
- // determine the start and end date
- // step 1: we calculate a timestamp for a day in this week
- //@todo Why ($week_number - 1) ?
- //$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
- $random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week
- // step 2: we which day this is (0=sunday, 1=monday, ...)
- $number_day_in_week = date('w', $random_day_in_week);
- // step 3: we calculate the timestamp of the monday of the week we are in
- $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60);
- // step 4: we calculate the timestamp of the sunday of the week we are in
- $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600;
- // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
- $start_day = date('j', $start_timestamp);
- $start_month = date('n', $start_timestamp);
- $start_year = date('Y', $start_timestamp);
- $end_day = date('j', $end_timestamp);
- $end_month = date('n', $end_timestamp);
- $end_year = date('Y', $end_timestamp);
- $start_end_array['start']['day'] = $start_day;
- $start_end_array['start']['month'] = $start_month;
- $start_end_array['start']['year'] = $start_year;
- $start_end_array['end']['day'] = $end_day;
- $start_end_array['end']['month'] = $end_month;
- $start_end_array['end']['year'] = $end_year;
- return $start_end_array;
- }
- /**
- * Show the mini calendar of the given month
- */
- function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName) {
- global $DaysShort, $DaysLong, $course_path;
- global $MonthsLong;
- global $query;
- // timestamp of today
- $today = mktime();
- $nextday = $today + (24 * 60 * 60);
- $previousday = $today - (24 * 60 * 60);
- // the week number of the year
- $week_number = date("W", $today);
- // if we moved to the next / previous day we have to recalculate the $today variable
- if (isset($_GET['day'])) {
- $today = mktime(0, 0, 0, $month, $day, $year);
- $nextday = $today + (24 * 60 * 60);
- $previousday = $today - (24 * 60 * 60);
- $week_number = date("W", $today);
- }
- // calculating the start date of the week
- // the date of the monday of this week is the timestamp of today minus
- // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
- $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
- $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
- // we are loading all the calendar items of all the courses for today
- echo "<table class=\"data_table\">";
- // the forward and backwards url
- $course_code = isset($_GET['courseCode']) ? Security::remove_XSS($_GET['courseCode']) : null;
- $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday);
- $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday);
- // The title row containing the day
- echo "<tr>", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></th>", "<th>";
- echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
- echo "</th>";
- echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>";
- echo "</tr>";
-
- // From 0 to 5h
- $class = "class=\"row_even\"";
- echo "<tr $class>";
- echo ("<td valign=\"top\" width=\"75\">0:00 ".get_lang("HourShort")." - 4:30 ".get_lang("HourShort")."</td>");
- echo "<td $class valign=\"top\" colspan=\"2\">";
- for ($i = 0; $i < 10; $i ++) {
- if (isset($agendaitems[$i])) {
- if (is_array($agendaitems[$i])) {
- foreach ($agendaitems[$i] as $key => $value) {
- echo $value;
- }
- } else {
- echo $agendaitems[$i];
- }
- }
- }
- echo "</td>";
- echo "</tr>";
- // the rows for each half an hour
- for ($i = 10; $i < 48; $i ++) {
- if ($i % 2 == 0) {
- $class = "class=\"row_even\"";
- } else {
- $class = "class=\"row_odd\"";
- }
- echo "<tr $class>";
- echo "";
- if ($i % 2 == 0) {
- echo ("<td valign=\"top\" width=\"75\">". (($i) / 2)." ".get_lang("HourShort")." 00</td>");
- } else {
- echo ("<td valign=\"top\" width=\"75\">". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>");
- }
- echo "<td $class valign=\"top\" colspan=\"2\">";
- if (isset($agendaitems[$i])) {
- if (is_array($agendaitems[$i])) {
- foreach ($agendaitems[$i] as $key => $value) {
- echo $value;
- }
- } else {
- echo $agendaitems[$i];
- }
- }
- echo "</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- /**
- * Display the weekly view of the calendar
- */
- function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName) {
- global $DaysShort,$course_path;
- global $MonthsLong;
- // timestamp of today
- $today = time();
- $day_of_the_week = date("w", $today);
- $thisday_of_the_week = date("w", $today);
- // the week number of the year
- $week_number = date("W", $today);
- $thisweek_number = $week_number;
- // if we moved to the next / previous week we have to recalculate the $today variable
- if (!isset($_GET['week'])) {
- $week_number = date("W", $today);
- } else {
- $week_number = intval($_GET['week']);
- }
-
- // calculating the start date of the week
- // the date of the monday of this week is the timestamp of today minus
- // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
- $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
- $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
- //Using the same script to calculate the start/end of a week
- $start_end = calculate_start_end_of_week($week_number, $year);
- $timestamp_first_date_of_week = mktime(0, 0, 0, $start_end['start']['month'], $start_end['start']['day'], $start_end['start']['year']);
- $timestamp_last_date_of_week = mktime(0, 0, 0, $start_end['end']['month'], $start_end['end']['day'], $start_end['end']['year']);
- $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=". ($week_number -1);
- $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=". ($week_number +1);
- echo '<table class="data_table">';
- // The title row containing the the week information (week of the year (startdate of week - enddate of week)
- echo '<tr>';
- echo "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></th>";
- echo "<th colspan=\"5\">".get_lang("Week")." ".$week_number;
- 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).')';
- echo "</th>";
- echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>", "</tr>";
- // The second row containing the short names of the days of the week
- echo "<tr>";
- //Printing the week days
- // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
- $tmp_timestamp = $timestamp_first_date_of_week;
- for ($ii = 1; $ii < 8; $ii ++) {
- $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number));
- echo "<td class=\"weekdays\">";
- if ($is_today) {
- echo "<font color=#CC3300>";
- }
- echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
- if ($is_today) {
- echo "</font>";
- }
- echo "</td>";
- // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
- $array_tmp_timestamp[] = $tmp_timestamp;
- $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
- }
- echo "</tr>";
- // The table cells containing all the entries for that day
- echo "<tr>";
- $counter = 0;
- foreach ($array_tmp_timestamp as $key => $value) {
- if ($counter < 5) {
- $class = "class=\"days_week\"";
- } else {
- $class = "class=\"days_weekend\"";
- }
- if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number)) {
- $class = "class=\"days_today\"";
- }
- echo "<td ".$class.">";
- $data = isset($agendaitems[date('j', $value)]) ? $agendaitems[date('j', $value)] : null;
- echo "<span class=\"agendaitem\">".$data." </span> ";
- echo "</td>";
- $counter ++;
- }
- echo "</tr>";
- echo "</table>";
- }
- /**
- * Show the monthcalender of the given month
- */
- function get_day_agendaitems($courses_dbs, $month, $year, $day) {
- global $setting_agenda_link;
- $items = array ();
- // get agenda-items for every course
- //$query=Database::query($sql_select_courses);
- foreach ($courses_dbs as $key => $array_course_info) {
- //echo $array_course_info['db'];
- //databases of the courses
- $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
- $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- // getting all the groups of the user for the current course
- $group_memberships = GroupManager :: get_group_ids($array_course_info['real_id'], api_get_user_id());
- $course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info['code']);
-
-
- $start_filter = $year."-".$month."-".$day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
- $end_filter = $year."-".$month."-".$day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
-
-
- // if the user is administrator of that course we show all the agenda items
- if ($course_user_status == '1') {
- //echo "course admin";
- $sqlquery = "SELECT
- DISTINCT agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE agenda.id = item_property.ref
- AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND item_property.visibility='1'
- GROUP BY agenda.id
- ORDER BY start_date ";
- }
- // if the user is not an administrator of that course
- else {
- //echo "course admin";
- if (is_array($group_memberships) && count($group_memberships)>0) {
- $sqlquery = "SELECT
- agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE agenda.id = item_property.ref
- AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
- AND item_property.visibility='1'
- ORDER BY start_date ";
- } else {
- $sqlquery = "SELECT
- agenda.*, item_property.*
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." item_property
- WHERE agenda.id = item_property.ref
- AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
- AND item_property.tool='".TOOL_CALENDAR_EVENT."'
- AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0')
- AND item_property.visibility='1'
- ORDER BY start_date ";
- }
- }
- $result = Database::query($sqlquery);
- while ($item = Database::fetch_array($result)) {
- // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
- // we want to know for each agenda item for this day to wich halfhour it must be assigned
- $item['start_date'] = api_get_local_time($item['start_date']);
- $time_minute = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
- list ($datepart, $timepart) = explode(" ", $item['start_date']);
- list ($year, $month, $day) = explode("-", $datepart);
- list ($hours, $minutes, $seconds) = explode(":", $timepart);
- $halfhour =2* $hours;
- if ($minutes >= '30') {
- $halfhour = $halfhour +1;
- }
- if ($setting_agenda_link == 'coursecode') {
- $title=$array_course_info['title'];
- $agenda_link = cut($title,14,true);
- } else {
- $agenda_link = Display::return_icon('course_home.png',' ','',ICON_SIZE_SMALL);
- }
- $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.urlencode($array_course_info["code"])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
- $items[$halfhour][] .= "<i>$time_minute</i> <a href=\"$URL\" title=\"".$array_course_info['title']."\">".$agenda_link."</a> ".$item['title']."<br />";
- }
- }
- // sorting by hour for every day
- $agendaitems = array();
- while (list($agendaday, $tmpitems) = each($items)) {
- sort($tmpitems);
- while (list($key,$val) = each($tmpitems))
- {
- $agendaitems[$agendaday].=$val;
- }
- }
- return $agendaitems;
- }
- /**
- * Return agenda items of the week
- */
- function get_week_agendaitems($courses_dbs, $month, $year, $week = '') {
- global $setting_agenda_link;
- $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
- $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $items = array ();
- // The default value of the week
- if ($week == '') {
- $week_number = date("W", time());
- } else {
- $week_number = $week;
- }
- $start_end = calculate_start_end_of_week($week_number, $year);
- $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
- $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- // get agenda-items for every course
- foreach ($courses_dbs as $key => $array_course_info) {
- //databases of the courses
- $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
- $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- // getting all the groups of the user for the current course
- $group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], api_get_user_id());
-
- $user_course_status = CourseManager::get_user_in_course_status(api_get_user_id(),$array_course_info["code"]);
- // if the user is administrator of that course we show all the agenda items
- if ($user_course_status == '1') {
- //echo "course admin";
- $sqlquery = "SELECT
- DISTINCT a.*, i.*
- FROM ".$TABLEAGENDA." a,
- ".$TABLE_ITEMPROPERTY." i
- WHERE a.id = i.ref
- AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
- AND i.tool='".TOOL_CALENDAR_EVENT."'
- AND i.visibility='1'
- GROUP BY a.id
- ORDER BY a.start_date";
- }
- // if the user is not an administrator of that course
- else {
- //echo "GEEN course admin";
- if (is_array($group_memberships) && count($group_memberships)>0) {
- $sqlquery = "SELECT
- a.*, i.*
- FROM ".$TABLEAGENDA." a,
- ".$TABLE_ITEMPROPERTY." i
- WHERE a.id = i.ref
- AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
- AND i.tool='".TOOL_CALENDAR_EVENT."'
- AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") )
- AND i.visibility='1'
- ORDER BY a.start_date";
- } else {
- $sqlquery = "SELECT
- a.*, i.*
- FROM ".$TABLEAGENDA." a,
- ".$TABLE_ITEMPROPERTY." i
- WHERE a.id = i.ref
- AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
- AND i.tool='".TOOL_CALENDAR_EVENT."'
- AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id='0')
- AND i.visibility='1'
- ORDER BY a.start_date";
- }
- }
- //echo "<pre>".$sqlquery."</pre>";
- // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
- // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
- // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
- //var_dump($sqlquery);
- $result = Database::query($sqlquery);
- while ($item = Database::fetch_array($result)) {
- $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
- $agendaday = intval($agendaday_string);
- $start_time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
- $end_time = api_convert_and_format_date($item['end_date'], DATE_TIME_FORMAT_LONG);
- if ($setting_agenda_link == 'coursecode') {
- $title=$array_course_info['title'];
- $agenda_link = cut($title, 14, true);
- } else {
- $agenda_link = Display::return_icon('course_home.png',' ','',ICON_SIZE_SMALL);
- }
- $URL = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
- //Display the events in agenda
- $content = "<i>$start_time - $end_time</i> <a href=\"$URL\" title=\"".$array_course_info["title"]."\"> <br />".$agenda_link."</a>";
- $content .= "<div>".$item['title']."</div><br>";
- $items[$agendaday][$item['start_date']] .= $content;
- }
- }
- $agendaitems = array ();
- // sorting by hour for every day
- while (list ($agendaday, $tmpitems) = each($items)) {
- sort($tmpitems);
- while (list ($key, $val) = each($tmpitems)) {
- $agendaitems[$agendaday] .= $val;
- }
- }
- return $agendaitems;
- }
- /**
- * Get repeated events of a course between two dates (timespan of a day).
- * Returns an array containing the events
- * @param string Course info array (as returned by api_get_course_info())
- * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
- * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
- * @param array A set of parameters to alter the SQL query
- * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
- */
- function get_repeated_events_day_view($course_info,$start=0,$end=0,$params)
- {
- $events = array();
- //initialise all values
- $y=0;
- $m=0;
- $d=0;
- //block $end if higher than 2038 -- PHP doesn't go past that
- if($end>2145934800){$end = 2145934800;}
- if($start == 0 or $end == 0)
- {
- $y=date('Y');
- $m=date('m');
- $d=date('j');
- }
- if($start==0)
- {
- $start = mktime(0,0,0,$m,$d,$y);
- }
- $db_start = date('Y-m-d H:i:s',$start);
- if($end==0)
- {
- $end = mktime(23,59,59,$m,$d,$y);
- }
- //$db_end = date('Y-m-d H:i:s',$end);
- $t_cal = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']);
- $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
- $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
- $sql = "SELECT c.id, c.title, c.content, " .
- " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
- " cr.cal_type, cr.cal_end " .
- " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
- " WHERE cr.cal_end >= $start " .
- " AND cr.cal_id = c.id " .
- " AND item_property.ref = c.id ".
- " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
- " AND c.start_date <= '$db_start' "
- .(!empty($params['conditions'])?$params['conditions']:'')
- .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
- .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- while($row = Database::fetch_array($res))
- {
- $orig_start = $row['orig_start'];
- $orig_end = $row['orig_end'];
- $repeat_type = $row['cal_type'];
- switch($repeat_type)
- {
- case 'daily':
- //we are in the daily view, so if this element is repeated daily and
- //the repetition is still active today (which is a condition of the SQL query)
- //then the event happens today. Just build today's timestamp for start and end
- $time_orig_h = date('H',$orig_start);
- $time_orig_m = date('i',$orig_start);
- $time_orig_s = date('s',$orig_start);
- $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
- $span = $orig_end - $orig_start; //total seconds between start and stop of original event
- $current_start =$start + $int_time; //unixtimestamp start of today's event
- $current_stop = $start+$int_time+$span; //unixtimestamp stop of today's event
- $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
- break;
- case 'weekly':
- $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/W/j/N/G/i/s',$end);
- list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))) && ($dw_orig == $dw_now))
- { //if the event is after the original (at least one week) and the day of the week is the same
- $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
- 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);
- $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']);
- }
- break;
- case 'monthlyByDate':
- $time_orig = date('Y/n/j/G/i/s',$orig_start);
- list($y_orig,$m_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/j/G/i/s',$end);
- list($y_now,$m_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($d_orig == $d_now))
- {
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
- $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']);
- }
- break;
- case 'monthlyByDayR':
- //not implemented yet
- break;
- case 'monthlyByDay':
- //not implemented yet
- break;
- case 'yearly':
- $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
- list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/j/z/G/i/s',$end);
- list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- if(($y_now>$y_orig) && ($dy_orig == $dy_now))
- {
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- 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);
- $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']);
- }
- break;
- default:
- break;
- }
- }
- }
- return $events;
- }
- /**
- * (This function is not been use in the code)
- * Get repeated events of a course between two dates (timespan of a week).
- * Returns an array containing the events
- * @param string Course info array (as returned by api_get_course_info())
- * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
- * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
- * @param array A set of parameters to alter the SQL query
- * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
- */
- function get_repeated_events_week_view($course_info,$start=0,$end=0,$params)
- {
- $events = array();
- //block $end if higher than 2038 -- PHP doesn't go past that
- if($end>2145934800){$end = 2145934800;}
- //initialise all values
- $y=0;
- $m=0;
- $d=0;
- if($start == 0 or $end == 0)
- {
- $time = time();
- $dw = date('w',$time);
- $week_start = $time - (($dw-1)*86400);
- $y = date('Y',$week_start);
- $m = date('m',$week_start);
- $d = date('j',$week_start);
- $w = date('W',$week_start);
- }
- if($start==0)
- {
- $start = mktime(0,0,0,$m,$d,$y);
- }
- $db_start = date('Y-m-d H:i:s',$start);
- if($end==0)
- {
- $end = $start+(86400*7)-1; //start of week, more 7 days, minus 1 second to get back to the previoyus day
- }
- //$db_end = date('Y-m-d H:i:s',$end);
- $t_cal = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']);
- $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
- $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
- $sql = "SELECT c.id, c.title, c.content, " .
- " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
- " cr.cal_type, cr.cal_end " .
- " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
- " WHERE cr.cal_end >= $start " .
- " AND cr.cal_id = c.id " .
- " AND item_property.ref = c.id ".
- " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
- " AND c.start_date <= '$db_start' "
- .(!empty($params['conditions'])?$params['conditions']:'')
- .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
- .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- while($row = Database::fetch_array($res))
- {
- $orig_start = $row['orig_start'];
- $orig_end = $row['orig_end'];
- $repeat_type = $row['cal_type'];
- switch($repeat_type)
- {
- case 'daily':
- $time_orig_h = date('H',$orig_start);
- $time_orig_m = date('i',$orig_start);
- $time_orig_s = date('s',$orig_start);
- $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
- $span = $orig_end - $orig_start; //total seconds between start and stop of original event
- for($i=0;$i<7;$i++)
- {
- $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event
- $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event
- $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
- }
- break;
- case 'weekly':
- $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/W/j/N/G/i/s',$end);
- list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))))
- { //if the event is after the original (at least one week) and the day of the week is the same
- $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
- 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);
- $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']);
- }
- break;
- case 'monthlyByDate':
- $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/W/j/G/i/s',$end);
- list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
- if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($start<$event_repetition_time && $event_repetition_time<$end))
- { //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
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
- $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']);
- }
- break;
- case 'monthlyByDayR':
- //not implemented yet
- break;
- case 'monthlyByDay':
- //not implemented yet
- break;
- case 'yearly':
- $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
- list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/j/z/G/i/s',$end);
- list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
- if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end)))
- {
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- 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);
- $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']);
- }
- break;
- default:
- break;
- }
- }
- }
- return $events;
- }
- /**
- * Get repeated events of a course between two dates (timespan of a month).
- * Returns an array containing the events
- * @param string Course info array (as returned by api_get_course_info())
- * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
- * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
- * @param array A set of parameters to alter the SQL query
- * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
- */
- function get_repeated_events_month_view($course_info,$start=0,$end=0,$params)
- {
- $events = array();
- //block $end if higher than 2038 -- PHP doesn't go past that
- if($end>2145934800){$end = 2145934800;}
- //initialise all values
- $y=0;
- $m=0;
- $d=0;
- if($start == 0 or $end == 0)
- {
- $time = time();
- $y = date('Y');
- $m = date('m');
- }
- if($start==0)
- {
- $start = mktime(0,0,0,$m,1,$y);
- }
- $db_start = date('Y-m-d H:i:s',$start);
- if($end==0)
- {
- if($m==12)
- {
- $end = mktime(0,0,0,1,1,$y+1)-1; //start of next month, minus 1 second to get back to the previoyus day
- }
- else
- {
- $end = mktime(0,0,0,$m+1,1,$y)-1;
- }
- }
- //$db_end = date('Y-m-d H:i:s',$end);
- $t_cal = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']);
- $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
- $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
- $sql = "SELECT c.id, c.title, c.content, " .
- " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
- " cr.cal_type, cr.cal_end " .
- " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
- " WHERE cr.cal_end >= $start " .
- " AND cr.cal_id = c.id " .
- " AND item_property.ref = c.id ".
- " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
- " AND c.start_date <= '$db_start' "
- .(!empty($params['conditions'])?$params['conditions']:'')
- .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
- .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- while($row = Database::fetch_array($res))
- {
- $orig_start = $row['orig_start'];
- $orig_end = $row['orig_end'];
- $repeat_type = $row['cal_type'];
- switch($repeat_type)
- {
- case 'daily':
- $time_orig_h = date('H',$orig_start);
- $time_orig_m = date('i',$orig_start);
- $time_orig_s = date('s',$orig_start);
- $month_last_day = date('d',$end);
- $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
- $span = $orig_end - $orig_start; //total seconds between start and stop of original event
- for($i=0;$i<$month_last_day;$i++)
- {
- $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event
- $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event
- $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
- }
- break;
- case 'weekly':
- //A weekly repeated event is very difficult to catch in a month view,
- //because weeks start before or at the same time as the first day of the month
- //The same can be said for the end of the month.
- // The idea is thus to get all possible events by enlarging the scope of
- // the month to get complete weeks covering the complete month, and then take out
- // the events that start before the 1st ($start) or after the last day of the month ($end)
- $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
- 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);
- $time_now = date('Y/n/W/j/N/G/i/s',$end);
- list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- $month_first_week = date('W',$start);
- $month_last_week = date('W',$end);
- if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))
- { //if the event is after the original (at least one week) and the day of the week is the same
- for($i=$month_first_week;$i<=$month_last_week;$i++)
- {
- //the "day of the week" of repetition is the same as the $dw_orig,
- //so to get the "day of the month" from the "day of the week", we have
- //to get the first "day of the week" for this week and add the number
- //of days (in seconds) to reach the $dw_orig
- //example: the first week spans between the 28th of April (Monday) to the
- // 4th of May (Sunday). The event occurs on the 2nd day of each week.
- // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
- // We want to get all of these, and then reject 29/4 because it is out
- // of the month itself.
- //First, to get the start time of the first day of the month view (even if
- // the day is from the past month), we get the month start date (1/5) and
- // see which day of the week it is, and subtract the number of days necessary
- // to get back to the first day of the week.
- $month_first_day_weekday = date('N',$start);
- $first_week_start = $start - (($month_first_day_weekday-1)*86400);
- //Second, we add the week day of the original event, so that we have an
- // absolute time that represents the first repetition of the event in
- // our 4- or 5-weeks timespan
- $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig;
- //Third, we start looping through the repetitions and see if they are between
- // $start and $end
- for($i = $first_event_repeat_start; $i<=$end; $i+=604800)
- {
- if($start<$i && $i<$end)
- {
- list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i));
- $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']);
- }
- }
- }
- }
- break;
- case 'monthlyByDate':
- $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/W/j/G/i/s',$end);
- list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
- if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig)))
- { //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
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
- $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']);
- }
- break;
- case 'monthlyByDayR':
- //not implemented yet
- break;
- case 'monthlyByDay':
- //not implemented yet
- break;
- case 'yearly':
- $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
- list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/j/z/G/i/s',$end);
- list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
- if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end)))
- {
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- 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);
- $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']);
- }
- break;
- default:
- break;
- }
- }
- }
- return $events;
- }
- /**
- * Get repeated events of a course between two dates (1 year timespan). Used for the list display.
- * 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)
- * Returns an array containing the events
- * @param string Course info array (as returned by api_get_course_info())
- * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
- * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
- * @param array A set of parameters to alter the SQL query
- * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
- */
- function get_repeated_events_list_view($course_info,$start=0,$end=0,$params)
- {
- $events = array();
- //block $end if higher than 2038 -- PHP doesn't go past that
- if($end>2145934800){$end = 2145934800;}
- //initialise all values
- $y=0;
- $m=0;
- $d=0;
- if(empty($start) or empty($end))
- {
- $time = time();
- $y = date('Y');
- $m = date('m');
- }
- if(empty($start))
- {
- $start = mktime(0, 0, 0, $m, 1, $y);
- }
- $db_start = date('Y-m-d H:i:s', $start);
- if(empty($end))
- {
- $end = mktime(0, 0, 0, 1, 1, 2037);
- }
- //$db_end = date('Y-m-d H:i:s',$end);
- $t_cal = Database::get_course_table(TABLE_AGENDA,$course_info['dbName']);
- $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
- $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
- $sql = "SELECT c.id, c.title, c.content, " .
- " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
- " cr.cal_type, cr.cal_end " .
- " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
- " WHERE cr.cal_end >= $start " .
- " AND cr.cal_id = c.id " .
- " AND item_property.ref = c.id ".
- " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
- " AND c.start_date <= '$db_start' "
- .(!empty($params['conditions'])?$params['conditions']:'')
- .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
- .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- while($row = Database::fetch_array($res))
- {
- $orig_start = $row['orig_start'];
- $orig_end = $row['orig_end'];
- $repeat_type = $row['cal_type'];
- $repeat_end = $row['cal_end'];
- switch($repeat_type)
- {
- case 'daily':
- $time_orig_h = date('H',$orig_start);
- $time_orig_m = date('i',$orig_start);
- $time_orig_s = date('s',$orig_start);
- $span = $orig_end - $orig_start; //total seconds between start and stop of original event
- for($i=$orig_start+86400;($i<$end && $i<=$repeat_end);$i+=86400)
- {
- $current_start = $i; //unixtimestamp start of today's event
- $current_stop = $i + $span; //unixtimestamp stop of today's event
- $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
- }
- break;
- case 'weekly':
- //A weekly repeated event is very difficult to catch in a month view,
- // because weeks start before or at the same time as the first day of the month
- //The same can be said for the end of the month.
- // The idea is thus to get all possible events by enlarging the scope of
- // the month to get complete weeks covering the complete month, and then take out
- // the events that start before the 1st ($start) or after the last day of the month ($end)
- $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
- 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);
- $time_now = date('Y/n/W/j/N/G/i/s',$end);
- list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- if($w_now==52)
- {
- ++$y_now;
- $w_now=1;
- }
- else
- {
- ++$w_now;
- }
- $month_first_week = date('W',$start);
- $total_weeks = ((date('Y',$end)-$y_orig)-1)*52;
- $month_last_week = $month_first_week + $total_weeks;
- if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))
- { //if the event is after the original (at least one week) and the day of the week is the same
- //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++)
- //{
- /*
- The "day of the week" of repetition is the same as the $dw_orig,
- so to get the "day of the month" from the "day of the week", we have
- to get the first "day of the week" for this week and add the number
- of days (in seconds) to reach the $dw_orig
- example: the first week spans between the 28th of April (Monday) to the
- 4th of May (Sunday). The event occurs on the 2nd day of each week.
- This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
- We want to get all of these, and then reject 29/4 because it is out
- of the month itself.
- First, to get the start time of the first day of the month view (even if
- the day is from the past month), we get the month start date (1/5) and
- see which day of the week it is, and subtract the number of days necessary
- to get back to the first day of the week.
- */
- $month_first_day_weekday = date('N',$start);
- $first_week_start = $start - (($month_first_day_weekday-1)*86400);
- //Second, we add the week day of the original event, so that we have an
- // absolute time that represents the first repetition of the event in
- // our 4- or 5-weeks timespan
- $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig;
- //Third, we start looping through the repetitions and see if they are between
- // $start and $end
- for($i = $first_event_repeat_start; ($i<=$end && $i<=$repeat_end); $i+=604800)
- {
- if($start<$i && $i<=$end && $i<=$repeat_end)
- {
- list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i));
- $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
- $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now);
- $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
- }
- $time_now = date('Y/n/W/j/N/G/i/s',$i+604800);
- list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- }
- //}
- }
- break;
- case 'monthlyByDate':
- $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
- list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/W/j/G/i/s',$start);
- list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- //make sure we are one month ahead (to avoid being the same month as the original event)
- if($m_now==12)
- {
- ++$y_now;
- $m_now = 1;
- }
- else
- {
- ++$m_now;
- }
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
- $diff = $orig_end - $orig_start;
- while((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end))
- { //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
- $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
- $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now);
- $events[] = array($course_info['id'],$row['id'],$new_start_time,$new_stop_time,$row['title'],$row['content']);
- if($m_now==12)
- {
- ++$y_now;
- $m_now = 1;
- }
- else
- {
- ++$m_now;
- }
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
- }
- break;
- case 'monthlyByDayR':
- //not implemented yet
- break;
- case 'monthlyByDay':
- //not implemented yet
- break;
- case 'yearly':
- $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
- list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
- $time_now = date('Y/n/j/z/G/i/s',$end);
- list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
- while((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end && $event_repetition_time<$repeat_end)))
- {
- $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
- 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);
- $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']);
- ++$y_now;
- $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
- }
- break;
- default:
- break;
- }
- }
- }
- return $events;
- }
- /**
- * Tells if an agenda item is repeated
- * @param string Course database
- * @param int The agenda item
- * @return boolean True if repeated, false otherwise
- */
- function is_repeated_event($id,$course=null)
- {
- if(empty($course))
- {
- $course_info = api_get_course_info();
- $course = $course_info['dbName'];
- }
- $id = (int) $id;
- $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course);
- $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- return true;
- }
- return false;
- }
- /**
- * Adds x weeks to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of weeks to add
- * @return int The new timestamp
- */
- function add_week($timestamp,$num=1)
- {
- return $timestamp + $num*604800;
- }
- /**
- * Adds x months to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of years to add
- * @return int The new timestamp
- */
- function add_month($timestamp,$num=1)
- {
- list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp));
- if($m+$num>12)
- {
- $y += floor($num/12);
- $m += $num%12;
- }
- else
- {
- $m += $num;
- }
- return mktime($h, $n, $s, $m, $d, $y);
- }
- /**
- * Adds x years to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of years to add
- * @return int The new timestamp
- */
- function add_year($timestamp,$num=1)
- {
- list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp));
- return mktime($h, $n, $s, $m, $d, $y+$num);
- }
- /**
- * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
- * @param array Course info
- * @param string Event title
- * @param string Event content/description
- * @param string Start date
- * @param string End date
- * @param array List of groups to which this event is added
- * @param int Parent id (optional)
- * @return int The new item's DB ID
- */
- function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to = array(), $parent_id = null, $file_comment='') {
- $user_id = api_get_user_id();
- // database table definitions
- $t_agenda = Database::get_course_table(TABLE_AGENDA);
- $item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
- // some filtering of the input data
- $title = Database::escape_string($title);
- $content = Database::escape_string($content);
- $db_start_date = api_get_utc_datetime($db_start_date);
- $start_date = Database::escape_string($db_start_date);
- if (!empty($db_end_date)) {
- $db_end_date = api_get_utc_datetime($db_end_date);
- }
- $end_date = Database::escape_string($db_end_date);
- $id_session = api_get_session_id();
- $course_id = api_get_course_int_id();
- $group_id = api_get_group_id();
- // check if exists in calendar_event table and if it is not deleted!
- $sql = "SELECT * FROM $t_agenda agenda, $item_property item_property
- WHERE
- agenda.c_id = $course_id AND
- item_property.c_id = $course_id AND
- agenda.title = '$title'
- AND agenda.content = '$content'
- AND agenda.start_date = '$start_date'
- AND agenda.end_date = '$end_date' ".(!empty($parent_id)? "
- AND agenda.parent_event_id = '$parent_id'":"")."
- AND agenda.session_id = '$id_session'
- AND item_property.tool = '".TOOL_CALENDAR_EVENT."'
- AND item_property.ref = agenda.id
- AND item_property.visibility <> 2";
-
- $result = Database::query($sql);
- $count = Database::num_rows($result);
- if ($count > 0) {
- return false;
- }
- $course_id = api_get_course_int_id();
-
- $sql = "INSERT INTO ".$t_agenda." (c_id, title,content, start_date, end_date".(!empty($parent_id)?',parent_event_id':'').", session_id)
- VALUES($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."'".(!empty($parent_id)?','.((int)$parent_id):'').", '".$id_session."')";
-
- $result = Database::query($sql);
- $last_id = Database::insert_id();
- // add a attachment file in agenda
- add_agenda_attachment_file($file_comment, $last_id);
- // store in last_tooledit (first the groups, then the users
-
- if (!empty($to)) {
- $send_to = separate_users_groups($to);
- // storing the selected groups
- if (is_array($send_to['groups'])) {
- foreach ($send_to['groups'] as $group) {
- api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group, 0, $start_date, $end_date);
- $done = true;
- }
- }
- // storing the selected users
- if (is_array($send_to['users'])) {
- foreach ($send_to['users'] as $user) {
- api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id,0,$user, $start_date,$end_date);
- $done = true;
- }
- }
- if (isset($send_to['everyone']) && $send_to['everyone']) {
- api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, 0, $start_date, $end_date);
- }
- }
- // storing the resources
- if (!empty($_SESSION['source_type']) && !empty($last_id)) {
- store_resources($_SESSION['source_type'], $last_id);
- }
- return $last_id;
- }
- /**
- * This function delete a attachment file by id
- * @param integer attachment file Id
- *
- */
- function delete_attachment_file($id_attach) {
- global $_course;
- $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
- $id_attach = intval($id_attach);
- $sql="DELETE FROM $agenda_table_attachment WHERE id = ".$id_attach;
- $result=Database::query($sql);
- $last_id_file=Database::insert_id();
- // update item_property
- api_item_property_update($_course, 'calendar_event_attachment', $id_attach ,'AgendaAttachmentDeleted', api_get_user_id());
- if (!empty($result)) {
- Display::display_confirmation_message(get_lang("AttachmentFileDeleteSuccess"));
- }
- }
- /**
- * This function add a attachment file into agenda
- * @param string a comment about file
- * @param int last id from calendar table
- *
- */
- function add_agenda_attachment_file($file_comment,$last_id) {
- global $_course;
- $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
- $last_id = intval($last_id);
- // Storing the attachments
- if(!empty($_FILES['user_upload']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['user_upload']);
- }
- if (!empty($upload_ok)) {
- $courseDir = $_course['path'].'/upload/calendar';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
- // Try to add an extension to the file if it hasn't one
- $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
- // user's file name
- $file_name =$_FILES['user_upload']['name'];
- if (!filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- } else {
- $new_file_name = uniqid('');
- $new_path=$updir.'/'.$new_file_name;
- $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
- $safe_file_comment= Database::escape_string($file_comment);
- $safe_file_name = Database::escape_string($file_name);
- $safe_new_file_name = Database::escape_string($new_file_name);
- $course_id = api_get_course_int_id();
- // Storing the attachments if any
- if ($result) {
- $sql='INSERT INTO '.$agenda_table_attachment.'(c_id, filename,comment, path,agenda_id,size) '.
- "VALUES ($course_id, '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".intval($_FILES['user_upload']['size'])."' )";
- $result=Database::query($sql);
- $message.=' / '.get_lang('FileUploadSucces').'<br />';
- $last_id_file=Database::insert_id();
- api_item_property_update($_course, 'calendar_event_attachment', $last_id_file ,'AgendaAttachmentAdded', api_get_user_id());
- }
- }
- }
- }
- /**
- * This function edit a attachment file into agenda
- * @param string a comment about file
- * @param int Agenda Id
- * @param int attachment file Id
- */
- function edit_agenda_attachment_file($file_comment, $agenda_id, $id_attach) {
- global $_course;
- $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
- // Storing the attachments
- if(!empty($_FILES['user_upload']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['user_upload']);
- }
- if (!empty($upload_ok)) {
- $courseDir = $_course['path'].'/upload/calendar';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
- // Try to add an extension to the file if it hasn't one
- $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
- // user's file name
- $file_name =$_FILES['user_upload']['name'];
- if (!filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- } else {
- $new_file_name = uniqid('');
- $new_path=$updir.'/'.$new_file_name;
- $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
- $safe_file_comment= Database::escape_string($file_comment);
- $safe_file_name = Database::escape_string($file_name);
- $safe_new_file_name = Database::escape_string($new_file_name);
- $safe_agenda_id = (int)$agenda_id;
- $safe_id_attach = (int)$id_attach;
- // Storing the attachments if any
- if ($result) {
- $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 ='".intval($_FILES['user_upload']['size'])."'
- WHERE id = '$safe_id_attach'";
- $result=Database::query($sql);
- api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach ,'AgendaAttachmentUpdated', api_get_user_id());
- }
- }
- }
- }
- /**
- * Adds a repetitive item to the database
- * @param array Course info
- * @param int The original event's id
- * @param string Type of repetition
- * @param int Timestamp of end of repetition (repeating until that date)
- * @param array Original event's destination (users list)
- * @param string a comment about a attachment file into agenda
- * @return boolean False if error, True otherwise
- */
- function agenda_add_repeat_item($course_info, $orig_id, $type, $end, $orig_dest, $file_comment='') {
- $t_agenda = Database::get_course_table(TABLE_AGENDA);
- $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
-
- $course_id = $course_info['real_id'];
- $sql = 'SELECT title, content, start_date as sd, end_date as ed FROM '. $t_agenda.' WHERE c_id = '.$course_id.' AND id ="'.intval($orig_id).'" ';
- $res = Database::query($sql);
- if(Database::num_rows($res)!==1){return false;}
- $row = Database::fetch_array($res);
- $orig_start = api_strtotime(api_get_local_time($row['sd']));
- $orig_end = api_strtotime(api_get_local_time($row['ed']));
-
- $diff = $orig_end - $orig_start;
- $orig_title = $row['title'];
- $orig_content = $row['content'];
- $now = time();
- $type = Database::escape_string($type);
- $end = intval($end);
-
- if (1<=$end && $end<=500) {
- //we assume that, with this type of value, the user actually gives a count of repetitions
- //and that he wants us to calculate the end date with that (particularly in case of imports from ical)
- switch($type) {
- case 'daily':
- $end = $orig_start + (86400*$end);
- break;
- case 'weekly':
- $end = add_week($orig_start,$end);
- break;
- case 'monthlyByDate':
- $end = add_month($orig_start,$end);
- break;
- case 'monthlyByDay':
- //TODO
- break;
- case 'monthlyByDayR':
- //TODO
- break;
- case 'yearly':
- $end = add_year($orig_start,$end);
- break;
- }
- }
-
- if ($end > $now
- && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly'))) {
- $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end) VALUES ($course_id, '$orig_id','$type',$end)";
- $res = Database::query($sql);
- switch($type) {
- case 'daily':
- for($i = $orig_start + 86400; ($i <= $end); $i += 86400) {
- $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);
- }
- break;
- case 'weekly':
- for($i = $orig_start + 604800; ($i <= $end); $i += 604800) {
- $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);
- }
- break;
- case 'monthlyByDate':
- $next_start = add_month($orig_start);
- while($next_start <= $end) {
- $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);
- $next_start = add_month($next_start);
- }
- break;
- case 'monthlyByDay':
- //not yet implemented
- break;
- case 'monthlyByDayR':
- //not yet implemented
- break;
- case 'yearly':
- $next_start = add_year($orig_start);
- while($next_start <= $end) {
- $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);
- $next_start = add_year($next_start);
- }
- break;
- }
- }
- return true;
- }
- /**
- * Import an iCal file into the database
- * @param array Course info
- * @return boolean True on success, false otherwise
- */
- function agenda_import_ical($course_info,$file) {
- require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- $charset = api_get_system_encoding();
- $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
- if (!@move_uploaded_file($file['tmp_name'],$filepath)) {
- error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__);
- return false;
- }
- require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php';
- $ical = new vcalendar();
- $ical->setConfig('directory', dirname($filepath) );
- $ical->setConfig('filename', basename($filepath) );
- $return = $ical->parse();
- //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name),
- /*
- $ve = $ical->getComponent(VEVENT);
- $ttitle = $ve->getProperty('summary');
- $title = api_convert_encoding($ttitle,$charset,'UTF-8');
- $tdesc = $ve->getProperty('description');
- $desc = api_convert_encoding($tdesc,$charset,'UTF-8');
- $start_date = $ve->getProperty('dtstart');
- $start_date_string = $start_date['year'].'-'.$start_date['month'].'-'.$start_date['day'].' '.$start_date['hour'].':'.$start_date['min'].':'.$start_date['sec'];
- $ts = $ve->getProperty('dtend');
- if ($ts) {
- $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
- } else {
- //Check duration if dtend does not exist
- $duration = $ve->getProperty('duration');
- if ($duration) {
- $duration = $ve->getProperty('duration');
- $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec'];
- $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year']));
- //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year']));
- //echo date('d-m-Y - h:i:s', $start_date_tms);
- $end_date_string = mktime(intval($start_date['hour']) +$duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day'])+$duration['day'], intval($start_date['year']) + $duration['year']);
- $end_date_string = date('Y-m-d H:i:s', $end_date_string);
- //echo date('d-m-Y - h:i:s', $end_date_string);
- }
- }
- //echo $start_date.' - '.$end_date;
- $organizer = $ve->getProperty('organizer');
- $attendee = $ve->getProperty('attendee');
- $course_name = $ve->getProperty('location');
- //insert the event in our database
- //var_dump($title,$desc,$start_date,$end_date);
- $id = agenda_add_item($course_info,$title,$desc,$start_date_string,$end_date_string,$_POST['selectedform']);
-
- $repeat = $ve->getProperty('rrule');
- if(is_array($repeat) && !empty($repeat['FREQ'])) {
- $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly');
- $freq = $trans[$repeat['FREQ']];
- $interval = $repeat['INTERVAL'];
- if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) {
- $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']);
- $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']);
- }*/
- $eventcount = 0;
- while (true) {
- //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name),
-
- $ve = $ical->getComponent(VEVENT, $eventcount);
- if (!$ve)
- break;
-
- $ttitle = $ve->getProperty('summary');
- $title = api_convert_encoding($ttitle,$charset,'UTF-8');
-
- $tdesc = $ve->getProperty('description');
- $desc = api_convert_encoding($tdesc,$charset,'UTF-8');
-
- $start_date = $ve->getProperty('dtstart');
- $start_date_string = $start_date['year'].'-'.$start_date['month'].'-'.$start_date['day'].' '.$start_date['hour'].':'.$start_date['min'].':'.$start_date['sec'];
-
-
- $ts = $ve->getProperty('dtend');
- if ($ts) {
- $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
- } else {
- //Check duration if dtend does not exist
- $duration = $ve->getProperty('duration');
- if ($duration) {
- $duration = $ve->getProperty('duration');
- $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec'];
- $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year']));
- //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year']));
- //echo date('d-m-Y - h:i:s', $start_date_tms);
-
- $end_date_string = mktime(intval($start_date['hour']) +$duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day'])+$duration['day'], intval($start_date['year']) + $duration['year']);
- $end_date_string = date('Y-m-d H:i:s', $end_date_string);
- //echo date('d-m-Y - h:i:s', $end_date_string);
- }
- }
-
- //echo $start_date.' - '.$end_date;
- $organizer = $ve->getProperty('organizer');
- $attendee = $ve->getProperty('attendee');
- $course_name = $ve->getProperty('location');
- //insert the event in our database
- //var_dump($title,$desc,$start_date,$end_date);
- $id = agenda_add_item($course_info,$title,$desc,$start_date_string,$end_date_string,$attendee);
-
- $repeat = $ve->getProperty('rrule');
- if(is_array($repeat) && !empty($repeat['FREQ'])) {
- $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly');
- $freq = $trans[$repeat['FREQ']];
- $interval = $repeat['INTERVAL'];
- if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) {
- $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']);
- $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$attendee);
- }
-
- //TODO: deal with count
- if(!empty($repeat['COUNT'])) {
- $count = $repeat['COUNT'];
- $res = agenda_add_repeat_item($course_info,$id,$freq,$count,$attendee);
- }
- }
- $eventcount++;
- }
- return true;
- }
- /**
- * This function retrieves one personal agenda item returns it.
- * @param array The array containing existing events. We add to this array.
- * @param int Day
- * @param int Month
- * @param int Year (4 digits)
- * @param int Week number
- * @param string Type of view (month_view, week_view, day_view)
- * @return array The results of the database query, or null if not found
- */
- function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type) {
- $tbl_global_agenda= Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
- $month = Database::escape_string($month);
- $year = Database::escape_string($year);
- $week = Database::escape_string($week);
- $day = Database::escape_string($day);
- // 1. creating the SQL statement for getting the personal agenda items in MONTH view
-
- $current_access_url_id = api_get_current_access_url_id();
- if ($type == "month_view" or $type == "") {
- // We are in month view
- $sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date)='".$month."' AND YEAR(start_date) = '".$year."' AND access_url_id = $current_access_url_id ORDER BY start_date ASC";
- }
- // 2. creating the SQL statement for getting the personal agenda items in WEEK view
- if ($type == "week_view") // we are in week view
- {
- $start_end_day_of_week = calculate_start_end_of_week($week, $year);
- $start_day = $start_end_day_of_week['start']['day'];
- $start_month = $start_end_day_of_week['start']['month'];
- $start_year = $start_end_day_of_week['start']['year'];
- $end_day = $start_end_day_of_week['end']['day'];
- $end_month = $start_end_day_of_week['end']['month'];
- $end_year = $start_end_day_of_week['end']['year'];
- // in sql statements you have to use year-month-day for date calculations
- $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
-
- $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id ";
- }
- // 3. creating the SQL statement for getting the personal agenda items in DAY view
- if ($type == "day_view") // we are in day view
- {
- // we could use mysql date() function but this is only available from 4.1 and higher
- $start_filter = $year."-".$month."-".$day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
-
- $end_filter = $year."-".$month."-".$day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id";
- }
- $result = Database::query($sql);
- while ($item = Database::fetch_array($result)) {
-
- if ($item['start_date'] != '0000-00-00 00:00:00') {
- $item['start_date'] = api_get_local_time($item['start_date']);
- $item['start_date_tms'] = api_strtotime($item['start_date']);
- }
- if ($item['end_date'] != '0000-00-00 00:00:00') {
- $item['end_date'] = api_get_local_time($item['end_date']);
- }
-
- // we break the date field in the database into a date and a time part
- $agenda_db_date = explode(" ", $item['start_date']);
- $date = $agenda_db_date[0];
- $time = $agenda_db_date[1];
- // we divide the date part into a day, a month and a year
- $agendadate = explode("-", $date);
- $year = intval($agendadate[0]);
- $month = intval($agendadate[1]);
- $day = intval($agendadate[2]);
- // we divide the time part into hour, minutes, seconds
- $agendatime = explode(":", $time);
- $hour = $agendatime[0];
- $minute = $agendatime[1];
- $second = $agendatime[2];
-
- if ($type == 'month_view') {
- $item['calendar_type'] = 'global';
- $agendaitems[$day][] = $item;
- continue;
- }
-
- $start_time = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
- $end_time = '';
- if ($item['end_date'] != '0000-00-00 00:00:00') {
- $end_time = ' - '.api_format_date($item['end_date'], DATE_TIME_FORMAT_LONG);
- }
-
- // if the student has specified a course we a add a link to that course
- if ($item['course'] <> "") {
- $url = api_get_path(WEB_CODE_PATH)."admin/agenda.php?cidReq=".urlencode($item['course'])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
- $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
- } else {
- $course_link = "";
- }
- // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
- // if we have a day_view we use a half hour as index => key 33 = 16h30
- if ($type !== "day_view") {
- // This is the array construction for the WEEK or MONTH view
-
- //Display the Agenda global in the tab agenda (administrator)
- $agendaitems[$day] .= "<i>$start_time $end_time</i> - ";
- $agendaitems[$day] .= "<b>".get_lang('GlobalEvent')."</b>";
- $agendaitems[$day] .= "<div>".$item['title']."</div><br>";
- } else {
- // this is the array construction for the DAY view
- $halfhour = 2 * $agendatime['0'];
- if ($agendatime['1'] >= '30') {
- $halfhour = $halfhour +1;
- }
- if (!is_array($agendaitems[$halfhour]))
- $content = $agendaitems[$halfhour];
- $agendaitems[$halfhour] = $content."<div><i>$hour:$minute</i> <b>".get_lang('GlobalEvent'). ": </b>".$item['title']."</div>";
-
- }
- }
- return $agendaitems;
- }
- function display_ical_import_form() {
- echo '<form enctype="multipart/form-data" action="'.api_get_self().'?origin='.Security::remove_XSS($_GET['origin']).'&action='.Security::remove_XSS($_GET['action']).'" method="post" name="frm_import_ical">';
- echo '<legend>'.get_lang('ICalFileImport').'</legend>';
- echo '<div class="row">
- <div class="label">
- <span class="form_required">*</span> '.get_lang('ICalFileImport').'
- </div>
- <div class="formw"><input type="file" name="ical_import"/>
- </div>
- </div>';
- echo '<div class="row">
- <div class="label">
- </div>
- <div class="formw">
- <button class="save" type="submit" name="ical_submit" value="'.get_lang('Import').'">'.get_lang('Import').'</button>
- </div>
- </div>';
- echo '</form>';
- }
|