Prestashop- How to add Amount Due in AdminOrdersController.php

My Prestashop version is 1.7.5
I wanted to add the amount due value in the AdminOrdersController. Amount due value can be calculated using (‘total_paid_tax_incl’-‘total_paid_real’)

        'total_paid_real' => array(
            'title' => $this->trans('Real Paid', array(), 'Admin.Global'),
            'align' => 'text-right',
            'type' => 'price',
            'currency' => true,
            'badge_success' => true,
        ),

So I modified it like this

        'total_paid_tax_incl'-'total_paid_real' => array(
            'title' => $this->trans('Amount Due', array(), 'Admin.Global'),
            'align' => 'text-right',
            'type' => 'price',
            'currency' => true,
            'badge_success' => true,
        ),

But It is throwing an error, Warning: A non-numeric value encountered.
Though both value ‘total_paid_tax_incl’ & ‘total_paid_real’ are in decimal(20,6)

Can you guys help me to solve the issue?

How did i get and Session Var into an function

my problem is that i did not get an php session variable into my function – i start in the top of the file

<?php
session_start();
var_dump($_SESSION);

this is the result

array(3) { ["loggedin"]=> bool(true) ["name"]=> string(4) "Piet" ["id_staff"]=> int(9) }
public static function getStaffList($_SESSION['name']){

  if ($_SESSION['name'] =="admin" || $_SESSION['name'] =="Piet") {
    $sql = "SELECT * FROM staff";
  }
  else {
    $sql = "SELECT * FROM staff where surname = '".$_SESSION['name']."'";
  }

  $result = Core::$link->query($sql);

  if (!$result) {
    return 'Error: ' . mysqli_error(Core::$link);
  }

  $return = array();
  while ($myrow = mysqli_fetch_assoc($result)) {
    if ($myrow['birthday'] !== '0000-00-00') {
      $myrow['birthday'] = date("d.m.Y", strtotime($myrow['birthday']));
    } else {
      $myrow['birthday'] = '';
    }

    $return[] = $myrow;
  }

  return $return;
}

How do I auto-post all posts under a certain custom post type ‘X’ one-by-one (either orderly or randomly) every x-time to my Telegram channel?

I want to auto-post all posts under a certain custom post type ‘escort’ one-by-one (orderly or randomly) every x-time to my Telegram channel.

For orderly auto-posting, loop.

There’re many WordPress plugins out there that offer auto-posting to Telegram, but NOT even the premium ones can do this.

Since no plugin could meet my needs, I decided to do it myself. But I ran into a serious trouble…

I added a menu item to WP Admin menu to be sure that the code captures the post links from the intended custom post type ‘escort’ correctly, which it does.

But the real trouble now is how to post each of these links to my bot on Telegram to post on my channel (post 1 link every 5mins). I’ve edited the code to try different posting methods but the bot isn’t getting it.

I know that my bot works because I have tested it with plugins like WP Telegram and Blog2social. I’ve also tested it with URL commands like: https://api.telegram.org/bot/sendMessage?chat_id=@&text=some_message and it works.

So, I’m almost certain that my bot is not getting the link from my code, which means my code isn’t posting the link to the bot, I guess.

Please someone should help correct my code.

Here are two variations of my custom plugin code:

<?php
/**
 * Plugin Name: SFS Auto Post to Telegram
 * Plugin URI:  https://example.com/auto-post-to-telegram
 * Description: Automatically posts links from the "escort" custom post type to a Telegram channel at regular intervals.
 * Version:     1.0.0
 * Author:      Godman Andrew
 * Author URI:  https://example.com
 */

// Add a custom menu page to display the post links
function sfs_auto_post_to_telegram_menu_page() {
    add_menu_page(
        'Post Links',
        'Post Links',
        'manage_options',
        'sfs_auto_post_to_telegram_links',
        'sfs_auto_post_to_telegram_links_callback'
    );
}
add_action('admin_menu', 'sfs_auto_post_to_telegram_menu_page');

