Fixing define PHP errorPHP warning/notices avoided

skala
Julio Montoya 13 years ago
parent 8eb2609715
commit 8c57e73fe4
  1. 2
      main/admin/statistics/statistics.lib.php
  2. 7
      main/auth/profile.php
  3. 65
      main/dashboard/dashboard.php
  4. 88
      main/dashboard/dashboard_controller.php
  5. 77
      main/inc/lib/dashboard.lib.php
  6. 366
      main/inc/lib/sessionmanager.lib.php
  7. 483
      main/inc/lib/usermanager.lib.php
  8. 46
      main/social/friends.php
  9. 13
      main/social/groups.php
  10. 6
      main/social/invitations.php
  11. 2
      main/social/search.php
  12. 37
      plugin/dashboard/block_course/block_course.class.php
  13. 49
      plugin/dashboard/block_daily/block_daily.class.php
  14. 156
      plugin/dashboard/block_student/block_student.class.php
  15. 145
      plugin/dashboard/block_teacher/block_teacher.class.php

@ -57,7 +57,7 @@ class Statistics {
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE); $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id(); $current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls']) { if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'"; $sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'";
if (isset ($vis)) { if (isset ($vis)) {
$sql .= " AND visibility = ".intval($vis); $sql .= " AND visibility = ".intval($vis);

@ -688,8 +688,6 @@ if (!empty($msg_is_not_password)){
$image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true); $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true);
$image_syspath['dir'].$image_syspath['file']; $image_syspath['dir'].$image_syspath['file'];
//$image_size = api_getimagesize($image_syspath['dir'].$image_syspath['file']);
//Web path //Web path
$image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true); $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true);
$image_dir = $image_path['dir']; $image_dir = $image_path['dir'];
@ -698,10 +696,6 @@ $image_file = $image_dir.$image;
$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
.'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
.'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" '; .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" ';
if ($image_size['width'] > 300) {
//limit display width to 300px
$img_attributes .= 'width="300" ';
}
// get the path,width and height from original picture // get the path,width and height from original picture
$big_image = $image_dir.'big_'.$image; $big_image = $image_dir.'big_'.$image;
@ -723,7 +717,6 @@ if (api_get_setting('allow_social_tool') == 'true') {
echo '</div>'; echo '</div>';
} else { } else {
// Style position:absolute has been removed for Opera-compatibility. // Style position:absolute has been removed for Opera-compatibility.
//echo '<div id="image-message-container" style="float:right;display:inline;position:absolute;padding:3px;width:250px;" >';
echo '<div id="image-message-container" style="float:right;display:inline;padding:3px;width:230px;" >'; echo '<div id="image-message-container" style="float:right;display:inline;padding:3px;width:230px;" >';
if ($image == 'unknown.jpg') { if ($image == 'unknown.jpg') {

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Template (view in MVC pattern) used for displaying blocks for dashboard * Template (view in MVC pattern) used for displaying blocks for dashboard
* @author Christian Fasanando <christian1827@gmail.com> * @author Christian Fasanando <christian1827@gmail.com>
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
@ -12,19 +12,20 @@ api_block_anonymous_users();
// menu actions for dashboard views // menu actions for dashboard views
$views = array('blocks', 'list'); $views = array('blocks', 'list');
//$dashboard_view = 'blocks';
if(isset($_GET['view']) && in_array($_GET['view'], $views)){ if(isset($_GET['view']) && in_array($_GET['view'], $views)){
$dashboard_view = $_GET['view']; $dashboard_view = $_GET['view'];
} }
if($dashboard_view == 'list') { $link_blocks_view = $link_list_view = null;
if (isset($dashboard_view) && $dashboard_view == 'list') {
$link_blocks_view = '<a href="'.api_get_self().'?view=blocks">'.Display::return_icon('blocks.png',get_lang('DashboardBlocks'),'',ICON_SIZE_MEDIUM).'</a>'; $link_blocks_view = '<a href="'.api_get_self().'?view=blocks">'.Display::return_icon('blocks.png',get_lang('DashboardBlocks'),'',ICON_SIZE_MEDIUM).'</a>';
} else { } else {
$link_list_view = '<a href="'.api_get_self().'?view=list">'.Display::return_icon('edit.png',get_lang('EditBlocks'),'',ICON_SIZE_MEDIUM).'</a>'; $link_list_view = '<a href="'.api_get_self().'?view=list">'.Display::return_icon('edit.png',get_lang('EditBlocks'),'',ICON_SIZE_MEDIUM).'</a>';
} }
$configuration_link = ''; $configuration_link = null;
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$configuration_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">' $configuration_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'
.Display::return_icon('settings.png',get_lang('ConfigureDashboardPlugin'),'',ICON_SIZE_MEDIUM).'</a>'; .Display::return_icon('settings.png',get_lang('ConfigureDashboardPlugin'),'',ICON_SIZE_MEDIUM).'</a>';
@ -35,64 +36,64 @@ echo $link_blocks_view.$link_list_view.$configuration_link;
echo '</div>'; echo '</div>';
// block dashboard view // block dashboard view
if($dashboard_view == 'blocks') { if (isset($dashboard_view) && $dashboard_view == 'blocks') {
if (isset($msg)) { if (isset($msg)) {
//Display::display_confirmation_message(get_lang('BlocksHaveBeenUpdatedSuccessfully')); //Display::display_confirmation_message(get_lang('BlocksHaveBeenUpdatedSuccessfully'));
} }
if (count($blocks) > 0) { if (count($blocks) > 0) {
$columns = array(); $columns = array();
// group content html by number of column // group content html by number of column
if (is_array($blocks)) { if (is_array($blocks)) {
$tmp_columns = array(); $tmp_columns = array();
foreach ($blocks as $block) { foreach ($blocks as $block) {
$tmp_columns[] = $block['column']; $tmp_columns[] = $block['column'];
if (in_array($block['column'], $tmp_columns)) { if (in_array($block['column'], $tmp_columns)) {
$columns['column_'.$block['column']][] = $block['content_html']; $columns['column_'.$block['column']][] = $block['content_html'];
} }
} }
} }
echo '<div id="columns">'; echo '<div id="columns">';
if (count($columns) > 0) { if (count($columns) > 0) {
$columns_name = array_keys($columns); $columns_name = array_keys($columns);
// blocks for column 1 // blocks for column 1
if (in_array('column_1',$columns_name)) { if (in_array('column_1',$columns_name)) {
echo '<ul id="column1" class="column">'; echo '<ul id="column1" class="column">';
foreach ($columns['column_1'] as $content) { foreach ($columns['column_1'] as $content) {
echo $content; echo $content;
} }
echo '</ul>'; echo '</ul>';
} else { } else {
echo '<ul id="column1" class="column">'; echo '<ul id="column1" class="column">';
echo '&nbsp;'; echo '&nbsp;';
echo '</ul>'; echo '</ul>';
} }
// blocks for column 2 // blocks for column 2
if (in_array('column_2',$columns_name)) { if (in_array('column_2',$columns_name)) {
// blocks for column 1 // blocks for column 1
echo '<ul id="column2" class="column">'; echo '<ul id="column2" class="column">';
foreach ($columns['column_2'] as $content) { foreach ($columns['column_2'] as $content) {
echo $content; echo $content;
} }
echo '</ul>'; echo '</ul>';
} else { } else {
echo '<ul id="column2" class="column">'; echo '<ul id="column2" class="column">';
echo '&nbsp;'; echo '&nbsp;';
echo '</ul>'; echo '</ul>';
} }
} }
echo '</div>'; echo '</div>';
} else { } else {
echo '<div style="margin-top:20px;">'.get_lang('YouHaveNotEnabledBlocks').'</div>'; echo '<div style="margin-top:20px;">'.get_lang('YouHaveNotEnabledBlocks').'</div>';
} }
} else { } else {
// block dashboard list // block dashboard list
if (isset($success)) { if (isset($success)) {
Display::display_confirmation_message(get_lang('BlocksHaveBeenUpdatedSuccessfully')); Display::display_confirmation_message(get_lang('BlocksHaveBeenUpdatedSuccessfully'));
} }
$user_id = api_get_user_id(); $user_id = api_get_user_id();
DashboardManager::display_user_dashboard_list($user_id); DashboardManager::display_user_dashboard_list($user_id);
} }

@ -9,23 +9,23 @@
/** /**
* Controller script. Prepares the common background variables to give to the scripts corresponding to * Controller script. Prepares the common background variables to give to the scripts corresponding to
* the requested action * the requested action
*/ */
class DashboardController { // extends Controller { class DashboardController { // extends Controller {
private $toolname; private $toolname;
private $view; private $view;
private $user_id; private $user_id;
/** /**
* Constructor * Constructor
*/ */
public function __construct() { public function __construct() {
$this->user_id = api_get_user_id(); $this->user_id = api_get_user_id();
$this->toolname = 'dashboard'; $this->toolname = 'dashboard';
$this->view = new View($this->toolname); $this->view = new View($this->toolname);
} }
/** /**
* Display blocks from dashboard plugin paths * Display blocks from dashboard plugin paths
* @param string message (optional) * @param string message (optional)
@ -33,90 +33,92 @@ class DashboardController { // extends Controller {
*/ */
public function display($msg = false) { public function display($msg = false) {
$data = array(); $data = array();
$user_id = $this->user_id; $user_id = $this->user_id;
$block_data_without_plugin = DashboardManager::get_block_data_without_plugin(); $block_data_without_plugin = DashboardManager::get_block_data_without_plugin();
$dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks(); $dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks();
$user_block_data = DashboardManager::get_user_block_data($user_id); $user_block_data = DashboardManager::get_user_block_data($user_id);
$user_blocks_id = array_keys($user_block_data); $user_blocks_id = array_keys($user_block_data);
$data_block = null;
if (!empty($dashboard_blocks)) { if (!empty($dashboard_blocks)) {
foreach ($dashboard_blocks as $block) { foreach ($dashboard_blocks as $block) {
// display only user blocks // display only user blocks
if (!in_array($block['id'], $user_blocks_id)) continue; if (!in_array($block['id'], $user_blocks_id)) continue;
$path = $block['path']; $path = $block['path'];
$controller_class = $block['controller']; $controller_class = $block['controller'];
$filename_controller = $path.'.class.php'; $filename_controller = $path.'.class.php';
$dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/'; $dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
require_once $dashboard_plugin_path.$filename_controller; require_once $dashboard_plugin_path.$filename_controller;
if (class_exists($controller_class)) { if (class_exists($controller_class)) {
$obj = new $controller_class($user_id); $obj = new $controller_class($user_id);
// check if user is allowed to see the block // check if user is allowed to see the block
if (method_exists($obj, 'is_block_visible_for_user')) { if (method_exists($obj, 'is_block_visible_for_user')) {
$is_block_visible_for_user = $obj->is_block_visible_for_user($user_id); $is_block_visible_for_user = $obj->is_block_visible_for_user($user_id);
if (!$is_block_visible_for_user) continue; if (!$is_block_visible_for_user) continue;
} }
$data_block[$path] = $obj->get_block(); $data_block[$path] = $obj->get_block();
// set user block column // set user block column
$data_block[$path]['column'] = $user_block_data[$block['id']]['column']; $data_block[$path]['column'] = $user_block_data[$block['id']]['column'];
} }
} }
$data['blocks'] = $data_block; $data['blocks'] = $data_block;
$data['dashboard_view'] = 'blocks'; $data['dashboard_view'] = 'blocks';
} }
if ($msg) { if ($msg) {
$data['msg'] = $msg; $data['msg'] = $msg;
} }
// render to the view // render to the view
$this->view->set_data($data); $this->view->set_data($data);
$this->view->set_layout('layout'); $this->view->set_layout('layout');
$this->view->set_template('dashboard'); $this->view->set_template('dashboard');
$this->view->render(); $this->view->render();
} }
/** /**
* This method allow store user blocks from dashboard manager * This method allow store user blocks from dashboard manager
* render to dashboard.php view * render to dashboard.php view
*/ */
public function store_user_block() { public function store_user_block() {
$data = array(); $data = array();
$user_id = $this->user_id; $user_id = $this->user_id;
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
$enabled_blocks = $_POST['enabled_blocks']; $enabled_blocks = $_POST['enabled_blocks'];
$columns = $_POST['columns']; $columns = $_POST['columns'];
$affected_rows = DashboardManager::store_user_blocks($user_id, $enabled_blocks, $columns); $affected_rows = DashboardManager::store_user_blocks($user_id, $enabled_blocks, $columns);
if ($affected_rows) { if ($affected_rows) {
$data['success'] = true; $data['success'] = true;
} }
} }
$data['dashboard_view'] = 'list'; $data['dashboard_view'] = 'list';
// render to the view // render to the view
$this->view->set_data($data); $this->view->set_data($data);
$this->view->set_layout('layout'); $this->view->set_layout('layout');
$this->view->set_template('dashboard'); $this->view->set_template('dashboard');
$this->view->render(); $this->view->render();
} }
/** /**
* This method is used when you close a block from dashboard block interface * This method is used when you close a block from dashboard block interface
* render to dashboard.php view * render to dashboard.php view
*/ */
public function close_user_block($path) { public function close_user_block($path) {
$user_id = $this->user_id; $user_id = $this->user_id;
$result = DashboardManager::close_user_block($user_id, $path); $result = DashboardManager::close_user_block($user_id, $path);
$this->display($result); $this->display($result);
} }
} }
?> ?>

