blog.lib.php 110 KB

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