Tuesday, July 27, 2010

Another way to clear FCKeditor value in javascript

Another way to clear FCKeditor value in javascript.
===================================================
Here I am telling you another way that how can you only clear FCKeditor value in javascript.
Assuming the you are using PHP as a server type script.

<?php
include_once("FCKeditor/fckeditor.php") ;
$sBasePath = "FCKeditor/" ;
// instance name as FCKeditor1
$oFCKeditor = new FCKeditor('FCKeditor1') ; 
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value = "test data";
$oFCKeditor->Create() ;
?>

<input name="resetButton" type="button" title="Reset" onclick="doClear();"  value="Reset"/>
<script>
function doClear(){
     var MyFCKeditor___Frame=document.getElementById("FCKeditor1___Frame");
     MyFCKeditor___Frame.src="FCKeditor/editor/fckeditor.html?InstanceName=FCKeditor1&Toolbar=Default";
    return false;
}
</script>


Note that, use same name/id in javascript here I am using "FCKeditor1" as a name.

Thursday, July 22, 2010

Show facebook bio and fan list.

Show facebook bio and fan list.

Here is the listed below link, click on it and find your
facebook bio with fan list

Show facebook bio and fan list.

Wednesday, July 21, 2010

event delegation in jQuery

event delegation in jQuery




$("#btnId").click(function(){
    // put your code here ;
});

Download gmail attachment in PHP

Download gmail attachment in PHP

If you want to download gmail attachment by PHP code?,  then here is the code that will do it.
just copy and paste the entire code and run it.



<?php
class ImapMail
{
    var $dirPath,$deleteEmails=false;
    var $imapInBox;
    function __construct($mailHost,$emailLogin,$pass) {
        $this->imapInBox=imap_open($mailHost,$emailLogin,$pass) or die("Unable to connect:".imap_last_error());
    }
    function getdecodevalue($msg,$bodyType) {
        if($bodyType==0 || $bodyType==1) {
            $msg = imap_base64($msg);
        }
        if($bodyType==2) {
            $msg = imap_binary($msg);
        }
        if($bodyType==3 || $bodyType==5) {
            $msg = imap_base64($msg);
        }
        if($bodyType==4) {
            $msg = imap_qprint($msg);
        }
        return $msg;
    }

    function downLoadAttachment($dirPath,$deleteEmails=false) {
        $nAttachment = 0;
        $dirPath = str_replace('\\', '/', $dirPath);
        if (substr($dirPath, strlen($dirPath) - 1) != '/') {
            $dirPath .= '/';
        }
        $message = array();
        $message["attachment"]["type"][0] = "text";
        $message["attachment"]["type"][1] = "multipart";
        $message["attachment"]["type"][2] = "message";
        $message["attachment"]["type"][3] = "application";
        $message["attachment"]["type"][4] = "audio";
        $message["attachment"]["type"][5] = "image";
        $message["attachment"]["type"][6] = "video";
        $message["attachment"]["type"][7] = "other";
       
        $nEmails = imap_search($this->imapInBox, 'ALL', SE_UID);
        $j=-1;
        for ($j = 0; $j < count($nEmails); $j++) {
            $j++;
            $messStructure = imap_fetchstructure($this->imapInBox, $nEmails[$j] , FT_UID);
            $overview = imap_fetch_overview($this->imapInBox,$j ,0);
        echo '<span>Read/Unread'.($overview[0]->seen ? 'read' : 'unread').'</span>';
        echo  '<span>Subject:: '.$overview[0]->subject.'</span> ';
        echo  '<span>From:: '.$overview[0]->from.'</span>';
        echo '<span>On:: '.$overview[0]->date.'</span>';
            $body = imap_fetchbody($this->imapInBox,$j ,2);
            echo $body;
            if(isset($messStructure->parts)) {
                $parts = $messStructure->parts;
                $fpos=2;
                for($i = 1; $i < count($parts); $i++) {
                $message["pid"][$i] = ($i);
                $part = $parts[$i];
                if(isset($part->disposition) && $part->disposition == "ATTACHMENT") {
                    $message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
                    $message["subtype"][$i] = strtolower($part->subtype);
                    $fileName=$part->dparameters[0]->value;
                    $mess = imap_fetchbody($this->imapInBox,$j+1,$fpos); 
                    $fp=fopen($dirPath.$fileName, 'w');
                    $data=$this->getdecodevalue($mess,$part->type);   
                    fwrite($fp,$data);
                    fclose($fp);
                    $nAttachment++;
                    $fpos+=1;
                }
            }
                if ($this->deleteEmails) {
                    //imap_delete($this->imapInBox,$j+1);
                }
            }
        }
        if ($this->deleteEmails) {
            //imap_expunge($this->imapInBox);
        }
        imap_close($this->imapInBox);
        return ("Completed ($nAttachment attachment(s) downloaded into $dirPath)");
    }
}

$mailHost="{imap.gmail.com:993/imap/ssl}INBOX";
$emailLogin="FULL-GMAIL-ID-HERE";
$pass="PASSWORD-HERE";
$dirPath=$_SERVER['DOCUMENT_ROOT']."test/gmail/";
$deleteEmails=false;
$mailObj=new ImapMail($mailHost,$emailLogin,$pass);
echo $mailObj->downLoadAttachment($dirPath,$deleteEmails=false);
?>




Friday, July 16, 2010

Insert value in auto increment column

How to insert automatically values in NOT NULL auto_increment and PRIMARY KEY column.

Suppose you have listed below table:

CREATE TABLE `testtest` (
  `id` bigint(20) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ; 
This table have only one column "id", and this column have attribute of  NOT NULL auto_increment and PRIMARY KEY.


you need to use listed below sql :

insert into testtest values(null)

OR

insert into testtest values('')

Thursday, July 15, 2010

change UL element text by class name

Change UL element text by class name.

var elements = document.getElementsByClassName("form-errors")[0];
//alert(elements.innerHTML);
elements.innerHTML=elements.innerHTML+"<br/><br/>";