blog.lib.php 123 KB

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