agenda.inc.php 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253
  1. <?php //$Id: agenda.inc.php 13772 2007-11-26 02:54:27Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. @author: Patrick Cool, patrick.cool@UGent.be
  19. @version: 1.1
  20. @todo: synchronisation with the function in myagenda.php (for instance: using one function for the mini_calendar
  21. ==============================================================================
  22. Large parts of the code are recycled from the old agenda tool, but I
  23. reworked it and cleaned the code to make it more readable. The code for
  24. the small calender on the left is taken from the My Agenda tool.
  25. Reabability is also the reason why I use the if ($is_allowed_to_edit)
  26. check for each part of the code. I'm aware that is duplication, but
  27. it makes the code much easier to read.
  28. ==============================================================================
  29. */
  30. /*
  31. -----------------------------------------------------------
  32. Constants and variables
  33. -----------------------------------------------------------
  34. */
  35. // the variables for the days and the months
  36. // Defining the shorts for the days
  37. $DaysShort = array (get_lang("SundayShort"), get_lang("MondayShort"), get_lang("TuesdayShort"), get_lang("WednesdayShort"), get_lang("ThursdayShort"), get_lang("FridayShort"), get_lang("SaturdayShort"));
  38. // Defining the days of the week to allow translation of the days
  39. $DaysLong = array (get_lang("SundayLong"), get_lang("MondayLong"), get_lang("TuesdayLong"), get_lang("WednesdayLong"), get_lang("ThursdayLong"), get_lang("FridayLong"), get_lang("SaturdayLong"));
  40. // Defining the months of the year to allow translation of the months
  41. $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"));
  42. /*
  43. ==============================================================================
  44. FUNCTIONS
  45. ==============================================================================
  46. */
  47. /**
  48. * Retrieves all the agenda items from the table
  49. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  50. * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
  51. * @param integer $month: the integer value of the month we are viewing
  52. * @param integer $year: the 4-digit year indication e.g. 2005
  53. * @return array
  54. */
  55. function get_calendar_items($month, $year)
  56. {
  57. global $_user, $_course;
  58. global $is_allowed_to_edit;
  59. // database variables
  60. $TABLEAGENDA=Database::get_course_table(TABLE_AGENDA);
  61. $TABLE_ITEM_PROPERTY=Database::get_course_table(TABLE_ITEM_PROPERTY);
  62. $group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  63. if (is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  64. {
  65. //echo "course admin";
  66. // added GROUP BY agenda.id to prevent double display of a message that has been sent to two groups
  67. $sql="SELECT
  68. DISTINCT agenda.*, toolitemproperties.*
  69. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  70. WHERE agenda.id = toolitemproperties.ref ".
  71. //$show_all_current.
  72. " AND MONTH(agenda.start_date)='".$month."' AND YEAR(agenda.start_date)='".$year."'
  73. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  74. AND toolitemproperties.visibility='1'
  75. GROUP BY agenda.id ".
  76. "ORDER BY start_date ";
  77. //.$sort;
  78. }
  79. // if the user is not an administrator of that course
  80. else
  81. {
  82. //echo "GEEN course admin";
  83. if (is_array($group_memberships))
  84. {
  85. $sql="SELECT
  86. agenda.*, toolitemproperties.*
  87. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  88. WHERE agenda.id = toolitemproperties.ref ".
  89. //$show_all_current.
  90. " AND MONTH(agenda.start_date)='".$month."'
  91. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  92. AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  93. AND toolitemproperties.visibility='1'"
  94. ."ORDER BY start_date ";
  95. //.$sort;
  96. }
  97. else
  98. {
  99. $sql="SELECT
  100. agenda.*, toolitemproperties.*
  101. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  102. WHERE agenda.id = toolitemproperties.ref ".
  103. //$show_all_current.
  104. " AND MONTH(agenda.start_date)='".$month."'
  105. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  106. AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  107. AND toolitemproperties.visibility='1' ".
  108. "ORDER BY start_date ";
  109. //.$sort;
  110. }
  111. }
  112. $result=api_sql_query($sql,__FILE__,__LINE__);
  113. $data=array();
  114. while ($row=mysql_fetch_array($result))
  115. {
  116. $datum_item=(int)substr($row["start_date"],8,2);
  117. //$dag_item=date("d",strtotime($datum_item));
  118. $data[$datum_item]=intval($datum_item);
  119. }
  120. return $data;
  121. }
  122. /**
  123. * show the mini calender of the given month
  124. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  125. * @param array an array containing all the agenda items for the given month
  126. * @param integer $month: the integer value of the month we are viewing
  127. * @param integer $year: the 4-digit year indication e.g. 2005
  128. * @param string $monthName: the language variable for the mont name
  129. * @return html code
  130. * @todo refactor this so that $monthName is no longer needed as a parameter
  131. */
  132. function display_minimonthcalendar($agendaitems, $month, $year, $monthName)
  133. {
  134. global $DaysShort;
  135. //Handle leap year
  136. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  137. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  138. $numberofdays[2] = 29;
  139. //Get the first day of the month
  140. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  141. //Start the week on monday
  142. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  143. $backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  144. $forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".$_GET['coursePath']."&amp;courseCode=".$_GET['courseCode']."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  145. echo "<table id=\"smallcalendar\">\n",
  146. "<tr class=\"title\">\n",
  147. "<td width=\"10%\"><a href=\"", $backwardsURL, "\"></a></td>\n",
  148. "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n",
  149. "<td width=\"10%\"><a href=\"", $forewardsURL, "\"></a></td>\n", "</tr>\n";
  150. echo "<tr>\n";
  151. for ($ii = 1; $ii < 8; $ii ++)
  152. {
  153. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  154. }
  155. echo "</tr>\n";
  156. $curday = -1;
  157. $today = getdate();
  158. while ($curday <= $numberofdays[$month])
  159. {
  160. echo "<tr>\n";
  161. for ($ii = 0; $ii < 7; $ii ++)
  162. {
  163. if (($curday == -1) && ($ii == $startdayofweek))
  164. {
  165. $curday = 1;
  166. }
  167. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  168. {
  169. $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
  170. $dayheader = "$curday";
  171. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon']))
  172. {
  173. $dayheader = "$curday";
  174. $class = "class=\"days_today\"";
  175. }
  176. echo "\t<td ".$class.">";
  177. if ($agendaitems[$curday] <> "")
  178. {
  179. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."\">".$dayheader."</a>";
  180. }
  181. else
  182. {
  183. echo $dayheader;
  184. }
  185. // "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>\n";
  186. echo "</td>\n";
  187. $curday ++;
  188. }
  189. else
  190. {
  191. echo "<td>&nbsp;</td>\n";
  192. }
  193. }
  194. echo "</tr>\n";
  195. }
  196. echo "</table>\n";
  197. }
  198. /**
  199. * show the calender of the given month
  200. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  201. * @param integer $month: the integer value of the month we are viewing
  202. * @param integer $year: the 4-digit year indication e.g. 2005
  203. * @return html code
  204. */
  205. function display_monthcalendar($month, $year)
  206. {
  207. global $MonthsLong;
  208. global $DaysShort;
  209. global $origin;
  210. // grabbing all the calendar items for this year and storing it in a array
  211. $data=get_calendar_items($month,$year);
  212. //Handle leap year
  213. $numberofdays = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  214. if (($year%400 == 0) or ($year%4==0 and $year%100<>0)) $numberofdays[2] = 29;
  215. //Get the first day of the month
  216. $dayone = getdate(mktime(0,0,0,$month,1,$year));
  217. //Start the week on monday
  218. $startdayofweek = $dayone['wday']<>0 ? ($dayone['wday']-1) : 6;
  219. $backwardsURL = api_get_self()."?".api_get_cidreq()."&origin=$origin&amp;month=".($month==1 ? 12 : $month-1)."&amp;year=".($month==1 ? $year-1 : $year);
  220. $forewardsURL = api_get_self()."?".api_get_cidreq()."&origin=$origin&amp;month=".($month==12 ? 1 : $month+1)."&amp;year=".($month==12 ? $year+1 : $year);
  221. $maand_array_maandnummer=$month-1;
  222. echo "<table id=\"smallcalendar\">\n",
  223. "<tr class=\"title\">\n",
  224. "<td width=\"10%\"><a href=\"",$backwardsURL,"\"></a></td>\n",
  225. "<td width=\"80%\" colspan=\"5\">",$MonthsLong[$maand_array_maandnummer]," ",$year,"</td>\n",
  226. "<td width=\"10%\"><a href=\"",$forewardsURL,"\"></a></td>\n",
  227. "</tr>\n";
  228. echo "<tr>\n";
  229. for ($ii=1;$ii<8; $ii++)
  230. {
  231. echo "<td id=\"weekdays\">",$DaysShort[$ii%7],"</td>\n";
  232. }
  233. echo "</tr>\n";
  234. $curday = -1;
  235. $today = getdate();
  236. while ($curday <=$numberofdays[$month])
  237. {
  238. echo "<tr>\n";
  239. for ($ii=0; $ii<7; $ii++)
  240. {
  241. if (($curday == -1)&&($ii==$startdayofweek))
  242. {
  243. $curday = 1;
  244. }
  245. if (($curday>0)&&($curday<=$numberofdays[$month]))
  246. {
  247. $bgcolor = $ii<5 ? "class=\"alternativeBgLight\"" : "class=\"alternativeBgDark\"";
  248. $dayheader = "$curday";
  249. if (in_array($curday,$data))
  250. { $dayheader="<a href='".api_get_self()."?".api_get_cidreq()."&origin=$origin&amp;month=$month&amp;year=$year&amp;day=$curday#$curday'>".$curday."</a>"; }
  251. if (($curday==$today['mday'])&&($year ==$today['year'])&&($month == $today['mon']))
  252. {
  253. echo "<td id=\"today\" ",$bgcolor,"\">".$dayheader." \n";
  254. }
  255. else
  256. {
  257. echo "<td id=\"days\" ",$bgcolor,"\">".$dayheader." \n";
  258. }
  259. echo "</td>\n";
  260. $curday++;
  261. }
  262. else
  263. {
  264. echo "<td>&nbsp;</td>";
  265. }
  266. }
  267. echo "</tr>";
  268. }
  269. echo "</table>";
  270. }
  271. /**
  272. * returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array
  273. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  274. * @return javascript code
  275. */
  276. function to_javascript()
  277. {
  278. $Send2All=get_lang("Send2All");
  279. return "<script type=\"text/javascript\" language=\"JavaScript\">
  280. <!-- Begin javascript menu swapper
  281. function move(fbox, tbox)
  282. {
  283. var arrFbox = new Array();
  284. var arrTbox = new Array();
  285. var arrLookup = new Array();
  286. var i;
  287. for (i = 0; i < tbox.options.length; i++)
  288. {
  289. arrLookup[tbox.options[i].text] = tbox.options[i].value;
  290. arrTbox[i] = tbox.options[i].text;
  291. }
  292. var fLength = 0;
  293. var tLength = arrTbox.length;
  294. for(i = 0; i < fbox.options.length; i++)
  295. {
  296. arrLookup[fbox.options[i].text] = fbox.options[i].value;
  297. if (fbox.options[i].selected && fbox.options[i].value != \"\")
  298. {
  299. arrTbox[tLength] = fbox.options[i].text;
  300. tLength++;
  301. }
  302. else
  303. {
  304. arrFbox[fLength] = fbox.options[i].text;
  305. fLength++;
  306. }
  307. }
  308. arrFbox.sort();
  309. arrTbox.sort();
  310. fbox.length = 0;
  311. tbox.length = 0;
  312. var c;
  313. for(c = 0; c < arrFbox.length; c++)
  314. {
  315. var no = new Option();
  316. no.value = arrLookup[arrFbox[c]];
  317. no.text = arrFbox[c];
  318. fbox[c] = no;
  319. }
  320. for(c = 0; c < arrTbox.length; c++)
  321. {
  322. var no = new Option();
  323. no.value = arrLookup[arrTbox[c]];
  324. no.text = arrTbox[c];
  325. tbox[c] = no;
  326. }
  327. }
  328. function validate()
  329. {
  330. var f = document.new_calendar_item;
  331. f.submit();
  332. return true;
  333. }
  334. function selectAll(cbList,bSelect,showwarning)
  335. {
  336. if (cbList.length < 1) {
  337. alert(\"$Send2All\");
  338. return;
  339. }
  340. for (var i=0; i<cbList.length; i++)
  341. cbList[i].selected = cbList[i].checked = bSelect
  342. }
  343. function reverseAll(cbList)
  344. {
  345. for (var i=0; i<cbList.length; i++)
  346. {
  347. cbList[i].checked = !(cbList[i].checked)
  348. cbList[i].selected = !(cbList[i].selected)
  349. }
  350. }
  351. // End -->
  352. </script>";
  353. }
  354. /**
  355. * returns the javascript for setting a filter. This is a jump menu
  356. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  357. * @return javascript code
  358. */
  359. function user_group_filter_javascript()
  360. {
  361. return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  362. <!--
  363. function MM_jumpMenu(targ,selObj,restore){
  364. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  365. if (restore) selObj.selectedIndex=0;
  366. }
  367. //-->
  368. </script>
  369. ";
  370. }
  371. /**
  372. * this function gets all the users of the current course
  373. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  374. * @return array: associative array where the key is the id of the user and the value is an array containing
  375. the first name, the last name, the user id
  376. */
  377. function get_course_users()
  378. {
  379. global $tbl_user;
  380. global $tbl_courseUser, $tbl_session_course_user;
  381. global $_cid;
  382. // not 100% if this is necessary, this however prevents a notice
  383. if (!isset($courseadmin_filter))
  384. {$courseadmin_filter='';}
  385. $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName
  386. FROM $tbl_user as u, $tbl_courseUser as cu
  387. WHERE cu.course_code = '".$_cid."'
  388. AND cu.user_id = u.user_id $courseadmin_filter
  389. ORDER BY u.lastname, u.firstname";
  390. $result = api_sql_query($sql,__FILE__,__LINE__);
  391. while($user=mysql_fetch_array($result)){
  392. $users[$user[0]] = $user;
  393. }
  394. if(!empty($_SESSION['id_session'])){
  395. $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName
  396. FROM $tbl_session_course_user AS session_course_user
  397. INNER JOIN $tbl_user u
  398. ON u.user_id = session_course_user.id_user
  399. WHERE id_session='".$_SESSION['id_session']."'
  400. AND course_code='$_cid'";
  401. $result = api_sql_query($sql,__FILE__,__LINE__);
  402. while($user=mysql_fetch_array($result)){
  403. $users[$user[0]] = $user;
  404. }
  405. }
  406. return $users;
  407. }
  408. /**
  409. * this function gets all the groups of the course
  410. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  411. * @return array
  412. */
  413. function get_course_groups()
  414. {
  415. global $tbl_group;
  416. global $tbl_groupUser;
  417. $group_list = array();
  418. $sql = "SELECT g.id, g.name, COUNT(gu.id) userNb
  419. FROM ".$tbl_group." AS g LEFT JOIN ".$tbl_groupUser." gu
  420. ON g.id = gu.group_id
  421. GROUP BY g.id";
  422. $result = api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  423. while ($group_data = mysql_fetch_array($result))
  424. {
  425. $group_list [$group_data['id']] = $group_data;
  426. }
  427. return $group_list;
  428. }
  429. /**
  430. * this function shows the form for sending a message to a specific group or user.
  431. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  432. * @return html code
  433. */
  434. function show_to_form($to_already_selected)
  435. {
  436. $user_list=get_course_users();
  437. $group_list=get_course_groups();
  438. echo "\n<table id=\"recipient_list\" style=\"display: none;\">\n";
  439. echo "\t<tr>\n";
  440. // the form containing all the groups and all the users of the course
  441. echo "\t\t<td>\n";
  442. construct_not_selected_select_form($group_list,$user_list,$to_already_selected);
  443. echo "\t\t</td>\n";
  444. // the buttons for adding or removing groups/users
  445. echo "\n\t\t<td valign=\"middle\">\n";
  446. echo "\t\t<input type=\"button\" ",
  447. "onclick=\"move(this.form.elements[2],this.form.elements[5])\" ",
  448. "value=\" &gt;&gt; \" />",
  449. "\n\t\t<p>&nbsp;</p>",
  450. "\n\t\t<input type=\"button\" ",
  451. "onclick=\"move(this.form.elements[5],this.form.elements[2])\" ",
  452. "value=\" &lt;&lt; \" />";
  453. echo "\t\t</td>\n";
  454. echo "\n\t\t<td>\n";
  455. construct_selected_select_form($group_list,$user_list,$to_already_selected);
  456. echo "\t\t</td>\n";
  457. echo "\t</tr>\n";
  458. echo "</table>";
  459. }
  460. /**
  461. * this function shows the form with the user that were not selected
  462. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  463. * @return html code
  464. */
  465. function construct_not_selected_select_form($group_list=null, $user_list=null,$to_already_selected=array())
  466. {
  467. echo "\t\t<select name=\"not_selected_form[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">\n";
  468. // adding the groups to the select form
  469. if (is_array($group_list))
  470. {
  471. foreach($group_list as $this_group)
  472. {
  473. //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
  474. 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
  475. {
  476. echo "\t\t<option value=\"GROUP:".$this_group['id']."\">",
  477. "G: ",$this_group['name']," &ndash; " . $this_group['userNb'] . " " . get_lang('Users') .
  478. "</option>\n";
  479. }
  480. }
  481. // a divider
  482. echo "\t\t<option value=\"\">----------------------------------</option>\n";
  483. }
  484. // adding the individual users to the select form
  485. foreach($user_list as $this_user)
  486. {
  487. 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
  488. {
  489. echo "\t\t<option value=\"USER:",$this_user['uid'],"\">",
  490. "",$this_user['lastName']," ",$this_user['firstName'],
  491. "</option>\n";
  492. }
  493. }
  494. echo "\t\t</select>\n";
  495. }
  496. /**
  497. * This function shows the form with the user that were selected
  498. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  499. * @return html code
  500. */
  501. function construct_selected_select_form($group_list=null, $user_list=null,$to_already_selected)
  502. {
  503. // we separate the $to_already_selected array (containing groups AND users into
  504. // two separate arrays
  505. if (is_array($to_already_selected))
  506. {
  507. $groupuser=separate_users_groups($to_already_selected);
  508. }
  509. $groups_to_already_selected=$groupuser['groups'];
  510. $users_to_already_selected=$groupuser['users'];
  511. // we load all the groups and all the users into a reference array that we use to search the name of the group / user
  512. $ref_array_groups=get_course_groups();
  513. $ref_array_users=get_course_users();
  514. // we construct the form of the already selected groups / users
  515. echo "\t\t<select name=\"selectedform[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">";
  516. if(is_array($to_already_selected))
  517. {
  518. foreach($to_already_selected as $groupuser)
  519. {
  520. list($type,$id)=explode(":",$groupuser);
  521. if ($type=="GROUP")
  522. {
  523. echo "\t\t<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  524. }
  525. else
  526. {
  527. echo "\t\t<option value=\"".$groupuser."\">".$ref_array_users[$id]['lastName']." ".$ref_array_users[$id]['firstName']."</option>";
  528. }
  529. }
  530. }
  531. echo "</select>\n";
  532. }
  533. /**
  534. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also
  535. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  536. * @return integer the id of the last added agenda item
  537. */
  538. function store_new_agenda_item()
  539. {
  540. global $_user, $_course;
  541. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  542. // some filtering of the input data
  543. $title=strip_tags(trim($_POST['title'])); // no html allowed in the title
  544. $content=trim($_POST['content']);
  545. $start_date=(int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00";
  546. $end_date=(int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00";
  547. // store in the table calendar_event
  548. $sql = "INSERT INTO ".$TABLEAGENDA."
  549. (title,content, start_date, end_date)
  550. VALUES
  551. ('".$title."','".$content."', '".$start_date."','".$end_date."')";
  552. $result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  553. $last_id=mysql_insert_id();
  554. // store in last_tooledit (first the groups, then the users
  555. $to=$_POST['selectedform'];
  556. if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) // !is_null($to): when no user is selected we send it to everyone
  557. {
  558. $send_to=separate_users_groups($to);
  559. // storing the selected groups
  560. if (is_array($send_to['groups']))
  561. {
  562. foreach ($send_to['groups'] as $group)
  563. {
  564. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'], $group,'',$start_date, $end_date);
  565. }
  566. }
  567. // storing the selected users
  568. if (is_array($send_to['users']))
  569. {
  570. foreach ($send_to['users'] as $user)
  571. {
  572. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'],'',$user, $start_date,$end_date);
  573. }
  574. }
  575. }
  576. else // the message is sent to everyone, so we set the group to 0
  577. {
  578. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'], '','',$start_date,$end_date);
  579. }
  580. // storing the resources
  581. store_resources($_SESSION['source_type'],$last_id);
  582. return $last_id;
  583. }
  584. /**
  585. * Stores the given agenda item as an announcement (unlinked copy)
  586. * @param integer Agenda item's ID
  587. * @return integer New announcement item's ID
  588. */
  589. function store_agenda_item_as_announcement($item_id){
  590. $table_agenda = Database::get_course_table(TABLE_AGENDA);
  591. $table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT);
  592. //check params
  593. if(empty($item_id) or $item_id != strval(intval($item_id))){return -1;}
  594. //get the agenda item
  595. $sql = "SELECT * FROM $table_agenda WHERE id = '".$item_id."'";
  596. $res = api_sql_query($sql,__FILE__,__LINE__);
  597. if(Database::num_rows($res)>0){
  598. $row = Database::fetch_array($res);
  599. //we have the agenda event, copy it
  600. //get the maximum value for display order in announcement table
  601. $sql_max = "SELECT MAX(display_order) FROM $table_ann";
  602. $res_max = api_sql_query($sql_max,__FILE__,__LINE__);
  603. $row_max = Database::fetch_array($res_max);
  604. $max = $row_max[0]+1;
  605. //build the announcement text
  606. $content = $row['start_date']." - ".$row['end_date']."\n\n".$row['content'];
  607. //insert announcement
  608. $sql_ins = "INSERT INTO $table_ann (title,content,end_date,display_order) " .
  609. "VALUES ('".$row['title']."','$content','".$row['end_date']."','$max')";
  610. $res_ins = api_sql_query($sql_ins,__FILE__,__LINE__);
  611. if($res > 0)
  612. {
  613. $ann_id = Database::get_last_insert_id();
  614. //Now also get the list of item_properties rows for this agenda_item (calendar_event)
  615. //and copy them into announcement item_properties
  616. $table_props = Database::get_course_table(TABLE_ITEM_PROPERTY);
  617. $sql_props = "SELECT * FROM $table_props WHERE tool = 'calendar_event' AND ref='$item_id'";
  618. $res_props = api_sql_query($sql_props,__FILE__,__LINE__);
  619. if(Database::num_rows($res_props)>0)
  620. {
  621. while($row_props = Database::fetch_array($res_props))
  622. {
  623. //insert into announcement item_property
  624. $time = date("Y-m-d H:i:s", time());
  625. $sql_ins_props = "INSERT INTO $table_props " .
  626. "(tool, insert_user_id, insert_date, " .
  627. "lastedit_date, ref, lastedit_type," .
  628. "lastedit_user_id, to_group_id, to_user_id, " .
  629. "visibility, start_visible, end_visible)" .
  630. " VALUES " .
  631. "('announcement','".$row_props['insert_user_id']."','".$time."'," .
  632. "'$time','$ann_id','AnnouncementAdded'," .
  633. "'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."'," .
  634. "'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')";
  635. $res_ins_props = api_sql_query($sql_ins_props,__FILE__,__LINE__);
  636. if($res_ins_props <= 0){
  637. error_log('SQL Error in '.__FILE__.' at line '.__LINE__.': '.$sql_ins_props);
  638. }else{
  639. //copy was a success
  640. return $ann_id;
  641. }
  642. }
  643. }
  644. }else{
  645. return -1;
  646. }
  647. }
  648. return -1;
  649. }
  650. /**
  651. * This function separates the users from the groups
  652. * users have a value USER:XXX (with XXX the dokeos id
  653. * groups have a value GROUP:YYY (with YYY the group id)
  654. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  655. * @return array
  656. */
  657. function separate_users_groups($to)
  658. {
  659. foreach($to as $to_item)
  660. {
  661. list($type, $id) = explode(':', $to_item);
  662. switch($type)
  663. {
  664. case 'GROUP':
  665. $grouplist[] =$id;
  666. break;
  667. case 'USER':
  668. $userlist[] =$id;
  669. break;
  670. }
  671. }
  672. $send_to['groups']=$grouplist;
  673. $send_to['users']=$userlist;
  674. return $send_to;
  675. }
  676. /**
  677. * returns all the users and all the groups a specific Agenda item has been sent to
  678. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  679. * @return array
  680. */
  681. function sent_to($tool, $id)
  682. {
  683. global $_course;
  684. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  685. $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'";
  686. $result=api_sql_query($sql,__FILE__,__LINE__);
  687. while ($row=mysql_fetch_array($result))
  688. {
  689. // if to_group_id is null then it is sent to a specific user
  690. // if to_group_id = 0 then it is sent to everybody
  691. if (!is_null($row['to_group_id']) )
  692. {
  693. $sent_to_group[]=$row['to_group_id'];
  694. //echo $row['to_group_id'];
  695. }
  696. // if to_user_id <> 0 then it is sent to a specific user
  697. if ($row['to_user_id']<>0)
  698. {
  699. $sent_to_user[]=$row['to_user_id'];
  700. }
  701. }
  702. if (isset($sent_to_group))
  703. {
  704. $sent_to['groups']=$sent_to_group;
  705. }
  706. if (isset($sent_to_user))
  707. {
  708. $sent_to['users']=$sent_to_user;
  709. }
  710. return $sent_to;
  711. }
  712. /**
  713. * constructs the form to display all the groups and users the message has been sent to
  714. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  715. * @param array $sent_to_array: a 2 dimensional array containing the groups and the users
  716. * the first level is a distinction between groups and users: $sent_to_array['groups'] and $sent_to_array['users']
  717. * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array containing all the id's of the
  718. * groups (resp. users) who have received this message.
  719. * @return html
  720. */
  721. function sent_to_form($sent_to_array)
  722. {
  723. // we find all the names of the groups
  724. $group_names=get_course_groups();
  725. count($sent_to_array);
  726. // we count the number of users and the number of groups
  727. if (isset($sent_to_array['users']))
  728. {
  729. $number_users=count($sent_to_array['users']);
  730. }
  731. else
  732. {
  733. $number_users=0;
  734. }
  735. if (isset($sent_to_array['groups']))
  736. {
  737. $number_groups=count($sent_to_array['groups']);
  738. }
  739. else
  740. {
  741. $number_groups=0;
  742. }
  743. $total_numbers=$number_users+$number_groups;
  744. // starting the form if there is more than one user/group
  745. if ($total_numbers >1)
  746. {
  747. $output="<select name=\"sent to\">\n";
  748. $output.="<option>".get_lang("SentTo")."</option>";
  749. // outputting the name of the groups
  750. if (is_array($sent_to_array['groups']))
  751. {
  752. foreach ($sent_to_array['groups'] as $group_id)
  753. {
  754. $output.="\t<option value=\"\">G: ".$group_names[$group_id]['name']."</option>\n";
  755. }
  756. }
  757. if (isset($sent_to_array['users']))
  758. {
  759. if (is_array($sent_to_array['users']))
  760. {
  761. foreach ($sent_to_array['users'] as $user_id)
  762. {
  763. $user_info=api_get_user_info($user_id);
  764. $output.="\t<option value=\"\">".$user_info['firstName']." ".$user_info['lastName']."</option>\n";
  765. }
  766. }
  767. }
  768. // ending the form
  769. $output.="</select>\n";
  770. }
  771. else // there is only one user/group
  772. {
  773. if (is_array($sent_to_array['users']))
  774. {
  775. $user_info=api_get_user_info($sent_to_array['users'][0]);
  776. echo $user_info['firstName']." ".$user_info['lastName'];
  777. }
  778. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]!==0)
  779. {
  780. $group_id=$sent_to_array['groups'][0];
  781. echo $group_names[$group_id]['name'];
  782. }
  783. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]==0)
  784. {
  785. echo get_lang("Everybody");
  786. }
  787. //.$sent_to_array['groups'][0];
  788. }
  789. echo $output;
  790. }
  791. /**
  792. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  793. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  794. */
  795. function show_group_filter_form()
  796. {
  797. $group_list=get_course_groups();
  798. echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
  799. echo "<option value=\"agenda.php?group=none\">show all groups</option>";
  800. foreach($group_list as $this_group)
  801. {
  802. // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
  803. echo "<option value=\"agenda.php?group=".$this_group['id']."\" ";
  804. echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
  805. echo ">".$this_group['name']."</option>";
  806. }
  807. echo "</select>";
  808. }
  809. /**
  810. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  811. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  812. */
  813. function show_user_filter_form()
  814. {
  815. $user_list=get_course_users();
  816. echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
  817. echo "<option value=\"agenda.php?user=none\">show all users</option>";
  818. foreach($user_list as $this_user)
  819. {
  820. // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  821. echo "<option value=\"agenda.php?user=".$this_user['uid']."\" ";
  822. echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
  823. echo ">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  824. }
  825. echo "</select>";
  826. }
  827. /**
  828. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  829. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  830. */
  831. function show_user_group_filter_form()
  832. {
  833. echo "\n<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
  834. echo "\n\t<option value=\"agenda.php?user=none\">".get_lang("ShowAll")."</option>";
  835. // Groups
  836. echo "\n\t<optgroup label=\"".get_lang("Groups")."\">";
  837. $group_list=get_course_groups();
  838. foreach($group_list as $this_group)
  839. {
  840. // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
  841. echo "\n\t\t<option value=\"agenda.php?group=".$this_group['id']."\" ";
  842. echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
  843. echo ">".$this_group['name']."</option>";
  844. }
  845. echo "\n\t</optgroup>";
  846. // Users
  847. echo "\n\t<optgroup label=\"".get_lang("Users")."\">";
  848. $user_list=get_course_users();
  849. foreach($user_list as $this_user)
  850. {
  851. // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  852. echo "\n\t\t<option value=\"agenda.php?user=".$this_user['uid']."\" ";
  853. echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
  854. echo ">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  855. }
  856. echo "\n\t</optgroup>";
  857. echo "</select>";
  858. }
  859. /**
  860. * This tools loads all the users and all the groups who have received a specific item (in this case an agenda item)
  861. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  862. */
  863. function load_edit_users($tool, $id)
  864. {
  865. global $_course;
  866. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  867. $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='$tool' AND ref='$id'";
  868. $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  869. while ($row=mysql_fetch_array($result))
  870. {
  871. $to_group=$row['to_group_id'];
  872. switch ($to_group)
  873. {
  874. // it was send to one specific user
  875. case null:
  876. $to[]="USER:".$row['to_user_id'];
  877. break;
  878. // it was sent to everyone
  879. case 0:
  880. return "everyone";
  881. exit;
  882. break;
  883. default:
  884. $to[]="GROUP:".$row['to_group_id'];
  885. }
  886. }
  887. return $to;
  888. }
  889. /**
  890. * This functions swithes the visibility a course resource using the visible field in 'last_tooledit' values: 0 = invisible
  891. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  892. */
  893. function change_visibility($tool,$id)
  894. {
  895. global $_course;
  896. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  897. $sql="SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".TOOL_CALENDAR_EVENT."' AND ref='$id'";
  898. $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  899. $row=mysql_fetch_array($result);
  900. if ($row['visibility']=='1')
  901. {
  902. $sql_visibility="UPDATE $TABLE_ITEM_PROPERTY SET visibility='0' WHERE tool='$tool' AND ref='$id'";
  903. api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,"invisible",api_get_user_id());
  904. }
  905. else
  906. {
  907. $sql_visibility="UPDATE $TABLE_ITEM_PROPERTY SET visibility='1' WHERE tool='$tool' AND ref='$id'";
  908. api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,"visible",api_get_user_id());
  909. }
  910. }
  911. /**
  912. * The links that allows the course administrator to add a new agenda item, to filter on groups or users
  913. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  914. */
  915. function display_courseadmin_links()
  916. {
  917. echo "<li><a href='".api_get_self()."?".api_get_cidreq()."&action=add&amp;origin=".$_GET['origin']."'><img src=\"../img/view_more_stats.gif\" alt=\"".get_lang('MoreStats')."\" border=\"0\" /> ".get_lang("AgendaAdd")."</a><br /></li>";
  918. if (empty ($_SESSION['toolgroup']))
  919. {
  920. echo "<li>".get_lang('UserGroupFilter')."<br/>";
  921. echo "<form name=\"filter\">";
  922. show_user_group_filter_form();
  923. echo "</form>";
  924. }
  925. echo "</li>";
  926. }
  927. /**
  928. * The links that allows the student AND course administrator to show all agenda items and sort up/down
  929. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  930. */
  931. function display_student_links()
  932. {
  933. global $show;
  934. if ($_SESSION['sort'] == 'DESC')
  935. {
  936. echo "<li><a href='".api_get_self()."?".api_get_cidreq()."&sort=asc&amp;origin=".$_GET['origin']."'>".Display::return_icon('calendar_up.gif',get_lang('AgendaSortChronologicallyUp')).' '.get_lang("AgendaSortChronologicallyUp")."</a></li>";
  937. }
  938. else
  939. {
  940. echo "<li><a href='".api_get_self()."?".api_get_cidreq()."&sort=desc&amp;origin=".$_GET['origin']."'>".Display::return_icon('calendar_down.gif',get_lang('AgendaSortChronologicallyDown')).' '.get_lang("AgendaSortChronologicallyDown")."</a></li>";
  941. }
  942. // showing the link to show all items or only those of the current month
  943. if ($_SESSION['show']=="showcurrent")
  944. {
  945. echo "<li><a href='".api_get_self()."?".api_get_cidreq()."&action=showall&amp;origin=".$_GET['origin']."'>".Display::return_icon('calendar_select.gif').' '.get_lang("ShowAll")."</a></li>";
  946. }
  947. else
  948. {
  949. echo "<li><a href='".api_get_self()."?".api_get_cidreq()."&action=showcurrent&amp;origin=".$_GET['origin']."'>".Display::return_icon('calendar_month.gif').' '.get_lang("ShowCurrent")."</a></li>";
  950. }
  951. }
  952. /**
  953. * get all the information of the agenda_item from the database
  954. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  955. * @param integer the id of the agenda item we are getting all the information of
  956. * @return an associative array that contains all the information of the agenda item. The keys are the database fields
  957. */
  958. function get_agenda_item($id)
  959. {
  960. global $TABLEAGENDA;
  961. $id=(int)addslashes($_GET['id']);
  962. $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."'";
  963. $result = api_sql_query($sql,__FILE__,__LINE__);
  964. $entry_to_edit = mysql_fetch_array($result);
  965. $item['title'] = $entry_to_edit["title"];
  966. $item['content'] = $entry_to_edit["content"];
  967. $item['start_date'] = $entry_to_edit["start_date"];
  968. $item['end_date'] = $entry_to_edit["end_date"];
  969. $item['to'] = load_edit_users(TOOL_CALENDAR_EVENT, $id);
  970. // if the item has been sent to everybody then we show the compact to form
  971. if ($item['to']=="everyone")
  972. {
  973. $_SESSION['allow_individual_calendar']="hide";
  974. }
  975. else
  976. {
  977. $_SESSION['allow_individual_calendar']="show";
  978. }
  979. //echo "<br />IN get_agenda_item".$_SESSION['allow_individual_calendar'];
  980. return $item;
  981. }
  982. /**
  983. * This is the function that updates an agenda item. It does 3 things
  984. * 1. storethe start_date, end_date, title and message in the calendar_event table
  985. * 2. store the groups/users who this message is meant for in the item_property table
  986. * 3. modify the attachments (if needed)
  987. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  988. */
  989. function store_edited_agenda_item()
  990. {
  991. global $_user, $_course;
  992. // database definitions
  993. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  994. // STEP 1: editing the calendar_event table
  995. // 1.a. some filtering of the input data
  996. $id=(int)$_POST['id'];
  997. $title=strip_tags(trim($_POST['title'])); // no html allowed in the title
  998. $content=trim($_POST['content']);
  999. $start_date=(int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00";
  1000. $end_date=(int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00";
  1001. $to=$_POST['selectedform'];
  1002. // 1.b. the actual saving in calendar_event table
  1003. $edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
  1004. // step 2: editing the item_propery table (=delete all and add the new destination users/groups)
  1005. if ($edit_result=true)
  1006. {
  1007. // 2.a. delete everything for the users
  1008. $sql_delete="DELETE FROM ".$TABLE_ITEM_PROPERTY." WHERE ref='$id' AND tool='".TOOL_CALENDAR_EVENT."'";
  1009. $result = api_sql_query($sql_delete,__FILE__,__LINE__) or die (mysql_error());
  1010. // 2.b. storing the new users/groups
  1011. if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
  1012. {
  1013. $send_to=separate_users_groups($to);
  1014. // storing the selected groups
  1015. if (is_array($send_to['groups']))
  1016. {
  1017. foreach ($send_to['groups'] as $group)
  1018. {
  1019. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", $_user['user_id'], $group,'',$start_date, $end_date);
  1020. }
  1021. }
  1022. // storing the selected users
  1023. if (is_array($send_to['users']))
  1024. {
  1025. foreach ($send_to['users'] as $user)
  1026. {
  1027. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", $_user['user_id'],'',$user, $start_date,$end_date);
  1028. }
  1029. }
  1030. }
  1031. else // the message is sent to everyone, so we set the group to 0
  1032. {
  1033. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id,"AgendaModified", $_user['user_id'], '','',$start_date,$end_date);
  1034. }
  1035. } //if ($edit_result=true)
  1036. // step 3: update the attachments (=delete all and add those in the session
  1037. update_added_resources("Agenda", $id);
  1038. // return the message;
  1039. Display::display_normal_message(get_lang("EditSuccess"));
  1040. }
  1041. /**
  1042. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit)
  1043. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1044. */
  1045. function save_edit_agenda_item($id,$title,$content,$start_date,$end_date)
  1046. {
  1047. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1048. // store the modifications in the table calendar_event
  1049. $sql = "UPDATE ".$TABLEAGENDA."
  1050. SET title='".$title."',
  1051. content='".$content."',
  1052. start_date='".$start_date."',
  1053. end_date='".$end_date."'
  1054. WHERE id='".$id."'";
  1055. $result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  1056. return true;
  1057. }
  1058. /**
  1059. * This is the function that deletes an agenda item.
  1060. * The agenda item is no longer fycically deleted but the visibility in the item_property table is set to 2
  1061. * which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
  1062. * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
  1063. * by the course administrator
  1064. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1065. * @param integer the id of the agenda item wa are deleting
  1066. */
  1067. function delete_agenda_item($id)
  1068. {
  1069. global $_course;
  1070. if (is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  1071. {
  1072. if (isset($_GET['id'])&&$_GET['id']&&isset($_GET['action'])&&$_GET['action']=="delete")
  1073. {
  1074. //$sql = "DELETE FROM ".$TABLEAGENDA." WHERE id='$id'";
  1075. //$sql= "UPDATE ".$TABLE_ITEM_PROPERTY." SET visibility='2' WHERE tool='Agenda' and ref='$id'";
  1076. //$result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  1077. $id=(int)addslashes($_GET['id']);
  1078. api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,"delete");
  1079. // delete the resources that were added to this agenda item
  1080. // 2DO: as we no longer fysically delete the agenda item (to make it possible to 'restore'
  1081. // deleted items, we should not delete the added resources either.
  1082. // 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)
  1083. //resetting the $id;
  1084. $id=null;
  1085. // displaying the result message in the yellow box
  1086. Display::display_normal_message(get_lang("AgendaDeleteSuccess"));
  1087. } // if (isset($id)&&$id&&isset($action)&&$action=="delete")
  1088. } // if ($is_allowed_to_edit)
  1089. }
  1090. /**
  1091. * Makes an agenda item visible or invisible for a student
  1092. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1093. * @param integer id the id of the agenda item we are changing the visibility of
  1094. */
  1095. function showhide_agenda_item($id)
  1096. {
  1097. global $nameTools;
  1098. /*==================================================
  1099. SHOW / HIDE A CALENDAR ITEM
  1100. ==================================================*/
  1101. // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following:
  1102. // change visibility -> studentview -> course manager view
  1103. if ((is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) and $_GET['isStudentView']<>"false")
  1104. {
  1105. if (isset($_GET['id'])&&$_GET['id']&&isset($_GET['action'])&&$_GET['action']=="showhide")
  1106. {
  1107. $id=(int)addslashes($_GET['id']);
  1108. change_visibility($nameTools,$id);
  1109. Display::display_normal_message(get_lang("VisibilityChanged"));
  1110. }
  1111. }
  1112. }
  1113. /**
  1114. * Displays all the agenda items
  1115. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1116. * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
  1117. */
  1118. function display_agenda_items()
  1119. {
  1120. global $TABLEAGENDA;
  1121. global $TABLE_ITEM_PROPERTY;
  1122. global $select_month, $select_year;
  1123. global $DaysShort, $DaysLong, $MonthsLong;
  1124. global $is_courseAdmin;
  1125. global $dateFormatLong, $timeNoSecFormat,$charset, $_user, $_course;
  1126. // getting the group memberships
  1127. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  1128. // getting the name of the groups
  1129. $group_names=get_course_groups();
  1130. /*--------------------------------------------------
  1131. CONSTRUCT THE SQL STATEMENT
  1132. --------------------------------------------------*/
  1133. // this is to make a difference between showing everything (all months) or only the current month)
  1134. // $show_all_current is a part of the sql statement
  1135. if ($_SESSION['show']!=="showall")
  1136. {
  1137. $show_all_current=" AND MONTH(start_date)=$select_month AND year(start_date)=$select_year";
  1138. }
  1139. else
  1140. {
  1141. $show_all_current="";
  1142. }
  1143. // 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
  1144. $user_id=$_user['user_id'];
  1145. if ($_SESSION['user']!==null)
  1146. {
  1147. $user_id=$_SESSION['user'];
  1148. }
  1149. if ($_SESSION['group']!==null)
  1150. {
  1151. $group_id=$_SESSION['group'];
  1152. }
  1153. if ($_SESSION['toolgroup']!==null)
  1154. {
  1155. $group_id=$_SESSION['toolgroup'];
  1156. }
  1157. //echo "user:".$_SESSION['user']."group: ".$_SESSION['group'];
  1158. // A. you are a course admin
  1159. //if ($is_courseAdmin)
  1160. if (is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  1161. {
  1162. // A.1. you are a course admin with a USER filter
  1163. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  1164. if (!empty($_SESSION['user']))
  1165. {
  1166. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_SESSION['user']);
  1167. if (is_array($group_memberships))
  1168. {
  1169. $sql="SELECT
  1170. agenda.*, toolitemproperties.*
  1171. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1172. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1173. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1174. AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1175. AND toolitemproperties.visibility='1'
  1176. ORDER BY start_date ".$_SESSION['sort'];
  1177. }
  1178. else
  1179. {
  1180. $sql="SELECT
  1181. agenda.*, toolitemproperties.*
  1182. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1183. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1184. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1185. AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0')
  1186. AND toolitemproperties.visibility='1'
  1187. ORDER BY start_date ".$_SESSION['sort'];
  1188. }
  1189. }
  1190. // A.2. you are a course admin with a GROUP filter
  1191. // => see only the messages of this specific group
  1192. elseif (!empty($_SESSION['group']))
  1193. {
  1194. $sql="SELECT
  1195. agenda.*, toolitemproperties.*
  1196. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1197. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1198. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1199. AND ( toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0')
  1200. AND toolitemproperties.visibility='1'
  1201. GROUP BY toolitemproperties.ref
  1202. ORDER BY start_date ".$_SESSION['sort'];
  1203. }
  1204. // A.3 you are a course admin without any group or user filter
  1205. else
  1206. {
  1207. // A.3.a you are a course admin without user or group filter but WITH studentview
  1208. // => see all the messages of all the users and groups without editing possibilities
  1209. if ($_GET['isStudentView']=='true')
  1210. {
  1211. $sql="SELECT
  1212. agenda.*, toolitemproperties.*
  1213. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1214. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1215. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1216. AND toolitemproperties.visibility='1'
  1217. GROUP BY toolitemproperties.ref
  1218. ORDER BY start_date ".$_SESSION['sort'];
  1219. }
  1220. // A.3.b you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  1221. // => see all the messages of all the users and groups with editing possibilities
  1222. else
  1223. {
  1224. $sql="SELECT
  1225. agenda.*, toolitemproperties.*
  1226. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1227. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1228. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1229. AND ( toolitemproperties.visibility='0' or toolitemproperties.visibility='1')
  1230. GROUP BY toolitemproperties.ref
  1231. ORDER BY start_date ".$_SESSION['sort'];
  1232. }
  1233. }
  1234. } //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  1235. // B. you are a student
  1236. else
  1237. {
  1238. if (is_array($group_memberships))
  1239. {
  1240. $sql="SELECT
  1241. agenda.*, toolitemproperties.*
  1242. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1243. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1244. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1245. AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1246. AND toolitemproperties.visibility='1'
  1247. ORDER BY start_date ".$_SESSION['sort'];
  1248. }
  1249. else
  1250. {
  1251. if ($_user['user_id'])
  1252. {
  1253. $sql="SELECT
  1254. agenda.*, toolitemproperties.*
  1255. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1256. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1257. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1258. AND ( toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0')
  1259. AND toolitemproperties.visibility='1'
  1260. ORDER BY start_date ".$_SESSION['sort'];
  1261. }
  1262. else
  1263. {
  1264. $sql="SELECT
  1265. agenda.*, toolitemproperties.*
  1266. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1267. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  1268. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1269. AND toolitemproperties.to_group_id='0'
  1270. AND toolitemproperties.visibility='1'
  1271. ORDER BY start_date ".$_SESSION['sort'];
  1272. }
  1273. }
  1274. } // you are a student
  1275. //echo "<pre>".$sql."</pre>";
  1276. $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  1277. $number_items=mysql_num_rows($result);
  1278. /*--------------------------------------------------
  1279. DISPLAY: NO ITEMS
  1280. --------------------------------------------------*/
  1281. if ($number_items==0)
  1282. {
  1283. echo "<table id=\"agenda_list\" ><tr><td>".get_lang("NoAgendaItems")."</td></tr></table>";
  1284. }
  1285. /*--------------------------------------------------
  1286. DISPLAY: THE ITEMS
  1287. --------------------------------------------------*/
  1288. $month_bar="";
  1289. $event_list="";
  1290. $counter=0;
  1291. $export_icon = api_get_path('WEB_IMG_PATH').'export.png';
  1292. $export_icon_low = api_get_path('WEB_IMG_PATH').'export_low_fade.png';
  1293. $export_icon_high = api_get_path('WEB_IMG_PATH').'export_high_fade.png';
  1294. while ($myrow=mysql_fetch_array($result))
  1295. {
  1296. echo "<table class=\"data_table\">\n";
  1297. /*--------------------------------------------------
  1298. display: the month bar
  1299. --------------------------------------------------*/
  1300. // Make the month bar appear only once.
  1301. if ($month_bar != date("m",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"])))
  1302. {
  1303. $month_bar = date("m",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"]));
  1304. echo "\t<tr>\n\t\t<td class=\"agenda_month_divider\" colspan=\"2\" valign=\"top\">".
  1305. ucfirst(format_locale_date("%B %Y",strtotime($myrow["start_date"]))).
  1306. "</td>\n\t</tr>\n";
  1307. }
  1308. /*--------------------------------------------------
  1309. display: the icon, title, destinees of the item
  1310. --------------------------------------------------*/
  1311. echo "\t<tr>\n";
  1312. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  1313. $db_date=(int)date("d",strtotime($myrow["start_date"])).date("n",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"]));
  1314. if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date)
  1315. {
  1316. if ($myrow['visibility']=='0')
  1317. {
  1318. $style="data_hidden";
  1319. $stylenotbold="datanotbold_hidden";
  1320. $text_style="text_hidden";
  1321. }
  1322. else
  1323. {
  1324. $style="data";
  1325. $stylenotbold="datanotbold";
  1326. $text_style="text";
  1327. }
  1328. }
  1329. else
  1330. {
  1331. $style="datanow";
  1332. $stylenotbold="datanotboldnow";
  1333. $text_style="textnow";
  1334. }
  1335. echo "\t\t<th>\n";
  1336. // adding an internal anchor
  1337. echo "\t\t\t<a name=\"".(int)date("d",strtotime($myrow["start_date"]))."\"></a>";
  1338. // the icons. If the message is sent to one or more specific users/groups
  1339. // we add the groups icon
  1340. // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon
  1341. Display::display_icon('agenda.gif', get_lang('Agenda'));
  1342. if ($myrow['to_group_id']!=='0')
  1343. {
  1344. echo "<img src=\"../img/group.gif\" border=\"0\" alt=\"".get_lang('Group')."\"/>";
  1345. }
  1346. echo " ".$myrow['title']."\n";
  1347. echo "\t\t</th>\n";
  1348. // the message has been sent to
  1349. echo "\t\t<th>".get_lang("SentTo").": ";
  1350. $sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
  1351. $sent_to_form=sent_to_form($sent_to);
  1352. echo $sent_to_form;
  1353. echo "</th>\n\t</tr>\n";
  1354. /*--------------------------------------------------
  1355. display: the title
  1356. --------------------------------------------------*/
  1357. echo "<tr class='row_odd'>";
  1358. echo "\t\t<td>".get_lang("StartTimeWindow").": ";
  1359. echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["start_date"])))."&nbsp;&nbsp;&nbsp;";
  1360. echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["start_date"])))."";
  1361. echo "</td>\n";
  1362. echo "\t\t<td>";
  1363. if ($myrow["end_date"]<>"0000-00-00 00:00:00")
  1364. {
  1365. echo get_lang("EndTimeWindow").": ";
  1366. echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["end_date"])))."&nbsp;&nbsp;&nbsp;";
  1367. echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["end_date"])))."";
  1368. }
  1369. echo "</td>\n";
  1370. echo "\n\t</tr>\n";
  1371. /*--------------------------------------------------
  1372. display: the content
  1373. --------------------------------------------------*/
  1374. $content = $myrow['content'];
  1375. $content = make_clickable($content);
  1376. $content = text_filter($content);
  1377. echo "<tr class='row_even'>";
  1378. echo "<td colspan='2'>";
  1379. echo '<a class="ical_export" href="ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'].'&class=confidential" title="'.get_lang('ExportiCalConfidential').'"><img src="'.$export_icon_high.'" alt="'.get_lang('ExportiCalConfidential').'"/></a>';
  1380. echo '<a class="ical_export" href="ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'].'&class=private" title="'.get_lang('ExportiCalPrivate').'"><img src="'.$export_icon_low.'" alt="'.get_lang('ExportiCalPrivate').'"/></a>';
  1381. echo '<a class="ical_export" href="ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'].'&class=public" title="'.get_lang('ExportiCalPublic').'"><img src="'.$export_icon.'" alt="'.get_lang('ExportiCalPublic').'"/></a>';
  1382. echo '<a href="#" onclick="javascript:win_print=window.open(\'print.php?id='.$myrow['id'].'\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">'.Display::return_icon('print.gif', get_lang('Print')).'</a>&nbsp;';
  1383. echo $content;
  1384. echo "</td></tr>";
  1385. /*--------------------------------------------------
  1386. display: the added resources
  1387. --------------------------------------------------*/
  1388. if (check_added_resources("Agenda", $myrow["id"]))
  1389. {
  1390. echo "<tr><td colspan='2'>";
  1391. echo "<i>".get_lang("AddedResources")."</i><br/>";
  1392. if ($myrow['visibility']==0)
  1393. {
  1394. $addedresource_style="invisible";
  1395. }
  1396. display_added_resources("Agenda", $myrow["id"], $addedresource_style);
  1397. echo "</td></tr>";
  1398. }
  1399. /*--------------------------------------------------
  1400. display: edit delete button (course admin only)
  1401. --------------------------------------------------*/
  1402. $event_list.=$myrow['id'].',';
  1403. echo "<tr class='row_odd'><td>";
  1404. if (is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  1405. {
  1406. // edit
  1407. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=edit&amp;id=".$myrow['id']."\">",
  1408. "<img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang("ModifyCalendarItem")."\" /></a>",
  1409. "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=delete&amp;id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."')) return false;\">",
  1410. "<img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang("Delete")."\"/></a>";
  1411. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=announce&amp;id=".$myrow['id']."\">".
  1412. "<img src=\"../img/announce_add.gif\" border=\"0\" alt=\"".get_lang("AddAnnouncement")."\"/></a>";
  1413. if ($myrow['visibility']==1)
  1414. {
  1415. $image_visibility="visible";
  1416. }
  1417. else
  1418. {
  1419. $image_visibility="invisible";
  1420. }
  1421. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=showhide&amp;id=".$myrow['id']."\">",
  1422. "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" alt=\"".get_lang("Visible")."\" /></a>";
  1423. }
  1424. echo "</td>";
  1425. $counter++;
  1426. /*--------------------------------------------------
  1427. display: jump-to-top icon
  1428. --------------------------------------------------*/
  1429. echo "<td><a href=\"#top\"><img src=\"../img/top.gif\" border=\"0\" alt=\"to top\" align=\"right\" /></a></td></tr>";
  1430. echo "</table><br /><br />";
  1431. } // end while ($myrow=mysql_fetch_array($result))
  1432. if(!empty($event_list))
  1433. {
  1434. $event_list=substr($event_list,0,-1);
  1435. }
  1436. else
  1437. {
  1438. $event_list='0';
  1439. }
  1440. echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"$event_list\" /></form>";
  1441. // closing the layout table
  1442. echo "</td>",
  1443. "</tr>",
  1444. "</table>";
  1445. }
  1446. /**
  1447. * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
  1448. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1449. */
  1450. function display_one_agenda_item($agenda_id)
  1451. {
  1452. global $TABLEAGENDA;
  1453. global $TABLE_ITEM_PROPERTY;
  1454. global $select_month, $select_year;
  1455. global $DaysShort, $DaysLong, $MonthsLong;
  1456. global $is_courseAdmin;
  1457. global $dateFormatLong, $timeNoSecFormat, $charset;
  1458. global $_user;
  1459. //echo "displaying agenda items";
  1460. // getting the name of the groups
  1461. $group_names=get_course_groups();
  1462. /*--------------------------------------------------
  1463. CONSTRUCT THE SQL STATEMENT
  1464. --------------------------------------------------*/
  1465. $sql="SELECT agenda.*, toolitemproperties.*
  1466. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  1467. WHERE agenda.id = toolitemproperties.ref
  1468. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  1469. AND toolitemproperties.visibility='1'
  1470. AND agenda.id='$agenda_id'";
  1471. $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
  1472. $number_items=mysql_num_rows($result);
  1473. $myrow=mysql_fetch_array($result); // there should be only one item so no need for a while loop
  1474. /*--------------------------------------------------
  1475. DISPLAY: NO ITEMS
  1476. --------------------------------------------------*/
  1477. if ($number_items==0)
  1478. {
  1479. echo "<table id=\"agenda_list\" ><tr><td>".get_lang("NoAgendaItems")."</td></tr></table>";
  1480. }
  1481. /*--------------------------------------------------
  1482. DISPLAY: THE ITEMS
  1483. --------------------------------------------------*/
  1484. echo "<table id=\"agenda_list\">\n";
  1485. /*--------------------------------------------------
  1486. DISPLAY : the icon, title, destinees of the item
  1487. --------------------------------------------------*/
  1488. echo "\t<tr>\n";
  1489. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  1490. $db_date=(int)date("d",strtotime($myrow["start_date"])).date("n",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"]));
  1491. if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date)
  1492. {
  1493. if ($myrow['visibility']=='0')
  1494. {
  1495. $style="data_hidden";
  1496. $stylenotbold="datanotbold_hidden";
  1497. $text_style="text_hidden";
  1498. }
  1499. else
  1500. {
  1501. $style="data";
  1502. $stylenotbold="datanotbold";
  1503. $text_style="text";
  1504. }
  1505. }
  1506. else
  1507. {
  1508. $style="datanow";
  1509. $stylenotbold="datanotboldnow";
  1510. $text_style="textnow";
  1511. }
  1512. echo "\t\t<td class=\"".$style."\">\n";
  1513. // adding an internal anchor
  1514. echo "\t\t\t<a name=\"".(int)date("d",strtotime($myrow["start_date"]))."\"></a>";
  1515. // the icons. If the message is sent to one or more specific users/groups
  1516. // we add the groups icon
  1517. // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon
  1518. echo Display::return_icon('agenda.gif');
  1519. if ($myrow['to_group_id']!=='0')
  1520. {
  1521. echo Display::return_icon('group.gif'); //"<img src=\"../img/group.gif\" border=\"0\" />";
  1522. }
  1523. echo " ".$myrow['title']."\n";
  1524. echo "\t\t</td>\n";
  1525. // the message has been sent to
  1526. echo "\t\t<td class=\"".$stylenotbold."\">".get_lang("SentTo").": ";
  1527. $sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
  1528. $sent_to_form=sent_to_form($sent_to);
  1529. echo $sent_to_form;
  1530. echo "</td>\n\t</tr>\n";
  1531. /*--------------------------------------------------
  1532. DISPLAY: the title
  1533. --------------------------------------------------*/
  1534. echo "\t<tr class=\"".$stylenotbold."\">\n";
  1535. echo "\t\t<td>".get_lang("StartTime").": ";
  1536. echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["start_date"])))."&nbsp;&nbsp;&nbsp;";
  1537. echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["start_date"])))."";
  1538. echo "</td>\n";
  1539. echo "\t\t<td>".get_lang("EndTime").": ";
  1540. echo ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["end_date"])))."&nbsp;&nbsp;&nbsp;";
  1541. echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["end_date"])))."";
  1542. echo "</td>\n";
  1543. echo "\n\t</tr>\n";
  1544. /*--------------------------------------------------
  1545. DISPLAY: the content
  1546. --------------------------------------------------*/
  1547. $content = $myrow['content'];
  1548. $content = make_clickable($content);
  1549. $content = text_filter($content);
  1550. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  1551. echo $content;
  1552. echo "</td></tr>";
  1553. /*--------------------------------------------------
  1554. DISPLAY: the added resources
  1555. --------------------------------------------------*/
  1556. if (check_added_resources("Agenda", $myrow["id"]))
  1557. {
  1558. echo "<tr><td colspan='2'>";
  1559. echo "<i>".get_lang("AddedResources")."</i><br/>";
  1560. if ($myrow['visibility']==0)
  1561. {
  1562. $addedresource_style="invisible";
  1563. }
  1564. display_added_resources("Agenda", $myrow["id"], $addedresource_style);
  1565. echo "</td></tr>";
  1566. }
  1567. /*--------------------------------------------------
  1568. DISPLAY: edit delete button (course admin only)
  1569. --------------------------------------------------*/
  1570. echo "<tr><td>";
  1571. if (is_allowed_to_edit())
  1572. {
  1573. // edit
  1574. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=edit&amp;id=".$myrow['id']."\">",
  1575. "<img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang("ModifyCalendarItem")."\" /></a>",
  1576. "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=delete&amp;id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."')) return false;\">",
  1577. "<img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang("Delete")."\" /></a>";
  1578. if ($myrow['visibility']==1)
  1579. {
  1580. $image_visibility="visible";
  1581. }
  1582. else
  1583. {
  1584. $image_visibility="invisible";
  1585. }
  1586. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&amp;action=showhide&amp;id=".$myrow['id']."\">",
  1587. "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" alt=\"".get_lang("Visible")."\" /></a><br /><br />";
  1588. }
  1589. echo "</td>";
  1590. echo "</table>";
  1591. // closing the layout table
  1592. echo "</td>",
  1593. "</tr>",
  1594. "</table>";
  1595. }
  1596. /**
  1597. * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
  1598. * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
  1599. * we have to retrieve the information that is in the database and use this information in the forms.
  1600. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1601. * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
  1602. * agenda item.
  1603. */
  1604. function show_add_form($id = '')
  1605. {
  1606. global $MonthsLong;
  1607. // the default values for the forms
  1608. if ($_GET['originalresource'] !== 'no')
  1609. {
  1610. $day = date('d');
  1611. $month = date('m');
  1612. $year = date('Y');
  1613. $hours = 9;
  1614. $minutes= '00';
  1615. $end_day = date('d');
  1616. $end_month = date('m');
  1617. $end_year = date('Y');
  1618. $end_hours = 17;
  1619. $end_minutes= '00';
  1620. }
  1621. else
  1622. {
  1623. // we are coming from the resource linker so there might already have been some information in the form.
  1624. // When we clicked on the button to add resources we stored every form information into a session and now we
  1625. // are doing the opposite thing: getting the information out of the session and putting it into variables to
  1626. // display it in the forms.
  1627. $form_elements=$_SESSION['formelements'];
  1628. $day=$form_elements['day'];
  1629. $month=$form_elements['month'];
  1630. $year=$form_elements['year'];
  1631. $hours=$form_elements['hour'];
  1632. $minutes=$form_elements['minutes'];
  1633. $end_day=$form_elements['end_day'];
  1634. $end_month=$form_elements['end_month'];
  1635. $end_year=$form_elements['end_year'];
  1636. $end_hours=$form_elements['end_hours'];
  1637. $end_minutes=$form_elements['end_minutes'];
  1638. $title=$form_elements['title'];
  1639. $content=$form_elements['content'];
  1640. $id=$form_elements['id'];
  1641. $to=$form_elements['to'];
  1642. }
  1643. // switching the send to all/send to groups/send to users
  1644. if ($_POST['To'])
  1645. {
  1646. $day = $_POST['fday'];
  1647. $month = $_POST['fmonth'];
  1648. $year = $_POST['fyear'];
  1649. $hours = $_POST['fhour'];
  1650. $minutes = $_POST['fminute'];
  1651. $end_day = $_POST['end_fday'];
  1652. $end_month = $_POST['end_fmonth'];
  1653. $end_year = $_POST['end_fyear'];
  1654. $end_hours = $_POST['end_fhour'];
  1655. $end_minutes = $_POST['end_fminute'];
  1656. $title = $_POST['title'];
  1657. $content = $_POST['content'];
  1658. // the invisible fields
  1659. $action = $_POST['action'];
  1660. $id = $_POST['id'];
  1661. }
  1662. // if the id is set then we are editing an agenda item
  1663. if (is_int($id))
  1664. {
  1665. //echo "before get_agenda_item".$_SESSION['allow_individual_calendar'];
  1666. $item_2_edit=get_agenda_item($id);
  1667. $title = $item_2_edit['title'];
  1668. $content= $item_2_edit['content'];
  1669. // start date
  1670. list($datepart, $timepart) = split(" ", $item_2_edit['start_date']);
  1671. list($year, $month, $day) = explode("-", $datepart);
  1672. list($hours, $minutes, $seconds) = explode(":", $timepart);
  1673. // end date
  1674. list($datepart, $timepart) = split(" ", $item_2_edit['end_date']);
  1675. list($end_year, $end_month, $end_day) = explode("-", $datepart);
  1676. list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
  1677. // attachments
  1678. edit_added_resources("Agenda", $id);
  1679. $to=$item_2_edit['to'];
  1680. //echo "<br />after get_agenda_item".$_SESSION['allow_individual_calendar'];
  1681. }
  1682. $content=stripslashes($content);
  1683. $title=stripslashes($title);
  1684. // we start a completely new item, we do not come from the resource linker
  1685. if ($_GET['originalresource']!=="no" and $_GET['action']=="add")
  1686. {
  1687. $_SESSION["formelements"]=null;
  1688. unset_session_resources();
  1689. }
  1690. ?>
  1691. <!-- START OF THE FORM -->
  1692. <form action="<?php echo api_get_self().'?origin='.$_GET['origin'].'&amp;action='.$_GET['action']; ?>" method="post" name="new_calendar_item">
  1693. <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
  1694. <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo $_GET['action']; ?>" />
  1695. <table border="0" cellpadding="5" cellspacing="0" width="100%" id="newedit_form">
  1696. <!-- the title -->
  1697. <tr class="title">
  1698. <td colspan="3">
  1699. <span style="font-weight: bold;"><?php echo (isset($id) AND $id<>'')?get_lang('ModifyCalendarItem'):get_lang("AddCalendarItem"); ?></span>
  1700. </td>
  1701. </tr>
  1702. <!-- the select specific users / send to all form -->
  1703. <?php
  1704. if (isset ($_SESSION['toolgroup']))
  1705. {
  1706. echo '<tr id="subtitle">';
  1707. echo '<td colspan="3">';
  1708. echo '<input type="hidden" name="selectedform[0]" value="GROUP:'.$_SESSION['toolgroup'].'"/>' ;
  1709. echo '<input type="hidden" name="To" value="true"/>' ;
  1710. echo '</td>';
  1711. echo '</tr>';
  1712. }
  1713. else
  1714. {
  1715. ?>
  1716. <tr class="subtitle">
  1717. <td valign="top" colspan="3">
  1718. <?php
  1719. // this variable defines if the course administrator can send a message to a specific user / group
  1720. // or not
  1721. //echo "<input type=\"submit\" name=\"To\" value=\"".get_lang("SelectGroupsUsers")."\" style=\"float:left\">" ;
  1722. //echo "sessiewaarde: ".$_SESSION['allow_individual_calendar'];
  1723. echo get_lang("SentTo").": ";
  1724. if ((isset($_GET['id']) && $to=='everyone') || !isset($_GET['id'])){
  1725. echo get_lang("Everybody").'&nbsp;';
  1726. }
  1727. 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>';
  1728. show_to_form($to);
  1729. if (isset($_GET['id']) && $to!='everyone'){
  1730. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  1731. }
  1732. ?>
  1733. <hr noshade="noshade" color="#cccccc" />
  1734. </td>
  1735. </tr>
  1736. <?php
  1737. }
  1738. ?>
  1739. <!-- START date and time -->
  1740. <tr class="subtitle">
  1741. <td>
  1742. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  1743. <tr><td width="110">
  1744. <!-- date: 1 -> 31 -->
  1745. <?php echo get_lang('StartDate').": \n"; ?>
  1746. </td>
  1747. <td>
  1748. <select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
  1749. <?php
  1750. // small loop for filling all the dates
  1751. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  1752. echo "\n";
  1753. foreach (range(1, 31) as $i)
  1754. {
  1755. // values have to have double digits
  1756. $value = ($i <= 9 ? '0'.$i : $i );
  1757. // the current day is indicated with [] around the date
  1758. if ($value==$day)
  1759. {
  1760. echo "\t\t\t\t <option value=\"".$value."\" selected> ".$i." </option>\n";
  1761. }
  1762. else
  1763. {
  1764. echo "\t\t\t\t<option value=\"$value\">$i</option>\n";
  1765. }
  1766. }
  1767. ?>
  1768. </select>
  1769. <!-- month: january -> december -->
  1770. <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
  1771. <?php
  1772. echo "\n";
  1773. for ($i=1; $i<=12; $i++)
  1774. {
  1775. // values have to have double digits
  1776. if ($i<=9)
  1777. {
  1778. $value="0".$i;
  1779. }
  1780. else
  1781. {
  1782. $value=$i;
  1783. }
  1784. if ($value==$month)
  1785. {
  1786. echo "\t\t\t\t <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n";
  1787. }
  1788. else
  1789. {
  1790. echo "\t\t\t\t <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n";
  1791. }
  1792. } ?>
  1793. </select>
  1794. <select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
  1795. <option value="<?php echo ($year-1); ?>"><?php echo ($year-1); ?></option>
  1796. <option value="<?php echo $year; ?>" selected="selected"><?php echo $year; ?></option>
  1797. <?php
  1798. echo "\n";
  1799. for ($i=1; $i<=5; $i++)
  1800. {
  1801. $value=$year+$i;
  1802. echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
  1803. } ?>
  1804. </select>
  1805. <a href="javascript:openCalendar('new_calendar_item', 'f')"><img src="../img/calendar_select.gif" border="0" alt="Select"/></a>
  1806. </td></tr></table>
  1807. </td>
  1808. <td>
  1809. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  1810. <tr><td width="110">
  1811. <!-- date: 1 -> 31 -->
  1812. <?php echo get_lang('StartTime').": \n"; ?>
  1813. </td>
  1814. <td>
  1815. <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
  1816. <option value="--">--</option>
  1817. <?php
  1818. echo "\n";
  1819. foreach (range(1, 24) as $i)
  1820. {
  1821. // values have to have double digits
  1822. $value = ($i <= 9 ? '0'.$i : $i );
  1823. // the current hour is indicated with [] around the hour
  1824. if ($hours==$value)
  1825. {
  1826. echo "\t\t\t\t<option value=\"".$value."\" selected> ".$value." </option>\n";
  1827. }
  1828. else
  1829. {
  1830. echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
  1831. }
  1832. } ?>
  1833. </select>
  1834. <?php echo get_lang('HourMinuteDivider'); ?>
  1835. <select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
  1836. <option value="<?php echo $minutes ?>"><?php echo $minutes; ?></option>
  1837. <option value="--">--</option>
  1838. <?php
  1839. foreach (range(0, 59) as $i)
  1840. {
  1841. // values have to have double digits
  1842. $value = ($i <= 9 ? '0'.$i : $i );
  1843. echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
  1844. } ?>
  1845. </select>
  1846. </td></tr></table>
  1847. </td>
  1848. </tr>
  1849. <!-- END date and time -->
  1850. <tr class="subtitle">
  1851. <td>
  1852. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  1853. <tr><td width="110">
  1854. <!-- date: 1 -> 31 -->
  1855. <?php echo get_lang('EndDate').": \n"; ?>
  1856. </td>
  1857. <td>
  1858. <select name="end_fday">
  1859. <?php
  1860. // small loop for filling all the dates
  1861. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  1862. echo "\n";
  1863. foreach (range(1, 31) as $i)
  1864. {
  1865. // values have to have double digits
  1866. $value = ($i <= 9 ? '0'.$i : $i );
  1867. // the current day is indicated with [] around the date
  1868. if ($value==$end_day)
  1869. { echo "\t\t\t\t <option value=\"".$value."\" selected> ".$i." </option>\n";}
  1870. else
  1871. { echo "\t\t\t\t <option value=\"".$value."\">".$i."</option>\n"; }
  1872. }?>
  1873. </select>
  1874. <!-- month: january -> december -->
  1875. <select name="end_fmonth">
  1876. <?php
  1877. echo "\n";
  1878. foreach (range(1, 12) as $i)
  1879. {
  1880. // values have to have double digits
  1881. $value = ($i <= 9 ? '0'.$i : $i );
  1882. if ($value==$end_month)
  1883. { echo "\t\t\t\t <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n"; }
  1884. else
  1885. { echo "\t\t\t\t <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n"; }
  1886. }?>
  1887. </select>
  1888. <select name="end_fyear">
  1889. <option value="<?php echo ($end_year-1) ?>"><?php echo ($end_year-1) ?></option>
  1890. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  1891. <?php
  1892. echo "\n";
  1893. for ($i=1; $i<=5; $i++)
  1894. {
  1895. $value=$end_year+$i;
  1896. echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
  1897. } ?>
  1898. </select>
  1899. <a href="javascript:openCalendar('new_calendar_item', 'end_f')"><img src="../img/calendar_select.gif" border="0" /></a>
  1900. </td></tr></table>
  1901. </td>
  1902. <td>
  1903. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  1904. <tr><td width="110">
  1905. <!-- date: 1 -> 31 -->
  1906. <?php echo get_lang('EndTime').": \n"; ?>
  1907. </td>
  1908. <td>
  1909. <select name="end_fhour">
  1910. <option value="--">--</option>
  1911. <?php
  1912. echo "\n";
  1913. foreach (range(1, 24) as $i)
  1914. {
  1915. // values have to have double digits
  1916. $value = ($i <= 9 ? '0'.$i : $i );
  1917. // the current hour is indicated with [] around the hour
  1918. if ($end_hours==$value)
  1919. { echo "\t\t\t\t<option value=\"".$value."\" selected> ".$value." </option>\n"; }
  1920. else
  1921. { echo "\t\t\t\t<option value=\"".$value."\"> ".$value." </option>\n"; }
  1922. } ?>
  1923. </select>
  1924. <?php echo get_lang('HourMinuteDivider'); ?>
  1925. <select name="end_fminute">
  1926. <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option>
  1927. <option value="--">--</option>
  1928. <?php
  1929. foreach (range(0, 59) as $i)
  1930. {
  1931. // values have to have double digits
  1932. $value = ($i <= 9 ? '0'.$i : $i );
  1933. echo "\t\t\t\t<option value=\"$value\">$value</option>\n";
  1934. } ?>
  1935. </select>
  1936. </td></tr></table>
  1937. </td>
  1938. </tr>
  1939. <tr class="subtitle">
  1940. <td colspan="3" valign="top"><hr noshade="noshade" color="#cccccc" /><?php echo get_lang('ItemTitle'); ?> :
  1941. <!--<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>-->
  1942. <input type="text" size="60" name="title" value="<?php if (isset($title)) echo $title; ?>" />
  1943. </td>
  1944. </tr>
  1945. <tr>
  1946. <td colspan="7">
  1947. <?php
  1948. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  1949. $oFCKeditor = new FCKeditor('content') ;
  1950. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  1951. $oFCKeditor->Height = '175';
  1952. $oFCKeditor->Width = '100%';
  1953. $oFCKeditor->Value = $content;
  1954. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  1955. $oFCKeditor->ToolbarSet = "Middle";
  1956. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  1957. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  1958. $result_sql=api_sql_query($sql);
  1959. $isocode_language=mysql_result($result_sql,0,0);
  1960. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  1961. $return = $oFCKeditor->CreateHtml();
  1962. echo $return;
  1963. ?>
  1964. </td>
  1965. </tr>
  1966. <!--<?php /* ADDED BY UGENT, Patrick Cool, march 2004 */ ?>
  1967. <tr>
  1968. <td colspan="7">
  1969. <?php
  1970. //onclick="selectAll(this.form.elements[6],true)"
  1971. if ($_SESSION['allow_individual_calendar']=='show')
  1972. show_addresource_button('onclick="selectAll(this.form.elements[6],true)"');
  1973. else
  1974. show_addresource_button();
  1975. $form_elements=$_SESSION['formelements'];
  1976. ?>
  1977. </td>
  1978. </tr>-->
  1979. <?php
  1980. //if ($_SESSION['addedresource'])
  1981. echo "\t<tr>\n";
  1982. echo "\t\t<td colspan=\"7\">\n";
  1983. echo display_resources(0);
  1984. $test=$_SESSION['addedresource'];
  1985. echo "\t\t</td>\n\t</tr>\n";
  1986. /* END ADDED BY UGENT, Patrick Cool, march 2004 */
  1987. ?>
  1988. <tr>
  1989. <td colspan="7">
  1990. <input type="submit" name="submit_event" value="<?php echo get_lang('Ok'); ?>" onclick="selectAll(this.form.elements[5],true)" />
  1991. </td>
  1992. </tr>
  1993. </table>
  1994. </form>
  1995. <p>&nbsp;</p>
  1996. <?php
  1997. }
  1998. ?>