// Callback function to output the post links on the custom menu page
function sfs_auto_post_to_telegram_links_callback() {
    // Query all posts of the custom post type "escort"
    $args = array(
        'post_type' => 'escort',
        'posts_per_page' => -1,
    );

    $loop = new WP_Query($args);

    // Create an array to store the post links
    $postLinks = array();

    if ($loop->have_posts()) {
        while ($loop->have_posts()) {
            $loop->the_post();
            $postLink = get_permalink();
            $postLinks[] = $postLink;
        }
    }

    // Close the loop
    wp_reset_postdata();

    // Output the post links on the page
    echo '<div class="wrap">';
    echo '<h1>Post Links</h1>';
    if (!empty($postLinks)) {
        echo '<ul>';
        foreach ($postLinks as $link) {
            echo '<li>' . $link . '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>No post links found.</p>';
    }
    echo '</div>';
}

// Set up the Telegram bot API credentials
$telegramBotToken = '6099757413:AAERb-CCDsrhoyXKZTgSYs7fjiWCuY9Hps0';
$telegramChannel = '@ExampleXYZT';

// Register a custom cron schedule interval
function sfs_auto_post_to_telegram_register_cron_interval($schedules) {
    $schedules['sfs_5_minutes'] = array(
        'interval' => 300,
        'display' => __('Every 5 minutes'),
    );
    return $schedules;
}
add_filter('cron_schedules', 'sfs_auto_post_to_telegram_register_cron_interval');

// Schedule the Telegram posting event
function sfs_auto_post_to_telegram_schedule_event() {
    if (!wp_next_scheduled('sfs_auto_post_to_telegram_event')) {
        wp_schedule_event(time(), 'sfs_5_minutes', 'sfs_auto_post_to_telegram_event');
    }
}
register_activation_hook(__FILE__, 'sfs_auto_post_to_telegram_schedule_event');

// Unschedule the Telegram posting event
function sfs_auto_post_to_telegram_unschedule_event() {
    wp_clear_scheduled_hook('sfs_auto_post_to_telegram_event');
}
register_deactivation_hook(__FILE__, 'sfs_auto_post_to_telegram_unschedule_event');

// Telegram posting event callback
function sfs_auto_post_to_telegram_event_callback() {
    // Include the necessary WordPress files
    // Check if WordPress is loaded, and if not, load the WordPress environment
if ( ! defined( 'ABSPATH' ) ) {
    /** Set up WordPress environment */
    require_once( dirname( __FILE__ ) . '/../../../wp-load.php' );
}

    // Query all posts of the custom post type "escort"
    $args = array(
        'post_type' => 'escort',
        'posts_per_page' => -1,
    );

    $loop = new WP_Query($args);

    // Create an array to store the post links
    $postLinks = array();

    if ($loop->have_posts()) {
        while ($loop->have_posts()) {
            $loop->the_post();
            $postLink = get_permalink();
            $postLinks[] = $postLink;
        }
    }

    // Close the loop
    wp_reset_postdata();

    // Get the current link index from options
    $currentLinkIndex = get_option('sfs_auto_post_to_telegram_current_link_index', 0);

    // Get the current post link
    $currentLink = $postLinks[$currentLinkIndex];

    // Send the current post link to Telegram using the bot API
    $telegramEndpoint = 'https://api.telegram.org/bot' . $telegramBotToken . '/sendMessage';
    $telegramParams = array(
        'chat_id' => $telegramChannel,
        'text' => $currentLink,
    );
    $telegramResponse = wp_remote_post(
    $telegramEndpoint,
    array(
        'body' => $telegramParams,
    )
);

    // Move to the next post link
    $currentLinkIndex++;
    if ($currentLinkIndex >= count($postLinks)) {
        $currentLinkIndex = 0;
    }

    // Update the current link index in options
    update_option('sfs_auto_post_to_telegram_current_link_index', $currentLinkIndex);
}
add_action('sfs_auto_post_to_telegram_event', 'sfs_auto_post_to_telegram_event_callback');

// Delete the current link index option on plugin uninstallation
function sfs_auto_post_to_telegram_uninstall() {
    delete_option('sfs_auto_post_to_telegram_current_link_index');
}
register_uninstall_hook(__FILE__, 'sfs_auto_post_to_telegram_uninstall');

THE SECOND VARIATION

<?php
/**
 * Plugin Name: SFS Auto Post to Telegram
 * Plugin URI:  https://example.com/auto-post-to-telegram
 * Description: Automatically posts links from the "escort" custom post type to a Telegram channel at regular intervals.
 * Version:     1.0.0
 * Author:      Godman Andrew
 * Author URI:  https://example.com
 */

// Add a custom menu page to display the post links
function sfs_auto_post_to_telegram_menu_page() {
    add_menu_page(
        'Post Links',
        'Post Links',
        'manage_options',
        'sfs_auto_post_to_telegram_links',
        'sfs_auto_post_to_telegram_links_callback'
    );
}
add_action('admin_menu', 'sfs_auto_post_to_telegram_menu_page');

// Callback function to output the post links on the custom menu page
function sfs_auto_post_to_telegram_links_callback() {
    // Query all posts of the custom post type "escort"
    $args = array(
        'post_type' => 'escort',
        'posts_per_page' => -1,
    );

    $loop = new WP_Query($args);

    // Create an array to store the post links
    $postLinks = array();

    if ($loop->have_posts()) {
        while ($loop->have_posts()) {
            $loop->the_post();
            $postLink = get_permalink();
            $postLinks[] = $postLink;
        }
    }

    // Close the loop
    wp_reset_postdata();

    // Output the post links on the page
    echo '<div class="wrap">';
    echo '<h1>Post Links</h1>';
    if (!empty($postLinks)) {
        echo '<ul>';
        foreach ($postLinks as $link) {
            echo '<li>' . $link . '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>No post links found.</p>';
    }
    echo '</div>';
}

// Set up the Telegram bot API credentials
$apiToken = '6025671013:AAERb-CCDQ06VjfsthkSYs7BtmWCuY9Hps0';
$chat_id = '-1036853733382';

// Register a custom cron schedule interval
function sfs_auto_post_to_telegram_register_cron_interval($schedules) {
    $schedules['sfs_5_minutes'] = array(
        'interval' => 300,
        'display' => __('Every 5 minutes'),
    );
    return $schedules;
}
add_filter('cron_schedules', 'sfs_auto_post_to_telegram_register_cron_interval');

// Schedule the Telegram posting event
function sfs_auto_post_to_telegram_schedule_event() {
    if (!wp_next_scheduled('sfs_auto_post_to_telegram_event')) {
        wp_schedule_event(time(), 'sfs_5_minutes', 'sfs_auto_post_to_telegram_event');
    }
}
register_activation_hook(__FILE__, 'sfs_auto_post_to_telegram_schedule_event');

// Unschedule the Telegram posting event
function sfs_auto_post_to_telegram_unschedule_event() {
    wp_clear_scheduled_hook('sfs_auto_post_to_telegram_event');
}
register_deactivation_hook(__FILE__, 'sfs_auto_post_to_telegram_unschedule_event');

// Telegram posting event callback
function sfs_auto_post_to_telegram_event_callback() {
    // Include the necessary WordPress files
    // Check if WordPress is loaded, and if not, load the WordPress environment
    if (!defined('ABSPATH')) {
        /** Set up WordPress environment */
        require_once(dirname(__FILE__) . '/../../../wp-load.php');
    }

    global $apiToken, $chat_id; // Make $apiToken and $chat_id accessible

    // Query all posts of the custom post type "escort"
    $args = array(
        'post_type' => 'escort',
        'posts_per_page' => -1,
    );

    $loop = new WP_Query($args);

    // Create an array to store the post links
    $postLinks = array();

    if ($loop->have_posts()) {
        while ($loop->have_posts()) {
            $loop->the_post();
            $postLink = get_permalink();
            $postLinks[] = $postLink;
        }
    }

    // Close the loop
    wp_reset_postdata();

    // Get the current link index from options
    $currentLinkIndex = get_option('sfs_auto_post_to_telegram_current_link_index', 0);

    // Get the current post link
    $currentLink = $postLinks[$currentLinkIndex];

    // Prepare the message to be sent to Telegram
    $message = sprintf('<a href="%s">%s</a>', $currentLink, $currentLink);

    // Send the message to Telegram using the bot API
    $telegramEndpoint = 'https://api.telegram.org/bot' . $apiToken . '/sendMessage';
    $telegramParams = array(
        'chat_id' => $chat_id,
        'text' => $message,
        'parse_mode' => 'HTML',
    );
    $args = array(
        'method' => 'POST',
        'timeout' => 45,
        'headers' => array(
            'Content-Type: application/json',
        ),
        'body' => json_encode($telegramParams),
    );

    $telegramResponse = wp_remote_post($telegramEndpoint, $args);

    // Move to the next post link
    $currentLinkIndex++;
    if ($currentLinkIndex >= count($postLinks)) {
        $currentLinkIndex = 0;
    }

    // Update the current link index in options
    update_option('sfs_auto_post_to_telegram_current_link_index', $currentLinkIndex);
}
add_action('sfs_auto_post_to_telegram_event', 'sfs_auto_post_to_telegram_event_callback');

// Delete the current link index option on plugin uninstallation
function sfs_auto_post_to_telegram_uninstall() {
    delete_option('sfs_auto_post_to_telegram_current_link_index');
}
register_uninstall_hook(__FILE__, 'sfs_auto_post_to_telegram_uninstall');

Retrieve multiple values from table column with comma separated values using explode in PHP [closed]

I insert data successfully, multiple value using implode() function, but I am not fetched the multiple data from table please help me

Data Value in table column like 28,29,30,31,62

am get only one first id

$services_sql1="select * from footer_servicess where id ='".$pro_bfloors[coures]."'";
$services_query1 = mysqli_query($conn,$services_sql1);
while($coures_subject=mysqli_fetch_array($services_query1)){
    print_r(explode(',',$coures_subject[cont_title],1));
    $coursid = explode(" ",$coures_subject[cont_title]);
    foreach ($coursid as $studentid){
        print_r($studentid);
    }
}

Why do I keep getting errors generating PDF with TCPDF in PHP when handling empty values in the R field?

while ($row = mysqli_fetch_assoc($result)) {
    $html .= '<tr style="font-family: times; color: black; font-size: 0.9em;">';
    $html .= '<td style="width:6%; border: 1px solid black;">' . $row['codeFonctionnel'] . '</td>';
    $html .= '<td style="width:6%; border: 1px solid black;">' . $row['codeEco'] . '</td>';
    $html .= '<td style="width:15%; border: 1px solid black;">' . $row['niveauR'] . '</td>';

    if ($row['niveauR'] == 'DEP') {
        $html .= '<td style="width:15%; border: 1px solid black;">-</td>'; // Print "-" for R
    } elseif ($row['niveauR'] == 'PRG') {
        $rValue = substr($row['R'], 10); // Get R value after 1211010000
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    } elseif ($row['niveauR'] == 'REG') {
        $rValue = substr($row['R'], 16); // Get R value after 1211010000920
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    } elseif ($row['niveauR'] == 'PRJ') {
        $rValue = substr($row['R'], 20); // Get R value after 121101000092000
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    } elseif ($row['niveauR'] == 'LIN') {
        $rValue = substr($row['R'], 22); // Get R value after 12110100009200010
        $html .= '<td style="width:15%; border: 1px solid black;">' . ($rValue ?: '') . '</td>'; // Use ternary operator to handle empty values
    }

    $html .= '<td style="width:43%; border: 1px solid black;">' . $row['lib'] . '</td>';
    $html .= '<td style="width:15%; border: 1px solid black;">' . $row['CP'] . '</td>';
    $html .= '</tr>';
}

this is the error i get :

Fatal error: Uncaught ValueError: max(): Argument #1 ($value) must
contain at least one element in
C:xampphtdocstestcommandetcpdf.php:6412 Stack trace: #0
C:xampphtdocstestcommandetcpdf.php(6412): max(Array) #1
C:xampphtdocstestcommandetcpdf.php(18592): TCPDF->Write(4.7625,
‘xEFxBFxBD’, ”, 0, ”, false, 0, true, true, 0, 0) #2
C:xampphtdocstestcommandetcpdf.php(5930):
TCPDF->writeHTML(‘[]</c…’, true, false, true, true, ”) #3
C:xampphtdocstestcommandetcpdf.php(18372):
TCPDF->MultiCell(81.698987111111, 0, ‘[]</c…’, false, ”,
false, 2, 89.800260666667, 95.927333333333, true, 0, true, true, 0,
‘T’, false) #4 C:xampphtdocstestcommandeexportPDF.php(136):
TCPDF->writeHTML(‘<div style=”tex…’, true, false, true, false, ”)
#5 {main} thrown in C:xampphtdocstestcommandetcpdf.php on line 6412

I added a ternary operator (?:) to handle empty values in the R field.

Removing an image from session on browser

This is my add Function of images Here is my dropzone code :-

public function upload() {
        $lang = $this->request->get_string('id_lang','POST');

        if($lang == "en") {
            $lang = 12;
        } else {
            $lang = 11;         
        }
        include DIR_HELPER_UPLOAD;
        $options = array('max_size' => 2000);
        $upload  = new BncUpload($options);
        $up_img  = $upload->upload($this->idw, 'news', 'img');
        
        if( isset($up_img['status']) ) {
            $res = [
                'status' => false,
                'msg' => 'Upload không thành công !'
            ];
            header('Content-Type: application/json');
            echo json_encode($res);
            exit();
        }
        
        $position = $_GET['position'];
        $position = !in_array( (int)$position, ["1","2"]) ? 1 : (int)$position;

        $slideModel = new Slide();
        $slide = $slideModel->getSlide(['idw' => $this->idw, 'position' => $position])->getOne();

        if($slide == null) {
            
            $slideModel->insertSlide(['idw' => $this->idw, 'title' => 'Slide', 'status' => 1, 'position' => $position]);    
            $slide = $slideModel->getSlide(['idw' => $this->idw, 'position' => $position])->getOne();
        }   
        

        $slideImageModel = new Model('vi_slide_image');

        $dataSlideImage = [
            'idw' => $this->idw,
            'slide_id' => $slide['id'],
            'src_link' => $up_img,
            'status' => 1,
            'id_lang' => $lang,
        ];

        $imageId = $slideImageModel->insert($dataSlideImage);
        
        if($imageId) {
            $res = [
                'status' => true,
                'msg' => 'Upload thành công!',
                'data' => [
                    'id' => $imageId,
                    'url' => $up_img,
                ],
            ];  
        } else {
            $res = [
                'status' => true,
                'msg' => 'Upload thất bại!',
            ];
        }
            

        header('Content-Type: application/json');
        echo json_encode($res);
        exit();
    }

My images are successfully uploaded but i want to remove the image from session as well as from folder can anyone help me how to do that Here is my delete function of image:-

public function deleteContributorImage(Request $request,$name = null){
    $imageName=explode('.',$name);
    $imageRandomName = $request->session()->get('contributorimage.'.$imageName[0].'.image');
    $destination = base_path() . '/public/images/ContributorImages/';
    if(unlink($destination.$imageRandomName)){
        $request->session()->forget('contributorimage.'.$imageName[0]);
        echo "success";
    }
    else{
        echo "failed";
    }
}

How do I change the webpage name from Cafe Billing System to RichiamoHub in my HTML and PHP web application? [closed]

I have a Database System Created using PHPMYADMIN, HTML, PHP, I cant seem to change the webpage name from Cafe Billing System to RichiamoHub. Can someone help me with it? Here is the google drive link to the zip file

https://drive.google.com/file/d/10xbKrorm1VJKAv_Gkr2_cppOBRNwjtTQ/view?usp=sharing

I tried changing the code but it did not work, So im lost atm.

how can I make the links appear after the first heading on the targeted pages?

enter image description here

I have a WordPress site, and I generate links using a function in the function.php file. In the single.php file, I use to display the function on the main section of the targeted pages.

Currently, the links appear after the footer. My question is, how can I make the links appear after the first heading on the targeted pages?

**The function **

function generate_internal_links($pageSlug, $pageTitle, $keywords, $currentPageURL)
{
    $internalLinks = '';

    // Check if the current page URL matches the provided condition
    if ($currentPageURL === $pageSlug) {
        $foundH3 = false; // Flag to track if the first <h3> tag is found
        foreach ($keywords as $keyword) {
            $slug = strtolower($keyword);
            $slug = str_replace(['é', 'è'], 'e', $slug);
            $slug = preg_replace('/[^a-zA-Z0-9]+/', '-', $slug);
            $link = 'https://sg-plombier.be/' . $slug . '/';
            $internalLinks .= '<a href="' . $link . '">' . $keyword . '</a>, ';

            // Check if the <h3> tag is found
            if (!$foundH3 && strpos($keyword, '<h3>') !== false) {
                $foundH3 = true;
                $internalLinks = rtrim($internalLinks, ', ');

                // Apply the function before the first <h3> tag
                $internalLinks = $pageTitle . ': ' . $internalLinks;
            }
        }
        if (!$foundH3) {
            // If no <h3> tag is found, apply the function at the end
            $internalLinks = rtrim($internalLinks, ', ');
            $internalLinks = $pageTitle . ': ' . $internalLinks;
        }
    }

    return $internalLinks;
}


// Get the current page URL
$currentPageURL = $_SERVER['REQUEST_URI'];

// Generate the internal links based on the conditions


$debouchageBruxellesKeywords = [
    'Débouchage Molenbeek',
    'Débouchage Jette',
    'Débouchage Laeken',
    'Débouchage Saint-Gilles',
    'Débouchage Watermael-Boitsfort',
    'Débouchage Berchem-Sainte-Agathe',
    'Débouchage Haren',
    'Débouchage Ganshoren',
    'Débouchage Etterbeek',
    'Débouchage Uccle',
    'Débouchage Schaerbeek',
    'Débouchage Auderghem',
    'Débouchage Anderlecht',
    'Débouchage Forest',
    'Débouchage Saint-Josse',
    'Débouchage Woluwe-Saint-Lambert',
    'Débouchage Neder-Over-Heembeek',
    'Débouchage Evere',
    'Débouchage Koekelberg',
    'Débouchage Ixelles',
];
$debouchageBruxellesLink = generate_internal_links('/debouchage-bruxelles/', 'Débouchage Bruxelles', $debouchageBruxellesKeywords, $currentPageURL);




$debouchageLiegeKeywords = [
    'Débouchage Ans',
    'Débouchage Awans',
    'Débouchage Aywaille',
    'Débouchage Bassenge',
    'Débouchage Beyne-Heusay',
    'Débouchage Blegny',
    'Débouchage Comblain-au-Pont',
    'Débouchage Flémalle',
    'Débouchage Fléron',
    'Débouchage Soumagne',
    'Débouchage Sprimont',
    'Débouchage Chaudfontaine',
    'Débouchage Grâce-Hollogne',
    'Débouchage Herstal',
    'Débouchage Juprelle',
    'Débouchage Neupré',
    'Débouchage Saint-Nicolas',
    'Débouchage Seraing',
    'Débouchage Trooz',
    'Débouchage Visé',
    'Débouchage Dalhem',
    'Débouchage Esneux',
    'Débouchage Oupeye',
];

$debouchageLiegeLink = generate_internal_links('/debouchage-liege/', 'Débouchage Liège', $debouchageLiegeKeywords, $currentPageURL);

$smallCitiesLiegeKeywords = [
    'Débouchage Huy',
    'Débouchage Verviers',
    'Débouchage Waremme',
];

$smallCitiesLiegeLink = generate_internal_links('/debouchage-liege/', 'Débouchage Liège', $smallCitiesLiegeKeywords, $currentPageURL);

$debouchageHuyKeywords = [
     'Débouchage Anthisnes',
    'Débouchage Burdinne',
    'Débouchage Clavier',
    'Débouchage Engis',
    'Débouchage Ferrières',
    'Débouchage Villers-le-Bouillet',
    'Débouchage Hamoir',
    'Débouchage Héron',
    'Débouchage Amay',
    'Débouchage Grâce-Marchin',
    'Débouchage Modave',
    'Débouchage Nandrin',
    'Débouchage Ouffet',
    'Débouchage Tinlot',
    'Débouchage Verlaine',
    'Débouchage Wanze',
];

$debouchageHuyLink = generate_internal_links('/debouchage-huy/', 'Débouchage Huy', $debouchageHuyKeywords, $currentPageURL);

$debouchageVerviersKeywords = [
     'Débouchage Amblève (Amel)',
    'Débouchage Aubel',
    'Débouchage Baelen',
    'Débouchage Bullange',
    'Débouchage Burg-Reuland',
    'Débouchage Butgenbach',
    'Débouchage Dison',
    'Débouchage Saint-Vith',
    'Débouchage Spa',
    'Débouchage Stavelot',
    'Débouchage Stoumont',
    'Débouchage Theux',
    'Débouchage Eupen',
    'Débouchage Herve',
    'Débouchage La Calamine',
    'Débouchage Lierneux',
    'Débouchage Limbourg',
    'Débouchage Lontzen',
    'Débouchage Malmedy',
    'Débouchage Olne',
    'Débouchage Plombières',
    'Débouchage Raeren',
    'Débouchage Pepinster',
    'Débouchage Waimes',
    'Débouchage Thimister-Clermont',
    'Débouchage Trois-Ponts',
    'Débouchage Welkenraedt',
];

$debouchageVerviersLink = generate_internal_links('/debouchage-verviers/', 'Débouchage Verviers', $debouchageVerviersKeywords, $currentPageURL);

$debouchageWaremmeKeywords = [
     'Débouchage Berloz',
    'Débouchage Braives',
    'Débouchage Crisnée',
    'Débouchage Donceel',
    'Débouchage Faimes',
    'Débouchage Fexhe-le-Haut-Clocher',
    'Débouchage Geer',
    'Débouchage Hannut',
    'Débouchage Lincent',
    'Débouchage Oreye',
    'Débouchage Remicourt',
    'Débouchage Wasseiges',
    'Débouchage Saint-Georges-sur-Meuse',
];


$debouchageWaremmeLink = generate_internal_links('/debouchage-waremme/', 'Débouchage Waremme', $debouchageWaremmeKeywords, $currentPageURL);

$debouchageBrabantKeywords = [
    'Débouchage Wavre',
    'Débouchage Beauvechain',
    'Débouchage Braine-lalleud',
    'Débouchage Braine-le-Chateau',
    'Débouchage Chastre',
    'Débouchage Chaumont-Gistoux',
    'Débouchage Court-Saint-Étienne',
    'Débouchage Genappe',
    'Débouchage Grez-Doiceau',
    'Débouchage Rixensart',
    'Débouchage Tubize',
    'Débouchage Villers-la-Ville',
    'Débouchage Walhain',
    'Débouchage Hélécine',
    'Débouchage Incourt',
    'Débouchage Ittre',
    'Débouchage Jodoigne',
    'Débouchage La Hulpe',
    'Débouchage Lasne',
    'Débouchage Mont-Saint-Guibert',
    'Débouchage Nivelles',
    'Débouchage Orp-Jauche',
    'Débouchage Ottignies-Louvain-la-Neuve',
    'Débouchage Perwez',
    'Débouchage Ramillies',
    'Débouchage Rebecq',
    'Débouchage Waterloo',
];

$debouchageBrabantLink = generate_internal_links('/debouchage-brabant-wallon/', 'Débouchage brabant wallon', $debouchageBrabantKeywords, $currentPageURL);


$debouchageNamurKeywords = [
    'Débouchage Andenne',
    'Débouchage Assesse',
    'Débouchage Éghezée',
    'Débouchage Fernelmont',
    'Débouchage Floreffe',
    'Débouchage Fosses-la-Ville',
    'Débouchage Gembloux',
    'Débouchage La Bruyère',
    'Débouchage Ohey',
    'Débouchage Profondeville',
    'Débouchage Sambreville',
    'Débouchage Sombreffe',
    'Débouchage Gesves',
    'Débouchage Mettet',
    'Débouchage Jemeppe-sur-Sambre',    
];

$debouchageNamurLink = generate_internal_links('/debouchage-namur/', 'Débouchage Namur', $debouchageNamurKeywords, $currentPageURL);

$smallCitiesNamurKeywords = [
    'Débouchage Dinant',
    'Débouchage Philippeville',
];

$smallCitiesNamurLink = generate_internal_links('/debouchage-namur/', 'Débouchage Namur', $smallCitiesNamurKeywords, $currentPageURL);

$debouchageDinantKeywords = [
    'Débouchage Beauraing',
    'Débouchage Bièvre',
    'Débouchage Ciney',
    'Débouchage Dinant',
    'Débouchage Gedinne',
    'Débouchage Hamois',
    'Débouchage Havelange',
    'Débouchage Houyet',
    'Débouchage Yvoir',
    'Débouchage Hastière',
    'Débouchage Onhaye',
    'Débouchage Rochefort',
    'Débouchage Somme-Leuze',
    'Débouchage Vresse-sur-Semois',
];

$debouchageDinantLink = generate_internal_links('/debouchage-dinant/', 'Débouchage Dinant', $debouchageDinantKeywords, $currentPageURL);

$debouchagePhilippevilleKeywords = [
    'Débouchage Cerfontaine',
    'Débouchage Couvin',
    'Débouchage Doische',
    'Débouchage Florennes',
    'Débouchage Walcourt',
    'Débouchage Viroinval',
];

$debouchagePhilippevilleLink = generate_internal_links('/debouchage-philippeville/', 'Débouchage Philippeville', $debouchagePhilippevilleKeywords, $currentPageURL);

$debouchageHainautKeywords = [
    'Débouchage Mons',
    'Débouchage Boussu',
    'Débouchage Dour',
    'Débouchage Frameries',
    'Débouchage Jurbise',
    'Débouchage Lens',
    'Débouchage Quaregnon',
    'Débouchage Quévy',
    'Débouchage Quiévrain',
    'Débouchage Saint-Ghislain',
    'Débouchage Hensies',
    'Débouchage Colfontaine',
    'Débouchage Honnelles',
];

$debouchageHainautLink = generate_internal_links('/debouchage-hainaut/', 'Débouchage Hainaut', $debouchageHainautKeywords, $currentPageURL);

$debouchageHainautKeywords = [
    'Débouchage Mons',
    'Débouchage Ath',
    'Débouchage Charleroi',
    'Débouchage La Louvière',
    'Débouchage Soignies',
    'Débouchage Thuin',
    'Débouchage Tournai',
];

$smallCitiesHainautLink = generate_internal_links('/debouchage-hainaut/', 'Débouchage Hainaut', $debouchageHainautKeywords, $currentPageURL);


$debouchageMonsKeywords = [
    'Débouchage Hainaut',
    'Débouchage Boussu',
    'Débouchage Dour',
    'Débouchage Frameries',
    'Débouchage Jurbise',
    'Débouchage Lens',
    'Débouchage Quaregnon',
    'Débouchage Quévy',
    'Débouchage Quiévrain',
    'Débouchage Saint-Ghislain',
    'Débouchage Hensies',
    'Débouchage Colfontaine',
    'Débouchage Honnelles',
];

$debouchageMonsLink = generate_internal_links('/debouchage-mons/', 'Débouchage Mons', $debouchageMonsKeywords, $currentPageURL);

$debouchageAthKeywords = [
    'Débouchage Belœil',
    'Débouchage Bernissart',
    'Débouchage Brugelette',
    'Débouchage Chièvres',
    'Débouchage Enghien',
    'Débouchage Ellezelles',
    'Débouchage Flobecq',
    'Débouchage Frasnes-lez-Anvaing',
    'Débouchage Lessines',
    'Débouchage Silly',
];

$debouchageAthLink = generate_internal_links('/debouchage-ath/', 'Débouchage Ath', $debouchageAthKeywords, $currentPageURL);

$debouchageCharleroiKeywords = [
    'Débouchage Aiseau-Presles',
    'Débouchage Chapelle-lez-Herlaimont',
    'Débouchage Courcelles',
    'Débouchage Fleurus',
    'Débouchage Gerpinnes',
    'Débouchage Les Bons Villers',
    'Débouchage Montigny-le-Tilleul',
    'Débouchage Farciennes',
    'Débouchage Fontaine-l'Évêque',
    'Débouchage Châtelet',
    'Débouchage Pont-à-Celles',
];

$debouchageCharleroiLink = generate_internal_links('/debouchage-charleroi/', 'Débouchage Charleroi', $debouchageCharleroiKeywords, $currentPageURL);

$debouchageLaLouvièreKeywords = [
    'Débouchage Binche',
    'Débouchage Estinnes',
    'Débouchage Morlanwelz',
];

$debouchageLaLouvièreLink = generate_internal_links('/debouchage-la-louviere/', 'Débouchage La Louvière', $debouchageLaLouvièreKeywords, $currentPageURL);


$debouchageSoigniesKeywords = [
    'Débouchage Braine-le-Comte',
    'Débouchage Écaussinnes',
    'Débouchage Le Rœulx',
    'Débouchage Manage',
    'Débouchage Seneffe',
];
$debouchageSoigniesLink = generate_internal_links('/debouchage-soignies/', 'Débouchage Soignies', $debouchageSoigniesKeywords, $currentPageURL);

$debouchageThuinKeywords = [
    'Débouchage Anderlues',
    'Débouchage Beaumont',
    'Débouchage Chimay',
    'Débouchage Erquelinnes',
    'Débouchage Froidchapelle',
    'Débouchage Ham-sur-Heure-Nalinnes',
    'Débouchage Lobbes',
    'Débouchage Merbes-le-Château',
    'Débouchage Momignies',
    'Débouchage Sivry-Rance',
];

$debouchageThuinLink = generate_internal_links('/debouchage-thuin/', 'Débouchage Thuin', $debouchageThuinKeywords, $currentPageURL);

$debouchageTournaiKeywords = [
    'Débouchage Antoing',
    'Débouchage Celles',
    'Débouchage Comines-Warneton',
    'Débouchage Estaimpuis',
    'Débouchage Leuze-en-Hainaut',
    'Débouchage Mont-de-l'Enclus',
    'Débouchage Mouscron',
    'Débouchage Pecq',
    'Débouchage Péruwelz',
    'Débouchage Rumes',
];

$debouchageTournaiLink = generate_internal_links('/debouchage-tournai/', 'Débouchage Tournai', $debouchageTournaiKeywords, $currentPageURL);



// Output the generated links
function display_internal_links() {
    $output = '';
    global $debouchageLiegeLink, $smallCitiesLiegeLink, $debouchageHuyLink, $debouchageVerviersLink, $debouchageWaremmeLink, $debouchageBruxellesLink, $debouchageBrabantLink, $debouchageNamurLink, $smallCitiesNamurLink, $debouchageDinantLink, $debouchagePhilippevilleLink, $debouchageHainautLink, $smallCitiesHainautLink, $debouchageMonsLink, $debouchageAthLink, $debouchageCharleroiLink, $debouchageLaLouvièreLink, $debouchageSoigniesLink, $debouchageThuinLink, $debouchageTournaiLink;
    
    if (!empty($debouchageLiegeLink)) {
        $output .= $debouchageLiegeLink;
    }
    
    if (!empty($smallCitiesLiegeLink)) {
        $output .= $smallCitiesLiegeLink;
    }
    
    if (!empty($debouchageHuyLink)) {
        $output .= $debouchageHuyLink;
    }
    
    if (!empty($debouchageVerviersLink)) {
        $output .= $debouchageVerviersLink;
    }
    
    if (!empty($debouchageWaremmeLink)) {
        $output .= $debouchageWaremmeLink;
    }
      if (!empty($debouchageBruxellesLink)) {
        $output .= $debouchageBruxellesLink;
    }
    
    if (!empty($debouchageBrabantLink)) {
        $output .= $debouchageBrabantLink;
    }
    
    if (!empty($debouchageNamurLink)) {
        $output .= $debouchageNamurLink;
    }
    if (!empty($smallCitiesNamurLink)) {
        $output .= $smallCitiesNamurLink;
    }
    
      if (!empty($debouchageDinantLink)) {
        $output .= $debouchageDinantLink;
    }
     if (!empty($debouchagePhilippevilleLink)) {
        $output .= $debouchagePhilippevilleLink;
    }
     if (!empty($debouchageHainautLink)) {
        $output .= $debouchageHainautLink;
    }
      
   if (!empty($smallCitiesHainautLink)) {
        $output .= $smallCitiesHainautLink;
    }
      if (!empty($debouchageMonsLink)) {
        $output .= $debouchageMonsLink;
    }
    if (!empty($debouchageAthLink)) {
        $output .= $debouchageAthLink;
    }
    
     if (!empty($debouchageCharleroiLink)) {
        $output .= $debouchageCharleroiLink;
    }
    
     if (!empty($debouchageLaLouvièreLink)) {
        $output .= $debouchageLaLouvièreLink;
    }
    
     if (!empty($debouchageSoigniesLink)) {
        $output .= $debouchageSoigniesLink;
    }
    
    if (!empty($debouchageThuinLink)) {
        $output .= $debouchageThuinLink;
    }
    
    if (!empty($debouchageTournaiLink)) {
        $output .= $debouchageTournaiLink;
    }
    
    return $output;
}

how can I make the links appear after the first heading on the targeted pages?

Installing php8.2-pgsql in Codespaces doesn’t work first time and workaround to solve it. Should I have done something different?

I’m using Codespaces to develop my project but for some reason I’ve had a lot of problems to install the pdo_pgsql driver to use Postgress with my symfony project.

Finally, I’ve found a solution that I’ve already applied in different codespaces and it works… but I don’t understand why it happens and if I’m really doing something wrong.

Here is a little howto of how I install the driver, at what point it gives error, and how I solve it…
I hope that we can find out if I did something wrong or that we can help anyone else in my situation:

  1. Installing the php postgress driver in codespaces
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install php8.2-pgsql
  1. Now we need to activate the extension in the php.ini, let’s see php where the file is:
$ php --ini
  1. Edit the php.ini file and uncomment the line
extension=pdo_pgsql
  1. Now to check that the library is active we can run:
$ php -m | grep pdo_pgsql
$ php -i | grep pgsql
  1. But in codespaces, for some unknown reason the library is not where PHP expects to find it… and in both cases it returns the following warning:
    PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql (/opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql: cannot open shared object file: No such file or directory), /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql.so (/opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/pdo_pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
  1. So we have to find where the library is installed and put it where PHP expects it to be:
    (be careful that paths can change… look at PHP’s warning where it expects it to be, and at the result of find to find it).
$ find / -name "pdo_pgsql.so" 2>/dev/null
$ cp /usr/lib/php/20220829/pdo_pgsql.so /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/
$ chmod +wx /opt/php/8.2.5/lib/php/extensions/no-debug-non-zts-20220829/*
  1. Now if we check again if it has worked, the warning has disappeared and PHP detects the library correctly:
$ php -m | grep pdo_pgsql
$ php -i | grep pgsql

How can I efficiently pass JSON data from a PostgreSQL jsonb field to Javascript?

I am looking for a smart solution to process some JSON data from a postgresql database in Javascript. I understand that I need to read the database via php and pass the data as an array to Javascript.

Normaly you would do something like this:

<?php
$phpArray = array('apple', 'banana', 'orange');
$jsonString = json_encode($phpArray);
?>

<script>
var jsonString = '<?php echo $jsonString ?>';
var jsArray = JSON.parse(jsonString);
</script>

But my data is already stored in JSON format in a postgresql jsonb field. So I hope there is a way to pass the array more effectively so the PC doesn’t have to iterate the same data twice.

root@monitor:~ $ sudo -u postgres psql
postgres=# c monitor
monitor=# SELECT * FROM "drone001";

id |                                             data
---+-----------------------------------------------------------------------------------------------
 1 | {"RX": 13.7, "Speed": 10.1, "Azimuth": 897, "Heading": 125, "DateTime": "2023-03-19 04:14:49"}
 2 | {"RX": 13.4, "Speed": 10.2, "Azimuth": 896, "Heading": 125, "DateTime": "2023-03-19 04:14:47"}
 3 | {"RX": 13.3, "Speed": 10.1, "Azimuth": 896, "Heading": 125, "DateTime": "2023-03-19 04:14:45"}
 4 | {"RX": 13.7, "Speed": 10.1, "Azimuth": 896, "Heading": 127, "DateTime": "2023-03-19 04:14:43"}
 5 | {"RX": 13.1, "Speed": 10.1, "Azimuth": 896, "Heading": 125, "DateTime": "2023-03-19 04:14:41"}
[...]

this code does not work, but should show approximately what I have in mind.

<?php
  require_once 'pgsql.php';

  $db = new database();
  $res = $db->select('drone001');
  $jsondata = array();
  while ($ds = pg_fetch_object($res)) {
    $jsondata[] = $ds->data;
  }
?>


<script type="text/javascript">
  var jsArray = JSON.parse('<?php echo $jsondata ?>');
  console.log(jsArray);
</script>

It would be nice if someone could point me in the right direction.

Laravel architecture for API, admin and web

I have to develop a backend for e-commerce application in laravel

  1. create APIs for mobile application.
  2. Create an admin panel to track the application overall
  3. Create a web front end

Now suppose i have to work on Orders section in this case what should be my approach

  1. Controllers/Api/OrderController for mobile API
  2. Controllers/Admin/OrderController for Admin Panel
  3. Controllers/Web/OrderController for web frontend

Or create a single OrderController and identify that request coming from which application and generate response accordingly

What approach should i use. Please tell me with your experience for designing software.

Passing optional custom parameter with Laravel (Monolog) logging

I have a Laravel project. I would like to pass an optional custom parameter (domain ID) when creating log entries. I am logging to a MySQL database via a custom Monolog event handler, based on this tutorial:.

I have searched but cannot find any solutions for what appears to be a relatively simple problem, there’s a number of posts discussing things like adding user ID but none consider a simple optional parameter. Any help would be much appreciated!

Laravel: 8.27
PHP: 8.0.2

As per the tutorial, I have configured a custom handler and I can see how to use session variables or similar for customer

As per the tutorial, I have this custom handler:

namespace AppLogging;
use DB;
use IlluminateSupportFacadesAuth;
use MonologLogger;
use MonologHandlerAbstractProcessingHandler;
class MySQLLoggingHandler extends AbstractProcessingHandler{

    public function __construct($level = Logger::DEBUG, $bubble = true) {
        parent::__construct($level, $bubble);
    }
    protected function write(array $record):void
    {
        $remote_addr = '127.0.0.1';
        if (isset( $_SERVER['REMOTE_ADDR'])) {$remote_addr = $_SERVER['REMOTE_ADDR'];}
        $user_agent = 'Unknown';
        if (isset( $_SERVER['HTTP_USER_AGENT'])) {$user_agent = $_SERVER['HTTP_USER_AGENT'];}
        $data = array(
            'message'       => $record['message'],
            'context'       => json_encode($record['context']),
            'level'         => $record['level'],
            'level_name'    => $record['level_name'],
            'channel'       => $record['channel'],
            'record_datetime' => $record['datetime']->format('Y-m-d H:i:s'),
            'extra'         => json_encode($record['extra']),
            'formatted'     => $record['formatted'],
            'remote_addr'   => $remote_addr,
            'user_agent'    => $user_agent,
            'created_at'    => date("Y-m-d H:i:s"),
        );
        DB::connection()->table('log_entries')->insert($data);
    }
}

And the custom logger class that uses it:

namespace AppLogging;
use MonologLogger;
class MySQLCustomLogger{
    /**
     * Custom Monolog instance.
     */
    public function __invoke(array $config){
        $logger = new Logger("MySQLLoggingHandler");
        return $logger->pushHandler(new MySQLLoggingHandler());
    }
}

The above works great for pushing logs to the database like this:

Log::info("New record created for domain id".$domain_id);

Unfortunately this makes searching the database painful when looking for enties for a specific ID, I was hoping to be able to add an option parameter like this:

Log::info("New record created for domain", $domain_id);

Why does the Filename Change when passed in Model ‘file:///C:/xampp/tmp/phpE19D.tmp’ – CodeIgniter 4.3.5

Im trying to save multiple image files but after uploading the 1st image, the 2nd image is saved as
Filename: 1685437485_6dff28534eb1268da6eb.jpg(String) but when its being passed in the Model it accepts file:///C:/xampp/tmp/phpE19D.tmp (File Object)

$moveFile = $userVehicle['orcr']->store('img');
$move_status = $userVehicle['orcr']->hasMoved();
$data = new File($moveFile);
$userVehicle['orcr'] = $data->getFilename();
$vehicle_status = $this->addModel->saveVehicle();

This is my code

public function addClient()
    {
        $userdata = [
            'firstname' => $this->request->getPost("firstname"),
            'lastname' => $this->request->getPost("lastname"),
            'middlename' => $this->request->getPost("middlename"),
            'addr_1' => $this->request->getPost("address-1"),
            'addr_2' => $this->request->getPost("address-2"),
            'idNum' => $this->request->getPost("idNum"),
            'dept' => $this->request->getPost('department'),
            'img' => $this->request->getFile('personalPic'),
        ];
        $userVehicle = [
            'plateNum' => $this->request->getPost("plateNum"),
            'year' => $this->request->getPost("yearModel"),
            'make' => $this->request->getPost("make"),
            'model' => $this->request->getPost('model'),
            'color' => $this->request->getPost("color"),
            'orcr' => $this->request->getFile('orcr'),
        ];
        $post = $this->request->is('post');
        $session_active = $this->session->has('logged-in');
        $check_personalInfo = $this->validation->run($userdata, 'add_rules_personal');
        $check_vehicleInfo = $this->validation->run($userVehicle, 'add_rules_vehicle');
        //check if form method is post, check if user and vehicle are filled out
        if ($post && $check_personalInfo && $session_active && $check_vehicleInfo) {
            //move file to WRITEPATH/uploads/img
            $moveFile = $userdata['img']->store('img',);
            $move_status = $userdata['img']->hasMoved();
            $data = new File($moveFile);
            //get random generated filename then overwrite userdata['img'] then pass it to model
            $userdata['img'] = $data->getFilename();
            $this->addModel->setUserInfo($userdata, $userVehicle);
            $personal_status = $this->addModel->savePersonal();
            //check if personal info was saved
            if ($personal_status && $move_status){
                //input save for vehicle info 
                $moveFile = $userVehicle['orcr']->store('img');
                $move_status = $userVehicle['orcr']->hasMoved();
                $data = new File($moveFile);
                $userVehicle['orcr'] = $data->getFilename();
                $vehicle_status = $this->addModel->saveVehicle();

I tried using both getFilename() and GetBasename() but same result