blog.lib.php 92 KB

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