public function special()
 {
     require_once _base_ . '/lib/lib.preference.php';
     $preference = new AdminPreference();
     $idst = Get::req('idst', DOTY_INT, 0);
     $output = array();
     if (Get::req('confirm', DOTY_INT, 0) == 1) {
         $rules = $preference->getRules();
         $new_rules = array();
         foreach ($rules as $path => $info) {
             switch ($info['type']) {
                 case 'enum':
                     $new_rules[$path] = Get::req(str_replace('.', '_', $path), DOTY_MIXED, 'off');
                     break;
                 case 'integer':
                     $new_rules[$path] = Get::req(str_replace('.', '_', $path), DOTY_INT, 0);
                     break;
             }
         }
         $output['success'] = $preference->saveSpecialAdminRules($idst, $new_rules);
         echo $this->json->encode($output);
     } else {
         $body = Form::openForm('add_rules_form', 'ajax.adm_server.php?r=adm/publicadminrules/special&confirm=1') . Form::openElementSpace() . $preference->getSpecialModifyMask($idst) . Form::closeElementSpace() . Form::closeForm();
         $output['success'] = true;
         $output['header'] = Lang::t('_MOD', 'adminrules') . ' ';
         $output['body'] = $body;
         echo $this->json->encode($output);
     }
 }
 public function sel_usersTask()
 {
     require_once _adm_ . '/lib/lib.directory.php';
     require_once _adm_ . '/class.module/class.directory.php';
     $base_url = 'index.php?r=adm/functionalroles/show';
     //check permissions: we should have mod privileges to assign users to the role group
     if (!$this->permissions['mod']) {
         Util::jump_to($base_url);
     }
     //read inputs
     $id_fncrole = Get::req('id_fncrole', DOTY_INT, -1);
     if ($id_fncrole <= 0) {
         $this->render('invalid', array('message' => $this->_getErrorMessage('invalid fncrole'), 'back_url' => $base_url));
         return;
     }
     //navigation urls
     $back_url = 'index.php?r=adm/functionalroles/man_users&id=' . (int) $id_fncrole;
     $jump_url = 'index.php?r=adm/functionalroles/sel_users&id_fncrole=' . (int) $id_fncrole;
     //competence details
     $info = $this->model->getFunctionalRoleInfo($id_fncrole);
     $name = $this->model->getFunctionalRoleName($id_fncrole);
     //page_title
     $page_title_arr = array($base_url => Lang::t('_FUNCTIONAL_ROLE', 'fncroles'), $back_url => Lang::t('_USERS', 'fncroles') . ': ' . $name, Lang::t('_ASSIGN_USERS', 'fncroles'));
     if (isset($_POST['cancelselector'])) {
         //--- UNDO: return to catalogue list -------------------------------------
         Util::jump_to($back_url);
     } elseif (isset($_POST['okselector'])) {
         //--- SAVE: users selection has been done --------------------------------
         $acl_man = Docebo::user()->getAclManager();
         $user_selector = new UserSelector();
         $selection = $user_selector->getSelection();
         $members_existent = $this->model->getMembers($id_fncrole);
         //retrieve newly selected users
         $_common_members = array_intersect($members_existent, $selection);
         $_new_members = array_diff($selection, $_common_members);
         //new users to add
         $_old_members = array_diff($members_existent, $_common_members);
         //old users to delete
         unset($_common_members);
         //free some memory
         //insert newly selected users in database
         $res1 = $this->model->assignMembers($id_fncrole, $_new_members);
         $res2 = $this->model->deleteMembers($id_fncrole, $_old_members);
         // apply enroll rules
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->applyRulesMultiLang('_LOG_USERS_TO_FNCROLE', $_new_members, false, $id_fncrole);
         //go back to main page, with result message
         Util::jump_to($back_url . '&res=' . ($res1 && $res2 ? 'ok_users' : 'err_users'));
     } else {
         //--- USER SELECTION IS IN PROGRESS: show selector -----------------------
         $user_selector = new UserSelector();
         $user_selector->show_user_selector = TRUE;
         $user_selector->show_group_selector = TRUE;
         $user_selector->show_orgchart_selector = TRUE;
         $user_selector->show_fncrole_selector = FALSE;
         //we can't assign functional roles to other functional roles ...
         //there should be a "role selector" too ...
         //$user_select->show_orgchart_simple_selector = TRUE;
         //filter selectable user by sub-admin permission
         $acl_man = Docebo::user()->getAclManager();
         $user_selector->setUserFilter('exclude', array($acl_man->getAnonymousId()));
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
             $user_selector->setUserFilter('user', $admin_users);
             $user_selector->setUserFilter('group', $admin_tree);
         }
         if (Get::req('is_updating', DOTY_INT, false)) {
             //...
         } else {
             //set initial selection
             $selection = $this->model->getMembers($id_fncrole);
             $user_selector->requested_tab = PEOPLEVIEW_TAB;
             $user_selector->resetSelection($selection);
         }
         $user_selector->addFormInfo(Form::getHidden('is_updating', 'is_updating', 1) . Form::getHidden('id_fncrole', 'id_fncrole', $id_fncrole));
         //draw selector
         $user_selector->loadSelector(Util::str_replace_once('&', '&amp;', $jump_url), $page_title_arr, Lang::t('_ASSIGN_USERS_TO_FNCROLE', 'fncroles'), true);
     }
 }
 public function lang()
 {
     require_once _base_ . '/lib/lib.preference.php';
     $preference = new AdminPreference();
     $idst = Get::req('idst', DOTY_INT, 0);
     $output = array();
     if (Get::req('confirm', DOTY_INT, 0) == 1) {
         $new_lang = array();
         if (isset($_POST['admin_lang'])) {
             $new_lang = array_keys($_POST['admin_lang']);
         }
         $new_lang = $this->json->encode($new_lang);
         $output['success'] = $preference->saveLangAdminRules($idst, $new_lang);
         echo $this->json->encode($output);
     } else {
         $body = Form::openForm('add_rules_form', 'ajax.adm_server.php?r=adm/adminrules/lang&confirm=1') . Form::openElementSpace() . Form::getHidden('idst', 'idst', $idst) . $preference->getLangModifyMask($idst) . Form::closeElementSpace() . Form::closeForm();
         $output['success'] = true;
         $output['header'] = Lang::t('_MOD', 'adminrules') . '&nbsp;';
         $output['body'] = $body;
         echo $this->json->encode($output);
     }
 }
Пример #4
0
 public function getCourseSubscribedUserIdst($id_course, $no_flat = false, $filter = '')
 {
     if (is_numeric($id_course)) {
         $arr = array($id_course);
     } elseif (is_array($id_course) && count($id_course) > 0) {
         $arr =& $id_course;
     } else {
         return false;
     }
     $query = "SELECT s.idUser, s.idCourse " . " FROM " . $this->subscribe_table . " AS s " . " JOIN " . $this->user_table . " AS u ON u.idst = s.idUser " . " WHERE s.idCourse IN (" . implode(",", $arr) . ") ";
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $query .= " AND " . $adminManager->getAdminUsersQuery(Docebo::user()->getIdSt(), 's.idUser');
     }
     if (is_array($filter)) {
         if (isset($filter['text']) && $filter['text'] != "") {
             $query .= " AND (u.userid LIKE '%" . $filter['text'] . "%' OR u.firstname LIKE '%" . $filter['text'] . "%' OR u.lastname LIKE '%" . $filter['text'] . "%') ";
         }
         $arr_idst = array();
         if (isset($filter['orgchart']) && $filter['orgchart'] > 0) {
             $umodel = new UsermanagementAdm();
             $use_desc = isset($filter['descendants']) && $filter['descendants'];
             $ulist = $umodel->getFolderUsers($filter['orgchart'], $use_desc);
             if (!empty($ulist)) {
                 $arr_idst = $ulist;
             }
             unset($ulist);
         }
         if (!empty($arr_idst)) {
             $conditions[] = " AND u.idst IN (" . implode(",", $arr_idst) . ") ";
         }
         if (isset($filter['date_valid']) && strlen($filter['date_valid']) >= 10) {
             $query .= " AND (s.date_begin_validity <= '" . $filter['date_valid'] . "' OR s.date_begin_validity IS NULL OR s.date_begin_validity='0000-00-00 00:00:00') ";
             $query .= " AND (s.date_expire_validity >= '" . $filter['date_valid'] . "' OR s.date_expire_validity IS NULL OR s.date_expire_validity='0000-00-00 00:00:00') ";
         }
     }
     $result = $this->db->query($query);
     $res = array();
     while (list($id_user, $id_course) = $this->db->fetch_row($result)) {
         if ($no_flat) {
             $res[$id_course][$id_user] = $id_user;
         } else {
             $res[$id_user] = (int) $id_user;
         }
     }
     if (!$no_flat) {
         $res = array_unique($res);
     }
     return $res;
 }
Пример #5
0
 function &getAllUserIdst()
 {
     $p_dr = new PeopleDataRetriever($GLOBALS['dbConn'], $GLOBALS['prefix_fw']);
     $userlevelid = Docebo::user()->getUserLevelId();
     if ($userlevelid != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $p_dr->intersectGroupFilter($adminManager->getAdminTree(Docebo::user()->getIdSt()));
     }
     $re_people = $p_dr->getAllRowsIdst();
     $user_selected = array();
     if (!$re_people) {
         return $user_selected;
     }
     while (list($idst) = sql_fetch_row($re_people)) {
         $user_selected[$idst] = $idst;
     }
     return $user_selected;
 }
Пример #6
0
 function loadCatalogueSelector($noprint = false)
 {
     require_once _base_ . '/lib/lib.table.php';
     require_once _base_ . '/lib/lib.form.php';
     $lang =& DoceboLanguage::createInstance('catalogue', 'lms');
     // Filter
     $this->filter['catalogue_name'] = isset($_POST['cat_filter_name']) ? $_POST['cat_filter_name'] : '';
     if ($this->show_filter === true) {
         $form = new Form();
         /*$GLOBALS['page']->add(
         			$form->getOpenFieldset($lang->def('_SEARCH'))
         			.Form::getTextfield($lang->def('_NAME'), 'cat_filter_name', 'cat_filter_name', '255',
         				( isset($_POST['cat_filter_name']) ? $_POST['cat_filter_name'] : '' ))
         			.$form->openButtonSpace()
         			.$form->getButton('catalogue_filter', 'catalogue_filter', $lang->def('_SEARCH'))
         			.$form->closeButtonSpace()
         			.$form->getCloseFieldset()
         		, 'content');
         		*/
         cout('<div class="quick_search_form">' . '<div>' . Form::getInputTextfield("search_t", "cat_filter_name", "cat_filter_name", Get::req('cat_filter_name', DOTY_MIXED, ''), '', 255, '') . Form::getButton("catalogue_filter", "catalogue_filter", Lang::t('_SEARCH', 'standard'), "search_b") . '</div>' . '</div>', 'content');
     }
     // End Filter
     $tb = new Table(Get::sett('visuItem'), $lang->def('_CATALOGUE'), $lang->def('_CATALOGUE_SUMMARY'));
     $tb->initNavBar('ini_cat', 'button');
     $ini = $tb->getSelectedElement();
     $select = "\r\n\t\tSELECT c.idCatalogue, c.name, c.description";
     $query_catalogue = "\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_catalogue AS c\r\n\t\tWHERE 1";
     // Retriving data
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         $all_courses = false;
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_courses = $adminManager->getAdminCourse(Docebo::user()->getIdST());
         if (isset($admin_courses['course'][0])) {
             $all_courses = true;
         }
         if (isset($admin_courses['course'][-1])) {
             require_once _lms_ . '/lib/lib.catalogue.php';
             $cat_man = new Catalogue_Manager();
             $admin_courses['catalogue'] = $cat_man->getUserAllCatalogueId(Docebo::user()->getIdSt());
             if (count($admin_courses['catalogue']) == 0 && Get::sett('on_catalogue_empty', 'off') == 'on') {
                 $all_courses = true;
             }
         }
         if (!$all_courses) {
             if (empty($admin_courses['catalogue'])) {
                 $query_catalogue .= " AND 0 ";
             } else {
                 $query_catalogue .= " AND c.idCatalogue IN (0," . implode(',', $admin_courses['catalogue']) . ") ";
             }
         }
     }
     if ($this->filter['catalogue_name'] != '') {
         $query_catalogue .= " AND c.name LIKE '%" . $this->filter['catalogue_name'] . "%'";
     }
     list($tot_catalogue) = sql_fetch_row(sql_query("SELECT COUNT(*) " . $query_catalogue));
     $query_catalogue .= " ORDER BY c.name\r\n\t\t\t\t\t\t\tLIMIT " . $ini . "," . (int) Get::sett('visuItem');
     $re_catalogue = sql_query($select . $query_catalogue);
     $type_h = array('image', '', '', '');
     $cont_h = array('<span class="access-only">' . $lang->def('_CATALOGUE_SELECTION') . '</span>', $lang->def('_NAME'), $lang->def('_DESCRIPTION'));
     $tb->setColsStyle($type_h);
     $tb->addHead($cont_h);
     while (list($id_catalogue, $name, $descr) = sql_fetch_row($re_catalogue)) {
         $tb_content = array(Form::getInputCheckbox('new_catalogue_selected_' . $id_catalogue, 'new_catalogue_selected[' . $id_catalogue . ']', $id_catalogue, isset($this->current_selection[$id_catalogue]), ''), '<label for="new_catalogue_selected_' . $id_catalogue . '">' . $name . '</label>', '<label for="new_catalogue_selected_' . $id_catalogue . '">' . $descr . '</label>');
         $tb->addBody($tb_content);
         if (isset($this->current_selection[$id_catalogue])) {
             unset($this->current_selection[$id_catalogue]);
         }
     }
     $output = $tb->getTable() . $tb->getNavBar($ini, $tot_catalogue) . $this->stateSelection();
     if ($noprint) {
         return $output;
     } else {
         cout($output, 'content');
     }
 }
Пример #7
0
 function modcatalogueassoc()
 {
     checkPerm('mod');
     $lang =& DoceboLanguage::createInstance('catalogue', 'lms');
     $acl_man =& Docebo::user()->getAclManager();
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     require_once _base_ . '/lib/lib.form.php';
     require_once _base_ . '/lib/lib.userselector.php';
     $id_catalogue = importVar('id_catalogue', true, 0);
     $out =& $GLOBALS['page'];
     $user_select = new UserSelector();
     $user_select->show_user_selector = FALSE;
     $user_select->show_group_selector = TRUE;
     $user_select->show_orgchart_selector = TRUE;
     $user_select->show_orgchart_simple_selector = TRUE;
     $user_select->multi_choice = TRUE;
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
         $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
         $user_select->setUserFilter('user', $admin_users);
         $user_select->setUserFilter('group', $admin_tree);
     }
     if (isset($_POST['okselector'])) {
         $old_members = array();
         $re_members = sql_query("\r\n\t\tSELECT idst_member\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_catalogue_member\r\n\t\tWHERE idCatalogue = '" . $id_catalogue . "'");
         while (list($id_members) = sql_fetch_row($re_members)) {
             $old_members[$id_members] = $id_members;
         }
         $new_members = $user_select->getSelection($_POST);
         $to_add = array_diff($new_members, $old_members);
         $to_del = array_diff($old_members, $new_members);
         $re = true;
         $re &= addToCatologue($to_add, $id_catalogue);
         $re &= removeFromCatologue($to_del, $id_catalogue);
         Util::jump_to('index.php?modname=catalogue&op=catlist&result=' . ($re ? 'ok' : 'err'));
     }
     if (isset($_GET['load'])) {
         $members = array();
         $re_members = sql_query("\r\n\t\tSELECT idst_member\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_catalogue_member\r\n\t\tWHERE idCatalogue = '" . $id_catalogue . "'");
         while (list($id_members) = sql_fetch_row($re_members)) {
             $members[$id_members] = $id_members;
         }
         $user_select->resetSelection($members);
     }
     $title_area = getTitleArea(array('index.php?modname=catalogue&amp;op=catlist' => $lang->def('_CATALOGUE'), getCatalogueName($id_catalogue)), 'catalogue');
     $user_select->setPageTitle($title_area);
     $user_select->loadSelector('index.php?modname=catalogue&amp;op=modcatalogueassoc&amp;id_catalogue=' . $id_catalogue, $lang->def('_CATALOGUE'), $lang->def('_ASSIGN_USERS'), true);
 }
