Ejemplo n.º 1
0
 public function search()
 {
     $parm = json_decode(rawurldecode($this->input->post('parm')), true);
     foreach ($parm as $key => $value) {
         $parm[$key] = html_escape_string($parm[$key]);
     }
     $this->session->set_userdata('searchinfo', $parm);
     return true;
 }
Ejemplo n.º 2
0
function write_html($in, $out_file, $options = array())
{
    if (!isset($options["contents_only"])) {
        $options["contents_only"] = false;
    }
    if (!isset($options["title"])) {
        $options["title"] = "worksheet converter";
    }
    $contents_only = $options["contents_only"];
    $force = $options["force"];
    if (file_exists($out_file) && !$force) {
        fputs(STDERR, "Error: already [{$out_file}] exists. use -f option to overwrite it.\n");
        return;
    }
    if (($out = fopen($out_file, "w")) === false) {
        fputs(STDERR, "Error: failed to open an output file.\n");
        return;
    }
    if (!$contents_only) {
        $ans = "";
        $ans .= "<!DOCTYPE html>\n";
        $ans .= "<html lang=\"ja\">\n";
        $ans .= "<head>\n";
        $ans .= "<meta charset=\"utf-8\">\n";
        $ans .= "<title>{$title}</title>\n";
        $ans .= "<script type=\"text/javascript\" src=\"jquery-1.11.2.min.js\"></script>\n";
        $ans .= "<script type=\"text/javascript\" src=\"bootstrap.min.js\"></script>\n";
        $ans .= "<link href=\"bootstrap.min.css\" rel=\"stylesheet\">\n";
        $ans .= "</head>\n";
        $ans .= "<body>\n";
        $ans .= "<div class=\"container\">\n";
        $ans .= "<div class=\"table-responsive\">\n";
        fputs($out, $ans);
    }
    while (($line = fgets($in)) !== false) {
        // # ファイル名はワークシートの先頭行を示す。
        if (substr($line, 0, 1) != "#") {
            continue;
        }
        $worksheet_name = trim(substr($line, 1));
        $headers = explode(":", "^:" . $options["outheader"] . ":\$");
        // ワークシートを出力する。
        $row = 0;
        while (($record = fgetcsv($in, 65536, ",", '"')) !== FALSE) {
            // 空行はワークシートの最終行を示す。
            if ($record == array('')) {
                break;
            }
            $tag = array_shift($record);
            switch ($tag) {
                case "fields":
                    $fields = $record;
                    break;
                case "types":
                    $types = $record;
                    break;
                case "params":
                    $params = $record;
                    break;
                case "titles":
                    $titles = $record;
                    break;
                case "record":
                    while (($header = array_shift($headers)) !== null) {
                        // ヘッダ情報を出力する。
                        if ($header == "^") {
                            $ans = "";
                            $ans .= "<table id=\"{$worksheet_name}\" ";
                            $ans .= "class=\"table table-striped table-bordered table-hover table-condensed\">\n";
                            $ans .= "<thead>\n";
                            fputs($out, $ans);
                        } else {
                            if ($header == "F") {
                                $ans = "";
                                $ans .= "<tr>\n";
                                for ($col = 0; $col < count($fields); $col++) {
                                    $value = html_escape_string($fields[$col]);
                                    $ans .= "\t<td>{$value}</td>\n";
                                }
                                $ans .= "</tr>\n";
                                fputs($out, $ans);
                            } else {
                                if ($header == "C") {
                                    $ans = "";
                                    $ans .= "<tr>\n";
                                    for ($col = 0; $col < count($types); $col++) {
                                        $value = html_escape_string($types[$col]);
                                        $ans .= "\t<td>{$value}</td>\n";
                                    }
                                    $ans .= "</tr>\n";
                                    fputs($out, $ans);
                                } else {
                                    if ($header == "P") {
                                        $ans = "";
                                        $ans .= "<tr>\n";
                                        for ($col = 0; $col < count($params); $col++) {
                                            $value = html_escape_string($params[$col]);
                                            $ans .= "\t<td>{$value}</td>\n";
                                        }
                                        $ans .= "</tr>\n";
                                        fputs($out, $ans);
                                    } else {
                                        if ($header == "T") {
                                            $ans = "";
                                            $ans .= "<tr>\n";
                                            for ($col = 0; $col < count($titles); $col++) {
                                                $value = html_escape_string($titles[$col]);
                                                $ans .= "\t<td>{$value}</td>\n";
                                            }
                                            $ans .= "</tr>\n";
                                            fputs($out, $ans);
                                        } else {
                                            if ($header == "N") {
                                                $ans = "";
                                                $ans .= "<tr>\n";
                                                for ($col = 0; $col < count($params); $col++) {
                                                    $value = html_escape_string($params[$col]);
                                                    $ans .= "\t<td>&nbsp;</td>\n";
                                                }
                                                $ans .= "</tr>\n";
                                                fputs($out, $ans);
                                            } else {
                                                if ($header == "\$") {
                                                    $ans = "";
                                                    $ans .= "</thead>\n";
                                                    $ans .= "<tbody>\n";
                                                    fputs($out, $ans);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    $ans = "";
                    $ans .= "<tr>\n";
                    for ($col = 0; $col < count($record); $col++) {
                        $value = html_escape_string($record[$col]);
                        $field = $fields[$col];
                        $ans .= "\t<td>{$value}</td>\n";
                    }
                    $ans .= "</tr>\n";
                    fputs($out, $ans);
                    break;
                default:
                    $contents = implode(",", $record);
                    fputs(STDERR, "Warning: unkown tag[{$tag}]. {$contents}\n");
                    return;
            }
            $row += 1;
        }
        $ans = "";
        $ans .= "</tbody>\n";
        $ans .= "</table>\n";
        fputs($out, $ans);
    }
    if (!$contents_only) {
        $ans = "";
        $ans .= "</div>\n";
        $ans .= "</div>\n";
        $ans .= "</body>\n";
        $ans .= "</html>\n";
        fputs($out, $ans);
    }
    fclose($out);
    return;
}
Ejemplo n.º 3
0
function write_html($in, $out_file, $options = array())
{
    if (!isset($options["title"])) {
        $options["title"] = "worksheet converter";
    }
    if (!isset($options["offset"])) {
        $options["offset"] = "0";
    }
    $title = $options["title"];
    $offset = $options["offset"] + 0;
    $force = $options["force"];
    // データベーススキーマを収集する。
    $arguments = array();
    while (($line = fgets($in)) !== false) {
        // "# ワークシート名"はワークシートの先頭行を示す。
        if (substr($line, 0, 1) != "#") {
            continue;
        }
        $table = trim(substr($line, 1));
        $records = array();
        $row = 0;
        while (($record = fgetcsv($in, 65536, ",", '"')) !== FALSE) {
            // 空行はワークシートの最終行を示す。
            if ($record == array('')) {
                break;
            }
            $tag = array_shift($record);
            $record = array_slice($record, $offset);
            $num_cols = count($record);
            for ($i = 0; $i < $num_cols; $i++) {
                $record[$i] = html_escape_string($record[$i]);
            }
            switch ($tag) {
                case "fields":
                    $fields = $record;
                    break;
                case "types":
                    $types = $record;
                    break;
                case "params":
                    $params = $record;
                    break;
                case "titles":
                    $titles = $record;
                    break;
                case "record":
                    $records[] = $record;
                    break;
                default:
                    $contents = implode(",", $record);
                    fputs(STDERR, "Error[{$tag}]: Unkown tag. {$contents}\n");
                    return;
            }
            $row += 1;
        }
        $arguments[$table] = ["fields" => $fields, "types" => $types, "params" => $params, "titles" => $titles, "records" => $records, "num_cols" => $num_cols];
    }
    // テンプレートのあるディレクトリと出力ディレクトリを決める。
    $template_dirs = array();
    $template_dirs[] = "./html_templates/";
    $template_dirs[] = dirname(__FILE__) . "/html_templates/";
    $instance_dirs = array();
    $instance_dirs[] = "./htmls/";
    $template_dir = "";
    foreach ($template_dirs as $dir) {
        if (file_exists($dir)) {
            $template_dir = $dir;
            break;
        }
    }
    if ($template_dir == "") {
        fputs(STDERR, "Error: Template directory does not exist.\n");
        return;
    }
    $instance_dir = "";
    foreach ($instance_dirs as $dir) {
        if (file_exists($dir)) {
            $instance_dir = $dir;
            break;
        }
    }
    if ($instance_dir == "") {
        if (mkdir("./htmls/", 0700)) {
            $instance_dir = "./htmls/";
        } else {
            fputs(STDERR, "Error: Output directory does not exist.\n");
            return;
        }
    }
    // コードを生成する。
    foreach ($arguments as $table => $detail) {
        $in_dir = $template_dir;
        $out_dir = "{$instance_dir}/" . Inflector::camelize($table);
        if (!file_exists($out_dir)) {
            mkdir($out_dir);
        }
        $in_ext = "html";
        $out_ext = "html";
        $templates = preg_grep("/^\\w+\\.{$in_ext}\$/", scandir($template_dir));
        foreach ($templates as $template) {
            $filename = pathinfo($template, PATHINFO_FILENAME);
            $in_file = "{$in_dir}/{$filename}.{$in_ext}";
            $out_file = "{$out_dir}/{$filename}.{$out_ext}";
            $ans = render_html(file_get_contents($in_file), $detail);
            if (file_exists($out_file) && !$force) {
                fputs(STDERR, "Error[{$out_file}]: The file already exists. Use -f option to overwrite it.\n");
                return;
            }
            file_put_contents($out_file, $ans);
        }
    }
    return;
}