Archive for Dynamic Web Development

OOP Javascript

Already heard about Object Oriented Programming on Javscript, well !, now post it in here cos i think this very important, specially people who will concern about AJAX scripting. However know about OOP on Javascript will make you better on Javascript programing.

This is a very simple sample, how to write:

<script language="Javascript">


ProgKu={
pariabelsatu : "Javascript" ,
   parkedua : "" ,
   fungsiSatu :
      function(val){
         if ( ( (val * 5) % 2 ) == 0 ) {
            this.pariabelsatu = "Javascript hasil OOPJs";
            this.parkedua = "Genap" ;
            return true;
         }else{
            this.pariabelsatu = "Hasil gak bener";
            this.parkedua = "Ganjil" ;
            return true;
         }
      }
   fungsiDua :
      function(){
         var t = prompt("Masukan angka 1 hingga 1000");
         var myVal = parseInt(t);
         if(isNaN(myVal)){
            alert("Yang dimasukan bukan angka");
            return false;
         }else{
            this.fungsiSatu(myVal);
         }
      }
}


//Sudah diluar class
function cobaCoba(){
var h = ProgKu.fungsiDua();
document.getElementById("test").innerHTML =
h.pariabelsatu +" mungkin karena "+h.parkedua;
}

And on HTML please put this code :

<div id="test">Look at here</div>

OK, have nice try :p

Leave a Comment

Create watermark on the Fly

I come to office earlier now. At a momment i just read my schedule of what will i do for today…? Let me see. ooh God, I have job to create a script which can protect all photo in my project using Logo, and i guess that i have to create watermark script.

However, it’s very interisting to create it. OK let’s create it…!!! (And don’t forget to help me if i’m wrong.. ). And this is the code which i used in my script:


<?php
/*create watermark
*By Gunturris - gunturris#a.t#gmail.com
*End of Feb 2007
*$imagesorce is original image
*$imagelogo is logo to blending (I used PNG)
*$alpha is alpha color output for watermark */


function watermak_on_the_fly($imagesource, $imagelogo, $alpha=15 ){
header("content-type: image/png");
//Check image resourse
if(! file_exists($
imagesource)){
$im = @imagecreate(50, 150)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "Img not found", $text_color);
imagepng($im);
return imagedestroy($im);
}


//Check watermark logo
if(! file_exists($imagelogo)){
$im = @imagecreate(50, 150)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "Logo not found", $text_color);
imagepng($im);
return imagedestroy($im);
}


settype($alpha,"integer");
if($alpha > 100) $alpha=100;
if($alpha < 0 )$alpha = 0;


list($ori_width,$ori_height,$ori_type,$ori_attr)=getimagesize($
imagesource);
switch($type){
case 1 : $img = @imagecreatefromgif($
imagesource);break; //GIF
case 2 : $img = @imagecreatefromjpeg($
imagesource); break; //JPG
case 3 : $img = @imagecreatefrompng($
imagesource); break; //PNG
default : die("IMAGE NOT SUPPORTED!"); break;
}


$watermark = imagecreatefrompng( $imagelogo );
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);


@imagecopymerge($img, $watermark, 0, ($ori_height-$watermark_height-5), 0, 0, $watermark_width, $watermark_height, $alpha);


return $img;


}
?>

And to use just ‘do’ like this:

<?php
$test = watermak_on_the_fly("imagejpeg.jpeg", "logo.png",25);
@imagejpeg($test );
@imagedestroy($test);
?>

OK, I hope it’s works good, if not please tell me or please debug by your self. Cos in my computer is no problem :p

Comments (3)

CakePHP vs Symfony, hmm..???

After i found a PHP framework who is called cakePHP, now i heard about the other ones framework which it’s name Symfony PHP5.

So what is different between both of its …? I don’t know much, but i can see several difference from its.

  • Installation, server requirement phpCake use PHP 4.3 or greater, and Symfony must use 5
  • Database, Symfony compatible with most engine like MySQL, Ms SQL, PostgreSQL and Oracle, but i don’t see cakePHP can use Oracle engine.
  • Models, Symfony has two versions of the data object model in two different directories and not for cakePHP
  • Propel XML, Symfony understands the Propel native XML schema format and i don’t think so on cakePHP

There is a several which i think difference from both, and i need your suggestion, input or addition to complete this article. And please correct if on above is wrong.

Comments (2)

Multi action on drop down

Moreless 2 days i’m not writing here.
Recently i’m very busy…
You know why..? NO, I’m not a workaholic…:D

Anyway, i want to write about javascript.
Why…? It’s about manage “multi action on drop down”
Have you ever think, How to create a form which it without submit button,
but only use drop down menu, where on list contain action by each list.

