agenda.inc.php 82 KB

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