Пример #8
0
 function _get_games_query($type = 'html', $report_data = NULL, $other = '')
 {
     require_once dirname(__FILE__) . '/report_tableprinter.php';
     if ($report_data == NULL) {
         $ref =& $_SESSION['report_tempdata'];
     } else {
         $ref =& $report_data;
     }
     $_ERR_NOUSER = Lang::t('_EMPTY_SELECTION', 'report');
     $_ERR_NOCOMP = Lang::t('_EMPTY_SELECTION', 'report');
     $_ERR_NODATA = Lang::t('_NO_CONTENT', 'report');
     //LO object types translations
     require_once _lms_ . '/lib/lib.report.php';
     $lang_type = _getLOtranslations();
     $sel_all = $ref['rows_filter']['all_users'];
     $arr_selected_users = $ref['rows_filter']['users'];
     //list of users selected in the filter (users, groups and org.branches)
     $comp_all = isset($ref['columns_filter']['all_games']) ? $ref['columns_filter']['all_games'] : false;
     $arr_selected_comp = isset($ref['columns_filter']['comp_selection']) ? $ref['columns_filter']['comp_selection'] : array();
     //list of communications selected in the filter
     $start_date = isset($ref['columns_filter']['comp_start_date']) ? substr($ref['columns_filter']['comp_start_date'], 0, 10) : '';
     $end_date = isset($ref['columns_filter']['comp_end_date']) ? substr($ref['columns_filter']['comp_end_date'], 0, 10) : '';
     //check and validate time period dates
     if (!preg_match('/^(\\d{4})\\D?(0[1-9]|1[0-2])\\D?([12]\\d|0[1-9]|3[01])$/', $start_date) || $start_date == '0000-00-00') {
         $start_date = '';
     }
     if (!preg_match('/^(\\d{4})\\D?(0[1-9]|1[0-2])\\D?([12]\\d|0[1-9]|3[01])$/', $end_date) || $end_date == '0000-00-00') {
         $end_date = '';
     }
     if ($start_date != '') {
         $start_date .= ' 00:00:00';
     }
     if ($end_date != '') {
         $end_date .= ' 23:59:59';
     }
     if ($start_date != '' && $end_date != '') {
         if ($start_date > $end_date) {
             //invalid time period
             $start_date = '';
             $end_date = '';
         }
     }
     //other checkings and validations
     if (!$sel_all && count($selection) <= 0) {
         cout('<p>' . $_ERR_NOUSER . '</p>');
         return;
     }
     $acl_man = new DoceboACLManager();
     $acl_man->include_suspended = true;
     //extract user idst from selection
     if ($sel_all) {
         $arr_selected_users = $acl_man->getAllUsersIdst();
     } else {
         $arr_selected_users = $acl_man->getAllUsersFromIdst($arr_selected_users);
     }
     if ($comp_all) {
         $query = "SELECT id_game FROM %lms_games";
         $res = $this->db->query($query);
         $arr_selected_comp = array();
         while (list($id_game) = $this->db->fetch_row($res)) {
             $arr_selected_comp[] = $id_game;
         }
     }
     //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);
         //filter users selection by admin visible users
         $arr_selected_users = array_intersect($arr_selected_users, $admin_users);
         //free some memory
         unset($admin_tree);
         unset($admin_users);
         unset($adminManager);
     }
     //check selected users ...
     if (count($arr_selected_users) <= 0) {
         //message: no users selected
         cout('<p>' . $_ERR_NOUSER . '</p>');
         return;
     }
     //check selected communications ...
     if (count($arr_selected_comp) <= 0) {
         //message: no communications selected
         cout('<p>' . $_ERR_NOCOMP . '</p>');
         return;
     }
     //set table properties and buffer
     $head = array(Lang::t('_GAMES_TITLE', 'report'), Lang::t('_GAMES_TYPE', 'report'), Lang::t('_FROM', 'report'), Lang::t('_TO', 'report'), Lang::t('_USER', 'report'), Lang::t('_GAMES_ATTEMPTED', 'report'), Lang::t('_GAMES_ATTEMPT_DATE', 'report'), Lang::t('_GAMES_FIRST_ATTEMPT_DATE', 'report'), Lang::t('_GAMES_CURRENT_SCORE', 'report'), Lang::t('_GAMES_MAX_SCORE', 'report'), Lang::t('_GAMES_NUM_ATTEMPTS', 'report'));
     if ($this->use_mail) {
         $head[] = array('style' => 'img-cell', 'value' => $this->_loadEmailIcon());
     }
     $buffer = new ReportTablePrinter();
     $buffer->openTable('', '');
     $buffer->openHeader();
     $buffer->addHeader($head);
     $buffer->closeHeader();
     $buffer->openBody();
     //rows cycle
     //which selected communication has been seen by selected users?
     $_YES = Lang::t('_YES', 'standard');
     $_NO = Lang::t('_NO', 'standard');
     $arr_viewed = array();
     $query = "SELECT ct.idReference, c.title, c.type_of, c.start_date, c.end_date, ct.status, " . " ct.dateAttempt, ct.firstAttempt, ct.idUser, u.userid, u.firstname, u.lastname, " . " ct.current_score, ct.max_score, ct.num_attempts " . " FROM (%lms_games_track as ct " . " JOIN %lms_games as c ON (ct.idReference=c.id_game)) " . " JOIN %adm_user as u ON (ct.idUser=u.idst) " . " WHERE ct.idUser IN (" . implode(",", $arr_selected_users) . ") " . " AND c.id_game IN (" . implode(",", $arr_selected_comp) . ") " . ($start_date != '' ? " AND ct.dateAttempt >= '" . $start_date . "' " : "") . ($end_date != '' ? " AND ct.dateAttempt <= '" . $end_date . "' " : "") . " ORDER BY c.title, u.userid";
     $res = $this->db->query($query);
     if ($this->db->num_rows($res) <= 0) {
         cout('<p>' . $_ERR_NODATA . '</p>');
         return;
     }
     while ($obj = $this->db->fetch_obj($res)) {
         $line = array();
         $line[] = $obj->title;
         $line[] = isset($lang_type[$obj->type_of]) ? $lang_type[$obj->type_of] : '';
         $line[] = Format::date($obj->start_date, "date");
         $line[] = Format::date($obj->end_date, "date");
         $line[] = $acl_man->relativeId($obj->userid);
         $line[] = $obj->status == 'completed' || $obj->status == 'passed' ? $_YES : $_NO;
         $line[] = Format::date($obj->dateAttempt, "datetime");
         $line[] = Format::date($obj->firstAttempt, "datetime");
         $line[] = $obj->current_score;
         $line[] = $obj->max_score;
         $line[] = $obj->num_attempts;
         if ($this->use_mail) {
             $line[] = '<div class="align_center">' . Form::getInputCheckbox('mail_' . $obj->idUser, 'mail_recipients[]', $obj->idUser, isset($_POST['select_all']), '') . '</div>';
         }
         $buffer->addLine($line);
     }
     $buffer->closeBody();
     $buffer->closeTable();
     cout($buffer->get());
     $this->_loadEmailActions();
 }
Пример #9
0
 public function searchFunctionalRolesByName($query, $limit = false, $language = false, $filter = false)
 {
     if ((int) $limit <= 0) {
         $limit = Get::sett('visuItem', 25);
     }
     $output = array();
     $_qfilter = "";
     if ($filter) {
         $ulevel = Docebo::user()->getUserLevelId();
         if ($ulevel != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             $_qfilter .= " AND g.idst IN (" . implode(",", $admin_tree) . ") ";
         }
     }
     $lang_code = $language ? $language : getLanguage();
     $query = "SELECT g.idst as id_fncrole, l.name FROM %adm_group as g " . " JOIN " . $this->_getRolesLangTable() . " as l ON (g.idst = l.id_fncrole AND l.lang_code='" . $lang_code . "')" . " WHERE l.name LIKE '%" . $query . "%' " . $_qfilter . " ORDER BY l.name " . ((int) $limit > 0 ? " LIMIT 0, " . (int) $limit : "");
     $res = $this->db->query($query);
     if ($res) {
         while ($obj = $this->db->fetch_obj($res)) {
             $output[] = $obj;
         }
     }
     return $output;
 }
Пример #10
0
 public function searchGroupsByGroupid($query, $limit = false, $filter = false)
 {
     if ((int) $limit <= 0) {
         $limit = Get::sett('visuItem', 25);
     }
     $output = array();
     $_qfilter = "";
     if ($filter) {
         $ulevel = Docebo::user()->getUserLevelId();
         if ($ulevel != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             //$admin_groups = $this->_extractGroupsFromMixedIdst($admin_tree);
             $_qfilter .= " AND idst IN (" . implode(",", $admin_tree) . ") ";
         }
     }
     $query = "SELECT idst, groupid FROM %adm_group " . " WHERE groupid LIKE '%" . $query . "%' " . $_qfilter . " " . " AND hidden='false' AND type<>'course' ORDER BY groupid " . ((int) $limit > 0 ? " LIMIT 0, " . (int) $limit : "");
     $res = $this->db->query($query);
     if ($res) {
         while ($obj = $this->db->fetch_obj($res)) {
             $output[] = $obj;
         }
     }
     return $output;
 }
 protected function _getUnsubscribeSelectAll()
 {
     $filter_text = Get::req('filter_text', DOTY_STRING, "");
     $filter_course = Get::req('filter_course', DOTY_INT, 0);
     $courses_filter = FALSE;
     $ulevel = Docebo::user()->user_level;
     if ($ulevel != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $preference = new AdminPreference();
         $view = $preference->getAdminCourse(Docebo::user()->idst);
         $all_courses = false;
         if (isset($view['course'][0])) {
             $all_courses = true;
         } elseif (isset($view['course'][-1])) {
             require_once _lms_ . '/lib/lib.catalogue.php';
             $cat_man = new Catalogue_Manager();
             $user_catalogue = $cat_man->getUserAllCatalogueId(Docebo::user()->getIdSt());
             if (count($user_catalogue) > 0) {
                 $courses = array(0);
                 foreach ($user_catalogue as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat);
                     $courses = array_merge($courses, $catalogue_course);
                 }
                 foreach ($courses as $id_course) {
                     if ($id_course != 0) {
                         $view['course'][$id_course] = $id_course;
                     }
                 }
             } elseif (Get::sett('on_catalogue_empty', 'off') == 'on') {
                 $all_courses = true;
             }
         } else {
             $array_courses = array();
             $array_courses = array_merge($array_courses, $view['course']);
             if (!empty($view['coursepath'])) {
                 require_once _lms_ . '/lib/lib.coursepath.php';
                 $path_man = new Catalogue_Manager();
                 $coursepath_course =& $path_man->getAllCourses($view['coursepath']);
                 $array_courses = array_merge($array_courses, $coursepath_course);
             }
             if (!empty($view['catalogue'])) {
                 require_once _lms_ . '/lib/lib.catalogue.php';
                 $cat_man = new Catalogue_Manager();
                 foreach ($view['catalogue'] as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     $array_courses = array_merge($array_courses, $catalogue_course);
                 }
             }
             $view['course'] = array_merge($view['course'], $array_courses);
         }
         if (!$all_courses) {
             $courses_filter = $view['course'];
         }
     }
     if ($filter_course > 0) {
         if ($courses_filter === FALSE) {
             $courses_filter = (int) $filter_course;
         } else {
             if (!in_array($filter_course, $courses_filter)) {
                 $courses_filter = array();
             } else {
                 $courses_filter = (int) $filter_course;
             }
         }
     }
     $filter = array();
     if ($filter_text != "") {
         $filter['text'] = $filter_text;
     }
     if (is_array($courses_filter)) {
         $filter['course'] = $courses_filter;
     }
     $output = $this->model->getUnsubscribeRequestsAll($filter);
     echo $this->json->encode($output);
 }
 function createuser_action()
 {
     //check permissions
     if (!$this->permissions['add_user']) {
         $output = array('success' => false, 'message' => $this->_getErrorMessage('no permission'));
         echo $this->echoResult($output);
         return;
     }
     $userid = Get::req('username', DOTY_STRING, '');
     $password = Get::Req('password', DOTY_STRING, '');
     $password_confirm = Get::req('password_confirm', DOTY_STRING, '');
     $output = array();
     if ($userid == '') {
         $output['success'] = false;
         $output['message'] = Lang::t('_ERR_INVALID_USER', 'register');
         echo $this->echoResult($output);
         return;
     }
     if ($password != $password_confirm) {
         $output['success'] = false;
         $output['message'] = Lang::t('_ERR_PASSWORD_NO_MATCH', 'register');
         echo $this->echoResult($output);
         return;
     }
     $userdata = new stdClass();
     $userdata->userid = trim($userid);
     $userdata->firstname = trim(Get::req('firstname', DOTY_STRING, ''));
     $userdata->lastname = trim(Get::req('lastname', DOTY_STRING, ''));
     $userdata->email = trim(Get::req('email', DOTY_STRING, ''));
     $userdata->password = $password;
     $userdata->force_change = trim(Get::Req('force_changepwd', DOTY_INT, 0));
     /* $userdata->facebook_id = Get::pReq('facebook_id', DOTY_STRING, '');
     		$userdata->twitter_id = Get::pReq('twitter_id', DOTY_STRING, '');
     		$userdata->linkedin_id = Get::pReq('linkedin_id', DOTY_STRING, '');
     		$userdata->google_id = Get::pReq('google_id', DOTY_STRING, ''); */
     if (Docebo::user()->user_level == ADMIN_GROUP_GODADMIN) {
         $userdata->level = Get::req('level', DOTY_STRING, ADMIN_GROUP_USER);
     } else {
         $userdata->level = ADMIN_GROUP_USER;
     }
     if (!$this->model->checkUserid($userdata->userid)) {
         $output['success'] = false;
         $output['message'] = Lang::t('_USERID_DUPLICATE', 'organization_chart');
         echo $this->echoResult($output);
         return;
     }
     if (!$this->_canUseLevel($userdata->level)) {
         $output['success'] = false;
         $output['message'] = Lang::t('_OPERATION_FAILURE', 'standard');
         echo $this->echoResult($output);
         return;
     }
     if (Get::sett('pass_change_first_login', 'off') == 'on') {
         $userdata->force_change = 1;
     }
     $userdata->preferences =& $_POST;
     $folders = Get::req('sel', DOTY_MIXED, false);
     $idst = $this->model->createUser($userdata, $folders);
     if (is_numeric($idst) && $idst > 0) {
         $output['success'] = true;
         $output['idst'] = $idst;
         $output['total_users'] = $this->model->getUsersCount();
         $output['message'] = Lang::t('_OPERATION_SUCCESSFUL', 'standard') . ': ' . $userid;
         // Send alert:
         require_once _base_ . '/lib/lib.eventmanager.php';
         $acl_man = Docebo::user()->getAclManager();
         $array_subst = array('[url]' => Get::sett('url'), '[userid]' => $userid, '[password]' => $password);
         $e_msg = new EventMessageComposer();
         $e_msg->setSubjectLangText('email', '_REGISTERED_USER_SBJ', false);
         $e_msg->setBodyLangText('email', '_REGISTERED_USER_TEXT', $array_subst);
         $e_msg->setBodyLangText('sms', '_REGISTERED_USER_TEXT_SMS', $array_subst);
         $recipients = array($idst);
         if (!empty($recipients)) {
             createNewAlert('UserNew', 'directory', 'edit', '1', 'New user created', $recipients, $e_msg);
             ob_clean();
         }
         // Increment the counter for users created by this admin:
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             $admin_pref = new AdminPreference();
             $pref = $admin_pref->getAdminRules(Docebo::user()->getIdSt());
             if ($pref['admin_rules.limit_user_insert'] == 'on') {
                 $user_pref = new UserPreferences(Docebo::user()->getIdSt());
                 $user_created_count = (int) $user_pref->getPreference('user_created_count');
                 $user_created_count++;
                 $user_pref->setPreference('user_created_count', $user_created_count);
                 if ($user_created_count >= $pref['admin_rules.max_user_insert']) {
                     $output['force_page_refresh'] = true;
                     $output['message'] = Lang::t('_USER_CREATED_MAX_REACHED', 'admin_directory');
                 }
             }
         }
     } else {
         $output['success'] = false;
         $output['message'] = Lang::t('_OPERATION_FAILURE', 'standard');
     }
     $this->echoResult($output);
 }
