<?php

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

/**
 * Description of rtgc_edit_link
 *
 * @author Igor Ratsun
 */
class rtgc_password implements rtgc_callback
{

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

    public function __construct($password_field = NULL)
    {
        if (empty($password_field)) {
            $password_field = 'password';
        }
        
        $this->CI = & get_instance();
        // If edit page
        if ($this->CI->uri->get_next_segment('edit') != 'add') {
            $this->get_rtgrid_api()->callback_before_edit(function($post) use ($password_field) {
                if (empty($post[$password_field])) {
                    unset($post[$password_field]);
                }
                
                return $post;
            });
        }
    }

    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)
    {
        $value = '';
        
        return '<input type="password" name="' . $name . '" value="' . $value . '" />';
    }
    
}
