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

Source for file blog.php

Documentation is available at blog.php

  1. <?php
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) 2003 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.     Copyright (c) various contributors
  10.  
  11.     For a full list of contributors, see "credits.txt".
  12.     The full license can be read in "license.txt".
  13.  
  14.     This program is free software; you can redistribute it and/or
  15.     modify it under the terms of the GNU General Public License
  16.     as published by the Free Software Foundation; either version 2
  17.     of the License, or (at your option) any later version.
  18.  
  19.     See the GNU General Public License for more details.
  20.  
  21.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium 
  22.     info@dokeos.com
  23.  
  24. ==============================================================================
  25.  
  26.     BLOG HOMEPAGE
  27.  
  28.     This file takes care of all blog navigation and displaying.
  29.  
  30.     @package dokeos.blogs
  31. ==============================================================================
  32. */
  33.  
  34. /*
  35. ==============================================================================
  36.     INIT
  37. ==============================================================================
  38. */
  39. // name of the language file that needs to be included
  40. $language_file "blog";
  41. $blog_id intval($_GET['blog_id']);
  42.  
  43. include ('../inc/global.inc.php');
  44. $this_section=SECTION_COURSES;
  45.  
  46. /* ------------    ACCESS RIGHTS ------------ */
  47. // notice for unauthorized people.
  48.  
  49.  
  50. //session
  51. if(isset($_GET['id_session']))
  52. {
  53.     $_SESSION['id_session'$_GET['id_session'];
  54. }
  55.  
  56. require_once (api_get_path(LIBRARY_PATH)."/display.lib.php");
  57. require_once (api_get_path(LIBRARY_PATH)."/text.lib.php");
  58. require_once (api_get_path(LIBRARY_PATH)."/blog.lib.php");
  59. require_once (api_get_path(LIBRARY_PATH)."/fckeditor.lib.php");
  60. $blog_table_attachment     Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  61.  
  62. $nameTools get_lang("Blogs");
  63. $DaysShort array (get_lang("SundayShort")get_lang("MondayShort")get_lang("TuesdayShort")get_lang("WednesdayShort")get_lang("ThursdayShort")get_lang("FridayShort")get_lang("SaturdayShort"));
  64. $DaysLong array (get_lang("SundayLong")get_lang("MondayLong")get_lang("TuesdayLong")get_lang("WednesdayLong")get_lang("ThursdayLong")get_lang("FridayLong")get_lang("SaturdayLong"));
  65. $MonthsLong array (get_lang("JanuaryLong")get_lang("FebruaryLong")get_lang("MarchLong")get_lang("AprilLong")get_lang("MayLong")get_lang("JuneLong")get_lang("JulyLong")get_lang("AugustLong")get_lang("SeptemberLong")get_lang("OctoberLong")get_lang("NovemberLong")get_lang("DecemberLong"));
  66.  
  67. $current_page $_GET['action'];
  68.  
  69. /*
  70. ==============================================================================
  71.     PROCESSING
  72. ==============================================================================
  73. */
  74. if ($_POST['new_post_submit'])
  75. {    
  76.     Blog :: create_post($_POST['post_title']$_POST['post_full_text']$_POST['post_file_comment'],$blog_id);
  77. }
  78. if ($_POST['edit_post_submit'])
  79. {
  80.     Blog :: edit_post($_POST['post_id']$_POST['post_title']$_POST['post_full_text']$blog_id);
  81. }
  82. if ($_POST['new_comment_submit'])
  83. {
  84.     Blog :: create_comment($_POST['comment_title']$_POST['comment_text']$_POST['post_file_comment'],$blog_id(int)$_GET['post_id']$_POST['comment_parent_id']);
  85. }
  86.  
  87. if ($_POST['new_task_submit'])
  88. {
  89.     Blog :: create_task($blog_id$_POST['task_name']$_POST['task_description']$_POST['chkArticleDelete']$_POST['chkArticleEdit']$_POST['chkCommentsDelete']$_POST['task_color']);
  90. }
  91. if ($_POST['edit_task_submit'])
  92. {
  93.     Blog :: edit_task($_POST['blog_id']$_POST['task_id']$_POST['task_name']$_POST['task_description']$_POST['chkArticleDelete']$_POST['chkArticleEdit'],$_POST['chkCommentsDelete']$_POST['task_color']);
  94. }
  95. if ($_POST['assign_task_submit'])
  96. {
  97.     Blog :: assign_task($blog_id$_POST['task_user_id']$_POST['task_task_id']$_POST['task_year']."-".$_POST['task_month']."-".$_POST['task_day']);
  98. }
  99.  
  100. if ($_POST['assign_task_edit_submit'])
  101. {
  102.     Blog :: edit_assigned_task($blog_id$_POST['task_user_id']$_POST['task_task_id']$_POST['task_year']."-".$_POST['task_month']."-".$_POST['task_day']$_POST['old_user_id']$_POST['old_task_id']$_POST['old_target_date']);
  103. }
  104. if ($_POST['new_task_execution_submit'])
  105. {
  106.     Blog :: create_comment($_POST['comment_title']$_POST['comment_text']$blog_id(int)$_GET['post_id']$_POST['comment_parent_id']$_POST['task_id']);
  107. }
  108. if ($_POST['register'])
  109. {
  110.     foreach ($_POST['user'as $index => $user_id)
  111.     {
  112.         Blog :: set_user_subscribed((int)$_GET['blog_id']$user_id);
  113.     }
  114. }
  115. if ($_POST['unregister'])
  116. {
  117.     foreach ($_POST['user'as $index => $user_id)
  118.     {
  119.         Blog :: set_user_unsubscribed((int)$_GET['blog_id']$user_id);
  120.     }
  121. }
  122. if ($_GET['register'])
  123. {
  124.     Blog :: set_user_subscribed((int)$_GET['blog_id'](int)$_GET['user_id']);
  125.     $flag 1;
  126. }
  127. if ($_GET['unregister'])
  128. {
  129.     Blog :: set_user_unsubscribed((int)$_GET['blog_id'](int)$_GET['user_id']);
  130. }
  131.  
  132. if ($_GET['action'== 'manage_tasks')
  133. {
  134.     if ($_GET['do'== 'delete')
  135.         Blog :: delete_task($blog_id(int)$_GET['task_id']);
  136.  
  137.     if ($_GET['do'== 'delete_assignment')
  138.         Blog :: delete_assigned_task($blog_id(int)$_GET['assignment_id']);
  139. }
  140.  
  141. if ($_GET['action'== 'view_post')
  142. {
  143.     $task_id (isset ($_GET['task_id']&& is_numeric($_GET['task_id'])) $_GET['task_id'0;
  144.  
  145.     if ($_GET['do'== 'delete_comment')
  146.     {
  147.         if (api_is_allowed('BLOG_'.$blog_id'article_comments_delete'$task_id))
  148.         {        
  149.             Blog :: delete_comment($blog_id(int)$_GET['post_id'],(int)$_GET['comment_id'])
  150.         }
  151.         else
  152.         {
  153.             $error true;
  154.             $message get_lang('ActionNotAllowed');
  155.         }
  156.     }
  157.  
  158.     if ($_GET['do'== 'delete_article')
  159.     {
  160.         if (api_is_allowed('BLOG_'.$blog_id'article_delete'$task_id))
  161.         {
  162.             Blog :: delete_post($blog_id(int)$_GET['article_id']);
  163.             $current_page ''// Article is gone, go to blog home
  164.         }
  165.         else
  166.         {
  167.             $error true;
  168.             $message get_lang('ActionNotAllowed');
  169.         }
  170.     }
  171.     if ($_GET['do'== 'rate')
  172.     {
  173.         if ($_GET['type'== 'post')
  174.         {
  175.             if (api_is_allowed('BLOG_'.$blog_id'article_rate'))
  176.             {
  177.                 Blog :: add_rating('post'$blog_id(int)$_GET['post_id'](int)$_GET['rating']);
  178.             }
  179.         }
  180.         if ($_GET['type'== 'comment')
  181.         {
  182.             if (api_is_allowed('BLOG_'.$blog_id'article_comments_add'))
  183.             {
  184.                 Blog :: add_rating('comment'$blog_id(int)$_GET['comment_id'](int)$_GET['rating']);
  185.             }
  186.         }
  187.     }
  188. }
  189. /*
  190. ==============================================================================
  191.     DISPLAY
  192. ==============================================================================
  193. */
  194. $htmlHeadXtra["<script src=\"tbl_change.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  195.  
  196. // Set bredcrumb
  197. switch ($current_page)
  198. {
  199.     case "new_post" :
  200.         $nameTools get_lang('NewPost');
  201.         $interbreadcrumb[array ("url" => "blog.php?blog_id=$blog_id""name" => Blog :: get_blog_title($blog_id));
  202.         Display :: display_header($nameTools'blogs');
  203.         break;
  204.     case "manage_tasks" :
  205.         $nameTools get_lang('TaskManager');
  206.         $interbreadcrumb[array ("url" => "blog.php?blog_id=$blog_id""name" => Blog :: get_blog_title($blog_id));
  207.         Display :: display_header($nameTools'blogs');
  208.         break;
  209.     case "manage_members" :
  210.         $nameTools get_lang('MemberManager');
  211.         $interbreadcrumb[array ("url" => "blog.php?blog_id=$blog_id""name" => Blog :: get_blog_title($blog_id));
  212.         Display :: display_header($nameTools'blogs');
  213.         break;
  214.     case "manage_rights" :
  215.         $nameTools get_lang('RightsManager');
  216.         $interbreadcrumb[array ("url" => "blog.php?blog_id=$blog_id""name" => Blog :: get_blog_title($blog_id));
  217.         Display :: display_header($nameTools'blogs');
  218.         break;
  219.     case "view_search_result" :
  220.         $nameTools get_lang('SearchResults');
  221.         $interbreadcrumb[array ("url" => "blog.php?blog_id=$blog_id""name" => Blog :: get_blog_title($blog_id));
  222.         Display :: display_header($nameTools'blogs');
  223.         break;
  224.     case "execute_task" :
  225.         $nameTools get_lang('ExecuteThisTask');
  226.         $interbreadcrumb[array ("url" => "blog.php?blog_id=$blog_id""name" => Blog :: get_blog_title($blog_id));
  227.         Display :: display_header($nameTools'blogs');
  228.         break;
  229.     default :
  230.         $nameTools Blog :: get_blog_title($blog_id);
  231.         Display :: display_header($nameTools'blogs');
  232. }
  233.  
  234. //Display::display_header($nameTools,'Blogs');
  235. ?>
  236. <span class="blog_title"><?php echo Blog::get_blog_title($blog_id?></span><br />
  237. <span class="blog_subtitle"><?php echo Blog::get_blog_subtitle($blog_id?></span>
  238. <br /><br />
  239. <table width="100%">
  240. <tr>
  241.     <td width="220" class="blog_left" valign="top">
  242.         <?php
  243.  
  244.  
  245. $month = (int)$_GET['month'? (int)$_GET['month': (int) date('m');
  246. $year = (int)$_GET['year'? (int)$_GET['year'date('Y');
  247. Blog :: display_minimonthcalendar($month$year$blog_id);
  248. ?>
  249.         <br />
  250.         <table width="100%">
  251.             <tr>
  252.                 <td class="blog_menu_title"><?php echo get_lang('ThisBlog'?></td>
  253.             </tr>
  254.             <tr>
  255.                 <td class="blog_menu">
  256.                     <ul>
  257.                         <li><a href="<?php echo api_get_self()?>?blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('Home'?>"><?php echo get_lang('Home'?></a></li>
  258.                         <?php if(api_is_allowed('BLOG_'.$blog_id'article_add')) ?><li><a href="<?php echo api_get_self()?>?action=new_post&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('NewPost'?>"><?php echo get_lang('NewPost'?></a></li><?php ?>
  259.                         <?php if(api_is_allowed('BLOG_'.$blog_id'task_management')) ?><li><a href="<?php echo api_get_self()?>?action=manage_tasks&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageTasks'?>"><?php echo get_lang('TaskManager'?></a></li> <?php ?>
  260.                         <?php if(api_is_allowed('BLOG_'.$blog_id'member_management')) ?><li><a href="<?php echo api_get_self()?>?action=manage_members&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageMembers'?>"><?php echo get_lang('MemberManager'?></a></li><?php ?>
  261.                     </ul>
  262.                 </td>
  263.             </tr>
  264.         </table>
  265.         <br />
  266.         <table width="100%">
  267.             <tr>
  268.                 <td class="blog_menu_title"><?php echo get_lang('Search'?></td>
  269.             </tr>
  270.             <tr>
  271.                 <td class="blog_menu">
  272.                     <form action="blog.php" method="get" enctype="multipart/form-data">
  273.                         <input type="hidden" name="blog_id" value="<?php echo $blog_id ?>" />
  274.                         <input type="hidden" name="action" value="view_search_result" />
  275.                         <input type="text" size="20" name="q" value="<?php echo (isset($_GET['q']$_GET['q''')?>" /><input type="submit" value="Go" />
  276.                     </form>
  277.                 </td>
  278.             </tr>
  279.         </table>
  280.         <br />
  281.         <table width="100%">
  282.             <tr>
  283.                 <td class="blog_menu_title"><?php echo get_lang('MyTasks'?></td>
  284.             </tr>
  285.             <tr>
  286.                 <td class="blog_menu">
  287.                     <?php Blog::get_personal_task_list()?>
  288.                 </td>
  289.             </tr>
  290.         </table>
  291.         <!--
  292.         <br />
  293.         <table width="100%">
  294.             <tr>
  295.                 <td class="blog_menu_title"><?php echo get_lang('FavoriteBlogs'?></td>
  296.             </tr>
  297.             <tr>
  298.                 <td class="blog_menu">
  299.                     <ul>
  300.                         <li>Favorite 1</li>
  301.                         <li>Favorite 2</li>
  302.                         <li>Favorite 3</li>
  303.                     </ul>
  304.                 </td>
  305.             </tr>
  306.         </table>
  307.         <br />
  308.         <table width="100%">
  309.             <tr>
  310.                 <td class="blog_menu_title"><?php echo get_lang('TopTen'?></td>
  311.             </tr>
  312.             <tr>
  313.                 <td class="blog_menu">
  314.                     <ul>
  315.                         <li>Blog 1</li>
  316.                         <li>Blog 2</li>
  317.                         <li>Blog 3</li>
  318.                     </ul>
  319.                 </td>
  320.             </tr>
  321.         </table>
  322.     -->
  323.     </td>
  324.     <td valign="top" class="blog_right">
  325.         <?php
  326.  
  327.  
  328. if ($error)
  329.     Display :: display_error_message($message);
  330.  
  331. if ($flag == '1')
  332. {
  333.     $current_page "manage_tasks";
  334.     Blog :: display_assign_task_form($blog_id);
  335. }
  336.  
  337. $user_task false;
  338.  
  339. if (isset ($_GET['task_id']&& is_numeric($_GET['task_id']))
  340.     $task_id = (int)$_GET['task_id'];
  341. else
  342. {
  343.     $task_id 0;
  344.  
  345.     $tbl_blogs_tasks_rel_user Database :: get_course_table(TABLE_BLOGS_TASKS_REL_USER);
  346.  
  347.     $sql "
  348.                             SELECT COUNT(*) as `number`
  349.                             FROM ".$tbl_blogs_tasks_rel_user."
  350.                             WHERE
  351.                                 `blog_id` = ".$blog_id." AND
  352.                                 `user_id` = ".api_get_user_id()." AND
  353.                                 `task_id` = ".$task_id;
  354.  
  355.     $result api_sql_query($sql__LINE____FILE__);
  356.     $row mysql_fetch_array($resultMYSQL_ASSOC);
  357.  
  358.     if ($row['number'== 1)
  359.         $user_task true;
  360. }
  361.  
  362. switch ($current_page)
  363. {
  364.     case 'new_post' :
  365.         if (api_is_allowed('BLOG_'.$blog_id'article_add'$user_task $task_id 0))
  366.         {
  367.             Blog :: display_form_new_post($blog_id);
  368.         }
  369.         else
  370.         {
  371.             api_not_allowed();
  372.         }
  373.         break;
  374.     case 'view_post' :
  375.         Blog :: display_post($blog_idmysql_real_escape_string((int)$_GET['post_id']));
  376.         break;
  377.     case 'edit_post' :
  378.         $task_id (isset ($_GET['task_id']&& is_numeric($_GET['task_id'])) $_GET['task_id'0;
  379.  
  380.         if (api_is_allowed('BLOG_'.$blog_id'article_edit'$task_id))
  381.             Blog :: display_form_edit_post($blog_idmysql_real_escape_string((int)$_GET['post_id']));
  382.         else
  383.             api_not_allowed();
  384.  
  385.         break;
  386.     case 'manage_members' :
  387.         if (api_is_allowed('BLOG_'.$blog_id'member_management'))
  388.         {
  389.             Blog :: display_form_user_subscribe($blog_id);
  390.             echo '<br /><br />';
  391.             Blog :: display_form_user_unsubscribe($blog_id);
  392.         }
  393.         else
  394.             api_not_allowed();
  395.  
  396.         break;
  397.     case 'manage_rights' :
  398.         Blog :: display_form_user_rights($blog_id);
  399.         break;
  400.     case 'manage_tasks' :
  401.         if (api_is_allowed('BLOG_'.$blog_id'task_management'))
  402.         {
  403.             if ($_GET['do'== 'add')
  404.             {
  405.                 Blog :: display_new_task_form($blog_id);
  406.             }
  407.             if ($_GET['do'== 'assign')
  408.             {
  409.                 Blog :: display_assign_task_form($blog_id);
  410.             }
  411.             if ($_GET['do'== 'edit')
  412.             {
  413.                 Blog :: display_edit_task_form($blog_idmysql_real_escape_string($_GET['task_id']));
  414.             }
  415.             if ($_GET['do'== 'edit_assignment')
  416.             {
  417.                 Blog :: display_edit_assigned_task_form($blog_idmysql_real_escape_string((int)$_GET['assignment_id']));
  418.             }
  419.             Blog :: display_task_list($blog_id);
  420.             echo '<br /><br />';
  421.             Blog :: display_assigned_task_list($blog_id);
  422.             echo '<br /><br />';
  423.             if (api_is_allowed('BLOG_'.$blog_id'role_management'))
  424.             {
  425.             ?>
  426.                 <a href="<?php echo api_get_self()?>?action=manage_rights&amp;blog_id=<?php echo $blog_id ?>" title="<?php echo get_lang('ManageRights'?>"><?php echo get_lang('RightsManager'?></a>
  427.             <?php
  428.             }
  429.         }
  430.         else
  431.             api_not_allowed();
  432.  
  433.         break;
  434.     case 'execute_task' :
  435.         if (isset ($_GET['post_id']))
  436.             Blog :: display_post($blog_idmysql_real_escape_string((int)$_GET['post_id']));
  437.         else
  438.             Blog :: display_select_task_post($blog_idmysql_real_escape_string((int)$_GET['task_id']));
  439.  
  440.         break;
  441.     case 'view_search_result' :
  442.         Blog :: display_search_results($blog_idmysql_real_escape_string($_GET['q']));
  443.         break;
  444.     case '' :
  445.     default :
  446.         if (isset ($_GET['filter']&& !empty ($_GET['filter']))
  447.         {
  448.             Blog :: display_day_results($blog_idmysql_real_escape_string($_GET['filter']));
  449.         }
  450.         else
  451.         {
  452.             Blog :: display_blog_posts($blog_id);
  453.         }
  454. }
  455. ?>
  456.     </td>
  457. </tr>
  458. </table>
  459.  
  460. <?php
  461. // Display the footer
  462. ?>

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