Пример #13
0
 function addsubscription()
 {
     checkPerm('subscribe');
     require_once _base_ . '/lib/lib.form.php';
     require_once _adm_ . '/class.module/class.directory.php';
     require_once _lms_ . '/lib/lib.subscribe.php';
     require_once _lms_ . '/lib/lib.coursepath.php';
     $id_path = importVar('id_path', true, 0);
     $lang =& DoceboLanguage::createInstance('coursepath', 'lms');
     $out =& $GLOBALS['page'];
     $acl_man =& Docebo::user()->getAclManager();
     if (isset($_POST['cancelselector'])) {
         Util::jump_to('index.php?modname=coursepath&amp;op=pathlist');
     }
     $user_select = new UserSelector();
     $user_select->show_user_selector = TRUE;
     $user_select->show_group_selector = TRUE;
     $user_select->show_orgchart_selector = TRUE;
     $user_select->show_orgchart_simple_selector = TRUE;
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
         $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
         $user_select->setUserFilter('user', $admin_users);
         $user_select->setUserFilter('group', $admin_tree);
     }
     $query_pathlist = "\r\n\tSELECT path_name, subscribe_method\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursepath\r\n\tWHERE id_path = '" . $id_path . "'\r\n\tORDER BY path_name ";
     list($path_name, $subscribe_method) = sql_fetch_row(sql_query($query_pathlist));
     if (isset($_GET['load'])) {
         $cp_man = new CoursePath_Manager();
         $users = $cp_man->getSubscribed($id_path);
         $user_select->resetSelection($users);
     }
     if (isset($_POST['okselector'])) {
         $acl_manager = new DoceboACLManager();
         $user_selected = $user_select->getSelection($_POST);
         $user_selected =& $acl_manager->getAllUsersFromIdst($user_selected);
         $user_selected = array_unique($user_selected);
         $cp_man = new CoursePath_Manager();
         $users = $cp_man->getSubscribed($id_path);
         $user_selected = array_diff($user_selected, $users);
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
             $user_selected = array_intersect($user_selected, $admin_users);
         }
         if (empty($user_selected)) {
             Util::jump_to('index.php?modname=coursepath&amp;op=pathlist');
         }
         $cpath_man = new CoursePath_Manager();
         $subs_man = new CourseSubscribe_Management();
         $courses = $cpath_man->getAllCourses(array($id_path));
         require_once $GLOBALS['where_lms'] . '/lib/lib.coursepath.php';
         $course_man = new Man_Course();
         $classroom = $course_man->getAllCourses(false, 'classroom', $courses);
         $edition = $course_man->getAllCourses(false, 'edition', $courses);
         if (!empty($classroom) || !empty($edition)) {
             $user_selected_post = urlencode(serialize($user_selected));
             cout(getTitleArea(array('index.php?modname=coursepath&amp;op=pathlist' => $lang->def('_COURSEPATH'), $path_name), 'coursepath') . '<div class="std_block">' . Form::openForm('edition_selection_form', 'index.php?modname=coursepath&amp;op=addsubscriptionedition&amp;id_path=' . $id_path) . Form::getHidden('users', 'users', $user_selected_post));
             if (!empty($classroom)) {
                 require_once _lms_ . '/lib/lib.date.php';
                 $date_man = new DateManager();
                 foreach ($classroom as $id_course => $info) {
                     $editions = $date_man->getCourseDate($id_course, true);
                     $edition_for_dropdown = array();
                     $edition_for_dropdown[0] = Lang::t('_NONE', 'coursepath');
                     foreach ($editions as $editions_info) {
                         $edition_for_dropdown[$editions_info['id_date']] = $editions_info['code'] . ' - ' . $editions_info['name'] . ' - ' . Format::date($editions_info['date_begin'], 'date') . ' - ' . Format::date($editions_info['date_end'], 'date');
                     }
                     cout(Form::getDropdown(Lang::t('_EDITION_SELECTION', 'coursepath') . ' : ' . $info['code'] . ' - ' . $info['name'], 'classroom_' . $id_course, 'classroom_' . $id_course, $edition_for_dropdown));
                 }
             }
             if (!empty($edition)) {
                 require_once _lms_ . '/lib/lib.edition.php';
                 $edition_man = new EditionManager();
                 foreach ($edition as $id_course => $info) {
                     $editions = $edition_man->getEditionsInfoByCourses($id_course);
                     $edition_for_dropdown = array();
                     $edition_for_dropdown[0] = Lang::t('_NONE', 'coursepath');
                     foreach ($editions[$id_course] as $editions_info) {
                         $edition_for_dropdown[$editions_info['id_edition']] = $editions_info['code'] . ' - ' . $editions_info['name'] . ' - ' . Format::date($editions_info['date_begin'], 'date') . ' - ' . Format::date($editions_info['date_end'], 'date');
                     }
                     cout(Form::getDropdown(Lang::t('_EDITION_SELECTION', 'coursepath') . ' : ' . $info['code'] . ' - ' . $info['name'], 'edition_' . $id_course, 'edition_' . $id_course, $edition_for_dropdown));
                 }
             }
             cout(Form::openButtonSpace() . Form::getButton('save', 'save', Lang::t('_SAVE', 'coursepath')) . Form::getButton('undo', 'undo', Lang::t('_UNDO', 'coursepath')) . Form::closeButtonSpace() . Form::closeForm() . '</div>');
         } else {
             $re = true;
             if ($subscribe_method != 1 && !checkPerm('moderate', true)) {
                 $waiting = 1;
             } else {
                 $waiting = 0;
             }
             $users_subsc = array();
             require_once $GLOBALS['where_lms'] . '/lib/lib.coursepath.php';
             $course_man = new Man_Course();
             $assessment = $course_man->getAllCourses(false, 'assessment', $courses);
             while (list(, $id_user) = each($user_selected)) {
                 $text_query = "\r\n\t\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_coursepath_user\r\n\t\t\t\t( id_path, idUser, waiting, subscribed_by ) VALUES\r\n\t\t\t\t( '" . $id_path . "', '" . $id_user . "', '" . $waiting . "', '" . getLogUserId() . "' )";
                 $re_s = sql_query($text_query);
                 if ($re_s == true) {
                     $users_subsc[] = $id_user;
                 }
                 $re &= $re_s;
                 foreach ($assessment as $id_assessment => $assessment_info) {
                     sql_query("INSERT INTO %lms_assessment_user (id_assessment, id_user, type_of) VALUES ('" . $id_assessment . "', '" . $id_user . "', 'user')");
                 }
             }
             // now subscribe user to all the course
             if ($waiting == 0) {
                 $re &= $subs_man->multipleSubscribe($users_subsc, $courses, 3);
             }
             Util::jump_to('index.php?modname=coursepath&amp;op=pathlist&result=' . ($re ? 'ok' : 'err'));
         }
     } else {
         $user_select->setPageTitle(getTitleArea(array('index.php?modname=coursepath&amp;op=pathlist' => $lang->def('_COURSEPATH'), $path_name), 'coursepath'));
         $user_select->loadSelector('index.php?modname=coursepath&amp;op=addsubscription&amp;id_path=' . $id_path, $lang->def('_SUBSCRIBE'), false, true);
     }
 }
 public function assign_users()
 {
     //check permissions
     if (!$this->permissions['associate_user']) {
         Util::jump_to('index.php?r=' . $this->base_link_competence . '/show');
     }
     require_once _adm_ . '/lib/lib.directory.php';
     require_once _adm_ . '/class.module/class.directory.php';
     //read inputs
     $id_competence = Get::req('id_competence', DOTY_INT, -1);
     if ($id_competence <= 0) {
         $this->render('invalid', array('message' => $this->_getErrorMessage("invalid competence"), 'back_url' => 'index.php?r=' . $this->base_link_competence . '/show'));
         return;
     }
     //navigation urls
     $back_url = 'index.php?r=' . $this->base_link_competence . '/show_users&id=' . (int) $id_competence;
     $jump_url = 'index.php?r=' . $this->base_link_competence . '/assign_users&id=' . (int) $id_competence;
     //competence details
     $info = $this->model->getCompetenceInfo($id_competence);
     $name = $this->model->getCompetenceName($id_competence);
     //page_title
     $page_title_arr = array($back_url => Lang::t('_COMPETENCES', 'competences'), $name, Lang::t('_ASSIGN_USERS', 'competences'));
     if (isset($_POST['cancelselector'])) {
         //--- UNDO: return to catalogue list -------------------------------------
         Util::jump_to($back_url);
     } elseif (isset($_POST['okselector'])) {
         //--- SAVE: users selection has been done --------------------------------
         $acl_man = Docebo::user()->getAclManager();
         $user_selector = new UserSelector();
         $selection = $user_selector->getSelection($_POST);
         $users_selected =& $acl_man->getAllUsersFromIdst($selection);
         $competence_users = $this->model->getCompetenceUsers($id_competence, true);
         $users_existent = array_keys($competence_users);
         //retrieve newly selected users
         $_common_users = array_intersect($users_existent, $users_selected);
         $_new_users = array_diff($users_selected, $_common_users);
         $_old_users = array_diff($users_existent, $_common_users);
         unset($_common_users);
         //free some memory
         //if no users to add: check removed users (if any) then go back
         if (empty($_new_users)) {
             $res = $this->model->removeCompetenceUsers($id_competence, $_old_users, true);
             $message = $res ? 'ok_assign' : 'err_assign';
             Util::jump_to('index.php?r=' . $this->base_link_competence . '/show_users&id=' . (int) $id_competence . '&res=' . $message);
         }
         //assign scores, if the competence type is 'score' (otherwise assign directly score 1 and go back)
         $type = $info->type;
         if ($type == 'score') {
             require_once _base_ . '/lib/lib.table.php';
             $table = new Table();
             $head_label = array();
             $head_style = array();
             $head_label[] = Lang::t('_USERNAME', 'standard');
             $head_label[] = Lang::t('_NAME');
             $head_label[] = Lang::t('_SCORE', 'competences');
             $head_style[] = '';
             $head_style[] = '';
             $head_style[] = 'img-cell';
             $table->addHead($head_label, $head_style);
             $user_model = new UsermanagementAdm();
             $_user_data = $user_model->getUsersDetails($_new_users, true, true);
             $_std_score = 0;
             foreach ($_new_users as $id_user) {
                 if (isset($_user_data[$id_user]) && is_object($_user_data[$id_user])) {
                     $line = array();
                     $line[] = $acl_man->relativeId($_user_data[$id_user]->userid);
                     $line[] = $_user_data[$id_user]->lastname . " " . $_user_data[$id_user]->firstname;
                     $line[] = Form::getInputTextfield('textfield', 'assign_score_' . $id_user, 'assign_score[' . $id_user . ']', $_std_score, '', 255, '');
                     $table->addBody($line);
                 }
             }
             $foot = array();
             $foot[] = array('label' => '<b>' . Lang::t('_TOTAL', 'standard') . ': ' . count($_new_users) . '</b>', 'colspan' => 2);
             $foot[] = Form::getInputTextfield('textfield', '_score_', '_score_', $_std_score, '', 255, '') . '<br />' . Form::getButton('set_score', false, Lang::t('_SET', 'standard')) . Form::getButton('reset_score', false, Lang::t('_RESET', 'standard'));
             $table->addFoot($foot);
             $this->render('users_assign', array('id_competence' => $id_competence, 'title' => $page_title_arr, 'type' => $type, 'form_url' => 'index.php?r=' . $this->base_link_competence . '/assign_users_action', 'table' => $table, 'score_std_value' => $_std_score, 'del_selection' => implode(",", $_old_users)));
         } else {
             $data = array();
             foreach ($_new_users as $id_user) {
                 $data[$id_user] = 1;
             }
             $res1 = $this->model->assignCompetenceUsers($id_competence, $data, true);
             $res2 = $this->model->removeCompetenceUsers($id_competence, $_old_users, true);
             $message = $res1 && $res2 ? 'ok_assign' : 'err_assign';
             Util::jump_to('index.php?r=' . $this->base_link_competence . '/show_users&id=' . (int) $id_competence . '&res=' . $message);
         }
     } else {
         //--- USER SELECTION IS IN PROGRESS: show selector -----------------------
         $user_selector = new UserSelector();
         $user_selector->show_user_selector = TRUE;
         $user_selector->show_group_selector = TRUE;
         $user_selector->show_orgchart_selector = TRUE;
         $user_selector->show_fncrole_selector = TRUE;
         //$user_select->show_orgchart_simple_selector = TRUE;
         //filter selectable user by sub-admin permission
         $acl_man = Docebo::user()->getAclManager();
         $user_selector->setUserFilter('exclude', array($acl_man->getAnonymousId()));
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
             $user_selector->setUserFilter('user', $admin_users);
             $user_selector->setUserFilter('group', $admin_tree);
         }
         if (Get::req('is_updating', DOTY_INT, false)) {
             //...
         } else {
             //set initial selection
             $selection = $this->model->getCompetenceUsers($id_competence);
             $user_selector->requested_tab = PEOPLEVIEW_TAB;
             $user_selector->resetSelection($selection);
         }
         $user_selector->addFormInfo(Form::getHidden('is_updating', 'is_updating', 1) . Form::getHidden('id_competence', 'id_competence', $id_competence));
         //draw selector
         $user_selector->loadSelector(Util::str_replace_once('&', '&amp;', $jump_url), $page_title_arr, false, true);
     }
 }
