Beispiel #1
0
 public function addUserSubscription($params)
 {
     require_once _lms_ . '/lib/lib.subscribe.php';
     require_once _lms_ . '/lib/lib.course.php';
     $output = array();
     $output['success'] = true;
     if (empty($params['idst']) || (int) $params['idst'] <= 0) {
         return false;
         // return array('success'=>true, 'debug'=>print_r($params, true));
     } else {
         $user_id = $params['idst'];
     }
     $course_id = isset($params['course_id']) ? (int) $params['course_id'] : false;
     $course_code = isset($params['course_code']) ? $params['course_code'] : false;
     $edition_id = isset($params['edition_id']) ? (int) $params['edition_id'] : false;
     $edition_code = isset($params['edition_code']) ? $params['edition_code'] : false;
     $classroom_id = isset($params['classroom_id']) ? (int) $params['classroom_id'] : false;
     $classroom_code = isset($params['classroom_code']) ? $params['classroom_code'] : false;
     $user_level = $this->getUserLevelId(isset($params['user_level']) ? $params['user_level'] : 'student');
     // $user_status =(isset($params['user_status']) ? $params['user_status'] : false);
     $acl_man = Docebo::user()->getAclManager();
     $course_man = new Man_Course();
     $db = DbConn::getInstance();
     $course_info = false;
     $edition_info = false;
     $classroom_info = false;
     $this->fillCourseDataFromParams($params, $db, $course_id, $edition_id, $classroom_id, $course_code, $edition_code, $classroom_code, $course_info, $edition_info, $classroom_info, $output);
     // --------------- add user: -----------------------------------
     $model = new SubscriptionAlms($course_id, $edition_id, $classroom_id);
     $docebo_course = new DoceboCourse($course_id);
     $level_idst = $docebo_course->getCourseLevel($course_id);
     if (count($level_idst) == 0 || $level_idst[1] == '') {
         $level_idst = $docebo_course->createCourseLevel($course_id);
     }
     $waiting = 0;
     $acl_man->addToGroup($level_idst[$user_level], $user_id);
     $subscribe_ok = $model->subscribeUser($user_id, $user_level, $waiting, false, false);
     if (!$subscribe_ok) {
         $acl_man->removeFromGroup($level_idst[$user_level], $user_id);
         $output['success'] = false;
     } else {
         $output['message'] = 'User has been subscribed to the course';
     }
     return $output;
 }
 /**
  * assign a group of user to a preassessment, you can specify if the users are administrator or not
  * @param int 	$id_assessment 	the id of the assessment
  * @param int 	$user_type 		is the identifier of the type of the user, use the constant USER_ASSES_TYPE_ADMIN, USER_ASSES_TYPE_USER
  * @param array $user_list 		the list of user that must be assigned to the assesment.If a user is not in this list, but is actually
  * 								assigned to the ass. the function will remove the user
  */
 function updateAssessmentUser($id_assessment, $user_type, $user_list)
 {
     require_once _lms_ . '/lib/lib.course.php';
     require_once _lms_ . '/admin/models/SubscriptionAlms.php';
     $docebo_course = new DoceboCourse($id_assessment);
     $acl_man = Docebo::user()->getAclManager();
     $subsciption_model = new SubscriptionAlms($id_assessment, 0, 0);
     $level_idst = $docebo_course->getCourseLevel($id_assessment);
     if (count($level_idst) == 0 || $level_idst[1] == '') {
         $level_idst = $docebo_course->createCourseLevel($id_assessment);
     }
     $level = 3;
     if ($user_type !== 'user') {
         $level = 6;
     }
     $op_result = true;
     $query = "\r\n\t\tSELECT " . implode($this->user_field, ',') . "\r\n\t\tFROM " . $this->tableUserAssessment() . "\r\n\t\tWHERE " . $this->user_field[USER_ASSES_ID] . " = '" . $id_assessment . "'\r\n\t\t\tAND " . $this->user_field[USER_ASSES_TYPE] . " = '" . $user_type . "'";
     $re_query = $this->_query($query);
     while ($row = $this->fetch_row($re_query)) {
         if (isset($user_list[$row[USER_ASSES_ID_USER]])) {
             unset($user_list[$row[USER_ASSES_ID_USER]]);
         } else {
             $del_query = "\r\n\t\t\t\tDELETE FROM " . $this->tableUserAssessment() . "\r\n\t\t\t\tWHERE " . $this->user_field[USER_ASSES_ID] . " = '{$id_assessment}'\r\n\t\t\t\t\t AND " . $this->user_field[USER_ASSES_ID_USER] . " = '" . $row[USER_ASSES_ID_USER] . "'";
             $op_result &= $this->_query($del_query);
             $acl_man->removeFromGroup($level_idst[$level], $row[USER_ASSES_ID_USER]);
             $subsciption_model->delUser($row[USER_ASSES_ID_USER]);
         }
     }
     // end while
     reset($user_list);
     while (list(, $id_user) = each($user_list)) {
         $upd_query = "\r\n\t\t\tINSERT INTO " . $this->tableUserAssessment() . "\r\n\t\t\t( \t" . $this->user_field[USER_ASSES_ID] . ",\r\n\t\t\t\t" . $this->user_field[USER_ASSES_ID_USER] . ",\r\n\t\t\t\t" . $this->user_field[USER_ASSES_TYPE] . " ) VALUES\r\n\t\t\t( \t'" . $id_assessment . "',\r\n\t\t\t\t'" . $id_user . "',\r\n\t\t\t\t'" . $user_type . "' )";
         $op_result &= $this->_query($upd_query);
         $acl_man->addToGroup($level_idst[$level], $id_user);
         $subsciption_model->subscribeUser($id_user, $level, false);
     }
     return $op_result;
 }
 public function subscribeToCourse()
 {
     $id_course = Get::req('id_course', DOTY_INT, 0);
     $id_date = Get::req('id_date', DOTY_INT, 0);
     $id_edition = Get::req('id_edition', DOTY_INT, 0);
     $id_user = Docebo::user()->getIdSt();
     $docebo_course = new DoceboCourse($id_course);
     require_once _lms_ . '/admin/models/SubscriptionAlms.php';
     $model = new SubscriptionAlms($id_course, $id_edition, $id_date);
     $course_info = $model->getCourseInfoForSubscription();
     $userinfo = $this->acl_man->getUser($id_user);
     $level_idst =& $docebo_course->getCourseLevel($id_course);
     if (count($level_idst) == 0 || $level_idst[1] == '') {
         $level_idst =& $docebo_course->createCourseLevel($id_course);
     }
     $waiting = 0;
     if ($course_info['subscribe_method'] != 2) {
         $waiting = 1;
     }
     $userlevel_subscrip = $this->get_userlevel_subscription($id_user);
     //UG
     //UG		$this->acl_man->addToGroup($level_idst[3], $id_user);
     $this->acl_man->addToGroup($level_idst[$userlevel_subscrip], $id_user);
     //UG
     //UG		if($model->subscribeUser($id_user, 3, $waiting))
     if ($model->subscribeUser($id_user, $userlevel_subscrip, $waiting)) {
         $res['success'] = true;
         $res['new_status_code'] = '';
         if ($id_edition != 0 || $id_date != 0) {
             $must_change_status = $this->model->controlSubscriptionRemaining($id_course);
             $res['new_status'] = '';
             if (!$must_change_status) {
                 $res['new_status'] = '<p class="cannot_subscribe">' . Lang::t('_NO_EDITIONS', 'catalogue') . '</p>';
             }
         } else {
             if ($waiting == 1) {
                 $res['new_status'] = '<p class="cannot_subscribe">' . Lang::t('_WAITING', 'catalogue') . '</p>';
                 $res['new_status_code'] = 'waiting';
             } else {
                 $res['new_status'] = '<p class="subscribed">' . Lang::t('_USER_STATUS_ENTER', 'catalogue') . '</p>';
                 $res['new_status_code'] = 'subscribed';
             }
         }
         $array_subst = array('[url]' => Get::sett('url'), '[course]' => $course_info['name'], '[firstname]' => $userinfo[ACL_INFO_FIRSTNAME], '[lastname]' => $userinfo[ACL_INFO_LASTNAME]);
         // message to user that is waiting
         require_once _base_ . '/lib/lib.eventmanager.php';
         $msg_composer = new EventMessageComposer('subscribe', 'lms');
         $msg_composer->setSubjectLangText('email', '_NEW_USER_SUBS_WAITING_SUBJECT', false);
         $msg_composer->setBodyLangText('email', '_NEW_USER_SUBS_WAITING_TEXT', $array_subst);
         $msg_composer->setSubjectLangText('sms', '_NEW_USER_SUBS_WAITING_SUBJECT_SMS', false);
         $msg_composer->setBodyLangText('sms', '_NEW_USER_SUBS_WAITING_TEXT_SMS', $array_subst);
         $acl =& Docebo::user()->getAcl();
         $acl_man =& $this->acl_man;
         $recipients = array();
         $idst_group_god_admin = $acl->getGroupST(ADMIN_GROUP_GODADMIN);
         $recipients = $acl_man->getGroupMembers($idst_group_god_admin);
         $idst_group_admin = $acl->getGroupST(ADMIN_GROUP_ADMIN);
         $idst_admin = $acl_man->getGroupMembers($idst_group_admin);
         require_once _adm_ . '/lib/lib.adminmanager.php';
         foreach ($idst_admin as $id_user) {
             $adminManager = new AdminManager();
             $acl_manager =& $acl_man;
             $idst_associated = $adminManager->getAdminTree($id_user);
             $array_user =& $acl_manager->getAllUsersFromIdst($idst_associated);
             $array_user = array_unique($array_user);
             $array_user[] = $array_user[0];
             unset($array_user[0]);
             $control_user = array_search(getLogUserId(), $array_user);
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'course'" . " AND id_entry = '" . $id_course . "'";
             list($control_course) = mysql_fetch_row(mysql_query($query));
             /*if($control)
             		$recipients[] = $id_user;*/
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'coursepath'" . " AND id_entry IN" . " (" . " SELECT id_path" . " FROM " . Get::cfg('prefix_lms') . "_coursepath_courses" . " WHERE id_item = '" . $id_course . "'" . " )";
             list($control_coursepath) = mysql_fetch_row(mysql_query($query));
             /*if($control)
             		$recipients[] = $id_user;*/
             $query = "SELECT COUNT(*)" . " FROM " . Get::cfg('prefix_fw') . "_admin_course" . " WHERE idst_user = '******'" . " AND type_of_entry = 'catalogue'" . " AND id_entry IN" . " (" . " SELECT idCatalogue" . " FROM " . Get::cfg('prefix_lms') . "_catalogue_entry" . " WHERE idEntry = '" . $id_course . "'" . " )";
             list($control_catalogue) = mysql_fetch_row(mysql_query($query));
             if ($control_user && ($control_course || $control_coursepath || $control_catalogue)) {
                 $recipients[] = $id_user;
             }
         }
         $recipients = array_unique($recipients);
         createNewAlert('UserCourseInsertModerate', 'subscribe', 'insert', '1', 'User subscribed with moderation', $recipients, $msg_composer);
         $res['message'] = UIFeedback::info(Lang::t('_SUBSCRIPTION_CORRECT', 'catalogue'), true);
     } else {
         $this->acl_man->removeFromGroup($level_idst[3], $id_user);
         $res['success'] = false;
         $res['message'] = UIFeedback::error(Lang::t('_SUBSCRIPTION_ERROR', 'catalogue'), true);
     }
     echo $this->json->encode($res);
 }
 public function fast_subscribe_dialog_action()
 {
     require_once _lms_ . '/lib/lib.course.php';
     $man_course = new Man_Course();
     $acl_man = Docebo::user()->getAclManager();
     $id_user = Get::req('id_user', DOTY_INT, 0);
     $id_course = Get::Req('id_course', DOTY_INT, 0);
     $level = Get::Req('level', DOTY_INT, 3);
     //default: student level
     $userid = Get::req('userid', DOTY_STRING, "");
     $course = Get::req('course', DOTY_STRING, "");
     if ($course != "") {
         $course = trim(preg_replace('|^\\[([^\\]]*)\\][\\s]*|i', '', $course));
     }
     //eliminates che code from the course name
     $id_user = $acl_man->getUserST($userid);
     $id_course = $man_course->getCourseIdByName($course);
     //check if input is correct
     if ($id_user <= 0 || $id_course <= 0) {
         $output['success'] = false;
         $output['message'] = UiFeedback::perror(Lang::t('_INVALID_DATA', 'standard'));
         //'Invalid input. COURSE: '.$id_course.'; USER: '******'edition', DOTY_INT, 0);
     $classroom = Get::Req('classroom', DOTY_INT, 0);
     $cinfo = $man_course->getCourseInfo($id_course);
     if ($cinfo['course_edition'] > 0) {
         $classroom = 0;
     } else {
         $edition = 0;
     }
     if ($cinfo['course_type'] == 'classroom') {
         $edition = 0;
     }
     if ($cinfo['course_type'] == 'classroom' && $classroom <= 0) {
         $output['success'] = false;
         $output['message'] = UIFeedback::pnotice(Lang::t('_CLASSROOM', 'standard') . ': ' . Lang::t('_EMPTY_SELECTION', 'standard'));
         echo $this->json->encode($output);
         return;
     }
     $_model = new SubscriptionAlms($id_course, $edition > 0 ? $edition : false, $classroom > 0 ? $classroom : false);
     //check if user is already subscribed
     if ($_model->isUserSubscribed($id_user)) {
         $output['success'] = false;
         $output['message'] = UIFeedback::pnotice(Lang::t('_USER_ALREADY_SUBSCRIBED', 'course') . ': ' . $userid);
         echo $this->json->encode($output);
         return;
     }
     //subscribe user
     $res = $_model->subscribeUser($id_user, $level, false);
     if ($res) {
         $docebo_course = new DoceboCourse($id_course);
         $level_idst =& $docebo_course->getCourseLevel($id_course);
         if (count($level_idst) == 0 || $level_idst[1] == '') {
             $level_idst =& $docebo_course->createCourseLevel($id_course);
         }
         //$this->acl_man->addToGroup($level_idst[$level], $id_user);
         $this->_addToCourseGroup($level_idst[$level], $id_user);
     }
     $output['success'] = $res ? true : false;
     if (!$res) {
         $output['message'] = UIFeedback::perror(Lang::t('_ERROR_WHILE_SAVING', 'standard'));
     } else {
         $output['message'] = UIFeedback::pinfo(Lang::t('_GOTO_COURSE_T', 'course'));
     }
     echo $this->json->encode($output);
 }
 public function makeOrder()
 {
     $wire = Get::req('wire', DOTY_INT, 0);
     $cart = $_SESSION['lms_cart'];
     require_once _lms_ . '/lib/lib.cart.php';
     if (Learning_Cart::cartItemCount() > 0) {
         $id_trans = $this->model->createTransaction();
     } else {
         $id_trans = false;
     }
     if ($id_trans === false) {
         $result = array('success' => false, 'message' => UIFeedback::error(Lang::t('_ERROR_CREATE_TRANS', 'catalogue'), true));
     } else {
         $course_info = $this->model->getCartList(true);
         $total_price = 0;
         foreach ($cart as $id_course => $extra) {
             $docebo_course = new DoceboCourse($id_course);
             require_once _lms_ . '/admin/models/SubscriptionAlms.php';
             $level_idst =& $docebo_course->getCourseLevel($id_course);
             if (count($level_idst) == 0 || $level_idst[1] == '') {
                 $level_idst =& $docebo_course->createCourseLevel($id_course);
             }
             $waiting = 1;
             $this->acl_man->addToGroup($level_idst[3], Docebo::user()->getIdSt());
             if (isset($extra['classroom'])) {
                 foreach ($extra['classroom'] as $id_date) {
                     $model = new SubscriptionAlms($id_course, 0, $id_date);
                     if (!$model->subscribeUser(Docebo::user()->getIdSt(), 3, $waiting)) {
                         $this->acl_man->removeFromGroup($level_idst[3], Docebo::user()->getIdSt());
                     } elseif ($this->model->addTransactionCourse($id_trans, $id_course, $id_date, 0, $course_info[$id_course . '_' . $id_date . '_0'])) {
                         unset($_SESSION['lms_cart'][$id_course]['classroom'][$id_date]);
                         $query = "UPDATE %lms_courseuser" . " SET status = '-2'" . " WHERE idUser = "******" AND idCourse = " . $id_course;
                         sql_query($query);
                         $total_price += $course_info[$id_course . '_' . $id_date . '_0']['price'];
                     }
                 }
             } elseif (isset($extra['edition'])) {
                 foreach ($extra['edition'] as $id_edition) {
                     $model = new SubscriptionAlms($id_course, $id_edition, 0);
                     if (!$model->subscribeUser(Docebo::user()->getIdSt(), 3, $waiting)) {
                         $this->acl_man->removeFromGroup($level_idst[3], Docebo::user()->getIdSt());
                     } elseif ($this->model->addTransactionCourse($id_trans, $id_course, 0, $id_edition, $course_info[$id_course . '_0_' . $id_edition])) {
                         unset($_SESSION['lms_cart'][$id_course]['edition'][$id_edition]);
                         $query = "UPDATE %lms_courseuser" . " SET status = '-2'" . " WHERE idUser = "******" AND idCourse = " . $id_course;
                         sql_query($query);
                         $total_price += $course_info[$id_course . '_0_' . $id_edition]['price'];
                     }
                 }
             } else {
                 $model = new SubscriptionAlms($id_course, 0, 0);
                 if (!$model->subscribeUser(Docebo::user()->getIdSt(), 3, $waiting)) {
                     $this->acl_man->removeFromGroup($level_idst[3], Docebo::user()->getIdSt());
                 } elseif ($this->model->addTransactionCourse($id_trans, $id_course, 0, 0, $course_info[$id_course . '_0_0'])) {
                     unset($_SESSION['lms_cart'][$id_course]);
                     $query = "UPDATE %lms_courseuser" . " SET status = '-2'" . " WHERE idUser = "******" AND idCourse = " . $id_course;
                     sql_query($query);
                     $total_price += $course_info[$id_course . '_0_0']['price'];
                 }
             }
         }
         require_once _lms_ . '/lib/lib.cart.php';
         if (Learning_Cart::cartItemCount() == 0) {
             $_SESSION['lms_cart'] = array();
         }
         $_SESSION['cart_transaction'] = $id_trans;
         $result = array('success' => true, 'message' => UIFeedback::info(Lang::t('_TRANS_CREATED', 'catalogue'), true), 'id_transaction' => $id_trans, 'total_price' => $total_price, 'link' => Get::sett('url') . _folder_lms_ . '/index.php?r=cart/show&id_transaction=' . $id_trans . '&cart=' . $_SESSION['cart_id']);
     }
     if ($wire) {
         if ($result['success']) {
             Util::jump_to('index.php?r=cart/wireInfo&id_transaction=' . $id_trans);
         }
         Util::jump_to('index.php?r=cart/show&error=1');
     } else {
         echo $this->json->encode($result);
     }
 }