blog.lib.php 111 KB

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