From d964f354dbbdc8d38b3b0273a80e249656819b9d Mon Sep 17 00:00:00 2001 From: markjcrane Date: Thu, 25 May 2023 10:15:56 -0600 Subject: [PATCH] Fix PHP 8.1 warnings --- app/access_controls/access_control_import.php | 71 ++++++++++--------- resources/app_languages.php | 50 ++++++------- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/app/access_controls/access_control_import.php b/app/access_controls/access_control_import.php index 76ebd2bc49..5f74e3c2b3 100644 --- a/app/access_controls/access_control_import.php +++ b/app/access_controls/access_control_import.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2022 + Portions created by the Initial Developer are Copyright (C) 2008-2023 the Initial Developer. All Rights Reserved. Contributor(s): @@ -45,13 +45,13 @@ $language = new text; $text = $language->get(); -//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher +//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduce the functionality but requires PHP 5.1.0 or higher if (!function_exists('str_getcsv')) { function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { $fp = fopen("php://memory", 'r+'); fputs($fp, $input); rewind($fp); - $data = fgetcsv($fp, null, $delimiter, $enclosure, $escape); + $data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0 fclose($fp); return $data; } @@ -61,27 +61,27 @@ ini_set('max_execution_time', 7200); //get the http get values and set them as php variables - $action = $_POST["action"]; - $from_row = $_POST["from_row"]; - $delimiter = $_POST["data_delimiter"]; - $enclosure = $_POST["data_enclosure"]; + $action = $_POST["action"] ?? ''; + $from_row = $_POST["from_row"] ?? ''; + $delimiter = $_POST["data_delimiter"] ?? ''; + $enclosure = $_POST["data_enclosure"] ?? ''; //save the data to the csv file if (isset($_POST['data'])) { $file = $_SESSION['server']['temp']['dir']."/access_control_nodes-".$_SESSION['domain_name'].".csv"; - file_put_contents($file, $_POST['data']); - $_SESSION['file'] = $file; + if (file_put_contents($file, $_POST['data'])) { + $_SESSION['file'] = $file; + } } //copy the csv file //$_POST['submit'] == "Upload" && - if ( is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('contact_upload')) { - if ($_POST['type'] == 'csv') { - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); - $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); - //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); + if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('access_control_node_add')) { + if (!empty($_POST['type']) &&$_POST['type'] == 'csv') { $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; - $_SESSION['file'] = $file; + if (move_uploaded_file($_FILES['ulfile']['tmp_name'], $file)) { + $_SESSION['file'] = $file; + } } } @@ -97,7 +97,12 @@ $i = 0; foreach ($apps[0]['db'] as $table) { //get the table name and parent name - $table_name = $table["table"]['name']; + if (is_array($table["table"]['name'])) { + $table_name = $table["table"]['name']['text']; + } + else { + $table_name = $table["table"]['name']; + } $parent_name = $table["table"]['parent']; //remove the v_ table prefix @@ -108,10 +113,12 @@ $parent_name = substr($parent_name, 2); } + //filter for specific tables and build the schema array if ($table_name == 'access_control_nodes') { $schema[$i]['table'] = $table_name; $schema[$i]['parent'] = $parent_name; - foreach ($table['fields'] as $row) { + foreach($table['fields'] as $row) { + $row['deprecated'] = $row['deprecated'] ?? ''; if ($row['deprecated'] !== 'true') { if (is_array($row['name'])) { $field_name = $row['name']['text']; @@ -122,8 +129,8 @@ $schema[$i]['fields'][] = $field_name; } } + $i++; } - $i++; } } @@ -150,7 +157,7 @@ echo "
\n"; echo "
\n"; - echo "
".$text['header-import']."
\n"; + echo "
".$text['label-import']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'access_control_node_edit.php?id='.$_GET['id']]); echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); @@ -218,7 +225,7 @@ } //upload the csv - if (file_exists($_SESSION['file']) && $action == 'import') { + if (file_exists($_SESSION['file'] ?? '') && $action == 'import') { //validate the token $token = new token; @@ -229,9 +236,9 @@ } //user selected fields, labels - $fields = $_POST['fields']; - $labels = $_POST['labels']; - + $fields = $_POST['fields'] ?? ''; + $labels = $_POST['labels'] ?? ''; + //set the domain_uuid $domain_uuid = $_SESSION['domain_uuid']; @@ -314,14 +321,13 @@ $database->save($array); //clear the array - unset($array); + unset($array); //set the row id back to 0 $row_id = 0; } - } //if ($from_row <= $row_number) - unset($field_count); + } //if ($from_row <= $row_id) $row_number++; $row_id++; } //end while @@ -331,7 +337,7 @@ //view_array($array); //save to the data - if (is_array($array)) { + if (!empty($array)) { $database = new database; $database->app_name = 'access_controls'; $database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd'; @@ -341,7 +347,7 @@ //send the redirect header header("Location: access_control_edit.php?id=".$_GET['id']); - exit; + return; } } @@ -350,14 +356,14 @@ $token = $object->create($_SERVER['PHP_SELF']); //include the header - $document['title'] = $text['title-import']; + $document['title'] = $text['label-import']; require_once "resources/header.php"; //show content echo "\n"; echo "
\n"; - echo "
".$text['header-import']."
\n"; + echo "
".$text['label-import']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'access_control_edit.php?id='.$_GET['id']]); echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); @@ -375,7 +381,7 @@ echo " ".$text['label-import_data']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-import_data']."\n"; echo "\n"; @@ -438,8 +444,7 @@ echo "\n"; echo "\n"; - echo "
\n"; - echo "
\n"; + echo "