Пример #15
0
 function _get_users_query($type = 'html', $report_data = NULL, $other = '')
 {
     //$jump_url, $alluser, $org_chart_subdivision, $start_time, $end_time
     if ($report_data == NULL) {
         $ref =& $_SESSION['report_tempdata'];
     } else {
         $ref =& $report_data;
     }
     $all_courses = $ref['rows_filter']['all_courses'];
     $course_selected =& $ref['rows_filter']['selected_courses'];
     $time_range = $ref['columns_filter']['time_belt']['time_range'];
     $start_time = $ref['columns_filter']['time_belt']['start_date'];
     $end_time = $ref['columns_filter']['time_belt']['end_date'];
     $org_chart_subdivision = $ref['columns_filter']['org_chart_subdivision'];
     $filter_cols = $ref['columns_filter']['showed_cols'];
     $show_percent = isset($ref['columns_filter']['show_percent']) ? (bool) $ref['columns_filter']['show_percent'] : true;
     $show_suspended = isset($ref['columns_filter']['show_suspended']) ? (bool) $ref['columns_filter']['show_suspended'] : false;
     $only_students = isset($ref['columns_filter']['only_students']) ? (bool) $ref['columns_filter']['only_students'] : false;
     $show_assessment = isset($ref['columns_filter']['show_assessment']) ? (bool) $ref['columns_filter']['show_assessment'] : false;
     $show_classrooms_editions = isset($ref['columns_filter']['show_classrooms_editions']) ? (bool) $ref['columns_filter']['show_classrooms_editions'] : false;
     if ($time_range != 0) {
         $start_time = date("Y-m-d H:i:s", time() - $time_range * 24 * 3600);
         $end_time = date("Y-m-d H:i:s");
     } else {
         $start_time = $start_time;
         $end_time = $end_time;
     }
     $alluser = $ref['columns_filter']['all_users'];
     $output = '';
     $lang =& DoceboLanguage::createInstance('course', 'framework');
     require_once $GLOBALS['where_framework'] . '/lib/lib.directory.php';
     require_once _base_ . '/lib/lib.userselector.php';
     $acl_man = new DoceboACLManager();
     $acl_man->include_suspended = TRUE;
     $course_man = new Man_Course();
     $user_level = Docebo::user()->getUserLevelId();
     if ($alluser == 0) {
         $user_selected =& $acl_man->getAllUsersFromSelection($ref['columns_filter']['users']);
     } else {
         $user_selected =& $acl_man->getAllUsersIdst();
     }
     //apply filters for sub-admins
     if ($user_level != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous()) {
         //filter users
         $alluser = 0;
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_users = $adminManager->getAdminUsers(Docebo::user()->getIdST());
         $admin_users = $acl_man->getAllUsersFromSelection($admin_users);
         $user_selected = array_intersect($user_selected, $admin_users);
         unset($admin_users);
         //filter courses
         $admin_courses = $adminManager->getAdminCourse(Docebo::user()->getIdST());
         if ($all_courses) {
             $all_courses = false;
             $rs = sql_query("SELECT idCourse FROM %lms_course");
             $course_selected = array();
             while (list($id_course) = sql_fetch_row($rs)) {
                 $course_selected[] = $id_course;
             }
         }
         if (isset($admin_courses['course'][0])) {
             //No filter
         } elseif (isset($admin_courses['course'][-1])) {
             require_once _lms_ . '/lib/lib.catalogue.php';
             $cat_man = new Catalogue_Manager();
             $user_catalogue = $cat_man->getUserAllCatalogueId(Docebo::user()->getIdSt());
             if (count($user_catalogue) > 0) {
                 $courses = array(0);
                 foreach ($user_catalogue as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     $courses = array_merge($courses, $catalogue_course);
                 }
                 foreach ($courses as $id_course) {
                     if ($id_course != 0) {
                         $admin_courses['course'][$id_course] = $id_course;
                     }
                 }
             } elseif (Get::sett('on_catalogue_empty', 'off') == 'on') {
                 //No filter
             }
             if (!empty($admin_courses['course'])) {
                 $_clist = array_values($admin_courses['course']);
                 $course_selected = array_intersect($course_selected, $_clist);
             } else {
                 $course_selected = array();
             }
         } else {
             $array_courses = array();
             $array_courses = array_merge($array_courses, $admin_courses['course']);
             if (!empty($admin_courses['coursepath'])) {
                 require_once _lms_ . '/lib/lib.coursepath.php';
                 $path_man = new Catalogue_Manager();
                 $coursepath_course =& $path_man->getAllCourses($admin_courses['coursepath']);
                 $array_courses = array_merge($array_courses, $coursepath_course);
             }
             if (!empty($admin_courses['catalogue'])) {
                 require_once _lms_ . '/lib/lib.catalogue.php';
                 $cat_man = new Catalogue_Manager();
                 foreach ($admin_courses['catalogue'] as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     $array_courses = array_merge($array_courses, $catalogue_course);
                 }
             }
             $admin_courses['course'] = array_merge($admin_courses['course'], $array_courses);
             if (!empty($admin_courses['course'])) {
                 $_clist = array_values($admin_courses['course']);
                 $course_selected = array_intersect($course_selected, $_clist);
             } else {
                 $course_selected = array();
             }
         }
         unset($admin_courses);
     }
     if ($org_chart_subdivision == 1) {
         require_once $GLOBALS['where_framework'] . '/lib/lib.orgchart.php';
         $org_man = new OrgChartManager();
         if ($alluser == 1) {
             $user_level = Docebo::user()->getUserLevelId();
             if ($user_level != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous()) {
                 $elem_selected = $user_selected;
             } else {
                 $elem_selected = $org_man->getAllGroupIdFolder();
             }
         } else {
             $elem_selected = $user_selected;
         }
         $org_name = $org_man->getFolderFormIdst($elem_selected);
         if ($user_level != ADMIN_GROUP_GODADMIN && !Docebo::user()->isAnonymous()) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
             $org_name_temp = $org_name;
             $org_name = array();
             foreach ($org_name_temp as $id => $value) {
                 if (isset($admin_tree[$id])) {
                     $org_name[$id] = $value;
                 }
             }
         }
     } else {
         $elem_selected = array();
     }
     if (empty($user_selected)) {
         //no users to display
         $GLOBALS['page']->add($lang->def('_NULL_SELECTION'), 'content');
         return;
     }
     // Retrieve all the course
     $id_courses = array();
     if (!$show_classrooms_editions) {
         $q_courses = "SELECT c.idCourse, c.code, c.name, c.description, c.course_type " . " FROM %lms_course As c " . ($show_assessment ? "" : " WHERE c.course_type <> 'assessment' ") . " ORDER BY c.code, c.name";
         $r_courses = sql_query($q_courses);
         while (list($id, $code, $name, $description, $course_type) = sql_fetch_row($r_courses)) {
             $id_courses[$id] = array('id_course' => $id, 'code' => $code, 'name' => $name, 'description' => $description, 'course_type' => $course_type);
         }
     } else {
         $q_courses = "SELECT c.idCourse, c.code, c.name, c.description, c.course_type, d.id_date " . " FROM %lms_course As c LEFT JOIN %lms_course_date AS d ON (c.idCourse = d.id_course) " . ($show_assessment ? "" : " WHERE c.course_type <> 'assessment' ") . " ORDER BY c.code, c.name, d.code, d.name";
         $r_courses = sql_query($q_courses);
         while (list($id, $code, $name, $description, $course_type, $id_date) = sql_fetch_row($r_courses)) {
             $index = $course_type == 'classroom' ? $id . '_' . $id_date : $id;
             $id_courses[$index] = array('id_course' => $id, 'code' => $code, 'name' => $name, 'description' => $description, 'course_type' => $course_type);
         }
     }
     if (empty($id_courses)) {
         //no courses on the platform
         cout($lang->def('_NULL_COURSE_SELECTION'), 'content');
         return;
     }
     $id_coursedates = array();
     $date_now = Format::date(date("Y-m-d H:i:s"));
     $classrooms_editions_info = array();
     if ($show_classrooms_editions) {
         //retrieve classrooms info
         $query = "SELECT d.*, MIN(dd.date_begin) AS date_1, MAX(dd.date_end) AS date_2 " . " FROM %lms_course_date AS d JOIN %lms_course_date_day AS dd ON (d.id_date = dd.id_date) " . (!$all_courses ? " AND d.id_course IN (" . implode(',', $course_selected) . ") " : "") . " GROUP BY dd.id_date";
         $res = sql_query($query);
         while ($obj = sql_fetch_object($res)) {
             $classrooms_editions_info['classrooms'][$obj->id_date] = $obj;
         }
         //retrieve editions info
         //TO DO ...
     }
     if (!$show_classrooms_editions) {
         if ($org_chart_subdivision == 0) {
             $query_course_user = "******" . " FROM %lms_courseuser AS cu JOIN %adm_user AS u ON (cu.idUser = u.idst) " . " WHERE cu.idUser IN ( " . implode(',', $user_selected) . " ) " . ($all_courses ? "" : "AND cu.idCourse IN (" . implode(',', $course_selected) . ") ") . ($show_suspended ? "" : " AND u.valid = 1 ") . ($only_students ? " AND cu.level = 3 " : "");
             if ($start_time != '' && $start_time != '0000-00-00') {
                 $query_course_user .= " AND cu.date_complete >= '" . $start_time . "' ";
             }
             if ($end_time != '' && $end_time != '0000-00-00') {
                 $query_course_user .= " AND cu.date_complete <= '" . $end_time . "'";
             }
             $num_iscr = array();
             $num_nobegin = array();
             $num_itinere = array();
             $num_end = array();
             $time_in_course = array();
             $effective_user = array();
             $re_course_user = sql_query($query_course_user);
             while (list($id_u, $id_c, $fisrt_access, $date_complete, $status) = sql_fetch_row($re_course_user)) {
                 if (isset($num_iscr[$id_c])) {
                     ++$num_iscr[$id_c];
                 } else {
                     $num_iscr[$id_c] = 1;
                 }
                 switch ($status) {
                     case _CUS_CONFIRMED:
                         break;
                     case _CUS_SUSPEND:
                         break;
                     case _CUS_SUBSCRIBED:
                         if (isset($num_nobegin[$id_c])) {
                             ++$num_nobegin[$id_c];
                         } else {
                             $num_nobegin[$id_c] = 1;
                         }
                         break;
                     case _CUS_BEGIN:
                         if (isset($num_itinere[$id_c])) {
                             ++$num_itinere[$id_c];
                         } else {
                             $num_itinere[$id_c] = 1;
                         }
                         break;
                     case _CUS_END:
                         if (isset($num_end[$id_c])) {
                             ++$num_end[$id_c];
                         } else {
                             $num_end[$id_c] = 1;
                         }
                         break;
                 }
                 $effective_user[] = $id_u;
             }
             if (!empty($effective_user)) {
                 $query_time = "\r\n\t\t\t\t\t\tSELECT idCourse, SUM(UNIX_TIMESTAMP(lastTime) - UNIX_TIMESTAMP(enterTime))\r\n\t\t\t\t\t\tFROM %lms_tracksession\r\n\t\t\t\t\t\tWHERE  idUser IN ( " . implode(',', $effective_user) . " )  ";
                 if ($start_time != '' && $start_time != '0000-00-00') {
                     $query_time .= " AND enterTime >= '" . $start_time . "' ";
                 }
                 if ($end_time != '' && $end_time != '0000-00-00') {
                     $query_time .= " AND enterTime <= '" . $end_time . "' ";
                 }
                 $query_time .= " GROUP BY idCourse ";
                 $re_time = sql_query($query_time);
                 while (list($id_c, $time_num) = sql_fetch_row($re_time)) {
                     $time_in_course[$id_c] = $time_num;
                 }
             }
             $output .= $this->_printTable_users($type, $acl_man, $id_courses, $num_iscr, $num_nobegin, $num_itinere, $num_end, $time_in_course, $filter_cols, $show_percent, $show_classrooms_editions, $classrooms_editions_info);
         } else {
             reset($org_name);
             while (list($idst_group, $folder_name) = each($org_name)) {
                 if ($first) {
                     $first = FALSE;
                 } else {
                     $output .= '<br /><br /><br />';
                 }
                 $output .= '<div class="datasummary">' . '<b>' . $lang->def('_FOLDER_NAME') . ' :</b> ' . $folder_name['name'] . ($folder_name['type_of_folder'] == ORG_CHART_WITH_DESCENDANTS ? ' (' . $lang->def('_WITH_DESCENDANTS') . ')' : '') . '<br />';
                 if ($start_time != '' && $start_time != '0000-00-00' || $end_time != '' && $end_time != '0000-00-00') {
                     $output .= '<b>' . $lang->def('_TIME_BELT_2') . ' :</b> ' . ($start_time != '' && $start_time != '0000-00-00' ? ' <b>' . $lang->def('_START_TIME') . ' </b>' . Format::date($start_time, 'date') : '') . ($end_time != '' && $end_time != '0000-00-00' ? ' <b>' . $lang->def('_TO') . ' </b>' . Format::date($end_time, 'date') : '') . '<br />';
                 }
                 $group_user = $acl_man->getGroupAllUser($idst_group);
                 $query_course_user = "******" . " FROM %lms_courseuser AS cu JOIN %adm_user AS u ON (cu.idUser = u.idst) " . " WHERE cu.idUser IN ( " . implode(',', $group_user) . " ) " . ($all_courses ? "" : "AND cu.idCourse IN (" . implode(',', $course_selected) . ") ") . ($show_suspended ? "" : " AND u.valid = 1 ") . ($only_students ? " AND cu.level = 3 " : "");
                 if ($start_time != '' && $start_time != '0000-00-00') {
                     $query_course_user .= " AND cu.date_complete >= '" . $start_time . "' ";
                 }
                 if ($end_time != '' && $end_time != '0000-00-00') {
                     $query_course_user .= " AND cu.date_complete <= '" . $end_time . "'  AND cu.level='3'";
                 }
                 $num_iscr = array();
                 $num_nobegin = array();
                 $num_itinere = array();
                 $num_end = array();
                 $time_in_course = array();
                 $effective_user = array();
                 $re_course_user = sql_query($query_course_user);
                 while (list($id_u, $id_c, $fisrt_access, $date_complete) = sql_fetch_row($re_course_user)) {
                     if (isset($num_iscr[$id_c])) {
                         ++$num_iscr[$id_c];
                     } else {
                         $num_iscr[$id_c] = 1;
                     }
                     if ($fisrt_access === NULL) {
                         //never enter
                         if (isset($num_nobegin[$id_c])) {
                             ++$num_nobegin[$id_c];
                         } else {
                             $num_nobegin[$id_c] = 1;
                         }
                     } elseif ($date_complete === NULL) {
                         //enter
                         if (isset($num_itinere[$id_c])) {
                             ++$num_itinere[$id_c];
                         } else {
                             $num_itinere[$id_c] = 1;
                         }
                     } else {
                         //complete
                         if (isset($num_end[$id_c])) {
                             ++$num_end[$id_c];
                         } else {
                             $num_end[$id_c] = 1;
                         }
                     }
                     $effective_user[] = $id_u;
                 }
                 if (!empty($group_user)) {
                     $query_time = "\r\n\t\t\t\t\t\tSELECT idCourse, SUM(UNIX_TIMESTAMP(lastTime) - UNIX_TIMESTAMP(enterTime))\r\n\t\t\t\t\t\tFROM %lms_tracksession\r\n\t\t\t\t\t\tWHERE  idUser IN ( " . implode(',', $group_user) . " )  ";
                     if ($start_time != '' && $start_time != '0000-00-00') {
                         $query_time .= " AND enterTime >= '" . $start_time . "' ";
                     }
                     if ($end_time != '' && $end_time != '0000-00-00') {
                         $query_time .= " AND enterTime <= '" . $end_time . "' ";
                     }
                     $query_time .= " GROUP BY idCourse ";
                     $re_time = sql_query($query_time);
                     while (list($id_c, $time_num) = sql_fetch_row($re_time)) {
                         $time_in_course[$id_c] = $time_num;
                     }
                 }
                 reset($id_courses);
                 $output .= $this->_printTable_users($type, $acl_man, $id_courses, $num_iscr, $num_nobegin, $num_itinere, $num_end, $time_in_course, $filter_cols, $show_percent, $show_classrooms_editions, $classrooms_editions_info);
             }
         }
     } else {
         //check classrooms and editions
         if ($org_chart_subdivision == 0) {
             $query_course_user = "******" . " FROM (%lms_courseuser AS cu JOIN %lms_course AS c JOIN %adm_user AS u ON (cu.idCourse = c.idCourse AND cu.idUser = u.idst)) " . " LEFT JOIN (%lms_course_date AS d JOIN %lms_course_date_user AS du ON (du.id_date=d.id_date)) " . " ON (du.id_user = cu.idUser AND d.id_course = cu.idCourse) " . " WHERE cu.idUser IN ( " . implode(',', $user_selected) . " ) " . ($all_courses ? "" : "AND cu.idCourse IN (" . implode(',', $course_selected) . ")") . ($show_suspended ? "" : " AND u.valid = 1 ") . ($only_students ? " AND cu.level = 3 " : "");
             if ($start_time != '' && $start_time != '0000-00-00') {
                 $query_course_user .= " AND cu.date_complete >= '" . $start_time . "' ";
             }
             if ($end_time != '' && $end_time != '0000-00-00') {
                 $query_course_user .= " AND cu.date_complete <= '" . $end_time . "'";
             }
             $num_iscr = array();
             $num_nobegin = array();
             $num_itinere = array();
             $num_end = array();
             $time_in_course = array();
             $effective_user = array();
             $re_course_user = sql_query($query_course_user);
             while (list($id_u, $id_c, $fisrt_access, $date_complete, $status, $course_type, $id_date) = sql_fetch_row($re_course_user)) {
                 $index = $course_type == 'classroom' ? $id_c . '_' . $id_date : $id_c;
                 if (isset($num_iscr[$index])) {
                     ++$num_iscr[$index];
                 } else {
                     $num_iscr[$index] = 1;
                 }
                 switch ($status) {
                     case _CUS_CONFIRMED:
                         break;
                     case _CUS_SUSPEND:
                         break;
                     case _CUS_SUBSCRIBED:
                         if (isset($num_nobegin[$index])) {
                             ++$num_nobegin[$index];
                         } else {
                             $num_nobegin[$index] = 1;
                         }
                         break;
                     case _CUS_BEGIN:
                         if (isset($num_itinere[$index])) {
                             ++$num_itinere[$index];
                         } else {
                             $num_itinere[$index] = 1;
                         }
                         break;
                     case _CUS_END:
                         if (isset($num_end[$index])) {
                             ++$num_end[$index];
                         } else {
                             $num_end[$index] = 1;
                         }
                         break;
                 }
                 if (!in_array($id_u, $effective_user)) {
                     $effective_user[] = $id_u;
                 }
             }
             if (!empty($effective_user)) {
                 $query_time = "SELECT idCourse, SUM(UNIX_TIMESTAMP(lastTime) - UNIX_TIMESTAMP(enterTime)) " . " FROM %lms_tracksession WHERE  idUser IN ( " . implode(',', $effective_user) . " ) ";
                 if ($start_time != '' && $start_time != '0000-00-00') {
                     $query_time .= " AND enterTime >= '" . $start_time . "' ";
                 }
                 if ($end_time != '' && $end_time != '0000-00-00') {
                     $query_time .= " AND enterTime <= '" . $end_time . "' ";
                 }
                 $query_time .= " GROUP BY idCourse ";
                 $re_time = sql_query($query_time);
                 while (list($id_c, $time_num) = sql_fetch_row($re_time)) {
                     $time_in_course[$id_c] = $time_num;
                 }
             }
             $output .= $this->_printTable_users($type, $acl_man, $id_courses, $num_iscr, $num_nobegin, $num_itinere, $num_end, $time_in_course, $filter_cols, $show_percent, $show_classrooms_editions, $classrooms_editions_info);
         } else {
             $first = true;
             reset($org_name);
             while (list($idst_group, $folder_name) = each($org_name)) {
                 if ($first) {
                     $first = FALSE;
                 } else {
                     $output .= '<br /><br /><br />';
                 }
                 $output .= '<div class="datasummary">' . '<b>' . $lang->def('_FOLDER_NAME') . ' :</b> ' . $folder_name['name'] . ($folder_name['type_of_folder'] == ORG_CHART_WITH_DESCENDANTS ? ' (' . $lang->def('_WITH_DESCENDANTS') . ')' : '') . '<br />';
                 if ($start_time != '' && $start_time != '0000-00-00' || $end_time != '' && $end_time != '0000-00-00') {
                     $output .= '<b>' . $lang->def('_TIME_BELT_2') . ' :</b> ' . ($start_time != '' && $start_time != '0000-00-00' ? ' <b>' . $lang->def('_START_TIME') . ' </b>' . Format::date($start_time, 'date') : '') . ($end_time != '' && $end_time != '0000-00-00' ? ' <b>' . $lang->def('_TO') . ' </b>' . Format::date($end_time, 'date') : '') . '<br />';
                 }
                 $group_user = $acl_man->getGroupAllUser($idst_group);
                 $query_course_user = "******" . " FROM (%lms_courseuser AS cu JOIN %lms_course AS c JOIN %adm_user AS u ON (cu.idCourse = c.idCourse AND cu.idUser = u.idst)) " . " LEFT JOIN (%lms_course_date AS d JOIN %lms_course_date_user AS du ON (du.id_date=d.id_date)) " . " ON (du.id_user = cu.idUser AND d.id_course = cu.idCourse) " . " WHERE cu.idUser IN ( " . implode(',', $group_user) . " ) " . ($all_courses ? "" : "AND cu.idCourse IN (" . implode(',', $course_selected) . ")") . ($show_suspended ? "" : " AND u.valid = 1 ") . ($only_students ? " AND cu.level = 3 " : "");
                 if ($start_time != '' && $start_time != '0000-00-00') {
                     $query_course_user .= " AND cu.date_complete >= '" . $start_time . "' ";
                 }
                 if ($end_time != '' && $end_time != '0000-00-00') {
                     $query_course_user .= " AND cu.date_complete <= '" . $end_time . "'";
                 }
                 $num_iscr = array();
                 $num_nobegin = array();
                 $num_itinere = array();
                 $num_end = array();
                 $time_in_course = array();
                 $effective_user = array();
                 //$re_course_user = sql_query($query_course_user);
                 //while(list($id_u, $id_c, $fisrt_access, $date_complete) = sql_fetch_row($re_course_user)) {
                 $re_course_user = sql_query($query_course_user);
                 while (list($id_u, $id_c, $fisrt_access, $date_complete, $status, $course_type, $id_date) = sql_fetch_row($re_course_user)) {
                     $index = $course_type == 'classroom' ? $id_c . '_' . $id_date : $id_c;
                     if (isset($num_iscr[$index])) {
                         ++$num_iscr[$index];
                     } else {
                         $num_iscr[$index] = 1;
                     }
                     if ($fisrt_access === NULL) {
                         //never enter
                         if (isset($num_nobegin[$index])) {
                             ++$num_nobegin[$index];
                         } else {
                             $num_nobegin[$index] = 1;
                         }
                     } elseif ($date_complete === NULL) {
                         //enter
                         if (isset($num_itinere[$index])) {
                             ++$num_itinere[$index];
                         } else {
                             $num_itinere[$index] = 1;
                         }
                     } else {
                         //complete
                         if (isset($num_end[$index])) {
                             ++$num_end[$index];
                         } else {
                             $num_end[$index] = 1;
                         }
                     }
                     if (!in_array($id_u, $effective_user)) {
                         $effective_user[] = $id_u;
                     }
                 }
                 if (!empty($group_user)) {
                     $query_time = "SELECT idCourse, SUM(UNIX_TIMESTAMP(lastTime) - UNIX_TIMESTAMP(enterTime)) " . " FROM %lms_tracksession WHERE  idUser IN ( " . implode(',', $group_user) . " ) ";
                     if ($start_time != '' && $start_time != '0000-00-00') {
                         $query_time .= " AND enterTime >= '" . $start_time . "' ";
                     }
                     if ($end_time != '' && $end_time != '0000-00-00') {
                         $query_time .= " AND enterTime <= '" . $end_time . "' ";
                     }
                     $query_time .= " GROUP BY idCourse ";
                     $re_time = sql_query($query_time);
                     while (list($id_c, $time_num) = sql_fetch_row($re_time)) {
                         $time_in_course[$id_c] = $time_num;
                     }
                 }
                 reset($id_courses);
                 $output .= $this->_printTable_users($type, $acl_man, $id_courses, $num_iscr, $num_nobegin, $num_itinere, $num_end, $time_in_course, $filter_cols, $show_percent, $show_classrooms_editions, $classrooms_editions_info);
             }
         }
     }
     return $output;
 }
