Changeset 3180204
- Timestamp:
- 11/01/2024 11:52:17 PM (5 months ago)
- Location:
- wp-easy-crm
- Files:
-
- 41 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-easy-crm/trunk/easy-crm.php
r3137153 r3180204 4 4 * Plugin Name: Easy CRM 5 5 * Description: Collect new leads, manage clients, quotations, invoices, tasks and more for your entire team 6 * Version: 1.0.2 46 * Version: 1.0.25 7 7 * Author: IT-iCO SRL 8 8 * Author URI: https://it-ico.com -
wp-easy-crm/trunk/readme.txt
r3137153 r3180204 3 3 Donate link: https://www.paypal.com/donate/?hosted_button_id=73ZZVYDUTMHME 4 4 Requires at least: 5.9 5 Tested up to: 6.6. 16 Stable tag: 1.0.2 45 Tested up to: 6.6.2 6 Stable tag: 1.0.25 7 7 Contributors: sunnysonic 8 8 License: GPLv2 or later … … 60 60 61 61 == Changelog == 62 63 = 1.0.25 = 64 * button to open contact in whatsapp added on client list and client profile with edit option 65 * tested with wordpress 6.2 62 66 63 67 = 1.0.24 = -
wp-easy-crm/trunk/views/clientProfile.php
r3137153 r3180204 161 161 } 162 162 163 ?> <b><?php _e( 'Contact(s):', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['nombrecontacto']) ?> <b>Email(s):</b> <?php echo esc_html($row_details['email']) ?> <b><?php _e( 'Telephone(s):', 'wp-easy-crm' );?></b> <?php echo $row_details['telefono'] ?> <b><?php _e( 'State:', 'wp-easy-crm' );?></b> <?php echo $row_details['provincia'] ?></code> 163 ?> <b><?php _e( 'Contact(s):', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['nombrecontacto']) ?> <b>Email(s):</b> <?php echo esc_html($row_details['email']) ?> 164 165 <?php 166 function parseAndFormatPhoneNumber($phone) { 167 // Load the country codes JSON file 168 $jsonPath = __DIR__ . '/CountryCodes.json'; 169 $countryCodes = json_decode(file_get_contents($jsonPath), true); 170 171 // If the JSON could not be loaded or parsed, return the original number 172 if (!$countryCodes) { 173 return $phone; 174 } 175 176 // Remove all non-numeric characters except "+" at the beginning 177 $cleanedPhone = preg_replace('/(?!^\+)\D/', '', $phone); 178 179 // If the number doesn't start with "+" and is in a local format 180 if (!empty($cleanedPhone) && $cleanedPhone[0] !== '+') { 181 // Attempt to identify if it starts with a known country code (no "+") 182 $potentialCountryCode = substr($cleanedPhone, 0, 3); // Try matching the first 3 digits 183 184 // Common country codes for primary use cases (retain existing functionality) 185 $commonCountryCodes = ['507', '506', '1']; 186 if (in_array($potentialCountryCode, $commonCountryCodes)) { 187 $cleanedPhone = $cleanedPhone; 188 } else { 189 // Check if the first digit matches a single-digit country code (e.g., US +1) 190 $potentialSingleCode = substr($cleanedPhone, 0, 1); 191 if ($potentialSingleCode === '1') { 192 $cleanedPhone = '1' . substr($cleanedPhone, 1); 193 } else { 194 // Assume based on length: 10 digits as US, 8 digits as Costa Rica or Panama 195 $phoneLength = strlen($cleanedPhone); 196 if ($phoneLength === 10) { 197 $cleanedPhone = '1' . $cleanedPhone; 198 } elseif ($phoneLength === 8 && substr($cleanedPhone, 0, 1) === '6') { 199 $cleanedPhone = '507' . $cleanedPhone; 200 } elseif ($phoneLength === 8) { 201 $cleanedPhone = '506' . $cleanedPhone; 202 } 203 } 204 } 205 } 206 207 // Remove the "+" sign for WhatsApp link format if present 208 $cleanedPhone = ltrim($cleanedPhone, '+'); 209 210 // Attempt to match with country codes from JSON for full coverage 211 foreach ($countryCodes as $country) { 212 $codeLength = strlen($country['dial_code']) - 1; // Exclude "+" for matching 213 $potentialCode = substr($cleanedPhone, 0, $codeLength); 214 215 if ($potentialCode == substr($country['dial_code'], 1)) { 216 // Format the phone number for WhatsApp (no "+") 217 return $cleanedPhone; 218 } 219 } 220 221 // Validate length (E.164 standard) and return if valid 222 $phoneLength = strlen(preg_replace('/\D/', '', $cleanedPhone)); // Only count digits 223 if ($phoneLength >= 8 && $phoneLength <= 15) { 224 return $cleanedPhone; 225 } 226 227 // Default: Return the original phone number if it doesn't meet criteria 228 return $phone; 229 } 230 231 232 233 // Display phone numbers with WhatsApp icons and tooltip 234 $phoneNumbers = explode(',', $row_details['telefono']); 235 ?> 236 237 <b><?php _e('Telephone(s):', 'wp-easy-crm'); ?></b> 238 <div style="display: inline;"> 239 <?php foreach ($phoneNumbers as $phone): 240 $formattedPhone = parseAndFormatPhoneNumber(trim($phone)); 241 if ($formattedPhone === false) continue; // Skip invalid numbers 242 243 $whatsappLink = "https://wa.me/" . $formattedPhone; // WhatsApp link format without "+" 244 $tooltipText = "# used: " . esc_html($formattedPhone) . " - Note: This number is calculated and might not be the accurate format for WhatsApp. In those cases please edit the number in the profile."; 245 ?> 246 <span style="margin-right: 10px; margin-top: 20px !important; position: relative;" data-tooltip="<?php echo esc_attr($tooltipText); ?>"> 247 <?php echo esc_html($phone); ?> <!-- Display original phone number --> 248 <a href="<?php echo esc_url($whatsappLink); ?>" target="_blank" style="text-decoration: none;color:#25D366;"> 249 <span class="dashicons dashicons-whatsapp"></span> <!-- WhatsApp icon using Dashicons --> 250 </a> 251 </span> 252 <?php endforeach; ?> 253 </div> 254 255 256 257 258 <b><?php _e('State:', 'wp-easy-crm'); ?></b> <?php echo esc_html($row_details['provincia']); ?> <b><?php _e('Source:', 'wp-easy-crm'); ?></b> <?php echo esc_html($row_details['clientsource']); ?> </code> 259 260 164 261 </br></br><code><b><?php _e( 'Address:', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['direccion']) ?> <b>Accounting Region:</b> <?php echo esc_html($accountingRegionName) ?> </code> 165 262 </br></br><code><b><?php _e( 'Note:', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['nota']) ?></code><br/><br/> -
wp-easy-crm/trunk/views/listClients.php
r3035881 r3180204 379 379 jQuery(this).toggleClass('show-menu'); 380 380 jQuery('#tagFilterContainer').slideToggle(); 381 382 //tooltip show 383 document.addEventListener('DOMContentLoaded', function () { 384 const tooltipElements = document.querySelectorAll('[data-tooltip]'); 385 const adminMenuWidth = document.getElementById('adminmenuwrap').offsetWidth; // Get the width of the WordPress admin menu 386 387 tooltipElements.forEach(function (elem) { 388 const tooltipText = elem.getAttribute('data-tooltip'); 389 const tooltipDiv = document.createElement('div'); 390 tooltipDiv.className = 'tooltiptext'; 391 tooltipDiv.innerHTML = tooltipText; 392 393 const wrapper = document.createElement('span'); 394 wrapper.className = 'tooltip'; 395 elem.parentNode.insertBefore(wrapper, elem); 396 wrapper.appendChild(elem); 397 wrapper.appendChild(tooltipDiv); 398 399 // Adjust tooltip position based on admin menu width 400 tooltipDiv.style.left = `calc(50% + ${adminMenuWidth}px)`; 401 }); 402 }); 403 381 404 382 405 … … 525 548 } 526 549 550 .tooltip { 551 position: relative; 552 display: inline-block; 553 cursor: pointer; 554 } 555 556 .tooltip .tooltiptext { 557 visibility: hidden; 558 width: 300px; /* Adjust the width if needed */ 559 background-color: #333; 560 color: #fff; 561 text-align: left; 562 padding: 5px; 563 border-radius: 5px; 564 position: absolute; 565 z-index: 1; 566 bottom: 100%; /* Position above the element */ 567 left: calc(50% + 160px); /* Shift to the right by the width of the WordPress menu */ 568 transform: translateX(-50%); 569 white-space: normal; /* Allow wrapping and line breaks */ 570 } 571 572 .tooltip:hover .tooltiptext { 573 visibility: visible; 574 } 575 576 527 577 528 578 </style> … … 637 687 <td class="column-columnname"><?php echo esc_html($client['email']) ?></td> 638 688 <td class="column-columnname"><?php echo esc_html($client['nombrecontacto']) ?></td> 639 <td class="column-columnname"><?php echo esc_html($client['telefono']) ?></td> 689 <td class="column-columnname"> 690 691 <!-- Display phone numbers with WhatsApp icons and tooltip --> 692 <?php $phoneNumbers = explode(',', $client['telefono']); 693 ?> 694 695 <div style="display: inline;"> 696 <?php foreach ($phoneNumbers as $phone): 697 $formattedPhone = parseAndFormatPhoneNumber(trim($phone)); 698 if ($formattedPhone === false) continue; // Skip invalid numbers 699 700 $whatsappLink = "https://wa.me/" . $formattedPhone; // WhatsApp link format without "+" 701 $tooltipText = "WhatsApp # used: " . esc_html($formattedPhone) . " - Note: This number is calculated and might not be the accurate format for WhatsApp. In those cases please edit the number in the profile of the client first."; 702 ?> 703 <div class="tooltip" style="margin-right: 10px;"> 704 <?php echo esc_html($phone); ?> <!-- Display original phone number --> 705 <a href="<?php echo esc_url($whatsappLink); ?>" target="_blank" style="text-decoration: none; color:lightgrey;"> 706 <span class="dashicons dashicons-whatsapp"></span> <!-- WhatsApp icon using Dashicons --> 707 </a> 708 <span class="tooltiptext"><?php echo esc_html($tooltipText); ?></span> <!-- Tooltip text --> 709 </div> 710 711 <?php endforeach; ?> 712 </div> 713 714 715 716 717 718 719 720 721 </td> 640 722 <td class="column-columnname"> 641 723 <?php … … 727 809 728 810 811 function parseAndFormatPhoneNumber($phone) { 812 // Load the country codes JSON file 813 $jsonPath = __DIR__ . '/CountryCodes.json'; 814 $countryCodes = json_decode(file_get_contents($jsonPath), true); 815 816 // If the JSON could not be loaded or parsed, return the original number 817 if (!$countryCodes) { 818 return $phone; 819 } 820 821 // Remove all non-numeric characters except "+" at the beginning 822 $cleanedPhone = preg_replace('/(?!^\+)\D/', '', $phone); 823 824 // If the number doesn't start with "+" and is in a local format 825 if (!empty($cleanedPhone) && $cleanedPhone[0] !== '+') { 826 // Attempt to identify if it starts with a known country code (no "+") 827 $potentialCountryCode = substr($cleanedPhone, 0, 3); // Try matching the first 3 digits 828 829 // Common country codes for primary use cases (retain existing functionality) 830 $commonCountryCodes = ['507', '506', '1']; 831 if (in_array($potentialCountryCode, $commonCountryCodes)) { 832 $cleanedPhone = $cleanedPhone; 833 } else { 834 // Check if the first digit matches a single-digit country code (e.g., US +1) 835 $potentialSingleCode = substr($cleanedPhone, 0, 1); 836 if ($potentialSingleCode === '1') { 837 $cleanedPhone = '1' . substr($cleanedPhone, 1); 838 } else { 839 // Assume based on length: 10 digits as US, 8 digits as Costa Rica or Panama 840 $phoneLength = strlen($cleanedPhone); 841 if ($phoneLength === 10) { 842 $cleanedPhone = '1' . $cleanedPhone; 843 } elseif ($phoneLength === 8 && substr($cleanedPhone, 0, 1) === '6') { 844 $cleanedPhone = '507' . $cleanedPhone; 845 } elseif ($phoneLength === 8) { 846 $cleanedPhone = '506' . $cleanedPhone; 847 } 848 } 849 } 850 } 851 852 // Remove the "+" sign for WhatsApp link format if present 853 $cleanedPhone = ltrim($cleanedPhone, '+'); 854 855 // Attempt to match with country codes from JSON for full coverage 856 foreach ($countryCodes as $country) { 857 $codeLength = strlen($country['dial_code']) - 1; // Exclude "+" for matching 858 $potentialCode = substr($cleanedPhone, 0, $codeLength); 859 860 if ($potentialCode == substr($country['dial_code'], 1)) { 861 // Format the phone number for WhatsApp (no "+") 862 return $cleanedPhone; 863 } 864 } 865 866 // Validate length (E.164 standard) and return if valid 867 $phoneLength = strlen(preg_replace('/\D/', '', $cleanedPhone)); // Only count digits 868 if ($phoneLength >= 8 && $phoneLength <= 15) { 869 return $cleanedPhone; 870 } 871 872 // Default: Return the original phone number if it doesn't meet criteria 873 return $phone; 874 } 875 729 876 730 877
Note: See TracChangeset
for help on using the changeset viewer.