blog.lib.php 112 KB

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