public function cataloguesubscribeusersTask() { require_once _adm_ . '/lib/lib.directory.php'; require_once _adm_ . '/class.module/class.directory.php'; require_once _lms_ . '/lib/lib.course.php'; require_once _lms_ . '/lib/lib.edition.php'; require_once _lms_ . '/lib/lib.date.php'; $acl_man =& Docebo::user()->getAclManager(); $edition_man = new EditionManager(); $date_man = new DateManager(); $id_catalogue = Get::req('id_catalogue', DOTY_INT, 0); $back_url = 'index.php?modname=catalogue&op=catlist&of_platform=lms'; $jump_url = 'index.php?r=' . $this->link . '/cataloguesubscribeusers'; //if we are a subadmin, check which courses/catalogues we can see $can_see_catalogue = true; if (Docebo::user()->getUserLevelId() != 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; } 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 (!isset($admin_courses['catalogue'][$id_catalogue])) { $can_see_catalogue = false; } } //invalid specified catalogue if ($id_catalogue <= 0 || !$can_see_catalogue) { $this->render('invalid', array('message' => Lang::t('_INVALID_CATALOGUE', 'subscribe'), 'back_url' => $back_url)); return; } //check if the selected catalogue has any courses $courses_list = $this->_getCatalogueCourses($id_catalogue, isset($admin_courses['course']) ? $admin_courses['course'] : false); if (count($courses_list) <= 0) { $this->render('invalid', array('message' => Lang::t('_NO_COURSES_IN_THE_CATALOGUE', 'subscribe'), 'back_url' => $back_url)); return; } $name = $this->_getCatalogueName($id_catalogue); if (isset($_POST['cancelselector'])) { //--- UNDO: return to catalogue list ------------------------------------- Util::jump_to($back_url); } elseif (isset($_POST['okselector'])) { //--- USERS SELECTION IS CONFIRMED: now select editions (if any) --------- //check user selection $_selector = new UserSelector(); $json = new Services_JSON(); $_entity_selected = $_selector->getSelection($_POST); $user_selected =& $acl_man->getAllUsersFromSelection($_entity_selected); //free some memory from garbage variables unset($_selector); unset($_entity_selected); //if no user selected, than give invalid screen if (!is_array($user_selected) || count($user_selected) <= 0) { $this->render('invalid', array('message' => Lang::t('_EMPTY_SELECTION', 'subscribe'), 'back_url' => $back_url)); return; } //extract editions info data by courses $editions_list = $edition_man->getEditionsInfoByCourses(array_keys($courses_list), true); //extract editions info data by courses $classrooms_list = $date_man->getDatesInfoByCourses(array_keys($courses_list), true); $tables = array('editions' => false, 'classrooms' => false); //check if the catalogue has editions; if any, than set the editions selector if (count($editions_list) > 0 || count($classrooms_list) > 0) { //set title $page_title_arr = array($back_url => Lang::t('_SUBSCRIBE', 'subscribe'), $name, Lang::t('_SUBSCRIBE', 'subscribe')); if (count($editions_list) > 0) { //instantiate a new table for editions selection require_once _base_ . '/lib/lib.table.php'; $tb = new Table(0, Lang::t('_CATALOGUE_SUBSCRIBE_CHOOSE_EDITIONS', 'subscribe'), Lang::t('_CATALOGUE_SUBSCRIBE_CHOOSE_EDITIONS', 'subscribe')); $head_style = array('align_center', '', 'align_center'); $head_label = array(Lang::t('_COURSE_CODE', 'course'), Lang::t('_COURSE_NAME', 'course'), Lang::t('_CLASSROOM_EDITION', 'course')); $tb->addHead($head_label, $head_style); //set table rows foreach ($editions_list as $id_course => $editions) { $line = array(); $cinfo = $courses_list[$id_course]; $line[] = $cinfo->code; $line[] = $cinfo->name; //create the dropdown with the editions for every course $_dropdown = array(); foreach ($editions as $id_edition => $ed_info) { $_line_content = ''; //print begin and end date if ($ed_info->date_begin != '') { $_line_content .= '[' . $ed_info->code . '] ' . $ed_info->name . ' ' . '(' . Format::date($ed_info->date_begin, 'date') . ' - ' . Format::date($ed_info->date_end, 'date') . ')'; } //check if the string is valid if ($_line_content == '') { //... } //add to dropdown list and sort the list alphabetically $_dropdown[$id_edition] = $_line_content; asort($_dropdown); } $line[] = Form::getInputDropdown('dropdown', 'sel_editions_' . $id_course, 'sel_editions[' . $id_course . ']', $_dropdown, false, ''); $tb->addBody($line); } $tables['editions'] = $tb; } if (count($classrooms_list) > 0) { //instantiate a new table for editions selection require_once _base_ . '/lib/lib.table.php'; $tb = new Table(0, Lang::t('_COURSE_TYPE_EDITION', 'course'), Lang::t('_CLASSROOM', 'standard')); $head_style = array('align_center', '', 'align_center'); $head_label = array(Lang::t('_COURSE_CODE', 'course'), Lang::t('_COURSE_NAME', 'course'), Lang::t('_CLASSROOM_EDITION', 'course')); $tb->addHead($head_label, $head_style); //set table rows foreach ($classrooms_list as $id_course => $classrooms) { $line = array(); $cinfo = $courses_list[$id_course]; $line[] = $cinfo->code; $line[] = $cinfo->name; //create the dropdown with the editions for every course $_dropdown = array(); foreach ($classrooms as $id_date => $cl_info) { $_line_content = ''; //print begin and end date if ($cl_info->date_begin != '') { $_line_content .= '[' . $cl_info->code . '] ' . $cl_info->name . ' ' . '(' . Format::date($cl_info->date_begin, 'date') . ' - ' . Format::date($cl_info->date_end, 'date') . ')'; } //check if the string is valid if ($_line_content == '') { //... } //add to dropdown list and sort the list alphabetically $_dropdown[$id_date] = $_line_content; asort($_dropdown); } $line[] = Form::getInputDropdown('dropdown', 'sel_classrooms_' . $id_course, 'sel_classrooms[' . $id_course . ']', $_dropdown, false, ''); $tb->addBody($line); } $tables['classrooms'] = $tb; } $this->render('catalogue_editions', array('id_catalogue' => $id_catalogue, 'page_title_arr' => $page_title_arr, 'num_users_selected' => count($user_selected), '_sel_users' => $json->encode($user_selected), 'tables' => $tables)); } else { //no editions in the catalogue's courses, call the save operation directly $data = array(); foreach ($user_selected as $user) { foreach ($courses_list as $idCourse => $course) { $data[] = array($user, $idCourse, false, false); } } $num_subscribed = $this->_subscribeUsersToCatalogue($data); Util::jump_to($back_url . '&res=' . $num_subscribed); //_operation_successful } } else { //--- USER SELECTION IS IN PROGRESS: show selector ----------------------- $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; //filter selectable user by sub-admin permission $user_select->setUserFilter('exclude', array($this->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 = $this->acl_man->getAllUsersFromIdst($admin_tree); $user_select->setUserFilter('user', $admin_users); $user_select->setUserFilter('group', $admin_tree); } if (Get::req('is_updating', DOTY_INT, false)) { //... } else { $user_select->requested_tab = PEOPLEVIEW_TAB; $user_select->resetSelection(); } $page_title_arr = array($back_url => Lang::t('_SUBSCRIBE', 'subscribe'), $name, Lang::t('_SUBSCRIBE', 'subscribe')); $user_select->addFormInfo(Form::getHidden('is_updating', 'is_updating', 1) . Form::getHidden('id_catalogue', 'id_catalogue', $id_catalogue)); //$user_select->setPageTitle($page_title_arr); //$user_select->resetSelection($_SESSION['report_tempdata']['rows_filter']['users']); $user_select->loadSelector(Util::str_replace_once('&', '&', $jump_url), $page_title_arr, false, true); } }