İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user