Base Directory:
/home/ecedu/public_html/new/api
View File: social_controller.php
<?php
include ('header.php');
// التحقق من قيمة الـ typeId
$typeId = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
if ($typeId === false || $typeId <= 0) {
exit('error: invalid type_id');
}
// استدعاء الكائن الخاص بإدارة dbs_basic / dbs_type
require_once __DIR__ . '/../Models/BasicManager.php';
require_once __DIR__ . '/../Models/Functions.php'; // مثلاً يحتوي على cleanHtml
$basicManager = new BasicManager();
$functions = new Functions();
function respond($status, $message) {
echo json_encode(['status' => $status, 'message' => $message], JSON_UNESCAPED_UNICODE);
exit;
}
// التحقق من النصوص
$texts = [];
if ( isset($_POST['text1'], $_POST['text2'], $_POST['text3'], $_POST['text4'])) {
$texts = [
$_POST['text1'],
$_POST['text2'],
$_POST['text3'],
$_POST['text4'],
];
} else {
exit('error: no valid text input');
}
// الاتصال (PDO) سيبدأ المعاملة (Transaction)
$db = $basicManager->getDb(); // أو أضف getConnection() في الـ BasicManager
$db->beginTransaction();
try {
foreach ($texts as $index => $rawText) {
$tid = $typeId + $index;
$desc = $functions->htmlToText($rawText);
// إدخال/تحديث الأساسي
if (!$basicManager->insertOrUpdateBasic($tid, $desc)) {
throw new Exception("insertOrUpdateBasic failed for type_id=$tid");
}
}
$db->commit();
respond(true, 'تم تحديث البيانات بنجاح');
} catch (Exception $e) {
$db->rollBack();
respond(false, $e->getMessage());
}