/**
  * Applique les champs variables sur une source html
  *
  * @param string $_source source html
  *
  * @return void
  */
 function renderDocument($_source)
 {
     $fields = array();
     $values = array();
     $fields_regex = array();
     $values_regex = array();
     foreach ($this->sections as $properties) {
         foreach ($properties as $key => $property) {
             if (strpos($key, ' - ') === false) {
                 foreach ($property as $_property) {
                     if ($_property["valueHTML"] && isset($_property["options"]["barcode"])) {
                         $options = $_property["options"]["barcode"];
                         $image = $this->getBarcodeDataUri($_property["valueHTML"], $options);
                         $fields[] = utf8_decode(html_entity_decode("src=\"{$_property['fieldHTML']}\""));
                         $values[] = "src=\"{$image}\"";
                     } elseif (isset($_property["options"]["data"])) {
                         $data = $_property["options"]["data"];
                         $fields_regex[] = $this->getDataRegex($data);
                         $values_regex[] = $_property["valueHTML"];
                     } else {
                         $fields[] = $_property["fieldHTML"];
                         $values[] = nl2br($_property["valueHTML"]);
                     }
                 }
             } else {
                 if ($property["valueHTML"] && isset($property["options"]["barcode"])) {
                     $options = $property["options"]["barcode"];
                     $image = $this->getBarcodeDataUri($property["valueHTML"], $options);
                     $fields[] = "src=\"{$property['fieldHTML']}\"";
                     $values[] = "src=\"{$image}\"";
                 } else {
                     if (isset($property["options"]["data"])) {
                         $data = $property["options"]["data"];
                         $fields_regex[] = $this->getDataRegex($data);
                         $values_regex[] = $property["valueHTML"];
                     } else {
                         if ($property["valueHTML"] && isset($property["options"]["image"])) {
                             $file = new CFile();
                             $file->load($property['value']);
                             $src = $file->getDataURI();
                             $fields[] = "src=\"{$property['fieldHTML']}\"";
                             $values[] = "src=\"{$src}\"";
                         } else {
                             $property["fieldHTML"] = preg_replace("/'/", ''', $property["fieldHTML"]);
                             $fields[] = $property["fieldHTML"];
                             $values[] = nl2br($property["valueHTML"]);
                         }
                     }
                 }
             }
         }
     }
     if (count($fields_regex)) {
         $_source = preg_replace($fields_regex, $values_regex, $_source);
     }
     if (count($fields)) {
         $_source = str_ireplace($fields, $values, $_source);
     }
     if (count($fields_regex) || count($fields)) {
         $this->document = $_source;
     }
 }
 /**
  * Ajoute les données des graphiques de supervision
  *
  * @param CTemplateManager $template The template manager
  * @param CMbObject        $object   The host object
  * @param string           $name     The field name
  *
  * @return void
  */
 static function addObservationDataToTemplate(CTemplateManager $template, CMbObject $object, $name)
 {
     $prefix = "Supervision";
     $group_id = CGroups::loadCurrent()->_id;
     $results = array();
     $times = array();
     if ($object->_id) {
         list($results, $times) = CObservationResultSet::getResultsFor($object, false);
         $times = array_combine($times, $times);
     }
     // CSupervisionGraphAxis
     $axis = new CSupervisionGraphAxis();
     $ds = $axis->getDS();
     $where = array("supervision_graph_axis.in_doc_template" => "= '1'", "supervision_graph.owner_class" => "= 'CGroups'", "supervision_graph.owner_id" => $ds->prepare("= ?", $group_id));
     $ljoin = array("supervision_graph" => "supervision_graph.supervision_graph_id = supervision_graph_axis.supervision_graph_id");
     $order = array("supervision_graph.title", "supervision_graph_axis.title");
     /** @var CSupervisionGraphAxis[] $axes */
     $axes = $axis->loadList($where, $order, null, null, $ljoin);
     CStoredObject::massLoadFwdRef($axes, "supervision_graph_id", null, true);
     foreach ($axes as $_axis) {
         $_graph = $_axis->loadRefGraph();
         $_series = $_axis->loadRefsSeries();
         $_axis->loadRefsLabels();
         $_data = array_fill_keys($times, array());
         foreach ($_series as $_serie) {
             $_unit_id = $_serie->value_unit_id ?: "none";
             $_unit_label = $_serie->loadRefValueUnit();
             if (!isset($results[$_serie->value_type_id][$_unit_id])) {
                 continue;
             }
             foreach ($results[$_serie->value_type_id][$_unit_id] as $_value) {
                 foreach ($times as $_time) {
                     if ($_value["datetime"] != $_time) {
                         continue;
                     }
                     $_value["unit"] = $_unit_label->label;
                     $_data["{$_time}"][$_serie->_id] = $_value;
                     break;
                 }
             }
         }
         $view = "";
         if (count($_data)) {
             $smarty = new CSmartyDP("modules/dPsalleOp");
             $smarty->assign("data", $_data);
             $smarty->assign("series", $_series);
             $smarty->assign("times", $times);
             $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0);
             $view = preg_replace('`([\\n\\r])`', '', $view);
         }
         $template->addProperty("{$name} - {$prefix} - {$_graph->title} - {$_axis->title}", trim($view), "", false);
     }
     // CSupervisionTimedPicture
     // CSupervisionTimedData
     $data = array("CSupervisionTimedPicture", "CSupervisionTimedData");
     foreach ($data as $_class) {
         /** @var CSupervisionTimedPicture|CSupervisionTimedData $_object */
         $_object = new $_class();
         $_table = $_object->_spec->table;
         $_ds = $_object->getDS();
         $where = array("{$_table}.in_doc_template" => "= '1'", "{$_table}.owner_class" => "= 'CGroups'", "{$_table}.owner_id" => $_ds->prepare("= ?", $group_id));
         $order = "title";
         /** @var CSupervisionTimedPicture[]|CSupervisionTimedData[] $_objects */
         $_objects = $_object->loadList($where, $order);
         foreach ($_objects as $_timed) {
             $_data = array_fill_keys($times, null);
             if (!isset($results[$_timed->value_type_id])) {
                 continue;
             }
             foreach ($results[$_timed->value_type_id]["none"] as $_value) {
                 foreach ($times as $_time) {
                     if ($_value["datetime"] != $_time) {
                         continue;
                     }
                     if ($_value["file_id"]) {
                         $_file = new CFile();
                         $_file->load($_value["file_id"]);
                         $_value["datauri"] = $_file->getDataURI();
                         $_value["file"] = $_file;
                     }
                     $_data["{$_time}"] = $_value;
                     break;
                 }
             }
             $view = "";
             if (count($_data)) {
                 $smarty = new CSmartyDP("modules/dPsalleOp");
                 $smarty->assign("data", $_data);
                 $smarty->assign("times", $times);
                 $smarty->assign("timed_data", true);
                 $view = $smarty->fetch("inc_print_observation_result_set.tpl", '', '', 0);
                 $view = preg_replace('`([\\n\\r])`', '', $view);
             }
             $template->addProperty("{$name} - {$prefix} - {$_timed->title}", trim($view), "", false);
         }
     }
 }
예제 #3
0
// post values
$dispo = CValue::post("tab_disposition");
$user_id = CValue::post("user_id");
$cat_id = CValue::post("category_id");
$print = CValue::post("print", 0);
// files
$file_array = CValue::post("file");
$data = $file_array[$dispo];
// context
$object_guid = CValue::post("context_guid");
$context = CMbObject::loadFromGuid($object_guid);
// get data uri
foreach ($data as $_key => &$_data) {
    $file = new CFile();
    $file->load($_data["file_id"]);
    $file->getDataURI();
    $_data["file_uri"] = $file->_data_uri;
}
//user
$user = CMediusers::get($user_id);
// file
$file = new CFile();
$file->setObject($context);
$file->file_name = CAppUI::tr("CFile-create-mozaic") . " de " . CAppUI::tr($context->_class) . " du " . CMbDT::dateToLocale(CMbDT::date()) . ".pdf";
$file->file_type = "application/pdf";
$file->file_category_id = $cat_id;
$file->author_id = CMediusers::get()->_id;
$file->fillFields();
$file->updateFormFields();
$file->forceDir();
$file->store();
예제 #4
0
$url = CValue::get('url');
$format = CValue::get('format');
if (!$file_id && !$url) {
    return "";
}
if ($file_id) {
    $file = new CFile();
    $file->load($file_id);
    $file->canDo();
    if (!$file->_can->read) {
        return "";
    }
    //@TODO le faire marcher avec du datauri
    if (strpos($file->file_type, "svg") !== false) {
        echo json_encode("?m=files&a=fileviewer&file_id={$file->_id}&phpTumb=1&suppressHeaders=1");
        CApp::rip();
        //echo CApp::json(file_get_contents($file->_file_path));
    } elseif ($format == 'uri') {
        $data = $file->getDataURI();
        CApp::json($data);
    }
} elseif ($url) {
    $mime_type = CMbPath::guessMimeType($url);
    $content = @file_get_contents($url);
    if ($content) {
        $data = "data:" . $mime_type . ";base64," . urlencode(base64_encode($content));
        CApp::json($data);
    } else {
        return "";
    }
}