<?php
include_once ("_dirinfo.php");

include_once (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."_ajaxManipulators/_class/class.gridData.php");
include_once (PATH_TO_ROOT."_ajaxManipulators/_class/class.formData.php");

include_once(PATH_TO_ROOT . 'webcati/_class/class.WebPoints.php');

class inactivePanelistsOverviewManipulator extends GridDataManipulator
{
    private $wp;
    
    function __construct($db,$table)
    {
        $this->wp = new WebPoints($db);
        
        parent::__construct($db,$table);
    }
    
    public function selectAction()
    {
        if($_POST['limit'] < 0 ) $_POST['limit'] = 20;
        $limit .= ' LIMIT '.$_POST['start'].", ".$_POST['limit'];
        
        
        $config = configLoader::loadConfig('incentive');
        echo $this->wp->getUsersWithoutPoints($this->filtering($_POST['filter']), $limit, $config['default_state_id']);
       // return parent::selectAction();
    }
    
    public function updateAction()
    {
        if($_POST['field'] == 'points')
        {
            $config = configLoader::loadConfig('incentive');
            echo $this->wp->addPointsToUser(array($_POST['id']), $config['default_state_id'], $_POST['value']);  
        }
        //
       // return parent::updateAction();
    }
    
    public function deleteAction()
    {
        $ids = stripslashes($_POST['ids']);
        echo $this->wp->removePoints($ids);
        
    }
    
    public function selectPurposesAction()
    {
        $wp = new WebPoints($this->db);
        echo $this->wp->getPurposesList();
        exit;
    }
}


$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);
$manipulator = new inactivePanelistsOverviewManipulator($db,$_POST['RMtable']);

$comm = $_POST['action'].'Action';
if(method_exists($manipulator,$comm))
    echo $manipulator->$comm();
else 
{
    
    Echo '{success:false,error:"Unknown action!"}'; 
    
}


?>
