dokeos-blogs
[ class tree: dokeos-blogs ] [ index: dokeos-blogs ] [ all elements ]

Source for file blog.lib.php

Documentation is available at blog.lib.php

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

Documentation generated on Thu, 12 Jun 2008 13:01:15 -0500 by phpDocumentor 1.4.1