About This Journal
Technical concerns tend to find a solution as long as there are good people working on them. And Linux has the very best. - Linus Torvalds
Vtiger CRM backtracing code
Administrator
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);
Posted in Miscellaneous |
No Comments »
Short note of Javascript refresher
pepesmith
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”> </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)
Posted in Miscellaneous |
No Comments »
A notes UTF8 in MySQL and PHP
pepesmith
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.
Posted in Miscellaneous |
No Comments »
Notes on PHP addslashes,mysql_escape and stripcslashes
pepesmith
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
Posted in Miscellaneous |
No Comments »
Perl script bad interpreter: Permission denied
pepesmith
Something went wrong on my perl code which was working earlier before I made an upgrade from debian etch to lenny.
Here are the errors :
debian:/home/jojo/Desktop/pepesfile/drupal/mysite# ./index.cgi
bash: ./index.cgi: /usr/bin/perl: bad interpreter: Permission denied
On the apache log :
[error] [client 192.168.1.2] (13)Permission denied: exec of '/home/jojo/Desktop/pepesfile/drupal/mysite/index.cgi' failed
I’ve been tracing the error on it. I simply commanded the perl index.cgi on it but its fine. I suspect that there are ^M character which the DOS/Windows based text editor is giving on the first few lines of code but its fine when I try to view via VIM[1].
And then I’ve tried to look at the way the folder mysite/drupal mounted on my /etc/fstab
Here is my entry:
UUID=38c8ec02-5ef7-49fd-8607-78e4b2fe78c7 /home/jojo/Desktop/pepesfile ext3 auto,rw,user 0 0
I did add the exec on the column auto,rw,user and remounted the partition but its still not working
.
Finally i’ve replaced that auto,rw,user,exec to defaults.
Ahh.. that solved my problem.
According to the fstab documentation here[2], “defaults uses the default options that are rw, suid, dev, exec, auto, nouser, and async.” I just need to type the other options and remove the nouser, but I’m glad fstab has this default.
[1] http://www.vim.org/
[2] http://www.tuxfiles.org/linuxhelp/fstab.html
Posted in Miscellaneous |
No Comments »