blog.lib.php 113 KB

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