Пример #16
0
function insCourse()
{
    require_once _base_ . '/lib/lib.upload.php';
    require_once _base_ . '/lib/lib.multimedia.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.manmenu.php';
    if ($_POST['course_type'] === 'classroom') {
        $url = 'index.php?r=alms/classroom/show&result=';
    } else {
        $url = 'index.php?modname=course&op=course_list&result=';
    }
    $array_lang = Docebo::langManager()->getAllLangCode();
    $array_lang[] = 'none';
    $acl_man =& Docebo::user()->getAclManager();
    $id_custom = importVar('selected_menu');
    // calc quota limit
    $quota = $_POST['course_quota'];
    if (isset($_POST['inherit_quota'])) {
        $quota = Get::sett('course_quota');
        $_POST['course_quota'] = COURSE_QUOTA_INHERIT;
    }
    $quota = $quota * 1024 * 1024;
    $path = Get::sett('pathcourse');
    $path = '/appLms/' . Get::sett('pathcourse') . (substr($path, -1) != '/' && substr($path, -1) != '\\' ? '/' : '');
    if ($_POST['course_name'] == '') {
        $_POST['course_name'] = Lang::t('_NO_NAME', 'course', 'lms');
    }
    // restriction on course status ------------------------------------------
    $user_status = 0;
    if (isset($_POST['user_status'])) {
        while (list($status) = each($_POST['user_status'])) {
            $user_status |= 1 << $status;
        }
    }
    // level that will be showed in the course --------------------------------
    $show_level = 0;
    if (isset($_POST['course_show_level'])) {
        while (list($lv) = each($_POST['course_show_level'])) {
            $show_level |= 1 << $lv;
        }
    }
    // save the file uploaded -------------------------------------------------
    $file_sponsor = '';
    $file_logo = '';
    $file_material = '';
    $file_othermaterial = '';
    $file_demo = '';
    $error = false;
    $quota_exceeded = false;
    $total_file_size = 0;
    if (is_array($_FILES) && !empty($_FILES)) {
        sl_open_fileoperations();
    }
    // load user material ---------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_user_material', '', $path, $quota != 0 ? $quota - $total_file_size : false, false);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_material = $arr_file['filename'];
    $total_file_size = $total_file_size + $arr_file['new_size'];
    // course otheruser material -------------------------------------------------------------------
    $arr_file = manageCourseFile('course_otheruser_material', '', $path, $quota != 0 ? $quota - $total_file_size : false, false);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_othermaterial = $arr_file['filename'];
    $total_file_size = $total_file_size + $arr_file['new_size'];
    // course demo-----------------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_demo', '', $path, $quota != 0 ? $quota - $total_file_size : false, false);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_demo = $arr_file['filename'];
    $total_file_size = $total_file_size + $arr_file['new_size'];
    // course sponsor---------------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_sponsor_logo', '', $path, $quota != 0 ? $quota - $total_file_size : false, false, true);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_sponsor = $arr_file['filename'];
    $total_file_size = $total_file_size + $arr_file['new_size'];
    // course logo-----------------------------------------------------------------------------------
    $arr_file = manageCourseFile('course_logo', '', $path, $quota != 0 ? $quota - $total_file_size : false, false, true);
    $error |= $arr_file['error'];
    $quota_exceeded |= $arr_file['quota_exceeded'];
    $file_logo = $arr_file['filename'];
    $total_file_size = $total_file_size + $arr_file['new_size'];
    // ----------------------------------------------------------------------------------------------
    sl_close_fileoperations();
    if ($_POST["can_subscribe"] == "2") {
        $sub_start_date = Format::dateDb($_POST["sub_start_date"], "date");
        $sub_end_date = Format::dateDb($_POST["sub_end_date"], "date");
    }
    $date_begin = Format::dateDb($_POST['course_date_begin'], "date");
    $date_end = Format::dateDb($_POST['course_date_end'], "date");
    // insert the course in database -----------------------------------------------------------
    $hour_begin = '-1';
    $hour_end = '-1';
    if ($_POST['hour_begin']['hour'] != '-1') {
        $hour_begin = strlen($_POST['hour_begin']['hour']) == 1 ? '0' . $_POST['hour_begin']['hour'] : $_POST['hour_begin']['hour'];
        if ($_POST['hour_begin']['quarter'] == '-1') {
            $hour_begin .= ':00';
        } else {
            $hour_begin .= ':' . $_POST['hour_begin']['quarter'];
        }
    }
    if ($_POST['hour_end']['hour'] != '-1') {
        $hour_end = strlen($_POST['hour_end']['hour']) == 1 ? '0' . $_POST['hour_end']['hour'] : $_POST['hour_end']['hour'];
        if ($_POST['hour_end']['quarter'] == '-1') {
            $hour_end .= ':00';
        } else {
            $hour_end .= ':' . $_POST['hour_end']['quarter'];
        }
    }
    $query_course = "\r\n\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_course\r\n\tSET idCategory \t\t\t= '" . (isset($_POST['idCategory']) ? $_POST['idCategory'] : 0) . "',\r\n\t\tcode \t\t\t\t= '" . $_POST['course_code'] . "',\r\n\t\tname \t\t\t\t= '" . $_POST['course_name'] . "',\r\n\t\tdescription \t\t= '" . $_POST['course_descr'] . "',\r\n\t\tlang_code \t\t\t= '" . $array_lang[$_POST['course_lang']] . "',\r\n\t\tstatus \t\t\t\t= '" . (int) $_POST['course_status'] . "',\r\n\t\tlevel_show_user \t= '" . $show_level . "',\r\n\t\tsubscribe_method \t= '" . (int) $_POST['course_subs'] . "',\r\n\r\n\t\tcreate_date\t\t\t= '" . date("Y-m-d H:i:s") . "',\r\n\r\n\t\tlinkSponsor \t\t= '" . $_POST['course_sponsor_link'] . "',\r\n\t\timgSponsor \t\t\t= '" . $file_sponsor . "',\r\n\t\timg_course \t\t\t= '" . $file_logo . "',\r\n\t\timg_material \t\t= '" . $file_material . "',\r\n\t\timg_othermaterial \t= '" . $file_othermaterial . "',\r\n\t\tcourse_demo \t\t= '" . $file_demo . "',\r\n\r\n\t\tmediumTime \t\t\t= '" . $_POST['course_medium_time'] . "',\r\n\t\tpermCloseLO \t\t= '" . $_POST['course_em'] . "',\r\n\t\tuserStatusOp \t\t= '" . $user_status . "',\r\n\t\tdifficult \t\t\t= '" . $_POST['course_difficult'] . "',\r\n\r\n\t\tshow_progress \t\t= '" . (isset($_POST['course_progress']) ? 1 : 0) . "',\r\n\t\tshow_time \t\t\t= '" . (isset($_POST['course_time']) ? 1 : 0) . "',\r\n\r\n\t\tshow_who_online\t\t= '" . $_POST['show_who_online'] . "',\r\n\r\n\t\tshow_extra_info \t= '" . (isset($_POST['course_advanced']) ? 1 : 0) . "',\r\n\t\tshow_rules \t\t\t= '" . (int) $_POST['course_show_rules'] . "',\r\n\r\n\t\tdirect_play \t\t= '" . (isset($_POST['direct_play']) ? 1 : 0) . "',\r\n\r\n\t\tdate_begin \t\t\t= '" . $date_begin . "',\r\n\t\tdate_end \t\t\t= '" . $date_end . "',\r\n\t\thour_begin \t\t\t= '" . $hour_begin . "',\r\n\t\thour_end \t\t\t= '" . $hour_end . "',\r\n\r\n\t\tvalid_time \t\t\t= '" . (int) $_POST['course_day_of'] . "',\r\n\r\n\t\tmin_num_subscribe \t= '" . (int) $_POST['min_num_subscribe'] . "',\r\n\t\tmax_num_subscribe \t= '" . (int) $_POST['max_num_subscribe'] . "',\r\n\t\tselling \t\t\t= '" . (isset($_POST['course_sell']) ? '1' : '0') . "',\r\n\t\tprize \t\t\t\t= '" . $_POST['course_prize'] . "',\r\n\r\n\t\tcourse_type \t\t= '" . $_POST['course_type'] . "',\r\n\r\n\t\tcourse_edition \t\t= '" . (isset($_POST['course_edition']) ? 1 : 0) . "',\r\n\r\n\t\tcourse_quota \t\t= '" . $_POST['course_quota'] . "',\r\n\t\tused_space\t\t\t= '" . $total_file_size . "',\r\n\t\tallow_overbooking \t= '" . (isset($_POST["allow_overbooking"]) ? 1 : 0) . "',\r\n\t\tcan_subscribe \t\t= '" . (int) $_POST["can_subscribe"] . "',\r\n\t\tsub_start_date \t\t= " . ($_POST["can_subscribe"] == '2' ? "'" . $sub_start_date . "'" : 'NULL') . ",\r\n\t\tsub_end_date \t\t= " . ($_POST["can_subscribe"] == '2' ? "'" . $sub_end_date . "'" : 'NULL') . ",\r\n\r\n\t\tadvance \t\t\t= '" . $_POST['advance'] . "',\r\n\t\tshow_result \t\t= '" . (isset($_POST["show_result"]) ? 1 : 0) . "',\r\n\r\n\t\tuse_logo_in_courselist = '" . (isset($_POST['use_logo_in_courselist']) ? '1' : '0') . "'";
    if (isset($_POST['random_course_autoregistration_code'])) {
        $control = 1;
        $str = '';
        while ($control) {
            for ($i = 0; $i < 10; $i++) {
                $seed = mt_rand(0, 10);
                if ($seed > 5) {
                    $str .= mt_rand(0, 9);
                } else {
                    $str .= chr(mt_rand(65, 90));
                }
            }
            $control_query = "SELECT COUNT(*)" . " " . $GLOBALS['prefix_lms'] . "_course" . " WHERE autoregistration_code = '" . $str . "'";
            $control_result = sql_query($control_query);
            list($result) = sql_fetch_row($control_result);
            $control = $result;
        }
        $query_course .= ", autoregistration_code = '" . $str . "'";
    } else {
        $query_course .= ", autoregistration_code = '" . $_POST['course_autoregistration_code'] . "'";
    }
    if (!sql_query($query_course)) {
        // course save failed, delete uploaded file
        if ($file_sponsor != '') {
            sl_unlink($path . $file_sponsor);
        }
        if ($file_logo != '') {
            sl_unlink($path . $file_logo);
        }
        if ($file_material != '') {
            sl_unlink($path . $file_material);
        }
        if ($file_othermaterial != '') {
            sl_unlink($path . $file_othermaterial);
        }
        if ($file_demo != '') {
            sl_unlink($path . $file_demo);
        }
        Util::jump_to($url . 'err_course');
    }
    // recover the id of the course inserted --------------------------------------------
    list($id_course) = sql_fetch_row(sql_query("SELECT LAST_INSERT_ID()"));
    require_once _lms_ . '/admin/models/LabelAlms.php';
    $label_model = new LabelAlms();
    $label = Get::req('label', DOTY_INT, 0);
    $label_model->associateLabelToCourse($label, $id_course);
    // add this corse to the pool of course visible by the user that have create it -----
    if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
        require_once _base_ . '/lib/lib.preference.php';
        $adminManager = new AdminPreference();
        $adminManager->addAdminCourse($id_course, Docebo::user()->getIdSt());
    }
    //if the scs exist create a room ----------------------------------------------------
    if ($GLOBALS['where_scs'] !== false) {
        require_once $GLOBALS['where_scs'] . '/lib/lib.room.php';
        $rules = array('room_name' => $_POST['course_name'], 'room_type' => 'course', 'id_source' => $id_course);
        //$admin_rules = getAdminRules();
        //$rules = array_merge($rules, $admin_rules);
        $re = insertRoom($rules);
    }
    $course_idst =& DoceboCourse::createCourseLevel($id_course);
    // create the course menu -----------------------------------------------------------
    if (!cerateCourseMenuFromCustom($id_custom, $id_course, $course_idst)) {
        Util::jump_to($url . 'err_coursemenu');
    }
    /*
    // send alert -------------------------------------------------------------------------------
    require_once($GLOBALS['where_framework'] . '/lib/lib.eventmanager.php');
    
    $msg_composer = new EventMessageComposer();
    
    $msg_composer->setSubjectLangText('email', '_ALERT_SUBJECT', false);
    $msg_composer->setBodyLangText('email', '_ALERT_TEXT', array(	'[url]' => Get::sett('url'),
    																'[course_code]' => $_POST['course_code'],
    																'[course]' => $_POST['course_name'] ) );
    
    $msg_composer->setBodyLangText('sms', '_ALERT_TEXT_SMS', array(	'[url]' => Get::sett('url'),
    																'[course_code]' => $_POST['course_code'],
    																'[course]' => $_POST['course_name'] ) );
    
    require_once($GLOBALS['where_lms'] . '/lib/lib.course.php');
    $course_man = new Man_Course();
    $recipients = $course_man->getIdUserOfLevel($id_course);
    createNewAlert(	'CoursePropModified',
    				'course',
    				'add',
    				'1',
    				'Inserted course '.$_POST['course_name'],
    				$recipients,
    				$msg_composer );
    */
    Util::jump_to($url . ($error ? 'err_course' : 'ok_course') . ($quota_exceeded ? '&limit_reach=1' : ''));
}
 function _get_games_query($type = 'html', $report_data = NULL, $other = '')
 {
     require_once dirname(__FILE__) . '/report_tableprinter.php';
     if ($report_data == NULL) {
         $ref =& $_SESSION['report_tempdata'];
     } else {
         $ref =& $report_data;
     }
     $_ERR_NOUSER = Lang::t('_EMPTY_SELECTION', 'report');
     $_ERR_NOCOMP = Lang::t('_EMPTY_SELECTION', 'report');
     $_ERR_NODATA = Lang::t('_NO_CONTENT', 'report');
     require_once _lms_ . '/lib/lib.report.php';
     $lang_type = _getLOtranslations();
     $sel_all = $ref['rows_filter']['select_all'];
     $arr_selected_users = $ref['rows_filter']['selection'];
     //list of users selected in the filter (users, groups and org.branches)
     $comp_all = $ref['columns_filter']['all_games'];
     $arr_selected_comp = $ref['columns_filter']['comp_selection'];
     //list of communications selected in the filter
     $start_date = substr($ref['columns_filter']['comp_start_date'], 0, 10);
     $end_date = substr($ref['columns_filter']['comp_end_date'], 0, 10);
     //check and validate time period dates
     if (!preg_match('/^(\\d{4})\\D?(0[1-9]|1[0-2])\\D?([12]\\d|0[1-9]|3[01])$/', $start_date) || $start_date == '0000-00-00') {
         $start_date = '';
     }
     if (!preg_match('/^(\\d{4})\\D?(0[1-9]|1[0-2])\\D?([12]\\d|0[1-9]|3[01])$/', $end_date) || $end_date == '0000-00-00') {
         $end_date = '';
     }
     if ($start_date != '') {
         $start_date .= ' 00:00:00';
     }
     if ($end_date != '') {
         $end_date .= ' 23:59:59';
     }
     if ($start_date != '' && $end_date != '') {
         if ($start_date > $end_date) {
             //invalid time period
             $start_date = '';
             $end_date = '';
         }
     }
     //instantiate acl manager
     $acl_man = new DoceboACLManager();
     $acl_man->include_suspended = true;
     //extract user idst from selection
     if ($sel_all) {
         $arr_selected_users = $acl_man->getAllUsersIdst();
     } else {
         $arr_selected_users = $acl_man->getAllUsersFromIdst($arr_selected_users);
     }
     //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);
         //filter users selection by admin visible users
         $arr_selected_users = array_intersect($arr_selected_users, $admin_users);
         //free some memory
         unset($admin_tree);
         unset($admin_users);
         unset($adminManager);
     }
     //Has the "All games" options been selected ?
     if ($comp_all) {
         $query = "SELECT id_game FROM %lms_games";
         $res = $this->db->query($query);
         $arr_selected_comp = array();
         while (list($id_game) = $this->db->fetch_row($res)) {
             $arr_selected_comp[] = $id_game;
         }
     }
     //check selected users ...
     //$arr_selected_users = array(); //list of users selected in the filter (users, groups and org.branches)
     if ($arr_selected_users <= 0) {
         cout('<p>' . $_ERR_NOUSER . '</p>');
         return;
     }
     //$arr_selected_comp = array(); //list of communications selected in the filter
     if ($arr_selected_comp <= 0) {
         cout('<p>' . $_ERR_NOCOMP . '</p>');
         return;
     }
     $arr_comp = array();
     //array $id_comm => list of generic idst
     foreach ($arr_selected_comp as $id_game) {
         $arr_comp[$id_game] = array();
     }
     //if no users have been assigned to the games, than display as 0 - 0
     $arr_idst = array();
     //flat list of idst
     $query = "SELECT * FROM %lms_games_access WHERE id_comp IN (" . implode(",", $arr_selected_comp) . ")";
     $res = $this->db->query($query);
     while (list($id_game, $idst) = $this->db->fetch_row($res)) {
         $arr_idst[] = $idst;
         $arr_comp[$id_game][] = $idst;
     }
     if (count($arr_idst) <= 0) {
         cout('<p>' . $_ERR_NOUSER . '</p>');
         return;
     }
     $arr_groups = array();
     //flat list of group idst
     $query = "SELECT idst FROM %adm_group WHERE idst IN (" . implode(",", $arr_idst) . ")";
     $res = $this->db->query($query);
     while (list($idst) = $this->db->fetch_row($res)) {
         $arr_groups[] = $idst;
     }
     //if any group selected, then extract users and create an array [id_group][id_user]
     $arr_idst_users_flat = array();
     $arr_members = array();
     //array $idst group => list of idst
     if (count($arr_groups) > 0) {
         $query = "SELECT idst, idstMember FROM %adm_group_members WHERE " . " idst IN (" . implode(",", $arr_groups) . ")" . " AND idstMember IN (" . implode(",", $arr_selected_users) . ")";
         $res = $this->db->query($query);
         while (list($idst, $idstMember) = $this->db->fetch_row($res)) {
             $arr_members[$idst][] = $idstMember;
             $arr_idst_users_flat[] = $idstMember;
         }
     }
     //set an array with all users idst ($_all)
     $diff = array_diff($arr_selected_users, $arr_groups);
     $_all_users = array_merge($arr_idst_users_flat, $diff);
     unset($diff);
     if (count($_all_users) <= 0) {
         cout('<p>' . $_ERR_NOUSER . '</p>');
         return;
     }
     //users have been extracted by group, now calculate report's rows ----------
     //get games info data and put it in an array by id_game => {info}
     $arr_comp_data = array();
     $query = "SELECT * FROM %lms_games WHERE id_game IN (" . implode(",", $arr_selected_comp) . ")";
     $res = $this->db->query($query);
     while ($obj = $this->db->fetch_obj($res)) {
         $arr_comp_data[$obj->id_game] = array('title' => $obj->title, 'type_of' => $obj->type_of, 'start_date' => $obj->start_date, 'end_date' => $obj->end_date);
     }
     //which selected communication has been seen by selected users?
     $arr_viewed = array();
     $query = "SELECT idReference, COUNT(idUser) as count " . " FROM %lms_games_track WHERE status IN ('completed', 'passed') " . " AND idUser IN (" . implode(",", $_all_users) . ") " . " AND idReference IN (" . implode(",", $arr_selected_comp) . ") " . ($start_date != '' ? " AND dateAttempt >= '" . $start_date . "' " : "") . ($end_date != '' ? " AND dateAttempt <= '" . $end_date . "' " : "") . " GROUP BY idReference";
     $res = $this->db->query($query);
     while ($obj = $this->db->fetch_obj($res)) {
         $arr_viewed[$obj->idReference] = $obj->count;
     }
     //calculate average values, no conditions on the status
     $arr_average = array();
     $query = "SELECT idReference, AVG(current_score) as average_current_score, " . " AVG(max_score) as average_max_score, AVG(num_attempts) as average_num_attempts " . " FROM %lms_games_track WHERE idUser IN (" . implode(",", $_all_users) . ") " . " AND idReference IN (" . implode(",", $arr_selected_comp) . ") " . ($start_date != '' ? " AND dateAttempt >= '" . $start_date . "' " : "") . ($end_date != '' ? " AND dateAttempt <= '" . $end_date . "' " : "") . " GROUP BY idReference";
     $res = $this->db->query($query);
     while ($obj = $this->db->fetch_obj($res)) {
         $arr_average[$obj->idReference] = $obj;
     }
     /*
     		//user details buffer
     		$acl_man = Docebo::user()->getAclManager();
     		$user_details = array();
     		$query = "SELECT idst, userid FROM %adm_user WHERE idst IN (".implode(",", $_all_users).")";
     		$res = $this->db->query($query);
     		while ($obj = $this->db->fetch_obj($res)) {
     			$user_details[$obj->idst] = $acl_man($obj->userid);
     		}
     */
     //set table properties and buffer
     $head = array(Lang::t('_GAMES_TITLE', 'report'), Lang::t('_GAMES_TYPE', 'report'), Lang::t('_FROM', 'standard'), Lang::t('_TO', 'standard'), Lang::t('_GAMES_ATTEMPTED', 'report'), Lang::t('_GAMES_TOTAL', 'report'), Lang::t('_GAMES_PERCENT', 'report'), Lang::t('_GAMES_AVG_SCORE', 'report'), Lang::t('_GAMES_AVG_MAX_SCORE', 'report'), Lang::t('_GAMES_AVG_NUM_ATTEMPTS', 'report'));
     $buffer = new ReportTablePrinter();
     $buffer->openTable('', '');
     $buffer->openHeader();
     $buffer->addHeader($head);
     $buffer->closeHeader();
     $buffer->openBody();
     //rows cycle
     foreach ($arr_comp as $id_game => $comp_id_list) {
         //calculate total assigned users for every communication
         $count = 0;
         foreach ($comp_id_list as $idst) {
             if (array_key_exists($idst, $arr_members)) {
                 foreach ($arr_members[$idst] as $idst_user) {
                     $count++;
                 }
             } else {
                 $count++;
             }
         }
         //line (one per communication)
         $line = array();
         $type_of = $arr_comp_data[$id_game]['type_of'];
         $completed_by = isset($arr_viewed[$id_game]) ? $arr_viewed[$id_game] : 0;
         $line[] = $arr_comp_data[$id_game]['title'];
         $line[] = isset($lang_type[$type_of]) ? $lang_type[$type_of] : '';
         $line[] = Format::date($arr_comp_data[$id_game]['start_date'], 'date');
         $line[] = Format::date($arr_comp_data[$id_game]['end_date'], 'date');
         $line[] = $completed_by;
         $line[] = $count;
         $line[] = number_format(($count > 0 ? $completed_by / $count : 0) * 100, 2, ',', '') . ' %';
         $avg1 = isset($arr_average[$id_game]) ? $arr_average[$id_game]->average_current_score : '';
         $avg2 = isset($arr_average[$id_game]) ? $arr_average[$id_game]->average_max_score : '';
         $avg3 = isset($arr_average[$id_game]) ? $arr_average[$id_game]->average_num_attempts : '';
         $line[] = number_format($avg1, 2, ',', '.');
         $line[] = number_format($avg2, 2, ',', '.');
         $line[] = number_format($avg3, 2, ',', '.');
         $buffer->addLine($line);
     }
     $buffer->closeBody();
     $buffer->closeTable();
     cout($buffer->get());
 }
