blog.lib.php 103 KB

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