<?php

class Timeline extends CodonModule
{

 public function HTMLHead()
    {
        $this->set('sidebar', 'Timeline/sidebar.php');
    }

    public function NavBar()
    {
        echo '<li><a href="'.SITE_URL.'/admin/index.php/Timeline">Timeline Admin</a></li>';
    }

public function index()
{
	if($this->post->action == 'save')
        {
            $this->save();
        }
        elseif($this->post->action == 'saveupdate')
        {
            $this->saveupdate();
        }
        else
        {
            $this->set('events', TimelineData::get_all_events());
            $this->render('Timeline/header.php');
			$this->render('Timeline/index.php');
        }
	 
}

public function create()
{
	$this->render('Timeline/header.php');
	$this->render('Timeline/create.php');
}

public function update($id)
{
	$this->set('events', TimelineData::get_events($id));
	$this->render('Timeline/header.php');
	$this->render('Timeline/update.php');
}

 public function delete_event($id)    {
        TimelineData::delete_event($id);
		
        $this->index();
    }

public function save() {
	if(DB::escape($this->post->name) == '')
            {
                $this->set('error', TRUE);
                $this->set('event', $event);
                $this->show('Timeline/create.php');
                return;
            }
		$name = DB::escape($this->post->name);
		$date = DB::escape($this->post->date);

		$sql = "INSERT INTO icrew_timeline(name, date) VALUES('$name', '$date')";
		DB::query($sql);
		$this->render('Timeline/header.php');
		$this->set('message', 'Event Added');
		$this->render('core_success');
	}
	
public function saveupdate() {
	
		$id = DB::escape($this->post->id);
		$name = DB::escape($this->post->name);
		$date = DB::escape($this->post->date);
		
		TimelineData::update($id,$name,$date);
		
		$this->render('Timeline/header.php');
		$this->set('message', 'Event Updated');
		$this->render('core_success');
	}
}
?>