\n"; echo "\n"; echo "\n"; diff --git a/resources/app_languages.php b/resources/app_languages.php index 9a5be584c8..ad15be5757 100644 --- a/resources/app_languages.php +++ b/resources/app_languages.php @@ -2055,31 +2055,31 @@ $text['label-summary']['zh-cn'] = "概括"; $text['label-summary']['ja-jp'] = "まとめ"; $text['label-summary']['ko-kr'] = "요약"; -$text['header-import']['en-us'] = "Import"; -$text['header-import']['en-gb'] = "Import"; -$text['header-import']['ar-eg'] = "يستورد"; -$text['header-import']['de-at'] = "Importieren"; -$text['header-import']['de-ch'] = "Importieren"; -$text['header-import']['de-de'] = "Importieren"; -$text['header-import']['el-gr'] = "Εισαγωγή"; -$text['header-import']['es-cl'] = "Importar"; -$text['header-import']['es-mx'] = "Importar"; -$text['header-import']['fr-ca'] = "Importer"; -$text['header-import']['fr-fr'] = "Importer"; -$text['header-import']['he-il'] = "יְבוּא"; -$text['header-import']['it-it'] = "Importare"; -$text['header-import']['nl-nl'] = "Importeren"; -$text['header-import']['pl-pl'] = "Importuj"; -$text['header-import']['pt-br'] = "Importar"; -$text['header-import']['pt-pt'] = "Importat"; -$text['header-import']['ro-ro'] = "Import"; -$text['header-import']['ru-ru'] = "Импорт"; -$text['header-import']['sv-se'] = "Importera"; -$text['header-import']['uk-ua'] = "Імпорт"; -$text['header-import']['tr-tr'] = "İçe Aktar"; -$text['header-import']['zh-cn'] = "进口"; -$text['header-import']['ja-jp'] = "輸入"; -$text['header-import']['ko-kr'] = "수입"; +$text['label-import']['en-us'] = "Import"; +$text['label-import']['en-gb'] = "Import"; +$text['label-import']['ar-eg'] = "يستورد"; +$text['label-import']['de-at'] = "Importieren"; +$text['label-import']['de-ch'] = "Importieren"; +$text['label-import']['de-de'] = "Importieren"; +$text['label-import']['el-gr'] = "Εισαγωγή"; +$text['label-import']['es-cl'] = "Importar"; +$text['label-import']['es-mx'] = "Importar"; +$text['label-import']['fr-ca'] = "Importer"; +$text['label-import']['fr-fr'] = "Importer"; +$text['label-import']['he-il'] = "יְבוּא"; +$text['label-import']['it-it'] = "Importare"; +$text['label-import']['nl-nl'] = "Importeren"; +$text['label-import']['pl-pl'] = "Importuj"; +$text['label-import']['pt-br'] = "Importar"; +$text['label-import']['pt-pt'] = "Importat"; +$text['label-import']['ro-ro'] = "Import"; +$text['label-import']['ru-ru'] = "Импорт"; +$text['label-import']['sv-se'] = "Importera"; +$text['label-import']['uk-ua'] = "Імпорт"; +$text['label-import']['tr-tr'] = "İçe Aktar"; +$text['label-import']['zh-cn'] = "进口"; +$text['label-import']['ja-jp'] = "輸入"; +$text['label-import']['ko-kr'] = "수입"; $text['description-import']['en-us'] = "Upload delimited data to add multiple records."; $text['description-import']['en-gb'] = "Upload delimited data to add multiple records.";