From 0d3ee17bee116878b257df7bfe6fc2324062f7e7 Mon Sep 17 00:00:00 2001 From: JKA Network Date: Tue, 31 Oct 2017 09:41:28 +0100 Subject: [PATCH] Delete global vars, better standarized things --- connect.php | 2 +- cronchk.php | 111 +++++++++++++++++++++++++++++--------------------- functions.php | 24 ++++------- index.php | 4 +- panel.php | 16 ++++---- 5 files changed, 84 insertions(+), 73 deletions(-) diff --git a/connect.php b/connect.php index 84b7a07..29f7cb9 100755 --- a/connect.php +++ b/connect.php @@ -25,7 +25,7 @@ if (isset($_COOKIE['SessionID'])){ } -$lang=getSystemOpt('lang'); +$lang=getSystemOpt($db_conn,'lang'); //Translations require_once __DIR__."/assets/translations/en.php"; //Ever first English, and then your lang (Database) require_once __DIR__."/assets/translations/$lang.php"; diff --git a/cronchk.php b/cronchk.php index bbc2ade..189549c 100755 --- a/cronchk.php +++ b/cronchk.php @@ -1,55 +1,74 @@ getSystemOpt("maxChecksSave")){ - $todelete = $count - getSystemOpt("maxChecksSave"); //How much to delete + if ($count > getSystemOpt($db_conn,"maxChecksSave")){ + $todelete = $count - getSystemOpt($db_conn,"maxChecksSave"); //How much to delete dbw_query($db_conn, "DELETE FROM CHKHIST WHERE ID_C='$site[ID_C]' ORDER BY `timestamp` ASC LIMIT $todelete"); } } diff --git a/functions.php b/functions.php index c250b9d..914ee5b 100755 --- a/functions.php +++ b/functions.php @@ -13,13 +13,12 @@ require_once 'lib/loadTwig.php'; 4-In maintenance 255-Not results recolected (grey) */ -function checkStatus($ID_C){ - global $db_conn; +function checkStatus($db_conn,$ID_C){ //First, check if the status is marked to any manual value $manualPage = dbw_query_fetch_array($db_conn,"SELECT ID_C,manStatus FROM CHECKS WHERE ID_C='$ID_C'")['manStatus']; if ($manualPage != NULL){return $manualPage;} //If it's not manual-setted, see real status - $result = checkUptime($ID_C); + $result = checkUptime($db_conn,$ID_C); //Return status if ($result == 255){return 255;} if ($result > 95 && $result <= 100){return 0;} @@ -28,8 +27,7 @@ function checkStatus($ID_C){ if ($result >= 0 && $result <= 10){return 3;} //If test fail much (90% fail) } -function checkUptime($ID_C,$precision = 0){ - global $db_conn; +function checkUptime($db_conn,$ID_C,$precision = 0){ $time = $precision; if ($precision != 0){ $good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0 AND `timestamp` > $time")[0]; @@ -61,10 +59,8 @@ function webRoot(){ } /** Returns a system option */ -function getSystemOpt($sysopt){ - global $db_conn; +function getSystemOpt($db_conn,$sysopt){ return dbw_query_fetch_array($db_conn,"SELECT * FROM SYS WHERE option = '$sysopt'")['value']; - } /** Return HttpCode of page. Returns false if page is not found */ @@ -116,18 +112,15 @@ function requireLogin(){ } } -function nameFromIDC($ID_C){ - global $db_conn; +function nameFromIDC($db_conn,$ID_C){ return dbw_query_fetch_array($db_conn,"SELECT name FROM CHECKS WHERE ID_C='$ID_C'")[0]; } -function nameGroupFromIDG($ID_G){ - global $db_conn; +function nameGroupFromIDG($db_conn,$ID_G){ return dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name']; } -function IDGFromIDC($ID_C){ - global $db_conn; +function IDGFromIDC($db_conn,$ID_C){ return dbw_query_fetch_array($db_conn,"SELECT ID_G FROM CHECKS WHERE ID_C='$ID_C'")['ID_G']; } @@ -140,8 +133,7 @@ function arrayTypeChk(){ '4' => 'DATABASE'); } /* This funtion returns the translated text of a type check */ -function textTypeChk($typeChk){ - global $T_; +function textTypeChk($T_,$typeChk){ $arr = array( '1' => $T_['PING_IP'], '2' => $T_['HTTP_CODE'], diff --git a/index.php b/index.php index 0828944..b04dc4b 100755 --- a/index.php +++ b/index.php @@ -22,7 +22,7 @@ while ($onechk = dbw_fetch_array($db_conn,$results)){ case 4: //MySQL if (dbw_query_fetch_array($db_conn, "SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$idchk'")[0] != 0){ - $chks[$idchk]['status'] = checkStatus($idchk); //Check status of a site + $chks[$idchk]['status'] = checkStatus($db_conn,$idchk); //Check status of a site $chks[$idchk]['dateLastChk'] = date('d/m H:i',dbw_query_fetch_array($db_conn, "SELECT `timestamp` FROM CHKHIST WHERE ID_C = '$idchk' ORDER BY `timestamp` DESC")['timestamp']); $chks[$idchk]['failedLastChk'] = dbw_query_fetch_array($db_conn, "SELECT `code` FROM CHKHIST WHERE ID_C = '$idchk' ORDER BY `timestamp` DESC LIMIT 0,1")['code']; @@ -33,7 +33,7 @@ while ($onechk = dbw_fetch_array($db_conn,$results)){ } $ID_TC = $chks[$idchk]['ID_TC']; - $chks[$idchk]['nameCheck'] = textTypeChk($ID_TC); + $chks[$idchk]['nameCheck'] = textTypeChk($T_,$ID_TC); } break; diff --git a/panel.php b/panel.php index aee8984..1f62435 100755 --- a/panel.php +++ b/panel.php @@ -38,7 +38,7 @@ switch($page){ $ID_G = $chks[$idchk]['ID_G']; //For nameGroup $chks[$idchk]['nameGroup'] = dbw_query_fetch_array($db_conn,"SELECT * FROM GROUPS WHERE ID_G='$ID_G'")['name']; $ID_TC = $chks[$idchk]['ID_TC']; - $chks[$idchk]['nameTCheck'] = textTypeChk($ID_TC); + $chks[$idchk]['nameTCheck'] = textTypeChk($T_,$ID_TC); } @@ -65,7 +65,7 @@ switch($page){ foreach(arrayTypeChk() as $key => $value){ $tchecks[] = array( 'ID_TC' =>$key, - 'name' => textTypeChk($key) + 'name' => textTypeChk($T_,$key) ); } @@ -187,7 +187,7 @@ switch($page){ $news[$ID_N]['mdtext'] = $result['text']; //Raw text } - echo $twig->render('panel/p_news.twig', array('T_' => $T_, 'mpage' => 'news', 'allnews' => $news)); + echo $twig->render('panel/p_news.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'news', 'allnews' => $news)); break; case 'newnews': @@ -216,7 +216,7 @@ switch($page){ $sys[$syso['option']] = $syso['value']; } - echo $twig->render('panel/p_settings.twig', array('T_' => $T_, 'mpage' => 'settings', 'sys' => $sys)); + echo $twig->render('panel/p_settings.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'settings', 'sys' => $sys)); break; case 'users': @@ -280,9 +280,9 @@ switch($page){ if ($failssql != false){ while ($fail = dbw_fetch_array($db_conn,$failssql)){ //Create array $fails[] = array ( - 'name' => nameFromIDC($fail['ID_C']), - 'groupName' => nameGroupFromIDG(IDGFromIDC($fail['ID_C'])), - 'typeCheck' => textTypeChk($fail['ID_TC']), + 'name' => nameFromIDC($db_conn,$fail['ID_C']), + 'groupName' => nameGroupFromIDG($db_conn,IDGFromIDC($db_conn,$fail['ID_C'])), + 'typeCheck' => textTypeChk($T_,$fail['ID_TC']), 'errorText' => $fail['errorText'], 'date' => date('j/n/Y',$fail['timestamp']), 'hour' => date('H:i',$fail['timestamp']) @@ -292,7 +292,7 @@ switch($page){ $fails = array(); //Empty } - echo $twig->render('panel/p_index.twig', array('T_' => $T_, 'mpage' => 'index', 'data' => $data,'fails' => $fails)); //Render + echo $twig->render('panel/p_index.twig', array('T_' => $T_, 'you' => $you, 'mpage' => 'index', 'data' => $data,'fails' => $fails)); //Render break; }