block_global_info.class.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * This file is part of global info block plugin for dashboard,
  4. * it should be required inside the dashboard controller for
  5. * showing it into the dashboard interface.
  6. * @package chamilo.dashboard
  7. * @author Yannick Warnier
  8. */
  9. /**
  10. * required files for getting data
  11. */
  12. require_once api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php';
  13. /**
  14. * This class is used like controller for this global info block plugin
  15. * the class name must be registered inside path.info file
  16. * (e.g: controller = "BlockGlobalInfo"), so dashboard controller can
  17. * instantiate it
  18. * @package chamilo.dashboard
  19. */
  20. class BlockGlobalInfo extends Block
  21. {
  22. private $user_id;
  23. private $courses;
  24. private $path;
  25. private $permission = array();
  26. /**
  27. * Constructor
  28. */
  29. public function __construct ($user_id)
  30. {
  31. $this->user_id = $user_id;
  32. $this->path = 'block_global_info';
  33. if ($this->is_block_visible_for_user($user_id)) {
  34. //$this->courses = CourseManager::get_courses_followed_by_drh($user_id);
  35. }
  36. }
  37. /**
  38. * This method check if a user is allowed to see the block inside dashboard interface
  39. * @param int User id
  40. * @return bool Is block visible for user
  41. */
  42. public function is_block_visible_for_user($user_id)
  43. {
  44. $user_info = api_get_user_info($user_id);
  45. $user_status = $user_info['status'];
  46. $is_block_visible_for_user = false;
  47. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  48. $is_block_visible_for_user = true;
  49. }
  50. return $is_block_visible_for_user;
  51. }
  52. /**
  53. * This method return content html containing information about courses and its position for showing it inside dashboard interface
  54. * it's important to use the name 'get_block' for beeing used from dashboard controller
  55. * @return array column and content html
  56. */
  57. public function get_block()
  58. {
  59. global $charset;
  60. $column = 2;
  61. $data = array();
  62. $content = $this->get_content_html();
  63. $html = '
  64. <li class="widget color-red" id="intro">
  65. <div class="widget-head">
  66. <h3>'.get_lang('GlobalPlatformInformation').'</h3>
  67. <div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
  68. </div>
  69. <div class="widget-content">
  70. '.$content.'
  71. </div>
  72. </li>
  73. ';
  74. $data['column'] = $column;
  75. $data['content_html'] = $html;
  76. return $data;
  77. }
  78. /**
  79. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  80. * @return string content html
  81. */
  82. public function get_content_html()
  83. {
  84. $global_data = $this->get_global_information_data();
  85. $content = '<div style="margin:10px;">';
  86. $content .= '<h3><font color="#000">'.get_lang('GlobalPlatformInformation').'</font></h3>';
  87. $data_table = null;
  88. if (!empty($global_data)) {
  89. $data_table = '<table class="data_table" width:"95%">';
  90. $i = 1;
  91. foreach ($global_data as $data) {
  92. if ($i%2 == 0) {
  93. $class_tr = 'row_odd';
  94. } else {
  95. $class_tr = 'row_even';
  96. }
  97. $data_table .= '<tr class="'.$class_tr.'">';
  98. foreach ($data as $cell) {
  99. $data_table .= '<td align="right">'.$cell.'</td>';
  100. }
  101. $data_table .= '</tr>';
  102. $i++;
  103. }
  104. $data_table .= '</table>';
  105. } else {
  106. $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
  107. }
  108. $content .= $data_table;
  109. $content .= '</div>';
  110. return $content;
  111. }
  112. /**
  113. * Get global information data
  114. * @return array
  115. */
  116. function get_global_information_data()
  117. {
  118. // Two-dimensional array with data about the system
  119. $path = api_get_path(WEB_CODE_PATH);
  120. // Check total number of users
  121. $global_info = array(
  122. array(get_lang('CountUsers'), '<a href="'.$path.'admin/user_list.php">'.Statistics::count_users().'</a>'),
  123. // Check only active users
  124. array(get_lang('NumberOfUsersActive'), '<a href="'.$path.'admin/user_list.php?keyword_firstname=&amp;keyword_lastname=&amp;keyword_username=&amp;keyword_email=&amp;keyword_officialcode=&amp;keyword_status=%25&amp;keyword_active=1&amp;submit=&amp;_qf__advanced_search=">'.Statistics::count_users(null,null,null,true).'</a>'),
  125. // Check number of courses
  126. array(get_lang('NumberOfCoursesTotal'), '<a href="'.$path.'admin/course_list.php">'.Statistics::count_courses().'</a>'),
  127. array(get_lang('NumberOfCoursesPublic'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_WORLD.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_WORLD).'</a>'),
  128. array(get_lang('NumberOfCoursesOpen'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_PLATFORM.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_PLATFORM).'</a>'),
  129. array(get_lang('NumberOfCoursesPrivate'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_REGISTERED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_REGISTERED).'</a>'),
  130. array(get_lang('NumberOfCoursesClosed'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_CLOSED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_CLOSED).'</a>'),
  131. array(get_lang('NumberOfCoursesHidden'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_HIDDEN.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_HIDDEN).'</a>')
  132. );
  133. return $global_info;
  134. }
  135. }