prefix . 'shed_calculator';
// پاکسازی و اعتبارسنجی ورودیها
$width = floatval($_POST['width']);
$length = floatval($_POST['length']);
$height = floatval($_POST['height']);
$shed_type = sanitize_text_field($_POST['shed_type']);
$province = sanitize_text_field($_POST['province']);
$phone = sanitize_text_field($_POST['phone']);
// اعتبارسنجی
$errors = [];
if ($width < 10) {
$errors[] = 'عرض باید بیشتر یا برابر 10 باشد.';
$width = 0;
}
if ($width > 46) {
$errors[] = 'عرض بیشتر از 46 است. لطفاً با واحد فنی تماس بگیرید (09143229415).';
$width = 0;
}
if ($length < 6) {
$errors[] = 'طول باید بیشتر یا برابر 6 باشد.';
$length = 0;
}
if ($height > 12) {
$errors[] = 'ارتفاع بیشتر از 12 متر است. لطفاً با مشاور تماس بگیرید (09143229415).';
$height = 0;
}
if (!preg_match('/^09[0-9]{9}$/', $phone)) {
$errors[] = 'شماره تلفن معتبر نیست (باید 11 رقم و با 09 شروع شود).';
}
if (empty($errors) && $width > 0 && $length > 0 && $height > 0) {
// محاسبه مضرب طول
if ($length <= 12) {
$length = 12;
} elseif ($length <= 18) {
$length = 18;
} elseif ($length <= 24) {
$length = 24;
} elseif ($length <= 30) {
$length = 30;
} elseif ($length <= 36) {
$length = 36;
} elseif ($length <= 42) {
$length = 42;
} elseif ($length <= 48) {
$length = 48;
} elseif ($length <= 54) {
$length = 54;
} elseif ($length <= 60) {
$length = 60;
} elseif ($length <= 66) {
$length = 66;
} elseif ($length <= 72) {
$length = 72;
} elseif ($length <= 78) {
$length = 78;
} elseif ($length <= 84) {
$length = 84;
} elseif ($length <= 90) {
$length = 90;
} elseif ($length <= 96) {
$length = 96;
} elseif ($length <= 102) {
$length = 102;
} elseif ($length <= 108) {
$length = 108;
} elseif ($length <= 114) {
$length = 114;
} elseif ($length <= 120) {
$length = 120;
}
// محاسبه ضریب ارتفاع
if ($width <= 24) {
if ($height <= 2.9) {
$height_factor = 18.5;
} elseif ($height <= 4.9) {
$height_factor = 21;
} elseif ($height <= 6) {
$height_factor = 26;
} elseif ($height <= 7) {
$height_factor = 28;
} elseif ($height <= 8) {
$height_factor = 29.8;
} elseif ($height <= 9) {
$height_factor = 33.6;
} elseif ($height <= 10) {
$height_factor = 36.3;
} elseif ($height <= 11) {
$height_factor = 41;
} elseif ($height <= 12) {
$height_factor = 45;
}
} elseif ($width <= 28.9) {
if ($height <= 2.9) {
$height_factor = 23;
} elseif ($height <= 4.9) {
$height_factor = 30;
} elseif ($height <= 6) {
$height_factor = 34.7;
} elseif ($height <= 7) {
$height_factor = 39.8;
} elseif ($height <= 8) {
$height_factor = 43.4;
} elseif ($height <= 9) {
$height_factor = 45;
} elseif ($height <= 10) {
$height_factor = 47;
} elseif ($height <= 11) {
$height_factor = 50;
} elseif ($height <= 12) {
$height_factor = 53;
}
} elseif ($width <= 46) {
if ($height <= 2.9) {
$height_factor = 29;
} elseif ($height <= 4.9) {
$height_factor = 31;
} elseif ($height <= 6) {
$height_factor = 34;
} elseif ($height <= 7) {
$height_factor = 37;
} elseif ($height <= 8) {
$height_factor = 40;
} elseif ($height <= 9) {
$height_factor = 44;
} elseif ($height <= 10) {
$height_factor = 47;
} elseif ($height <= 11) {
$height_factor = 50;
} elseif ($height <= 12) {
$height_factor = 55;
}
}
// محاسبه وزن
$total_weight = $width * $length * $height_factor;
if ($shed_type == '2') { // دو طبقه
$total_weight *= 2.2;
$total_weight = round($total_weight);
} elseif ($shed_type == '3') { // سردخانهای
$total_weight *= 1.5; // ضریب فرضی برای سردخانهای
}
// محاسبه هزینه
$total_cost = $total_weight * STEEL_PRICE_PER_KG;
// ذخیره اطلاعات در پایگاه داده
$wpdb->insert(
$table_name,
[
'width' => $width,
'length' => $length,
'height' => $height,
'shed_type' => $shed_type,
'province' => $province,
'phone' => $phone,
'total_weight' => $total_weight,
'total_cost' => $total_cost,
],
['%f', '%f', '%f', '%s', '%s', '%s', '%f', '%d']
);
$calculation_id = $wpdb->insert_id;
// نمایش نتیجه
echo "
";
echo "
نتیجه محاسبه
";
echo "
وزن کل سوله: " . number_format($total_weight, 2) . " کیلوگرم
";
echo "
مساحت کل: " . number_format($width * $length, 2) . " متر مربع
";
echo "
هزینه تقریبی: " . number_format($total_cost) . " تومان
";
echo "
محل اجرا: " . esc_html($province) . "
";
echo "
شماره تماس: " . esc_html($phone) . "
";
echo "
";
echo "
توضیحات: این محاسبه تقریبی است و وزن و هزینه دقیق تنها با نقشههای اجرایی قابل تعیین است.
";
echo "
مشاوره در واتساب: 09143229415
";
echo "
";
// فرم ثبت نظر
echo "";
} else {
echo "
";
foreach ($errors as $error) {
echo "
$error
";
}
echo "
";
}
}
// ثبت نظر
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_comment'])) {
global $wpdb;
$table_name = $wpdb->prefix . 'shed_calculator';
$calculation_id = intval($_POST['calculation_id']);
$comment = sanitize_textarea_field($_POST['comment']);
$wpdb->update(
$table_name,
['comment' => $comment],
['id' => $calculation_id],
['%s'],
['%d']
);
echo "
";
echo "
نظر شما با موفقیت ثبت شد.
";
echo "
";
}
?>
محاسبه وزن و قیمت سوله
نظر خود را ثبت کنید
"; echo ""; echo "