Joywork/cron/move_req_doers.php
2026-05-22 21:21:54 +03:00

54 lines
1.6 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
set_time_limit(0);
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Перенос совместной работы с заявками</title>
</head>
<body>
<?php
$sql = "SELECT * FROM requisitions WHERE doers IS NOT NULL AND doers <> '' AND doers <> '[]'";
$rez = mysql_query($sql);
while($req = mysql_fetch_assoc($rez)) {
$req_id = $req['id'];
echo "Работаем с заявкой " . $req_id;
if(!empty($req['doers'])){
$doers = json_decode(html_entity_decode($req['doers']), true);
var_dump($doers);
foreach($doers as $key => $agent){
$sql_s = "SELECT id FROM requisition_doers WHERE requisition_id = {$req_id} AND user_id = {$key}";
$q_s = mysql_query($sql_s);
if(mysql_num_rows($q_s) > 0) {
echo "Нашли, обновляем ";
$sql_u = "UPDATE requisition_doers SET confirm = {$agent} WHERE requisition_id = {$req_id} AND user_id = {$key}";
if (!mysql_query($sql_u)) {
echo mysql_error();
}
} else {
echo "Не нашли, вставляем";
$sql_i = "INSERT INTO requisition_doers (requisition_id, user_id, confirm) VALUES (" . $req_id . ", " . $key . ", " . $agent . ")";
if (!mysql_query($sql_i)) {
echo mysql_error();
}
}
}
}
}
?>
</body>
</html>