Пример #18
0
 public function getCoursePathSubscriptionsList($id_path, $filter = false)
 {
     require_once _lms_ . '/lib/lib.coursepath.php';
     $cman = new CoursePath_Manager();
     $courses = $cman->getAllCourses(array($id_path));
     if (empty($courses)) {
         //...
     }
     $query = "SELECT DISTINCT s.idUser " . " FROM (%lms_courseuser as s JOIN %lms_coursepath_user as p " . " ON (s.idUser = p.idUser)) " . " JOIN %adm_user as u " . " ON (s.idUser = u.idst) " . " WHERE p.id_path = " . (int) $id_path . " AND s.idCourse IN (" . implode(",", array_values($courses)) . ") ";
     //." GROUP BY s.idUser";
     if (is_array($filter)) {
         if (isset($filter['text']) && $filter['text'] != "") {
             $query .= " AND (u.userid LIKE '%" . $filter['text'] . "%' OR u.firstname LIKE '%" . $filter['text'] . "%' OR u.lastname LIKE '%" . $filter['text'] . "%') ";
         }
         $arr_idst = array();
         if (isset($filter['orgchart']) && $filter['orgchart'] > 0) {
             $umodel = new UsermanagementAdm();
             $use_desc = isset($filter['descendants']) && $filter['descendants'];
             $ulist = $umodel->getFolderUsers($filter['orgchart'], $use_desc);
             if (!empty($ulist)) {
                 $arr_idst = $ulist;
             }
             unset($ulist);
         }
         if (!empty($arr_idst)) {
             $conditions[] = " AND u.idst IN (" . implode(",", $arr_idst) . ") ";
         }
         if (isset($filter['date_valid']) && strlen($filter['date_valid']) >= 10) {
             $query .= " AND (s.date_begin_validity <= '" . $filter['date_valid'] . "' OR s.date_begin_validity IS NULL OR s.date_begin_validity='0000-00-00 00:00:00') ";
             $query .= " AND (s.date_expire_validity >= '" . $filter['date_valid'] . "' OR s.date_expire_validity IS NULL OR s.date_expire_validity='0000-00-00 00:00:00') ";
         }
         if (isset($filter['show'])) {
             //validate values
             switch ($filter['show']) {
                 case 0:
                     //all
                     //no condition to check ...
                     break;
                 case 1:
                     //expired
                     $query .= " AND (s.date_expire_validity IS NOT NULL AND s.date_expire_validity < NOW())";
                     break;
                 case 2:
                     //not expired with expiring date
                     $query .= " AND (s.date_expire_validity IS NOT NULL AND s.date_expire_validity > NOW())";
                     break;
                 case 3:
                     //not expired without expiring date
                     $query .= " AND (s.date_expire IS NULL OR s.date_expire='' OR s.date_expire='0000-00-00 00:00:00') ";
                     break;
                 default:
                     //all ...
                     break;
             }
         }
     }
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $acl_man = new DoceboACLManager();
         $adminManager = new AdminPreference();
         $admin_tree = $adminManager->getAdminTree(getLogUserId());
         $admin_users = $acl_man->getAllUsersFromSelection($admin_tree);
         $query .= " AND s.idUser IN (" . implode(',', $admin_users) . ")";
     }
     $output = array();
     $res = sql_query($query);
     if ($res) {
         while (list($idst) = sql_fetch_row($res)) {
             $output[] = $idst;
         }
     }
     return $output;
 }
