<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Set input with default value
 *
 * @author Igor Ratsun
 */
class rtgc_input_with_default_value implements rtgc_callback
{

    protected $CI = NULL;
    protected $rtgrid_api = NULL;
    protected $default_value = NULL;

    public function __construct($default_value = NULL)
    {
        $this->CI = & get_instance();
        $this->default_value = $default_value;
    }

    public function set_rtgrid_api(rtgrid_api $rtgrid_api)
    {
        $this->rtgrid_api = $rtgrid_api;
    }

    public function get_rtgrid_api()
    {
        if (is_null($this->rtgrid_api)) {
            $this->rtgrid_api = & $this->CI->rtgrid_api;
        }

        return $this->rtgrid_api;
    }

    public function column($value = '', $data = array())
    {
        return $value;
    }

    public function field($name = '', $value = NULL)
    {
        if ($this->CI->uri->get_next_segment('edit') == 'add') {
            $value = $this->default_value;
        }
     
        return '<input type="text" name="' . $name . '" value="' . $value . '" />';
    }
    
}
