blog.lib.php 113 KB

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