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. AND blog.blog_id = ".intval($_GET['blog_id'])."
  509. WHERE task_rel_user.user_id = ".(int)$_user['user_id']." ORDER BY `target_date` ASC";
  510. $result = api_sql_query($sql, __FILE__, __LINE__);
  511. if(mysql_numrows($result) > 0)
  512. {
  513. echo '<ul>';
  514. while($mytask = mysql_fetch_array($result))
  515. {
  516. 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>';
  517. }
  518. echo '<ul>';
  519. }
  520. else
  521. {
  522. echo get_lang('NoTasks');
  523. }
  524. }
  525. else
  526. {
  527. echo get_lang('NoTasks');
  528. }
  529. }
  530. /**
  531. * Changes the visibility of a blog
  532. * @author Toon Keppens
  533. *
  534. * @param Integer $blog_id
  535. *
  536. * @return void
  537. */
  538. function change_blog_visibility($blog_id)
  539. {
  540. // Init
  541. $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
  542. $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
  543. // Get blog properties
  544. $sql = "SELECT blog_name, visibility FROM $tbl_blogs WHERE blog_id='".(int)$blog_id."'";
  545. $result = api_sql_query($sql, __FILE__, __LINE__);
  546. $blog = mysql_fetch_array($result);
  547. $visibility = $blog['visibility'];
  548. $title = $blog['blog_name'];
  549. if($visibility == 1)
  550. {
  551. // Change visibility state, remove from course home.
  552. $sql = "UPDATE $tbl_blogs SET `visibility` = '0' WHERE `blog_id` ='".(int)$blog_id."' LIMIT 1";
  553. $result = api_sql_query($sql, __FILE__, __LINE__);
  554. $sql = "DELETE FROM $tbl_tool WHERE name = '".mysql_real_escape_string($title)."' LIMIT 1";
  555. $result = api_sql_query($sql, __FILE__, __LINE__);
  556. }
  557. else
  558. {
  559. // Change visibility state, add to course home.
  560. $sql = "UPDATE $tbl_blogs SET `visibility` = '1' WHERE `blog_id` ='".(int)$blog_id."' LIMIT 1";
  561. $result = api_sql_query($sql, __FILE__, __LINE__);
  562. $sql = "INSERT INTO $tbl_tool (`name`, `link`, `image`, `visibility`, `admin`, `address`, `added_tool`, `target` )
  563. VALUES ('".mysql_real_escape_string($title)."', 'blog/blog.php?blog_id=".(int)$blog_id."', 'blog.gif', '1', '0', 'pastillegris.gif', '0', '_self')";
  564. $result = api_sql_query($sql, __FILE__, __LINE__);
  565. }
  566. return void;
  567. }
  568. /**
  569. * Shows the posts of a blog
  570. * @author Toon Keppens
  571. *
  572. * @param Integer $blog_id
  573. */
  574. function display_blog_posts($blog_id, $filter = '1=1', $max_number_of_posts = 20)
  575. {
  576. // Init
  577. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  578. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  579. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  580. global $dateFormatLong;
  581. // Get posts and authors
  582. $sql = "SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts post
  583. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  584. WHERE post.blog_id = '".(int)$blog_id."'
  585. AND $filter
  586. ORDER BY post_id DESC LIMIT 0,".(int)$max_number_of_posts;
  587. $result = api_sql_query($sql, __FILE__, __LINE__);
  588. // Display
  589. if(mysql_num_rows($result) > 0)
  590. {
  591. while($blog_post = mysql_fetch_array($result))
  592. {
  593. // Get number of comments
  594. $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']."'";
  595. $tmp = api_sql_query($sql, __FILE__, __LINE__);
  596. $blog_post_comments = mysql_fetch_array($tmp);
  597. // Prepare data
  598. $blog_post_id = $blog_post['post_id'];
  599. $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
  600. $blog_post_date = ucfirst(format_locale_date($dateFormatLong,strtotime($blog_post['date_creation'])));
  601. $blog_post_time = date('H:i',strtotime($blog_post['date_creation']));
  602. // Create an introduction text (but keep FULL sentences)
  603. $limit = 100; //nmbr of words in introduction text
  604. $introduction_text = "";
  605. $words = 0;
  606. $tok = strtok(make_clickable(stripslashes($blog_post['full_text'])), " ");
  607. //original
  608. //$tok = strtok(make_clickable(stripslashes(strip_tags($blog_post['full_text'],"<br><p><ol><ul><li><img>"))), " ");
  609. while($tok)
  610. {
  611. $introduction_text .= " $tok";
  612. $words++;
  613. // check if the number of words is larger than our limit AND if this token ends with a ! . or ? (meaning end of sentance).
  614. if(($words >= $limit) && ((substr($tok, -1) == "!")||(substr($tok, -1) == ".")||(substr($tok, -1) == "?")))
  615. {
  616. break;
  617. }
  618. $tok = strtok(" ");
  619. }
  620. if($words >= $limit)
  621. {
  622. $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>';
  623. }
  624. else
  625. {
  626. $readMoreLink = '';
  627. }
  628. $introduction_text=stripslashes($introduction_text);
  629. echo '<div class="blogpost">'."\n";
  630. 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";
  631. echo '<span class="blogpost_date">' . $blog_post_date . ' (' . $blog_post_time . ')</span>'."\n";
  632. echo '<span class="blogpost_introduction" id="blogpost_introduction_' . $blog_post_id . '">' . $introduction_text . $readMoreLink . '</span>'."\n";
  633. echo '<span class="blogpost_text" id="blogpost_text_' . $blog_post_id . '" style="display: none">' . $blog_post_text . '</span>'."\n";
  634. 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";
  635. echo '</div>'."\n";
  636. }
  637. } else {
  638. if($filter == '1=1')
  639. {
  640. echo get_lang('NoArticles');
  641. }
  642. else
  643. {
  644. echo get_lang('NoArticleMatches');
  645. }
  646. }
  647. }
  648. /**
  649. * Display the search results
  650. *
  651. * @param Integer $blog_id
  652. * @param String $query_string
  653. */
  654. function display_search_results($blog_id, $query_string)
  655. {
  656. // Init
  657. $query_string_parts = explode(' ',$query_string);
  658. $query_string = array();
  659. foreach ($query_string_parts as $query_part)
  660. {
  661. $query_string[] = " full_text LIKE '%" . $query_part."%' OR title LIKE '%" . $query_part."%' ";
  662. }
  663. $query_string = '('.implode('OR',$query_string) . ')';
  664. // Display the posts
  665. echo '<span class="blogpost_title">' . get_lang('SearchResults') . '</span>';
  666. Blog::display_blog_posts($blog_id, $query_string);
  667. }
  668. /**
  669. * Display posts from a certain date
  670. *
  671. * @param Integer $blog_id
  672. * @param String $query_string
  673. */
  674. function display_day_results($blog_id, $query_string)
  675. {
  676. // Init
  677. $date_output = $query_string;
  678. $date = explode('-',$query_string);
  679. $query_string = ' DAYOFMONTH(`date_creation`) =' . $date[2] . ' AND MONTH(`date_creation`) =' . $date[1] . ' AND YEAR(`date_creation`) =' . $date[0];
  680. global $dateFormatLong;
  681. // Put date in correct output format
  682. $date_output = ucfirst(format_locale_date($dateFormatLong,strtotime($date_output)));
  683. // Display the posts
  684. echo '<span class="blogpost_title">' . get_lang('PostsOf') . ': ' . $date_output . '</span>';
  685. Blog::display_blog_posts($blog_id, $query_string);
  686. }
  687. /**
  688. * Displays a post and his comments
  689. *
  690. * @param Integer $blog_id
  691. * @param Integer $post_id
  692. */
  693. function display_post($blog_id, $post_id)
  694. {
  695. // Init
  696. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  697. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  698. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  699. global $charset,$dateFormatLong;
  700. // Get posts and author
  701. $sql = "SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts post
  702. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  703. WHERE post.blog_id = '".(int)$blog_id."'
  704. AND post.post_id = '".(int)$post_id."'
  705. ORDER BY post_id DESC";
  706. $result = api_sql_query($sql, __FILE__, __LINE__);
  707. $blog_post = mysql_fetch_array($result);
  708. // Get number of comments
  709. $sql = "SELECT COUNT(1) as number_of_comments FROM $tbl_blogs_comments WHERE blog_id = '".(int)$blog_id."' AND post_id = '".(int)$post_id."'";
  710. $result = api_sql_query($sql, __FILE__, __LINE__);
  711. $blog_post_comments = mysql_fetch_array($result);
  712. // Prepare data
  713. $blog_post_text = make_clickable(stripslashes($blog_post['full_text']));
  714. $blog_post_date = ucfirst(format_locale_date($dateFormatLong,strtotime($blog_post['date_creation'])));
  715. $blog_post_time = date('H:m',strtotime($blog_post['date_creation']));
  716. $blog_post_actions = "";
  717. $task_id = (isset($_GET['task_id']) && is_numeric($_GET['task_id'])) ? $_GET['task_id'] : 0;
  718. if(api_is_allowed('BLOG_' . $blog_id, 'article_edit', $task_id))
  719. $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>';
  720. if(api_is_allowed('BLOG_' . $blog_id, 'article_delete', $task_id))
  721. $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>';
  722. if(api_is_allowed('BLOG_' . $blog_id, 'article_rate'))
  723. $rating_select = Blog::display_rating_form('post',$blog_id,$post_id);
  724. $blog_post_text=stripslashes($blog_post_text);
  725. // Display post
  726. echo '<div class="blogpost">';
  727. 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>';
  728. echo '<span class="blogpost_date">' . $blog_post_date . ' (' . $blog_post_time . ')</span>';
  729. echo '<span class="blogpost_text">' . $blog_post_text . '</span>';
  730. 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>';
  731. echo '<span class="blogpost_actions">' . $blog_post_actions . '</span>';
  732. echo '</div>';
  733. // Display comments if there are any
  734. if($blog_post_comments['number_of_comments'] > 0)
  735. {
  736. echo '<div class="comments">';
  737. echo '<span class="blogpost_title">' . get_lang('Comments') . '</span><br />';
  738. Blog::get_threaded_comments(0, 0, $blog_id, $post_id, $task_id);
  739. echo '</div>';
  740. }
  741. // Display comment form
  742. if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_add'))
  743. {
  744. Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);
  745. }
  746. }
  747. /**
  748. * Adds rating to a certain post or comment
  749. * @author Toon Keppens
  750. *
  751. * @param String $type
  752. * @param Integer $blog_id
  753. * @param Integer $item_id
  754. * @param Integer $rating
  755. *
  756. * @return Boolean success
  757. */
  758. function add_rating($type, $blog_id, $item_id, $rating)
  759. {
  760. global $_user;
  761. // Init
  762. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  763. // Check if the user has already rated this post/comment
  764. $sql = "SELECT rating_id FROM $tbl_blogs_rating
  765. WHERE blog_id = '".(int)$blog_id."'
  766. AND item_id = '".(int)$item_id."'
  767. AND rating_type = '".mysql_real_escape_string($type)."'
  768. AND user_id = '".(int)$_user['user_id']."'";
  769. $result = api_sql_query($sql, __FILE__, __LINE__);
  770. if(mysql_num_rows($result) == 0) // Add rating
  771. {
  772. $sql = "INSERT INTO $tbl_blogs_rating ( `blog_id`, `rating_type`, `item_id`, `user_id`, `rating` )
  773. VALUES ('".(int)$blog_id."', '".mysql_real_escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".mysql_real_escape_string($rating)."')";
  774. $result = api_sql_query($sql, __FILE__, __LINE__);
  775. return true;
  776. }
  777. else // Return
  778. {
  779. return false;
  780. }
  781. }
  782. function display_rating($type, $blog_id, $item_id)
  783. {
  784. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  785. // Calculate rating
  786. $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)."' ";
  787. $result = api_sql_query($sql, __FILE__, __LINE__);
  788. $result = mysql_fetch_array($result);
  789. return round($result['rating'], 2);
  790. }
  791. /**
  792. * Shows the rating form if not already rated by that user
  793. * @author Toon Keppens
  794. *
  795. * @param String $type
  796. * @param Integer $blog_id
  797. * @param Integer $item_id
  798. *
  799. */
  800. function display_rating_form($type, $blog_id, $post_id, $comment_id = NULL)
  801. {
  802. global $_user;
  803. // Init
  804. $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);
  805. if($type == 'post')
  806. {
  807. // Check if the user has already rated this post
  808. $sql = "SELECT rating_id FROM $tbl_blogs_rating
  809. WHERE blog_id = '".(int)$blog_id."'
  810. AND item_id = '".(int)$post_id."'
  811. AND rating_type = '".mysql_real_escape_string($type)."'
  812. AND user_id = '".(int)$_user['user_id']."'";
  813. $result = api_sql_query($sql, __FILE__, __LINE__);
  814. if(mysql_num_rows($result) == 0) // Add rating
  815. {
  816. 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>';
  817. }
  818. else // Return
  819. {
  820. return '';
  821. }
  822. }
  823. if($type = 'comment')
  824. {
  825. // Check if the user has already rated this comment
  826. $sql = "SELECT rating_id FROM $tbl_blogs_rating
  827. WHERE blog_id = '".(int)$blog_id ."'
  828. AND item_id = '".(int)$comment_id."'
  829. AND rating_type = '".mysql_real_escape_string($type)."'
  830. AND user_id = '".(int)$_user['user_id']."'";
  831. $result = api_sql_query($sql, __FILE__, __LINE__);
  832. if(mysql_num_rows($result) == 0) // Add rating
  833. {
  834. 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>';
  835. }
  836. else // Return
  837. {
  838. return '';
  839. }
  840. }
  841. }
  842. /**
  843. * This functions gets all replys to a post, threaded.
  844. *
  845. * @param Integer $current
  846. * @param Integer $current_level
  847. * @param Integer $blog_id
  848. * @param Integer $post_id
  849. */
  850. function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)
  851. {
  852. // Init
  853. $tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);
  854. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  855. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  856. global $charset,$dateFormatLong;
  857. // Select top level comments
  858. $next_level = $current_level + 1;
  859. $sql = "SELECT comments.*, user.lastname, user.firstname, task.color
  860. FROM $tbl_blogs_comments comments
  861. INNER JOIN $tbl_users user ON comments.author_id = user.user_id
  862. LEFT JOIN $tbl_blogs_tasks task ON comments.task_id = task.task_id
  863. WHERE parent_comment_id = $current
  864. AND comments.blog_id = '".(int)$blog_id."'
  865. AND comments.post_id = '".(int)$post_id."'";
  866. $result = api_sql_query($sql, __FILE__, __LINE__);
  867. while($comment = mysql_fetch_array($result))
  868. {
  869. // Select the children recursivly
  870. $tmp = "SELECT comments.*, user.lastname, user.firstname FROM $tbl_blogs_comments comments
  871. INNER JOIN $tbl_users user ON comments.author_id = user.user_id
  872. WHERE comment_id = $current
  873. AND blog_id = '".(int)$blog_id."'
  874. AND post_id = '".(int)$post_id."'";
  875. $tmp = api_sql_query($tmp, __FILE__, __LINE__);
  876. $tmp = mysql_fetch_array($tmp);
  877. $parent_cat = $tmp['parent_comment_id'];
  878. $border_color = '';
  879. // Prepare data
  880. $comment_text = make_clickable(stripslashes($comment['comment']));
  881. $blog_comment_date = ucfirst(format_locale_date($dateFormatLong,strtotime($comment['date_creation'])));
  882. $blog_comment_time = date('H:i',strtotime($comment['date_creation']));
  883. $blog_comment_actions = "";
  884. 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>'; }
  885. if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_rate')) { $rating_select = Blog::display_rating_form('comment', $blog_id, $post_id, $comment['comment_id']); }
  886. if(!is_null($comment['task_id']))
  887. {
  888. $border_color = ' border-left: 3px solid #' . $comment['color'];
  889. }
  890. $comment_text=stripslashes($comment_text);
  891. // Output...
  892. $margin = $current_level * 30;
  893. echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';
  894. 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>';
  895. echo '<span class="blogpost_comment_date">' . $blog_comment_date . ' (' . $blog_comment_time . ')</span>';
  896. echo '<span class="blogpost_text">' . $comment_text . '</span>';
  897. 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>';
  898. echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';
  899. echo '</div>';
  900. // Go further down the tree.
  901. Blog::get_threaded_comments( $comment['comment_id'], $next_level, $blog_id, $post_id);
  902. }
  903. }
  904. /**
  905. * Displays the form to create a new post
  906. * @author Toon Keppens
  907. *
  908. * @param Integer $blog_id
  909. */
  910. function display_form_new_post($blog_id)
  911. {
  912. if(api_is_allowed('BLOG_' . $blog_id, 'article_add'))
  913. {
  914. echo '<script type="text/javascript">
  915. function FCKeditor_OnComplete( editorInstance )
  916. {
  917. editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;
  918. }
  919. function check_for_title()
  920. {
  921. // This functions shows that you can interact directly with the editor area
  922. // DOM. In this way you have the freedom to do anything you want with it.
  923. // Get the editor instance that we want to interact with.
  924. var oEditor = FCKeditorAPI.GetInstance(\'post_full_text\') ;
  925. // Get the Editor Area DOM (Document object).
  926. var oDOM = oEditor.EditorDocument ;
  927. var iLength ;
  928. var contentText ;
  929. var contentTextArray;
  930. var bestandsnaamNieuw = "";
  931. var bestandsnaamOud = "";
  932. // The are two diffent ways to get the text (without HTML markups).
  933. // It is browser specific.
  934. if( document.all ) // If Internet Explorer.
  935. {
  936. contentText = oDOM.body.innerText ;
  937. }
  938. else // If Gecko.
  939. {
  940. var r = oDOM.createRange() ;
  941. r.selectNodeContents( oDOM.body ) ;
  942. contentText = r.toString() ;
  943. }
  944. // Compose title if there is none
  945. contentTextArray = contentText.split(\' \') ;
  946. var x=0;
  947. for(x=0; (x<5 && x<contentTextArray.length); x++)
  948. {
  949. if(x < 4)
  950. {
  951. bestandsnaamNieuw += contentTextArray[x] + \' \';
  952. }
  953. else
  954. {
  955. bestandsnaamNieuw += contentTextArray[x] + \'...\';
  956. }
  957. }
  958. if(document.getElementById(\'post_title_edited\').value == "false")
  959. {
  960. document.getElementById(\'post_title\').value = bestandsnaamNieuw;
  961. }
  962. }
  963. function trim(s) {
  964. while(s.substring(0,1) == \' \') {
  965. s = s.substring(1,s.length);
  966. }
  967. while(s.substring(s.length-1,s.length) == \' \') {
  968. s = s.substring(0,s.length-1);
  969. }
  970. return s;
  971. }
  972. function check_if_still_empty()
  973. {
  974. if(trim(document.getElementById(\'post_title\').value) != "")
  975. {
  976. document.getElementById(\'post_title_edited\').value = "true";
  977. }
  978. }
  979. </script>';
  980. echo '<form name="add_post" method="post" action="blog.php?blog_id=' . $blog_id . '">
  981. <span class="blogpost_title">' . get_lang('NewPost') . '</span>
  982. <table width="100%" border="0" cellspacing="2" cellpadding="0">
  983. <tr>
  984. <td width="80" valign="top">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  985. <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>
  986. </tr>
  987. <tr>
  988. <td valign="top">' . get_lang('PostFullText') . ':&nbsp;&nbsp;</td>
  989. <td>';
  990. $oFCKeditor = new FCKeditor('post_full_text') ;
  991. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  992. $oFCKeditor->Height = '350';
  993. $oFCKeditor->Width = '98%';
  994. $oFCKeditor->Value = isset($_POST['post_full_text'])?stripslashes($_POST['post_full_text']):'';
  995. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  996. $oFCKeditor->Config['IMUploadPath'] = "upload/blog/";
  997. $oFCKeditor->ToolbarSet = "Blog";
  998. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  999. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".mysql_real_escape_string($_SESSION["_course"]["language"])."'";
  1000. $result_sql=api_sql_query($sql);
  1001. $isocode_language=mysql_result($result_sql,0,0);
  1002. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  1003. $oFCKeditor->Create() ;
  1004. echo ' <br /></td>
  1005. </tr>
  1006. <tr>
  1007. <td >&nbsp;</td>
  1008. <td>
  1009. <input type="hidden" name="action" value="" />
  1010. <input type="hidden" name="new_post_submit" value="true" />
  1011. <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />
  1012. </td>
  1013. </tr>
  1014. </table>
  1015. </form>';
  1016. }
  1017. else
  1018. {
  1019. api_not_allowed();
  1020. }
  1021. }
  1022. /**
  1023. * Displays the form to edit a post
  1024. * @author Toon Keppens
  1025. *
  1026. * @param Integer $blog_id
  1027. */
  1028. function display_form_edit_post($blog_id, $post_id)
  1029. {
  1030. // Init
  1031. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  1032. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1033. // Get posts and author
  1034. $sql = "SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts post
  1035. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  1036. WHERE post.blog_id = '".(int)$blog_id ."'
  1037. AND post.post_id = '".(int)$post_id."'
  1038. ORDER BY post_id DESC";
  1039. $result = api_sql_query($sql, __FILE__, __LINE__);
  1040. $blog_post = mysql_fetch_array($result);
  1041. // Prepare data
  1042. $blog_post_text = stripslashes($blog_post['full_text']);
  1043. echo '<form name="edit_post" method="post" action="blog.php?blog_id=' . $blog_id . '">
  1044. <span class="blogpost_title">' . get_lang('EditPost') . '</span>
  1045. <table width="100%" border="0" cellspacing="2" cellpadding="0">
  1046. <tr>
  1047. <td width="80" valign="top">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1048. <td><input name="post_title" id="post_title" type="text" size="60" value="'.stripslashes($blog_post['title']) . '" /><br /><br /></td>
  1049. </tr>
  1050. <tr>
  1051. <td valign="top">' . get_lang('PostFullText') . ':&nbsp;&nbsp;</td>
  1052. <td>';
  1053. $oFCKeditor = new FCKeditor('post_full_text') ;
  1054. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  1055. $oFCKeditor->Height = '350';
  1056. $oFCKeditor->Width = '98%';
  1057. $oFCKeditor->Value = isset($_POST['post_full_text'])?stripslashes($_POST['post_full_text']):$blog_post_text;
  1058. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  1059. $oFCKeditor->Config['IMUploadPath'] = "upload/blog/";
  1060. $oFCKeditor->ToolbarSet = "Blog";
  1061. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  1062. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".mysql_real_escape_string($_SESSION["_course"]["language"])."'";
  1063. $result_sql=api_sql_query($sql);
  1064. $isocode_language=mysql_result($result_sql,0,0);
  1065. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  1066. $oFCKeditor->Create() ;
  1067. echo ' <br /></td>
  1068. </tr>
  1069. <tr>
  1070. <td >&nbsp;</td>
  1071. <td>
  1072. <input type="hidden" name="action" value="" />
  1073. <input type="hidden" name="edit_post_submit" value="true" />
  1074. <input type="hidden" name="post_id" value="' . (int)$_GET['post_id'] . '" />
  1075. <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />
  1076. </td>
  1077. </tr>
  1078. </table>
  1079. </form>';
  1080. }
  1081. /**
  1082. * Displays a list of tasks in this blog
  1083. * @author Toon Keppens
  1084. *
  1085. * @param Integer $blog_id
  1086. */
  1087. function display_task_list($blog_id)
  1088. {
  1089. global $charset;
  1090. if(api_is_allowed('BLOG_' . $blog_id, 'article_add'))
  1091. {
  1092. // Init
  1093. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1094. $counter = 0;
  1095. global $color2;
  1096. 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> ';
  1097. 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>';
  1098. echo '<span class="blogpost_title">' . get_lang('TaskList') . '</span><br />';
  1099. echo "<table class=\"data_table\">";
  1100. echo "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
  1101. "<th width='240'><b>",get_lang('Title'),"</b></th>\n",
  1102. "<th><b>",get_lang('Description'),"</b></th>\n",
  1103. "<th><b>",get_lang('Color'),"</b></th>\n",
  1104. "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
  1105. "</tr>\n";
  1106. $sql = "
  1107. SELECT
  1108. `blog_id`,
  1109. `task_id`,
  1110. `blog_id`,
  1111. `title`,
  1112. `description`,
  1113. `color`,
  1114. `system_task`
  1115. FROM " . $tbl_blogs_tasks . "
  1116. WHERE `blog_id` = " . (int)$blog_id . "
  1117. ORDER BY
  1118. `system_task`,
  1119. `title`";
  1120. $result = api_sql_query($sql, __FILE__, __LINE__);
  1121. while($task = mysql_fetch_array($result))
  1122. {
  1123. $counter++;
  1124. $css_class = (($counter % 2) == 0) ? "row_odd" : "row_even";
  1125. $delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
  1126. $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
  1127. $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'];
  1128. $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
  1129. echo '<tr class="' . $css_class . '" valign="top">',
  1130. '<td width="240">' . stripslashes($task['title']) . '</td>',
  1131. '<td>' . stripslashes($task['description']) . '</td>',
  1132. '<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>',
  1133. '<td width="50">',
  1134. '<a href="' .api_get_self(). '?action=manage_tasks&amp;blog_id=' . $task['blog_id'] . '&amp;do=edit&amp;task_id=' . $task['task_id'] . '">',
  1135. '<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
  1136. "</a>\n",
  1137. '<a href="' . $delete_link . '"',
  1138. $delete_confirm,
  1139. '><img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
  1140. "</a>\n",
  1141. '</td>',
  1142. '</tr>';
  1143. }
  1144. echo "</table>";
  1145. }
  1146. }
  1147. /**
  1148. * Displays a list of tasks assigned to a user in this blog
  1149. * @author Toon Keppens
  1150. *
  1151. * @param Integer $blog_id
  1152. */
  1153. function display_assigned_task_list($blog_id)
  1154. {
  1155. // Init
  1156. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1157. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1158. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1159. $counter = 0;
  1160. global $charset,$color2;
  1161. echo '<span class="blogpost_title">' . get_lang('AssignedTasks') . '</span><br />';
  1162. echo "<table class=\"data_table\">";
  1163. echo "<tr bgcolor=\"$color2\" align=\"center\" valign=\"top\">",
  1164. "<th width='240'><b>",get_lang('Member'),"</b></th>\n",
  1165. "<th><b>",get_lang('Task'),"</b></th>\n",
  1166. "<th><b>",get_lang('Description'),"</b></th>\n",
  1167. "<th><b>",get_lang('TargetDate'),"</b></th>\n",
  1168. "<th width='50'><b>",get_lang('Modify'),"</b></th>\n",
  1169. "</tr>\n";
  1170. $sql = "SELECT task_rel_user.*, task.title, user.firstname, user.lastname, task.description FROM $tbl_blogs_tasks_rel_user task_rel_user
  1171. INNER JOIN $tbl_blogs_tasks task ON task_rel_user.task_id = task.task_id
  1172. INNER JOIN $tbl_users user ON task_rel_user.user_id = user.user_id
  1173. WHERE task_rel_user.blog_id = '".(int)$blog_id."' ORDER BY `target_date` ASC";
  1174. $result = api_sql_query($sql, __FILE__, __LINE__);
  1175. while($assignment = mysql_fetch_array($result))
  1176. {
  1177. $counter++;
  1178. $css_class = (($counter % 2)==0) ? "row_odd" : "row_even";
  1179. $delete_icon = ($task['system_task'] == '1') ? "delete_na.gif" : "delete.gif";
  1180. $delete_title = ($task['system_task'] == '1') ? get_lang('DeleteSystemTask') : get_lang('DeleteTask');
  1181. $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'];
  1182. $delete_confirm = ($task['system_task'] == '1') ? '' : 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"';
  1183. echo '<tr class="' . $css_class . '" valign="top">',
  1184. '<td width="240">' . $assignment['firstname'] . ' ' . $assignment['lastname'] . '</td>',
  1185. '<td>'.stripslashes($assignment['title']) . '</td>',
  1186. '<td>'.stripslashes($assignment['description']) . '</td>',
  1187. '<td>' . $assignment['target_date'] . '</td>',
  1188. '<td width="50">',
  1189. '<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'] . '">',
  1190. '<img src="../img/edit.gif" border="0" title="' . get_lang('EditTask') . '" />',
  1191. "</a>\n",
  1192. '<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'] . '" ',
  1193. 'onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"',
  1194. '<img src="../img/' . $delete_icon . '" border="0" title="' . $delete_title . '" />',
  1195. "</a>\n",
  1196. '</td>',
  1197. '</tr>';
  1198. }
  1199. echo "</table>";
  1200. }
  1201. /**
  1202. * Displays new task form
  1203. * @author Toon Keppens
  1204. *
  1205. */
  1206. function display_new_task_form($blog_id)
  1207. {
  1208. // Init
  1209. $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
  1210. // Display
  1211. echo '<form name="add_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1212. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1213. <tr>
  1214. <td width="200"></td>
  1215. <td><b>' . get_lang('AddTask') . '</b><br /><br /></td>
  1216. </tr>
  1217. <tr>
  1218. <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1219. <td><input name="task_name" type="text" size="70" /></td>
  1220. </tr>
  1221. <tr>
  1222. <td align="right">' . get_lang('Description') . ':&nbsp;&nbsp;</td>
  1223. <td><input name="task_description" type="text" size="70" /></td>
  1224. </tr>';
  1225. /* edit by Kevin Van Den Haute (kevin@develop-it.be) */
  1226. echo "\t" . '<tr>' . "\n";
  1227. echo "\t\t" . '<td style="text-align:right; vertical-align:top;">Task management:&nbsp;&nbsp;</td>' . "\n";
  1228. echo "\t\t" . '<td>' . "\n";
  1229. echo "\t\t\t" . '<table cellspacing="0" style="border:1px solid #808080; border-collapse:collapse; width:446px;">';
  1230. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1231. echo "\t\t\t\t\t" . '<th colspan="2" style="border:1px solid #808080; width:223px;">' . get_lang('ArticleManager') . '</th>' . "\n";
  1232. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080;" width:223px;>' . get_lang('CommentManager') . '</th>' . "\n";
  1233. echo "\t\t\t\t" . '</tr>' . "\n";
  1234. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1235. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1236. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>' . "\n";
  1237. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1238. echo "\t\t\t\t" . '</tr>' . "\n";
  1239. echo "\t\t\t\t" . '<tr>' . "\n";
  1240. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input id="articleDelete" name="chkArticleDelete" type="checkbox" /></td>' . "\n";
  1241. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input id="articleEdit" name="chkArticleEdit" type="checkbox" /></td>' . "\n";
  1242. echo "\t\t\t\t\t" . '<td style="border:1px dotted #808080; text-align:center;"><input id="commentsDelete" name="chkCommentsDelete" type="checkbox" /></td>' . "\n";
  1243. echo "\t\t\t\t" . '</tr>' . "\n";
  1244. echo "\t\t\t" . '</table>' . "\n";
  1245. echo "\t\t" . '</td>' . "\n";
  1246. echo "\t" . '</tr>' . "\n";
  1247. /* end of edit */
  1248. echo ' <tr>
  1249. <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
  1250. <td>
  1251. <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">';
  1252. foreach ($colors as $color)
  1253. {
  1254. $style = 'style="background-color: #' . $color . '"';
  1255. echo '<option value="' . $color . '" ' . $style . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
  1256. }
  1257. echo ' </select>
  1258. </td>
  1259. </tr>
  1260. <tr>
  1261. <td align="right">&nbsp;</td>
  1262. <input type="hidden" name="action" value="" />
  1263. <input type="hidden" name="new_task_submit" value="true" />
  1264. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1265. </tr>
  1266. </table>
  1267. </form>';
  1268. }
  1269. /**
  1270. * Displays edit task form
  1271. * @author Toon Keppens
  1272. *
  1273. */
  1274. function display_edit_task_form($blog_id, $task_id)
  1275. {
  1276. // Init
  1277. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1278. $colors = array('FFFFFF','FFFF99','FFCC99','FF9933','FF6699','CCFF99','CC9966','66FF00', '9966FF', 'CF3F3F', '990033','669933','0033FF','003366','000000');
  1279. $sql = "SELECT blog_id, task_id, title, description, color FROM $tbl_blogs_tasks WHERE task_id = '".(int)$task_id."'";
  1280. $result = api_sql_query($sql, __FILE__, __LINE__);
  1281. $task = mysql_fetch_array($result);
  1282. // Display
  1283. echo '<form name="edit_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1284. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1285. <tr>
  1286. <td width="200"></td>
  1287. <td><b>' . get_lang('EditTask') . '</b><br /><br /></td>
  1288. </tr>
  1289. <tr>
  1290. <td align="right">' . get_lang('Title') . ':&nbsp;&nbsp;</td>
  1291. <td><input name="task_name" type="text" size="70" value="'.stripslashes($task['title']) . '" /></td>
  1292. </tr>
  1293. <tr>
  1294. <td align="right">' . get_lang('Description') . ':&nbsp;&nbsp;</td>
  1295. <td><input name="task_description" type="text" size="70" value="'.stripslashes($task['description']) . '" /></td>
  1296. </tr>';
  1297. /* edit by Kevin Van Den Haute (kevin@develop-it.be) */
  1298. $tbl_tasks_permissions = Database::get_course_table(TABLE_BLOGS_TASKS_PERMISSIONS);
  1299. $sql = "
  1300. SELECT
  1301. `id`,
  1302. `action`
  1303. FROM " . $tbl_tasks_permissions . "
  1304. WHERE `task_id` = '" . (int)$task_id."'";
  1305. $result = api_sql_query($sql, __FILE__, __LINE__);
  1306. $arrPermissions = array();
  1307. while($row = @mysql_fetch_array($result))
  1308. $arrPermissions[] = $row['action'];
  1309. echo "\t" . '<tr>' . "\n";
  1310. echo "\t\t" . '<td style="text-align:right; vertical-align:top;">Task management:&nbsp;&nbsp;</td>' . "\n";
  1311. echo "\t\t" . '<td>' . "\n";
  1312. echo "\t\t\t" . '<table cellspacing="0" style="border:1px solid #808080; border-collapse:collapse; width:446px;">';
  1313. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1314. echo "\t\t\t\t\t" . '<th colspan="2" style="border:1px solid #808080; width:223px;">' . get_lang('ArticleManager') . '</th>' . "\n";
  1315. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080;" width:223px;>' . get_lang('CommentManager') . '</th>' . "\n";
  1316. echo "\t\t\t\t" . '</tr>' . "\n";
  1317. echo "\t\t\t\t" . '<tr style="background:#E5EDF9;">' . "\n";
  1318. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:111px;"><label for="articleDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1319. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:112px;"><label for="articleEdit">' . get_lang('Edit') . '</label></th>' . "\n";
  1320. echo "\t\t\t\t\t" . '<th style="border:1px solid #808080; width:223px;"><label for="commentsDelete">' . get_lang('Delete') . '</label></th>' . "\n";
  1321. echo "\t\t\t\t" . '</tr>' . "\n";
  1322. echo "\t\t\t\t" . '<tr>' . "\n";
  1323. 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";
  1324. 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";
  1325. 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";
  1326. echo "\t\t\t\t" . '</tr>' . "\n";
  1327. echo "\t\t\t" . '</table>' . "\n";
  1328. echo "\t\t" . '</td>' . "\n";
  1329. echo "\t" . '</tr>' . "\n";
  1330. /* end of edit */
  1331. echo '<tr>
  1332. <td align="right">' . get_lang('Color') . ':&nbsp;&nbsp;</td>
  1333. <td>
  1334. <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">';
  1335. foreach ($colors as $color)
  1336. {
  1337. $selected = ($color == $task['color']) ? ' selected' : '';
  1338. $style = 'style="background-color: #' . $color . '"';
  1339. echo '<option value="' . $color . '" ' . $style . ' ' . $selected . ' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
  1340. }
  1341. echo ' </select>
  1342. </td>
  1343. </tr>
  1344. <tr>
  1345. <td align="right">&nbsp;</td>
  1346. <td><br /><input type="hidden" name="action" value="" />
  1347. <input type="hidden" name="edit_task_submit" value="true" />
  1348. <input type="hidden" name="task_id" value="' . $task['task_id'] . '" />
  1349. <input type="hidden" name="blog_id" value="' . $task['blog_id'] . '" />
  1350. <input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1351. </tr>
  1352. </table>
  1353. </form>';
  1354. }
  1355. /**
  1356. * Displays assign task form
  1357. * @author Toon Keppens
  1358. *
  1359. */
  1360. function display_assign_task_form($blog_id)
  1361. {
  1362. // Init
  1363. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1364. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1365. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1366. $day = date("d");
  1367. $month = date("m");
  1368. $year = date("Y");
  1369. global $MonthsLong;
  1370. // Get users in this blog / make select list of it
  1371. $sql = "SELECT user.user_id, user.firstname, user.lastname FROM $tbl_users user
  1372. INNER JOIN $tbl_blogs_rel_user blogs_rel_user
  1373. ON user.user_id = blogs_rel_user.user_id
  1374. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1375. $result = api_sql_query($sql, __FILE__, __LINE__);
  1376. $select_user_list = '<select name="task_user_id">';
  1377. while($user = mysql_fetch_array($result))
  1378. {
  1379. $select_user_list .= '<option value="' . $user['user_id'] . '">' . $user['firstname']." " . $user['lastname'] . '</option>';
  1380. }
  1381. $select_user_list .= '</select>';
  1382. // Get tasks in this blog / make select list of it
  1383. $sql = "
  1384. SELECT
  1385. `blog_id`,
  1386. `task_id`,
  1387. `blog_id`,
  1388. `title`,
  1389. `description`,
  1390. `color`,
  1391. `system_task`
  1392. FROM " . $tbl_blogs_tasks . "
  1393. WHERE `blog_id` = " . (int)$blog_id . "
  1394. ORDER BY
  1395. `system_task`,
  1396. `title`";
  1397. $result = api_sql_query($sql, __FILE__, __LINE__);
  1398. $select_task_list = '<select name="task_task_id">';
  1399. while($task = mysql_fetch_array($result))
  1400. {
  1401. $select_task_list .= '<option value="' . $task['task_id'] . '">'.stripslashes($task['title']) . '</option>';
  1402. }
  1403. $select_task_list .= '</select>';
  1404. // Display
  1405. echo '<form name="assign_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1406. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1407. <tr>
  1408. <td width="200"></td>
  1409. <td><b>' . get_lang('AssignTask') . '</b><br /><br /></td>
  1410. </tr>
  1411. <tr>
  1412. <td align="right">' . get_lang('SelectUser') . ':&nbsp;&nbsp;</td>
  1413. <td>' . $select_user_list . '</td>
  1414. </tr>
  1415. <tr>
  1416. <td align="right">' . get_lang('SelectTask') . ':&nbsp;&nbsp;</td>
  1417. <td>' . $select_task_list . '</td>
  1418. </tr>
  1419. <tr>
  1420. <td align="right">' . get_lang('SelectTargetDate') . ':&nbsp;&nbsp;</td>
  1421. <td>
  1422. <select name="task_day">';
  1423. for($i=1; $i<=31; $i++)
  1424. {
  1425. // values need to have double digits
  1426. $value = ($i <= 9 ? "0" . $i : $i);
  1427. // the current day is indicated with [] around the date
  1428. if($value==$day)
  1429. { echo "\t\t\t\t <option value=\"" . $value."\" selected> " . $i." </option>\n";}
  1430. else
  1431. { echo "\t\t\t\t <option value=\"" . $value."\">" . $i."</option>\n"; }
  1432. }
  1433. echo '</select>
  1434. <select name="task_month">';
  1435. for($i=1; $i<=12; $i++)
  1436. {
  1437. // values need to have double digits
  1438. $value = ($i <= 9 ? "0" . $i : $i);
  1439. if($value==$month)
  1440. { echo "\t\t\t\t <option value=\"" . $value."\" selected>" . $MonthsLong[$i-1]."</option>\n"; }
  1441. else
  1442. { echo "\t\t\t\t <option value=\"" . $value."\">" . $MonthsLong[$i-1]."</option>\n"; }
  1443. }
  1444. echo '</select>
  1445. <select name="task_year">
  1446. <option value="'.($year-1) . '">'.($year-1) . '</option>
  1447. <option value="' . $year . '" selected> ' . $year . ' </option>';
  1448. for($i=1; $i<=5; $i++)
  1449. {
  1450. $value=$year+$i;
  1451. echo "\t\t\t\t<option value=\"" . $value."\">" . $value."</option>\n";
  1452. }
  1453. echo '</select>
  1454. <a title="Kalender" href="javascript:openCalendar(\'assign_task\', \'task_\')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a>
  1455. </td>
  1456. </tr>
  1457. <tr>
  1458. <td align="right">&nbsp;</td>
  1459. <input type="hidden" name="action" value="" />
  1460. <input type="hidden" name="assign_task_submit" value="true" />
  1461. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1462. </tr>
  1463. </table>
  1464. </form>';
  1465. }
  1466. /**
  1467. * Displays assign task form
  1468. * @author Toon Keppens
  1469. *
  1470. */
  1471. function display_edit_assigned_task_form($blog_id, $assignment_id)
  1472. {
  1473. $parameters = explode('|', $assignment_id);
  1474. $task_id = $parameters[0];
  1475. $user_id = $parameters[1];
  1476. /* ------------- */
  1477. // Init
  1478. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1479. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1480. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1481. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1482. $year = date("Y");
  1483. global $MonthsLong;
  1484. /*// Get assignd tasks of user
  1485. $sql = "
  1486. SELECT task_id
  1487. FROM $tbl_blogs_tasks_rel_user
  1488. WHERE
  1489. user_id = $user_id AND
  1490. blog_id = $blog_id";
  1491. $result = api_sql_query($sql, __FILE__, __LINE__);
  1492. $arrUserTasks = array();*/
  1493. while($row = mysql_fetch_assoc($result))
  1494. {
  1495. $arrUserTasks[] = $row['task_id'];
  1496. }
  1497. // Get assignd date;
  1498. $sql = "
  1499. SELECT target_date
  1500. FROM $tbl_blogs_tasks_rel_user
  1501. WHERE blog_id = '".(int)$blog_id."'
  1502. AND user_id = '".(int)$user_id."'
  1503. AND task_id = '".(int)$task_id."'";
  1504. $result = api_sql_query($sql, __FILE__, __LINE__);
  1505. $row = mysql_fetch_assoc($result);
  1506. $old_date = $row['target_date'];
  1507. $date = explode('-', $row['target_date']);
  1508. // Get users in this blog / make select list of it
  1509. $sql = "
  1510. SELECT user.user_id, user.firstname, user.lastname
  1511. FROM $tbl_users user
  1512. INNER JOIN $tbl_blogs_rel_user blogs_rel_user on user.user_id = blogs_rel_user.user_id
  1513. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1514. $result = api_sql_query($sql, __FILE__, __LINE__);
  1515. $select_user_list = '<select name="task_user_id">';
  1516. while($user = mysql_fetch_array($result))
  1517. {
  1518. $select_user_list .= '<option ' . (($user_id == $user['user_id']) ? 'selected="selected "' : ' ') . 'value="' . $user['user_id'] . '">' . $user['firstname']." " . $user['lastname'] . '</option>';
  1519. }
  1520. $select_user_list .= '</select>';
  1521. // Get tasks in this blog / make select list of it
  1522. $sql = "
  1523. SELECT
  1524. `blog_id`,
  1525. `task_id`,
  1526. `title`,
  1527. `description`,
  1528. `color`,
  1529. `system_task`
  1530. FROM " . $tbl_blogs_tasks . "
  1531. WHERE `blog_id` = " . (int)$blog_id . "
  1532. ORDER BY
  1533. `system_task`,
  1534. `title`";
  1535. $result = api_sql_query($sql, __FILE__, __LINE__);
  1536. $select_task_list = '<select name="task_task_id">';
  1537. while($task = mysql_fetch_array($result))
  1538. {
  1539. //if(!in_array($task['task_id'], $arrUserTasks) || $task_id == $task['task_id'])
  1540. $select_task_list .= '<option ' . (($task_id == $task['task_id']) ? 'selected="selected "' : ' ') . 'value="' . $task['task_id'] . '">'.stripslashes($task['title']) . '</option>';
  1541. }
  1542. $select_task_list .= '</select>';
  1543. // Display
  1544. echo '<form name="assign_task" method="post" action="blog.php?action=manage_tasks&amp;blog_id=' . $blog_id . '">
  1545. <table width="100%" border="0" cellspacing="2" cellpadding="0" style="background-color: #f6f6f6; border: 1px solid #dddddd">
  1546. <tr>
  1547. <td width="200"></td>
  1548. <td><b>' . get_lang('AssignTask') . '</b><br /><br /></td>
  1549. </tr>
  1550. <tr>
  1551. <td align="right">' . get_lang('SelectUser') . ':&nbsp;&nbsp;</td>
  1552. <td>' . $select_user_list . '</td>
  1553. </tr>
  1554. <tr>
  1555. <td align="right">' . get_lang('SelectTask') . ':&nbsp;&nbsp;</td>
  1556. <td>' . $select_task_list . '</td>
  1557. </tr>
  1558. <tr>
  1559. <td align="right">' . get_lang('SelectTargetDate') . ':&nbsp;&nbsp;</td>
  1560. <td>
  1561. <select name="task_day">';
  1562. for($i=1; $i<=31; $i++)
  1563. {
  1564. // values need to have double digits
  1565. $value = ($i <= 9 ? "0" . $i : $i);
  1566. echo "\t\t\t\t<option " . (($date[2] == $value) ? 'selected="selected "' : ' ') . "value=\"" . $value . "\">" . $i . "</option>\n";
  1567. }
  1568. echo '</select>
  1569. <select name="task_month">';
  1570. for($i=1; $i<=12; $i++)
  1571. {
  1572. // values need to have double digits
  1573. $value = ($i <= 9 ? "0" . $i : $i);
  1574. echo "\t\t\t\t<option " . (($date[1] == $value) ? 'selected="selected "' : ' ') . "value=\"" . $value . "\">" . $MonthsLong[$i-1]."</option>\n";
  1575. }
  1576. echo '</select>
  1577. <select name="task_year">
  1578. <option value="' . ($year - 1) . '">' . ($year - 1) . '</option>
  1579. <option value="' . $year . '" selected> ' . $year . ' </option>';
  1580. for($i=1; $i<=5; $i++)
  1581. {
  1582. $value = $year + $i;
  1583. echo "\t\t\t\t<option " . (($date[0] == $value) ? 'selected="selected "' : ' ') . "value=\"" . $value . "\">" . $value . "</option>\n";
  1584. }
  1585. echo '</select>
  1586. <a title="Kalender" href="javascript:openCalendar(\'assign_task\', \'task_\')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a>
  1587. </td>
  1588. </tr>
  1589. <tr>
  1590. <td align="right">&nbsp;</td>
  1591. <input type="hidden" name="action" value="" />
  1592. <input type="hidden" name="old_task_id" value="' . $task_id . '" />
  1593. <input type="hidden" name="old_user_id" value="' . $user_id . '" />
  1594. <input type="hidden" name="old_target_date" value="' . $old_date . '" />
  1595. <input type="hidden" name="assign_task_edit_submit" value="true" />
  1596. <td><br /><input type="submit" name="Submit" value="' . get_lang('Ok') . '" /></td>
  1597. </tr>
  1598. </table>
  1599. </form>';
  1600. }
  1601. /**
  1602. * Assigns a task to a user in a blog
  1603. *
  1604. * @param Integer $blog_id
  1605. * @param Integer $user_id
  1606. * @param Integer $task_id
  1607. * @param Date $target_date
  1608. */
  1609. function assign_task($blog_id, $user_id, $task_id, $target_date)
  1610. {
  1611. // Init
  1612. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1613. $sql = "
  1614. SELECT COUNT(*) as 'number'
  1615. FROM " . $tbl_blogs_tasks_rel_user . "
  1616. WHERE `blog_id` = " . (int)$blog_id . "
  1617. AND `user_id` = " . (int)$user_id . "
  1618. AND `task_id` = " . (int)$task_id . "
  1619. ";
  1620. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1621. $row = mysql_fetch_assoc($result);
  1622. if($row['number'] == 0)
  1623. {
  1624. $sql = "
  1625. INSERT INTO " . $tbl_blogs_tasks_rel_user . " (
  1626. `blog_id`,
  1627. `user_id`,
  1628. `task_id`,
  1629. `target_date`
  1630. ) VALUES (
  1631. '" . (int)$blog_id . "',
  1632. '" . (int)$user_id . "',
  1633. '" . (int)$task_id . "',
  1634. '" . mysql_real_escape_string($target_date) . "'
  1635. )";
  1636. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1637. }
  1638. }
  1639. function edit_assigned_task($blog_id, $user_id, $task_id, $target_date, $old_user_id, $old_task_id, $old_target_date)
  1640. {
  1641. // Init
  1642. $tbl_blogs_tasks_rel_user = Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  1643. $sql = "
  1644. SELECT COUNT(*) as 'number'
  1645. FROM " . $tbl_blogs_tasks_rel_user . "
  1646. WHERE
  1647. `blog_id` = " . (int)$blog_id . " AND
  1648. `user_id` = " . (int)$user_id . " AND
  1649. `task_id` = " . (int)$task_id . "
  1650. ";
  1651. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1652. $row = mysql_fetch_assoc($result);
  1653. if($row['number'] == 0 || ($row['number'] != 0 && $task_id == $old_task_id && $user_id == $old_user_id))
  1654. {
  1655. $sql = "
  1656. UPDATE " . $tbl_blogs_tasks_rel_user . "
  1657. SET
  1658. `user_id` = " . (int)$user_id . ",
  1659. `task_id` = " . (int)$task_id . ",
  1660. `target_date` = '" . mysql_real_escape_string($target_date) . "'
  1661. WHERE
  1662. `blog_id` = " . (int)$blog_id . " AND
  1663. `user_id` = " . (int)$old_user_id . " AND
  1664. `task_id` = " . (int)$old_task_id . " AND
  1665. `target_date` = '" . mysql_real_escape_string($old_target_date) . "'
  1666. ";
  1667. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1668. }
  1669. }
  1670. /**
  1671. * Displays a list with posts a user can select to execute his task.
  1672. *
  1673. * @param Integer $blog_id
  1674. * @param unknown_type $task_id
  1675. */
  1676. function display_select_task_post($blog_id, $task_id)
  1677. {
  1678. // Init
  1679. $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
  1680. $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
  1681. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1682. $sql = "
  1683. SELECT title, description
  1684. FROM $tbl_blogs_tasks
  1685. WHERE task_id = '".(int)$task_id."'";
  1686. $result = api_sql_query($sql, __FILE__, __LINE__);
  1687. $row = mysql_fetch_assoc($result);
  1688. // Get posts and authors
  1689. $sql = "
  1690. SELECT
  1691. post.*,
  1692. user.lastname,
  1693. user.firstname
  1694. FROM $tbl_blogs_posts post
  1695. INNER JOIN $tbl_users user ON post.author_id = user.user_id
  1696. WHERE post.blog_id = '".(int)$blog_id."'
  1697. ORDER BY post_id DESC
  1698. LIMIT 0, 100";
  1699. $result = api_sql_query($sql, __FILE__, __LINE__);
  1700. // Display
  1701. echo '<span class="blogpost_title">' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"</span>';
  1702. echo '<span style="font-style: italic;"">'.stripslashes($row['description']) . '</span><br><br>';
  1703. if(mysql_num_rows($result) > 0)
  1704. {
  1705. while($blog_post = mysql_fetch_array($result))
  1706. {
  1707. 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 />';
  1708. }
  1709. }
  1710. else
  1711. echo get_lang('NoArticles');
  1712. }
  1713. /**
  1714. * Subscribes a user to a given blog
  1715. * @author Toon Keppens
  1716. *
  1717. * @param Integer $blog_id
  1718. * @param Integer $user_id
  1719. */
  1720. function set_user_subscribed($blog_id,$user_id)
  1721. {
  1722. // Init
  1723. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1724. $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
  1725. // Subscribe the user
  1726. $sql = "INSERT INTO $tbl_blogs_rel_user ( `blog_id`, `user_id` ) VALUES ('".(int)$blog_id."', '".(int)$user_id."');";
  1727. $result = api_sql_query($sql, __FILE__, __LINE__);
  1728. // Give this user basic rights
  1729. $sql="INSERT INTO $tbl_user_permissions (user_id,tool,action) VALUES ('".(int)$user_id."','BLOG_" . (int)$blog_id."','article_add')";
  1730. $result = api_sql_query($sql, __LINE__, __FILE__);
  1731. $sql="INSERT INTO $tbl_user_permissions (user_id,tool,action) VALUES ('".(int)$user_id."','BLOG_" . (int)$blog_id."','article_comments_add')";
  1732. $result = api_sql_query($sql, __LINE__, __FILE__);
  1733. }
  1734. /**
  1735. * Unsubscribe a user from a given blog
  1736. * @author Toon Keppens
  1737. *
  1738. * @param Integer $blog_id
  1739. * @param Integer $user_id
  1740. */
  1741. function set_user_unsubscribed($blog_id, $user_id)
  1742. {
  1743. // Init
  1744. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1745. $tbl_user_permissions = Database::get_course_table(TABLE_PERMISSION_USER);
  1746. // Unsubscribe the user
  1747. $sql = "DELETE FROM $tbl_blogs_rel_user WHERE `blog_id` = '".(int)$blog_id."' AND `user_id` = '".(int)$user_id."'";
  1748. $result = @api_sql_query($sql, __FILE__, __LINE__);
  1749. // Remove this user's permissions.
  1750. $sql = "DELETE FROM $tbl_user_permissions WHERE user_id = '".(int)$user_id."'";
  1751. $result = api_sql_query($sql, __LINE__, __FILE__);
  1752. }
  1753. /**
  1754. * Displays the form to register users in a blog (in a course)
  1755. * The listed users are users subcribed in the course.
  1756. * @author Toon Keppens
  1757. *
  1758. * @param Integer $blog_id
  1759. *
  1760. * @return Html Form with sortable table with users to subcribe in a blog, in a course.
  1761. */
  1762. function display_form_user_subscribe($blog_id)
  1763. {
  1764. // Init
  1765. global $_course;
  1766. $currentCourse = $_course['sysCode'];
  1767. $tbl_users = Database::get_main_table(TABLE_MAIN_USER);
  1768. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  1769. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  1770. echo '<span class="blogpost_title">' . get_lang('SubscribeMembers') . '</span>';
  1771. $properties["width"] = "100%";
  1772. // Get blog members' id.
  1773. $sql = "SELECT user.user_id FROM $tbl_users user
  1774. INNER JOIN $tbl_blogs_rel_user blogs_rel_user
  1775. ON user.user_id = blogs_rel_user.user_id
  1776. WHERE blogs_rel_user.blog_id = '".(int)$blog_id."'";
  1777. $result = api_sql_query($sql, __FILE__, __LINE__);
  1778. $blog_member_ids = array ();
  1779. while($user = mysql_fetch_array($result))
  1780. {
  1781. $blog_member_ids[] = $user['user_id'];
  1782. }
  1783. // Set table headers
  1784. $column_header[] = array ('', false, '');
  1785. $column_header[] = array (get_lang('LastName'), true, '');
  1786. $column_header[] = array (get_lang('FirstName'), true, '');
  1787. $column_header[] = array (get_lang('Email'), true, '');
  1788. $column_header[] = array (get_lang('Register'), false, '');
  1789. include_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  1790. include_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  1791. if(isset($_SESSION['session_id'])){
  1792. $session_id = $_SESSION['session_id'];
  1793. }
  1794. else{
  1795. $session_id = 0;
  1796. }
  1797. $student_list = CourseManager :: get_student_list_from_course_code($currentCourse, true, $session_id);
  1798. $user_data = array ();
  1799. // Add users that are not in this blog to the list.
  1800. foreach($student_list as $key=>$user)
  1801. {
  1802. if(isset($user['id_user']))
  1803. {
  1804. $user['user_id'] = $user['id_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. ?>