Ok, Think that we should edit or delete option.
O ya, On this

<?php   //action.php//Better if you control referer and else that you thing it a security issue

$action = isset($_POST['action']) : $_POST['action'] ? 0 ;

if($action == 1 ){

//Delete action here

} elseif ( $action ==2 ){

//Edit action here

} else {

//default

}

?>

And HTML page is like this

<html>

<head>

<!– Everything about HTML head //–><script language=”Javascript”>

<!–

function goAction(n){

var f = document.frm1;
  f.id.value = n;
  f.submit();

}

//–>

</script>

</head>
<body>

<form method=”post” name=”frm1″ action=”action.php”><input type=”hidden” name=”id”>

<table width=”100%”>

   <tr bgcolor=”#CCCCCC”>
      <td>Computer</td>
      <td>$US 340</td>
      <td>
         <select name=”action” onchange=”goAction(234)”>
         <option value=”0">Action</option>
         <option value=”1">Delete</option>
         <option value=”2">Edit</option>
         </select>
     </td>
   </tr>

    <tr bgcolor=”#CDCDCD”>
      <td>Rack Server</td>
      <td>$US 1422</td>
      <td>
         <select name=”action” onchange=”goAction(234)”>
         <option value=”0">Action</option>
         <option value=”1">Delete</option>
         <option value=”2">Edit</option>
         </select>
     </td>
   </tr>
</table>

</form>
</body>
</html>

Any other idea?…
I ‘m waiting :D

Leave a Comment

Any minithesis to all my Friends

Fiewwh….

Many days ago, my friend who studing in a university which concern in Computer and Technology in Yogyakarta ask me, “Hi gun, what is good theme for my thesis”.

Aha…

My friend think that i can answer his question, of course,…. No i cannot… :D
Btw, after thinking about his question i’m searching any pages which content any technology research, and every page always prepare and present about article that i don’t understand. Deply, very very don’t understand :D ( How stupid i am )

Thinking again, i’m only know about PHP ( look at here , i’m very stupid, aren’t me? ).
But, i remembered that PHP can do everything with your PC nad network, so i try to investigate it, and what i think came true. I found many themes that perhaps good for him.

And here are the themes:

  1. Mengelola file kompresi pada website (Compress file management on website)
  2. Mengelola database master dan slave serta pengaruhnya terhadap kinerja website dengan PHP dan API MySQLi . ( Master and slave database management and effect on website performance use PHP and MySQLi API )
  3. Pengaruh mirror terhadap pelayanan XML website. ( Mirror effect towards XML website serving )

OK, now only three themes for your minithesis, I will update any idea soon.
Do you interest ? ( I hope no ) if yes just write in comment. Hehehe…

Leave a Comment

Between “Switch else PHP” and “Choose otherwise XSLT”

Hi, Still know this switch control on PHP programming?
switch($var){
case $var="" : PHP statement ; break;
case $var="" : PHP statement ; break;
default : other PHP statement ; break;
}

Let’s equal it with XSLTransformer <XSLT:CHOOSE>
Check it out.!
<!-- Estimate that you are in a XML tag data -->
<xsl:choose >
<xsl:when test = "xml:value" >
XHTML statement
</xsl:when>
<xsl:when test = "xml:value" >
XHTML statement
</xsl:when>
<xsl:otherwise >
Other XHTML statement
</xsl:otherwise>
</xsl:choose>

Huehuehue…, Can you find the same thing between them..?
Actually, it’s not too hard to find the same thing, especially for a good programmer.

Yea, You’re right, the same thing what i mean, is structure, cos’ these programms use logicaly control by event on one statement which give another statement. ( do you what i mean..? ) I hope… :D
So, what are diferent if we use <xsl:if> ..?
Hahaha, I thing you are better than me to answered this.
Please tell me.

O ya… what i have been written may be wrong, please correct me too, cos i’m in learn about that.. :D

Leave a Comment

Using CakePHP … nyam.. nyam… nyam….

Do you enjoyed developt a web using PHP + API Database only..? If no, i suggest you to go with template engine. Like smarty, tiny but strong , cakePHP or else, Now i’ll tell you about cake PHP, What the f*** is it..?? hehehehe…

Cake PHP (sounds like cake which good to taste it :D ) , is an alternative template engine for you who knows how PHP script does… perhaps!..perhaps..!perhaps..!
Actualy i don’t know it very good..:D ..Sorry…..!!! SO just look and feel by your self, open it on Manual
But …, I have tested it, and it’s cool bro…
O ya… It run on PHP 5

cos you will ussualy using this

class Y extends X

Comments (4)