Files
citrus-cms/app/Functions/replace-placeholder-with-inputs.php
2026-04-28 21:14:25 +03:00

60 lines
2.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
function replacePlaceholdersWithInputs($html, $relationDatas=[]) {
// Placeholder deseni: {type.name}
$pattern = '/\{(\w+)\.(\w+)(?:\.([^}]+))?\}/';
$html = str_replace("{page}", '<input type="number" name="page" >', $html);
$html = preg_replace_callback($pattern, function($matches) use($relationDatas) {
$type = $matches[1];
$name = $matches[2];
$value = isset($matches[3]) ? $matches[3] : null;
switch ($type) {
case 'radio':
case 'checkbox':
return '<input type="' . htmlspecialchars($type) . '" placeholder="'. $name .'" value="' . $value . '" name="' . htmlspecialchars($name) . '" checked>';
case 'text':
case 'email':
case 'number':
case 'date':
if($type == "date") {
$value = date("Y-m-d");
} else {
$value = "";
}
return '<input type="' . htmlspecialchars($type) . '" placeholder="'. $name .'" class="form-control" value="'. $value .'" name="' . htmlspecialchars($name) . '">';
case 'time':
return '<input type="' . htmlspecialchars($type) . '" placeholder="'. $name .'" class="form-control" name="' . htmlspecialchars($name) . '">';
case 'textarea':
return '<textarea style="height: 400px;" name="' . htmlspecialchars($name) . '" placeholder="'. $name .'" class="form-control"></textarea>';
case 'select':
$options = "<option value=''>Select $name</option>";
if(isset($relationDatas[$name]))
{
foreach($relationDatas[$name] AS $option)
{
$options .= "<option value='$option'>$option</option>";
}
}
return '<select class="form-control" name="' . htmlspecialchars($name) . '">'
. $options
. '</select>';
default:
return $matches[0]; // Değişiklik yapılmadan bırak
}
}, $html);
$mainContractor = db("subcontractors")->where("operation_type", "MAIN CONTRACTOR")->first();
if($mainContractor)
{
$html = str_replace("{project_address}", $mainContractor->address_ru . " / " . $mainContractor->address_en, $html);
}
$html = str_replace("{project_name}", setting("project_name_ru") . " / " . setting("project_name"), $html);
return $html;
}
?>