public function createFromJson($json)
 {
     // 1. Parse JSON
     $decoded = json_decode($json);
     if ($decoded !== null) {
         if ($this->validateJson($decoded)) {
             $this->packagenumber = $decoded->package->number;
             $tags = $this->getPreparedTags($decoded->tags_format, $decoded->tags);
             // Populate Config overwrite defaults
             Config::$glsbox_label_beginx = intval($decoded->pdf->beginx);
             // zero is the default anyway
             Config::$glsbox_label_beginy = intval($decoded->pdf->beginy);
             $format = resempty($decoded, array('pdf', 'format'), 'A4', Primitive::STR);
             if (in_array($format, array('A4', 'A5'))) {
                 Config::$glsbox_label_papersize = $format;
             }
             Config::$filename_prefix = resempty($decoded, array('pdf', 'prefix'), "", Primitive::STR);
             $mode = resempty($decoded, 'mode', 'business', Primitive::STR);
             if (in_array($mode, array('business', 'express'))) {
                 Config::$mode = $mode;
             }
             $glsService = null;
             if (Config::$mode == "express") {
                 $glsService = new Gls_Unibox_Model_Label_Gls_Express();
             } else {
                 $glsService = new Gls_Unibox_Model_Label_Gls_Business();
             }
             $glsService->importValues($tags);
             $ready_tags = $glsService->getData();
             $gls_unibox_label_pdf = new Gls_Unibox_Model_Pdf_Label();
             $pdf = $gls_unibox_label_pdf->createLabel($ready_tags);
             $this->content = $pdf->render();
             return true;
         } else {
             array_push($this->errors, new GCError("Error: Validation of input parameters did not succeed."));
         }
     } else {
         array_push($this->errors, new GCError("Error: Decoding of the JSON-Input failed - invalid JSON."));
     }
     return false;
 }
Exemplo n.º 2
0
                echo $tp;
            } else {
                if (strlen($tp = $imp["productName es_ES"]) > 1) {
                    echo $tp;
                } else {
                    if (strlen($tp = $imp["productName fr_FR"]) > 1) {
                        echo $tp;
                    }
                }
            }
        }
    }
    ?>
</td>
                    <td><?php 
    echo resempty($imp, "bestandsfuehrer");
    ?>
</td>
                    <td data-nfieldb="<?php 
    echo $imp["id"];
    ?>
"><?php 
    if (strlen($tp = $imp["productBrand de_AT"]) > 1) {
        echo $tp;
    } else {
        if (strlen($tp = $imp["productBrand de_DE"]) > 1) {
            echo $tp;
        } else {
            if (strlen($tp = $imp["productBrand en_US"]) > 1) {
                echo $tp;
            } else {
</textarea>
                </p>
                <p>
                    <input type="checkbox" name="create_json_only" value="1" <?php 
echo resempty($_POST, 'create_json_only') == "1" ? 'checked' : '';
?>
 /> Create JSON (PDF otherwise)
                </p>

               <p><input type="submit" value="Create" /></p>
            </form>
        </div>

        <div id="create_from_json" class="mpt">
            <?php 
$json = resempty($_POST, 'data');
if ($json == "") {
    global $output_json;
    if ($output_json != "") {
        $json = json_encode($output_json, JSON_PRETTY_PRINT);
    }
}
?>
            <h1>Create from JSON</h1>
            <form method="post" action="/create/" enctype="multipart/form-data">
                <textarea name="data" id="data"><?php 
echo $json;
?>
</textarea>
                <p><input type="submit" value="Create" /></p>
            </form>