@ -9,7 +9,6 @@
* Code * Code
*/ */
// required files // required files
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
/** /**
* DashboardManager can be used to manage dashboard * DashboardManager can be used to manage dashboard
* @package chamilo.dashboard * @package chamilo.dashboard
@ -30,7 +29,7 @@ class DashboardManager {
$dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH).'dashboard/'; $dashboard_pluginpath = api_get_path(SYS_PLUGIN_PATH).'dashboard/';
$possibleplugins = self::get_posible_dashboard_plugins_path(); $possibleplugins = self::get_posible_dashboard_plugins_path();
$table_cols = array('name', 'version', 'description'); $table_cols = array('name', 'version', 'description');
echo Display::page_subheader(get_lang('DashboardPlugins')); echo Display::page_subheader(get_lang('DashboardPlugins'));
echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">'; echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">';
echo '<table class="data_table">'; echo '<table class="data_table">';
@ -45,14 +44,14 @@ class DashboardManager {
// We display all the possible enabled or disabled plugins // We display all the possible enabled or disabled plugins
foreach ($possibleplugins as $testplugin) { foreach ($possibleplugins as $testplugin) {
$plugin_info_file = $dashboard_pluginpath.$testplugin."/$testplugin.info"; $plugin_info_file = $dashboard_pluginpath.$testplugin."/$testplugin.info";
$plugin_info = array(); $plugin_info = array();
if (file_exists($plugin_info_file) && is_readable($plugin_info_file)) { if (file_exists($plugin_info_file) && is_readable($plugin_info_file)) {
$plugin_info = parse_info_file($plugin_info_file); $plugin_info = parse_info_file($plugin_info_file);
// change index to lower case // change index to lower case
$plugin_info = array_change_key_case($plugin_info); $plugin_info = array_change_key_case($plugin_info);
echo '<tr>'; echo '<tr>';
self::display_dashboard_plugin_checkboxes($testplugin); self::display_dashboard_plugin_checkboxes($testplugin);
for ($i = 0 ; $i < count($table_cols); $i++) { for ($i = 0 ; $i < count($table_cols); $i++) {
@ -69,7 +68,7 @@ class DashboardManager {
echo Display::tag('tr', Display::tag('td', get_lang('CheckFilePermissions').' '.Security::remove_XSS($plugin_info_file) , array('colspan'=>'3'))); echo Display::tag('tr', Display::tag('td', get_lang('CheckFilePermissions').' '.Security::remove_XSS($plugin_info_file) , array('colspan'=>'3')));
} }
} }
// display all disabled block data // display all disabled block data
if (count($disabled_blocks_data) > 0) { if (count($disabled_blocks_data) > 0) {
foreach ($disabled_blocks_data as $disabled_block) { foreach ($disabled_blocks_data as $disabled_block) {
@ -94,7 +93,7 @@ class DashboardManager {
echo '</tr>'; echo '</tr>';
} }
} }
echo '</table>'; echo '</table>';
echo '<br />'; echo '<br />';
echo '<button class="save" type="submit" name="submit_dashboard_plugins" value="'.get_lang('EnableDashboardPlugins').'">'.get_lang('EnableDashboardPlugins').'</button></form>'; echo '<button class="save" type="submit" name="submit_dashboard_plugins" value="'.get_lang('EnableDashboardPlugins').'">'.get_lang('EnableDashboardPlugins').'</button></form>';
@ -139,11 +138,11 @@ class DashboardManager {
$possibleplugins = self::get_posible_dashboard_plugins_path(); $possibleplugins = self::get_posible_dashboard_plugins_path();
if (count($possibleplugins) > 0) { if (count($possibleplugins) > 0) {
$selected_plugins = array_intersect(array_keys($plugin_paths),$possibleplugins); $selected_plugins = array_intersect(array_keys($plugin_paths),$possibleplugins);
$not_selected_plugins = array_diff($possibleplugins,array_keys($plugin_paths)); $not_selected_plugins = array_diff($possibleplugins,array_keys($plugin_paths));
// get blocks id from not selected path // get blocks id from not selected path
$not_selected_blocks_id = array(); $not_selected_blocks_id = array();
foreach ($not_selected_plugins as $plugin) { foreach ($not_selected_plugins as $plugin) {
$block_data = self::get_enabled_dashboard_blocks($plugin); $block_data = self::get_enabled_dashboard_blocks($plugin);
@ -151,23 +150,23 @@ class DashboardManager {
$not_selected_blocks_id[] = $block_data[$plugin]['id']; $not_selected_blocks_id[] = $block_data[$plugin]['id'];
} }
} }
/* clean not selected plugins for extra user data and block data */ /* clean not selected plugins for extra user data and block data */
// clean from extra user data // clean from extra user data
$field_variable = 'dashboard'; $field_variable = 'dashboard';
$extra_user_data = UserManager::get_extra_user_data_by_field_variable($field_variable); $extra_user_data = UserManager::get_extra_user_data_by_field_variable($field_variable);
foreach ($extra_user_data as $key => $user_data) { foreach ($extra_user_data as $key => $user_data) {
$user_id = $key; $user_id = $key;
$user_block_data = self::get_user_block_data($user_id); $user_block_data = self::get_user_block_data($user_id);
$user_block_id = array_keys($user_block_data); $user_block_id = array_keys($user_block_data);
// clean disabled block data // clean disabled block data
foreach ($user_block_id as $block_id) { foreach ($user_block_id as $block_id) {
if (in_array($block_id, $not_selected_blocks_id)) { if (in_array($block_id, $not_selected_blocks_id)) {
unset($user_block_data[$block_id]); unset($user_block_data[$block_id]);
} }
} }
// get columns and blocks id for updating extra user data // get columns and blocks id for updating extra user data
$columns = array(); $columns = array();
$user_blocks_id = array(); $user_blocks_id = array();
@ -178,9 +177,9 @@ class DashboardManager {
// update extra user blocks data // update extra user blocks data
$upd_extra_field = self::store_user_blocks($user_id, $user_blocks_id, $columns); $upd_extra_field = self::store_user_blocks($user_id, $user_blocks_id, $columns);
} }
// clean from block data // clean from block data
if (!empty($not_selected_blocks_id)) { if (!empty($not_selected_blocks_id)) {
$sql_check = "SELECT id FROM $tbl_block WHERE id IN(".implode(',',$not_selected_blocks_id).")"; $sql_check = "SELECT id FROM $tbl_block WHERE id IN(".implode(',',$not_selected_blocks_id).")";
@ -191,11 +190,11 @@ class DashboardManager {
} }
} }
// store selected plugins // store selected plugins
foreach ($selected_plugins as $testplugin) { foreach ($selected_plugins as $testplugin) {
$selected_path = Database::escape_string($testplugin); $selected_path = Database::escape_string($testplugin);
// check if the path already stored inside block table for updating or adding it // check if the path already stored inside block table for updating or adding it
$sql = "SELECT path FROM $tbl_block WHERE path = '$selected_path'"; $sql = "SELECT path FROM $tbl_block WHERE path = '$selected_path'";
$rs = Database::query($sql); $rs = Database::query($sql);
@ -234,10 +233,10 @@ class DashboardManager {
Database::query($ins); Database::query($ins);
} }
$affected_rows = Database::affected_rows(); $affected_rows = Database::affected_rows();
} }
} }
return $affected_rows; return $affected_rows;
} }
@ -359,21 +358,21 @@ class DashboardManager {
// We display all enabled plugins and the checkboxes // We display all enabled plugins and the checkboxes
foreach ($enabled_dashboard_plugins as $block) { foreach ($enabled_dashboard_plugins as $block) {
$path = $block['path']; $path = $block['path'];
$controller_class = $block['controller']; $controller_class = $block['controller'];
$filename_controller = $path.'.class.php'; $filename_controller = $path.'.class.php';
$dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/'; $dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
require_once $dashboard_plugin_path.$filename_controller; require_once $dashboard_plugin_path.$filename_controller;
if (class_exists($controller_class)) { if (class_exists($controller_class)) {
$obj_block = new $controller_class($user_id); $obj_block = new $controller_class($user_id);
// check if user is allowed to see the block // check if user is allowed to see the block
if (method_exists($obj_block, 'is_block_visible_for_user')) { if (method_exists($obj_block, 'is_block_visible_for_user')) {
$is_block_visible_for_user = $obj_block->is_block_visible_for_user($user_id); $is_block_visible_for_user = $obj_block->is_block_visible_for_user($user_id);
if (!$is_block_visible_for_user) continue; if (!$is_block_visible_for_user) continue;
} }
echo '<tr>'; echo '<tr>';
// checkboxes // checkboxes
self::display_user_dashboard_list_checkboxes($user_id, $block['id']); self::display_user_dashboard_list_checkboxes($user_id, $block['id']);
@ -381,14 +380,14 @@ class DashboardManager {
echo '<td>'.$block['description'].'</td>'; echo '<td>'.$block['description'].'</td>';
echo '<td><center> echo '<td><center>
<select name="columns['.$block['id'].']"> <select name="columns['.$block['id'].']">
<option value="1" '.($user_block_data[$block['id']]['column']==1?'selected':'').' >1</option> <option value="1" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column']==1?'selected':'').' >1</option>
<option value="2" '.($user_block_data[$block['id']]['column']==2?'selected':'').' >2</option> <option value="2" '.(isset($user_block_data[$block['id']]) && $user_block_data[$block['id']]['column']==2?'selected':'').' >2</option>
</select></center> </select></center>
</td>'; </td>';
echo '</tr>'; echo '</tr>';
} else { } else {
echo Display::tag('tr', Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3'))); echo Display::tag('tr', Display::tag('td', get_lang('Error').' '.$controller_class, array('colspan'=>'3')));
} }
} }
echo '</table>'; echo '</table>';
@ -398,7 +397,7 @@ class DashboardManager {
} else { } else {
echo '<div style="margin-top:20px">'.get_lang('ThereAreNoEnabledDashboardPlugins').'</div>'; echo '<div style="margin-top:20px">'.get_lang('ThereAreNoEnabledDashboardPlugins').'</div>';
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'.get_lang('ConfigureDashboardPlugin').'</a>'; echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'.get_lang('ConfigureDashboardPlugin').'</a>';
} }
} }
} }
@ -464,13 +463,13 @@ class DashboardManager {
$data = array(); $data = array();
foreach ($extra_user_data as $extra) { foreach ($extra_user_data as $extra) {
$split_extra = explode(':',$extra); $split_extra = explode(':',$extra);
$block_id = $split_extra[0]; if (!empty($split_extra)) {
$column = $split_extra[1]; $block_id = $split_extra[0];
$data[$block_id] = array('block_id' => $block_id, 'column' => $column); $column = isset($split_extra[1]) ? $split_extra[1] : null;
$data[$block_id] = array('block_id' => $block_id, 'column' => $column);
}
} }
return $data; return $data;
} }
/** /**

@ -11,10 +11,10 @@
* Code * Code
*/ */
class SessionManager { class SessionManager {
private function __construct() { private function __construct() {
} }
/** /**
* Fetches a session from the database * Fetches a session from the database
* @param int Session ID * @param int Session ID
@ -28,7 +28,7 @@ class SessionManager {
if (Database::num_rows($r) != 1) { return array(); } if (Database::num_rows($r) != 1) { return array(); }
return Database::fetch_array($r,'ASSOC'); return Database::fetch_array($r,'ASSOC');
} }
/** /**
* Create a session * Create a session
* @author Carlos Vargas from existing code * @author Carlos Vargas from existing code
@ -50,9 +50,9 @@ class SessionManager {
* @todo use an array to replace all this parameters or use the model.lib.php ... * @todo use an array to replace all this parameters or use the model.lib.php ...
* @return mixed Session ID on success, error message otherwise * @return mixed Session ID on success, error message otherwise
**/ **/
public static function create_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after, $nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit = true, $end_limit = true, $fix_name = false) { public static function create_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after, $nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit = true, $end_limit = true, $fix_name = false) {
global $_configuration; global $_configuration;
//Check portal limits //Check portal limits
$access_url_id = 1; $access_url_id = 1;
if (api_get_multiple_access_url()) { if (api_get_multiple_access_url()) {
@ -77,8 +77,8 @@ class SessionManager {
$id_session_category = intval($id_session_category); $id_session_category = intval($id_session_category);
$id_visibility = intval($id_visibility); $id_visibility = intval($id_visibility);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
if (is_int($coach_username)) { if (is_int($coach_username)) {
$id_coach = $coach_username; $id_coach = $coach_username;
} else { } else {
@ -95,16 +95,16 @@ class SessionManager {
$date_start ="0000-00-00"; $date_start ="0000-00-00";
$date_end ="0000-00-00"; $date_end ="0000-00-00";
} }
if (empty($end_limit)) { if (empty($end_limit)) {
$date_end ="0000-00-00"; $date_end ="0000-00-00";
$id_visibility = 1; // by default session visibility is read only $id_visibility = 1; // by default session visibility is read only
} }
if (empty($start_limit)) { if (empty($start_limit)) {
$date_start ="0000-00-00"; $date_start ="0000-00-00";
} }
if (empty($name)) { if (empty($name)) {
$msg=get_lang('SessionNameIsRequired'); $msg=get_lang('SessionNameIsRequired');
return $msg; return $msg;
@ -123,44 +123,44 @@ class SessionManager {
} else { } else {
$ready_to_create = false; $ready_to_create = false;
if ($fix_name) { if ($fix_name) {
$name = self::generate_nice_next_session_name($name); $name = self::generate_nice_next_session_name($name);
if ($name) { if ($name) {
$ready_to_create = true; $ready_to_create = true;
} else { } else {
$msg=get_lang('SessionNameAlreadyExists'); $msg=get_lang('SessionNameAlreadyExists');
return $msg; return $msg;
} }
} else { } else {
$rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".$name."'"); $rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".$name."'");
if (Database::num_rows($rs)) { if (Database::num_rows($rs)) {
$msg=get_lang('SessionNameAlreadyExists'); $msg=get_lang('SessionNameAlreadyExists');
return $msg; return $msg;
} }
$ready_to_create = true; $ready_to_create = true;
} }
if ($ready_to_create) { if ($ready_to_create) {
$sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility) $sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility)
VALUES('".$name."','$date_start','$date_end','$id_coach',".api_get_user_id().",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")"; VALUES('".$name."','$date_start','$date_end','$id_coach',".api_get_user_id().",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")";
Database::query($sql_insert); Database::query($sql_insert);
$session_id = Database::insert_id(); $session_id = Database::insert_id();
if (!empty($session_id)) { if (!empty($session_id)) {
/* /*
Sends a message to the user_id = 1 Sends a message to the user_id = 1
$user_info = api_get_user_info(1); $user_info = api_get_user_info(1);
$complete_name = $user_info['firstname'].' '.$user_info['lastname']; $complete_name = $user_info['firstname'].' '.$user_info['lastname'];
$subject = api_get_setting('siteName').' - '.get_lang('ANewSessionWasCreated'); $subject = api_get_setting('siteName').' - '.get_lang('ANewSessionWasCreated');
$message = get_lang('ANewSessionWasCreated')." <br /> ".get_lang('NameOfTheSession').' : '.$name; $message = get_lang('ANewSessionWasCreated')." <br /> ".get_lang('NameOfTheSession').' : '.$name;
api_mail_html($complete_name, $user_info['email'], $subject, $message); api_mail_html($complete_name, $user_info['email'], $subject, $message);
* *
*/ */
//Adding to the correct URL //Adding to the correct URL
$access_url_id = api_get_current_access_url_id(); $access_url_id = api_get_current_access_url_id();
UrlManager::add_session_to_url($session_id,$access_url_id); UrlManager::add_session_to_url($session_id,$access_url_id);
// add event to system log // add event to system log
$user_id = api_get_user_id(); $user_id = api_get_user_id();
event_system(LOG_SESSION_CREATE, LOG_SESSION_ID, $session_id, api_get_utc_datetime(), $user_id); event_system(LOG_SESSION_CREATE, LOG_SESSION_ID, $session_id, api_get_utc_datetime(), $user_id);
} }
@ -168,38 +168,38 @@ class SessionManager {
} }
} }
} }
function session_name_exists($session_name) { function session_name_exists($session_name) {
$session_name = Database::escape_string($session_name); $session_name = Database::escape_string($session_name);
$result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' ")); $result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' "));
return $result['count'] > 0; return $result['count'] > 0;
} }
static function get_count_admin() { static function get_count_admin() {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$where = 'WHERE 1=1 '; $where = 'WHERE 1=1 ';
$user_id = api_get_user_id(); $user_id = api_get_user_id();
if (api_is_session_admin() && api_get_setting('allow_session_admins_to_see_all_sessions') == 'false') { if (api_is_session_admin() && api_get_setting('allow_session_admins_to_see_all_sessions') == 'false') {
$where.=" WHERE s.session_admin_id = $user_id "; $where.=" WHERE s.session_admin_id = $user_id ";
} }
$query_rows = "SELECT count(*) as total_rows $query_rows = "SELECT count(*) as total_rows
FROM $tbl_session s FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id INNER JOIN $tbl_user u ON s.id_coach = u.user_id
$where "; $where ";
global $_configuration; global $_configuration;
if ($_configuration['multiple_access_urls']) { if ($_configuration['multiple_access_urls']) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id(); $access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) { if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id "; $where.= " AND ar.access_url_id = $access_url_id ";
$query_rows = "SELECT count(*) as total_rows $query_rows = "SELECT count(*) as total_rows
FROM $tbl_session s FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
@ -211,64 +211,64 @@ class SessionManager {
$result_rows = Database::query($query_rows); $result_rows = Database::query($query_rows);
$recorset = Database::fetch_array($result_rows); $recorset = Database::fetch_array($result_rows);
$num = $recorset['total_rows']; $num = $recorset['total_rows'];
return $num; return $num;
} }
/** /**
* Gets the admin session list callback of the admin/session_list.php page * Gets the admin session list callback of the admin/session_list.php page
* @param array order and limit keys * @param array order and limit keys
*/ */
public static function get_sessions_admin($options) { public static function get_sessions_admin($options) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$where = 'WHERE 1=1 '; $where = 'WHERE 1=1 ';
$user_id = api_get_user_id(); $user_id = api_get_user_id();
if (api_is_session_admin() && api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false') { if (api_is_session_admin() && api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false') {
$where.=" AND s.session_admin_id = $user_id "; $where.=" AND s.session_admin_id = $user_id ";
} }
$coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name "; $coach_name = " CONCAT (u.lastname , ' ', u.firstname) as coach_name ";
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name "; $coach_name = " CONCAT (u.firstname, ' ', u.lastname) as coach_name ";
} }
$today = api_get_utc_datetime(); $today = api_get_utc_datetime();
$today = api_strtotime($today, 'UTC'); $today = api_strtotime($today, 'UTC');
$today = date('Y-m-d', $today); $today = date('Y-m-d', $today);
$select = "SELECT * FROM (SELECT $select = "SELECT * FROM (SELECT
IF ( IF (
(s.date_start <= '$today' AND '$today' < s.date_end) OR (s.date_start <= '$today' AND '$today' < s.date_end) OR
(s.date_start = '0000-00-00' AND s.date_end = '0000-00-00' ) OR (s.date_start = '0000-00-00' AND s.date_end = '0000-00-00' ) OR
(s.date_start <= '$today' AND '0000-00-00' = s.date_end) OR (s.date_start <= '$today' AND '0000-00-00' = s.date_end) OR
('$today' < s.date_end AND '0000-00-00' = s.date_start) ('$today' < s.date_end AND '0000-00-00' = s.date_start)
, 1, 0) , 1, 0)
as session_active, as session_active,
s.name, s.name,
nbr_courses, nbr_courses,
nbr_users, nbr_users,
s.date_start, s.date_start,
s.date_end, s.date_end,
$coach_name, $coach_name,
sc.name as category_name, sc.name as category_name,
s.visibility, s.visibility,
u.user_id, u.user_id,
s.id"; s.id";
$limit = null; $limit = null;
if (!empty($options['limit'])) { if (!empty($options['limit'])) {
$limit = " LIMIT ".$options['limit']; $limit = " LIMIT ".$options['limit'];
} }
$query = "$select FROM $tbl_session s $query = "$select FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id INNER JOIN $tbl_user u ON s.id_coach = u.user_id
$where $limit"; $where $limit";
global $_configuration; global $_configuration;
if ($_configuration['multiple_access_urls']) { if ($_configuration['multiple_access_urls']) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
@ -283,18 +283,18 @@ class SessionManager {
$where $limit"; $where $limit";
} }
} }
$query .= ") AS session_table"; $query .= ") AS session_table";
if (!empty($options['where'])) { if (!empty($options['where'])) {
$query .= ' WHERE '.$options['where']; $query .= ' WHERE '.$options['where'];
} }
if (!empty($options['order'])) { if (!empty($options['order'])) {
$query .= " ORDER BY ".$options['order']; $query .= " ORDER BY ".$options['order'];
} }
//var_dump($query); //var_dump($query);
$result = Database::query($query); $result = Database::query($query);
$formatted_sessions = array(); $formatted_sessions = array();
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -320,7 +320,7 @@ class SessionManager {
if ($session['date_end'] == '0000-00-00') { if ($session['date_end'] == '0000-00-00') {
$session['date_end'] = ''; $session['date_end'] = '';
} }
switch ($session['visibility']) { switch ($session['visibility']) {
case SESSION_VISIBLE_READ_ONLY: //1 case SESSION_VISIBLE_READ_ONLY: //1
$session['visibility'] = get_lang('ReadOnly'); $session['visibility'] = get_lang('ReadOnly');
@ -335,13 +335,13 @@ class SessionManager {
$formatted_sessions[] = $session; $formatted_sessions[] = $session;
} }
} }
return $formatted_sessions; return $formatted_sessions;
} }
/** /**
* Creates a new course code based in given code * Creates a new course code based in given code
* *
* @param string wanted code * @param string wanted code
* <code> * <code>
* $wanted_code = 'curse' if there are in the DB codes like curse1 curse2 the function will return: course3 * $wanted_code = 'curse' if there are in the DB codes like curse1 curse2 the function will return: course3
@ -349,12 +349,12 @@ class SessionManager {
* </code> * </code>
* @return string wanted unused code * @return string wanted unused code
*/ */
function generate_nice_next_session_name($session_name) { function generate_nice_next_session_name($session_name) {
$session_name_ok = !self::session_name_exists($session_name); $session_name_ok = !self::session_name_exists($session_name);
if (!$session_name_ok) { if (!$session_name_ok) {
$table = Database::get_main_table(TABLE_MAIN_SESSION); $table = Database::get_main_table(TABLE_MAIN_SESSION);
$session_name = Database::escape_string($session_name); $session_name = Database::escape_string($session_name);
$sql = "SELECT count(*) as count FROM $table WHERE name LIKE '$session_name%'"; $sql = "SELECT count(*) as count FROM $table WHERE name LIKE '$session_name%'";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0 ) { if (Database::num_rows($result) > 0 ) {
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
@ -363,13 +363,13 @@ class SessionManager {
$result = self::session_name_exists($session_name); $result = self::session_name_exists($session_name);
if (!$result) { if (!$result) {
return $session_name; return $session_name;
} }
} }
return false; return false;
} }
return $session_name; return $session_name;
} }
/** /**
* Edit a session * Edit a session
* @author Carlos Vargas from existing code * @author Carlos Vargas from existing code
@ -407,7 +407,7 @@ class SessionManager {
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
if (empty($nolimit)) { if (empty($nolimit)) {
$date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start); $date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
$date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end); $date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
@ -416,20 +416,20 @@ class SessionManager {
$date_end = "0000-00-00"; $date_end = "0000-00-00";
$id_visibility = 1;//force read only $id_visibility = 1;//force read only
} }
if (!empty($no_end_limit)) { if (!empty($no_end_limit)) {
$date_end = "0000-00-00"; $date_end = "0000-00-00";
} }
if (empty($end_limit)) { if (empty($end_limit)) {
$date_end ="0000-00-00"; $date_end ="0000-00-00";
$id_visibility = 1;//force read only $id_visibility = 1;//force read only
} }
if (empty($start_limit)) { if (empty($start_limit)) {
$date_start ="0000-00-00"; $date_start ="0000-00-00";
} }
if (empty($name)) { if (empty($name)) {
$msg=get_lang('SessionNameIsRequired'); $msg=get_lang('SessionNameIsRequired');
return $msg; return $msg;
@ -483,9 +483,9 @@ class SessionManager {
$tbl_session= Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session= Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_course= Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_rel_course_rel_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_course_rel_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session_rel_user= Database::get_main_table(TABLE_MAIN_SESSION_USER); $tbl_session_rel_user= Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_url_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $tbl_url_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
global $_user; global $_user;
if(is_array($id_checked)) { if(is_array($id_checked)) {
$id_checked = Database::escape_string(implode(',',$id_checked)); $id_checked = Database::escape_string(implode(',',$id_checked));
@ -567,7 +567,7 @@ class SessionManager {
} }
} }
*/ */
// Add event to system log // Add event to system log
$user_id = api_get_user_id(); $user_id = api_get_user_id();
event_system(LOG_SESSION_DELETE, LOG_SESSION_ID, $id_checked, api_get_utc_datetime(), $user_id); event_system(LOG_SESSION_DELETE, LOG_SESSION_ID, $id_checked, api_get_utc_datetime(), $user_id);
} }
@ -594,7 +594,7 @@ class SessionManager {
$session_info = api_get_session_info($id_session); $session_info = api_get_session_info($id_session);
$session_name = $session_info['name']; $session_name = $session_info['name'];
//from function parameter //from function parameter
if (empty($session_visibility)) { if (empty($session_visibility)) {
$session_visibility = $session_info['visibility']; //loaded from DB $session_visibility = $session_info['visibility']; //loaded from DB
//default status loaded if empty //default status loaded if empty
@ -606,36 +606,36 @@ class SessionManager {
} }
} }
$sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user WHERE id_session = '$id_session' AND status = 0"; $sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user WHERE id_session = '$id_session' AND status = 0";
$result = Database::query($sql); $result = Database::query($sql);
$existingUsers = array(); $existingUsers = array();
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$existingUsers[] = $row['id_user']; $existingUsers[] = $row['id_user'];
} }
$sql = "SELECT course_code FROM $tbl_session_rel_course WHERE id_session = '$id_session'"; $sql = "SELECT course_code FROM $tbl_session_rel_course WHERE id_session = '$id_session'";
$result = Database::query($sql); $result = Database::query($sql);
$course_list = array(); $course_list = array();
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$course_list[] = $row['course_code']; $course_list[] = $row['course_code'];
} }
if ($send_email) { if ($send_email) {
//global $_configuration; //global $_configuration;
//sending emails only //sending emails only
if (is_array($user_list) && count($user_list)>0) { if (is_array($user_list) && count($user_list)>0) {
foreach ($user_list as $user_id) { foreach ($user_list as $user_id) {
if (!in_array($user_id, $existingUsers)) { if (!in_array($user_id, $existingUsers)) {
$subject = '['.get_setting('siteName').'] '.get_lang('YourReg').' '.get_setting('siteName'); $subject = '['.get_setting('siteName').'] '.get_lang('YourReg').' '.get_setting('siteName');
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$content = get_lang('Dear')." ".stripslashes($user_info['complete_name']).",\n\n".sprintf(get_lang('YouAreRegisterToSessionX'), $session_name) ." \n\n" .get_lang('Address') ." ". get_setting('siteName') ." ". get_lang('Is') ." : ". api_get_path(WEB_PATH) ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".get_setting('administratorName')." ".get_setting('administratorSurname')."\n". get_lang('Manager'). " ".get_setting('siteName')."\nT. ".get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".get_setting('emailAdministrator'); $content = get_lang('Dear')." ".stripslashes($user_info['complete_name']).",\n\n".sprintf(get_lang('YouAreRegisterToSessionX'), $session_name) ." \n\n" .get_lang('Address') ." ". get_setting('siteName') ." ". get_lang('Is') ." : ". api_get_path(WEB_PATH) ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".get_setting('administratorName')." ".get_setting('administratorSurname')."\n". get_lang('Manager'). " ".get_setting('siteName')."\nT. ".get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".get_setting('emailAdministrator');
MessageManager::send_message($user_id, $subject, $content, array(), array(), null, null, null, null, null); MessageManager::send_message($user_id, $subject, $content, array(), array(), null, null, null, null, null);
/*$emailheaders = 'From: '.get_setting('administratorName').' '.get_setting('administratorSurname').' <'.get_setting('emailAdministrator').">\n"; /*$emailheaders = 'From: '.get_setting('administratorName').' '.get_setting('administratorSurname').' <'.get_setting('emailAdministrator').">\n";
$emailheaders .= 'Reply-To: '.get_setting('emailAdministrator'); $emailheaders .= 'Reply-To: '.get_setting('emailAdministrator');
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".sprintf(get_lang('YouAreRegisterToSessionX'), $session_name) ." \n\n" .get_lang('Address') ." ". get_setting('siteName') ." ". get_lang('Is') ." : ". api_get_path(WEB_PATH) ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".get_setting('administratorName')." ".get_setting('administratorSurname')."\n". get_lang('Manager'). " ".get_setting('siteName')."\nT. ".get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".get_setting('emailAdministrator'); $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".sprintf(get_lang('YouAreRegisterToSessionX'), $session_name) ." \n\n" .get_lang('Address') ." ". get_setting('siteName') ." ". get_lang('Is') ." : ". api_get_path(WEB_PATH) ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".get_setting('administratorName')." ".get_setting('administratorSurname')."\n". get_lang('Manager'). " ".get_setting('siteName')."\nT. ".get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".get_setting('emailAdministrator');
@api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);*/ @api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);*/
} }
} }
@ -658,7 +658,7 @@ class SessionManager {
} }
} }
} }
//Replace with this new function //Replace with this new function
// //
// insert new users into session_rel_course_rel_user and ignore if they already exist // insert new users into session_rel_course_rel_user and ignore if they already exist
@ -685,9 +685,9 @@ class SessionManager {
if ($empty_users===true) { if ($empty_users===true) {
Database::query("DELETE FROM $tbl_session_rel_user WHERE id_session = $id_session AND relation_type<>".SESSION_RELATION_TYPE_RRHH.""); Database::query("DELETE FROM $tbl_session_rel_user WHERE id_session = $id_session AND relation_type<>".SESSION_RELATION_TYPE_RRHH."");
} }
// Insert missing users into session // Insert missing users into session
$nbr_users = 0; $nbr_users = 0;
foreach ($user_list as $enreg_user) { foreach ($user_list as $enreg_user) {
$enreg_user = Database::escape_string($enreg_user); $enreg_user = Database::escape_string($enreg_user);
$nbr_users++; $nbr_users++;
@ -696,34 +696,34 @@ class SessionManager {
} }
// update number of users in the session // update number of users in the session
$nbr_users = count($user_list); $nbr_users = count($user_list);
if ($empty_users) { if ($empty_users) {
// update number of users in the session // update number of users in the session
$update_sql = "UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' "; $update_sql = "UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' ";
Database::query($update_sql); Database::query($update_sql);
} else { } else {
$update_sql = "UPDATE $tbl_session SET nbr_users= nbr_users + $nbr_users WHERE id='$id_session' "; $update_sql = "UPDATE $tbl_session SET nbr_users= nbr_users + $nbr_users WHERE id='$id_session' ";
Database::query($update_sql); Database::query($update_sql);
} }
} }
function subscribe_users_to_session_course($user_list, $session_id, $course_code, $session_visibility = SESSION_VISIBLE_READ_ONLY ) { function subscribe_users_to_session_course($user_list, $session_id, $course_code, $session_visibility = SESSION_VISIBLE_READ_ONLY ) {
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
if (empty($user_list) || empty($session_id) || empty($course_code)) { if (empty($user_list) || empty($session_id) || empty($course_code)) {
return false; return false;
} }
$session_id = intval($session_id); $session_id = intval($session_id);
$course_code = Database::escape_string($course_code); $course_code = Database::escape_string($course_code);
$session_visibility = intval($session_visibility); $session_visibility = intval($session_visibility);
$nbr_users = 0; $nbr_users = 0;
foreach ($user_list as $enreg_user) { foreach ($user_list as $enreg_user) {
//if (!in_array($enreg_user, $existingUsers)) { //if (!in_array($enreg_user, $existingUsers)) {
$enreg_user = intval($enreg_user); $enreg_user = intval($enreg_user);
$insert_sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user,visibility) $insert_sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user,visibility)
VALUES ('$session_id','$course_code','$enreg_user','$session_visibility')"; VALUES ('$session_id','$course_code','$enreg_user','$session_visibility')";
Database::query($insert_sql); Database::query($insert_sql);
if (Database::affected_rows()) { if (Database::affected_rows()) {
@ -1107,7 +1107,7 @@ class SessionManager {
VALUES('".Database::escape_string($name)."','$date_start','$date_end', '$access_url_id')"; VALUES('".Database::escape_string($name)."','$date_start','$date_end', '$access_url_id')";
Database::query($sql); Database::query($sql);
$id_session = Database::insert_id(); $id_session = Database::insert_id();
// Add event to system log // Add event to system log
$user_id = api_get_user_id(); $user_id = api_get_user_id();
event_system(LOG_SESSION_CATEGORY_CREATE, LOG_SESSION_CATEGORY_ID, $id_session, api_get_utc_datetime(), $user_id); event_system(LOG_SESSION_CATEGORY_CREATE, LOG_SESSION_CATEGORY_ID, $id_session, api_get_utc_datetime(), $user_id);
return $id_session; return $id_session;
@ -1184,11 +1184,11 @@ class SessionManager {
} else { } else {
$id_checked = intval($id_checked); $id_checked = intval($id_checked);
} }
//Setting session_category_id to 0 //Setting session_category_id to 0
$sql = "UPDATE $tbl_session SET session_category_id = 0 WHERE session_category_id IN (".$id_checked.")"; $sql = "UPDATE $tbl_session SET session_category_id = 0 WHERE session_category_id IN (".$id_checked.")";
Database::query($sql); Database::query($sql);
$sql = "SELECT id FROM $tbl_session WHERE session_category_id IN (".$id_checked.")"; $sql = "SELECT id FROM $tbl_session WHERE session_category_id IN (".$id_checked.")";
$result = @Database::query($sql); $result = @Database::query($sql);
while ($rows = Database::fetch_array($result)) { while ($rows = Database::fetch_array($result)) {
@ -1205,9 +1205,9 @@ class SessionManager {
$rs = @Database::query($sql); $rs = @Database::query($sql);
$result = Database::affected_rows(); $result = Database::affected_rows();
// Add event to system log // Add event to system log
$user_id = api_get_user_id(); $user_id = api_get_user_id();
event_system(LOG_SESSION_CATEGORY_DELETE, LOG_SESSION_CATEGORY_ID, $id_checked, api_get_utc_datetime(), $user_id); event_system(LOG_SESSION_CATEGORY_DELETE, LOG_SESSION_CATEGORY_ID, $id_checked, api_get_utc_datetime(), $user_id);
@ -1250,9 +1250,9 @@ class SessionManager {
$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$user_table = Database::get_main_table(TABLE_MAIN_USER); $user_table = Database::get_main_table(TABLE_MAIN_USER);
$table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id(); $access_url_id = api_get_current_access_url_id();
$return_array = array(); $return_array = array();
$sql_query = " SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname, sc.name as category_name, s.promotion_id $sql_query = " SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname, sc.name as category_name, s.promotion_id
@ -1261,7 +1261,7 @@ class SessionManager {
INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
LEFT JOIN $session_category_table sc ON s.session_category_id = sc.id LEFT JOIN $session_category_table sc ON s.session_category_id = sc.id
WHERE ar.access_url_id = $access_url_id "; WHERE ar.access_url_id = $access_url_id ";
if (count($conditions)>0) { if (count($conditions)>0) {
$sql_query .= ' AND '; $sql_query .= ' AND ';
foreach ($conditions as $field=>$value) { foreach ($conditions as $field=>$value) {
@ -1282,7 +1282,7 @@ class SessionManager {
} }
return $return_array; return $return_array;
} }
/** /**
* Get the session category information by id * Get the session category information by id
* @param string session category ID * @param string session category ID
@ -1300,16 +1300,16 @@ class SessionManager {
return false; return false;
} }
} }
/** /**
* Get all session categories (filter by access_url_id) * Get all session categories (filter by access_url_id)
* @return mixed false if the session category does not exist, array if the session category exists * @return mixed false if the session category does not exist, array if the session category exists
*/ */
public static function get_all_session_category() { public static function get_all_session_category() {
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$id = api_get_current_access_url_id(); $id = api_get_current_access_url_id();
$sql = 'SELECT * FROM '.$tbl_session_category.' WHERE access_url_id ="'.$id.'" ORDER BY name ASC'; $sql = 'SELECT * FROM '.$tbl_session_category.' WHERE access_url_id ="'.$id.'" ORDER BY name ASC';
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0 ){ if (Database::num_rows($result) > 0 ){
$data = Database::store_result($result,'ASSOC'); $data = Database::store_result($result,'ASSOC');
return $data; return $data;
@ -1410,19 +1410,19 @@ class SessionManager {
// Database Table Definitions // Database Table Definitions
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$hr_manager_id = intval($hr_manager_id); $hr_manager_id = intval($hr_manager_id);
$affected_rows = 0; $affected_rows = 0;
//Deleting assigned sessions to hrm_id //Deleting assigned sessions to hrm_id
if ($_configuration['multiple_access_urls']) { if ($_configuration['multiple_access_urls']) {
$sql = "SELECT id_session FROM $tbl_session_rel_user s INNER JOIN $tbl_session_rel_access_url a ON (a.session_id = s.id_session) WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH." AND access_url_id = ".api_get_current_access_url_id().""; $sql = "SELECT id_session FROM $tbl_session_rel_user s INNER JOIN $tbl_session_rel_access_url a ON (a.session_id = s.id_session) WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH." AND access_url_id = ".api_get_current_access_url_id()."";
} else { } else {
$sql = "SELECT id_session FROM $tbl_session_rel_user s WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH.""; $sql = "SELECT id_session FROM $tbl_session_rel_user s WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH."";
} }
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
@ -1469,12 +1469,12 @@ class SessionManager {
$hr_manager_id = intval($hr_manager_id); $hr_manager_id = intval($hr_manager_id);
$assigned_sessions_to_hrm = array(); $assigned_sessions_to_hrm = array();
if ($_configuration['multiple_access_urls']) { if (api_is_multiple_url_enabled()) {
$sql = "SELECT * FROM $tbl_session s INNER JOIN $tbl_session_rel_user sru ON (sru.id_session = s.id) LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id) $sql = "SELECT * FROM $tbl_session s INNER JOIN $tbl_session_rel_user sru ON (sru.id_session = s.id) LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
WHERE sru.id_user = '$hr_manager_id' AND sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' AND access_url_id = ".api_get_current_access_url_id().""; WHERE sru.id_user = '$hr_manager_id' AND sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' AND access_url_id = ".api_get_current_access_url_id()."";
} else { } else {
$sql = "SELECT * FROM $tbl_session s $sql = "SELECT * FROM $tbl_session s
INNER JOIN $tbl_session_rel_user sru ON sru.id_session = s.id AND sru.id_user = '$hr_manager_id' AND sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' "; INNER JOIN $tbl_session_rel_user sru ON sru.id_session = s.id AND sru.id_user = '$hr_manager_id' AND sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' ";
} }
$rs_assigned_sessions = Database::query($sql); $rs_assigned_sessions = Database::query($sql);
if (Database::num_rows($rs_assigned_sessions) > 0) { if (Database::num_rows($rs_assigned_sessions) > 0) {
@ -1483,7 +1483,7 @@ class SessionManager {
} }
} }
return $assigned_sessions_to_hrm; return $assigned_sessions_to_hrm;
} }
/** /**
* Gets the list of courses by session filtered by access_url * Gets the list of courses by session filtered by access_url
@ -1493,9 +1493,9 @@ class SessionManager {
public static function get_course_list_by_session_id ($session_id) { public static function get_course_list_by_session_id ($session_id) {
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
// select the courses // select the courses
$sql = "SELECT * FROM $tbl_course c INNER JOIN $tbl_session_rel_course src ON c.code = src.course_code $sql = "SELECT * FROM $tbl_course c INNER JOIN $tbl_session_rel_course src ON c.code = src.course_code
WHERE src.id_session = '$session_id' ORDER BY title;"; WHERE src.id_session = '$session_id' ORDER BY title;";
$result = Database::query($sql); $result = Database::query($sql);
$num_rows = Database::num_rows($result); $num_rows = Database::num_rows($result);
@ -1527,11 +1527,11 @@ class SessionManager {
return 0; return 0;
} }
} }
/** /**
* Get users by session * Get users by session
* @param int session id * @param int session id
* @param int filter by status * @param int filter by status
* @return array a list with an user list * @return array a list with an user list
*/ */
public static function get_users_by_session($id, $with_status = null) { public static function get_users_by_session($id, $with_status = null) {
@ -1544,36 +1544,36 @@ class SessionManager {
$sql = "SELECT $tbl_user.user_id, lastname, firstname, username $sql = "SELECT $tbl_user.user_id, lastname, firstname, username
FROM $tbl_user INNER JOIN $tbl_session_rel_user FROM $tbl_user INNER JOIN $tbl_session_rel_user
ON $tbl_user.user_id = $tbl_session_rel_user.id_user ON $tbl_user.user_id = $tbl_session_rel_user.id_user
AND $tbl_session_rel_user.id_session = $id"; AND $tbl_session_rel_user.id_session = $id";
if (isset($with_status) && $with_status != '') { if (isset($with_status) && $with_status != '') {
$with_status = intval($with_status); $with_status = intval($with_status);
$sql .= " WHERE relation_type = $with_status "; $sql .= " WHERE relation_type = $with_status ";
} }
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result,'ASSOC')) { while ($row = Database::fetch_array($result,'ASSOC')) {
$return_array[] = $row; $return_array[] = $row;
} }
return $return_array; return $return_array;
} }
public static function get_sessions_by_coach($user_id) { public static function get_sessions_by_coach($user_id) {
$session_table = Database::get_main_table(TABLE_MAIN_SESSION); $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
return Database::select('*', $session_table, array('where'=>array('id_coach = ?'=>$user_id))); return Database::select('*', $session_table, array('where'=>array('id_coach = ?'=>$user_id)));
} }
public static function get_user_status_in_course_session($user_id, $course_code, $session_id) { public static function get_user_status_in_course_session($user_id, $course_code, $session_id) {
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT session_rcru.status $sql = "SELECT session_rcru.status
FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
WHERE session_rcru.id_user = user.user_id AND WHERE session_rcru.id_user = user.user_id AND
session_rcru.id_session = '".intval($session_id)."' AND session_rcru.id_session = '".intval($session_id)."' AND
session_rcru.course_code ='".Database::escape_string($course_code)."' AND session_rcru.course_code ='".Database::escape_string($course_code)."' AND
user.user_id = ".intval($user_id); user.user_id = ".intval($user_id);
$result = Database::query($sql); $result = Database::query($sql);
$status = false; $status = false;
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -1582,9 +1582,9 @@ class SessionManager {
} }
return $status; return $status;
} }
/** /**
* Gets user status within a session * Gets user status within a session
* @param $user_id * @param $user_id
* @param $course_code * @param $course_code
* @param $session_id * @param $session_id
@ -1592,13 +1592,13 @@ class SessionManager {
*/ */
public static function get_user_status_in_session($user_id, $course_code, $session_id) { public static function get_user_status_in_session($user_id, $course_code, $session_id) {
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT session_rcru.status $sql = "SELECT session_rcru.status
FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
WHERE session_rcru.id_user = user.user_id AND WHERE session_rcru.id_user = user.user_id AND
session_rcru.id_session = '".intval($session_id)."' AND session_rcru.id_session = '".intval($session_id)."' AND
session_rcru.course_code ='".Database::escape_string($course_code)."' AND session_rcru.course_code ='".Database::escape_string($course_code)."' AND
user.user_id = ".intval($user_id); user.user_id = ".intval($user_id);
$result = Database::query($sql); $result = Database::query($sql);
$status = false; $status = false;
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -1607,27 +1607,27 @@ class SessionManager {
} }
return $status; return $status;
} }
function get_all_sessions_by_promotion($id) { function get_all_sessions_by_promotion($id) {
$t = Database::get_main_table(TABLE_MAIN_SESSION); $t = Database::get_main_table(TABLE_MAIN_SESSION);
return Database::select('*', $t, array('where'=>array('promotion_id = ?'=>$id))); return Database::select('*', $t, array('where'=>array('promotion_id = ?'=>$id)));
} }
function suscribe_sessions_to_promotion($promotion_id, $list) { function suscribe_sessions_to_promotion($promotion_id, $list) {
$t = Database::get_main_table(TABLE_MAIN_SESSION); $t = Database::get_main_table(TABLE_MAIN_SESSION);
$params = array(); $params = array();
$params['promotion_id'] = 0; $params['promotion_id'] = 0;
Database::update($t, $params, array('promotion_id = ?'=>$promotion_id)); Database::update($t, $params, array('promotion_id = ?'=>$promotion_id));
$params['promotion_id'] = $promotion_id; $params['promotion_id'] = $promotion_id;
if (!empty($list)) { if (!empty($list)) {
foreach ($list as $session_id) { foreach ($list as $session_id) {
$session_id= intval($session_id); $session_id= intval($session_id);
Database::update($t, $params, array('id = ?'=>$session_id)); Database::update($t, $params, array('id = ?'=>$session_id));
} }
} }
} }
/** /**
* Updates a session status * Updates a session status
* @param int session id * @param int session id
@ -1638,9 +1638,9 @@ class SessionManager {
$params['visibility'] = $status; $params['visibility'] = $status;
Database::update($t, $params, array('id = ?'=>$session_id)); Database::update($t, $params, array('id = ?'=>$session_id));
} }
/** /**
* Copies a session with the same data to a new session. * Copies a session with the same data to a new session.
* The new copy is not assigned to the same promotion. @see suscribe_sessions_to_promotions() for that * The new copy is not assigned to the same promotion. @see suscribe_sessions_to_promotions() for that
* @param int Session ID * @param int Session ID
* @param bool Whether to copy the relationship with courses * @param bool Whether to copy the relationship with courses
@ -1665,7 +1665,7 @@ class SessionManager {
$s['day_start'] = substr($s['date_start'],8,2); $s['day_start'] = substr($s['date_start'],8,2);
$s['year_end'] = substr($s['date_end'],0,4); $s['year_end'] = substr($s['date_end'],0,4);
$s['month_end'] = substr($s['date_end'],5,2); $s['month_end'] = substr($s['date_end'],5,2);
$s['day_end'] = substr($s['date_end'],8,2); $s['day_end'] = substr($s['date_end'],8,2);
$consider_start = true; $consider_start = true;
if ($s['year_start'].'-'.$s['month_start'].'-'.$s['day_start'] == '0000-00-00') { if ($s['year_start'].'-'.$s['month_start'].'-'.$s['day_start'] == '0000-00-00') {
$consider_start = false; $consider_start = false;
@ -1674,22 +1674,22 @@ class SessionManager {
if ($s['year_end'].'-'.$s['month_end'].'-'.$s['day_end'] == '0000-00-00') { if ($s['year_end'].'-'.$s['month_end'].'-'.$s['day_end'] == '0000-00-00') {
$consider_end = false; $consider_end = false;
} }
$sid = self::create_session($s['name'].' '.get_lang('Copy'), $sid = self::create_session($s['name'].' '.get_lang('Copy'),
$s['year_start'], $s['month_start'], $s['day_start'], $s['year_start'], $s['month_start'], $s['day_start'],
$s['year_end'],$s['month_end'],$s['day_end'], $s['year_end'],$s['month_end'],$s['day_end'],
$s['nb_days_acess_before_beginning'],$s['nb_days_acess_after_end'], $s['nb_days_acess_before_beginning'],$s['nb_days_acess_after_end'],
false,(int)$s['id_coach'], $s['session_category_id'], false,(int)$s['id_coach'], $s['session_category_id'],
(int)$s['visibility'],$consider_start, $consider_end, true); (int)$s['visibility'],$consider_start, $consider_end, true);
if (!is_numeric($sid) || empty($sid)) { if (!is_numeric($sid) || empty($sid)) {
return false; return false;
} }
if ($copy_courses) { if ($copy_courses) {
// Register courses from the original session to the new session // Register courses from the original session to the new session
$courses = self::get_course_list_by_session_id($id); $courses = self::get_course_list_by_session_id($id);
$short_courses = $new_short_courses = array(); $short_courses = $new_short_courses = array();
if (is_array($courses) && count($courses)>0) { if (is_array($courses) && count($courses)>0) {
foreach ($courses as $course) { foreach ($courses as $course) {
@ -1697,7 +1697,7 @@ class SessionManager {
} }
} }
$courses = null; $courses = null;
//We will copy the current courses of the session to new courses //We will copy the current courses of the session to new courses
if (!empty($short_courses)) { if (!empty($short_courses)) {
if ($create_new_courses) { if ($create_new_courses) {
@ -1705,20 +1705,20 @@ class SessionManager {
if (function_exists('ini_set')) { if (function_exists('ini_set')) {
ini_set('memory_limit','256M'); ini_set('memory_limit','256M');
ini_set('max_execution_time',0); ini_set('max_execution_time',0);
} }
$params = array(); $params = array();
$params['skip_lp_dates'] = true; $params['skip_lp_dates'] = true;
foreach ($short_courses as $course_data) { foreach ($short_courses as $course_data) {
$course_info = CourseManager::copy_course_simple($course_data['title'].' '.get_lang('Copy'), $course_data['course_code'], $id, $sid, $params); $course_info = CourseManager::copy_course_simple($course_data['title'].' '.get_lang('Copy'), $course_data['course_code'], $id, $sid, $params);
if ($course_info) { if ($course_info) {
//By default new elements are invisible //By default new elements are invisible
if ($set_exercises_lp_invisible) { if ($set_exercises_lp_invisible) {
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php'; require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
$list = new LearnpathList('', $course_info['code'], $sid); $list = new LearnpathList('', $course_info['code'], $sid);
$flat_list = $list->get_flat_list(); $flat_list = $list->get_flat_list();
if (!empty($flat_list)) { if (!empty($flat_list)) {
foreach($flat_list as $lp_id => $data) { foreach($flat_list as $lp_id => $data) {
api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0 ,0, 0, 0, $sid); api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0 ,0, 0, 0, $sid);
api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0 ,0, 0, 0); api_item_property_update($course_info, TOOL_LEARNPATH, $lp_id, 'invisible', api_get_user_id(), 0 ,0, 0, 0);
} }
@ -1727,11 +1727,11 @@ class SessionManager {
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
//@todo check this query //@todo check this query
$sql = "UPDATE $quiz_table SET active = 0 WHERE c_id = $course_id "; $sql = "UPDATE $quiz_table SET active = 0 WHERE c_id = $course_id ";
$result=Database::query($sql); $result=Database::query($sql);
} }
$new_short_courses[] = $course_info['code']; $new_short_courses[] = $course_info['code'];
} }
} }
} else { } else {
foreach($short_courses as $course_data) { foreach($short_courses as $course_data) {
$new_short_courses[] = $course_data['code']; $new_short_courses[] = $course_data['code'];
@ -1758,15 +1758,15 @@ class SessionManager {
} }
return $sid; return $sid;
} }
function user_is_general_coach($user_id, $session_id) { function user_is_general_coach($user_id, $session_id) {
$session_id = intval($session_id); $session_id = intval($session_id);
$user_id = intval($user_id); $user_id = intval($user_id);
$session_table = Database::get_main_table(TABLE_MAIN_SESSION); $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "SELECT DISTINCT id $sql = "SELECT DISTINCT id
FROM $session_table FROM $session_table
WHERE session.id_coach = '".$user_id."' AND id = '$session_id'"; WHERE session.id_coach = '".$user_id."' AND id = '$session_id'";
$result = Database::query($sql); $result = Database::query($sql);
if ($result && Database::num_rows($result)) { if ($result && Database::num_rows($result)) {
return true; return true;
} }
@ -1800,7 +1800,7 @@ class SessionManager {
} }
} }
} }
static function get_session_by_course($course_code) { static function get_session_by_course($course_code) {
$table_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $table_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$table_session = Database::get_main_table(TABLE_MAIN_SESSION); $table_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -1810,14 +1810,14 @@ class SessionManager {
$result = Database::query($sql); $result = Database::query($sql);
return Database::store_result($result); return Database::store_result($result);
} }
static function get_sessions_by_user($user_id) { static function get_sessions_by_user($user_id) {
$session_categories = UserManager::get_sessions_by_category($user_id); $session_categories = UserManager::get_sessions_by_category($user_id);
$session_array = array(); $session_array = array();
if (!empty($session_categories)) { if (!empty($session_categories)) {
foreach ($session_categories as $category) { foreach ($session_categories as $category) {
if (isset($category['sessions'])) { if (isset($category['sessions'])) {
foreach ($category['sessions'] as $session) { foreach ($category['sessions'] as $session) {
$session_array[] = $session; $session_array[] = $session;
} }
} }

File diff suppressed because it is too large Load Diff

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /chamilo_license.txt */
/* For licensing terms, see /license.txt */
/** /**
* @package chamilo.social * @package chamilo.social
* @author Julio Montoya <gugli100@gmail.com> * @author Julio Montoya <gugli100@gmail.com>
@ -8,20 +9,20 @@
* Initialization * Initialization
*/ */
$language_file = array('userInfo'); $language_file = array('userInfo');
$cidReset=true; $cidReset = true;
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
api_block_anonymous_users(); api_block_anonymous_users();
if (api_get_setting('allow_social_tool') !='true') { if (api_get_setting('allow_social_tool') != 'true') {
api_not_allowed(); api_not_allowed();
} }
$this_section = SECTION_SOCIAL; $this_section = SECTION_SOCIAL;
$htmlHeadXtra[] = '<script type="text/javascript"> $htmlHeadXtra[] = '<script>
function delete_friend (element_div) { function delete_friend (element_div) {
id_image=$(element_div).attr("id"); id_image=$(element_div).attr("id");
@ -82,40 +83,40 @@ function clear_form () {
</script>'; </script>';
$interbreadcrumb[]= array ('url' =>'profile.php','name' => get_lang('SocialNetwork')); $interbreadcrumb[] = array('url' => 'profile.php', 'name' => get_lang('SocialNetwork'));
$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Friends')); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Friends'));
$social_left_content = SocialManager::show_social_menu('friends'); $social_left_content = SocialManager::show_social_menu('friends');
$user_id = api_get_user_id(); $user_id = api_get_user_id();
$user_id = api_get_user_id(); $user_id = api_get_user_id();
$name_search = isset($_POST['search_name_q']) ? $_POST['search_name_q']: null; $name_search = isset($_POST['search_name_q']) ? $_POST['search_name_q'] : null;
$number_friends = 0; $number_friends = 0;
if (isset($name_search) && $name_search!='undefined') { if (isset($name_search) && $name_search != 'undefined') {
$friends = SocialManager::get_friends($user_id,null,$name_search); $friends = SocialManager::get_friends($user_id, null, $name_search);
} else { } else {
$friends = SocialManager::get_friends($user_id); $friends = SocialManager::get_friends($user_id);
} }
$social_right_content = '<div class="span8">'; $social_right_content = '<div class="span8">';
if (count($friends) == 0 ) { if (count($friends) == 0) {
$social_right_content .= get_lang('NoFriendsInYourContactList').'<br /><br />'; $social_right_content .= get_lang('NoFriendsInYourContactList').'<br /><br />';
$social_right_content .= '<a class="btn" href="search.php">'.get_lang('TryAndFindSomeFriends').'</a>'; $social_right_content .= '<a class="btn" href="search.php">'.get_lang('TryAndFindSomeFriends').'</a>';
} else { } else {
$social_right_content .= get_lang('Search') .'&nbsp;&nbsp; : &nbsp;&nbsp;'; $social_right_content .= get_lang('Search').'&nbsp;&nbsp; : &nbsp;&nbsp;';
$social_right_content .= '<input class="social-search-image" type="text" id="id_search_image" name="id_search_image" onkeyup="search_image_social()" />'; $social_right_content .= '<input class="social-search-image" type="text" id="id_search_image" name="id_search_image" onkeyup="search_image_social()" />';
$friend_html = '<div id="friends">'; $friend_html = '<div id="friends">';
$number_friends = count($friends); $number_friends = count($friends);
$j=0; $j = 0;
$friend_html.= '<ul class="thumbnails">'; $friend_html.= '<ul class="thumbnails">';
for ($k=0;$k<$number_friends;$k++) { for ($k = 0; $k < $number_friends; $k++) {
while ($j<$number_friends) { while ($j < $number_friends) {
if (isset($friends[$j])) { if (isset($friends[$j])) {
$friend_html.='<li class="span2">'; $friend_html.='<li class="span2">';
@ -135,7 +136,7 @@ if (count($friends) == 0 ) {
} }
$friend_html.='</ul>'; $friend_html.='</ul>';
$friend_html.='</div>'; $friend_html.='</div>';
$social_right_content .= $friend_html; $social_right_content .= $friend_html;
} }
$social_right_content .= '</div>'; $social_right_content .= '</div>';
@ -143,7 +144,6 @@ $social_right_content .= '</div>';
$tpl = new Template(get_lang('Social')); $tpl = new Template(get_lang('Social'));
$tpl->assign('social_left_content', $social_left_content); $tpl->assign('social_left_content', $social_left_content);
$tpl->assign('social_right_content', $social_right_content); $tpl->assign('social_right_content', $social_right_content);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$social_layout = $tpl->get_template('layout/social_layout.tpl'); $social_layout = $tpl->get_template('layout/social_layout.tpl');
$tpl->display($social_layout); $tpl->display($social_layout);

@ -118,6 +118,7 @@ jQuery(document).ready(function() {
$allowed_views = array('mygroups','newest','pop'); $allowed_views = array('mygroups','newest','pop');
$interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('SocialNetwork')); $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('SocialNetwork'));
$content = null;
if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) { if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
if ($_GET['view'] == 'mygroups') { if ($_GET['view'] == 'mygroups') {
@ -187,6 +188,8 @@ if ($group_id != 0 ) {
$social_left_content = SocialManager::show_social_menu($show_menu); $social_left_content = SocialManager::show_social_menu($show_menu);
} }
$social_right_content = null;
if ($group_id != 0 ) { if ($group_id != 0 ) {
$group_info = GroupPortalManager::get_group_data($group_id); $group_info = GroupPortalManager::get_group_data($group_id);
@ -455,6 +458,8 @@ if ($group_id != 0 ) {
// Display groups (newest, mygroups, pop) // Display groups (newest, mygroups, pop)
$query_vars = array(); $query_vars = array();
$newest_content = $popular_content = $my_group_content = null;
if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) { if (isset($_GET['view']) && in_array($_GET['view'],$allowed_views)) {
$view_group = $_GET['view']; $view_group = $_GET['view'];
@ -521,19 +526,17 @@ if ($group_id != 0 ) {
$social_right_content .= '<div class="span9">'.Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse').'</div>'; $social_right_content .= '<div class="span9">'.Display::tabs($headers, array($newest_content, $popular_content, $my_group_content),'tab_browse').'</div>';
} }
//Display :: display_footer(); $show_message = null;
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && $_REQUEST['msg'] == 'topic_deleted') { if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show_message' && $_REQUEST['msg'] == 'topic_deleted') {
$show_message = Display::return_message(get_lang('Deleted'), 'success'); $show_message = Display::return_message(get_lang('Deleted'), 'success');
} }
$tpl = new Template($tool_name); $tpl = new Template();
$tpl->set_help('Groups'); $tpl->set_help('Groups');
$tpl->assign('social_left_content', $social_left_content); $tpl->assign('social_left_content', $social_left_content);
$tpl->assign('social_left_menu', $social_left_menu);
$tpl->assign('social_right_content', $social_right_content); $tpl->assign('social_right_content', $social_right_content);
$tpl->assign('actions', $actions);
$tpl->assign('message', $show_message); $tpl->assign('message', $show_message);
$tpl->assign('content', $content); $tpl->assign('content', $content);
$social_layout = $tpl->get_template('layout/social_layout.tpl'); $social_layout = $tpl->get_template('layout/social_layout.tpl');
$tpl->display($social_layout); $tpl->display($social_layout);

@ -65,6 +65,8 @@ function register_friend(element_input) {
} }
</script>'; </script>';
$show_message = null;
$content = null;
// easy links // easy links
if (is_array($_GET) && count($_GET)>0) { if (is_array($_GET) && count($_GET)>0) {
@ -188,12 +190,10 @@ if (count($pending_invitations) > 0) {
$social_right_content .= Display::return_sortable_grid('waiting_user', array(), $new_invitation, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false,false,true,true,true,true)); $social_right_content .= Display::return_sortable_grid('waiting_user', array(), $new_invitation, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false,false,true,true,true,true));
} }
$tpl = new Template($tool_name); $tpl = new Template(null);
$tpl->assign('social_left_content', $social_left_content); $tpl->assign('social_left_content', $social_left_content);
$tpl->assign('social_left_menu', $social_left_menu);
$tpl->assign('social_right_content', $social_right_content); $tpl->assign('social_right_content', $social_right_content);
$tpl->assign('actions', $actions);
$tpl->assign('message', $show_message); $tpl->assign('message', $show_message);
$tpl->assign('content', $content); $tpl->assign('content', $content);
$social_layout = $tpl->get_template('layout/social_layout.tpl'); $social_layout = $tpl->get_template('layout/social_layout.tpl');

@ -40,7 +40,7 @@ if ($query !='') {
$social_right_content .= get_lang('SorryNoResults'); $social_right_content .= get_lang('SorryNoResults');
} }
$results .= '<div id="online_grid_container"><div class="span9">'; $results = '<div id="online_grid_container"><div class="span9">';
if (is_array($users) && count($users)> 0) { if (is_array($users) && count($users)> 0) {
$results .= Display::page_subheader(get_lang('Users')); $results .= Display::page_subheader(get_lang('Users'));

@ -20,15 +20,15 @@ class BlockCourse extends Block {
private $user_id; private $user_id;
private $courses; private $courses;
private $path; private $path;
private $permission = array(DRH); private $permission = array(DRH);
/** /**
* Constructor * Constructor
*/ */
public function __construct ($user_id) { public function __construct ($user_id) {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_course'; $this->path = 'block_course';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
/*if (api_is_platform_admin()) { /*if (api_is_platform_admin()) {
$this->courses = CourseManager::get_real_course_list(); $this->courses = CourseManager::get_real_course_list();
@ -37,22 +37,22 @@ class BlockCourse extends Block {
//} //}
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) { public function is_block_visible_for_user($user_id) {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about courses and its position for showing it inside dashboard interface * This method return content html containing information about courses and its position for showing it inside dashboard interface
@ -93,13 +93,14 @@ class BlockCourse extends Block {
$course_data = $this->get_course_information_data(); $course_data = $this->get_course_information_data();
$content = '<div style="margin:10px;">'; $content = '<div style="margin:10px;">';
$content .= '<h3><font color="#000">'.get_lang('YourCourseList').'</font></h3>'; $content .= '<h3><font color="#000">'.get_lang('YourCourseList').'</font></h3>';
$data_table = null;
if (!empty($course_data)) { if (!empty($course_data)) {
$data_table = '<table class="data_table" width:"95%">'; $data_table .= '<table class="data_table" width:"95%">';
$data_table .= '<tr> $data_table .= '<tr>
<th>'.get_lang('CourseTitle').'</th> <th>'.get_lang('CourseTitle').'</th>
<th width="20%">'.get_lang('NbStudents').'</th> <th width="20%">'.get_lang('NbStudents').'</th>
<th width="20%">'.get_lang('AvgTimeSpentInTheCourse').'</th> <th width="20%">'.get_lang('AvgTimeSpentInTheCourse').'</th>
<th width="20%">'.get_lang('ThematicAdvance').'</th> <th width="20%">'.get_lang('ThematicAdvance').'</th>
</tr>'; </tr>';
$i = 1; $i = 1;
@ -122,7 +123,7 @@ class BlockCourse extends Block {
$data_table .= '</table>'; $data_table .= '</table>';
} else { } else {
$data_table .= get_lang('ThereIsNoInformationAboutYourCourses'); $data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
} }
$content .= $data_table; $content .= $data_table;
if (!empty($course_data)) { if (!empty($course_data)) {
$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>'; $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>';
@ -151,9 +152,9 @@ class BlockCourse extends Block {
$a_course_students = array(); $a_course_students = array();
$course_data = array(); $course_data = array();
$courses = $this->courses; $courses = $this->courses;
$thematic = new Thematic(); $thematic = new Thematic();
foreach ($courses as $row_course) { foreach ($courses as $row_course) {
$course_code = $row_course['code']; $course_code = $row_course['code'];
@ -173,8 +174,8 @@ class BlockCourse extends Block {
$avg_time_spent_in_course = null; $avg_time_spent_in_course = null;
} }
$tematic_advance_progress = 0; $tematic_advance_progress = 0;
$tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, 0); $tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, 0);
if (!empty($tematic_advance)) { if (!empty($tematic_advance)) {
@ -186,7 +187,7 @@ class BlockCourse extends Block {
$table_row = array(); $table_row = array();
$table_row[] = $row_course['title']; $table_row[] = $row_course['title'];
$table_row[] = $nb_students_in_course; $table_row[] = $nb_students_in_course;
$table_row[] = $avg_time_spent_in_course; $table_row[] = $avg_time_spent_in_course;
$table_row[] = $tematic_advance_progress; $table_row[] = $tematic_advance_progress;
$course_data[] = $table_row; $course_data[] = $table_row;
} }

@ -5,7 +5,7 @@
* @package chamilo.dashboard * @package chamilo.dashboard
* @author Marco Sousa original code * @author Marco Sousa original code
* @author Julio Montoya class named was changed of name, and some minor changes * @author Julio Montoya class named was changed of name, and some minor changes
*/ */
/** /**
@ -25,15 +25,15 @@ class BlockDaily extends Block {
private $user_id; private $user_id;
private $courses; private $courses;
private $path; private $path;
private $permission = array(DRH); private $permission = array(DRH);
/** /**
* Constructor * Constructor
*/ */
public function __construct ($user_id) { public function __construct ($user_id) {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_daily'; $this->path = 'block_daily';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
/*if (api_is_platform_admin()) { /*if (api_is_platform_admin()) {
$this->courses = CourseManager::get_real_course_list(); $this->courses = CourseManager::get_real_course_list();
@ -42,22 +42,22 @@ class BlockDaily extends Block {
//} //}
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) { public function is_block_visible_for_user($user_id) {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about courses and its position for showing it inside dashboard interface * This method return content html containing information about courses and its position for showing it inside dashboard interface
@ -97,9 +97,10 @@ class BlockDaily extends Block {
$course_data = $this->get_course_information_data(); $course_data = $this->get_course_information_data();
$content = '<div style="margin:10px;">'; $content = '<div style="margin:10px;">';
$content .= '<h3><font color="#000">'.get_lang('YourCourseList').'</font></h3>'; $content .= '<h3><font color="#000">'.get_lang('YourCourseList').'</font></h3>';
$data_table = null;
if (!empty($course_data)) { if (!empty($course_data)) {
$data_table = '<table class="data_table" width:"95%">'; $data_table .= '<table class="data_table" width:"95%">';
$data_table .= '<tr> $data_table .= '<tr>
<th>'.get_lang('CourseTitle').'</th> <th>'.get_lang('CourseTitle').'</th>
<th width="20%">'.get_lang('NbStudents').'</th> <th width="20%">'.get_lang('NbStudents').'</th>
@ -126,7 +127,7 @@ class BlockDaily extends Block {
$data_table .= '</table>'; $data_table .= '</table>';
} else { } else {
$data_table .= get_lang('ThereIsNoInformationAboutYourCourses'); $data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
} }
$content .= $data_table; $content .= $data_table;
if (!empty($course_data)) { if (!empty($course_data)) {
$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>'; $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>';
@ -154,7 +155,7 @@ class BlockDaily extends Block {
$a_course_students = array(); $a_course_students = array();
$course_data = array(); $course_data = array();
$courses = $this->courses; $courses = $this->courses;
foreach ($courses as $row_course) { foreach ($courses as $row_course) {
$score = null; $score = null;
$course_code = $row_course['code']; $course_code = $row_course['code'];
@ -162,12 +163,12 @@ class BlockDaily extends Block {
if (empty($course_info)) { if (empty($course_info)) {
continue; continue;
} }
// Attendance table // Attendance table
$table_course = Database::get_course_table(TABLE_ATTENDANCE); $table_course = Database::get_course_table(TABLE_ATTENDANCE);
$sql = "SELECT id, name, attendance_qualify_max FROM $table_course WHERE c_id = ".$course_info['real_id']." AND active = 1 AND session_id = 0"; $sql = "SELECT id, name, attendance_qualify_max FROM $table_course WHERE c_id = ".$course_info['real_id']." AND active = 1 AND session_id = 0";
$rs = Database::query($sql); $rs = Database::query($sql);
$attendance = array(); $attendance = array();
$attendances = array(); $attendances = array();
@ -176,12 +177,12 @@ class BlockDaily extends Block {
$param_gradebook = '&gradebook='.$_SESSION['gradebook']; $param_gradebook = '&gradebook='.$_SESSION['gradebook'];
} }
while ($row = Database::fetch_array($rs,'ASSOC')) { while ($row = Database::fetch_array($rs,'ASSOC')) {
$attendance['done'] = $row['attendance_qualify_max']; $attendance['done'] = $row['attendance_qualify_max'];
$attendance['id'] = $row['id']; $attendance['id'] = $row['id'];
//$attendance['name'] = $row['name']; //$attendance['name'] = $row['name'];
$attendance['course_code'] = $course_code; $attendance['course_code'] = $course_code;
if ($attendance['done'] != '0') if ($attendance['done'] != '0')
$attendances[] = '<a href="'.api_get_path(WEB_PATH).'main/attendance/index.php?cidReq='.$attendance['course_code'].'&action=attendance_sheet_print&attendance_id='.$attendance['id'].$param_gradebook.'">'.Display::return_icon('printmgr.gif',get_lang('Print')).'</a>'; $attendances[] = '<a href="'.api_get_path(WEB_PATH).'main/attendance/index.php?cidReq='.$attendance['course_code'].'&action=attendance_sheet_print&attendance_id='.$attendance['id'].$param_gradebook.'">'.Display::return_icon('printmgr.gif',get_lang('Print')).'</a>';
else else
@ -191,7 +192,7 @@ class BlockDaily extends Block {
// quantidade de alunos // quantidade de alunos
$sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status=".STUDENT." AND course_rel_user.course_code='$course_code'"; $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status=".STUDENT." AND course_rel_user.course_code='$course_code'";
$rs = Database::query($sql); $rs = Database::query($sql);
$users = array(); $users = array();
while ($row = Database::fetch_array($rs)) { while ($row = Database::fetch_array($rs)) {
$users[] = $row['user_id']; $users[] = $row['user_id'];
@ -214,16 +215,16 @@ class BlockDaily extends Block {
while ($row = Database::fetch_array($rs)) { while ($row = Database::fetch_array($rs)) {
$category = $row['id']; $category = $row['id'];
} }
if (!empty($category)) { if (!empty($category)) {
$cat = Category::load($category); $cat = Category::load($category);
$eval = $cat[0]->get_evaluations(); $eval = $cat[0]->get_evaluations();
if (count($eval) > 0){ if (count($eval) > 0){
$i = 0; $i = 0;
foreach ($eval as $item) { foreach ($eval as $item) {
$score .= '<a href="'.api_get_path(WEB_PATH).'main/gradebook/gradebook_view_result.php?export=pdf&cat_code='.$cat[0]->get_id().'&official_code='.$cat[0]->get_course_code().'&selecteval='.$item->get_id().$param_gradebook.'">'.$item->get_name().'</a>'; $score .= '<a href="'.api_get_path(WEB_PATH).'main/gradebook/gradebook_view_result.php?export=pdf&cat_code='.$cat[0]->get_id().'&official_code='.$cat[0]->get_course_code().'&selecteval='.$item->get_id().$param_gradebook.'">'.$item->get_name().'</a>';
if (count($eval)-1 != $i) { if (count($eval)-1 != $i) {
$score .= ', '; $score .= ', ';
} }
$i++; $i++;
} }

@ -1,6 +1,6 @@
<?php <?php
/** /**
* This file is part of student block plugin for dashboard, * This file is part of student block plugin for dashboard,
* it should be required inside dashboard controller for showing it into dashboard interface from plattform * it should be required inside dashboard controller for showing it into dashboard interface from plattform
* @package chamilo.dashboard * @package chamilo.dashboard
* @author Christian Fasanando * @author Christian Fasanando
@ -17,7 +17,7 @@ require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/linkfactory.class.php
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/category.class.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/category.class.php';
/** /**
* This class is used like controller for student block plugin, * This class is used like controller for student block plugin,
* the class name must be registered inside path.info file (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it * the class name must be registered inside path.info file (e.g: controller = "BlockStudent"), so dashboard controller will be instantiate it
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
@ -30,45 +30,45 @@ class BlockStudent extends Block {
/** /**
* Constructor * Constructor
*/ */
public function __construct ($user_id) { public function __construct ($user_id) {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_student'; $this->path = 'block_student';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
/*if (api_is_platform_admin()) { /*if (api_is_platform_admin()) {
$this->students = UserManager::get_user_list(array('status' => STUDENT)); $this->students = UserManager::get_user_list(array('status' => STUDENT));
} else {*/ } else {*/
$this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT); $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT);
//} //}
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) { public function is_block_visible_for_user($user_id) {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about students and its position for showing it inside dashboard interface * This method return content html containing information about students and its position for showing it inside dashboard interface
* it's important to use the name 'get_block' for beeing used from dashboard controller * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
public function get_block() { public function get_block() {
global $charset; global $charset;
$column = 1; $column = 1;
$data = array(); $data = array();
$student_content_html = $this->get_students_content_html_for_drh(); $student_content_html = $this->get_students_content_html_for_drh();
$html = '<li class="widget color-blue" id="intro"> $html = '<li class="widget color-blue" id="intro">
<div class="widget-head"> <div class="widget-head">
@ -80,76 +80,76 @@ class BlockStudent extends Block {
<div class="widget-content"> <div class="widget-content">
'.$student_content_html.' '.$student_content_html.'
</div> </div>
</li>'; </li>';
$data['column'] = $column; $data['column'] = $column;
$data['content_html'] = $html; $data['content_html'] = $html;
return $data; return $data;
} }
/** /**
* This method return a content html, it's used inside get_block method for showing it inside dashboard interface * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html * @return string content html
*/ */
public function get_students_content_html_for_platform_admin() { public function get_students_content_html_for_platform_admin() {
$students = $this->students; $students = $this->students;
$content = '<div style="margin:10px;">'; $content = '<div style="margin:10px;">';
$content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>'; $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
$students_table = null;
if (count($students) > 0) { if (count($students) > 0) {
$students_table = '<table class="data_table">'; $students_table .= '<table class="data_table">';
$students_table .= '<tr> $students_table .= '<tr>
<th width="10%" rowspan="2">'.get_lang('FirstName').'</th> <th width="10%" rowspan="2">'.get_lang('FirstName').'</th>
<th width="10%" rowspan="2">'.get_lang('LastName').'</th> <th width="10%" rowspan="2">'.get_lang('LastName').'</th>
<th width="30%" colspan="2">'.get_lang('CourseInformation').'</th> <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th>
</tr> </tr>
<tr> <tr>
<th width="10%">'.get_lang('Courses').'</th> <th width="10%">'.get_lang('Courses').'</th>
<th width="10%">'.get_lang('Time').'</th> <th width="10%">'.get_lang('Time').'</th>
</tr>'; </tr>';
$i = 1; $i = 1;
foreach ($students as $student) { foreach ($students as $student) {
$courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true); $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true);
$count_courses = count($courses_by_user); $count_courses = count($courses_by_user);
$rowspan = $count_courses?$count_courses+1:2; $rowspan = $count_courses?$count_courses+1:2;
if ($i%2 == 0) { if ($i%2 == 0) {
$style = ' style="background-color:#F2F2F2" '; $style = ' style="background-color:#F2F2F2" ';
} else { } else {
$style = ' style="background-color:#FFF" '; $style = ' style="background-color:#FFF" ';
} }
$students_table .= '<tr '.$style.'> $students_table .= '<tr '.$style.'>
<td rowspan="'.$rowspan.'">'.$student['firstname'].'</td> <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td>
<td rowspan="'.$rowspan.'">'.$student['lastname'].'</td> <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td>
</tr>'; </tr>';
// courses information about the student // courses information about the student
if (!empty($courses_by_user)) { if (!empty($courses_by_user)) {
foreach ($courses_by_user as $course) { foreach ($courses_by_user as $course) {
$course_code = $course['code']; $course_code = $course['code'];
$course_title = $course['title']; $course_title = $course['title'];
$time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $course_code)); $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $course_code));
$students_table .= '<tr '.$style.'> $students_table .= '<tr '.$style.'>
<td align="right">'.$course_title.'</td> <td align="right">'.$course_title.'</td>
<td align="right">'.$time.'</td> <td align="right">'.$time.'</td>
</tr>'; </tr>';
} }
} else { } else {
$students_table .= '<tr '.$style.'> $students_table .= '<tr '.$style.'>
<td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td> <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td>
</tr>'; </tr>';
} }
$i++; $i++;
} }
$students_table .= '</table>'; $students_table .= '</table>';
} else { } else {
$students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
} }
$content .= $students_table; $content .= $students_table;
if (count($students) > 0) { if (count($students) > 0) {
$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>'; $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>';
} }
@ -157,37 +157,37 @@ class BlockStudent extends Block {
return $content; return $content;
} }
public function get_students_content_html_for_drh() { public function get_students_content_html_for_drh() {
$attendance = new Attendance(); $attendance = new Attendance();
$students = $this->students; $students = $this->students;
$content = '<div style="margin:5px;">'; $content = '<div style="margin:5px;">';
$content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>'; $content .= '<h3><font color="#000">'.get_lang('YourStudents').'</font></h3>';
$students_table = null;
if (count($students) > 0) { if (count($students) > 0) {
$students_table = '<table class="data_table">'; $students_table .= '<table class="data_table">';
$students_table .= '<tr> $students_table .= '<tr>
<th>'.get_lang('User').'</th> <th>'.get_lang('User').'</th>
<th>'.get_lang('AttendancesFaults').'</th> <th>'.get_lang('AttendancesFaults').'</th>
<th>'.get_lang('Evaluations').'</th> <th>'.get_lang('Evaluations').'</th>
</tr>'; </tr>';
$i = 1; $i = 1;
foreach ($students as $student) { foreach ($students as $student) {
$student_id = $student['user_id']; $student_id = $student['user_id'];
$firstname = $student['firstname']; $firstname = $student['firstname'];
$lastname = $student['lastname']; $lastname = $student['lastname'];
$username = $student['username']; $username = $student['username'];
// get average of faults in attendances by student
$results_faults_avg = $attendance->get_faults_average_inside_courses($student_id); // get average of faults in attendances by student
$results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
if (!empty($results_faults_avg)) { if (!empty($results_faults_avg)) {
$attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>'; $attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>';
} else { } else {
$attendances_faults_avg = '0%'; $attendances_faults_avg = '0%';
} }
$courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true); $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
$evaluations_avg = 0; $evaluations_avg = 0;
$score = $weight = 0; $score = $weight = 0;
@ -195,54 +195,54 @@ class BlockStudent extends Block {
$course_code = $course['code']; $course_code = $course['code'];
$cats = Category::load(null, null, $course_code, null, null, null, false); $cats = Category::load(null, null, $course_code, null, null, null, false);
$scoretotal = array(); $scoretotal = array();
if (isset($cats) && isset($cats[0])) { if (isset($cats) && isset($cats[0])) {
$scoretotal= $cats[0]->calc_score($student_id, $course_code); $scoretotal= $cats[0]->calc_score($student_id, $course_code);
} }
if (!empty($scoretotal)) { if (!empty($scoretotal)) {
$score += $scoretotal[0]; $score += $scoretotal[0];
$weight += $scoretotal[1]; $weight += $scoretotal[1];
} }
} }
if (!empty($weight)) { if (!empty($weight)) {
$evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score,2).'/'.round($weight,2).'('.round(($score / $weight) * 100,2) . ' %)</a>'; $evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score,2).'/'.round($weight,2).'('.round(($score / $weight) * 100,2) . ' %)</a>';
} }
if ($i%2 == 0) { if ($i%2 == 0) {
$class_tr = 'row_odd'; $class_tr = 'row_odd';
} else { } else {
$class_tr = 'row_even'; $class_tr = 'row_even';
} }
$students_table .= '<tr class="'.$class_tr.'"> $students_table .= '<tr class="'.$class_tr.'">
<td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td> <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td>
<td>'.$attendances_faults_avg.'</td> <td>'.$attendances_faults_avg.'</td>
<td>'.$evaluations_avg.'</td> <td>'.$evaluations_avg.'</td>
</tr>'; </tr>';
$i++; $i++;
} }
$students_table .= '</table>'; $students_table .= '</table>';
} else { } else {
$students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
} }
$content .= $students_table; $content .= $students_table;
if (count($students) > 0) { if (count($students) > 0) {
$content .= '<div style="text-align:right;margin-top:10px;"> $content .= '<div style="text-align:right;margin-top:10px;">
<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a> <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a>
</div>'; </div>';
} }
$content .= '</div>'; $content .= '</div>';
return $content; return $content;
} }
/** /**
* Get number of students * Get number of students
* @return int * @return int
*/ */
function get_number_of_students() { function get_number_of_students() {
return count($this->students); return count($this->students);
} }
} }

@ -1,6 +1,6 @@
<?php <?php
/** /**
* This file is part of teacher block plugin for dashboard, * This file is part of teacher block plugin for dashboard,
* it should be required inside dashboard controller for showing it into dashboard interface from plattform * it should be required inside dashboard controller for showing it into dashboard interface from plattform
* @package chamilo.dashboard * @package chamilo.dashboard
* @author Christian Fasanando * @author Christian Fasanando
@ -11,7 +11,7 @@
*/ */
/** /**
* This class is used like controller for teacher block plugin, * This class is used like controller for teacher block plugin,
* the class name must be registered inside path.info file (e.g: controller = "BlockTeacher"), so dashboard controller will be instantiate it * the class name must be registered inside path.info file (e.g: controller = "BlockTeacher"), so dashboard controller will be instantiate it
* @package chamilo.dashboard * @package chamilo.dashboard
*/ */
@ -25,7 +25,7 @@ class BlockTeacher extends Block {
/** /**
* Controller * Controller
*/ */
public function __construct ($user_id) { public function __construct ($user_id) {
$this->user_id = $user_id; $this->user_id = $user_id;
$this->path = 'block_teacher'; $this->path = 'block_teacher';
if ($this->is_block_visible_for_user($user_id)) { if ($this->is_block_visible_for_user($user_id)) {
@ -33,44 +33,44 @@ class BlockTeacher extends Block {
$this->teachers = UserManager::get_user_list(array('status' => COURSEMANAGER)); $this->teachers = UserManager::get_user_list(array('status' => COURSEMANAGER));
} else {*/ } else {*/
$this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER); $this->teachers = UserManager::get_users_followed_by_drh($user_id, COURSEMANAGER);
//} //}
} }
} }
/** /**
* This method check if a user is allowed to see the block inside dashboard interface * This method check if a user is allowed to see the block inside dashboard interface
* @param int User id * @param int User id
* @return bool Is block visible for user * @return bool Is block visible for user
*/ */
public function is_block_visible_for_user($user_id) { public function is_block_visible_for_user($user_id) {
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
$user_status = $user_info['status']; $user_status = $user_info['status'];
$is_block_visible_for_user = false; $is_block_visible_for_user = false;
if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
$is_block_visible_for_user = true; $is_block_visible_for_user = true;
} }
return $is_block_visible_for_user; return $is_block_visible_for_user;
} }
/** /**
* This method return content html containing information about teachers and its position for showing it inside dashboard interface * This method return content html containing information about teachers and its position for showing it inside dashboard interface
* it's important to use the name 'get_block' for beeing used from dashboard controller * it's important to use the name 'get_block' for beeing used from dashboard controller
* @return array column and content html * @return array column and content html
*/ */
public function get_block() { public function get_block() {
global $charset; global $charset;
$column = 1; $column = 1;
$data = array(); $data = array();
/*if (api_is_platform_admin()) { /*if (api_is_platform_admin()) {
$teacher_content_html = $this->get_teachers_content_html_for_platform_admin(); $teacher_content_html = $this->get_teachers_content_html_for_platform_admin();
} else if (api_is_drh()) {*/ } else if (api_is_drh()) {*/
$teacher_content_html = $this->get_teachers_content_html_for_drh(); $teacher_content_html = $this->get_teachers_content_html_for_drh();
//} //}
$html = ' $html = '
<li class="widget color-blue" id="intro"> <li class="widget color-blue" id="intro">
<div class="widget-head"> <div class="widget-head">
<h3>'.get_lang('TeachersInformationsList').'</h3> <h3>'.get_lang('TeachersInformationsList').'</h3>
@ -79,137 +79,134 @@ class BlockTeacher extends Block {
<div class="widget-content"> <div class="widget-content">
'.$teacher_content_html.' '.$teacher_content_html.'
</div> </div>
</li> </li>
'; ';
$data['column'] = $column; $data['column'] = $column;
$data['content_html'] = $html; $data['content_html'] = $html;
return $data; return $data;
} }
/** /**
* This method return a content html, it's used inside get_block method for showing it inside dashboard interface * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
* @return string content html * @return string content html
*/ */
public function get_teachers_content_html_for_platform_admin() { public function get_teachers_content_html_for_platform_admin() {
$teachers = $this->teachers; $teachers = $this->teachers;
$content = '';
$content = '<div style="margin:10px;">'; $content = '<div style="margin:10px;">';
$content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>'; $content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';
$teachers_table = null;
if (count($teachers) > 0) { if (count($teachers) > 0) {
$teachers_table = '<table class="data_table" width:"95%">'; $teachers_table .= '<table class="data_table" width:"95%">';
$teachers_table .= ' $teachers_table .= '
<tr> <tr>
<th>'.get_lang('User').'</th> <th>'.get_lang('User').'</th>
<th>'.get_lang('TimeSpentOnThePlatform').'</th> <th>'.get_lang('TimeSpentOnThePlatform').'</th>
<th>'.get_lang('LastConnexion').'</th> <th>'.get_lang('LastConnexion').'</th>
</tr> </tr>
'; ';
$i = 1; $i = 1;
foreach ($teachers as $teacher) { foreach ($teachers as $teacher) {
$teacher_id = $teacher['user_id']; $teacher_id = $teacher['user_id'];
$firstname = $teacher['firstname']; $firstname = $teacher['firstname'];
$lastname = $teacher['lastname']; $lastname = $teacher['lastname'];
$username = $teacher['username']; $username = $teacher['username'];
$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id)); $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id));
$last_connection = Tracking :: get_last_connection_date($teacher_id); $last_connection = Tracking :: get_last_connection_date($teacher_id);
if ($i%2 == 0) $class_tr = 'row_odd'; if ($i%2 == 0) $class_tr = 'row_odd';
else $class_tr = 'row_even'; else $class_tr = 'row_even';
$teachers_table .= ' $teachers_table .= '
<tr class="'.$class_tr.'"> <tr class="'.$class_tr.'">
<td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td> <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
<td align="right">'.$time_on_platform.'</td> <td align="right">'.$time_on_platform.'</td>
<td align="right">'.$last_connection.'</td> <td align="right">'.$last_connection.'</td>
</tr> </tr>
'; ';
$i++; $i++;
} }
$teachers_table .= '</table>'; $teachers_table .= '</table>';
} else { } else {
$teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers'); $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
} }
$content .= $teachers_table; $content .= $teachers_table;
if (count($teachers) > 0) { if (count($teachers) > 0) {
$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>'; $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin">'.get_lang('SeeMore').'</a></div>';
} }
$content .= '</div>'; $content .= '</div>';
return $content; return $content;
} }
public function get_teachers_content_html_for_drh() { public function get_teachers_content_html_for_drh() {
$teachers = $this->teachers; $teachers = $this->teachers;
$content = '';
$content = '<div style="margin:10px;">'; $content = '<div style="margin:10px;">';
$content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>'; $content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';
$teachers_table = null;
if (count($teachers) > 0) { if (count($teachers) > 0) {
$a_last_week = get_last_week(); $a_last_week = get_last_week();
$last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]); $last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
$teachers_table = '<table class="data_table" width:"95%">'; $teachers_table .= '<table class="data_table" width:"95%">';
$teachers_table .= ' $teachers_table .= '
<tr> <tr>
<th>'.get_lang('User').'</th> <th>'.get_lang('User').'</th>
<th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th> <th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th>
</tr> </tr>
'; ';
$i = 1; $i = 1;
foreach ($teachers as $teacher) { foreach ($teachers as $teacher) {
$teacher_id = $teacher['user_id']; $teacher_id = $teacher['user_id'];
$firstname = $teacher['firstname']; $firstname = $teacher['firstname'];
$lastname = $teacher['lastname']; $lastname = $teacher['lastname'];
$username = $teacher['username']; $username = $teacher['username'];
$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id,true)); $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id,true));
if ($i%2 == 0) $class_tr = 'row_odd'; if ($i%2 == 0) $class_tr = 'row_odd';
else $class_tr = 'row_even'; else $class_tr = 'row_even';
$teachers_table .= '<tr class="'.$class_tr.'"> $teachers_table .= '<tr class="'.$class_tr.'">
<td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td> <td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>
<td align="right">'.$time_on_platform.'</td> <td align="right">'.$time_on_platform.'</td>
</tr>'; </tr>';
$i++; $i++;
} }
$teachers_table .= '</table>'; $teachers_table .= '</table>';
} else { } else {
$teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers'); $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
} }
$content .= $teachers_table; $content .= $teachers_table;
if (count($teachers) > 0) { if (count($teachers) > 0) {
$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/teachers.php">'.get_lang('SeeMore').'</a></div>'; $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/teachers.php">'.get_lang('SeeMore').'</a></div>';
} }
$content .= '</div>'; $content .= '</div>';
return $content; return $content;
} }
/** /**
* Get number of teachers * Get number of teachers
* @return int * @return int
*/ */
function get_number_of_teachers() { function get_number_of_teachers() {
return count($this->teachers); return count($this->teachers);
} }
} }
Loading…
Cancel
Save