function _get_time_query($type = 'html', $report_data = NULL, $other = '')
 {
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     require_once dirname(__FILE__) . '/report_tableprinter.php';
     if ($report_data == NULL) {
         $ref =& $_SESSION['report_tempdata'];
     } else {
         $ref =& $report_data;
     }
     $fw = $GLOBALS['prefix_fw'];
     $lms = $GLOBALS['prefix_lms'];
     $sel_all = $ref['rows_filter']['select_all'];
     $sel_type = $ref['rows_filter']['selection_type'];
     $selection = $ref['rows_filter']['selection'];
     $timetype = $ref['columns_filter']['timetype'];
     $years =& $ref['columns_filter']['years'];
     $months =& $ref['columns_filter']['months'];
     if (!$sel_all && count($selection) <= 0) {
         cout('<p>' . $this->lang->def('_EMPTY_SELECTION') . '</p>');
         return;
     }
     $acl = new DoceboACLManager();
     $acl->include_suspended = true;
     //admin users filter
     $userlevelid = Docebo::user()->getUserLevelId();
     if ($userlevelid != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous()) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
         $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
         $admin_users = array_unique($admin_users);
     }
     $html = '';
     $times = array();
     switch ($timetype) {
         case 'years':
             $now = date('Y');
             for ($i = $now - $years + 1; $i <= $now; $i++) {
                 $times[] = $i;
             }
             break;
         case 'months':
             //...
             break;
     }
     switch ($sel_type) {
         case 'users':
             $data = array();
             $users_list = $sel_all ? $acl->getAllUsersIdst() : $acl->getAllUsersFromIdst($selection);
             $users_list = array_unique($users_list);
             if ($userlevelid != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous()) {
                 $users_list = array_intersect($users_list, $admin_users);
             }
             $query = "SELECT idUser, YEAR(date_complete) as yearComplete " . " FROM " . $lms . "_courseuser " . " WHERE status=2 " . ($userlevelid != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous() ? " AND idUser IN (" . implode(",", $users_list) . ") " : "");
             $res = sql_query($query);
             while ($row = mysql_fetch_assoc($res)) {
                 //$data[ $row['idUser'] ][ $row['yearComplete'] ] = $row['complete'];
                 $idUser = $row['idUser'];
                 $year = $row['yearComplete'];
                 if (!isset($data[$idUser][$year])) {
                     $data[$idUser][$year] = 0;
                 }
                 $data[$idUser][$year]++;
             }
             $usernames = array();
             $query = "SELECT idst, userid FROM " . $fw . "_user WHERE idst IN (" . implode(",", $users_list) . ")";
             $res = sql_query($query);
             while ($row = mysql_fetch_assoc($res)) {
                 $usernames[$row['idst']] = $acl->relativeId($row['userid']);
             }
             //draw table
             $buffer = new ReportTablePrinter($type, true);
             $buffer->openTable('', '');
             $head = array($this->lang->def('_USER'));
             foreach ($times as $time) {
                 $head[] = $time;
             }
             $head[] = $this->lang->def('_TOTAL');
             $buffer->openHeader();
             $buffer->addHeader($head);
             $buffer->closeHeader();
             $tot_total = 0;
             $buffer->openBody();
             foreach ($users_list as $user) {
                 if (!isset($usernames[$user])) {
                     break;
                 }
                 $line = array();
                 $line_total = 0;
                 $line[] = $usernames[$user];
                 foreach ($times as $time) {
                     //years or months
                     switch ($timetype) {
                         case 'years':
                             if (isset($data[$user][$time])) {
                                 $line[] = $data[$user][$time];
                                 $line_total += $data[$user][$time];
                             } else {
                                 $line[] = '0';
                             }
                             break;
                         case 'months':
                             //$year = ...
                             //$month = ...
                             //$line[] = (isset($data[$group][$year][$month]) ? $data[$group][$year][$month] : '0'); break;
                     }
                 }
                 $line[] = $line_total;
                 $tot_total += $line_total;
                 $buffer->addLine($line);
             }
             $buffer->closeBody();
             //totals
             $foot = array('');
             foreach ($times as $time) {
                 $temp = 0;
                 foreach ($users_list as $user) {
                     if (isset($data[$user][$time])) {
                         $temp += $data[$user][$time];
                     }
                 }
                 $foot[] = $temp;
             }
             $foot[] = $tot_total;
             $buffer->setFoot($foot);
             $buffer->closeTable();
             $html .= $buffer->get();
             break;
             //--------------------
         //--------------------
         case 'groups':
             //retrieve all labels
             $orgchart_labels = array();
             $query = "SELECT * FROM " . $fw . "_org_chart WHERE lang_code='" . getLanguage() . "'";
             $res = sql_query($query);
             while ($row = mysql_fetch_assoc($res)) {
                 $orgchart_labels[$row['id_dir']] = $row['translation'];
             }
             $labels = array();
             //$query = "SELECT * FROM ".$fw."_group WHERE (hidden='false' OR groupid LIKE '/oc_%' OR groupid LIKE '/ocd_%') AND type='free'";
             $query = "SELECT * FROM " . $fw . "_group WHERE groupid LIKE '/oc\\_%' OR groupid LIKE '/ocd\\_%' OR hidden = 'false' ";
             $res = sql_query($query);
             while ($row = mysql_fetch_assoc($res)) {
                 if ($row['hidden'] == 'false') {
                     $labels[$row['idst']] = $acl->relativeId($row['groupid']);
                 } else {
                     $temp = explode("_", $row['groupid']);
                     //echo '<div>'.print_r($temp,true).'</div>';
                     if ($temp[0] == '/oc') {
                         $labels[$row['idst']] = $temp[1] != 0 ? $orgchart_labels[$temp[1]] : '';
                     } elseif ($temp[0] == '/ocd') {
                         $labels[$row['idst']] = $temp[1] != 0 ? $orgchart_labels[$temp[1]] : '';
                     }
                 }
             }
             //solve groups user
             $solved_groups = array();
             $subgroups_list = array();
             foreach ($selection as $group) {
                 $temp = $acl->getGroupGDescendants($group);
                 $temp[] = $group;
                 foreach ($temp as $idst_subgroup) {
                     $solved_groups[$idst_subgroup] = $group;
                 }
                 $subgroups_list = array_merge($subgroups_list, $temp);
             }
             $query = "SELECT gm.idst as idGroup, YEAR(cu.date_complete) as yearComplete, MONTH(cu.date_complete) as monthComplete " . " FROM " . $lms . "_courseuser as cu JOIN " . $fw . "_group_members as gm ON (cu.idUser=gm.idstMember) " . " WHERE status=2 AND gm.idst IN (" . implode(",", $subgroups_list) . ")";
             $data = array();
             $res = sql_query($query);
             while ($row = mysql_fetch_assoc($res)) {
                 $idGroup = $solved_groups[$row['idGroup']];
                 $year = $row['yearComplete'];
                 $month = $row['monthComplete'];
                 switch ($timetype) {
                     case 'years':
                         if (!isset($data[$idGroup][$year])) {
                             $data[$idGroup][$year] = 0;
                         }
                         $data[$idGroup][$year]++;
                         break;
                     case 'months':
                         if (!isset($data[$idGroup][$year][$month])) {
                             $data[$idGroup][$year][$month] = 0;
                         }
                         $data[$idGroup][$year][$month]++;
                         break;
                 }
                 //end switch
             }
             //draw table
             $buffer = new ReportTablePrinter($type, true);
             $buffer->openTable('', '');
             $head = array($this->lang->def('_GROUPS'), $this->lang->def('_USERS'));
             foreach ($times as $time) {
                 $head[] = $time;
             }
             $head[] = $this->lang->def('_TOTAL');
             $buffer->openHeader();
             $buffer->addHeader($head);
             $buffer->closeHeader();
             $tot_users = 0;
             $tot_total = 0;
             $buffer->openBody();
             foreach ($selection as $group) {
                 $group_users = $acl->getGroupAllUser($group);
                 if ($userlevelid != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous()) {
                     $group_users = array_intersect($group_users, $admin_users);
                 }
                 $users_num = count($group_users);
                 $line = array();
                 $line_total = 0;
                 $line[] = $labels[$group];
                 $line[] = $users_num;
                 foreach ($times as $time) {
                     //years or months
                     switch ($timetype) {
                         case 'years':
                             if (isset($data[$group][$time])) {
                                 $line[] = $data[$group][$time];
                                 $line_total += $data[$group][$time];
                             } else {
                                 $line[] = '0';
                             }
                             break;
                         case 'months':
                             //$year = ...
                             //$month = ...
                             //$line[] = (isset($data[$group][$year][$month]) ? $data[$group][$year][$month] : '0'); break;
                     }
                 }
                 $line[] = $line_total;
                 $tot_users += $users_num;
                 $tot_total += $line_total;
                 $buffer->addLine($line);
             }
             $buffer->closeBody();
             //totals
             $foot = array('', $tot_users);
             foreach ($times as $time) {
                 $temp = 0;
                 foreach ($selection as $group) {
                     if (isset($data[$group][$time])) {
                         $temp += $data[$group][$time];
                     }
                 }
                 $foot[] = $temp;
             }
             $foot[] = $tot_total;
             $buffer->setFoot($foot);
             $buffer->closeTable();
             $html .= $buffer->get();
             break;
     }
     //end switch
     cout($html);
 }