12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240 |
- <?php //$Id: agenda.inc.php 11607 2007-03-16 13:18:47Z elixir_julian $
- /*
- ==============================================================================
- Dokeos - elearning and course management software
- Copyright (c) 2004-2005 Dokeos S.A.
- Copyright (c) 2003 Ghent University (UGent)
- Copyright (c) 2001 Universite catholique de Louvain (UCL)
- For a full list of contributors, see "credits.txt".
- The full license can be read in "license.txt".
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- See the GNU General Public License for more details.
- Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
- Mail: info@dokeos.com
- ==============================================================================
- @author: Patrick Cool, patrick.cool@UGent.be
- @version: 1.1
- @todo: synchronisation with the function in myagenda.php (for instance: using one function for the mini_calendar
- ==============================================================================
- Large parts of the code are recycled from the old agenda tool, but I
- reworked it and cleaned the code to make it more readable. The code for
- the small calender on the left is taken from the My Agenda tool.
- Reabability is also the reason why I use the if ($is_allowedToEdit)
- check for each part of the code. I'm aware that is duplication, but
- it makes the code much easier to read.
- ==============================================================================
- */
- /*
- -----------------------------------------------------------
- Constants and variables
- -----------------------------------------------------------
- */
- // the variables for the days and the months
- // Defining the shorts for the days
- $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
- // Defining the days of the week to allow translation of the days
- $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
- // Defining the months of the year to allow translation of the months
- $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
- /*
- ==============================================================================
- FUNCTIONS
- ==============================================================================
- */
- /**
- * Retrieves all the agenda items from the table
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @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_kalender_items($month, $year)
- {
- global $_user, $_course;
- global $is_allowedToEdit;
- // 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['dbName'], $_user['user_id']);
- if (is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda'))
- {
- //echo "course admin";
- // added GROUP BY `agenda`.`id` to prevent double display of a message that has been sent to two groups
- $sql="SELECT
- DISTINCT agenda.*, toolitemproperties.*
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
- WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current."
- AND MONTH(`agenda`.`start_date`)='".$month."' AND YEAR(`agenda`.`start_date`)='".$year."'
- AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."'
- AND `toolitemproperties`.`visibility`='1'
- GROUP BY `agenda`.`id`
- ORDER BY start_date ".$sort;
- }
- // if the user is not an administrator of that course
- else
- {
- //echo "GEEN course admin";
- if (is_array($group_memberships))
- {
- $sql="SELECT
- agenda.*, toolitemproperties.*
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
- WHERE `agenda`.`id` = `toolitemproperties`.`ref` ".$show_all_current."
- AND MONTH(`agenda`.`start_date`)='".$month."'
- AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."'
- AND ( `toolitemproperties`.`to_user_id`='".$_user['user_id']."' OR `toolitemproperties`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
- AND `toolitemproperties`.`visibility`='1'
- 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 MONTH(`agenda`.`start_date`)='".$month."'
- AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."'
- AND ( `toolitemproperties`.`to_user_id`='".$_user['user_id']."' OR `toolitemproperties`.`to_group_id`='0')
- AND `toolitemproperties`.`visibility`='1'
- ORDER BY start_date ".$sort;
- }
- }
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $data=array();
- while ($row=mysql_fetch_array($result))
- {
- $datum_item=(int)substr($row["start_date"],8,2);
- //$dag_item=date("d",strtotime($datum_item));
- $data[$datum_item]=intval($datum_item);
- }
- return $data;
- }
- /**
- * 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($agendaitems, $month, $year, $monthName)
- {
- global $DaysShort;
- //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 = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&courseCode=".$_GET['courseCode']."&month=". ($month == 1 ? 12 : $month -1)."&year=". ($month == 1 ? $year -1 : $year);
- $forewardsURL = $_SERVER['PHP_SELF']."?coursePath=".$_GET['coursePath']."&courseCode=".$_GET['courseCode']."&month=". ($month == 12 ? 1 : $month +1)."&year=". ($month == 12 ? $year +1 : $year);
- echo "<table id=\"smallcalendar\">\n",
- "<tr class=\"title\">\n",
- "<td width=\"10%\"><a href=\"", $backwardsURL, "\"></a></td>\n",
- "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n",
- "<td width=\"10%\"><a href=\"", $forewardsURL, "\"></a></td>\n", "</tr>\n";
- echo "<tr>\n";
- for ($ii = 1; $ii < 8; $ii ++)
- {
- echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
- }
- echo "</tr>\n";
- $curday = -1;
- $today = getdate();
- while ($curday <= $numberofdays[$month])
- {
- echo "<tr>\n";
- 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 "\t<td ".$class.">";
- if ($agendaitems[$curday] <> "")
- {
- echo "<a href=\"".$_SERVER['PHP_SELF']."?action=view&view=day&day=".$curday."&month=".$month."&year=".$year."\">".$dayheader."</a>";
- }
- else
- {
- echo $dayheader;
- }
- // "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>\n";
- echo "</td>\n";
- $curday ++;
- }
- else
- {
- echo "<td> </td>\n";
- }
- }
- echo "</tr>\n";
- }
- echo "</table>\n";
- }
- /**
- * show the calender of the given month
- * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @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)
- {
- global $MonthsLong;
- global $datakalenderitems;
- global $DaysShort;
- global $origin;
- // grabbing all the kalender items for this year and storing it in a array
- $data=get_kalender_items($month,$year);
- //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 = $_SERVER['PHP_SELF']."?origin=$origin&month=".($month==1 ? 12 : $month-1)."&year=".($month==1 ? $year-1 : $year);
- $forewardsURL = $_SERVER['PHP_SELF']."?origin=$origin&month=".($month==12 ? 1 : $month+1)."&year=".($month==12 ? $year+1 : $year);
- $maand_array_maandnummer=$month-1;
- echo "<table id=\"smallcalendar\">\n",
- "<tr class=\"title\">\n",
- "<td width=\"10%\"><a href=\"",$backwardsURL,"\"></a></td>\n",
- "<td width=\"80%\" colspan=\"5\">",$MonthsLong[$maand_array_maandnummer]," ",$year,"</td>\n",
- "<td width=\"10%\"><a href=\"",$forewardsURL,"\"></a></td>\n",
- "</tr>\n";
- echo "<tr>\n";
- for ($ii=1;$ii<8; $ii++)
- {
- echo "<td id=\"weekdays\">",$DaysShort[$ii%7],"</td>\n";
- }
- echo "</tr>\n";
- $curday = -1;
- $today = getdate();
- while ($curday <=$numberofdays[$month])
- {
- echo "<tr>\n";
- for ($ii=0; $ii<7; $ii++)
- {
- if (($curday == -1)&&($ii==$startdayofweek))
- {
- $curday = 1;
- }
- if (($curday>0)&&($curday<=$numberofdays[$month]))
- {
- $bgcolor = $ii<5 ? "class=\"alternativeBgLight\"" : "class=\"alternativeBgDark\"";
- $dayheader = "$curday";
- if (in_array($curday,$data))
- { $dayheader="<a href='".$_SERVER['PHP_SELF']."?origin=$origin&month=$month&year=$year&day=$curday#$curday'>".$curday."</a>"; }
- if (($curday==$today['mday'])&&($year ==$today['year'])&&($month == $today[mon]))
- {
- echo "<td id=\"today\" ",$bgcolor,"\">".$dayheader." \n";
- }
- else
- {
- echo "<td id=\"days\" ",$bgcolor,"\">".$dayheader." \n";
- }
- echo "</td>\n";
- $curday++;
- }
- else
- {
- echo "<td> </td>";
- }
- }
- echo "</tr>";
- }
- 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()
- {
- $Send2All=get_lang("Send2All");
- return "<script type=\"text/javascript\" language=\"JavaScript\">
- <!-- Begin javascript menu swapper
- function move(fbox, tbox)
- {
- var arrFbox = new Array();
- var arrTbox = new Array();
- var arrLookup = new Array();
- var i;
- for (i = 0; i < tbox.options.length; i++)
- {
- arrLookup[tbox.options[i].text] = tbox.options[i].value;
- 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;
- 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();
- 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];
- fbox[c] = no;
- }
- for(c = 0; c < arrTbox.length; c++)
- {
- var no = new Option();
- no.value = arrLookup[arrTbox[c]];
- no.text = arrTbox[c];
- tbox[c] = no;
- }
- }
- function validate()
- {
- var f = document.new_calendar_item;
- f.submit();
- return true;
- }
- function selectAll(cbList,bSelect,showwarning)
- {
- if (cbList.length < 1) {
- alert(\"$Send2All\");
- return;
- }
- for (var i=0; i<cbList.length; i++)
- cbList[i].selected = cbList[i].checked = bSelect
- }
- function reverseAll(cbList)
- {
- for (var i=0; i<cbList.length; i++)
- {
- cbList[i].checked = !(cbList[i].checked)
- cbList[i].selected = !(cbList[i].selected)
- }
- }
- // 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 $tbl_user;
- global $tbl_courseUser, $tbl_session_course_user;
- global $_cid;
- // not 100% if this is necessary, this however prevents a notice
- if (!isset($courseadmin_filter))
- {$courseadmin_filter='';}
- $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName
- FROM $tbl_user as u, $tbl_courseUser as cu
- WHERE cu.course_code = '".$_cid."'
- AND cu.user_id = u.user_id $courseadmin_filter
- ORDER BY u.lastname, u.firstname";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- while($user=mysql_fetch_array($result)){
- $users[$user[0]] = $user;
- }
- if(!empty($_SESSION['id_session'])){
- $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName
- 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_session']."'
- AND course_code='$_cid'";
-
- $result = api_sql_query($sql,__FILE__,__LINE__);
- while($user=mysql_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()
- {
- global $tbl_group;
- global $tbl_groupUser;
- $sql = "SELECT g.id, g.name, COUNT(gu.id) userNb
- FROM ".$tbl_group." AS g LEFT JOIN ".$tbl_groupUser." gu
- ON g.id = gu.group_id
- GROUP BY g.id";
- $result = api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
- while ($group_data = mysql_fetch_array($result))
- {
- $group_list [$group_data['id']] = $group_data;
- }
- 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();
- echo "\n<table id=\"recipient_list\" style=\"display: none;\">\n";
- echo "\t<tr>\n";
- // the form containing all the groups and all the users of the course
- echo "\t\t<td>\n";
- construct_not_selected_select_form($group_list,$user_list,$to_already_selected);
- echo "\t\t</td>\n";
- // the buttons for adding or removing groups/users
- echo "\n\t\t<td valign=\"middle\">\n";
- echo "\t\t<input type=\"button\" ",
- "onclick=\"move(this.form.elements[2],this.form.elements[5])\" ",
- "value=\" >> \" />",
- "\n\t\t<p> </p>",
- "\n\t\t<input type=\"button\" ",
- "onclick=\"move(this.form.elements[5],this.form.elements[2])\" ",
- "value=\" << \" />";
- echo "\t\t</td>\n";
- echo "\n\t\t<td>\n";
- construct_selected_select_form($group_list,$user_list,$to_already_selected);
- echo "\t\t</td>\n";
- echo "\t</tr>\n";
- echo "</table>";
- }
- /**
- * 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)
- {
- echo "\t\t<select name=\"not_selected_form[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">\n";
- // 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 (!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 "\t\t<option value=\"GROUP:".$this_group['id']."\">",
- "G: ",$this_group['name']," – " . $this_group['userNb'] . " " . get_lang('Users') .
- "</option>\n";
- }
- }
- // a divider
- echo "\t\t<option value=\"\">---------------------------------------------------------</option>\n";
- }
- // adding the individual users to the select form
- foreach($user_list as $this_user)
- {
- if (!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 "\t\t<option value=\"USER:",$this_user['uid'],"\">",
- "",$this_user['lastName']," ",$this_user['firstName'],
- "</option>\n";
- }
- }
- echo "\t\t</select>\n";
- }
- /**
- * 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($groupuser))
- {
- $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 "\t\t<select name=\"selectedform[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">";
- foreach($to_already_selected as $groupuser)
- {
- list($type,$id)=explode(":",$groupuser);
- if ($type=="GROUP")
- {
- echo "\t\t<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
- }
- else
- {
- echo "\t\t<option value=\"".$groupuser."\">".$ref_array_users[$id]['lastName']." ".$ref_array_users[$id]['firstName']."</option>";
- }
- }
- echo "</select>\n";
- }
- /**
- * 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 $TABLEAGENDA;
- global $_user;
- // some filtering of the input data
- $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";
- // store in the table calendar_event
- $sql = "INSERT INTO ".$TABLEAGENDA."
- (title,content, start_date, end_date)
- VALUES
- ('".$title."','".$content."', '".$start_date."','".$end_date."')";
- $result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
- $last_id=mysql_insert_id();
- // store in last_tooledit (first the groups, then the users
- $to=$_POST['selectedform'];
- if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) // !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, $last_id,"AgendaAdded", $_user['user_id'], $group,'',$start_visible, $end_visible);
- }
- }
- // 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", $_user['user_id'],'',$user, $start_visible,$end_visible);
- }
- }
- }
- 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", $_user['user_id'], '','',$start_visible,$end_visible);
- }
- // storing the resources
- store_resources($_SESSION['source_type'],$last_id);
- 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
- $sql = "SELECT * FROM $table_agenda WHERE id = '".$item_id."'";
- $res = api_sql_query($sql,__FILE__,__LINE__);
- 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";
- $res_max = api_sql_query($sql_max,__FILE__,__LINE__);
- $row_max = Database::fetch_array($res_max);
- $max = $row_max[0]+1;
- //build the announcement text
- $content = $row['start_date']." - ".$row['end_date']."\n\n".$row['content'];
- //insert announcement
-
- $sql_ins = "INSERT INTO $table_ann (title,content,end_date,display_order) " .
- "VALUES ('".$row['title']."','$content','".$row['end_date']."','$max')";
- $res_ins = api_sql_query($sql_ins,__FILE__,__LINE__);
- if($res > 0)
- {
- $ann_id = Database::get_last_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 = api_sql_query($sql_props,__FILE__,__LINE__);
- if(Database::num_rows($res_props)>0)
- {
- while($row_props = Database::fetch_array($res_props))
- {
- //insert into announcement item_property
- $time = date("Y-m-d H:i:s", time());
- $sql_ins_props = "INSERT INTO $table_props " .
- "(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 " .
- "('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 = api_sql_query($sql_ins_props,__FILE__,__LINE__);
- if($res_ins_props <= 0){
- error_log('SQL Error in '.__FILE__.' at line '.__LINE__.': '.$sql_ins_props);
- }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)
- {
- foreach($to as $to_item)
- {
- list($type, $id) = explode(':', $to_item);
- switch($type)
- {
- 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)
- {
- global $_course;
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- while ($row=mysql_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();
- count($sent_to_array);
- // 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;
- // starting the form if there is more than one user/group
- if ($total_numbers >1)
- {
- $output="<select name=\"sent to\">\n";
- $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)
- {
- $output.="\t<option value=\"\">G: ".$group_names[$group_id]['name']."</option>\n";
- }
- }
- if (isset($sent_to_array['users']))
- {
- if (is_array($sent_to_array['users']))
- {
- foreach ($sent_to_array['users'] as $user_id)
- {
- $user_info=api_get_user_info($user_id);
- $output.="\t<option value=\"\">".$user_info['firstName']." ".$user_info['lastName']."</option>\n";
- }
- }
- }
- // ending the form
- $output.="</select>\n";
- }
- else // there is only one user/group
- {
- if (is_array($sent_to_array['users']))
- {
- $user_info=api_get_user_info($sent_to_array['users'][0]);
- echo $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];
- echo $group_names[$group_id]['name'];
- }
- if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]==0)
- {
- echo get_lang("Everybody");
- }
- //.$sent_to_array['groups'][0];
- }
- echo $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=\"MM_jumpMenu('parent',this,0)\">";
- echo "<option value=\"agenda.php?group=none\">show all groups</option>";
- foreach($group_list as $this_group)
- {
- // echo "<option value=\"agenda.php?isStudentView=true&group=".$this_group['id']."\">".$this_group['name']."</option>";
- echo "<option value=\"agenda.php?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=\"MM_jumpMenu('parent',this,0)\">";
- echo "<option value=\"agenda.php?user=none\">show all users</option>";
- foreach($user_list as $this_user)
- {
- // echo "<option value=\"agenda.php?isStudentView=true&user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
- echo "<option value=\"agenda.php?user=".$this_user['uid']."\" ";
- echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
- echo ">".$this_user['lastName']." ".$this_user['firstName']."</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 "\n<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
- echo "\n\t<option value=\"agenda.php?user=none\">".get_lang("ShowAll")."</option>";
- // Groups
- echo "\n\t<optgroup label=\"".get_lang("Groups")."\">";
- $group_list=get_course_groups();
- foreach($group_list as $this_group)
- {
- // echo "<option value=\"agenda.php?isStudentView=true&group=".$this_group['id']."\">".$this_group['name']."</option>";
- echo "\n\t\t<option value=\"agenda.php?group=".$this_group['id']."\" ";
- echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
- echo ">".$this_group['name']."</option>";
- }
- echo "\n\t</optgroup>";
- // Users
- echo "\n\t<optgroup label=\"".get_lang("Users")."\">";
- $user_list=get_course_users();
- foreach($user_list as $this_user)
- {
- // echo "<option value=\"agenda.php?isStudentView=true&user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
- echo "\n\t\t<option value=\"agenda.php?user=".$this_user['uid']."\" ";
- echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
- echo ">".$this_user['lastName']." ".$this_user['firstName']."</option>";
- }
- echo "\n\t</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)
- {
- global $_course;
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='$tool' AND ref='$id'";
- $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
- while ($row=mysql_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)
- {
- global $_course;
- $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".TOOL_CALENDAR_EVENT."' AND ref='$id'";
- $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
- $row=mysql_fetch_array($result);
- if ($row['visibility']=='1')
- {
- $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");
- }
- 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");
- }
- }
- /**
- * 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()
- {
- echo "<li><a href='".$_SERVER['PHP_SELF']."?action=add&origin=".$_GET['origin']."'><img src=\"../img/view_more_stats.gif\" align=\"absmiddle\" border=\"0\" /> ".get_lang("AgendaAdd")."</a><br /></li>";
- if (empty ($_SESSION['toolgroup']))
- {
- echo "<li>".get_lang(UserGroupFilter)."<br/>";
- echo "<form name=\"filter\">";
- show_user_group_filter_form();
- echo "</form>";
- }
- echo "</li>";
- }
- /**
- * 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
- */
- function display_student_links()
- {
- global $show;
- if ($_SESSION['sort'] == 'DESC')
- {
- echo "<li><a href='".$_SERVER['PHP_SELF']."?sort=asc&origin=".$_GET['origin']."'><img src=\"../img/calendar_up.gif\" border=\"0\" /> ".get_lang("AgendaSortChronologicallyUp")."</a></li>";
- }
- else
- {
- echo "<li><a href='".$_SERVER['PHP_SELF']."?sort=desc&origin=".$_GET['origin']."'><img src=\"../img/calendar_down.gif\" border=\"0\" /> ".get_lang("AgendaSortChronologicallyDown")."</a></li>";
- }
- // showing the link to show all items or only those of the current month
- if ($_SESSION['show']=="showcurrent")
- {
- echo "<li><a href='".$_SERVER['PHP_SELF']."?action=showall&origin=".$_GET['origin']."'><img src=\"../img/calendar_select.gif\" border=\"0\" /> ".get_lang("ShowAll")."</a></li>";
- }
- else
- {
- echo "<li><a href='".$_SERVER['PHP_SELF']."?action=showcurrent&origin=".$_GET['origin']."'><img src=\"../img/calendar_month.gif\" border=\"0\" /> ".get_lang("ShowCurrent")."</a></li>";
- }
- }
- /**
- * 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;
- $id=(int)addslashes($_GET['id']);
- $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- $entry_to_edit = mysql_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";
- }
- //echo "<br />IN get_agenda_item".$_SESSION['allow_individual_calendar'];
- 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
- */
- function store_edited_agenda_item()
- {
- global $_user;
- // 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'];
- // 1.b. the actual saving in calendar_event table
- $edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
- // 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 = api_sql_query($sql_delete,__FILE__,__LINE__) or die (mysql_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", $_user['user_id'], $group,'',$start_visible, $end_visible);
- }
- }
- // 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", $_user['user_id'],'',$user, $start_visible,$end_visible);
- }
- }
- }
- else // the message is sent to everyone, so we set the group to 0
- {
- api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", $_user['user_id'], '','',$start_visible,$end_visible);
- }
- } //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_normal_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);
- // 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 = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
- 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)
- {
- if (is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda'))
- {
- if (isset($_GET['id'])&&$_GET['id']&&isset($_GET['action'])&&$_GET['action']=="delete")
- {
- //$sql = "DELETE FROM ".$TABLEAGENDA." WHERE id='$id'";
- //$sql= "UPDATE ".$TABLE_ITEM_PROPERTY." SET visibility='2' WHERE tool='Agenda' and ref='$id'";
- //$result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
- $id=(int)addslashes($_GET['id']);
- api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,"delete");
- // 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_normal_message(get_lang("AgendaDeleteSuccess"));
- } // if (isset($id)&&$id&&isset($action)&&$action=="delete")
- } // if ($is_allowedToEdit)
- }
- /**
- * 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)
- {
- /*==================================================
- 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 ((is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda')) and $_GET['isStudentView']<>"false")
- {
- if (isset($_GET['id'])&&$_GET['id']&&isset($_GET['action'])&&$_GET['action']=="showhide")
- {
- $id=(int)addslashes($_GET['id']);
- change_visibility($_GLOBAL['nameTools'],$id);
- Display::display_normal_message(get_lang("VisibilityChanged"));
- }
- }
- }
- /**
- * Displays all the agenda items
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- */
- function display_agenda_items()
- {
- global $TABLEAGENDA;
- global $TABLE_ITEM_PROPERTY;
- global $select_month, $select_year;
- global $DaysShort, $DaysLong, $MonthsLong;
- global $is_courseAdmin;
- global $dateFormatLong, $timeNoSecFormat;
- global $_user;
-
- // getting the group memberships
- $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
- // getting the name of the groups
- $group_names=get_course_groups();
- /*--------------------------------------------------
- CONSTRUCT THE SQL STATEMENT
- --------------------------------------------------*/
- // this is to make a difference between showing everything (all months) or only the current month)
- // $show_all_current is a part of the sql statement
- if ($_SESSION['show']!=="showall")
- {
- $show_all_current=" AND MONTH(start_date)=$select_month AND year(start_date)=$select_year";
- }
- else
- {
- $show_all_current="";
- }
- // 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=$_user['user_id'];
- if ($_SESSION['user']!==null)
- {
- $user_id=$_SESSION['user'];
- }
- if ($_SESSION['group']!==null)
- {
- $group_id=$_SESSION['group'];
- }
- if ($_SESSION['toolgroup']!==null)
- {
- $group_id=$_SESSION['toolgroup'];
- }
- //echo "user:".$_SESSION['user']."group: ".$_SESSION['group'];
- // A. you are a course admin
- //if ($is_courseAdmin)
- if (is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda'))
- {
- // 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 ($_SESSION['user']!==null)
- {
- $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_SESSION['user']);
- if (is_array($group_memberships))
- {
- $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`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
- AND `toolitemproperties`.`visibility`='1'
- ORDER BY start_date ".$_SESSION['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`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id`='0')
- AND `toolitemproperties`.`visibility`='1'
- ORDER BY start_date ".$_SESSION['sort'];
- }
- }
- // A.2. you are a course admin with a GROUP filter
- // => see only the messages of this specific group
- elseif ($_SESSION['group']!==null)
- {
- $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`.`to_group_id`=$group_id OR `toolitemproperties`.`to_group_id`='0')
- AND `toolitemproperties`.`visibility`='1'
- GROUP BY `toolitemproperties`.`ref`
- ORDER BY start_date ".$_SESSION['sort'];
- }
- // 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 ($isStudentView=="true")
- {
- $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'
- GROUP BY `toolitemproperties`.`ref`
- ORDER BY start_date ".$_SESSION['sort'];
- }
- // A.3.b you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
- // => see all the messages of all the users and groups with editing possibilities
- 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`='0' or `toolitemproperties`.`visibility`='1')
- GROUP BY `toolitemproperties`.`ref`
- ORDER BY start_date ".$_SESSION['sort'];
- }
- }
- } //if (is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda'))
- // B. you are a student
- else
- {
- if (is_array($group_memberships))
- {
- $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`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
- AND `toolitemproperties`.`visibility`='1'
- ORDER BY start_date ".$_SESSION['sort'];
- }
- else
- {
- if ($_user['user_id'])
- {
- $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`.`to_user_id`=$user_id OR `toolitemproperties`.`to_group_id`='0')
- AND `toolitemproperties`.`visibility`='1'
- ORDER BY start_date ".$_SESSION['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`.`to_group_id`='0'
- AND `toolitemproperties`.`visibility`='1'
- ORDER BY start_date ".$_SESSION['sort'];
- }
- }
- } // you are a student
- //echo "<pre>".$sql."</pre>";
- $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
- $number_items=mysql_num_rows($result);
- /*--------------------------------------------------
- DISPLAY: NO ITEMS
- --------------------------------------------------*/
- if ($number_items==0)
- {
- echo "<table id=\"agenda_list\" ><tr><td>".get_lang("NoAgendaItems")."</td></tr></table>";
- }
- /*--------------------------------------------------
- DISPLAY: THE ITEMS
- --------------------------------------------------*/
- $month_bar="";
- $event_list="";
- $counter=0;
- while ($myrow=mysql_fetch_array($result))
- {
- echo "<table class=\"data_table\">\n";
- /*--------------------------------------------------
- display: the month bar
- --------------------------------------------------*/
- // Make the month bar appear only once.
- if ($month_bar != date("m",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"])))
- {
- $month_bar = date("m",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"]));
- echo "\t<tr>\n\t\t<td class=\"agenda_month_divider\" colspan=\"2\" valign=\"top\">".
- ucfirst(format_locale_date("%B %Y",strtotime($myrow["start_date"]))).
- "</td>\n\t</tr>\n";
- }
- /*--------------------------------------------------
- display: the icon, title, destinees of the item
- --------------------------------------------------*/
- echo "\t<tr>\n";
- // highlight: if a date in the small calendar is clicked we highlight the relevant items
- $db_date=(int)date("d",strtotime($myrow["start_date"])).date("n",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"]));
- 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 "\t\t<th>\n";
- // adding an internal anchor
- echo "\t\t\t<a name=\"".(int)date("d",strtotime($myrow["start_date"]))."\"></a>";
- // the icons. If the message is sent to one or more specific users/groups
- // we add the groups icon
- // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon
- echo "<img src=\"../img/agenda.gif\" align=\"absbottom\" border=\"0\" />";
- if ($myrow['to_group_id']!=='0')
- {
- echo "<img src=\"../img/group.gif\" border=\"0\" />";
- }
- echo " ".$myrow['title']."\n";
- echo "\t\t</td>\n";
- // the message has been sent to
- echo "\t\t<th>".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>\n\t</tr>\n";
- /*--------------------------------------------------
- display: the title
- --------------------------------------------------*/
- echo "<tr class='row_odd'>";
- echo "\t\t<td>".get_lang("StartTimeWindow").": ";
- echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["start_date"])))." ";
- echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["start_date"])))."";
- echo "</td>\n";
- echo "\t\t<td>";
- if ($myrow["end_date"]<>"0000-00-00 00:00:00")
- {
- echo get_lang("EndTimeWindow").": ";
- echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["end_date"])))." ";
- echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["end_date"])))."";
- }
- echo "</td>\n";
- echo "\n\t</tr>\n";
- /*--------------------------------------------------
- display: the content
- --------------------------------------------------*/
- $content = $myrow['content'];
- $content = make_clickable($content);
- $content = text_filter($content);
- echo "<tr class='row_even'>";
- echo "<td colspan='2'>";
- 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;"><img src="../img/print.gif" border="0" title="'.htmlentities(get_lang('Print')).'" /></a> ';
- echo $content;
- echo "</td></tr>";
- /*--------------------------------------------------
- display: the added resources
- --------------------------------------------------*/
- if (check_added_resources("Agenda", $myrow["id"]))
- {
- echo "<tr><td colspan='2'>";
- 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>";
- }
- /*--------------------------------------------------
- display: edit delete button (course admin only)
- --------------------------------------------------*/
-
- $event_list.=$myrow['id'].',';
-
- echo "<tr class='row_odd'><td>";
- if (is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_agenda'))
- {
- // edit
- echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=edit&id=".$myrow['id']."\">",
- "<img src=\"../img/edit.gif\" border=\"0\" align=\"absmiddle\" alt=\"".get_lang("ModifyCalendarItem")."\" /></a>",
- "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=delete&id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."')) return false;\">",
- "<img src=\"../img/delete.gif\" border=\"0\" align=\"absmiddle\" alt=\"".get_lang("Delete")."\"/></a>";
- echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=announce&id=".$myrow['id']."\">".
- "<img src=\"../img/announce_add.gif\" border=\"0\" align=\"absmiddle\" alt=\"".get_lang("AddAnnouncement")."\"/></a>";
- if ($myrow['visibility']==1)
- {
- $image_visibility="visible";
- }
- else
- {
- $image_visibility="invisible";
- }
- echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=showhide&id=".$myrow['id']."\">",
- "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" align=\"absmiddle\" alt=\"".get_lang("Visible")."\" /></a>";
- }
- echo "</td>";
-
- $counter++;
- /*--------------------------------------------------
- display: jump-to-top icon
- --------------------------------------------------*/
- echo "<td><a href=\"#top\"><img src=\"../img/top.gif\" border=\"0\" alt=\"to top\" align=\"right\" /></a></td></tr>";
- echo "</table><br><br>";
- } // end while ($myrow=mysql_fetch_array($result))
- if(!empty($event_list))
- {
- $event_list=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>";
- }
- /**
- * 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;
- global $_user;
- //echo "displaying agenda items";
- // getting the name of the groups
- $group_names=get_course_groups();
- /*--------------------------------------------------
- CONSTRUCT THE SQL STATEMENT
- --------------------------------------------------*/
- $sql="SELECT agenda.*, toolitemproperties.*
- FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
- WHERE `agenda`.`id` = `toolitemproperties`.`ref`
- AND `toolitemproperties`.`tool`='".TOOL_CALENDAR_EVENT."'
- AND `toolitemproperties`.`visibility`='1'
- AND `agenda`.`id`='$agenda_id'";
- $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
- $number_items=mysql_num_rows($result);
- $myrow=mysql_fetch_array($result); // there should be only one item so no need for a while loop
- /*--------------------------------------------------
- DISPLAY: NO ITEMS
- --------------------------------------------------*/
- if ($number_items==0)
- {
- echo "<table id=\"agenda_list\" ><tr><td>".get_lang("NoAgendaItems")."</td></tr></table>";
- }
- /*--------------------------------------------------
- DISPLAY: THE ITEMS
- --------------------------------------------------*/
- echo "<table id=\"agenda_list\">\n";
- /*--------------------------------------------------
- DISPLAY : the icon, title, destinees of the item
- --------------------------------------------------*/
- echo "\t<tr>\n";
- // highlight: if a date in the small calendar is clicked we highlight the relevant items
- $db_date=(int)date("d",strtotime($myrow["start_date"])).date("n",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"]));
- 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 "\t\t<td class=\"".$style."\">\n";
- // adding an internal anchor
- echo "\t\t\t<a name=\"".(int)date("d",strtotime($myrow["start_date"]))."\"></a>";
- // the icons. If the message is sent to one or more specific users/groups
- // we add the groups icon
- // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon
- echo "<img src=\"../img/agenda.gif\" border=\"0\" />";
- if ($myrow['to_group_id']!=='0')
- {
- echo "<img src=\"../img/group.gif\" border=\"0\" />";
- }
- echo " ".$myrow['title']."\n";
- echo "\t\t</td>\n";
- // the message has been sent to
- echo "\t\t<td class=\"".$stylenotbold."\">".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>\n\t</tr>\n";
- /*--------------------------------------------------
- DISPLAY: the title
- --------------------------------------------------*/
- echo "\t<tr class=\"".$stylenotbold."\">\n";
- echo "\t\t<td>".get_lang("StartTime").": ";
- echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["start_date"])))." ";
- echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["start_date"])))."";
- echo "</td>\n";
- echo "\t\t<td>".get_lang("EndTime").": ";
- echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["end_date"])))." ";
- echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["end_date"])))."";
- echo "</td>\n";
- echo "\n\t</tr>\n";
- /*--------------------------------------------------
- DISPLAY: the content
- --------------------------------------------------*/
- $content = $myrow['content'];
- $content = make_clickable($content);
- $content = text_filter($content);
- echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
- echo $content;
- echo "</td></tr>";
- /*--------------------------------------------------
- DISPLAY: the added resources
- --------------------------------------------------*/
- if (check_added_resources("Agenda", $myrow["id"]))
- {
- echo "<tr><td colspan='2'>";
- 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>";
- }
- /*--------------------------------------------------
- DISPLAY: edit delete button (course admin only)
- --------------------------------------------------*/
- echo "<tr><td>";
- if (is_allowed_to_edit())
- {
- // edit
- echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=edit&id=".$myrow['id']."\">",
- "<img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang("ModifyCalendarItem")."\" /></a>",
- "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=delete&id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."')) return false;\">",
- "<img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang("Delete")."\" /></a>";
- if ($myrow['visibility']==1)
- {
- $image_visibility="visible";
- }
- else
- {
- $image_visibility="invisible";
- }
- echo "<a href=\"".$_SERVER['PHP_SELF']."?origin=".$_GET['origin']."&action=showhide&id=".$myrow['id']."\">",
- "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" alt=\"".get_lang("Visible")."\" /></a><br /><br />";
- }
- echo "</td>";
- echo "</table>";
- // 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;
- // the default values for the forms
- if ($_GET['originalresource'] !== 'no')
- {
- $day = date('d');
- $month = date('m');
- $year = date('Y');
- $hours = date('H');
- $minutes= date('i');
- $end_day = date('d');
- $end_month = date('m');
- $end_year = date('Y');
- $end_hours = date('H');
- $end_minutes= date('i');
- }
- 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'];
- }
- // switching the send to all/send to groups/send to users
- if ($_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'];
- }
- // if the id is set then we are editing an agenda item
- if (is_int($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
- list($datepart, $timepart) = split(" ", $item_2_edit['start_date']);
- list($year, $month, $day) = explode("-", $datepart);
- list($hours, $minutes, $seconds) = explode(":", $timepart);
- // 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);
- // attachments
- edit_added_resources("Agenda", $id);
- $to=$item_2_edit['to'];
- //echo "<br />after get_agenda_item".$_SESSION['allow_individual_calendar'];
- }
- $content=stripslashes($content);
- $title=stripslashes($title);
- // we start a completely new item, we do not come from the resource linker
- if ($_GET['originalresource']!=="no" and $_GET['action']=="add")
- {
- $_SESSION["formelements"]=null;
- unset_session_resources();
- }
- ?>
- <!-- START OF THE FORM -->
- <form action="<?php echo $_SERVER['PHP_SELF'].'?origin='.$_GET['origin'].'&action='.$_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']; ?>" />
- <table border="0" cellpadding="5" cellspacing="0" width="100%" id="newedit_form">
- <!-- the title -->
- <tr class="title">
- <td colspan="3">
- <span style="font-weight: bold;"><?php echo (isset($id) AND $id<>'')?get_lang('ModifyCalendarItem'):get_lang("AddCalendarItem"); ?></span>
- </td>
- </tr>
- <!-- the select specific users / send to all form -->
- <?php
- if (isset ($_SESSION['toolgroup']))
- {
- echo '<tr id="subtitle">';
- echo '<td colspan="3">';
- echo '<input type="hidden" name="selectedform[0]" value="GROUP:'.$_SESSION['toolgroup'].'"/>' ;
- echo '<input type="hidden" name="To" value="true"/>' ;
- echo '</td>';
- echo '</tr>';
-
- }else{
-
- ?>
- <tr class="subtitle">
- <td valign="top" colspan="3">
- <?php
- // this variable defines if the course administrator can send a message to a specific user / group
- // or not
- //echo "<input type=\"submit\" name=\"To\" value=\"".get_lang("SelectGroupsUsers")."\" style=\"float:left\">" ;
-
- //echo "sessiewaarde: ".$_SESSION['allow_individual_calendar'];
- echo get_lang("SentTo").": ";
- if ((isset($_GET['id']) && $to=='everyone') || !isset($_GET['id'])){
- echo get_lang("Everybody").' ';
- }
- echo '<a href="#" onclick="if(document.getElementById(\'recipient_list\').style.display==\'none\') document.getElementById(\'recipient_list\').style.display=\'block\'; else document.getElementById(\'recipient_list\').style.display=\'none\';">'.get_lang('ModifyRecipientList').'</a>';
- show_to_form($to);
- if (isset($_GET['id']) && $to!='everyone'){
- echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
- }
- ?>
- <hr noshade="noshade" color="#cccccc" />
- </td>
- </tr>
- <?php
- }
- ?>
- <!-- START date and time -->
- <tr class="subtitle">
- <td>
-
- <table cellpadding="0" cellspacing="0" border="0" width="100%">
-
- <tr><td width="110">
- <!-- date: 1 -> 31 -->
- <?php echo get_lang('StartDate').": \n"; ?>
- </td>
-
- <td>
-
- <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
- echo "\n";
- 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 "\t\t\t\t <option value=\"".$value."\" selected> ".$i." </option>\n";
- }
- else
- {
- echo "\t\t\t\t<option value=\"$value\">$i</option>\n";
- }
- }
- ?>
- </select>
- <!-- month: january -> december -->
- <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
- <?php
- echo "\n";
- 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 "\t\t\t\t <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n";
- }
- else
- {
- echo "\t\t\t\t <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n";
- }
- } ?>
- </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
- echo "\n";
- for ($i=1; $i<=5; $i++)
- {
- $value=$year+$i;
- echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
- } ?>
- </select>
- <a href="javascript:openCalendar('new_calendar_item', 'f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle" /></a>
- </td></tr></table>
- </td>
- <td>
-
- <table cellpadding="0" cellspacing="0" border="0" width="100%">
-
- <tr><td width="110">
- <!-- date: 1 -> 31 -->
- <?php echo get_lang('StartTime').": \n"; ?>
- </td>
-
- <td>
-
- <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
- <option value="--">--</option>
- <?php
- echo "\n";
- foreach (range(1, 24) 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 "\t\t\t\t<option value=\"".$value."\" selected> ".$value." </option>\n";
- }
- else
- {
- echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
- }
- } ?>
- </select>
- <?php echo get_lang('HourMinuteDivider'); ?>
- <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 );
- echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
- } ?>
- </select>
- </td></tr></table>
- </td>
- </tr>
- <!-- END date and time -->
- <tr class="subtitle">
- <td>
-
- <table cellpadding="0" cellspacing="0" border="0" width="100%">
-
- <tr><td width="110">
- <!-- date: 1 -> 31 -->
- <?php echo get_lang('EndDate').": \n"; ?>
- </td>
-
- <td>
-
- <select 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
- echo "\n";
- 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 "\t\t\t\t <option value=\"".$value."\" selected> ".$i." </option>\n";}
- else
- { echo "\t\t\t\t <option value=\"".$value."\">".$i."</option>\n"; }
- }?>
- </select>
- <!-- month: january -> december -->
- <select name="end_fmonth">
- <?php
- echo "\n";
- foreach (range(1, 12) as $i)
- {
- // values have to have double digits
- $value = ($i <= 9 ? '0'.$i : $i );
- if ($value==$end_month)
- { echo "\t\t\t\t <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n"; }
- else
- { echo "\t\t\t\t <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n"; }
- }?>
- </select>
- <select 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
- echo "\n";
- for ($i=1; $i<=5; $i++)
- {
- $value=$end_year+$i;
- echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
- } ?>
- </select>
- <a href="javascript:openCalendar('new_calendar_item', 'end_f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle" /></a>
- </td></tr></table>
- </td>
- <td>
-
- <table cellpadding="0" cellspacing="0" border="0" width="100%">
-
- <tr><td width="110">
- <!-- date: 1 -> 31 -->
- <?php echo get_lang('EndTime').": \n"; ?>
- </td>
-
- <td>
-
- <select name="end_fhour">
- <option value="--">--</option>
- <?php
- echo "\n";
- foreach (range(1, 24) 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 "\t\t\t\t<option value=\"".$value."\" selected> ".$value." </option>\n"; }
- else
- { echo "\t\t\t\t<option value=\"".$value."\"> ".$value." </option>\n"; }
- } ?>
- </select>
- <?php echo get_lang('HourMinuteDivider'); ?>
- <select 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 );
- echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
- } ?>
- </select>
- </td></tr></table>
- </td>
- </tr>
- <tr class="subtitle">
- <td colspan="3" valign="top"><hr noshade="noshade" color="#cccccc" /><?php echo get_lang('ItemTitle'); ?> :
- <!--<div style='margin-left: 80px'><textarea name="title" cols="50" rows="2" wrap="virtual" style="vertical-align:top; width:75%; height:50px;"><?php if (isset($title)) echo $title; ?></textarea></div>-->
- <input type="text" size="60" name="title" value="<?php if (isset($title)) echo $title; ?>" />
- </td>
- </tr>
- <tr>
- <td colspan="7">
-
- <?php
- require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
-
- $oFCKeditor = new FCKeditor('content') ;
- $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
- $oFCKeditor->Height = '175';
- $oFCKeditor->Width = '100%';
- $oFCKeditor->Value = $content;
- $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
- $oFCKeditor->ToolbarSet = "Middle";
-
- $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'";
- $result_sql=api_sql_query($sql);
- $isocode_language=mysql_result($result_sql,0,0);
- $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
-
- $return = $oFCKeditor->CreateHtml();
-
- echo $return;
-
- ?>
- </td>
- </tr>
- <!--<?php /* ADDED BY UGENT, Patrick Cool, march 2004 */ ?>
- <tr>
- <td colspan="7">
- <?php
- //onclick="selectAll(this.form.elements[6],true)"
- if ($_SESSION['allow_individual_calendar']=='show')
- show_addresource_button('onclick="selectAll(this.form.elements[6],true)"');
- else
- show_addresource_button();
- $form_elements=$_SESSION['formelements'];
- ?>
- </td>
- </tr>-->
- <?php
- //if ($_SESSION['addedresource'])
- echo "\t<tr>\n";
- echo "\t\t<td colspan=\"7\">\n";
- echo display_resources(0);
- $test=$_SESSION['addedresource'];
- echo "\t\t</td>\n\t</tr>\n";
- /* END ADDED BY UGENT, Patrick Cool, march 2004 */
- ?>
- <tr>
- <td colspan="7">
- <input type="submit" name="submit_event" value="<?php echo get_lang('Ok'); ?>" onclick="selectAll(this.form.elements[5],true)" />
- </td>
- </tr>
- </table>
- </form>
- <p> </p>
- <?php
- }
- ?>
|