Vtiger CRM backtracing code

June 29th, 2010

To backtrace the particular part in the vtiger script.. add the following code.

$bt = debug_backtrace();
$ut = array();
foreach($bt as $t){
$ut[] = array('file'=>$t['file'],'line'=>$t['line'],'function'=>$t['function']);
}
var_export($ut);

Short note of Javascript refresher

September 28th, 2009

In the program i made, which tabulates the latest 20 call in a minute, I’ve found some good resource for it.
My setup, perl-cgi script is the one that generates the list of calls. This script is just called via an Ajax function.

The main important part of that is part that contains this setInterval.
I chose setInterval since the “Call Accounting System” i made needs a refreshing every minute to update
the user about the activity of PBX.

The code also requires to have an id “content” to have the content generated by “refresher.cgi” displayed.
An example of usage will be.

<div id=”content”>&nbsp;</div>

and i put the code at the bottom of the html page.

<script type=”text/javascript” src=”20records.js”></script>

Below is the content of the 20records.js file:

var xmlhttp;

function showList()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="refresher.cgi";
url=url+"?sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{

document.getElementById('content').innerHTML = xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
window.setInterval("showList();",60000)

A notes UTF8 in MySQL and PHP

May 12th, 2009

According to Wikipedia, the Congo Region has 3 countries, the 2 Congo countries and the Angola.

I was tasked to list the countries all over the world and that includes the two (2) countries of Congo called Republic of the Congo (Congo-Brazzaville) and the Democratic Republic of the Congo (Congo-Kinshasa).

The addition of the dash – thing on the country to identify that separate country rendered some special unknown characters in both IE and Firefox browser. So upon seeing the content of the combo-box that contains the list of the country, this 2 country was rendered then as Congo <special character> Kinshasa and Congo <special character> Brazzaville. I thought that was just the result of the uploads via LOAD DATA INFILE command of Mysql yet when I browse the code via mysql client console, the dash stays there. Later I realize that this UTF8 thing really made that difference.

Thus using the command :
mysql_query("SET NAMES 'utf8'");
resolves that issue.

Notes on PHP addslashes,mysql_escape and stripcslashes

April 21st, 2009

This is just a short note while I was coding/studying on PHP a few minutes earlier for my site.

From the manual of PHP:

addslashes – Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote (‘), double quote (“), backslash (\) and NUL (the NULL byte). [1]

mysql_real_escape_string — Escapes special characters in a string for use in a SQL statement [2]

stripslashes — Un-quote string quoted with addslashes() [3]

The purpose of using mysql_real_escape_string is to prevent this sql injection attack thing on data that was then typed by the user. This mysql_real_escape_string is somewhat functions like addslashes. When you browse or retrieve your data via mysql shell or any mysql query browser utility you will notice that there are additional characters that were added. To remove that additional character, the stripslashes function is needed and provided also by PHP.

Here is my sample code :

foreach ($dispute_message2 as $key => $value)
{
$value[messages] = stripslashes($value[messages]);
}

Note that is code is on a function and the field messages is the one that contains the extra-codes made by mysql_real_escape_string(). The issue then here is that when i tried to print the messages here from $dispute_message2 array, still i can see the extra-codes.

I’ve found later my answer on this on the foreach explanation.
“Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself.”

Thus, I made some revisions on the code and here is the latest one.

foreach ($dispute_message2 as $key => $value)
{
$dispute_messages2[$key][messages] = stripslashes($value[messages]);
}

:) Adding this $dispute_messages2[$key] fixed my problem.

[1] http://www.php.net/manual/en/function.addslashes.php
[2] http://www.php.net/manual/en/function.mysql-real-escape-string.php
[3] http://www.php.net/manual/en/function.stripslashes.php

« Older Entries