blog.lib.php 123 KB

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