Files
MYSOPHAL/front/article.existance.php
2025-08-07 13:15:31 +01:00

61 lines
2.2 KiB
PHP

<?php
include ('../model_controller/article.existance.php');
Session::checkLoginUser();
if(isset($_GET['type'])){
$type = $_GET['type'];
$name = $_GET['art'];
$exist = 0;
$created = 0;
$qry = "";
$code ="";
$exist = ($type == "famplus") ? checkFamExist(strtoupper($name)) : checkSFamExist(strtoupper($name));
if(!$exist){
$temp = explode(" ",$name);
if(count($temp) > 1){
foreach($temp as $str){
$code = $code.$str[0];
}
$exist = ($type == "famplus") ? checkFamCodeExist(strtoupper($code)) : checkSFamCodeExist(strtoupper($code));
if($exist){
$lastid = ($type == "famplus") ? getFamLastId(strtoupper($code)) : getSFamLastId(strtoupper($code));
$count = ($lastid != null) ? intval($lastid['c']) : 0;
$code = $code.($count + 1);
$created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name));
if($created){
$exist = 0;
}
}else{
$created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name));
}
}else{
$code = substr($name,0,3);
$exist = ($type == "famplus") ? checkFamCodeExist(strtoupper($code)) : checkSFamCodeExist(strtoupper($code));
if($exist){
$lastid = ($type == "famplus") ? getFamLastId(strtoupper($code)) : getSFamLastId(strtoupper($code));
$count = ($lastid != null) ? intval($lastid['c']) : 0;
$code = $code.($count + 1);
$created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name));
}else{
$created = ($type == "famplus") ? addFamille(strtoupper($code),strtoupper($name)) : addSFamille(strtoupper($code),strtoupper($name));
}
}
}
$data = array("exists" => $exist,"created"=>$created,"code"=>$code);
echo json_encode($data);
}