LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Tuesday, July 25, 2023

Automating WhatsApp Number Updates in Koha ILS

0 comments
In this blog post, we will explore a PHP script that automates the process of adding and updating WhatsApp numbers for borrowers in a Koha library management system. Integrating WhatsApp numbers into the borrowers' information by the library users themself can provide an additional means of communication and enhance user engagement.

WhatsApp Number Validation

The first step in the process is to validate the provided WhatsApp number. The PHP script uses a regular expression to check if the number consists of ten digits, as WhatsApp numbers typically do. This validation helps ensure that only valid numbers are accepted and entered into the database.

If the provided number is invalid, the script displays an error message to the user and redirects them back to the index page, prompting them to re-enter the correct WhatsApp number.

Querying the Database

Once the provided WhatsApp number is validated, the script executes an SQL SELECT query to verify whether the borrower's card number exists in the "borrowers" table of the Koha database. This step is crucial to prevent adding duplicate entries for borrowers with multiple WhatsApp numbers.

Updating the WhatsApp Number

If the card number exists in the database and the user-provided WhatsApp number differs from the existing entry (if any), the script proceeds to update the "phone" column using an SQL UPDATE query. This ensures that borrowers have their latest WhatsApp numbers recorded in the database.

User Feedback and Security

The script provides informative feedback to the user after attempting to update the WhatsApp number. If the number was successfully updated, the user is informed accordingly. Similarly, if the number remained unchanged due to an existing entry with the same WhatsApp number, the user is notified.

Security is emphasized throughout the script. Data sanitization and validation are implemented to prevent potential SQL injection attacks and ensure that only valid data is entered into the database. The use of prepared statements and parameterized queries helps safeguard against common security vulnerabilities.

Installation and Setup

Step 1: Install required packages

Open a terminal and run the following command to install Apache2, PHP, and other necessary packages:

sudo apt update
sudo apt install apache2 apache2-utils software-properties-common libapache2-mod-php php-{bcmath,bz2,intl,gd,mbstring,mysql,zip,cli,fpm,opcache,xml,curl,intl,xsl,soap,json,apcu,imap,xmlrpc} git

Step 2: Clone the application

Navigate to the default web directory and clone the application repository from GitHub:

cd /usr/share/koha/opac/htdocs
sudo git clone https://github.com/maheshpalamuttath/wa.git

Step 3: Set appropriate permissions

Change the permissions of the cloned directory to make sure the web server can access it:

sudo chmod 755 -R wa
sudo chown www-data:www-data -R wa

Step 4: Configure the application

Please make sure to replace the placeholders in the update_phone.php file with your actual Koha database credentials: 

sudo vim /usr/share/koha/opac/htdocs/wa/update_phone.php


How to get user credentials ?

To retrieve the user credentials for your Koha library, assuming your instance name is "library," follow these steps:

  • Koha Database Name: koha_library
  • Koha Database Username: koha_library
  • The Koha Database Password will be automatically generated during the Koha installation process. To find the password, execute the command below:

sudo koha-passwd library

Step 5: Enable Apache Modules

Enable the necessary Apache modules:

sudo a2enmod php
sudo a2enmod rewrite

Step 6: Restart Apache

Restart the Apache web server to apply the changes:

sudo systemctl reload apache2 && sudo systemctl restart apache2

Step 7: Access the application

Now, you should be able to access the application through your web browser. Open the following URL:



Please note that if you are accessing the server remotely, replace localhost with the server's IP address or domain name.

Video Reference:

No comments:

Post a Comment