Пример #19
0
 public function __construct()
 {
     $this->db = DbConn::getInstance();
     $this->users_filter = false;
     $this->courses_filter = false;
     $this->user_level = Docebo::user()->getUserLevelId();
     if ($this->user_level != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $this->users_filter = $adminManager->getAdminUsers(Docebo::user()->getIdST());
         $all_courses = false;
         $array_courses = array();
         $admin_courses = $adminManager->getAdminCourse(Docebo::user()->getIdST());
         foreach ($admin_courses['course'] as $key => $id_course) {
             if ($key > 0) {
                 $array_courses[$key] = $id_course;
             }
         }
         if (isset($admin_courses['course'][0])) {
             $all_courses = true;
         } elseif (isset($admin_courses['course'][-1])) {
             require_once _lms_ . '/lib/lib.catalogue.php';
             $cat_man = new Catalogue_Manager();
             $user_catalogue = $cat_man->getUserAllCatalogueId(Docebo::user()->getIdSt());
             if (count($user_catalogue) > 0) {
                 $courses = array();
                 foreach ($user_catalogue as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     if (empty($courses)) {
                         $courses = $catalogue_course;
                     } else {
                         $courses = array_merge($courses, $catalogue_course);
                     }
                 }
                 foreach ($courses as $id_course) {
                     if ($id_course != 0) {
                         $array_courses[$id_course] = $id_course;
                     }
                 }
             } elseif (Get::sett('on_catalogue_empty', 'off') == 'on') {
                 $all_courses = true;
             }
         } else {
             if (!empty($admin_courses['coursepath'])) {
                 require_once _lms_ . '/lib/lib.coursepath.php';
                 $path_man = new CoursePath_Manager();
                 $coursepath_course =& $path_man->getAllCourses($admin_courses['coursepath']);
                 $array_courses = array_merge($array_courses, $coursepath_course);
             }
             if (!empty($admin_courses['catalogue'])) {
                 require_once _lms_ . '/lib/lib.catalogue.php';
                 $cat_man = new Catalogue_Manager();
                 foreach ($admin_courses['catalogue'] as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     $array_courses = array_merge($array_courses, $catalogue_course);
                 }
             }
         }
         if (!$all_courses) {
             $this->courses_filter = array_values($array_courses);
         }
         //if "$all_courses" is true, than leave "$this->courses_filter" as false
     }
 }
function selSendTo()
{
    checkPerm('view');
    // [TODO] check write or mod. permissions
    // http://127.0.0.1:82/claudio/lms_cvs/appCore/index.php?modname=public_newsletter_admin&op=selsendto&id_send=1
    if (isset($_GET["id_send"]) && $_GET["id_send"] > 0) {
        $id_send = $_GET["id_send"];
    } else {
        die("Newsletter setup error.");
    }
    require_once $GLOBALS['where_lms'] . "/class.module/class.public_user_admin.php";
    $mdir = new Module_Public_User_Admin();
    require_once _base_ . '/lib/lib.preference.php';
    $adminManager = new AdminPreference();
    $admin_tree = $adminManager->getAdminTree(Docebo::user()->getIdST());
    $admin_users = $acl_man->getAllUsersFromIdst($admin_tree);
    $mdir->setUserFilter('user', $admin_users);
    $mdir->setUserFilter('group', $admin_tree);
    $out =& $GLOBALS['page'];
    $out->setWorkingZone("content");
    $lang =& DoceboLanguage::createInstance('admin_newsletter', 'framework');
    $back_url = "index.php?modname=public_newsletter_admin&amp;op=selsendto&amp;id_send=" . $id_send;
    if (isset($_POST['okselector'])) {
        $arr_selection = $mdir->getSelection($_POST);
        $send_to_idst = array();
        foreach ($arr_selection as $idstMember) {
            $arr = Docebo::aclm()->getGroupAllUser($idstMember);
            if (is_array($arr) && count($arr) > 0) {
                $send_to_idst = array_merge($arr, $send_to_idst);
                $send_to_idst = array_unique($send_to_idst);
            } else {
                $send_to_idst[] = $idstMember;
            }
            $send_to_idst = array_intersect($send_to_idst, $admin_users);
        }
        foreach ($send_to_idst as $key => $val) {
            $qtxt = "INSERT INTO " . $GLOBALS["prefix_fw"] . "_newsletter_sendto (id_send, idst, stime) ";
            $qtxt .= "VALUES ('" . (int) $id_send . "', '" . (int) $val . "', NOW())";
            $q = sql_query($qtxt);
        }
        $qtxt = "SELECT language FROM " . $GLOBALS["prefix_fw"] . "_newsletter WHERE id='" . $id_send . "'";
        $q = sql_query($qtxt);
        list($lang) = sql_fetch_row($q);
        if ($lang != _ANY_LANG_CODE) {
            $tot = count(Docebo::aclm()->getUsersIdstByLanguage($lang, $send_to_idst));
        } else {
            $tot = count($send_to_idst);
        }
        $qtxt = "UPDATE " . $GLOBALS["prefix_fw"] . "_newsletter SET tot='" . $tot . "' WHERE id='{$id_send}'";
        $q = sql_query($qtxt);
        $back_url = "index.php?modname=public_newsletter_admin&amp;op=summary&amp;tot=" . $tot . "&amp;id_send=" . $id_send;
        Util::jump_to(str_replace("&amp;", "&", $back_url));
    } else {
        if (isset($_POST['cancelselector'])) {
            $info = get_send_info($id_send);
            $file = $info['file'];
            $path = '/appCore/newsletter/';
            require_once _base_ . '/lib/lib.upload.php';
            if ($file != '') {
                sl_open_fileoperations();
                sl_unlink($path . $file);
                sl_close_fileoperations();
            }
            Util::jump_to('index.php?modname=newsletter&op=newsletter');
        } else {
            if (isset($_GET['load'])) {
                $mdir->resetSelection(array());
            }
            $url = "index.php?modname=public_newsletter_admin&amp;op=selsendto&amp;id_send=" . $id_send . "&amp;stayon=1";
            $mdir->show_user_selector = TRUE;
            $mdir->show_group_selector = TRUE;
            if (Get::sett('use_org_chart') == '1') {
                $mdir->show_orgchart_selector = TRUE;
                $mdir->show_orgchart_simple_selector = TRUE;
            } else {
                $mdir->show_orgchart_selector = FALSE;
            }
            $acl_manager =& Docebo::user()->getAclManager();
            if (defined("IN_LMS")) {
                $id_course = (int) $_SESSION['idCourse'];
                $arr_idstGroup = $acl_manager->getGroupsIdstFromBasePath('/lms/course/' . $id_course . '/subscribed/');
                $mdir->setUserFilter('group', $arr_idstGroup);
                $mdir->setGroupFilter('path', '/lms/course/' . $id_course . '/group');
                $mdir->show_orgchart_selector = FALSE;
            }
            // Exclude anonymous user!
            $mdir->setUserFilter('exclude', array($acl_manager->getAnonymousId()));
            $mdir->loadSelector($url, array(Lang::t('_NEWSLETTER', 'admin_newsletter'), Lang::t('_RECIPIENTS', 'admin_newsletter')), "", TRUE);
        }
    }
}
Пример #21
0
 function loadCoursepathSelector($noprint = false)
 {
     require_once _base_ . '/lib/lib.table.php';
     require_once _base_ . '/lib/lib.form.php';
     $lang =& DoceboLanguage::createInstance('coursepath', 'lms');
     $output = '';
     // Filter
     $this->filter['coursepath_name'] = isset($_POST['coursepath_filter_name']) ? $_POST['coursepath_filter_name'] : '';
     if ($this->show_filter === true) {
         /*
         			$form = new Form();
         			$output .= $form->getOpenFieldset($lang->def('_COURSEPATH_FILTER'))
         				.Form::getTextfield($lang->def('_NAME'), 'coursepath_filter_name', 'coursepath_filter_name', '255',
         					( isset($_POST['coursepath_filter_name']) ? $_POST['coursepath_filter_name'] : '' ))
         				.$form->openButtonSpace()
         				.$form->getButton('coursepath_filter', 'coursepath_filter', $lang->def('_SEARCH'))
         				.$form->closeButtonSpace()
         				.$form->getCloseFieldset();*/
         $output .= '<div class="quick_search_form">' . '<div>' . Form::getInputTextfield("search_t", "coursepath_filter_name", "coursepath_filter_name", Get::req('coursepath_filter_name', DOTY_MIXED, ''), '', 255, '') . Form::getButton("coursepath_filter", "coursepath_filter", Lang::t('_SEARCH', 'standard'), "search_b") . '</div>' . '</div>';
     }
     // End Filter
     $tb = new Table(Get::sett('visuItem'), $lang->def('_COURSE_PATH_CAPTION'), $lang->def('_COURSE_PATH_SUMMARY'));
     $tb->initNavBar('ini_cpath', 'button');
     $ini = $tb->getSelectedElement();
     $select = "\r\n\t\tSELECT id_path, path_name, path_descr ";
     $query_coursepath = "\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_coursepath\r\n\t\tWHERE 1 ";
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         $all_courses = false;
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_courses = $adminManager->getAdminCourse(Docebo::user()->getIdST());
         if (isset($admin_courses['course'][0])) {
             $all_courses = true;
         }
         if (isset($admin_courses['course'][-1])) {
             $query = "SELECT id_path" . " FROM %lms_coursepath_user" . " WHERE idUser = '******'";
             $result = sql_query($query);
             $admin_courses['coursepath'] = array();
             while (list($id_path) = sql_fetch_row($result)) {
                 $admin_courses['coursepath'][$id_path] = $id_path;
             }
             if (!empty($admin_courses['coursepath']) && Get::sett('on_catalogue_empty', 'off') == 'on') {
                 $all_courses = true;
             }
         }
         if (!$all_courses) {
             if (empty($admin_courses['coursepath'])) {
                 $query_coursepath .= " AND 0 ";
             } else {
                 $query_coursepath .= " AND id_path IN (" . implode(',', $admin_courses['coursepath']) . ") ";
             }
         }
     }
     if ($this->filter['coursepath_name'] != '') {
         $query_coursepath .= " AND path_name LIKE '%" . $this->filter['coursepath_name'] . "%'";
     }
     list($tot_coursepath) = sql_fetch_row(sql_query("SELECT COUNT(*) " . $query_coursepath));
     $query_coursepath .= "\r\n\t\tORDER BY path_name\r\n\t\tLIMIT " . $ini . "," . (int) Get::sett('visuItem');
     $re_coursepath = sql_query($select . $query_coursepath);
     $type_h = array('image', '', '', '');
     $cont_h = array('<span class="access-only">' . $lang->def('_SELECT') . '</span>', $lang->def('_NAME'), $lang->def('_DESCRIPTION'));
     $tb->setColsStyle($type_h);
     $tb->addHead($cont_h);
     while (list($id_path, $name, $descr) = sql_fetch_row($re_coursepath)) {
         $tb_content = array(Form::getInputCheckbox('new_coursepath_selected_' . $id_path, 'new_coursepath_selected[' . $id_path . ']', $id_path, isset($this->current_selection[$id_path]), ''), '<label for="new_coursepath_selected_' . $id_path . '">' . $name . '</label>', '<label for="new_coursepath_selected_' . $id_path . '">' . $descr . '</label>');
         $tb->addBody($tb_content);
         if (isset($this->current_selection[$id_path])) {
             unset($this->current_selection[$id_path]);
         }
     }
     $output .= $tb->getTable() . $tb->getNavBar($ini, $tot_coursepath) . $this->stateSelection();
     if ($noprint) {
         return $output;
     } else {
         cout($output, 'content');
     }
 }
