blog.lib.php 111 KB

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