Skip to main content

Posts

Showing posts from August, 2019

How to run database queries in WordPress

WordPress has a  built-in object class  for dealing with database queries. It’s called  wpdb  and it’s found in the includes/wp-db.php file. When you’re running queries you should always use this class to execute them. To use this class you first need to define $wpdb as a global variable before you can use it. Just place this line of code before every $wpdb function:

Vtiger report can not customize after created by own non-admin

Example, You belong to sales & Marketing team This team in CRM system belong to Sales and Marketing role and you are a non-admin user When you create a report providing by vtiger CRM system(call default report) after that you around to customize your own report before next and next, final you click on save. System out "Permission Denied", The following the way to fix this issue: creating 2 tables and custom report and save again: CREATE TABLE IF NOT EXISTS vtiger_report_sharerole ( reportid int(25) NOT NULL, roleid int(25) NOT NULL ) CREATE TABLE IF NOT EXISTS vtiger_report_sharers ( reportid int(25) NOT NULL, rsid int(25) NOT NULL )

Change text label of option in select

When you have a selection with values difference but you want show with other name. Following is the way to show values with other label var value_will_change = ['value 1','value 2','value 3','value n']; value_will_change.forEach(function(item) { $("select[name ='select_name'] option[value='" + item + "']").text('Text will change to'); }); explain: - value_will_change: is array of option will show with other label.

Count number of month from date to date

If you have two date and want to count number of month between them, following is function to count this. public function countMonthFromDate( $date ){ $date1 = $date ; $date2 = date ( 'Y-m-d' ); $ts1 = strtotime ( $date1 ); $ts2 = strtotime ( $date2 ); $year1 = date ( 'Y' , $ts1 ); $year2 = date ( 'Y' , $ts2 ); $month1 = date ( 'm' , $ts1 ); $month2 = date ( 'm' , $ts2 ); $diff = (( $year2 - $year1 ) * 12 ) + ( $month2 - $month1 ); return $diff ; }

How to fix crm 7.1.0 List view issue

I saw that current Vtiger 7.1.0 taking ListView error with non-admin user, because missing two table: vtiger_cv2role, vtiger_cv2rs Please run two sql queries to create table to fix this issue: CREATE TABLE IF NOT EXISTS `vtiger_cv2role` ( `cvid` int(25) NOT NULL, `roleid` varchar(50) NOT NULL ) CREATE TABLE IF NOT EXISTS `vtiger_cv2rs` ( `cvid` int(25) NOT NULL, `rsid` varchar(255) NOT NULL )

Curl Example

$ch = curl_init (); $authHeader = '' ; curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true ); curl_setopt ( $ch , CURLOPT_URL , " $url " ); curl_setopt ( $ch , CURLOPT_HTTPHEADER , array ( $authHeader )); curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , FALSE ); curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , FALSE ); $response = curl_exec ( $ch ); $error = curl_error ( $ch );

Delete all file in Directory

function delete_directory($dirname){     if (is_dir($dirname)) $dir_handle = opendir($dirname);     if (!$dir_handle) return false;     while ($file = readdir($dir_handle)) {         if ($file != "." && $file != "..") {             if (!is_dir($dirname . "/" . $file)) {                 unlink($dirname . "/" . $file);             } else {                 delete_directory($dirname . '/' . $file);             }         }     }     closedir($dir_handle);     rmdir($dirname);     return true; }

Copy File from Directory to Directory

function copy_directory(){     $src = 'customscript/hrm';     $dst = 'layouts/v7/skins/test';     if (is_dir($src)) $dir_handle = opendir($src);     if (!$dir_handle) return false;     while ($file = readdir($dir_handle)) {         if ($file != "." && $file != "..") {             if ( is_dir($src . '/' . $file) ) {                 recurse_copy($src . '/' . $file,$dst . '/' . $file);             }             else {                 copy($src . '/' . $file,$dst . '/' . $file);             }         }     }     closedir($dir_handle);     return true; }

Check if Website is Available by PHP

When you have a website and you need to check that website is available or not to confirm it still working, the following is some function to check it is available or not: ----------Technique #1 function isDomainAvailible($domain) {     //check, if a valid url is provided     if(!filter_var($domain, FILTER_VALIDATE_URL))     {         return false;     }     //initialize curl     $curlInit = curl_init($domain);     curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);     curl_setopt($curlInit,CURLOPT_HEADER,true);     curl_setopt($curlInit,CURLOPT_NOBODY,true);     curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);     //get answer     $response = curl_exec($curlInit);     curl_close($curlInit);     if ($response) return true;     return false; } ----------Technique #2 function Visit($url){...

Convert Vietnamese Text Latin text

function stripVN($str) {     $str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);     $str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);     $str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);     $str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);     $str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);     $str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);     $str = preg_replace("/(đ)/", 'd', $str);     $str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);     $str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);     $str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);     $str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);     $str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/...