Пример #22
0
 public function getCourseEdition($id_course, $start_index = false, $results = false, $sort = false, $dir = false, $ed_arr = false)
 {
     if ($ed_arr !== false && is_array($ed_arr) && empty($ed_arr)) {
         $ed_arr[] = 0;
     }
     $query = "SELECT dt.id_date, dt.code, dt.name, dt.status, MIN(dy.date_begin) AS date_begin, MAX(dy.date_end) AS date_end, COUNT(dy.id_day) as num_day, COUNT(DISTINCT du.id_user) as user_subscribed, dt.unsubscribe_date_limit" . " FROM " . $this->date_table . " as dt" . " JOIN " . $this->day_date_table . " as dy ON dy.id_date = dt.id_date" . " LEFT JOIN " . $this->user_date_table . " as du ON du.id_date = dt.id_date" . " LEFT JOIN " . $this->user_table . " AS u ON u.idst = du.id_user" . " WHERE dt.id_course = " . $id_course . (!empty($ed_arr) && is_array($ed_arr) ? " AND dt.id_date IN (" . implode(",", $ed_arr) . ") " : "") . " GROUP BY dt.id_date";
     switch ($sort) {
         case 'code':
             $query .= " ORDER BY dt.code " . $dir . ", dt.name " . $dir . ", date_begin " . $dir;
             break;
         case 'name':
             $query .= " ORDER BY dt.name " . $dir . ", date_begin " . $dir;
             break;
         case 'status':
             $query .= " ORDER BY dt.status " . $dir . ", dt.code " . $dir . ", dt.name " . $dir . ", date_begin " . $dir;
             break;
         case 'date_begin':
             $query .= " ORDER BY date_begin " . $dir . ", dt.code " . $dir . ", dt.name " . $dir;
             break;
         case 'date_end':
             $query .= " ORDER BY date_end " . $dir . ", date_begin " . $dir . ", dt.code " . $dir . ", dt.name " . $dir;
             break;
     }
     $start_index === false ? '' : ($query .= " LIMIT " . $start_index . ", " . $results);
     $result = sql_query($query);
     $res = array();
     while (list($id_date, $code, $name, $status, $date_begin, $date_end, $num_day, $user_subscribed, $unsubscribe_date_limit) = sql_fetch_row($result)) {
         if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
             require_once _base_ . '/lib/lib.preference.php';
             $adminManager = new AdminPreference();
             $query = "SELECT COUNT(*)" . " FROM " . $this->user_date_table . " WHERE id_date = '" . $id_date . "'" . " AND " . $adminManager->getAdminUsersQuery(Docebo::user()->getIdSt(), 'id_user');
             list($user_subscribed) = sql_fetch_row(sql_query($query));
             $query = "SELECT COUNT(*) FROM %lms_courseuser AS cu JOIN %lms_course_date AS cd JOIN %lms_course_date_user AS cdu " . " ON (cd.id_date = cdu.id_date AND cd.id_course = cu.idCourse AND cu.idUser = cdu.id_user) " . " WHERE cd.id_date = " . (int) $id_date . " AND cu.level = 3" . " AND " . $adminManager->getAdminUsersQuery(Docebo::user()->getIdSt(), 'u.id_user');
             list($num_student) = sql_fetch_row(sql_query($query));
         } else {
             $query = "SELECT COUNT(*) FROM %lms_courseuser AS cu JOIN %lms_course_date AS cd JOIN %lms_course_date_user AS cdu " . " ON (cd.id_date = cdu.id_date AND cd.id_course = cu.idCourse AND cu.idUser = cdu.id_user) " . " WHERE cd.id_date = " . (int) $id_date . " AND cu.level = 3";
             list($num_student) = sql_fetch_row(sql_query($query));
         }
         $res[] = array('id_date' => $id_date, 'code' => $code, 'name' => $name, 'status' => $status, 'date_begin' => Format::date($date_begin, 'date'), 'date_end' => Format::date($date_end, 'date'), 'classroom' => $this->getDateClassrooms($id_date, true), 'students' => $num_student, 'num_subscribe' => $user_subscribed, 'subscription' => '<a href="index.php?r=' . (Docebo::user()->getUserLevelId() == ADMIN_GROUP_PUBLICADMIN ? 'lms/p' : 'alms/') . 'subscription/show&id_course=' . $id_course . '&amp;id_date=' . $id_date . '" title="' . Lang::t('_SUBSCRIPTION', 'course') . '">' . ($user_subscribed ? $user_subscribed : 0) . ' <span class="ico-sprite subs_' . ($user_subscribed > 0 ? 'users' : 'notice') . '"><span>' . Lang::t('_USER_STATUS_SUBS') . '</span></span></a>', 'presence' => '<a href="index.php?r=' . (Docebo::user()->getUserLevelId() == ADMIN_GROUP_PUBLICADMIN ? 'lms/p' : 'alms/') . 'classroom/presence&id_course=' . $id_course . '&amp;id_date=' . $id_date . '">' . Lang::t('_ATTENDANCE', 'course') . '</a>', 'num_day' => $num_day, 'user_subscribed' => $user_subscribed, 'mod' => '<a href="index.php?r=' . (Docebo::user()->getUserLevelId() == ADMIN_GROUP_PUBLICADMIN ? 'lms/p' : 'alms/') . 'classroom/modclassroom&id_course=' . $id_course . '&amp;id_date=' . $id_date . '">' . Get::img('standard/edit.png', Lang::t('_MOD', 'course')) . '</a>', 'del' => 'ajax.adm_server.php?r=' . (Docebo::user()->getUserLevelId() == ADMIN_GROUP_PUBLICADMIN ? 'lms/p' : 'alms/') . 'classroom/delclassroom&id_course=' . $id_course . '&amp;id_date=' . $id_date, 'unsubscribe_date_limit' => $unsubscribe_date_limit);
     }
     return $res;
 }
Пример #23
0
 public function getCourseEditionSubscription($id_course, $id_edition, $start_index, $results, $sort, $dir, $filter)
 {
     $query = "SELECT u.idst, u.userid, u.firstname, u.lastname, s.level, s.status, s.date_begin_validity, s.date_expire_validity" . " FROM " . $this->courseuser_table . " AS s" . " JOIN " . $this->user_table . " AS u ON s.idUser = u.idst" . " WHERE s.idCourse = " . (int) $id_course . " AND u.idst IN (" . implode(', ', $this->getEditionSubscribed($id_edition)) . ")";
     if (is_array($filter)) {
         if (isset($filter['text']) && $filter['text'] != "") {
             $query .= " AND (u.userid LIKE '%" . $filter['text'] . "%' OR u.firstname LIKE '%" . $filter['text'] . "%' OR u.lastname LIKE '%" . $filter['text'] . "%') ";
         }
         $arr_idst = array();
         if (isset($filter['orgchart']) && $filter['orgchart'] > 0) {
             $umodel = new UsermanagementAdm();
             $use_desc = isset($filter['descendants']) && $filter['descendants'];
             $ulist = $umodel->getFolderUsers($filter['orgchart'], $use_desc);
             if (!empty($ulist)) {
                 $arr_idst = $ulist;
             }
             unset($ulist);
         }
         if (!empty($arr_idst)) {
             $conditions[] = " AND u.idst IN (" . implode(",", $arr_idst) . ") ";
         }
         if (isset($filter['date_valid']) && strlen($filter['date_valid']) >= 10) {
             $query .= " AND (s.date_begin_validity <= '" . $filter['date_valid'] . "' OR s.date_begin_validity IS NULL OR s.date_begin_validity='0000-00-00 00:00:00') ";
             $query .= " AND (s.date_expire_validity >= '" . $filter['date_valid'] . "' OR s.date_expire_validity IS NULL OR s.date_expire_validity='0000-00-00 00:00:00') ";
         }
         if (isset($filter['show'])) {
             //validate values
             switch ($filter['show']) {
                 case 0:
                     //all
                     //no condition to check ...
                     break;
                 case 1:
                     //expired
                     $query .= " AND (s.date_expire_validity IS NOT NULL AND s.date_expire_validity < NOW())";
                     break;
                 case 2:
                     //not expired with expiring date
                     $query .= " AND (s.date_expire_validity IS NOT NULL AND s.date_expire_validity > NOW())";
                     break;
                 case 3:
                     //not expired without expiring date
                     $query .= " AND (s.date_expire_validity IS NULL OR s.date_expire_validity='' OR s.date_expire_validity='0000-00-00 00:00:00') ";
                     break;
                 default:
                     //all ...
                     break;
             }
         }
     }
     if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $query .= " AND " . $adminManager->getAdminUsersQuery(Docebo::user()->getIdSt(), 'idUser');
     }
     switch ($sort) {
         case 'userid':
             $query .= " ORDER BY u.userid " . $dir;
             break;
         case 'fullname':
             $query .= " ORDER BY u.firstname " . $dir . ", u.lastname " . $dir . ", u.userid " . $dir;
             break;
         case 'level':
             $query .= " ORDER BY s.level " . $dir . ", u.userid " . $dir;
             break;
         case 'status':
             $query .= " ORDER BY s.status " . $dir . ", u.userid " . $dir;
             break;
     }
     $start_index === false ? '' : ($query .= " LIMIT " . $start_index . ", " . $results);
     $result = sql_query($query);
     $res = array();
     while (list($id_user, $userid, $firstname, $lastname, $level, $status, $date_begin_validity, $date_expire_validity) = sql_fetch_row($result)) {
         if ($firstname !== '' && $lastname !== '') {
             $user = $firstname . ' ' . $lastname;
         } elseif ($firstname !== '') {
             $user = $firstname;
         } elseif ($lastname !== '') {
             $user = $lastname;
         } else {
             $user = '';
         }
         $res[] = array('sel' => '', 'id_user' => $id_user, 'userid' => $this->acl_man->relativeId($userid), 'fullname' => $user, 'level_id' => $level, 'status_id' => $status, 'date_begin_validity' => $date_begin_validity, 'date_expire_validity' => $date_expire_validity, 'del' => 'ajax.adm_server.php?r=' . (Docebo::user()->getUserLevelId() == ADMIN_GROUP_PUBLICADMIN ? 'lms/p' : 'alms/') . 'subscription/delPopUp&id_course=' . $id_course . '&id_edition=' . $id_edition . '&id_user=' . $id_user);
     }
     return $res;
 }
Пример #24
0
 public function getClassrooms($start_index = false, $results = false, $sort = false, $dir = false, $categories = false, $filter_text = false, $filter_waiting = false)
 {
     require_once _lms_ . '/lib/lib.date.php';
     $date_man = new DateManager();
     $status_list = array(CST_PREPARATION => Lang::t('_CST_PREPARATION', 'course'), CST_AVAILABLE => Lang::t('_CST_AVAILABLE', 'course'), CST_EFFECTIVE => Lang::t('_CST_CONFIRMED', 'course'), CST_CONCLUDED => Lang::t('_CST_CONCLUDED', 'course'), CST_CANCELLED => Lang::t('_CST_CANCELLED', 'course'));
     $query = "SELECT c.idCourse, c.code, c.name, c.status, COUNT(cd.id_date) as classroom_number " . " FROM %lms_course as c LEFT JOIN %lms_course_date as cd ON c.idCourse=cd.id_course " . " WHERE c.course_type = 'classroom' ";
     //if ($categories) {
     if (!is_array($categories)) {
         $query .= " AND c.idCategory = " . (int) $categories . " ";
     } else {
         $query .= " AND c.idCategory IN (" . implode(',', $categories) . ") ";
     }
     //}
     if ($filter_text) {
         if (is_string($filter_text)) {
             $query .= " AND (c.code LIKE '%" . $filter_text . "%' " . " OR c.name LIKE '%" . $filter_text . "%' " . " OR c.description LIKE '%" . $filter_text . "%') ";
         }
     }
     if ($filter_waiting) {
         $query .= " AND c.idCourse IN" . " (" . " SELECT idCOurse" . " FROM %lms_courseuser" . " WHERE waiting = 1" . " )";
     }
     $userlevelid = Docebo::user()->getUserLevelId();
     $is_subadmin = false;
     $all_courses = false;
     if ($userlevelid != ADMIN_GROUP_GODADMIN) {
         require_once _base_ . '/lib/lib.preference.php';
         $adminManager = new AdminPreference();
         $admin_courses = $adminManager->getAdminCourse(Docebo::user()->getIdST());
         $all_courses = false;
         if (isset($admin_courses['course'][0])) {
             $all_courses = true;
         } elseif (isset($admin_courses['course'][-1])) {
             require_once _lms_ . '/lib/lib.catalogue.php';
             $cat_man = new Catalogue_Manager();
             $user_catalogue = $cat_man->getUserAllCatalogueId(Docebo::user()->getIdSt());
             if (count($user_catalogue) > 0) {
                 $courses = array(0);
                 foreach ($user_catalogue as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     $courses = array_merge($courses, $catalogue_course);
                 }
                 foreach ($courses as $id_course) {
                     if ($id_course != 0) {
                         $admin_courses['course'][$id_course] = $id_course;
                     }
                 }
             } elseif (Get::sett('on_catalogue_empty', 'off') == 'on') {
                 $all_courses = true;
             }
         } else {
             $array_courses = array();
             $array_courses = array_merge($array_courses, $admin_courses['course']);
             if (!empty($admin_courses['coursepath'])) {
                 require_once _lms_ . '/lib/lib.coursepath.php';
                 $path_man = new Catalogue_Manager();
                 $coursepath_course =& $path_man->getAllCourses($admin_courses['coursepath']);
                 $array_courses = array_merge($array_courses, $coursepath_course);
             }
             if (!empty($admin_courses['catalogue'])) {
                 require_once _lms_ . '/lib/lib.catalogue.php';
                 $cat_man = new Catalogue_Manager();
                 foreach ($admin_courses['catalogue'] as $id_cat) {
                     $catalogue_course =& $cat_man->getCatalogueCourse($id_cat, true);
                     $array_courses = array_merge($array_courses, $catalogue_course);
                 }
             }
             $admin_courses['course'] = array_merge($admin_courses['course'], $array_courses);
         }
         $is_subadmin = true;
     }
     $query .= $is_subadmin && !$all_courses ? !empty($admin_courses['course']) ? ' AND c.idCourse IN (' . implode(',', $admin_courses['course']) . ')' : ' AND c.idCourse = 0' : '';
     $query .= " GROUP BY c.idCourse ";
     switch ($sort) {
         case 'code':
             $query .= " ORDER BY c.code " . $dir;
             break;
         case 'name':
             $query .= " ORDER BY c.name " . $dir;
             break;
     }
     $start_index === false ? '' : ($query .= " LIMIT " . $start_index . ", " . $results);
     $result = sql_query($query);
     $res = array();
     while (list($id_course, $code, $name, $status, $classroom_number) = sql_fetch_row($result)) {
         //$classroom_number = $date_man->getCourseDateNumber($id_course);
         $res[] = array('id_course' => $id_course, 'code' => $code, 'name' => $name, 'status' => $status_list[$status], 'classroom_number' => $classroom_number);
     }
     return $res;
 }