Contact Form 7 country list - wordpress

I want Get Current country(Find by IP) in cf 7 dropdown.
Below I find the country by IP:
function wpcf7_custom_date_shortcode_handler($mycountry) {
$myipd = get_client_ip();
$url = 'http://www.geoplugin.net/json.gp?ip='.$myipd;
$details = ip_details($url);
$v = json_decode($details);
$mycountry = $v->geoplugin_countryName;
return $mycountry;
}
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
function ip_details($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Below the contact form 7 form tag:
Country[select* countrylist id:Country "Please Select a Country" "United States|USA" "Afghanistan|AFG" "Albania|ALB" "Algeria|DZA" "American Samoa|ASM" ........ ] (Note: ..... means list all countries defined)

you can use this plugin to achieve user tracking details in form email. Lead info with country for Contact Form 7

Related

WooCommerce Get All Shiping Method Calculated API

I am trying to create an API functions for mobile to get shipping methods from WordPress WooCommerce. This is my code:
public function get_shipping($request){
$params = (array) json_decode(file_get_contents('php://input'), TRUE);
$state = $params['state'];
$country = $params['country'];
global $woocommerce;
$woocommerce->cart->empty_cart();
foreach ($params['line_items'] as $item) {
if((int) $item["variation_id"] > 0 ){
$woocommerce->cart->add_to_cart(
(int) $item["id"],
(int) $item["quantity"],
$item["variation_id"]);
} else {
$woocommerce->cart->add_to_cart(
(int) $item["id"],
(int) $item["quantity"]);
}
}
$package = $woocommerce->cart->get_shipping_packages();
$delivery_zones = (Array) WC_Shipping_Zones::get_zones();
$new_delivery_zones = Array();
foreach ($delivery_zones as $zone) {
$z_object = (Array) $zone;
$new_shippings = Array();
foreach ($z_object["shipping_methods"] as $shipping) {
$s_item = Array();
$objects = (Array) $shipping;
foreach ($objects as $key => $value) {
if($key != "instance_form_fields") {
$s_item[$key] = $value;
}else{
$f_item = Array();
$new_form_fields = Array();
$form_fields = (Array) $value;
foreach ($form_fields as $keyi => $valuei) {
$valuei["name"] = $keyi;
$f_item[$keyi] = $valuei;
array_push($new_form_fields, $valuei);
}
$s_item["instance_form_fields"] = $new_form_fields;
}
}
array_push($new_shippings, $s_item);
}
$z_object["shipping_methods"] = null;
$z_object["shipping_methods"] = $new_shippings;
array_push($new_delivery_zones, $z_object);
}
$correct_zone = null;
foreach ($new_delivery_zones as $zone) {
foreach ($zone["zone_locations"] as $location) {
$splits = explode(":",$location-> code);
if(count($splits) > 1){
$country = $splits[0];
$code = $splits[1];
if($country == $country && $code == $state ){
$correct_zone = $zone;
}
}
}
}
if($correct_zone == null)
return $correct_zone;
$package['destination']['country'] = $country;
$package['destination']['state'] = (int) $state;
$package['destination']['country'] = $country;
$new_shipping_method = Array();
foreach ($correct_zone["shipping_methods"] as $shipping_method) {
if (class_exists($shipping_method["id"])) {
$class = new $shipping_method["id"]();
$class->calculate_shipping_for_package($package);
foreach ($class->rates as $rate) {
array_push($shipping_method["rates"], Array(
"cost" => $rate->cost,
"label" => $rate->label,
"method_id" => $rate->method_id
));
}
// error_log(print_r($class->rates, true));
array_push($new_shipping_method, $shipping_method);
}else{
array_push($new_shipping_method, $shipping_method);
}
}
$correct_zone["shipping_methods"] = $new_shipping_method;
return $correct_zone;
}
and I'm reading this post
BUT I did not understand where the problem is, Because it does not work properly and its calculated prices do not match post plugins.
Please Please Please give me the correct code
thank you very much

Invalid parameter: token 1 is not defined in the query

Here is my code to filter pets base on a JSON ajax Query
I am getting error follwoing image
public function filter($object, $active=true){
$query = $this->createQueryBuilder('p');
$query->innerjoin('TadpetProfessionalBundle:ProPet', 'pp', 'WITH', 'pp.professionalId = p.id');
$query->innerjoin('TadpetManagerBundle:Pet', 'ppp', 'WITH', 'ppp.id = pp.petId');
$query->where('p.isActive = :active')
->setParameter('active', $active);
if(!empty($object->pets)){
$qString = "";
for($i=1; $i<=sizeof($object->pets); $i++){
if($i == 1){
$qString .= "ppp.name = :petname".$i;
}else{
$qString .= " OR ppp.name = :petname".$i;
}
}
$query->andWhere($qString);
$query->setParameter('petname'+1,$object->pets[0]);
$query->setParameter('petname'+2,$object->pets[1]);
$query->setParameter('petname'+3,$object->pets[2]);
}
return $query->getQuery()->getResult();
}
Help me please
In these lines:
$query->setParameter('petname'+1,$object->pets[0]);
$query->setParameter('petname'+2,$object->pets[1]);
$query->setParameter('petname'+3,$object->pets[2]);
You are adding 'petname' to the numbers, but you should concatenate them:
$query->setParameter('petname'.1,$object->pets[0]);
$query->setParameter('petname'.2,$object->pets[1]);
$query->setParameter('petname'.3,$object->pets[2]);
Also, you could use a loop:
for($i=1; $i<=sizeof($object->pets); $i++){
$query->setParameter('petname'.$i,$object->pets[$i-1]);
}

Locking Telegram Custom Keyboard Buttons for Multiple Inputs

I am trying to lock the keys in the custom keyboard so the user can tap multiple buttons in the custom keyboard before sending the message. The default is you tap a custom keyboard button and message is sent, like with trivia bot. Any ideas on how to do this or if it is even possible?
If I understood right, what you want to do is multiselect (checkbox); there is no such function in telegram, but you can implement it a bit differently.
First, you send message with inline buttons and empty checkboxes with some text:
switch ($callback_query){
case 'choose':
$inline_keyboard = [
[
['text'=>'☐ 1', 'callback_data'=>"n1"],
['text'=>'☐ 2', 'callback_data'=>"n2"],
['text'=>'☐ 3', 'callback_data'=>"n3"]
],
[
['text'=>'☐ 4', 'callback_data'=>"n4"],
['text'=>'☐ 5', 'callback_data'=>"n5"]
],
[
['text'=>'Next', 'callback_data'=>"$someData"]
]
];
$keyboard=["inline_keyboard"=>$inline_keyboard];
$replyMarkup = json_encode($keyboard);
sendMessage($chat_id_callback, "Lorem ipsum dolor sit amet.", $replyMarkup);
break;
// When user is clicking on the buttons You process it with another case with all possible buttons in it and using telegram api to editMessageReplyMarkup
case "n1":
case "1":
case "n2":
case "2":
case "n3":
case "3":
case "n4":
case "4":
case "n5":
case "5":
$empty_checkbox = "☐";
$galochka = "✔";
if (substr($data,0,1)== "n"){
$is_checked = TRUE;
} else {
$is_checked = FALSE;
}
if ($is_checked){
$what_is_checked = substr($data, 1);;
} else {
$what_is_checked = $data;
}
// $output is variable, in wich telegram data is stored, which came through webhook
$text1 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][0]['text'];
$text2 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][1]['text'];
$text3 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][2]['text'];
$text4 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][0]['text'];
$text5 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][1]['text'];
$room_callback_data1 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][0]['callback_data'];
$room_callback_data2 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][1]['callback_data'];
$room_callback_data3 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][2]['callback_data'];
$room_callback_data4 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][0]['callback_data'];
$room_callback_data5 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][1]['callback_data'];
if ($what_is_checked == "1"){
if ($is_checked == TRUE) {
$text1 = $galochka . " 1";
$room_callback_data1 = "1";
} else {
$text1 = $empty_checkbox . " 1";
$room_callback_data1 = 'n2';
}
} elseif ($what_is_checked == "2"){
if ($is_checked == TRUE) {
$text2 = $galochka . " 2";
$room_callback_data2 = "2";
} else {
$text2 = $empty_checkbox . " 2";
$room_callback_data2 = 'n2';
}
} elseif ($what_is_checked == "3"){
if ($is_checked == TRUE) {
$text3 = $galochka . " 3";
$room_callback_data3 = "3";
} else {
$text3 = $empty_checkbox . " 3";
$room_callback_data3 = 'n3';
}
} elseif ($what_is_checked == "4"){
if ($is_checked == TRUE) {
$text4 = $galochka . " 4";
$room_callback_data4 = "4";
} else {
$text4 = $empty_checkbox . " 4";
$room_callback_data4 = 'n4';
}
} elseif ($what_is_checked == "5"){
if ($is_checked == TRUE){
$text5 = $galochka . " 5";
$room_callback_data5 = "5";
} else {
$text5 = $empty_checkbox . " 5";
$room_callback_data5 = 'n5';
}
}
$inline_keyboard = [
[
['text'=>$text1, 'callback_data'=>$room_callback_data1],
['text'=>$text2, 'callback_data'=>$room_callback_data2],
['text'=>$text3, 'callback_data'=>$room_callback_data3]
],
[
['text'=>$text4, 'callback_data'=>$room_callback_data4],
['text'=>$text5, 'callback_data'=>$room_callback_data5]
],
[
['text'=>'Next', 'callback_data'=>"remont"]
]
];
$keyboard=["inline_keyboard"=>$inline_keyboard];
$replyMarkup = json_encode($keyboard);
editMessageReplyMarkup($chat_id_callback, $message_id, $replyMarkup);
break;
}
In the second case, you are just checking which button was pressed and simply change empty box on check mark.
Also, you need to use answerCallbackQuery, to work properly:
function send_answerCallbackQuery($callback_query_id, $text ='', $alert = 0){
file_get_contents($GLOBALS['api']."/answerCallbackQuery?callback_query_id=".$callback_query_id . '&text=' . $text . '&show_alert=' . $alert);
}
if (isset($output['callback_query'])) {
send_answerCallbackQuery($output['callback_query']['id']);
}
It's a default behavior to preserve custom keyboard unless you set one_time_keyboard = True or return a ReplyKeyboardHide to a user.
See docs: https://core.telegram.org/bots/api#replykeyboardmarkup
Also you can send the same keyboard in a reply message every time you want to make sure the keyboard is displayed.

