blog.lib.php 111 KB

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