/** * Delete a course * This method initially displays a form for confirming deletion * then deletes course and associated information upon POST * * @return void */ public function deleteTask() { // Build title $this->_buildTitle(); // Build pathway $this->_buildPathway(); // Check if they're logged in if (User::isGuest()) { $this->loginTask(Lang::txt('COM_COURSES_NOT_LOGGEDIN')); return; } // Ensure we found the course info if (!$this->course->exists()) { return App::abort(404, Lang::txt('COM_COURSES_NO_COURSE_FOUND')); } // Check authorization if (!$this->course->access('delete')) { return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH')); } // Get number of course members $managers = $this->course->get('managers'); // Incoming $process = Request::getVar('process', ''); $confirmdel = Request::getVar('confirmdel', ''); $msg = trim(Request::getVar('msg', '', 'post')); // Did they confirm delete? if (!$process || !$confirmdel) { if ($process && !$confirmdel) { Notify::error(Lang::txt('COM_COURSES_ERROR_CONFIRM_DELETION'), 'courses'); } $log = Lang::txt('COM_COURSES_MEMBERS_LOG', count($managers)); // Trigger the functions that delete associated content // Should return logs of what was deleted $logs = Event::trigger('courses.onCourseDeleteCount', array($course)); if (count($logs) > 0) { $log .= '<br />' . implode('<br />', $logs); } // Output HTML $this->view->title = Lang::txt('COM_COURSES_DELETE_COURSE') . ': ' . $this->course->get('title'); $this->view->course = $course; $this->view->log = $log; $this->view->msg = $msg; $this->view->notifications = Notify::messages('courses'); $this->view->display(); return; } $this->course->set('state', 2); // Delete course if (!$this->course->update()) { $this->view->setLayout('error'); $this->view->title = $title; if ($this->course->getError()) { Notify::error($this->course->getError(), 'courses'); } $this->view->notifications = Notify::messages('courses'); $this->view->display(); return; } // Get and set some vars $date = Date::of('now'); // Build the "from" info for e-mails $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name)), 'email' => Config::get('mailfrom')); // E-mail subject $subject = Lang::txt('COM_COURSES_SUBJECT_COURSE_DELETED', $gcn); // Build the e-mail message $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'deleted')); $eview->option = $this->_option; $eview->sitename = Config::get('sitename'); $eview->user = User::getInstance(); $eview->gcn = $gcn; $eview->msg = $msg; $eview->course = $deletedcourse; $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); // Send the message if (!Event::trigger('xmessage.onSendMessage', array('courses_deleted', $subject, $message, $from, $members, $this->_option))) { Notify::error(Lang::txt('COM_COURSES_ERROR_EMAIL_MEMBERS_FAILED')); } // Log the deletion $xlog = new Tables\Log($this->database); $xlog->gid = $this->course->get('id'); $xlog->uid = User::get('id'); $xlog->timestamp = Date::toSql(); $xlog->action = 'course_deleted'; $xlog->comments = $log; $xlog->actorid = User::get('id'); if (!$xlog->store()) { Notify::error($xlog->getError()); } // Redirect back to the courses page App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_COURSES_COURSE_DELETED', $this->course->get('title')), 'passed'); }
/** * Log an action * * @param integer $scope_id Scope ID * @param string $scope Scope * @param string $action Action performed * @param string $log Data * @return void */ public function log($scope_id, $scope, $action, $log = null) { $log = new Tables\Log($this->_db); $log->scope_id = $scope_id; $log->scope = $scope; $log->user_id = User::get('id'); $log->timestamp = Date::toSql(); $log->action = $action; $log->comments = $log; $log->actor_id = User::get('id'); if (!$log->store()) { $this->setError($log->getError()); } }
/** * Removes a course and all associated information * * @return void */ public function deleteTask() { // Check for request forgeries Request::checkToken(); // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $num = 0; // Do we have any IDs? if (!empty($ids)) { foreach ($ids as $id) { // Load the course page $model = \Components\Courses\Models\Unit::getInstance($id); // Ensure we found the course info if (!$model->exists()) { continue; } // Delete course if (!$model->delete()) { throw new Exception(Lang::txt('COM_COURSES_ERROR_UNABLE_TO_REMOVE_ENTRY'), 500); } // Log the course approval $log = new Tables\Log($this->database); $log->scope_id = $id; $log->scope = 'course_unit'; $log->user_id = User::get('id'); $log->timestamp = Date::toSql(); $log->action = 'unit_deleted'; $log->actor_id = User::get('id'); if (!$log->store()) { $this->setError($log->getError()); } $num++; } } // Redirect back to the courses page App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&offering=' . Request::getInt('offering', 0), false), Lang::txt('COM_COURSES_ITEMS_REMOVED', $num)); }