Jump to content

hook file help for provisioning module


sokalsondha

Recommended Posts

dear community member..

hope all doing very well. i am trying to make a module for my VoIP project . one of my friend helping me out in this module. but i dont know what he done something is he can't figure out how to fix.

basically its for VoIP project. so we will sell voip service with local city number. so when the ordering time  we will select the city and then based on the city name the available numbers will be display..

so for the list of city the api link is

https://mydomainname.com/api/city_list.php?&token=123456

this api link display all the city name from remote database

image.png.eae04e4bcece1e4ed601b57c54690644.png

so thats i want it to show in one custom field

and for the second custom field based on the city name i have another api link which is

https://mydomainname.com/api/did_free.php?city=Dublin&token=123456

which shows result this way

image.png.5709278afcf2a53d0d09e8e8b96e5250.png

its only shows the number is dublin city from the remote database.

my friend make the module for me. but the way i want its show very right in the customer order form . i mean if customer directly buy from the client area its shows perfect according to city name

so when i select the city then i see available numbers based on the city which the way i wanted to see from the client area. so from the client area its works properly no problem.

problem with from the admin area

when i wanted to setup a product to client from admin in the admin panel i see like this

image.png.229b8b863866da17aea962989cd491d8.png

which means its doesn't matter which city i select. but i see all numbers from my remote database.

like 35391 is Galway numbers 35314 is Dublin Numbers and 35321 is Cork numbers. they are all showing together. which is very frustrating .

here is my hook file code. can some please please tell me where he did wrong?

HOOK FILE CODE

========================================

<?php
use PDO;
use Exception;
use PDOException;
use WHMCS\Database\Capsule;
$host = 'https://mydomainname.com/api/';
    $token = '123456';

    $ch = curl_init();
    $fields = array(
        'token' => $token
    );
    curl_setopt($ch, CURLOPT_URL, $host.'city_list.php?'.http_build_query($fields));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $city = curl_exec($ch);
    curl_close($ch);
    $packageNames = json_decode($city, true);  

    $citylist = array();
    $numberslist = array();
    foreach ($packageNames['result'] as $packageName) {
        $citylist[$packageName['city']] = ucfirst($packageName['city']);
        $ch = curl_init();
        $fields = array(
            'city' => $packageName['city'],
            'token' => $token
        );
        curl_setopt($ch, CURLOPT_URL, $host.'did_free.php?'.http_build_query($fields));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $numbers = curl_exec($ch);
        $numbers = json_decode($numbers);
        $numberslist = array_merge($numbers->result,$numberslist);
        curl_close($ch);
    }
    
    
    $citylist = implode($citylist,',');
    $numberslist = implode($numberslist,',');
    //echo json_encode(array('cities'=>explode(",",$citylist),'numbers'=>explode(",",$numberslist)));
    $pdo = Capsule::connection()->getPdo();
    try {
        $result = $pdo->query(
            "update tblcustomfields set fieldoptions = '".$citylist."' where fieldname = 'City'"
        );

    } catch (\Exception $e) {
        echo "Uh oh! {$e->getMessage()}";
        return $e->getMessage();
    }

    try {
        $result = $pdo->query(
            "update tblcustomfields set fieldoptions = '".$numberslist."' where fieldname = 'Available Phone Numbers'"
        );

    } catch (\Exception $e) {
        echo "Uh oh! {$e->getMessage()}";
        return $e->getMessage();
    }
    
add_hook('OverrideModuleUsernameGeneration', 1, function($vars) {
    
    return $vars['customfields']['Available Phone Numbers'];
});
   

=============================================================

please someone help me to correct the code.

please

 

Edited by sokalsondha
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated