blog.lib.php 107 KB

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