remove db=null
This commit is contained in:
+6
-29
@@ -113,7 +113,7 @@ CreateApi(function ($api) {
|
|||||||
// according docs (UPPERCASE, MIN 3 MAX 10)
|
// according docs (UPPERCASE, MIN 3 MAX 10)
|
||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM classes WHERE classid = ?", [$classId]);
|
$results = FastDBReq($db, "SELECT * FROM classes WHERE classid = ?", [$classId]);
|
||||||
$db = null;
|
|
||||||
if (count($results) != 0) {
|
if (count($results) != 0) {
|
||||||
return $results[0];
|
return $results[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -130,7 +130,7 @@ CreateApi(function ($api) {
|
|||||||
// according docs (UPPERCASE, MIN 3 MAX 10)
|
// according docs (UPPERCASE, MIN 3 MAX 10)
|
||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT userclassname FROM classes WHERE classid = ?", [$classId]);
|
$results = FastDBReq($db, "SELECT userclassname FROM classes WHERE classid = ?", [$classId]);
|
||||||
$db = null;
|
|
||||||
|
|
||||||
if (count($results) != 0) {
|
if (count($results) != 0) {
|
||||||
return $results[0];
|
return $results[0];
|
||||||
@@ -147,7 +147,7 @@ CreateApi(function ($api) {
|
|||||||
$adminId = $req->data['adminId'];
|
$adminId = $req->data['adminId'];
|
||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT adminName FROM admins where adminid = ?", [$adminId]);
|
$results = FastDBReq($db, "SELECT adminName FROM admins where adminid = ?", [$adminId]);
|
||||||
$db = null;
|
|
||||||
|
|
||||||
if (count($results) != 0) {
|
if (count($results) != 0) {
|
||||||
return $results[0];
|
return $results[0];
|
||||||
@@ -164,7 +164,7 @@ CreateApi(function ($api) {
|
|||||||
$adminId = $req->data['adminId'];
|
$adminId = $req->data['adminId'];
|
||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT adminPrems FROM admins where adminid = ?", [$adminId]);
|
$results = FastDBReq($db, "SELECT adminPrems FROM admins where adminid = ?", [$adminId]);
|
||||||
$db = null;
|
|
||||||
|
|
||||||
if (count($results) != 0) {
|
if (count($results) != 0) {
|
||||||
return $results[0];
|
return $results[0];
|
||||||
@@ -181,7 +181,7 @@ CreateApi(function ($api) {
|
|||||||
$adminId = $req->data['adminId'];
|
$adminId = $req->data['adminId'];
|
||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminid = ?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminid = ?", [$adminId]);
|
||||||
$db = null;
|
|
||||||
|
|
||||||
if (count($results) != 0) {
|
if (count($results) != 0) {
|
||||||
return $results[0];
|
return $results[0];
|
||||||
@@ -218,7 +218,6 @@ CreateApi(function ($api) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($has_full_rings) {
|
if ($has_full_rings) {
|
||||||
$db = null;
|
|
||||||
// with rings
|
// with rings
|
||||||
return ['data' => $content, 'type' => 2];
|
return ['data' => $content, 'type' => 2];
|
||||||
} else {
|
} else {
|
||||||
@@ -229,7 +228,6 @@ CreateApi(function ($api) {
|
|||||||
if ($rings !== null) {
|
if ($rings !== null) {
|
||||||
$out = joinArraysByKey($content, $rings, true);
|
$out = joinArraysByKey($content, $rings, true);
|
||||||
}
|
}
|
||||||
$db = null;
|
|
||||||
return ['data' => $out, 'type' => 1];
|
return ['data' => $out, 'type' => 1];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -245,10 +243,8 @@ CreateApi(function ($api) {
|
|||||||
if ($rings !== null) {
|
if ($rings !== null) {
|
||||||
$out = joinArraysByKey($schedule, $rings);
|
$out = joinArraysByKey($schedule, $rings);
|
||||||
}
|
}
|
||||||
$db = null;
|
|
||||||
return ['data' => $out, 'type' => 0];
|
return ['data' => $out, 'type' => 0];
|
||||||
} else {
|
} else {
|
||||||
$db = null;
|
|
||||||
return ['data' => []];
|
return ['data' => []];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,7 +258,6 @@ CreateApi(function ($api) {
|
|||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "админ не найден";
|
return "админ не найден";
|
||||||
# end
|
# end
|
||||||
@@ -293,7 +288,6 @@ CreateApi(function ($api) {
|
|||||||
$rings = json_decode(findClosestDateSort($results, $day)['content'], true);
|
$rings = json_decode(findClosestDateSort($results, $day)['content'], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$db = null;
|
|
||||||
|
|
||||||
switch ($tab) {
|
switch ($tab) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -323,7 +317,6 @@ CreateApi(function ($api) {
|
|||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "админ не найден";
|
return "админ не найден";
|
||||||
# end
|
# end
|
||||||
@@ -334,7 +327,6 @@ CreateApi(function ($api) {
|
|||||||
$newDataRaw = $req->data['newData'];
|
$newDataRaw = $req->data['newData'];
|
||||||
$newData = json_decode($newDataRaw, true);
|
$newData = json_decode($newDataRaw, true);
|
||||||
|
|
||||||
// im too lazy to close db
|
|
||||||
|
|
||||||
switch ($tab) {
|
switch ($tab) {
|
||||||
case 0: // changes
|
case 0: // changes
|
||||||
@@ -397,7 +389,6 @@ CreateApi(function ($api) {
|
|||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "админ не найден";
|
return "админ не найден";
|
||||||
# end
|
# end
|
||||||
@@ -417,10 +408,8 @@ CreateApi(function ($api) {
|
|||||||
FastDBReq($db, 'DELETE FROM rings WHERE classId=? AND fromDate=?', [$classId, $day]);
|
FastDBReq($db, 'DELETE FROM rings WHERE classId=? AND fromDate=?', [$classId, $day]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$db = null;
|
|
||||||
return "you saved your live because you didn't know what tabs are here";
|
return "you saved your live because you didn't know what tabs are here";
|
||||||
}
|
}
|
||||||
$db = null;
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
$api->on('/update_admin', "POST", function ($req) {
|
$api->on('/update_admin', "POST", function ($req) {
|
||||||
@@ -438,12 +427,10 @@ CreateApi(function ($api) {
|
|||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "админ не найден";
|
return "админ не найден";
|
||||||
}
|
}
|
||||||
if (!$withSelf && !in_array($results[0]['adminPrems'], [-1, 2])) {
|
if (!$withSelf && !in_array($results[0]['adminPrems'], [-1, 2])) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return 'нету прав';
|
return 'нету прав';
|
||||||
}
|
}
|
||||||
@@ -462,7 +449,6 @@ CreateApi(function ($api) {
|
|||||||
try {
|
try {
|
||||||
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $adminId]);
|
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $adminId]);
|
||||||
} catch (PDOException) {
|
} catch (PDOException) {
|
||||||
$db = null;
|
|
||||||
return "egor";
|
return "egor";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -483,16 +469,13 @@ CreateApi(function ($api) {
|
|||||||
try {
|
try {
|
||||||
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $person]);
|
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $person]);
|
||||||
} catch (PDOException) {
|
} catch (PDOException) {
|
||||||
$db = null;
|
|
||||||
return "egor";
|
return "egor";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$db = null;
|
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$db = null;
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -505,12 +488,10 @@ CreateApi(function ($api) {
|
|||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "админ не найден";
|
return "админ не найден";
|
||||||
}
|
}
|
||||||
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
|
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "недостаточно прав";
|
return "недостаточно прав";
|
||||||
}
|
}
|
||||||
@@ -519,13 +500,12 @@ CreateApi(function ($api) {
|
|||||||
|
|
||||||
$results = FastDBReq($db, "SELECT * FROM classes WHERE classId=?", [$classId]);
|
$results = FastDBReq($db, "SELECT * FROM classes WHERE classId=?", [$classId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "класса не существует";
|
return "класса не существует";
|
||||||
}
|
}
|
||||||
$classData = $results[0];
|
$classData = $results[0];
|
||||||
$adminsData = FastDBReq($db, "SELECT * FROM admins WHERE adminClass=?", [$classId]);
|
$adminsData = FastDBReq($db, "SELECT * FROM admins WHERE adminClass=?", [$classId]);
|
||||||
$db = null;
|
|
||||||
|
|
||||||
return ["status" => 1, "class" => $classData, "admins" => $adminsData];
|
return ["status" => 1, "class" => $classData, "admins" => $adminsData];
|
||||||
});
|
});
|
||||||
@@ -539,12 +519,10 @@ CreateApi(function ($api) {
|
|||||||
$db = db();
|
$db = db();
|
||||||
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
|
||||||
if (count($results) == 0) {
|
if (count($results) == 0) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "админ не найден";
|
return "админ не найден";
|
||||||
}
|
}
|
||||||
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
|
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
|
||||||
$db = null;
|
|
||||||
$req->res->code(400);
|
$req->res->code(400);
|
||||||
return "недостаточно прав";
|
return "недостаточно прав";
|
||||||
}
|
}
|
||||||
@@ -610,7 +588,6 @@ CreateApi(function ($api) {
|
|||||||
FastDBReq($db, "DELETE FROM admins WHERE adminId=?", [$person]);
|
FastDBReq($db, "DELETE FROM admins WHERE adminId=?", [$person]);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
$db = null;
|
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user