Archive for August, 2010

>IEs4Linux (Fedora)

Posted: August 26, 2010 in Linux

>Open a terminal. Log in as root to install wine and cabextract:

yum -y install wine*
yum -y install cabextract

Logout and install IEs 4 Linux with your normal user account:

wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux


>Under Debian Linux, you can use the same apt-get method as follows to install unrar program:

$ apt-get install unrar

If you are using Fedora core Linux then use yum command as follows:

$ yum install unrar

If you are using FreeBSD, you can use:

$ pkg_add -v -r unrar

If any of above, methods is not working, you can download binary package from official rarlab site and choose the right package for your machine… for example, i chose the latest (by the time i write this post):

$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.7.1.tar.gz

then untar the file:

$ tar -zxvf rarlinux-3.7.1.tar.gz

Both rar and unrar commands are located in rar sub-directory. Just go to rar directory:

$ cd rar
$ ./unrar

Now copy rar and unrar to /bin directory:

$ cp rar unrar /bin

Then you can use the same method on creating and extracting rar files in linux in my previous post.

Another thing to add, you can also test the integrity of archive, with this command:

$ unrar t filename.rar

or list the files inside the rar file using this command:

$ unrar l filename.rar

>Export Database Data to .XLS in PHP

Posted: August 12, 2010 in MYSQL

>


$DB_Server = "localhost";        //your MySQL Server
$DB_Username = "username";         //your MySQL User Name
$DB_Password = "password";        //your MySQL Password
$DB_DBName = "databasename";            //your MySQL Database Name

 $DB_TBLName = “users”;           //your MySQL Table Name
$ttype = $DB_TBLName;

 $sql = “Select * from $DB_TBLName”; 

$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
    or die(“Couldn’t connect to MySQL:
” . mysql_error() . “
” . mysql_errno());
//select database
$Db = @mysql_select_db($DB_DBName, $Connect)
    or die(“Couldn’t select database:
” . mysql_error(). “
” . mysql_errno());
//execute query
$result = @mysql_query($sql,$Connect)
    or die(“Couldn’t execute query:
” . mysql_error(). “
” . mysql_errno());

    while($row = mysql_fetch_row($result))
    {
           $data = $row;

    }


function cleanData(&$str) {
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"'))
$str = '"' . str_replace('"', '""', $str) . '"';

}

# filename for download $filename = "website_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
foreach($data as $row) {
if(!$flag) { # display field/column names as first row echo implode("\t", array_keys($row)) . "\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\n";
}
exit;

>Codeigniter Layout Library

Posted: August 5, 2010 in CI

>Create Layout.php in libraries(/application/libraries/Layout.php) folder and copy the below code in the file

< ?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’); class Layout { var $obj; var $layout; function Layout($layout = “layout_main”) { $this->obj =& get_instance();
$this->layout = $layout;
}

function setLayout($layout)
{
$this->layout = $layout;
}

function view($view, $data=null, $return=false)
{
$loadedData = array();
$loadedData[‘content_for_layout’] = $this->obj->load->view($view,$data,true);

if($return)
{
$output = $this->obj->load->view($this->layout, $loadedData, true);
return $output;
}
else
{
$this->obj->load->view($this->layout, $loadedData, false);
}
}
}
? >

Then load your library in your controller

You can use it in two ways. First and obvious is to place the following line in the controller’s constructor function.

$this->load->library(‘layout’, ‘layout_main’);

The second is by enabling codeIgniter to autoload the library by editing /application/config/autoload.php

$autoload[‘libraries’] = array(‘layout’);

in your controller you may do this:

$this->layout->view(‘welcome_message’);

Master layout

/application/views/layout_main.php
Your view file must use $content_for_layout. For example:

<html>
<head>
<title><?=$title_for_layout?></title>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″ />
<link rel=”stylesheet” href=”/css/main.css” type=”text/css” />
</head>
<body>
<div id=”pagewidth” >
  <div id=”header” ><img src=”/images/header.jpg” width=”700″ height=”200″></div>
  <div id=”wrapper” class=”clearfix” >
    <div id=”twocols” class=”clearfix”>
      <?php echo $content_for_layout?>
    </div>
  </div>
  <div id=”footer” > Footer </div>
</div>
</body>
</html>


>function yourtheme_preprocess_node(&$variables) {
if ($your_condition) {
drupal_add_css(path_to_theme(). “/filename.css”, “theme”);
$variables[‘styles’] = drupal_get_css();

drupal_add_js(file_directory_path() .’/javascript.js’, ‘inline’);
$vars[‘scripts’] = drupal_get_js();
}
}