public function getCourseInfoForSubscription() { if ($this->id_edition != 0) { require_once _lms_ . '/lib/lib.edition.php'; $edition_man = new EditionManager(); $edition_info = $edition_man->getEditionInfo($this->id_edition); require_once _lms_ . '/lib/lib.course.php'; $course_info = Man_Course::getCourseInfo($this->id_course); $res = array('max_num_subscribe' => $edition_info['max_num_subscribe'], 'subscribe_method' => $course_info['subscribe_method'], 'code' => $edition_info['code'], 'name' => $edition_info['name'], 'medium_time' => $course_info['mediumTime'], 'course_type' => $course_info['course_type'], 'date_begin' => $edition_info['date_begin'], 'date_end' => $edition_info['date_end']); } elseif ($this->id_date != 0) { require_once _lms_ . '/lib/lib.date.php'; $date_man = new DateManager(); $date_info = $date_man->getDateInfo($this->id_date); require_once _lms_ . '/lib/lib.course.php'; $course_info = Man_Course::getCourseInfo($this->id_course); $res = array('max_num_subscribe' => $course_info['max_num_subscribe'], 'subscribe_method' => $course_info['subscribe_method'], 'code' => $date_info['code'], 'name' => $date_info['name'], 'medium_time' => $course_info['mediumTime'], 'course_type' => $course_info['course_type'], 'date_begin' => $date_info['date_begin'], 'date_end' => $date_info['date_end']); } else { require_once _lms_ . '/lib/lib.course.php'; $course_info = Man_Course::getCourseInfo($this->id_course); $res = array('max_num_subscribe' => $course_info['max_num_subscribe'], 'subscribe_method' => $course_info['subscribe_method'], 'code' => $course_info['code'], 'name' => $course_info['name'], 'medium_time' => $course_info['mediumTime'], 'course_type' => $course_info['course_type'], 'date_begin' => $course_info['date_begin'], 'date_end' => $course_info['date_end']); } return $res; }
function modTransaction() { require_once _base_ . '/lib/lib.table.php'; require_once _base_ . '/lib/lib.form.php'; require_once _base_ . '/lib/lib.dialog.php'; require_once _lms_ . '/lib/lib.course.php'; require_once _lms_ . '/lib/lib.date.php'; $lang =& DoceboLanguage::createInstance('transaction'); $acl_man = Docebo::user()->getAclManager(); $man_transaction = new Man_Transaction(); $course_man = new Man_Course(); $date_man = new DateManager(); $id_transaction = Get::req('id', DOTY_INT, 0); $transaction_info = $man_transaction->getTransactionInfo($id_transaction); if (isset($_POST['update'])) { $payment_status = Get::req('payment_status', DOTY_INT, 0); $course_status = Get::req('course_status', DOTY_INT, 0); $note = Get::req('note', DOTY_MIXED, ''); if ($man_transaction->updateTransaction($id_transaction, $payment_status, $course_status, $note)) { if (isset($_POST['confirm'])) { $activations = array(); foreach ($_POST['confirm'] as $id => $n) { list($id_course, $id_date) = explode('_', $id); if ($id_date != 0) { $activations[$id_course]['dates'][$id_date] = $id_date; } else { $activations[$id_course] = $id_course; } } if ($man_transaction->activateCourses($id_transaction, $transaction_info['id_user'], $activations)) { Util::jump_to('index.php?modname=transaction&op=transaction&res=ok'); } } else { Util::jump_to('index.php?modname=transaction&op=transaction&res=ok'); } } Util::jump_to('index.php?modname=transaction&op=transaction&res=err_up'); } $array_title = array('index.php?modname=transaction&op=transaction' => $lang->def('_TRANSACTION'), $lang->def('_MOD_TRANSACTION')); //Status info & note $array_payment_status = array('-1' => $lang->def('_CANCELLED'), '0' => $lang->def('_WAITING_PAYMENT'), '1' => $lang->def('_PARTIAL_PAID'), '2' => $lang->def('_PAID')); $array_course_status = array('-1' => $lang->def('_CANCELLED'), '0' => $lang->def('_NO_COURSE_ACTIVATED'), '1' => $lang->def('_SOME_COURSE_ACTIVATED'), '2' => $lang->def('_ALL_COURSE_ACTIVATED')); cout(getTitleArea($array_title) . '<div class="std_block">' . Form::openForm('transaction_info', 'index.php?modname=transaction&op=mod&id=' . $id_transaction) . Form::openElementSpace() . Form::getDropdown($lang->def('_PAYMENT_STATUS_FILTER'), 'payment_status', 'payment_status', $array_payment_status, $transaction_info['payment_status']) . Form::getDropdown($lang->def('_COURSE_STATUS_FILTER'), 'course_status', 'course_status', $array_course_status, $transaction_info['course_status']) . Form::getSimpleTextarea($lang->def('_NOTES'), 'note', 'note', $transaction_info['note']) . Form::closeElementSpace()); //User info $user_info = $acl_man->getUser($transaction_info['id_user'], false); $tb_user = new Table(0, $lang->def('_USER_INFO'), $lang->def('_USER_INFO')); $cont_h = array($lang->def('_USERNAME'), $lang->def('_FIRSTNAME'), $lang->def('_LASTNAME'), $lang->def('_EMAIL')); $type_h = array('', '', '', ''); $tb_user->setColsStyle($type_h); $tb_user->addHead($cont_h); $tb_user->addBody(array($acl_man->relativeId($user_info[ACL_INFO_USERID]), $user_info[ACL_INFO_FIRSTNAME], $user_info[ACL_INFO_LASTNAME], $user_info[ACL_INFO_EMAIL])); cout('<br />' . $tb_user->getTable()); //Payment info if we need it //Product info $tb_product = new Table(0, $lang->def('_PRODUCT_INFO'), $lang->def('_PRODUCT_INFO')); $cont_h = array($lang->def('_CODE'), $lang->def('_NAME'), $lang->def('_DATE_BEGIN'), $lang->def('_DATE_END'), $lang->def('_COURSE_PRIZE'), $lang->def('_CONFIRM_COURSE')); $type_h = array('', '', '', '', '', ''); $tb_product->setColsStyle($type_h); $tb_product->addHead($cont_h); $transaction_course = $man_transaction->getTransactionCourses($id_transaction); foreach ($transaction_course as $id_course => $details) { if (is_array($details)) { foreach ($details['dates'] as $id_date) { $date_info = $date_man->getDateInfo($id_date); $checked = false; $other = ''; if ($man_transaction->controlActivation($id_transaction, $id_course, $id_date)) { $checked = true; $other = 'disabled="disabled"'; } $tb_product->addBody(array($date_info['code'], $date_info['name'], Format::date($date_info['date_begin']), Format::date($date_info['date_end']), $date_info['price'], Form::getInputCheckbox($id_course . '_' . $id_date, 'confirm[' . $id_course . '_' . $id_date . ']', 1, $checked, $other))); } } else { $course_info = $course_man->getCourseInfo($id_course); $checked = false; $other = ''; if ($man_transaction->controlActivation($id_transaction, $id_course)) { $checked = true; $other = 'disabled="disabled"'; } $tb_product->addBody(array($course_info['code'], $course_info['name'], $course_info['date_begin'] !== '0000-00-00' ? Format::date($course_info['date_begin'], 'date') . ($course_info['hour_begin'] !== '-1' ? $course_info['hour_begin'] : '') : '', $course_info['date_end'] !== '0000-00-00' ? Format::date($course_info['date_end'], 'date') . ($course_info['hour_end'] !== '-1' ? $course_info['hour_end'] : '') : '', $course_info['prize'] == '' ? '0' : $course_info['prize'], Form::getInputCheckbox($id_course . '_0', 'confirm[' . $id_course . '_0]', 1, $checked, $other))); } } cout('<br />' . $tb_product->getTable() . Form::openButtonSpace() . Form::getButton('update', 'update', $lang->def('_UPDATE')) . Form::getButton('back_mod', 'back_mod', $lang->def('_BACK')) . Form::closeButtonSpace() . Form::closeForm()); cout('</div>'); }
function savePanel() { checkPerm('mod'); require_once _base_ . '/lib/lib.form.php'; require_once _adm_ . '/lib/lib.publicadminmanager.php'; require_once _lms_ . '/lib/lib.course.php'; require_once _lms_ . '/lib/lib.date.php'; require_once _lms_ . '/lib/lib.competences.php'; $save = Get::req('save', DOTY_MIXED, false); $undo = Get::req('undo', DOTY_MIXED, false); $update = Get::req('update', DOTY_MIXED, false); $db = DbConn::getInstance(); $lang =& DoceboLanguage::CreateInstance('public_coursepanel', 'lms'); $man_competences = new Competences_Manager(); //back page link $back_ui = getBackUi('index.php?modname=public_coursepanel&op=coursepanel', $lang->def('_BACK')); cout(getTitleArea($lang->def('_COURSEPANEL'), 'coursepanel') . '<div class="std_block">' . $back_ui, 'content'); $sel_competence = Get::req('sel_competence', DOTY_INT, false); $sel_course = Get::req('sel_course', DOTY_INT, false); $required_filter = Get::req('required_filter', DOTY_INT, 0); $is_retraining = $man_competences->isRetrainingCourse($sel_course, $sel_competence); $back_url = "index.php?modname=public_coursepanel&op=coursepanel&sel_competence=" . (int) $sel_competence . "&sel_course=" . (int) $sel_course; if ($required_filter > 0) { $back_url .= '&required_filter=1'; } $to_consider = Get::req('to_consider', DOTY_MIXED, false); if ($to_consider) { require_once _base_ . '/lib/lib.json.php'; $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $to_consider = $json->decode(base64_decode($to_consider)); } else { $to_consider = array('users' => array(), 'editions' => array()); } if ($undo) { Util::jump_to("index.php"); } elseif ($save) { //change users' subscription to course editions $data = Get::req('subscriptions', DOTY_MIXED, array()); $man_course = new Man_Course(); $course_info = $man_course->getCourseInfo($sel_course); if (!$sel_competence || !$sel_course) { //error ... Util::jump_to($back_url . "&err=invalid"); } //check the admin level of the current user, if it's not an admin or the idst is invalid, return an error $id_pa = getLogUserId(); if (!$id_pa) { Util::jump_to($back_url . "&err=invalid"); } $acl_man = new DoceboACLManager(); $admin_manager = new PublicAdminManager(); $array_users = array(); $idst_associated = $admin_manager->getAdminTree($id_pa); $array_users =& $acl_man->getAllUsersFromIdst($idst_associated); $array_users = array_unique($array_users); if (empty($array_users)) { Util::jump_to($back_url . "&err=invalid"); } //filter array of user ids by competence $filtered_users = array(); $query_filter = "SELECT id_user FROM %lms_competence_user WHERE id_user IN (" . implode(",", $array_users) . ") AND id_competence='" . (int) $sel_competence . "'"; $res_filter = $db->query($query_filter); while (list($idst) = $db->fetch_row($res_filter)) { $filtered_users[] = $idst; } $subs_limit = array(); $subs_count = array(); if ($course_info['course_type'] == 'elearning') { $editions[] = $sel_course; $subscribed[$sel_course] = getSubscribed((int) $sel_course); $course_info = $man_course->getCourseInfo($sel_course); $subs_count[$sel_course] = count($data); } elseif ($course_info['course_type'] == 'classroom') { //get all combinations id_user - id_date $date_man = new DateManager(); $editions = array(); $query_editions = "SELECT id_date, id_course, code, name FROM %lms_course_date WHERE id_course='" . (int) $sel_course . "'"; $res_editions = $db->query($query_editions); while (list($id_edition, $id_course, $code, $name) = $db->fetch_row($res_editions)) { $editions[] = $id_edition; $subscribed[$id_edition] = $date_man->getDateSubscribed($id_edition); $date_info = $date_man->getDateInfo($id_edition); $subs_limit[$id_edition] = array('max' => $date_info['max_par'], 'subs' => $date_info['user_subscribed']); $subs_count[$id_edition] = 0; } } //------------------------------------------------------------------------------ //count the users to be subscribed/unsubscribed and check subscription limits, if any //subtract users to de-subscribe from courses foreach ($subscribed as $id_edition => $users_list) { foreach ($users_list as $id_user) { if ($course_info['course_type'] == 'elearning') { if (!isset($data[$id_user])) { $subs_count[$id_edition]--; } } elseif ($course_info['course_type'] == 'classroom') { //check if the current selection match the current subscriptions if (!isset($data[$id_user][$id_edition])) { $subs_count[$id_edition]--; } } } } foreach ($data as $user => $edition_list) { //id user foreach ($edition_list as $edition => $val) { //id date edition if (isset($subscribed[$edition][$user])) { //already subscribed, do nothing } else { $subs_count[$edition]++; } } } //check if we have enough room to subscribe users //{at the moment, rely on js ...} //------------------------------------------------------------------------------ //unsubscribe deselected users foreach ($subscribed as $id_edition => $users_list) { foreach ($users_list as $id_user) { if ($course_info['course_type'] == 'elearning') { if (!isset($data[$id_user])) { if (in_array($id_user, $to_consider['users']) && in_array($id_edition, $to_consider['editions'])) { $group_levels = DoceboCourse::getCourseLevel($sel_course); $user_levels = getSubscribedLevel($sel_course, false, false, 0); $_res = _removeCourseSubscription($sel_course, $id_user, $group_levels[$user_levels[$id_user]], 0); } } } elseif ($course_info['course_type'] == 'classroom') { //check if the current selection match the current subscriptions if (!isset($data[$id_user][$id_edition])) { if (in_array($id_user, $to_consider['users']) && in_array($id_edition, $to_consider['editions'])) { $date_man->removeUserFromDate($id_user, $id_edition, $sel_course); } } } } } //------------------------------------------------------------------------------ //check every single user for inscription $count = 0; $lv_sel = 3; //student level $waiting = 0; //don't subscribe as "waiting for approvation" //retrive id of group of the course for the varioud level $level_idst = DoceboCourse::getCourseLevel((int) $sel_course); //if the group doesn't exists create it if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& DoceboCourse::createCourseLevel((int) $sel_course); } foreach ($data as $user => $edition_list) { //id user foreach ($edition_list as $edition => $val) { //id date edition if (isset($subscribed[$edition][$user])) { //already subscribed, do nothing } else { //this user is to be subscribed, do it //add to level group of the course $acl_man->addToGroup($level_idst[$lv_sel], $user); // Add in table $re = $db->query("INSERT INTO %lms_courseuser (idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr)" . " VALUES ( '" . (int) $user . "', '" . (int) $sel_course . "', '0', '" . $lv_sel . "', '" . $waiting . "', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t"); //additional operations for editions if ($course_info['course_type'] == 'elearning') { //... } elseif ($course_info['course_type'] == 'classroom') { $ret = $date_man->addUserToDate($edition, $user, getLogUserId()); if ($ret) { $count++; } } } } } Util::jump_to($back_url . "&err=ok&count=" . (int) $count); } elseif ($update) { $sel_competence = Get::req('sel_competence', DOTY_INT, false); $sel_course = Get::req('sel_course', DOTY_INT, false); Util::jump_to($back_url); //."&sel_competence=".(int)$sel_competence."&sel_course=".(int)$sel_course); } else { //... } cout($back_ui . '</div>', 'content'); }