#!/usr/bin/perl
#
##############################

use CGI;

my $q = new CGI;


# param
my $type = $q->param('type');
&error("type not specified") if !defined $type or $type!~/^[a-zA-Z_]+$/;
my $cpid = $q->param('cpid');
$cpid = "" if !defined $cpid or $cpid!~/^[a-zA-Z0-9]+$/;
my $var = $q->param('var');
$var = $type if !defined $var or $var!~/^[a-zA-Z_]+$/;

my $url;
if($type eq 'version' or $type eq 'client') {
    $url = "../schedule.json";
}
else {
    &error("type not specified");
}

#
#  データーファイル取り込み
#
  $body ='';  
  open(FILET, $url) or die;
  @rec_c = <FILET>;
  close(FILET);
  foreach (@rec_c) {
    $body .= $_;
  }
  
#
# javascript化する
#
  $body = 'jsonfeed(' . $body . ');';
  print $q->header(-type => "text/plain", -charset => "utf-8");
  print "\n\n";
  print $body;
  exit;
    
sub error {
  local($err) = @_;
  print $q->header(-type => "text/plain", -charset => "utf-8");
  print "\n\n";
  print 'jsonfeed(null);';
  exit(0);    
}