Google geocoding using v3 not showing error

Kindly help on the code below. What happens is that I get the latitude and longitude of the name of a place when I click on a button. However, of late, it is not working. It prints that "Address x failed to Geocode. Received status " Note that x is a given address and no status code is given.
$id=$_REQUEST['id'];
define("MAPS_HOST", "maps.googleapis.com");
define("KEY", "xxxxxxx");
$query = "SELECT * FROM markers WHERE mid = $id LIMIT 1";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?address=";
if($row = #mysql_fetch_assoc($result)){
$geocode_pending = true;
$address = $row["address"];
while ($geocode_pending) {
$request_url = $base_url . urlencode($address) . "&sensor=false&key=" . KEY;
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
//$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
//$lat = $coordinatesSplit[1];
//$lng = $coordinatesSplit[0];
list($lat,$lng) = explode(",",$coordinates);
$query = sprintf("UPDATE markers " .
" SET lat = '%s', lng = '%s' " .
" WHERE mid = '%s' LIMIT 1;",
mysql_real_escape_string($lng),
mysql_real_escape_string($lat),
mysql_real_escape_string($id));
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}else{
echo "$lat;$lng";
}
} else if (strcmp($status, "620") == 0) {
// sent geocodes too fast
$delay += 100000;
} else {
// failure to geocode
$geocode_pending = false;
echo "Address " . $address . " failed to geocode. ";
echo "Received status " . $status . "
\n";
}
usleep($delay);
}
}
I'm not sure on which API your code is based on, but the response of the current API will not work with these lines:
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
There are no elements Response,Status or code, furthermore the response will not contain a numeric status-code.
use this instead:
$status = $xml->status;
if (strcmp($status, "OK") == 0) {
To fix the rest of the code please take a look at the structure of the returned XML, there are also no elements Placemark,Point and coordinates.
it should be:
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;

Counts and left join not working right

Trying to do a count on these lines COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
but it keeps returning the same numbers for all three. So I'm trying to add a Where for each one, Example Count(isContractor where isContractor = 'yes') as contractorCount but getting errors please help, thank you.
<?php
clASs EfficiencyController extends DooController
{
function getEfficiency(){
include './protected/config/db.conf.php';
Doo::db()->setDb($dbconfig, 'local_network');
$Vendor = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['Vendor'] : $_GET['Vendor'];
$date = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['date'] : $_GET['date'];
$level = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['level'] : $_GET['level'];
switch($level) {
case "Region":
case "area":
$Market99="";
break;
default:
$Market99=$level;
break;
}
{
//
// LUCENT,NORTEL
//
$query = " SELECT
DayKey,
Market99,
Region,
areaName,
Sum(Total_Sites) as totalCount,
Max(engineerCount) AS engineerCount,
Max(managerCount) AS managerCount,
Max(contractorCount) AS contractorCount,
SC_Type,
Sum(Total_Carriers),
Sum(Total_Sectors),
Vendor
FROM
network.envEquipSummaryConfig a
Left Join
(SELECT
market,
areaName,
COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
FROM
employee.employees
GROUP BY market
ORDER BY COUNT(market) DESC) b ON a.Market99 = b.market
Where
a.DayKey <= \"$date\" and a.Vendor = \"$Vendor\"
Group By Market99 asc";
switch($level) {
case "region":
$query = $query. " order by region ASC";
break;
case "area":
$query = $query. " order by areaName ASC";
break;
default;
$query = $query. " order by Market99 ASC";
break;
}
}
//echo $query; exit;
$this->setContentType('xml');
$result = Doo::db()->fetchAll($query);
printf("<root>\n");
if(count($result) > 0)
foreach($result AS $row) {
printf("\t<data>\n");
printf("\t\t<date>%s</date>\n",$row["DayKey"]);
printf("\t\t<vName>%s</vName>\n",$row["Vendor"]);
printf("\t\t<location>%s</location>\n",$row["Market99"]);
printf("\t\t<toCount>%s</toCount>\n",$row["totalCount"]);
printf("\t\t<enCount>%s</enCount>\n",$row["engineerCount"]);
printf("\t\t<mnCount>%s</mnCount>\n",$row["managerCount"]);
printf("\t\t<cnCount>%s</cnCount>\n",$row["contractorCount"]);
printf("\t</data>\n");
}
printf("</root>\n");
}
}
?>
SELECT
market,
areaName,
COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
FROM
employee.employees
GROUP BY market
should be
Group By market,areaName at a guess.
Which is all it can be seeing as you've provided next to no useful information.

Resources