2014-01-28 13:07:36 +02:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Letter controller.
|
|
|
|
**/
|
|
|
|
class Controller_Letter extends Controller_Layout {
|
|
|
|
protected $secure_actions = array(
|
2014-01-29 10:52:33 +02:00
|
|
|
'index','create', 'edit', 'delete'
|
2014-01-28 13:07:36 +02:00
|
|
|
);
|
2014-01-29 10:52:33 +02:00
|
|
|
protected $controls = array(
|
2014-01-29 12:41:25 +02:00
|
|
|
'subject' => 'input',
|
2014-01-29 10:52:33 +02:00
|
|
|
'text' => 'textarea',
|
|
|
|
'order' => 'input',
|
|
|
|
);
|
|
|
|
public function action_create()
|
|
|
|
{
|
|
|
|
$this->template = new View_Edit;
|
|
|
|
$id = $this->request->param('id');
|
2014-02-05 10:10:05 +02:00
|
|
|
if (!Model_Course::exists($id))
|
2014-01-29 10:52:33 +02:00
|
|
|
{
|
|
|
|
$this->redirect('error/500');
|
|
|
|
}
|
|
|
|
$this->template->model = ORM::factory('Letter');
|
2014-02-05 10:10:05 +02:00
|
|
|
$this->template->model->course_id = $id;
|
2014-01-29 10:52:33 +02:00
|
|
|
$this->template->title = __('New letter');
|
|
|
|
$this->_edit($this->template->model);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_edit()
|
|
|
|
{
|
|
|
|
$this->template = new View_Edit;
|
|
|
|
$this->template->title = __('Letter editing');
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
$model = ORM::factory('Letter', $id);
|
|
|
|
if (!$model->loaded())
|
|
|
|
{
|
|
|
|
$this->redirect('error/404');
|
|
|
|
}
|
|
|
|
$this->_edit($model);
|
|
|
|
}
|
2014-02-16 06:13:01 +02:00
|
|
|
|
|
|
|
protected function _edit_redirect($model)
|
|
|
|
{
|
|
|
|
return Route::url('default', array('controller' => 'Course','action' => 'view','id' => $model->course_id));
|
|
|
|
}
|
2014-01-29 10:52:33 +02:00
|
|
|
|
|
|
|
public function action_delete()
|
|
|
|
{
|
|
|
|
$this->template = new View_Delete;
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
$model = ORM::factory('Letter', $id);
|
|
|
|
if (!$model->loaded())
|
|
|
|
{
|
|
|
|
$this->redirect('error/404');
|
|
|
|
}
|
|
|
|
$this->template->title = __('Delete letter');
|
|
|
|
$this->template->content_title = $model->title;
|
|
|
|
$this->template->content = $model->description;
|
|
|
|
|
|
|
|
$confirmation = $this->request->post('confirmation');
|
|
|
|
if ($confirmation === 'yes') {
|
2014-02-19 12:09:06 +02:00
|
|
|
$model->delete();
|
2014-01-29 10:52:33 +02:00
|
|
|
$this->redirect('/');
|
|
|
|
}
|
|
|
|
}
|
2014-02-21 08:53:42 +02:00
|
|
|
|
|
|
|
public function action_view()
|
|
|
|
{
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
$model = ORM::factory('Letter', $id);
|
|
|
|
if (!$model->loaded())
|
|
|
|
{
|
|
|
|
$this->redirect('error/404');
|
|
|
|
}
|
|
|
|
$this->template = new View_Letter_View;
|
|
|
|
$this->template->content = $model->text;
|
|
|
|
}
|
2014-01-28 13:07:36 +02:00
|
|
|
}
|