/** * The action of self-unsubscription from a course (if enabled for the course), * available in the course box of the courses list */ public function self_unsubscribe() { $id_user = Docebo::user()->idst; //Get::req('id_user', DOTY_INT, Docebo::user()->idst); $id_course = Get::req('id_course', DOTY_INT, 0); $id_edition = Get::req('id_edition', DOTY_INT, 0); $id_date = Get::req('id_date', DOTY_INT, 0); $cmodel = new CourseAlms(); $cinfo = $cmodel->getCourseModDetails($id_course); //index.php?r=elearning/show $back = Get::req('back', DOTY_STRING, ""); if ($back != "") { $parts = explode('/', $back); $length = count($parts); if ($length > 0) { $parts[$length - 1] = 'show'; $back = implode('/', $parts); } } $jump_url = 'index.php?r=' . ($back ? $back : 'lms/elearning/show'); if ($cinfo['auto_unsubscribe'] == 0) { //no self unsubscribe possible for this course Util::jump_to($jump_url . '&res=err_unsub'); } $date_ok = TRUE; if ($cinfo['unsubscribe_date_limit'] != "" && $cinfo['unsubscribe_date_limit'] != "0000-00-00 00:00:00") { if ($cinfo['unsubscribe_date_limit'] < date("Y-m-d H:i:s")) { //self unsubscribing is no more allowed, go back to courselist page Util::jump_to($jump_url . '&res=err_unsub'); } } $smodel = new SubscriptionAlms(); $param = ''; if ($cinfo['auto_unsubscribe'] == 1) { //moderated self unsubscribe $res = $smodel->setUnsubscribeRequest($id_user, $id_course, $id_edition, $id_date); $param .= $res ? '&res=ok_unsub' : '&res=err_unsub'; } if ($cinfo['auto_unsubscribe'] == 2) { //directly unsubscribe user $res = $smodel->unsubscribeUser($id_user, $id_course, $id_edition, $id_date); $param .= $res ? '&res=ok_unsub' : '&res=err_unsub'; } Util::jump_to($jump_url); }