blog.lib.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573
  1. <?php
  2. /**
  3. ===============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) Keppens Toon
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ===============================================================================
  17. Functions in this API file:
  18. ===============================================================================
  19. */
  20. /**
  21. * Blog class
  22. * Contains several functions dealing with displaying,
  23. * editing,... of a blog
  24. *
  25. * @version 1.0
  26. * @package dokeos.blogs
  27. * @author Toon Keppens <toon@vi-host.net>
  28. *
  29. */
  30. class Blog
  31. {
  32. /**
  33. * Get the title of a blog
  34. * @author Toon Keppens
  35. *
  36. * @param Integer $blog_id
  37. *
  38. * @return String Blog Title
  39. */
  40. function get_blog_title($blog_id)
  41. {
  42. if(is_numeric($blog_id))
  43. {
  44. // init
  45. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  46. $sql = "
  47. SELECT `blog_name`
  48. FROM " . $tbl_blogs . "
  49. WHERE `blog_id` = " . mysql_real_escape_string((int)$blog_id);
  50. $result = api_sql_query($sql, __FILE__, __LINE__);
  51. $blog = mysql_fetch_array($result);
  52. return stripslashes($blog['blog_name']);
  53. }
  54. }
  55. /**
  56. * Get the description of a blog
  57. * @author Toon Keppens
  58. *
  59. * @param Integer $blog_id
  60. *
  61. * @return String Blog description
  62. */
  63. function get_blog_subtitle($blog_id)
  64. {
  65. // init
  66. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  67. $sql = "SELECT blog_subtitle FROM $tbl_blogs WHERE blog_id ='".mysql_real_escape_string((int)$blog_id)."'";
  68. $result = api_sql_query($sql, __FILE__, __LINE__);
  69. $blog = mysql_fetch_array($result);
  70. return stripslashes($blog['blog_subtitle']);
  71. }
  72. /**
  73. * Get the users of a blog
  74. * @author Toon Keppens
  75. *
  76. * @param Integer $blog_id
  77. *
  78. * @return Array Returns an array with [userid]=>[username]
  79. */
  80. function get_blog_users($blog_id)
  81. {
  82. // Database table definitions
  83. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  84. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  85. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  86. // Get blog members
  87. $sql = "
  88. SELECT
  89. user.user_id,
  90. user.firstname,
  91. user.lastname
  92. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  93. INNER JOIN " . $tbl_users . " user ON blogs_rel_user.user_id = user.user_id
  94. WHERE blogs_rel_user.blog_id = '" . mysql_real_escape_string((int)$blog_id)."'";
  95. $result = api_sql_query($sql, __FILE__, __LINE__);
  96. $blog_members = array ();
  97. while($user = mysql_fetch_array($result))
  98. {
  99. $blog_members[$user['user_id']] = $user['lastname']." " . $user['firstname'];
  100. }
  101. return $blog_members;
  102. }
  103. /**
  104. * Creates a new blog in the given course
  105. * @author Toon Keppens
  106. *
  107. * @param Integer $course_id Id
  108. * @param String $title
  109. * @param Text $description
  110. *
  111. * @return void
  112. */
  113. function create_blog($title, $subtitle)
  114. {
  115. global $_user;
  116. // Tabel definitions
  117. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  118. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  119. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  120. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  121. // Create the blog
  122. $sql = "INSERT INTO $tbl_blogs (`blog_name`, `blog_subtitle`, `date_creation`, `visibility` )
  123. VALUES ('".mysql_real_escape_string($title)."', '".mysql_real_escape_string($subtitle)."', NOW(), '1');";
  124. api_sql_query($sql, __FILE__, __LINE__);
  125. $this_blog_id = Database::get_last_insert_id();
  126. // Make first post. :)
  127. $sql = "INSERT INTO $tbl_blogs_posts (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` )
  128. VALUES ('".get_lang("Welcome")."', '" . get_lang('FirstPostText')."', NOW(), '".mysql_real_escape_string((int)$this_blog_id)."', '".mysql_real_escape_string((int)$_user['user_id'])."');";
  129. api_sql_query($sql, __FILE__, __LINE__);
  130. // Put it on course homepage
  131. $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool)
  132. VALUES ('".mysql_real_escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0)";
  133. api_sql_query($sql, __FILE__, __LINE__);
  134. // Subscribe the teacher to this blog
  135. Blog::set_user_subscribed((int)$this_blog_id,(int)$_user['user_id']);
  136. return void;
  137. }
  138. /**
  139. * Update title and subtitle of a blog in the given course
  140. * @author Toon Keppens
  141. *
  142. * @param Integer $course_id Id
  143. * @param String $title
  144. * @param Text $description
  145. *
  146. * @return void
  147. */
  148. function edit_blog($blog_id, $title, $subtitle)
  149. {
  150. global $_user;
  151. // Table definitions
  152. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  153. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  154. // Update the blog
  155. $sql = "UPDATE $tbl_blogs SET blog_name = '".mysql_real_escape_string($title)."', blog_subtitle = '".mysql_real_escape_string($subtitle)."' WHERE blog_id ='".mysql_real_escape_string((int)$blog_id)."' LIMIT 1";
  156. api_sql_query($sql, __FILE__, __LINE__);
  157. $this_blog_id = Database::get_last_insert_id();
  158. // Update course homepage link
  159. $sql = "UPDATE $tbl_tool SET name = '".mysql_real_escape_string($title)."' WHERE link = 'blog/blog.php?blog_id=".mysql_real_escape_string((int)$blog_id)."' LIMIT 1";
  160. api_sql_query($sql, __FILE__, __LINE__);
  161. return void;
  162. }
  163. /**
  164. * Deletes a blog and it's posts from the course database
  165. * @author Toon Keppens
  166. *
  167. * @param Integer $blog_id
  168. *
  169. * @return void
  170. */
  171. function delete_blog($blog_id)
  172. {
  173. // Init
  174. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  175. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  176. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  177. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  178. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  179. // Delete posts
  180. $sql = "DELETE FROM $tbl_blogs_posts WHERE blog_id ='".(int)$blog_id."'";
  181. api_sql_query($sql, __FILE__, __LINE__);
  182. // Delete tasks
  183. $sql = "DELETE FROM $tbl_blogs_tasks WHERE blog_id ='".(int)$blog_id."'";
  184. api_sql_query($sql, __FILE__, __LINE__);
  185. // Delete ratings
  186. $sql = "DELETE FROM $tbl_blogs_rating WHERE blog_id ='".(int)$blog_id."'";
  187. api_sql_query($sql, __FILE__, __LINE__);
  188. // Delete blog
  189. $sql ="DELETE FROM $tbl_blogs WHERE blog_id ='".(int)$blog_id."'";
  190. api_sql_query($sql, __FILE__, __LINE__);
  191. // Delete from course homepage
  192. $sql = "DELETE FROM $tbl_tool WHERE link = 'blog/blog.php?blog_id=".(int)$blog_id."'";
  193. api_sql_query($sql, __FILE__, __LINE__);
  194. return void;
  195. }
  196. /**
  197. * Creates a new post in a given blog
  198. * @author Toon Keppens
  199. *
  200. * @param String $title
  201. * @param String $full_text
  202. * @param Integer $blog_id
  203. *
  204. * @return void
  205. */
  206. function create_post($title, $full_text, $blog_id)
  207. {
  208. global $_user;
  209. // Table Definitions
  210. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  211. // Create the post
  212. $sql = "INSERT INTO " . $tbl_blogs_posts." (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` )
  213. VALUES ('".mysql_real_escape_string($title)."', '".mysql_real_escape_string($full_text)."', NOW(), '".(int)$blog_id."', '".(int)$_user['user_id']."');";
  214. api_sql_query($sql, __FILE__, __LINE__);
  215. return void;
  216. }
  217. /**
  218. * Edits a post in a given blog
  219. * @author Toon Keppens
  220. *
  221. * @param Integer $blog_id
  222. * @param String $title
  223. * @param String $full_text
  224. * @param Integer $blog_id
  225. *
  226. * @return void
  227. */
  228. function edit_post($post_id, $title, $full_text, $blog_id)
  229. {
  230. // Init
  231. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  232. // Create the post
  233. $sql = "UPDATE $tbl_blogs_posts SET title = '" . mysql_real_escape_string($title)."', full_text = '" . mysql_real_escape_string($full_text)."' WHERE post_id ='".(int)$post_id."' AND blog_id ='".(int)$blog_id."' LIMIT 1 ;";
  234. api_sql_query($sql, __FILE__, __LINE__);
  235. return void;
  236. }
  237. /**
  238. * Deletes an article and it's comments
  239. * @author Toon Keppens
  240. *
  241. * @param Integer $blog_id
  242. * @param Integer $post_id
  243. *
  244. * @return void
  245. */
  246. function delete_post($blog_id, $post_id)
  247. {
  248. // Init
  249. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  250. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  251. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  252. // Delete ratings on this comment
  253. $sql = "DELETE FROM $tbl_blogs_rating WHERE blog_id = '".(int)$blog_id."' AND item_id = '".(int)$post_id."' AND rating_type = 'post'";
  254. api_sql_query($sql, __FILE__, __LINE__);
  255. // Delete the post
  256. $sql = "DELETE FROM $tbl_blogs_posts WHERE `post_id` = '".(int)$post_id."'";
  257. api_sql_query($sql, __FILE__, __LINE__);
  258. // Delete the comments
  259. $sql = "DELETE FROM $tbl_blogs_comments WHERE `post_id` = '".(int)$post_id."' AND `blog_id` = '".(int)$blog_id."'";
  260. api_sql_query($sql, __FILE__, __LINE__);
  261. return void;
  262. }
  263. /**
  264. * Creates a comment on a post in a given blog
  265. * @author Toon Keppens
  266. *
  267. * @param String $title
  268. * @param String $full_text
  269. * @param Integer $blog_id
  270. * @param Integer $post_id
  271. * @param Integer $parent_id
  272. *
  273. * @return void
  274. */
  275. function create_comment($title, $full_text, $blog_id, $post_id, $parent_id, $task_id = 'NULL')
  276. {
  277. global $_user;
  278. // Table Definition
  279. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  280. // Create the comment
  281. $sql = "INSERT INTO $tbl_blogs_comments (`title`, `comment`, `author_id`, `date_creation`, `blog_id`, `post_id`, `parent_comment_id`, `task_id` )
  282. VALUES ('".mysql_real_escape_string($title)."', '".mysql_real_escape_string($full_text)."', '".(int)$_user['user_id']."', NOW(), '".(int)$blog_id."', '".(int)$post_id."', '".(int)$parent_id."', '".(int)$task_id."')";
  283. api_sql_query($sql, __FILE__, __LINE__);
  284. // Empty post values, or they are shown on the page again
  285. $_POST['comment_title'] = "";
  286. $_POST['comment_text'] = "";
  287. return void;
  288. }
  289. /**
  290. * Deletes a comment from a blogpost
  291. * @author Toon Keppens
  292. *
  293. * @param Integer $blog_id
  294. * @param Integer $comment_id
  295. *
  296. * @return void
  297. */
  298. function delete_comment($blog_id, $comment_id)
  299. {
  300. // Init
  301. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  302. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  303. // Delete ratings on this comment
  304. $sql = "DELETE FROM $tbl_blogs_rating WHERE blog_id = '".(int)$blog_id."' AND item_id = '".(int)$comment_id."' AND rating_type = 'comment'";
  305. api_sql_query($sql, __FILE__, __LINE__);
  306. // select comments that have the selected comment as their parent
  307. $sql = "SELECT comment_id FROM $tbl_blogs_comments WHERE parent_comment_id = '".(int)$comment_id."'";
  308. $result = api_sql_query($sql, __FILE__, __LINE__);
  309. // Delete them recursively
  310. while($comment = mysql_fetch_array($result))
  311. {
  312. Blog::delete_comment($blog_id, $comment['comment_id']);
  313. }
  314. // Finally, delete the selected comment to
  315. $sql = "DELETE FROM $tbl_blogs_comments WHERE `comment_id` = '".(int)$comment_id."'";
  316. api_sql_query($sql, __FILE__, __LINE__);
  317. return void;
  318. }
  319. /**
  320. * Creates a new task in a blog
  321. * @author Toon Keppens
  322. *
  323. * @param Integer $blog_id
  324. * @param String $title
  325. * @param String $description
  326. * @param String $color
  327. *
  328. * @return void
  329. */
  330. function create_task($blog_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
  331. {
  332. // Init
  333. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  334. $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
  335. // Create the task
  336. $sql = "INSERT INTO $tbl_blogs_tasks (`blog_id`, `title`, `description`, `color`, `system_task` )
  337. VALUES ('".(int)$blog_id."', '" . mysql_real_escape_string($title)."', '" . mysql_real_escape_string($description)."', '" . mysql_real_escape_string($color)."', '0');";
  338. api_sql_query($sql, __FILE__, __LINE__);
  339. $task_id = mysql_insert_id();
  340. $tool = 'BLOG_' . $blog_id;
  341. if($articleDelete == 'on')
  342. {
  343. $sql = "
  344. INSERT INTO " . $tbl_tasks_permissions . " (
  345. `task_id`,
  346. `tool`,
  347. `action`
  348. ) VALUES (
  349. '" . (int)$task_id . "',
  350. '" . mysql_real_escape_string($tool) . "',
  351. 'article_delete'
  352. )";
  353. api_sql_query($sql, __FILE__, __LINE__);
  354. }
  355. if($articleEdit == 'on')
  356. {
  357. $sql = "
  358. INSERT INTO " . $tbl_tasks_permissions . " (
  359. `task_id`,
  360. `tool`,
  361. `action`
  362. ) VALUES (
  363. '" . (int)$task_id . "',
  364. '" . mysql_real_escape_string($tool) . "',
  365. 'article_edit'
  366. )";
  367. api_sql_query($sql, __FILE__, __LINE__);
  368. }
  369. if($commentsDelete == 'on')
  370. {
  371. $sql = "
  372. INSERT INTO " . $tbl_tasks_permissions . " (
  373. `task_id`,
  374. `tool`,
  375. `action`
  376. ) VALUES (
  377. '" . (int)$task_id . "',
  378. '" . mysql_real_escape_string($tool) . "',
  379. 'article_comments_delete'
  380. )";
  381. api_sql_query($sql, __FILE__, __LINE__);
  382. }
  383. return void;
  384. }
  385. /**
  386. * Edit a task in a blog
  387. * @author Toon Keppens
  388. *
  389. * @param Integer $task_id
  390. * @param String $title
  391. * @param String $description
  392. * @param String $color
  393. *
  394. * @return void
  395. */
  396. function edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)
  397. {
  398. // Init
  399. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  400. $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
  401. // Create the task
  402. $sql = "UPDATE $tbl_blogs_tasks SET
  403. title = '".mysql_real_escape_string($title)."',
  404. description = '".mysql_real_escape_string($description)."',
  405. color = '".mysql_real_escape_string($color)."'
  406. WHERE task_id ='".(int)$task_id."' LIMIT 1";
  407. api_sql_query($sql, __FILE__, __LINE__);
  408. $tool = 'BLOG_' . $blog_id;
  409. $sql = "
  410. DELETE FROM " . $tbl_tasks_permissions . "
  411. WHERE `task_id` = '" . (int)$task_id."'";
  412. api_sql_query($sql, __FILE__, __LINE__);
  413. if($articleDelete == 'on')
  414. {
  415. $sql = "
  416. INSERT INTO " . $tbl_tasks_permissions . " (
  417. `task_id`,
  418. `tool`,
  419. `action`
  420. ) VALUES (
  421. '" . (int)$task_id . "',
  422. '" . mysql_real_escape_string($tool) . "',
  423. 'article_delete'
  424. )";
  425. api_sql_query($sql, __FILE__, __LINE__);
  426. }
  427. if($articleEdit == 'on')
  428. {
  429. $sql = "
  430. INSERT INTO " . $tbl_tasks_permissions . " (
  431. `task_id`,
  432. `tool`,
  433. `action`
  434. ) VALUES (
  435. '" . (int)$task_id . "',
  436. '" . mysql_real_escape_string($tool) . "',
  437. 'article_edit'
  438. )";
  439. api_sql_query($sql, __FILE__, __LINE__);
  440. }
  441. if($commentsDelete == 'on')
  442. {
  443. $sql = "
  444. INSERT INTO " . $tbl_tasks_permissions . " (
  445. `task_id`,
  446. `tool`,
  447. `action`
  448. ) VALUES (
  449. '" . (int)$task_id . "',
  450. '" . mysql_real_escape_string($tool) . "',
  451. 'article_comments_delete'
  452. )";
  453. api_sql_query($sql, __FILE__, __LINE__);
  454. }
  455. return void;
  456. }
  457. /**
  458. * Deletes a task from a blog
  459. *
  460. * @param Integer $blog_id
  461. * @param Integer $task_id
  462. */
  463. function delete_task($blog_id, $task_id)
  464. {
  465. // Init
  466. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  467. // Delete posts
  468. $sql = "DELETE FROM $tbl_blogs_tasks WHERE `blog_id` = '".(int)$blog_id."' AND `task_id` = '".(int)$task_id."'";
  469. api_sql_query($sql, __FILE__, __LINE__);
  470. return void;
  471. }
  472. /**
  473. * Deletes an assigned task from a blog
  474. *
  475. * @param Integer $blog_id
  476. * @param Integer $assignment_id
  477. */
  478. function delete_assigned_task($blog_id, $assignment_id)
  479. {
  480. // Init
  481. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  482. $parameters = explode('|',$assignment_id);
  483. $task_id = $parameters[0];
  484. $user_id = $parameters[1];
  485. // Delete posts
  486. $sql = "DELETE FROM $tbl_blogs_tasks_rel_user WHERE `blog_id` = '".(int)$blog_id."' AND `task_id` = '".(int)$task_id."' AND `user_id` = '".(int)$user_id."'";
  487. api_sql_query($sql, __FILE__, __LINE__);
  488. return void;
  489. }
  490. /**
  491. * Get personal task list
  492. * @author Toon Keppens
  493. *
  494. * @return Returns an unsorted list (<ul>) with the users' tasks
  495. */
  496. function get_personal_task_list()
  497. {
  498. global $_user;
  499. // Init
  500. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  501. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  502. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  503. if($_user['user_id'])
  504. {
  505. $sql = "SELECT task_rel_user.*, task.title, blog.blog_name FROM $tbl_blogs_tasks_rel_user task_rel_user
  506. INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
  507. INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
  508. WHERE task_rel_user.user_id = ".(int)$_user['user_id']." ORDER BY `target_date` ASC";
  509. $result = api_sql_query($sql, __FILE__, __LINE__);
  510. if(mysql_numrows($result) > 0)
  511. {
  512. echo '<ul>';
  513. while($mytask = mysql_fetch_array($result))
  514. {
  515. echo '<li><a href="blog.php?action=execute_task&amp;blog_id=' . $mytask['blog_id'] . '&amp;task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: '.stripslashes($mytask['blog_name']) . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
  516. }
  517. echo '<ul>';
  518. }
  519. else
  520. {
  521. echo get_lang('NoTasks');
  522. }
  523. }
  524. else
  525. {
  526. echo get_lang('NoTasks');
  527. }
  528. }
  529. /**
  530. * Changes the visibility of a blog
  531. * @author Toon Keppens
  532. *
  533. * @param Integer $blog_id
  534. *
  535. * @return void
  536. */
  537. function change_blog_visibility($blog_id)
  538. {
  539. // Init
  540. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  541. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  542. // Get blog properties
  543. $sql = "SELECT blog_name, visibility FROM $tbl_blogs WHERE blog_id='".(int)$blog_id."'";
  544. $result = api_sql_query($sql, __FILE__, __LINE__);
  545. $blog = mysql_fetch_array($result);
  546. $visibility = $blog['visibility'];
  547. $title = $blog['blog_name'];
  548. if($visibility == 1)
  549. {
  550. // Change visibility state, remove from course home.
  551. $sql = "UPDATE $tbl_blogs SET `visibility` = '0' WHERE `blog_id` ='".(int)$blog_id."' LIMIT 1";
  552. $result = api_sql_query($sql, __FILE__, __LINE__);
  553. $sql = "DELETE FROM $tbl_tool WHERE name = '".mysql_real_escape_string($title)."' LIMIT 1";
  554. $result = api_sql_query($sql, __FILE__, __LINE__);
  555. }
  556. else
  557. {
  558. // Change visibility state, add to course home.
  559. $sql = "UPDATE $tbl_blogs SET `visibility` = '1' WHERE `blog_id` ='".(int)$blog_id."' LIMIT 1";
  560. $result = api_sql_query($sql, __FILE__, __LINE__);
  561. $sql = "INSERT INTO $tbl_tool (`name`, `link`, `image`, `visibility`, `admin`, `address`, `added_tool`, `target` )
  562. VALUES ('".mysql_real_escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
  563. $result = api_sql_query($sql, __FILE__, __LINE__);
  564. }
  565. return void;
  566. }
  567. /**
  568. * Shows the posts of a blog
  569. * @author Toon Keppens
  570. *
  571. * @param Integer $blog_id
  572. */
  573. function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
  574. {
  575. // Init
  576. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  577. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  578. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  579. global $dateFormatLong;
  580. // Get posts and authors
  581. $sql = "SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts post
  582. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  583. WHERE post.blog_id = '".(int)$blog_id."'
  584. AND $filter
  585. ORDER BY post_id DESC LIMIT 0,".(int)$max_number_of_posts;
  586. $result = api_sql_query($sql, __FILE__, __LINE__);
  587. // Display
  588. if(mysql_num_rows($result) > 0)
  589. {
  590. while($blog_post = mysql_fetch_array($result))
  591. {
  592. // Get number of comments
  593. $sql = "SELECT COUNT(1) as number_of_comments FROM $tbl_blogs_comments WHERE blog_id = '".(int)$blog_id."' AND post_id = '" . (int)$blog_post['post_id']."'";
  594. $tmp = api_sql_query($sql, __FILE__, __LINE__);
  595. $blog_post_comments = mysql_fetch_array($tmp);
  596. // Prepare data
  597. $blog_post_id = $blog_post['post_id'];
  598. $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
  599. $blog_post_date = ucfirst(format_locale_date($dateFormatLong,strtotime($blog_post['date_creation'])));
  600. $blog_post_time = date('H:i',strtotime($blog_post['date_creation']));
  601. // Create an introduction text (but keep FULL sentences)
  602. $limit = 100; //nmbr of words in introduction text
  603. $introduction_text = "";
  604. $words = 0;
  605. $tok = strtok(make_clickable(stripslashes($blog_post['full_text'])), " ");
  606. //original
  607. //$tok = strtok(make_clickable(stripslashes(strip_tags($blog_post['full_text'],"<br><p><ol><ul><li><img>"))), " ");
  608. while($tok)
  609. {
  610. $introduction_text .= " $tok";
  611. $words++;
  612. // check if the number of words is larger than our limit AND if this token ends with a ! . or ? (meaning end of sentance).
  613. if(($words >= $limit) && ((substr($tok, -1) == "!")||(substr($tok, -1) == ".")||(substr($tok, -1) == "?")))
  614. {
  615. break;
  616. }
  617. $tok = strtok(" ");
  618. }
  619. if($words >= $limit)
  620. {
  621. $readMoreLink = ' <span class="link" onclick="document.getElementById(\'blogpost_text_' . $blog_post_id . '\').style.display=\'block\'; document.getElementById(\'blogpost_introduction_' . $blog_post_id . '\').style.display=\'none\'">' . get_lang('ReadMore') . '</span>';
  622. }
  623. else
  624. {
  625. $readMoreLink = '';
  626. }
  627. $introduction_text=stripslashes($introduction_text);
  628. echo '<div class="blogpost">'."\n";
  629. echo '<span class="blogpost_title"><a href="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>'."\n";
  630. echo '<span class="blogpost_date">' . $blog_post_date . ' (' . $blog_post_time . ')</span>'."\n";
  631. echo '<span class="blogpost_introduction" id="blogpost_introduction_' . $blog_post_id . '">' . $introduction_text . $readMoreLink . '</span>'."\n";
  632. echo '<span class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</span>'."\n";
  633. echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . $blog_post['lastname'] . ' ' . $blog_post['firstname'] . ' - <a href="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $blog_post['post_id'] . '#add_comment" title="' . get_lang('ReadPost') . '" >' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . '</a></span>'."\n";
  634. echo '</div>'."\n";
  635. }
  636. } else {
  637. if($filter == '1=1')
  638. {
  639. echo get_lang('NoArticles');
  640. }
  641. else
  642. {
  643. echo get_lang('NoArticleMatches');
  644. }
  645. }
  646. }
  647. /**
  648. * Display the search results
  649. *
  650. * @param Integer $blog_id
  651. * @param String $query_string
  652. */
  653. function display_search_results($blog_id, $query_string)
  654. {
  655. // Init
  656. $query_string_parts = explode(' ',$query_string);
  657. $query_string = array();
  658. foreach ($query_string_parts as $query_part)
  659. {
  660. $query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
  661. }
  662. $query_string = '('.implode('OR',$query_string) . ')';
  663. // Display the posts
  664. echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
  665. Blog::display_blog_posts($blog_id, $query_string);
  666. }
  667. /**
  668. * Display posts from a certain date
  669. *
  670. * @param Integer $blog_id
  671. * @param String $query_string
  672. */
  673. function display_day_results($blog_id, $query_string)
  674. {
  675. // Init
  676. $date_output = $query_string;
  677. $date = explode('-',$query_string);
  678. $query_string = ' DAYOFMONTH(`date_creation`) =' . $date[2] . ' AND MONTH(`date_creation`) =' . $date[1] . ' AND YEAR(`date_creation`) =' . $date[0];
  679. global $dateFormatLong;
  680. // Put date in correct output format
  681. $date_output = ucfirst(format_locale_date($dateFormatLong,strtotime($date_output)));
  682. // Display the posts
  683. echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
  684. Blog::display_blog_posts($blog_id, $query_string);
  685. }
  686. /**
  687. * Displays a post and his comments
  688. *
  689. * @param Integer $blog_id
  690. * @param Integer $post_id
  691. */
  692. function display_post($blog_id, $post_id)
  693. {
  694. // Init
  695. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  696. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  697. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  698. global $charset,$dateFormatLong;
  699. // Get posts and author
  700. $sql = "SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts post
  701. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  702. WHERE post.blog_id = '".(int)$blog_id."'
  703. AND post.post_id = '".(int)$post_id."'
  704. ORDER BY post_id DESC";
  705. $result = api_sql_query($sql, __FILE__, __LINE__);
  706. $blog_post = mysql_fetch_array($result);
  707. // Get number of comments
  708. $sql = "SELECT COUNT(1) as number_of_comments FROM $tbl_blogs_comments WHERE blog_id = '".(int)$blog_id."' AND post_id = '".(int)$post_id."'";
  709. $result = api_sql_query($sql, __FILE__, __LINE__);
  710. $blog_post_comments = mysql_fetch_array($result);
  711. // Prepare data
  712. $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
  713. $blog_post_date = ucfirst(format_locale_date($dateFormatLong,strtotime($blog_post['date_creation'])));
  714. $blog_post_time = date('H:m',strtotime($blog_post['date_creation']));
  715. $blog_post_actions = "";
  716. $task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  717. if(api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id))
  718. $blog_post_actions .= '<a href="blog.php?action=edit_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $post_id . '&amp;article_id=' . $blog_post['post_id'] . '&amp;task_id=' . $task_id . '" title="' . get_lang('EditThisPost') . '"><img src="../img/edit.gif" /></a>';
  719. if(api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id))
  720. $blog_post_actions .= '<a href="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $post_id . '&amp;do=delete_article&amp;article_id=' . $blog_post['post_id'] . '&amp;task_id=' . $task_id . '" title="' . get_lang('DeleteThisArticle') . '" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"><img src="../img/delete.gif" border="0" /></a>';
  721. if(api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
  722. $rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
  723. $blog_post_text=stripslashes($blog_post_text);
  724. // Display post
  725. echo '<div class="blogpost">';
  726. echo '<span class="blogpost_title"><a href="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $blog_post['post_id'] . '" title="' . get_lang('ReadPost') . '" >'.stripslashes($blog_post['title']) . '</a></span>';
  727. echo '<span class="blogpost_date">' . $blog_post_date . ' (' . $blog_post_time . ')</span>';
  728. echo '<span class="blogpost_text">' . $blog_post_text . '</span>';
  729. echo '<span class="blogpost_info">' . get_lang('Author') . ': ' . $blog_post['lastname'] . ' ' . $blog_post['firstname'] . ' - ' . get_lang('Comments') . ': ' . $blog_post_comments['number_of_comments'] . ' - ' . get_lang('Rating') . ': '.Blog::display_rating('post',$blog_id,$post_id) . $rating_select . '</span>';
  730. echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
  731. echo '</div>';
  732. // Display comments if there are any
  733. if($blog_post_comments['number_of_comments'] > 0)
  734. {
  735. echo '<div class="comments">';
  736. echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
  737. Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
  738. echo '</div>';
  739. }
  740. // Display comment form
  741. if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_add'))
  742. {
  743. Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
  744. }
  745. }
  746. /**
  747. * Adds rating to a certain post or comment
  748. * @author Toon Keppens
  749. *
  750. * @param String $type
  751. * @param Integer $blog_id
  752. * @param Integer $item_id
  753. * @param Integer $rating
  754. *
  755. * @return Boolean success
  756. */
  757. function add_rating($type, $blog_id, $item_id, $rating)
  758. {
  759. global $_user;
  760. // Init
  761. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  762. // Check if the user has already rated this post/comment
  763. $sql = "SELECT rating_id FROM $tbl_blogs_rating
  764. WHERE blog_id = '".(int)$blog_id."'
  765. AND item_id = '".(int)$item_id."'
  766. AND rating_type = '".mysql_real_escape_string($type)."'
  767. AND user_id = '".(int)$_user['user_id']."'";
  768. $result = api_sql_query($sql, __FILE__, __LINE__);
  769. if(mysql_num_rows($result) == 0) // Add rating
  770. {
  771. $sql = "INSERT INTO $tbl_blogs_rating ( `blog_id`, `rating_type`, `item_id`, `user_id`, `rating` )
  772. VALUES ('".(int)$blog_id."', '".mysql_real_escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".mysql_real_escape_string($rating)."')";
  773. $result = api_sql_query($sql, __FILE__, __LINE__);
  774. return true;
  775. }
  776. else // Return
  777. {
  778. return false;
  779. }
  780. }
  781. function display_rating($type, $blog_id, $item_id)
  782. {
  783. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  784. // Calculate rating
  785. $sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating WHERE blog_id = '".(int)$blog_id."' AND item_id = '".(int)$item_id."' AND rating_type = '".mysql_real_escape_string($type)."' ";
  786. $result = api_sql_query($sql, __FILE__, __LINE__);
  787. $result = mysql_fetch_array($result);
  788. return round($result['rating'], 2);
  789. }
  790. /**
  791. * Shows the rating form if not already rated by that user
  792. * @author Toon Keppens
  793. *
  794. * @param String $type
  795. * @param Integer $blog_id
  796. * @param Integer $item_id
  797. *
  798. */
  799. function display_rating_form($type, $blog_id, $post_id, $comment_id = NULL)
  800. {
  801. global $_user;
  802. // Init
  803. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  804. if($type == 'post')
  805. {
  806. // Check if the user has already rated this post
  807. $sql = "SELECT rating_id FROM $tbl_blogs_rating
  808. WHERE blog_id = '".(int)$blog_id."'
  809. AND item_id = '".(int)$post_id."'
  810. AND rating_type = '".mysql_real_escape_string($type)."'
  811. AND user_id = '".(int)$_user['user_id']."'";
  812. $result = api_sql_query($sql, __FILE__, __LINE__);
  813. if(mysql_num_rows($result) == 0) // Add rating
  814. {
  815. return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';
  816. }
  817. else // Return
  818. {
  819. return '';
  820. }
  821. }
  822. if($type = 'comment')
  823. {
  824. // Check if the user has already rated this comment
  825. $sql = "SELECT rating_id FROM $tbl_blogs_rating
  826. WHERE blog_id = '".(int)$blog_id ."'
  827. AND item_id = '".(int)$comment_id."'
  828. AND rating_type = '".mysql_real_escape_string($type)."'
  829. AND user_id = '".(int)$_user['user_id']."'";
  830. $result = api_sql_query($sql, __FILE__, __LINE__);
  831. if(mysql_num_rows($result) == 0) // Add rating
  832. {
  833. return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';
  834. }
  835. else // Return
  836. {
  837. return '';
  838. }
  839. }
  840. }
  841. /**
  842. * This functions gets all replys to a post, threaded.
  843. *
  844. * @param Integer $current
  845. * @param Integer $current_level
  846. * @param Integer $blog_id
  847. * @param Integer $post_id
  848. */
  849. function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
  850. {
  851. // Init
  852. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  853. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  854. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  855. global $charset,$dateFormatLong;
  856. // Select top level comments
  857. $next_level = $current_level + 1;
  858. $sql = "SELECT comments.*, user.lastname, user.firstname, task.color
  859. FROM $tbl_blogs_comments comments
  860. INNER JOIN $tbl_users user ON comments.author_id = user.user_id
  861. LEFT JOIN $tbl_blogs_tasks task ON comments.task_id = task.task_id
  862. WHERE parent_comment_id = $current
  863. AND comments.blog_id = '".(int)$blog_id."'
  864. AND comments.post_id = '".(int)$post_id."'";
  865. $result = api_sql_query($sql, __FILE__, __LINE__);
  866. while($comment = mysql_fetch_array($result))
  867. {
  868. // Select the children recursivly
  869. $tmp = "SELECT comments.*, user.lastname, user.firstname FROM $tbl_blogs_comments comments
  870. INNER JOIN $tbl_users user ON comments.author_id = user.user_id
  871. WHERE comment_id = $current
  872. AND blog_id = '".(int)$blog_id."'
  873. AND post_id = '".(int)$post_id."'";
  874. $tmp = api_sql_query($tmp, __FILE__, __LINE__);
  875. $tmp = mysql_fetch_array($tmp);
  876. $parent_cat = $tmp['parent_comment_id'];
  877. $border_color = '';
  878. // Prepare data
  879. $comment_text = make_clickable(stripslashes($comment['comment']));
  880. $blog_comment_date = ucfirst(format_locale_date($dateFormatLong,strtotime($comment['date_creation'])));
  881. $blog_comment_time = date('H:i',strtotime($comment['date_creation']));
  882. $blog_comment_actions = "";
  883. if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_delete', $task_id)) { $blog_comment_actions .= '<a href="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $post_id . '&amp;do=delete_comment&amp;comment_id=' . $comment['comment_id'] . '&amp;task_id=' . $task_id . '" title="' . get_lang('DeleteThisComment') . '" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"><img src="../img/delete.gif" border="0" /></a>'; }
  884. if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_rate')) { $rating_select = Blog::display_rating_form('comment', $blog_id, $post_id, $comment['comment_id']); }
  885. if(!is_null($comment['task_id']))
  886. {
  887. $border_color = ' border-left: 3px solid #' . $comment['color'];
  888. }
  889. $comment_text=stripslashes($comment_text);
  890. // Output...
  891. $margin = $current_level * 30;
  892. echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
  893. echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';
  894. echo '<span class="blogpost_comment_date">' . $blog_comment_date . ' (' . $blog_comment_time . ')</span>';
  895. echo '<span class="blogpost_text">' . $comment_text . '</span>';
  896. echo '<span class="blogpost_comment_info">' . get_lang('Author') . ': ' . $comment['lastname'] . ' ' . $comment['firstname'] . ' - ' . get_lang('Rating') . ': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']) . $rating_select . '</span>';
  897. echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
  898. echo '</div>';
  899. // Go further down the tree.
  900. Blog::get_threaded_comments( $comment['comment_id'], $next_level, $blog_id, $post_id);
  901. }
  902. }
  903. /**
  904. * Displays the form to create a new post
  905. * @author Toon Keppens
  906. *
  907. * @param Integer $blog_id
  908. */
  909. function display_form_new_post($blog_id)
  910. {
  911. if(api_is_allowed('BLOG_' . $blog_id, 'article_add'))
  912. {
  913. echo '<script type="text/javascript">
  914. function FCKeditor_OnComplete( editorInstance )
  915. {
  916. editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;
  917. }
  918. function check_for_title()
  919. {
  920. // This functions shows that you can interact directly with the editor area
  921. // DOM. In this way you have the freedom to do anything you want with it.
  922. // Get the editor instance that we want to interact with.
  923. var oEditor = FCKeditorAPI.GetInstance(\'post_full_text\') ;
  924. // Get the Editor Area DOM (Document object).
  925. var oDOM = oEditor.EditorDocument ;
  926. var iLength ;
  927. var contentText ;
  928. var contentTextArray;
  929. var bestandsnaamNieuw = "";
  930. var bestandsnaamOud = "";
  931. // The are two diffent ways to get the text (without HTML markups).
  932. // It is browser specific.
  933. if( document.all ) // If Internet Explorer.
  934. {
  935. contentText = oDOM.body.innerText ;
  936. }
  937. else // If Gecko.
  938. {
  939. var r = oDOM.createRange() ;
  940. r.selectNodeContents( oDOM.body ) ;
  941. contentText = r.toString() ;
  942. }
  943. // Compose title if there is none
  944. contentTextArray = contentText.split(\' \') ;
  945. var x=0;
  946. for(x=0; (x<5 && x<contentTextArray.length); x++)
  947. {
  948. if(x < 4)
  949. {
  950. bestandsnaamNieuw += contentTextArray[x] + \' \';
  951. }
  952. else
  953. {
  954. bestandsnaamNieuw += contentTextArray[x] + \'...\';
  955. }
  956. }
  957. if(document.getElementById(\'post_title_edited\').value == "false")
  958. {
  959. document.getElementById(\'post_title\').value = bestandsnaamNieuw;
  960. }
  961. }
  962. function trim(s) {
  963. while(s.substring(0,1) == \' \') {
  964. s = s.substring(1,s.length);
  965. }
  966. while(s.substring(s.length-1,s.length) == \' \') {
  967. s = s.substring(0,s.length-1);
  968. }
  969. return s;
  970. }
  971. function check_if_still_empty()
  972. {
  973. if(trim(document.getElementById(\'post_title\').value) != "")
  974. {
  975. document.getElementById(\'post_title_edited\').value = "true";
  976. }
  977. }
  978. </script>';
  979. echo '<form name="add_post" method="post" action="blog.php?blog_id=' . $blog_id . '">
  980. <span class="blogpost_title">' . get_lang('NewPost') . '</span>
  981. <table width="100%" border="0" cellspacing="2" cellpadding="0">
  982. <tr>
  983. <td width="80" valign="top">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  984. <td><input name="post_title" id="post_title" type="text" size="60" onblur="check_if_still_empty()" /><input type="hidden" name="post_title_edited" id="post_title_edited" value="false" /><br /><br /></td>
  985. </tr>
  986. <tr>
  987. <td valign="top">' . get_lang('PostFullText') . ':&nbsp;&nbsp;</td>
  988. <td>';
  989. $oFCKeditor = new FCKeditor('post_full_text') ;
  990. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  991. $oFCKeditor->Height = '350';
  992. $oFCKeditor->Width = '98%';
  993. $oFCKeditor->Value = isset($_POST['post_full_text'])?stripslashes($_POST['post_full_text']):'';
  994. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  995. $oFCKeditor->Config['IMUploadPath'] = "upload/blog/";
  996. $oFCKeditor->ToolbarSet = "Blog";
  997. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  998. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".mysql_real_escape_string($_SESSION["_course"]["language"])."'";
  999. $result_sql=api_sql_query($sql);
  1000. $isocode_language=mysql_result($result_sql,0,0);
  1001. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  1002. $oFCKeditor->Create() ;
  1003. echo ' <br /></td>
  1004. </tr>
  1005. <tr>
  1006. <td >&nbsp;</td>
  1007. <td>
  1008. <input type="hidden" name="action" value="" />
  1009. <input type="hidden" name="new_post_submit" value="true" />
  1010. <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />
  1011. </td>
  1012. </tr>
  1013. </table>
  1014. </form>';
  1015. }
  1016. else
  1017. {
  1018. api_not_allowed();
  1019. }
  1020. }
  1021. /**
  1022. * Displays the form to edit a post
  1023. * @author Toon Keppens
  1024. *
  1025. * @param Integer $blog_id
  1026. */
  1027. function display_form_edit_post($blog_id, $post_id)
  1028. {
  1029. // Init
  1030. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  1031. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1032. // Get posts and author
  1033. $sql = "SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts post
  1034. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  1035. WHERE post.blog_id = '".(int)$blog_id ."'
  1036. AND post.post_id = '".(int)$post_id."'
  1037. ORDER BY post_id DESC";
  1038. $result = api_sql_query($sql, __FILE__, __LINE__);
  1039. $blog_post = mysql_fetch_array($result);
  1040. // Prepare data
  1041. $blog_post_text = stripslashes($blog_post['full_text']);
  1042. echo '<form name="edit_post" method="post" action="blog.php?blog_id=' . $blog_id . '">
  1043. <span class="blogpost_title">' . get_lang('EditPost') . '</span>
  1044. <table width="100%" border="0" cellspacing="2" cellpadding="0">
  1045. <tr>
  1046. <td width="80" valign="top">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1047. <td><input name="post_title" id="post_title" type="text" size="60" value="'.stripslashes($blog_post['title']) . '" /><br /><br /></td>
  1048. </tr>
  1049. <tr>
  1050. <td valign="top">' . get_lang('PostFullText') . ':&nbsp;&nbsp;</td>
  1051. <td>';
  1052. $oFCKeditor = new FCKeditor('post_full_text') ;
  1053. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  1054. $oFCKeditor->Height = '350';
  1055. $oFCKeditor->Width = '98%';
  1056. $oFCKeditor->Value = isset($_POST['post_full_text'])?stripslashes($_POST['post_full_text']):$blog_post_text;
  1057. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  1058. $oFCKeditor->Config['IMUploadPath'] = "upload/blog/";
  1059. $oFCKeditor->ToolbarSet = "Blog";
  1060. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  1061. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".mysql_real_escape_string($_SESSION["_course"]["language"])."'";
  1062. $result_sql=api_sql_query($sql);
  1063. $isocode_language=mysql_result($result_sql,0,0);
  1064. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  1065. $oFCKeditor->Create() ;
  1066. echo ' <br /></td>
  1067. </tr>
  1068. <tr>
  1069. <td >&nbsp;</td>
  1070. <td>
  1071. <input type="hidden" name="action" value="" />
  1072. <input type="hidden" name="edit_post_submit" value="true" />
  1073. <input type="hidden" name="post_id" value="' . (int)$_GET['post_id'] . '" />
  1074. <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />
  1075. </td>
  1076. </tr>
  1077. </table>
  1078. </form>';
  1079. }
  1080. /**
  1081. * Displays a list of tasks in this blog
  1082. * @author Toon Keppens
  1083. *
  1084. * @param Integer $blog_id
  1085. */
  1086. function display_task_list($blog_id)
  1087. {
  1088. global $charset;
  1089. if(api_is_allowed('BLOG_' . $blog_id, 'article_add'))
  1090. {
  1091. // Init
  1092. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1093. $counter = 0;
  1094. global $color2;
  1095. echo '<a href="' .api_get_self(). '?action=manage_tasks&amp;blog_id=' . $blog_id . '&amp;do=add"><img src="../img/blog.gif" border="0" align="middle" alt="scormbuilder" />' . get_lang('AddTasks') . '</a> ';
  1096. echo '<a href="' .api_get_self(). '?action=manage_tasks&amp;blog_id=' . $blog_id . '&amp;do=assign"><img src="../img/blog.gif" border="0" align="middle" alt="scormbuilder" />' . get_lang('AssignTasks') . '</a>';
  1097. echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
  1098. echo "<table class=\"data_table\">";
  1099. echo "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
  1100. "<th width='240'><b>",get_lang('Title'),"</b></th>\n",
  1101. "<th><b>",get_lang('Description'),"</b></th>\n",
  1102. "<th><b>",get_lang('Color'),"</b></th>\n",
  1103. "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
  1104. "</tr>\n";
  1105. $sql = "
  1106. SELECT
  1107. `blog_id`,
  1108. `task_id`,
  1109. `blog_id`,
  1110. `title`,
  1111. `description`,
  1112. `color`,
  1113. `system_task`
  1114. FROM " . $tbl_blogs_tasks . "
  1115. WHERE `blog_id` = " . (int)$blog_id . "
  1116. ORDER BY
  1117. `system_task`,
  1118. `title`";
  1119. $result = api_sql_query($sql, __FILE__, __LINE__);
  1120. while($task = mysql_fetch_array($result))
  1121. {
  1122. $counter++;
  1123. $css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
  1124. $delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
  1125. $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
  1126. $delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&amp;blog_id=' . $task['blog_id'] . '&amp;do=delete&amp;task_id=' . $task['task_id'];
  1127. $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
  1128. echo '<tr class="' . $css_class . '" valign="top">',
  1129. '<td width="240">' . stripslashes($task['title']) . '</td>',
  1130. '<td>' . stripslashes($task['description']) . '</td>',
  1131. '<td><span style="background-color: #' . $task['color'] . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>',
  1132. '<td width="50">',
  1133. '<a href="' .api_get_self(). '?action=manage_tasks&amp;blog_id=' . $task['blog_id'] . '&amp;do=edit&amp;task_id=' . $task['task_id'] . '">',
  1134. '<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
  1135. "</a>\n",
  1136. '<a href="' . $delete_link . '"',
  1137. $delete_confirm,
  1138. '><img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
  1139. "</a>\n",
  1140. '</td>',
  1141. '</tr>';
  1142. }
  1143. echo "</table>";
  1144. }
  1145. }
  1146. /**
  1147. * Displays a list of tasks assigned to a user in this blog
  1148. * @author Toon Keppens
  1149. *
  1150. * @param Integer $blog_id
  1151. */
  1152. function display_assigned_task_list($blog_id)
  1153. {
  1154. // Init
  1155. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1156. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1157. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1158. $counter = 0;
  1159. global $charset,$color2;
  1160. echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
  1161. echo "<table class=\"data_table\">";
  1162. echo "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
  1163. "<th width='240'><b>",get_lang('Member'),"</b></th>\n",
  1164. "<th><b>",get_lang('Task'),"</b></th>\n",
  1165. "<th><b>",get_lang('Description'),"</b></th>\n",
  1166. "<th><b>",get_lang('TargetDate'),"</b></th>\n",
  1167. "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
  1168. "</tr>\n";
  1169. $sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, task.description FROM $tbl_blogs_tasks_rel_user task_rel_user
  1170. INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
  1171. INNER JOIN $tbl_users user ON task_rel_user.user_id = user.user_id
  1172. WHERE task_rel_user.blog_id = '".(int)$blog_id."' ORDER BY `target_date` ASC";
  1173. $result = api_sql_query($sql, __FILE__, __LINE__);
  1174. while($assignment = mysql_fetch_array($result))
  1175. {
  1176. $counter++;
  1177. $css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
  1178. $delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
  1179. $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
  1180. $delete_link = ($task['system_task'] == '1') ? '#' : api_get_self() . '?action=manage_tasks&amp;blog_id=' . $task['blog_id'] . '&amp;do=delete&amp;task_id=' . $task['task_id'];
  1181. $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
  1182. echo '<tr class="' . $css_class . '" valign="top">',
  1183. '<td width="240">' . $assignment['firstname'] . ' ' . $assignment['lastname'] . '</td>',
  1184. '<td>'.stripslashes($assignment['title']) . '</td>',
  1185. '<td>'.stripslashes($assignment['description']) . '</td>',
  1186. '<td>' . $assignment['target_date'] . '</td>',
  1187. '<td width="50">',
  1188. '<a href="' .api_get_self(). '?action=manage_tasks&amp;blog_id=' . $assignment['blog_id'] . '&amp;do=edit_assignment&amp;assignment_id=' . $assignment['task_id'] . '|' . $assignment['user_id'] . '">',
  1189. '<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
  1190. "</a>\n",
  1191. '<a href="' .api_get_self(). '?action=manage_tasks&amp;blog_id=' . $assignment['blog_id'] . '&amp;do=delete_assignment&amp;assignment_id=' . $assignment['task_id'] . '|' . $assignment['user_id'] . '" ',
  1192. 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"',
  1193. '<img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
  1194. "</a>\n",
  1195. '</td>',
  1196. '</tr>';
  1197. }
  1198. echo "</table>";
  1199. }
  1200. /**
  1201. * Displays new task form
  1202. * @author Toon Keppens
  1203. *
  1204. */
  1205. function display_new_task_form($blog_id)
  1206. {
  1207. // Init
  1208. $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
  1209. // Display
  1210. echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1211. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1212. <tr>
  1213. <td width="200"></td>
  1214. <td><b>' . get_lang('AddTask') . '</b><br /><br /></td>
  1215. </tr>
  1216. <tr>
  1217. <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1218. <td><input name="task_name" type="text" size="70" /></td>
  1219. </tr>
  1220. <tr>
  1221. <td align="right">' . get_lang('Description') . ':&nbsp;&nbsp;</td>
  1222. <td><input name="task_description" type="text" size="70" /></td>
  1223. </tr>';
  1224. /* edit by Kevin Van Den Haute (kevin@develop-it.be) */
  1225. echo "\t" . '<tr>' . "\n";
  1226. echo "\t\t" . '<td style="text-align:right; vertical-align:top;">Task management:&nbsp;&nbsp;</td>' . "\n";
  1227. echo "\t\t" . '<td>' . "\n";
  1228. echo "\t\t\t" . '<table cellspacing="0" style="border:1px solid #808080; border-collapse:collapse; width:446px;">';
  1229. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1230. echo "\t\t\t\t\t" . '<th colspan="2" style="border:1px solid #808080; width:223px;">' . get_lang('ArticleManager') . '</th>' . "\n";
  1231. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080;" width:223px;>' . get_lang('CommentManager') . '</th>' . "\n";
  1232. echo "\t\t\t\t" . '</tr>' . "\n";
  1233. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1234. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1235. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>' . "\n";
  1236. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1237. echo "\t\t\t\t" . '</tr>' . "\n";
  1238. echo "\t\t\t\t" . '<tr>' . "\n";
  1239. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>' . "\n";
  1240. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>' . "\n";
  1241. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>' . "\n";
  1242. echo "\t\t\t\t" . '</tr>' . "\n";
  1243. echo "\t\t\t" . '</table>' . "\n";
  1244. echo "\t\t" . '</td>' . "\n";
  1245. echo "\t" . '</tr>' . "\n";
  1246. /* end of edit */
  1247. echo ' <tr>
  1248. <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
  1249. <td>
  1250. <select name="task_color" id="color" style="width: 150px; background-color: #eeeeee" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
  1251. foreach ($colors as $color)
  1252. {
  1253. $style = 'style="background-color: #' . $color . '"';
  1254. echo '<option value="' . $color . '" ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
  1255. }
  1256. echo ' </select>
  1257. </td>
  1258. </tr>
  1259. <tr>
  1260. <td align="right">&nbsp;</td>
  1261. <input type="hidden" name="action" value="" />
  1262. <input type="hidden" name="new_task_submit" value="true" />
  1263. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1264. </tr>
  1265. </table>
  1266. </form>';
  1267. }
  1268. /**
  1269. * Displays edit task form
  1270. * @author Toon Keppens
  1271. *
  1272. */
  1273. function display_edit_task_form($blog_id, $task_id)
  1274. {
  1275. // Init
  1276. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1277. $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
  1278. $sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE task_id = '".(int)$task_id."'";
  1279. $result = api_sql_query($sql, __FILE__, __LINE__);
  1280. $task = mysql_fetch_array($result);
  1281. // Display
  1282. echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1283. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1284. <tr>
  1285. <td width="200"></td>
  1286. <td><b>' . get_lang('EditTask') . '</b><br /><br /></td>
  1287. </tr>
  1288. <tr>
  1289. <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1290. <td><input name="task_name" type="text" size="70" value="'.stripslashes($task['title']) . '" /></td>
  1291. </tr>
  1292. <tr>
  1293. <td align="right">' . get_lang('Description') . ':&nbsp;&nbsp;</td>
  1294. <td><input name="task_description" type="text" size="70" value="'.stripslashes($task['description']) . '" /></td>
  1295. </tr>';
  1296. /* edit by Kevin Van Den Haute (kevin@develop-it.be) */
  1297. $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
  1298. $sql = "
  1299. SELECT
  1300. `id`,
  1301. `action`
  1302. FROM " . $tbl_tasks_permissions . "
  1303. WHERE `task_id` = '" . (int)$task_id."'";
  1304. $result = api_sql_query($sql, __FILE__, __LINE__);
  1305. $arrPermissions = array();
  1306. while($row = @mysql_fetch_array($result))
  1307. $arrPermissions[] = $row['action'];
  1308. echo "\t" . '<tr>' . "\n";
  1309. echo "\t\t" . '<td style="text-align:right; vertical-align:top;">Task management:&nbsp;&nbsp;</td>' . "\n";
  1310. echo "\t\t" . '<td>' . "\n";
  1311. echo "\t\t\t" . '<table cellspacing="0" style="border:1px solid #808080; border-collapse:collapse; width:446px;">';
  1312. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1313. echo "\t\t\t\t\t" . '<th colspan="2" style="border:1px solid #808080; width:223px;">' . get_lang('ArticleManager') . '</th>' . "\n";
  1314. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080;" width:223px;>' . get_lang('CommentManager') . '</th>' . "\n";
  1315. echo "\t\t\t\t" . '</tr>' . "\n";
  1316. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1317. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1318. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>' . "\n";
  1319. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1320. echo "\t\t\t\t" . '</tr>' . "\n";
  1321. echo "\t\t\t\t" . '<tr>' . "\n";
  1322. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input ' . ((in_array('article_delete', $arrPermissions)) ? 'checked ' : '') . 'id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>' . "\n";
  1323. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input ' . ((in_array('article_edit', $arrPermissions)) ? 'checked ' : '') . 'id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>' . "\n";
  1324. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input ' . ((in_array('article_comments_delete', $arrPermissions)) ? 'checked ' : '') . 'id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>' . "\n";
  1325. echo "\t\t\t\t" . '</tr>' . "\n";
  1326. echo "\t\t\t" . '</table>' . "\n";
  1327. echo "\t\t" . '</td>' . "\n";
  1328. echo "\t" . '</tr>' . "\n";
  1329. /* end of edit */
  1330. echo '<tr>
  1331. <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
  1332. <td>
  1333. <select name="task_color" id="color" style="width: 150px; background-color: #' . $task['color'] . '" onchange="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value" onkeypress="document.getElementById(\'color\').style.backgroundColor=\'#\'+document.getElementById(\'color\').value">';
  1334. foreach ($colors as $color)
  1335. {
  1336. $selected = ($color == $task['color']) ? ' selected' : '';
  1337. $style = 'style="background-color: #' . $color . '"';
  1338. echo '<option value="' . $color . '" ' . $style . ' ' . $selected . ' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
  1339. }
  1340. echo ' </select>
  1341. </td>
  1342. </tr>
  1343. <tr>
  1344. <td align="right">&nbsp;</td>
  1345. <td><br /><input type="hidden" name="action" value="" />
  1346. <input type="hidden" name="edit_task_submit" value="true" />
  1347. <input type="hidden" name="task_id" value="' . $task['task_id'] . '" />
  1348. <input type="hidden" name="blog_id" value="' . $task['blog_id'] . '" />
  1349. <input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1350. </tr>
  1351. </table>
  1352. </form>';
  1353. }
  1354. /**
  1355. * Displays assign task form
  1356. * @author Toon Keppens
  1357. *
  1358. */
  1359. function display_assign_task_form($blog_id)
  1360. {
  1361. // Init
  1362. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1363. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1364. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1365. $day = date("d");
  1366. $month = date("m");
  1367. $year = date("Y");
  1368. global $MonthsLong;
  1369. // Get users in this blog / make select list of it
  1370. $sql = "SELECT user.user_id, user.firstname, user.lastname FROM $tbl_users user
  1371. INNER JOIN $tbl_blogs_rel_user blogs_rel_user
  1372. ON user.user_id = blogs_rel_user.user_id
  1373. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1374. $result = api_sql_query($sql, __FILE__, __LINE__);
  1375. $select_user_list = '<select name="task_user_id">';
  1376. while($user = mysql_fetch_array($result))
  1377. {
  1378. $select_user_list .= '<option value="' . $user['user_id'] . '">' . $user['firstname']." " . $user['lastname'] . '</option>';
  1379. }
  1380. $select_user_list .= '</select>';
  1381. // Get tasks in this blog / make select list of it
  1382. $sql = "
  1383. SELECT
  1384. `blog_id`,
  1385. `task_id`,
  1386. `blog_id`,
  1387. `title`,
  1388. `description`,
  1389. `color`,
  1390. `system_task`
  1391. FROM " . $tbl_blogs_tasks . "
  1392. WHERE `blog_id` = " . (int)$blog_id . "
  1393. ORDER BY
  1394. `system_task`,
  1395. `title`";
  1396. $result = api_sql_query($sql, __FILE__, __LINE__);
  1397. $select_task_list = '<select name="task_task_id">';
  1398. while($task = mysql_fetch_array($result))
  1399. {
  1400. $select_task_list .= '<option value="' . $task['task_id'] . '">'.stripslashes($task['title']) . '</option>';
  1401. }
  1402. $select_task_list .= '</select>';
  1403. // Display
  1404. echo '<form name="assign_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1405. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1406. <tr>
  1407. <td width="200"></td>
  1408. <td><b>' . get_lang('AssignTask') . '</b><br /><br /></td>
  1409. </tr>
  1410. <tr>
  1411. <td align="right">' . get_lang('SelectUser') . ':&nbsp;&nbsp;</td>
  1412. <td>' . $select_user_list . '</td>
  1413. </tr>
  1414. <tr>
  1415. <td align="right">' . get_lang('SelectTask') . ':&nbsp;&nbsp;</td>
  1416. <td>' . $select_task_list . '</td>
  1417. </tr>
  1418. <tr>
  1419. <td align="right">' . get_lang('SelectTargetDate') . ':&nbsp;&nbsp;</td>
  1420. <td>
  1421. <select name="task_day">';
  1422. for($i=1; $i<=31; $i++)
  1423. {
  1424. // values need to have double digits
  1425. $value = ($i <= 9 ? "0" . $i : $i);
  1426. // the current day is indicated with [] around the date
  1427. if($value==$day)
  1428. { echo "\t\t\t\t <option value=\"" . $value."\" selected> " . $i." </option>\n";}
  1429. else
  1430. { echo "\t\t\t\t <option value=\"" . $value."\">" . $i."</option>\n"; }
  1431. }
  1432. echo '</select>
  1433. <select name="task_month">';
  1434. for($i=1; $i<=12; $i++)
  1435. {
  1436. // values need to have double digits
  1437. $value = ($i <= 9 ? "0" . $i : $i);
  1438. if($value==$month)
  1439. { echo "\t\t\t\t <option value=\"" . $value."\" selected>" . $MonthsLong[$i-1]."</option>\n"; }
  1440. else
  1441. { echo "\t\t\t\t <option value=\"" . $value."\">" . $MonthsLong[$i-1]."</option>\n"; }
  1442. }
  1443. echo '</select>
  1444. <select name="task_year">
  1445. <option value="'.($year-1) . '">'.($year-1) . '</option>
  1446. <option value="' . $year . '" selected> ' . $year . ' </option>';
  1447. for($i=1; $i<=5; $i++)
  1448. {
  1449. $value=$year+$i;
  1450. echo "\t\t\t\t<option value=\"" . $value."\">" . $value."</option>\n";
  1451. }
  1452. echo '</select>
  1453. <a title="Kalender" href="javascript:openCalendar(\'assign_task\', \'task_\')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a>
  1454. </td>
  1455. </tr>
  1456. <tr>
  1457. <td align="right">&nbsp;</td>
  1458. <input type="hidden" name="action" value="" />
  1459. <input type="hidden" name="assign_task_submit" value="true" />
  1460. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1461. </tr>
  1462. </table>
  1463. </form>';
  1464. }
  1465. /**
  1466. * Displays assign task form
  1467. * @author Toon Keppens
  1468. *
  1469. */
  1470. function display_edit_assigned_task_form($blog_id, $assignment_id)
  1471. {
  1472. $parameters = explode('|', $assignment_id);
  1473. $task_id = $parameters[0];
  1474. $user_id = $parameters[1];
  1475. /* ------------- */
  1476. // Init
  1477. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1478. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1479. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1480. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1481. $year = date("Y");
  1482. global $MonthsLong;
  1483. /*// Get assignd tasks of user
  1484. $sql = "
  1485. SELECT task_id
  1486. FROM $tbl_blogs_tasks_rel_user
  1487. WHERE
  1488. user_id = $user_id AND
  1489. blog_id = $blog_id";
  1490. $result = api_sql_query($sql, __FILE__, __LINE__);
  1491. $arrUserTasks = array();*/
  1492. while($row = mysql_fetch_assoc($result))
  1493. {
  1494. $arrUserTasks[] = $row['task_id'];
  1495. }
  1496. // Get assignd date;
  1497. $sql = "
  1498. SELECT target_date
  1499. FROM $tbl_blogs_tasks_rel_user
  1500. WHERE blog_id = '".(int)$blog_id."'
  1501. AND user_id = '".(int)$user_id."'
  1502. AND task_id = '".(int)$task_id."'";
  1503. $result = api_sql_query($sql, __FILE__, __LINE__);
  1504. $row = mysql_fetch_assoc($result);
  1505. $old_date = $row['target_date'];
  1506. $date = explode('-', $row['target_date']);
  1507. // Get users in this blog / make select list of it
  1508. $sql = "
  1509. SELECT user.user_id, user.firstname, user.lastname
  1510. FROM $tbl_users user
  1511. INNER JOIN $tbl_blogs_rel_user blogs_rel_user on user.user_id = blogs_rel_user.user_id
  1512. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1513. $result = api_sql_query($sql, __FILE__, __LINE__);
  1514. $select_user_list = '<select name="task_user_id">';
  1515. while($user = mysql_fetch_array($result))
  1516. {
  1517. $select_user_list .= '<option ' . (($user_id == $user['user_id']) ? 'selected="selected "' : ' ') . 'value="' . $user['user_id'] . '">' . $user['firstname']." " . $user['lastname'] . '</option>';
  1518. }
  1519. $select_user_list .= '</select>';
  1520. // Get tasks in this blog / make select list of it
  1521. $sql = "
  1522. SELECT
  1523. `blog_id`,
  1524. `task_id`,
  1525. `title`,
  1526. `description`,
  1527. `color`,
  1528. `system_task`
  1529. FROM " . $tbl_blogs_tasks . "
  1530. WHERE `blog_id` = " . (int)$blog_id . "
  1531. ORDER BY
  1532. `system_task`,
  1533. `title`";
  1534. $result = api_sql_query($sql, __FILE__, __LINE__);
  1535. $select_task_list = '<select name="task_task_id">';
  1536. while($task = mysql_fetch_array($result))
  1537. {
  1538. //if(!in_array($task['task_id'], $arrUserTasks) || $task_id == $task['task_id'])
  1539. $select_task_list .= '<option ' . (($task_id == $task['task_id']) ? 'selected="selected "' : ' ') . 'value="' . $task['task_id'] . '">'.stripslashes($task['title']) . '</option>';
  1540. }
  1541. $select_task_list .= '</select>';
  1542. // Display
  1543. echo '<form name="assign_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1544. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1545. <tr>
  1546. <td width="200"></td>
  1547. <td><b>' . get_lang('AssignTask') . '</b><br /><br /></td>
  1548. </tr>
  1549. <tr>
  1550. <td align="right">' . get_lang('SelectUser') . ':&nbsp;&nbsp;</td>
  1551. <td>' . $select_user_list . '</td>
  1552. </tr>
  1553. <tr>
  1554. <td align="right">' . get_lang('SelectTask') . ':&nbsp;&nbsp;</td>
  1555. <td>' . $select_task_list . '</td>
  1556. </tr>
  1557. <tr>
  1558. <td align="right">' . get_lang('SelectTargetDate') . ':&nbsp;&nbsp;</td>
  1559. <td>
  1560. <select name="task_day">';
  1561. for($i=1; $i<=31; $i++)
  1562. {
  1563. // values need to have double digits
  1564. $value = ($i <= 9 ? "0" . $i : $i);
  1565. echo "\t\t\t\t<option " . (($date[2] == $value) ? 'selected="selected "' : ' ') . "value=\"" . $value . "\">" . $i . "</option>\n";
  1566. }
  1567. echo '</select>
  1568. <select name="task_month">';
  1569. for($i=1; $i<=12; $i++)
  1570. {
  1571. // values need to have double digits
  1572. $value = ($i <= 9 ? "0" . $i : $i);
  1573. echo "\t\t\t\t<option " . (($date[1] == $value) ? 'selected="selected "' : ' ') . "value=\"" . $value . "\">" . $MonthsLong[$i-1]."</option>\n";
  1574. }
  1575. echo '</select>
  1576. <select name="task_year">
  1577. <option value="' . ($year - 1) . '">' . ($year - 1) . '</option>
  1578. <option value="' . $year . '" selected> ' . $year . ' </option>';
  1579. for($i=1; $i<=5; $i++)
  1580. {
  1581. $value = $year + $i;
  1582. echo "\t\t\t\t<option " . (($date[0] == $value) ? 'selected="selected "' : ' ') . "value=\"" . $value . "\">" . $value . "</option>\n";
  1583. }
  1584. echo '</select>
  1585. <a title="Kalender" href="javascript:openCalendar(\'assign_task\', \'task_\')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a>
  1586. </td>
  1587. </tr>
  1588. <tr>
  1589. <td align="right">&nbsp;</td>
  1590. <input type="hidden" name="action" value="" />
  1591. <input type="hidden" name="old_task_id" value="' . $task_id . '" />
  1592. <input type="hidden" name="old_user_id" value="' . $user_id . '" />
  1593. <input type="hidden" name="old_target_date" value="' . $old_date . '" />
  1594. <input type="hidden" name="assign_task_edit_submit" value="true" />
  1595. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1596. </tr>
  1597. </table>
  1598. </form>';
  1599. }
  1600. /**
  1601. * Assigns a task to a user in a blog
  1602. *
  1603. * @param Integer $blog_id
  1604. * @param Integer $user_id
  1605. * @param Integer $task_id
  1606. * @param Date $target_date
  1607. */
  1608. function assign_task($blog_id, $user_id, $task_id, $target_date)
  1609. {
  1610. // Init
  1611. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1612. $sql = "
  1613. SELECT COUNT(*) as 'number'
  1614. FROM " . $tbl_blogs_tasks_rel_user . "
  1615. WHERE `blog_id` = " . (int)$blog_id . "
  1616. AND `user_id` = " . (int)$user_id . "
  1617. AND `task_id` = " . (int)$task_id . "
  1618. ";
  1619. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1620. $row = mysql_fetch_assoc($result);
  1621. if($row['number'] == 0)
  1622. {
  1623. $sql = "
  1624. INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
  1625. `blog_id`,
  1626. `user_id`,
  1627. `task_id`,
  1628. `target_date`
  1629. ) VALUES (
  1630. '" . (int)$blog_id . "',
  1631. '" . (int)$user_id . "',
  1632. '" . (int)$task_id . "',
  1633. '" . mysql_real_escape_string($target_date) . "'
  1634. )";
  1635. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1636. }
  1637. }
  1638. function edit_assigned_task($blog_id, $user_id, $task_id, $target_date, $old_user_id, $old_task_id, $old_target_date)
  1639. {
  1640. // Init
  1641. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1642. $sql = "
  1643. SELECT COUNT(*) as 'number'
  1644. FROM " . $tbl_blogs_tasks_rel_user . "
  1645. WHERE
  1646. `blog_id` = " . (int)$blog_id . " AND
  1647. `user_id` = " . (int)$user_id . " AND
  1648. `task_id` = " . (int)$task_id . "
  1649. ";
  1650. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1651. $row = mysql_fetch_assoc($result);
  1652. if($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id))
  1653. {
  1654. $sql = "
  1655. UPDATE " . $tbl_blogs_tasks_rel_user . "
  1656. SET
  1657. `user_id` = " . (int)$user_id . ",
  1658. `task_id` = " . (int)$task_id . ",
  1659. `target_date` = '" . mysql_real_escape_string($target_date) . "'
  1660. WHERE
  1661. `blog_id` = " . (int)$blog_id . " AND
  1662. `user_id` = " . (int)$old_user_id . " AND
  1663. `task_id` = " . (int)$old_task_id . " AND
  1664. `target_date` = '" . mysql_real_escape_string($old_target_date) . "'
  1665. ";
  1666. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1667. }
  1668. }
  1669. /**
  1670. * Displays a list with posts a user can select to execute his task.
  1671. *
  1672. * @param Integer $blog_id
  1673. * @param unknown_type $task_id
  1674. */
  1675. function display_select_task_post($blog_id, $task_id)
  1676. {
  1677. // Init
  1678. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1679. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  1680. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1681. $sql = "
  1682. SELECT title, description
  1683. FROM $tbl_blogs_tasks
  1684. WHERE task_id = '".(int)$task_id."'";
  1685. $result = api_sql_query($sql, __FILE__, __LINE__);
  1686. $row = mysql_fetch_assoc($result);
  1687. // Get posts and authors
  1688. $sql = "
  1689. SELECT
  1690. post.*,
  1691. user.lastname,
  1692. user.firstname
  1693. FROM $tbl_blogs_posts post
  1694. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  1695. WHERE post.blog_id = '".(int)$blog_id."'
  1696. ORDER BY post_id DESC
  1697. LIMIT 0, 100";
  1698. $result = api_sql_query($sql, __FILE__, __LINE__);
  1699. // Display
  1700. echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
  1701. echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
  1702. if(mysql_num_rows($result) > 0)
  1703. {
  1704. while($blog_post = mysql_fetch_array($result))
  1705. {
  1706. echo '<a href="blog.php?action=execute_task&amp;blog_id=' . $blog_id . '&amp;task_id=' . $task_id . '&amp;post_id=' . $blog_post['post_id'] . '#add_comment">'.stripslashes($blog_post['title']) . '</a>, ' . get_lang('WrittenBy') . ' ' . $blog_post['firstname'] . ' '.stripslashes($blog_post['lastname']) . '<br />';
  1707. }
  1708. }
  1709. else
  1710. echo get_lang('NoArticles');
  1711. }
  1712. /**
  1713. * Subscribes a user to a given blog
  1714. * @author Toon Keppens
  1715. *
  1716. * @param Integer $blog_id
  1717. * @param Integer $user_id
  1718. */
  1719. function set_user_subscribed($blog_id,$user_id)
  1720. {
  1721. // Init
  1722. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1723. $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
  1724. // Subscribe the user
  1725. $sql = "INSERT INTO $tbl_blogs_rel_user ( `blog_id`, `user_id` ) VALUES ('".(int)$blog_id."', '".(int)$user_id."');";
  1726. $result = api_sql_query($sql, __FILE__, __LINE__);
  1727. // Give this user basic rights
  1728. $sql="INSERT INTO $tbl_user_permissions (user_id,tool,action) VALUES ('".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
  1729. $result = api_sql_query($sql, __LINE__, __FILE__);
  1730. $sql="INSERT INTO $tbl_user_permissions (user_id,tool,action) VALUES ('".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
  1731. $result = api_sql_query($sql, __LINE__, __FILE__);
  1732. }
  1733. /**
  1734. * Unsubscribe a user from a given blog
  1735. * @author Toon Keppens
  1736. *
  1737. * @param Integer $blog_id
  1738. * @param Integer $user_id
  1739. */
  1740. function set_user_unsubscribed($blog_id, $user_id)
  1741. {
  1742. // Init
  1743. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1744. $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
  1745. // Unsubscribe the user
  1746. $sql = "DELETE FROM $tbl_blogs_rel_user WHERE `blog_id` = '".(int)$blog_id."' AND `user_id` = '".(int)$user_id."'";
  1747. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1748. // Remove this user's permissions.
  1749. $sql = "DELETE FROM $tbl_user_permissions WHERE user_id = '".(int)$user_id."'";
  1750. $result = api_sql_query($sql, __LINE__, __FILE__);
  1751. }
  1752. /**
  1753. * Displays the form to register users in a blog (in a course)
  1754. * The listed users are users subcribed in the course.
  1755. * @author Toon Keppens
  1756. *
  1757. * @param Integer $blog_id
  1758. *
  1759. * @return Html Form with sortable table with users to subcribe in a blog, in a course.
  1760. */
  1761. function display_form_user_subscribe($blog_id)
  1762. {
  1763. // Init
  1764. global $_course;
  1765. $currentCourse = $_course['sysCode'];
  1766. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1767. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1768. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  1769. echo '<span class="blogpost_title">' . get_lang('SubscribeMembers') . '</span>';
  1770. $properties["width"] = "100%";
  1771. // Get blog members' id.
  1772. $sql = "SELECT user.user_id FROM $tbl_users user
  1773. INNER JOIN $tbl_blogs_rel_user blogs_rel_user
  1774. ON user.user_id = blogs_rel_user.user_id
  1775. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1776. $result = api_sql_query($sql, __FILE__, __LINE__);
  1777. $blog_member_ids = array ();
  1778. while($user = mysql_fetch_array($result))
  1779. {
  1780. $blog_member_ids[] = $user['user_id'];
  1781. }
  1782. // Set table headers
  1783. $column_header[] = array ('', false, '');
  1784. $column_header[] = array (get_lang('LastName'), true, '');
  1785. $column_header[] = array (get_lang('FirstName'), true, '');
  1786. $column_header[] = array (get_lang('Email'), true, '');
  1787. $column_header[] = array (get_lang('Register'), false, '');
  1788. // Get users in this course
  1789. $sql = "SELECT u.user_id, u.lastname, u.firstname, u.email FROM $tbl_users u
  1790. INNER JOIN $table_course_user cu
  1791. ON u.user_id = cu.user_id AND course_code='$currentCourse'";
  1792. $result = api_sql_query($sql, __FILE__, __LINE__);
  1793. include_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  1794. include_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  1795. if(isset($_SESSION['session_id'])){
  1796. $session_id = $_SESSION['session_id'];
  1797. }
  1798. else{
  1799. $session_id = 0;
  1800. }
  1801. $student_list = CourseManager :: get_student_list_from_course_code($currentCourse, true, $session_id);
  1802. $user_data = array ();
  1803. // Add users that are not in this blog to the list.
  1804. foreach($student_list as $key=>$user)
  1805. {
  1806. if(!in_array($user['user_id'],$blog_member_ids)) {
  1807. $a_infosUser = UserManager :: get_user_info_by_id($user['user_id']);
  1808. $row = array ();
  1809. $row[] = '<input type="checkbox" name="user[]" value="' . $a_infosUser['user_id'] . '" '.(($_GET['selectall'] == "subscribe") ? ' checked="checked" ' : '') . '/>';
  1810. $row[] = $a_infosUser["lastname"];
  1811. $row[] = $a_infosUser["firstname"];
  1812. $row[] = Display::encrypted_mailto_link($a_infosUser["email"]);
  1813. //Link to register users
  1814. if($a_infosUser["user_id"] != $_SESSION['_user']['user_id'])
  1815. {
  1816. $row[] = "<a href=\"" .api_get_self()."?action=manage_members&amp;blog_id=$blog_id&amp;register=yes&amp;user_id=" . $a_infosUser["user_id"]."\">" . get_lang('Register')."</a>";
  1817. }
  1818. else
  1819. {
  1820. $row[] = '';
  1821. }
  1822. $user_data[] = $row;
  1823. }
  1824. }
  1825. // Display
  1826. $query_vars['action'] = 'manage_members';
  1827. $query_vars['blog_id'] = $blog_id;
  1828. echo '<form method="post" action="blog.php?action=manage_members&amp;blog_id=' . $blog_id . '">';
  1829. Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
  1830. $link = '';
  1831. $link .= isset ($_GET['action']) ? 'action=' . $_GET['action'] . '&amp;' : '';
  1832. $link .= "blog_id=$blog_id&amp;";
  1833. $link .= isset ($_GET['page_nr']) ? 'page_nr=' . (int)$_GET['page_nr'] . '&amp;' : '';
  1834. $link .= isset ($_GET['per_page']) ? 'per_page=' . (int)$_GET['per_page'] . '&amp;' : '';
  1835. $link .= isset ($_GET['column']) ? 'column=' . (int)$_GET['column'] . '&amp;' : '';
  1836. $link .= isset ($_GET['direction']) ? 'direction=' . $_GET['direction'] . '&amp;' : '';;
  1837. echo '<a href="blog.php?' . $link . 'selectall=subscribe">' . get_lang('SelectAll') . '</a> - ';
  1838. echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
  1839. echo get_lang('WithSelected') . ' : ';
  1840. echo '<select name="action">';
  1841. echo '<option value="select_subscribe">' . get_lang('Register') . '</option>';
  1842. echo '</select>';
  1843. echo '<input type="hidden" name="register" value="true" />';
  1844. echo '<input type="submit" value="' . get_lang('Ok') . '"/>';
  1845. echo '</form>';
  1846. }
  1847. /**
  1848. * Displays the form to register users in a blog (in a course)
  1849. * The listed users are users subcribed in the course.
  1850. * @author Toon Keppens
  1851. *
  1852. * @param Integer $blog_id
  1853. *
  1854. * @return Html Form with sortable table with users to unsubcribe from a blog.
  1855. */
  1856. function display_form_user_unsubscribe($blog_id)
  1857. {
  1858. global $_user;
  1859. // Init
  1860. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1861. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1862. echo '<span class="blogpost_title">' . get_lang('UnsubscribeMembers') . '</span>';
  1863. $properties["width"] = "100%";
  1864. //table column titles
  1865. $column_header[] = array ('', false, '');
  1866. $column_header[] = array (get_lang('LastName'), true, '');
  1867. $column_header[] = array (get_lang('FirstName'), true, '');
  1868. $column_header[] = array (get_lang('Email'), true, '');
  1869. $column_header[] = array (get_lang('TaskManager'), true, '');
  1870. $column_header[] = array (get_lang('UnRegister'), false, '');
  1871. $sql_query = "SELECT user.user_id, user.lastname, user.firstname, user.email
  1872. FROM $tbl_users user
  1873. INNER JOIN $tbl_blogs_rel_user blogs_rel_user
  1874. ON user.user_id = blogs_rel_user.user_id
  1875. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1876. //$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  1877. $sql_result = mysql_query($sql_query) or die(mysql_error());
  1878. $user_data = array ();
  1879. while($myrow = mysql_fetch_array($sql_result))
  1880. {
  1881. $row = array ();
  1882. $row[] = '<input type="checkbox" name="user[]" value="' . $myrow['user_id'] . '" '.(($_GET['selectall'] == "unsubscribe") ? ' checked="checked" ' : '') . '/>';
  1883. $row[] = $myrow["lastname"];
  1884. $row[] = $myrow["firstname"];
  1885. $row[] = Display::encrypted_mailto_link($myrow["email"]);
  1886. $sql = "SELECT bt.title task
  1887. FROM " . Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER) . " `btu`
  1888. INNER JOIN " . Database::get_course_table(TABLE_BLOGS_TASKS) . " `bt` ON `btu`.`task_id` = `bt`.`task_id`
  1889. WHERE btu.blog_id = $blog_id AND btu.user_id = " . $myrow['user_id'] . "";
  1890. $sql_res = mysql_query($sql) or die(mysql_error());
  1891. $task = '';
  1892. while($r = mysql_fetch_array($sql_res))
  1893. {
  1894. $task .= stripslashes($r['task']) . ', ';
  1895. }
  1896. echo $task;
  1897. $task = (strlen(trim($task)) != 0) ? substr($task, 0, strlen($task) - 2) : 'reader';
  1898. $row[] = $task;
  1899. //Link to register users
  1900. if($myrow["user_id"] != $_user['user_id'])
  1901. {
  1902. $row[] = "<a href=\"" .api_get_self()."?action=manage_members&amp;blog_id=$blog_id&amp;unregister=yes&amp;user_id=" . $myrow[user_id]."\">" . get_lang('UnRegister')."</a>";
  1903. }
  1904. else
  1905. {
  1906. $row[] = '';
  1907. }
  1908. $user_data[] = $row;
  1909. }
  1910. $query_vars['action'] = 'manage_members';
  1911. $query_vars['blog_id'] = $blog_id;
  1912. echo '<form method="post" action="blog.php?action=manage_members&amp;blog_id=' . $blog_id . '">';
  1913. Display::display_sortable_table($column_header, $user_data,null,null,$query_vars);
  1914. $link = '';
  1915. $link .= isset ($_GET['action']) ? 'action=' . $_GET['action'] . '&amp;' : '';
  1916. $link .= "blog_id=$blog_id&amp;";
  1917. $link .= isset ($_GET['page_nr']) ? 'page_nr=' . (int)$_GET['page_nr'] . '&amp;' : '';
  1918. $link .= isset ($_GET['per_page']) ? 'per_page=' . (int)$_GET['per_page'] . '&amp;' : '';
  1919. $link .= isset ($_GET['column']) ? 'column=' . (int)$_GET['column'] . '&amp;' : '';
  1920. $link .= isset ($_GET['direction']) ? 'direction=' . $_GET['direction'] . '&amp;' : '';;
  1921. echo '<a href="blog.php?' . $link . 'selectall=unsubscribe">' . get_lang('SelectAll') . '</a> - ';
  1922. echo '<a href="blog.php?' . $link . '">' . get_lang('UnSelectAll') . '</a> ';
  1923. echo get_lang('WithSelected') . ' : ';
  1924. echo '<select name="action">';
  1925. echo '<option value="select_unsubscribe">' . get_lang('UnRegister') . '</option>';
  1926. echo '</select>';
  1927. echo '<input type="hidden" name="unregister" value="true" />';
  1928. echo '<input type="submit" value="' . get_lang('Ok') . '"/>';
  1929. echo '</form>';
  1930. }
  1931. /**
  1932. * Displays a matrix with selectboxes. On the left: users, on top: possible rights.
  1933. * The blog admin can thus select what a certain user can do in the current blog
  1934. *
  1935. * @param Integer $blog_id
  1936. */
  1937. function display_form_user_rights($blog_id)
  1938. {
  1939. // Init
  1940. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1941. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1942. echo '<span class="blogpost_title">' . get_lang('RightsManager') . '</span>';
  1943. // Integration of patricks permissions system.
  1944. include_once('../permissions/blog_permissions.inc.php');
  1945. }
  1946. /**
  1947. * Displays the form to create a new post
  1948. * @author Toon Keppens
  1949. *
  1950. * @param Integer $blog_id
  1951. */
  1952. function display_new_comment_form($blog_id, $post_id, $title)
  1953. {
  1954. echo '<form name="add_post" method="post" action="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $post_id . '">
  1955. <table width="100%" border="0" cellspacing="2" cellpadding="0" class="new_comment">
  1956. <tr>
  1957. <td colspan="2">
  1958. <span class="blogpost_title">'.(isset($_GET['task_id']) ? get_lang('ExecuteThisTask') : get_lang('NewComment')) . '</span><br />
  1959. <a name="add_comment" />
  1960. </td>
  1961. </tr>
  1962. <tr>
  1963. <td width="100" valign="top">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1964. <td><input name="comment_title" id="comment_title" type="text" size="60" value="Re: '.stripslashes($title) . '" /><br /><br /></td>
  1965. </tr>
  1966. <tr>
  1967. <td valign="top">' . get_lang('Comment') . ':&nbsp;&nbsp;</td>
  1968. <td>';
  1969. $oFCKeditor = new FCKeditor('comment_text') ;
  1970. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  1971. $oFCKeditor->Height = '200';
  1972. $oFCKeditor->Width = '97%';
  1973. $oFCKeditor->Value = isset($_POST['comment_text'])?stripslashes($_POST['comment_text']):'';
  1974. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  1975. $oFCKeditor->Config['IMUploadPath'] = "upload/blog/";
  1976. $oFCKeditor->ToolbarSet = "Blog";
  1977. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  1978. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".mysql_real_escape_string($_SESSION["_course"]["language"])."'";
  1979. $result_sql=api_sql_query($sql);
  1980. $isocode_language=mysql_result($result_sql,0,0);
  1981. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  1982. $oFCKeditor->Create() ;
  1983. echo ' <br /></td>
  1984. </tr>
  1985. <tr>
  1986. <td >&nbsp;</td>
  1987. <td>
  1988. <input type="hidden" name="action" value="" />
  1989. <input type="hidden" name="comment_parent_id" id="comment_parent_id" value="0" />';
  1990. if(isset($_GET['task_id']))
  1991. {
  1992. echo ' <input type="hidden" name="new_task_execution_submit" value="true" />';
  1993. echo ' <input type="hidden" name="task_id" value="' . (int)$_GET['task_id'] . '" />';
  1994. }
  1995. else
  1996. {
  1997. echo ' <input type="hidden" name="new_comment_submit" value="true" />';
  1998. }
  1999. echo ' <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />
  2000. </td>
  2001. </tr>
  2002. </table>
  2003. </form>';
  2004. }
  2005. /**
  2006. * show the calender of the given month
  2007. * @author Patrick Cool
  2008. * @author Toon Keppens
  2009. *
  2010. * @param Array $blogitems an array containing all the blog items for the given month
  2011. * @param Integer $month: the integer value of the month we are viewing
  2012. * @param Integer $year: the 4-digit year indication e.g. 2005
  2013. * @param String $monthName: the language variable for the mont name
  2014. *
  2015. * @return html code
  2016. */
  2017. function display_minimonthcalendar($month, $year, $blog_id)
  2018. {
  2019. // Init
  2020. global $_user;
  2021. global $DaysShort;
  2022. global $MonthsLong;
  2023. $posts = array();
  2024. $tasks = array();
  2025. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  2026. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  2027. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  2028. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  2029. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  2030. //Handle leap year
  2031. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  2032. if(($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  2033. $numberofdays[2] = 29;
  2034. //Get the first day of the month
  2035. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  2036. $monthName = $MonthsLong[$month-1];
  2037. //Start the week on monday
  2038. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  2039. $backwardsURL = api_get_self()."?blog_id=" . (int)$_GET['blog_id']."&amp;filter=" . $_GET['filter']."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  2040. $forewardsURL = api_get_self()."?blog_id=" . (int)$_GET['blog_id']."&amp;filter=" . $_GET['filter']."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  2041. // Get posts for this month
  2042. $sql = "SELECT post.*, DAYOFMONTH(`date_creation`) as post_day, user.lastname, user.firstname FROM $tbl_blogs_posts post
  2043. INNER JOIN $tbl_users user
  2044. ON post.author_id = user.user_id
  2045. WHERE post.blog_id = '".(int)$blog_id."'
  2046. AND MONTH(date_creation) = '".(int)$month."'
  2047. AND YEAR(date_creation) = '".(int)$year."'
  2048. ORDER BY date_creation";
  2049. $result = api_sql_query($sql, __FILE__, __LINE__);
  2050. // We will create an array of days on which there are posts.
  2051. if(mysql_num_rows($result) > 0)
  2052. {
  2053. while($blog_post = mysql_fetch_array($result))
  2054. {
  2055. // If the day of this post is not yet in the array, add it.
  2056. if(!in_array($blog_post['post_day'], $posts))
  2057. $posts[] = $blog_post['post_day'];
  2058. }
  2059. }
  2060. // Get tasks for this month
  2061. if($_user['user_id'])
  2062. {
  2063. $sql = "
  2064. SELECT
  2065. task_rel_user.*,
  2066. DAYOFMONTH(`target_date`) as task_day,
  2067. task.title,
  2068. blog.blog_name
  2069. FROM $tbl_blogs_tasks_rel_user task_rel_user
  2070. INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
  2071. INNER JOIN $tbl_blogs blog ON task_rel_user.blog_id = blog.blog_id
  2072. WHERE task_rel_user.user_id = '".(int)$_user['user_id']."'
  2073. AND MONTH(`target_date`) = '".(int)$month."'
  2074. AND YEAR(`target_date`) = '".(int)$year."'
  2075. ORDER BY `target_date` ASC";
  2076. $result = api_sql_query($sql, __FILE__, __LINE__);
  2077. if(mysql_numrows($result) > 0)
  2078. {
  2079. while($mytask = mysql_fetch_array($result))
  2080. {
  2081. $tasks[$mytask['task_day']][$mytask['task_id']]['task_id'] = $mytask['task_id'];
  2082. $tasks[$mytask['task_day']][$mytask['task_id']]['title'] = $mytask['title'];
  2083. $tasks[$mytask['task_day']][$mytask['task_id']]['blog_id'] = $mytask['blog_id'];
  2084. $tasks[$mytask['task_day']][$mytask['task_id']]['blog_name'] = $mytask['blog_name'];
  2085. $tasks[$mytask['task_day']][$mytask['task_id']]['day'] = $mytask['task_day'];
  2086. //echo '<li><a href="blog.php?action=execute_task&amp;blog_id=' . $mytask['blog_id'] . '&amp;task_id='.stripslashes($mytask['task_id']) . '" title="[Blog: ' . $mytask['blog_name'] . '] ' . get_lang('ExecuteThisTask') . '">'.stripslashes($mytask['title']) . '</a></li>';
  2087. }
  2088. }
  2089. }
  2090. echo "<table id=\"smallcalendar\">\n",
  2091. "<tr id=\"title\">\n",
  2092. "<td width=\"10%\"><a href=\"", $backwardsURL, "\">«</a></td>\n",
  2093. "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n",
  2094. "<td width=\"10%\"><a href=\"", $forewardsURL, "\">»</a></td>\n", "</tr>\n";
  2095. echo "<tr>\n";
  2096. for($ii = 1; $ii < 8; $ii ++)
  2097. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  2098. echo "</tr>\n";
  2099. $curday = -1;
  2100. $today = getdate();
  2101. while($curday <= $numberofdays[$month])
  2102. {
  2103. echo "<tr>\n";
  2104. for($ii = 0; $ii < 7; $ii ++)
  2105. {
  2106. if(($curday == -1) && ($ii == $startdayofweek))
  2107. $curday = 1;
  2108. if(($curday > 0) && ($curday <= $numberofdays[$month]))
  2109. {
  2110. $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
  2111. $dayheader = "$curday";
  2112. if(($curday == $today[mday]) && ($year == $today[year]) && ($month == $today[mon]))
  2113. {
  2114. $dayheader = "$curday";
  2115. $class = "class=\"days_today\"";
  2116. }
  2117. echo "\t<td " . $class.">";
  2118. // If there are posts on this day, create a filter link.
  2119. if(in_array($curday, $posts))
  2120. echo '<a href="blog.php?blog_id=' . $blog_id . '&amp;filter=' . $year . '-' . $month . '-' . $curday . '&amp;month=' . $month . '&amp;year=' . $year . '" title="' . get_lang('ViewPostsOfThisDay') . '">' . $curday . '</a>';
  2121. else
  2122. echo $dayheader;
  2123. // Add tasks to calendar
  2124. foreach ($tasks[$curday] as $task)
  2125. echo '<a href="blog.php?action=execute_task&amp;blog_id=' . $task['blog_id'] . '&amp;task_id='.stripslashes($task['task_id']) . '" title="« ' . $task['title'] . ' » ' . get_lang('InBlog') . ' « ' . $task['blog_name'] . ' » - ' . get_lang('ExecuteThisTask') . '"><img src="../img/blog_task.gif" alt="Task" /></a>';
  2126. echo "</td>\n";
  2127. $curday ++;
  2128. }
  2129. else
  2130. echo "<td>&nbsp;</td>\n";
  2131. }
  2132. echo "</tr>\n";
  2133. }
  2134. echo "</table>\n";
  2135. }
  2136. /**
  2137. * Blog admin | Display the form to add a new blog.
  2138. *
  2139. */
  2140. function display_new_blog_form()
  2141. {
  2142. echo '<form name="add_blog" method="post" action="blog_admin.php">
  2143. <table width="100%" border="0" cellspacing="2" cellpadding="0" class="newBlog">
  2144. <tr>
  2145. <td></td>
  2146. <td><b>' . get_lang('AddBlog') . '</b><br /><br /></td>
  2147. </tr>
  2148. <tr>
  2149. <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  2150. <td><input name="blog_name" type="text" size="100" /></td>
  2151. </tr>
  2152. <tr>
  2153. <td align="right">' . get_lang('Subtitle') . ':&nbsp;&nbsp;</td>
  2154. <td><input name="blog_subtitle" type="text" size="100" /></td>
  2155. </tr>
  2156. <tr>
  2157. <td align="right">&nbsp;</td>
  2158. <input type="hidden" name="action" value="" />
  2159. <input type="hidden" name="new_blog_submit" value="true" />
  2160. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  2161. </tr>
  2162. </table>
  2163. </form>';
  2164. }
  2165. /**
  2166. * Blog admin | Display the form to edit a blog.
  2167. *
  2168. */
  2169. function display_edit_blog_form($blog_id)
  2170. {
  2171. // Init
  2172. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  2173. $sql = "SELECT blog_id, blog_name, blog_subtitle FROM $tbl_blogs WHERE blog_id = '".(int)$blog_id."'";
  2174. $result = api_sql_query($sql, __FILE__, __LINE__);
  2175. $blog = mysql_fetch_array($result);
  2176. echo '<form name="edit_blog" method="post" action="blog_admin.php">
  2177. <table width="100%" border="0" cellspacing="2" cellpadding="0" class="newBlog">
  2178. <tr>
  2179. <td></td>
  2180. <td><b>' . get_lang('EditBlog') . '</b><br /><br /></td>
  2181. </tr>
  2182. <tr>
  2183. <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  2184. <td><input name="blog_name" type="text" size="100" value="' . $blog['blog_name'] . '" /></td>
  2185. </tr>
  2186. <tr>
  2187. <td align="right">' . get_lang('Subtitle') . ':&nbsp;&nbsp;</td>
  2188. <td><input name="blog_subtitle" type="text" size="100" value="' . $blog['blog_subtitle'] . '" /></td>
  2189. </tr>
  2190. <tr>
  2191. <td align="right">&nbsp;</td>
  2192. <input type="hidden" name="action" value="" />
  2193. <input type="hidden" name="edit_blog_submit" value="true" />
  2194. <input type="hidden" name="blog_id" value="' . $blog['blog_id'] . '" />
  2195. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  2196. </tr>
  2197. </table>
  2198. </form>';
  2199. }
  2200. /**
  2201. * Blog admin | Returns table with blogs in this course
  2202. */
  2203. function display_blog_list()
  2204. {
  2205. global $charset;
  2206. // Init
  2207. $counter = 0;
  2208. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  2209. $sql = "SELECT `blog_id`, `blog_name`, `blog_subtitle`, `visibility` FROM $tbl_blogs ORDER BY `blog_name`";
  2210. $result = api_sql_query($sql, __FILE__, __LINE__);
  2211. while($blog = mysql_fetch_array($result))
  2212. {
  2213. $counter++;
  2214. $css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
  2215. $visibility_icon = ($blog['visibility'] == '0') ? "invisible.gif" : "visible.gif";
  2216. $visibility_class = ($blog['visibility'] == '0') ? ' class="invisible"' : "";
  2217. $visibility_set = ($blog['visibility'] == '0') ? 1 : 0;
  2218. echo '<tr class="' . $css_class . '" valign="top">',
  2219. '<td width="290"' . $visibility_class . '>'.stripslashes($blog['blog_name']) . '</td>',
  2220. '<td' . $visibility_class . '>'.stripslashes($blog['blog_subtitle']) . '</td>',
  2221. '<td width="200">',
  2222. '<a href="' .api_get_self(). '?action=edit&amp;blog_id=' . $blog['blog_id'] . '">',
  2223. '<img src="../img/edit.gif" border="0" title="' . get_lang('EditBlog') . '" />',
  2224. "</a>\n",
  2225. '<a href="' .api_get_self(). '?action=delete&amp;blog_id=' . $blog['blog_id'] . '" ',
  2226. 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"',
  2227. '<img src="../img/delete.gif" border="0" title="' . get_lang('DeleteBlog') . '" />',
  2228. "</a>\n",
  2229. '<a href="' .api_get_self(). '?action=visibility&amp;blog_id=' . $blog['blog_id'] . '">',
  2230. '<img src="../img/' . $visibility_icon . '" border="0" title="' . get_lang('Visible') . '" />',
  2231. "</a>\n",
  2232. '</td>',
  2233. '</tr>';
  2234. }
  2235. }
  2236. }
  2237. ?>