<?php
//ini_set("display_errors","1");

include_once("_dirinfo.php");
include_once (PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."config.php");


$table = "_plugin_intervalselect";

$sql = "SELECT * FROM " . DB_WARPIT_WEBCATI_BASE . "._Plugin  WHERE plugin_path = 'slider'";
$res = $db->SQLexecute($sql);
$dat = $db->fetchAssoc($res);

$idPlugin = $dat['id_plugin'];



if($_POST['action'] == "update")
{
    $data = json_decode(stripslashes($_POST['data']), TRUE);
    //var_dump($data);
    
    $strData = array();
    foreach($data as $dat)
    {
        $strData[] = $dat['value'] . " " . $dat['label']; 
    }
    
    $tmpSql[] =  "available_fields_list = '" . implode('/', $strData) . "'";
    $tmpSql[] = "id_project = '" . $_POST['projectId'] . "'";
    $tmpSql[] = "id_question = '" . $_POST['questionId']. "'"; 
    
    $sql = "INSERT INTO " . DB_WARPIT_WEBCATI_BASE . ".". $table ." 
            SET " . implode(",", $tmpSql) ." ON DUPLICATE KEY UPDATE " . implode(",", $tmpSql) . ", deleted = 0";
    
//    print $sql;
    $db->SQLexecute($sql);
    
    $result['success'] = TRUE;
    //print json_encode($result);
    exit;
}
?>