#!/usr/bin/perl

#use utf8;
use strict;
use CGI;
use Opals::Context;
use Opals::Template qw(
    tmpl_read
    tmpl_write
);

use POSIX qw(
    floor
);


use JSON;

my $dbh = Opals::Context->dbh();
END { $dbh->disconnect(); }

my $cgi      = CGI->new;
my $input    = $cgi->Vars();

my $op= $input->{'op'};
my $id=$input->{'id'};
my $name=$input->{'name'};
my $uidList=$input->{'uidList'};

if($op eq 'del'){
    $dbh->do("delete  from opl_preSelUserList where id=?",undef,$id);
}
elsif($op eq 'save'){
    if($id && $id>0){
        $dbh->do("update opl_preSelUserList set name=?, uidList=? where id=?",undef,$name,$uidList,$id );
    }
    else{
        $dbh->do("insert into opl_preSelUserList set name=?, uidList=?,dateCreated=now() ",undef,$name,$uidList );
        $id=$dbh->{'mysql_insertid'};
    }
}
print "Content-type: text/plain\n\n";
print  to_json({status=>1,listId=>$id});

