Install Ether-pad lite

1.  sudo apt-get install build-essential python libssl-dev git-core git libsqlite3-dev gzip curl
2.  mkdir ~/local
3.  cd ~/local
4.  wget http://nodejs.org/dist/v0.6.12/node-v0.6.12.tar.gz
5.  tar -zxvf node-v0.6.11.tar.gz
6.  cd node-v0.6.11
7.  ./configure –prefix=$HOME/local/node
8.  make
9.  make install
10. echo ‘export PATH=$HOME/local/node/bin:$PATH’ >> ~/.profile
11. echo ‘export NODE_PATH=$HOME/local/node:$HOME/local/node/lib        /node_modules’ >> ~/.profile
12. source ~/.profile
13. Installing Etherpad Lite and running it
14. git clone git://github.com/Pita/etherpad-lite.git
15. etherpad-lite/bin/run.sh

Access it on http://localhost:9001

How to deploy Etherpad Lite as a service

1.  Create a user called etherpad-lite
2.  Create a log folder for the service /var/log/etherpad-lite
3.  Ensure the etherpad-lite user have full access to the log and the git folder
4.  Save the following script to /etc/init/etherpad-lite.conf
5.  Set EPHOME and EPUSER to the proper values
6.  Run sudo start etherpad-lite

etherpad-lite.conf script

description "etherpad-lite"
start on started networking
stop on runlevel [!2345]
env EPHOME=/usr/local/etherpad-lite
env EPLOGS=/var/log/etherpad-lite
env EPUSER=etherpad-lite
respawn
pre-start script
chdir $EPHOME
mkdir $EPLOGS ||true
chown $EPUSER:admin $EPLOGS ||true
chmod 0755 $EPLOGS ||true
chown -R $EPUSER:admin $EPHOME/var ||true
bin/installDeps.sh >> $EPLOGS/error.log || { stop; exit 1; }
end script
script
cd $EPHOME/node
exec su -s /bin/sh -c 'exec "$0" "$@"' $EPUSER -- node server.js 
>> $EPLOGS/access.log 
2>> $EPLOGS/error.log
end script


Make Certificate with odtphp

ODTPHP

OdtPHP is an oriented object libary for PHP 5+. It allows you to generate automatically OpenOffice text documents from templates. You can use it directly within your PHP scripts (without OpenOffice).
OdtPHP is very easy to use : with a minimum of code, you will be able to generate simple documents by replacing tags from template and by inserting some images. You can also take advantage from advanced features in order to create complex OpenOffice files by repeating parts of the document or lines of array.
Features
OdtPHP allows you to replace tags from your OpenOffice template by text content or pictures. The library also handles loops that can be imbricated as you want. Moreover, odtPHP allows you to simply repeat lines of OpenOffice tables. Eventually, you can export the final result in a file on your server or directly to the client browser.

Requirements
1. Linux Operating System
1. Apache Web Server
2. MySql
3. PHP
3. Download odtphp-1.0.1.zip link http://sourceforge.net/projects/odtphp/files/

Steps

1. Unzip odtphp package

#tar xvzf odtphp-1.0.1.zip

2. Place folder in /var/www file directory.

 #cd /var/www/odtphp-1.0.1

3. Move to test directory and create certificate.php file.

 #vim /tests/certificate.php

4. Include Library file

 require_once('../library/odf.php');

5. Include Template file in which form certificate produce.

 $odf = new odf("certificate.odt");

6. Database connectivity, give database details from which you want to get information.

 $dbConnection = mysql_connect("localhost", "dbUser", "dbpass");
 mysql_select_db("dbName", $dbConnection);

7. Create a segment.

 $article = $odf->setSegment('articles');
 $odf->mergeSegment($article);

8. In articles, use sql query to fetch data and define segment variable and assign data value to it.

For Example:

$result = mysql_query("SELECT * FROM lime_survey_65311");
while($row = mysql_fetch_array($result))
{
 //image
 $pic = "images/" . $row['image'];
 $article->setImage('pic', $pic);
 //name
 $nameResult = $row['65311X7X12'];
 $nameRow = mysql_fetch_array(mysql_query("select answer from bongo_answers where code='$nameResult'"));
 $article->nameArticle($nameRow['answer']." ".$row['65311X7X13B1'] ." ". $row['65311X7X13B2'] ." ". $row['65311X7X13B3']);
 //department
 $deptResult = $row['65311X7X17'];
 $deptRow = mysql_fetch_array(mysql_query("select answer from bongo_answers where code='$deptResult'"));
 $article->deptArticle($deptRow['answer']);
 $article->merge(); 
}
9. Export as attached file.
 $odf->exportAsAttachedFile();

10.Create a template file. In which you create your own design and define variables which you were define in your segment.

Login & Signup in Zend Framework

Zend Framework is an Open-Source object-oriented Web application framework implemented in PHP .The goal of ZF is to simplify Web development while maintaining object-oriented best practices for building Web 2.0 applications and Web services.

I am starting with simple Signup & Login Authentication .

Requirements:-

(i)Latest version of PHP,My SQL Database and Apache Web Server must be installed on your system.

(ii)mod_rewrite must be enabled by using this command

sudo a2enmod rewrite

(iii)Restart Apache

sudo service apache2 restart

(iv)Download Zend minimal package

Make a Directory Structure like this

project/

application/

controllers/

forms/

models/

views/

scripts/

index/

Steps:-

1.Extract the library folder from zend package to the main working project/ directory.

2.Create a index.php file and placed in project/ directory

index.php

<?php

define(‘ROOT_DIR’, dirname(__FILE__));

set_include_path(‘.’

. PATH_SEPARATOR . ROOT_DIR . ‘/library’

. PATH_SEPARATOR . ROOT_DIR . ‘/application/models’

. PATH_SEPARATOR . ROOT_DIR . ‘/application/forms’

. PATH_SEPARATOR . get_include_path()

);

require_once “Zend/Loader/Autoloader.php”;

$autoloader = Zend_Loader_Autoloader::getInstance();

$autoloader->setFallbackAutoloader(true);

$config = new Zend_Config_Ini(ROOT_DIR.’/application/config.ini’, ‘general’);

$db = Zend_Db::factory($config->db);

Zend_Db_Table::setDefaultAdapter($db);

$frontController = Zend_Controller_Front::getInstance();

$frontController->throwExceptions(true);

$frontController->setControllerDirectory(ROOT_DIR.’/application/controllers’);

$frontController->dispatch();

?>

3.Create a Database by executing this following sql query.

CREATE TABLE IF NOT EXISTS `Users` (

`id` int(100) NOT NULL AUTO_INCREMENT,

`firstname` varchar(100) NOT NULL,

`lastname` varchar(100) NOT NULL,

`email` varchar(255) NOT NULL,

`username` varchar(100) NOT NULL,

`password` int(20) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

4.Create a config.ini file in project/application/ Directory

[general]

db.adapter = “PDO_MYSQL”

db.params.host = “localhost”

db.params.username = “root”

db.params.password = ” “

db.params.dbname = ” “

5.Create a Controller named IndexController.php and placed in application/controllers/ Directory.

IndexController.php

class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
    } 
    public function signupAction()
    {
    } 
    public function logoutAction()
    {
    }
    public function homeAction()
    {
    }
}

 

6.Now we will need to create template files in application/views/scripts/index/ named

   index.phtml
   signup.phtml
   logout.phtml
   home.phtml

 

7.Now we begin with us forms create LoginForm in applications/forms/

LoginForm.php

<?php

class LoginForm extends Zend_Form

{

public function init()

{

$this->setMethod(‘post’);

$username = $this->createElement(‘text’,’username’);

$username->setLabel(‘Username’)

->setAttrib(‘maxlength’,75);

 

$password = $this->createElement(‘password’,’password’);

$password->setLabel(‘password:’)

->setAttrib(‘maxlength’,75);

 

$signin = $this->createElement(‘submit’,’signin’);

$signin->setLabel(“sign in”)

->setIgnore(true);

 

$this->addElements(array(

$username,

$password,

$signin

));

}

}

?>

 

8.Next form is RegistrationForm in application/forms/ Directory.

RegistrationForm.php

 

<?php

class RegistrationForm extends Zend_Form

{

public function init()

{

$firstname = $this->createElement(‘text’,’firstname’);

$firstname->setLabel(‘First Name:’)

->setRequired(false);

 

$lastname = $this->createElement(‘text’,’lastname’);

$lastname->setLabel(‘Last Name:’)

->setRequired(false);

 

$email = $this->createElement(‘text’,’email’);

$email->setLabel(‘Email:’)

->setRequired(false);

 

$username = $this->createElement(‘text’,’username’);

$username->setLabel(‘Username:’)

->setRequired(true);

 

$password = $this->createElement(‘password’,’password’);

$password->setLabel(‘Password:’)

->setRequired(true);

 

$confirmPassword = $this->createElement(‘password’,’confirmPassword’);

$confirmPassword->setLabel(‘Confirm Password:’)

->setRequired(true);

 

$register = $this->createElement(‘submit’,’register’);

$register->setLabel(‘Sign up’)

->setIgnore(true);

 

$this->addElements(array(

$firstname,

$lastname,

$email,

$username,

$password,

$confirmPassword,

$register

));

}

}

?>

 

 

9.Now add homeAction fuction to the IndexController.php

 

public function homeAction()

{

$storage = new Zend_Auth_Storage_Session();

$data = $storage->read();

if(!$data){

$this->_redirect(‘index/index’);

}

$this->view->username = $data->username;

}

 

Create template file for this home.phtml in application/views/scripts/index/ Directory

Welcome <?=$this->username?>,<br>

This is your home page<br>

<a href='<?php $i=$this->baseUrl().”/index/logout”; echo $i; ?>’>click here to logout</a>

 

10.Now add indexAction fuction to the IndexController.php

 

public function indexAction()

{

$users = new Users();

$form = new LoginForm();

$this->view->form = $form;

if($this->getRequest()->isPost()){

if($form->isValid($_POST)){

$data = $form->getValues();

$auth = Zend_Auth::getInstance();

$authAdapter = new Zend_Auth_Adapter_DbTable($users->getAdapter(),’Users’);

$authAdapter->setIdentityColumn(‘username’)

->setCredentialColumn(‘password’);

$authAdapter->setIdentity($data[‘username’])

->setCredential($data[‘password’]);

$result = $auth->authenticate($authAdapter);

if($result->isValid()){

$storage = new Zend_Auth_Storage_Session();

$storage->write($authAdapter->getResultRowObject());

$this->_redirect(‘index/home’);

} else {

$this->view->errorMessage = “Invalid username or password. Please try again.”;

}

}

}

}

Create template file for this index.phtml in application/views/scripts/index/ Directory

<?

if(isset($this->errorMessage)){

echo $this->errorMessage;

}?>

<?

echo $this->form;

?>

<a href='<?php $i=$this->baseUrl().”/index/signup”; echo $i; ?>’>New users click here?</a>

11.Now add signupAction fuction to the IndexController.php

public function signupAction()

{

$users = new Users();

$form = new RegistrationForm();

$this->view->form=$form;

if($this->getRequest()->isPost()){

if($form->isValid($_POST)){

$data = $form->getValues();

if($data[‘password’] != $data[‘confirmPassword’]){

$this->view->errorMessage = “Password and confirm password don’t match.”;

return;

}

unset($data[‘confirmPassword’]);

$users->insert($data);

$this->_redirect(‘index/index’);

}

}

}

 

Create template file for this signup.phtml in application/views/scripts/index/ Directory

<?

if(isset($this->errorMessage)){

echo $this->errorMessage;

}?>

<h4>Sign up</h4>

<?

echo $this->form;

?>

 

12.Now add logoutAction fuction to the IndexController.php

 

public function logoutAction()

{

$storage = new Zend_Auth_Storage_Session();

$storage->clear();

$this->_redirect(‘index/index’);

}

 

13.Our model class is placed in applications/models/ Directory

Users.php

<?php

class Users extends Zend_Db_Table

{

public function checkUnique($username)

{

$select = $this->_dbTable->select()

->from($this->_name,array(‘username’))

->where(‘username=?’,$username);

$stmt = $select->query();

$result = $stmt->fetchAll();

if($result){

return true;

}

return false;

}

}

?>

 

14.Now you can run your project by put this URL on your browser bar

http://localhost/project_name/index

 

15.Thankiew

How to create draggable div

To create a draggable div .We have some basic knowledge about

  • HTML
  • CSS
  • Javascript

First create a div.The div act as an element using to drag on the screen. Div id is “dragger” use to refer in javascript.The content in between div tags are optional.you may also write ur own text.

<body><div id="dragger" class="dude">
Div  with class <b>dude</b>
<p>replace this text!</p>  </div></body>

We give it a class “dude” which define it’s attributes.

<head><style type="text/css">
.dude {
background: #FF0000;
width: 200px;
height: 200px;
position: absolute;
top: 50px;
left: 50px;
</style></head>

Secondly After making a div, now think about how to make it move.To move the division we need to know about the coordinates values of the screen.

Create one another division

<div id="co-ed">
X: <span  id="X-coord"></span><br>
Y: <span  id="Y-coord"></span>
</div>

This div use two spans which we will put the X and Y coordinates. Its attributes given in internal style manner.

.co-di{float:right;}

We use javascript to find the coordinate values of screen.

x=event.offsetX;
y=event.offsetY;
document.getElementById('X-coord').innerHTML = x  +'px';
document.getElementById('Y-coord').innerHTML = y  +'px';

All we do is set the innerHTML of the spans to be the variable and append the letters px by doing +’px’.

Now we use some event handler like onMouseMove event

<body onMouseMove="mouser(event)">

We put it in the <body> tag.Because whenever a mouse moves on the screen our function “mouser(event)” is called. We want to be able to move anywhere over the page and drag our object.An event is an argument that detect the mouse actions like the mouse click.
Now lets define our mouser(event) function’s code.
It should be in <script> tag under the <head> tag

<script language="javascript">
var x;
var y;
function mouser(event){if(event.offsetX || event.offsetY) {
x=event.offsetX;
y=event.offsetY; }
document.getElementById('X-coord').innerHTML = x  +'px';
document.getElementById('Y-coord').innerHTML = y  +'px';}
</script>

First of course <script language=”javascript”>.Some global variables x and y to used to hold the value of the coordinates. event.offsetX; event is mouse happening action and offsetX is the just the X position relative to the screen of the cursor. Y is the same.By doing this we only just track the cursor positions.

Now to make the division draggableTo drag a div we use event handler(s)
onMouseDown(); //press down
onMouseMove(); //move
onMouseUp(); //release
There are two states of div. One is dynamic means being dragged and one is static where it is not being dragged.To track the state of div we will use two variable.
Add this to your javascript.

var being_dragged = false;
var element;
if(being_dragged == true) {
document.getElementById(element).style.top = y +'px'; document.getElementById(element).style.left = x +'px';}

if(being_dragged == true).This execute the move code, else it will do nothing.It set the top and left value of the element to the cursor position.when you mouse down, the state is true, and when you mouse up the state is false.

Now let’s create our final div, adding all the event handlers.

<div id="dragger" class="dude"  onMouseDown="mouse_down(event,'dragger')" onMouseUp="mouse_up()">
Div with class <b>dude</b>
<p>replace this text!</p>
</div>

We create our div and assign it a class and id. We setup our event handlers for onMouseDown and onMouseUp. These functions we will define next (remember these go in the <head></head> tags).

First mouse_down() function.

function mouse_down(event, ele_name) {
being_dragged = true;
element = ele_name;
document.getElementById(element).style.cursor = 'move';}

 

This function is performed after pressing down on the div, it sets our state to true. So we are now being_dragged. It also sets the element to the ele_name passed in which was ‘dragger’. So element = dragger, which is our current div. The last line give us the “move” cursor when moving an item.

Now the mouse_up() function.

function mouse_up() {
being_dragged = false;
document.getElementById(element).style.cursor = 'auto';
document.getElementById(element).style.top = y  +'px';
document.getElementById(element).style.left = x +'px';}

This function takes no arguments.The first line resets the state. The 2nd line resets the cursor. Then the 3rd and 4th line set the positions. Because the top and left attributes are defined in the style tag.

THE CODE

<html>
<head>
<style>
.dude{
background-color:green;
width:200px;
height:100px;
position:relative;
color:white;
top:200;
left:200;
}
.co-di{
float:right;
}
</style>
<script language="javascript">
var x;
var y;
var element;
var being_dragged = false;
function mouser(event){
if(event.offsetX || event.offsetY){
x=event.offsetX;
y=event.offsetY;
}
document.getElementById('X-coord').innerHTML = x +'px';
document.getElementById('Y-coord').innerHTML = y +'px';
if(being_dragged == true) {
document.getElementById(element).style.left = x +'px';
document.getElementById(element).style.top = y +'px';
}}
function mouse_down(event, ele_name) {
being_dragged = true;
element = ele_name;
document.getElementById(element).style.cursor = 'move'; }
function mouse_up() {
being_dragged = false;
document.getElementById(element).style.cursor = 'auto';
document.getElementById(element).style.top = y +'px';
document.getElementById(element).style.left = x +'px';}
</script>
</head>
<body onMouseMove="mouser(event)">
<div id="dragger" onMouseDown="mouse_down(event, 'dragger')" onMouseUp="mouse_up()">
Div with class <b>dude</b>
<p>replace this text!</p>
</div>
<div>
X: <span id="X-coord"></span><br><br>
Y: <span id="Y-coord"></span>
</div>
</body>
</html>

Thankiew

How to Create Thumbnail Images using PHP

 

 

How to Create Thumbnail Images using PHP

 

This tutorial will describe how to create thumbnail images using PHP.you learn how to batch process a whole folder of images and create their thumbnails.

REQUIREMENTS

1) Latest version of PHP, MySql Database and Apache Web Server(httpd) are installed on your system.

2) You need to have the GD image library installed and activated in your PHP.

Below we will create a PHP script that contains two functions. The first one scans a provided directory for any .JPG images and, for each one, creates a thumbnail in the specified folder using the GD image functions. The second function creates an HTML file in the same directory as the script, which contains all of the thumbnails with links to the original images.

The code below creates a first function named createThumbs that will get three parameters. The first and the second is correspondingly the path to the directory that contains original images and the path to the directory in which thumbnails will be placed. The third parameter is the width you want for the thumbnail images.

The second  function named createGallery which gets two parameters (the relative paths to the directories in which images and thumbnails are stored) and creates an HTML page which contains all of the thumbnails with links to the original images.

<?php

function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )

{

// open the directory

$dir = opendir( $pathToImages );

// loop through it, looking for any/all JPG files:

while (false !== ($fname = readdir( $dir )))

{

// parse path for the extension

$info = pathinfo($pathToImages . $fname);

// continue only if this is a JPEG image

if ( strtolower($info[‘extension’]) == ‘jpg’ )

{

echo “Creating thumbnail for {$fname} <br />”;
// load image and get image size

$img = imagecreatefromjpeg( “{$pathToImages}{$fname}” );

$width = imagesx( $img );

$height = imagesy( $img );

// calculate thumbnail size

$new_width = $thumbWidth;

$new_height = floor( $height * ( $thumbWidth / $width ) );

// create a new tempopary image

$tmp_img = imagecreatetruecolor( $new_width, $new_height );

// copy and resize old image into new image

imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

// save thumbnail into a file

imagejpeg( $tmp_img, “{$pathToThumbs}{$fname}” );

}  }

// close the directory

closedir( $dir );

}
function createGallery( $pathToImages, $pathToThumbs )

{

echo “Creating gallery.html <br />”;

$output = “<html>”;

$output .= “<head><title>Thumbnails</title></head>”;

$output .= “<body>”;

$output .= “<table cellspacing=”0″ cellpadding=”2″ width=”500″>”;

$output .= “<tr>”;

// open the directory

$dir = opendir( $pathToThumbs );

$counter = 0;

// loop through the directory

while (false !== ($fname = readdir($dir)))

{

// strip the . and .. entries out

if ($fname != ‘.’ && $fname != ‘..’)

{

$output .= “<td valign=”middle” align=”center”><a href=”{$pathToImages}{$fname}”>”;

$output .= “<img src=”{$pathToThumbs}{$fname}” border=”0″ />”;

$output .= “</a></td>”;
$counter += 1;

if ( $counter % 4 == 0 ) {$output .= “</tr><tr>”; }

}  }

// close the directory

closedir( $dir );

$output .= “</tr>”;

$output .= “</table>”;

$output .= “</body>”;

$output .= “</html>”;

// open the file

$fhandle = fopen( “gallery.html”, “w” );

// write the contents of the $output variable to the file

fwrite( $fhandle, $output );

// close the file

fclose( $fhandle );

}
// call createThumb function and pass to it as parameters the path

// to the directory that contains images, the path to the directory

// in which thumbnails will be placed and the thumbnail’s width.

// We are assuming that the path will be a relative path working

// both in the filesystem, and through the web for links

createThumbs(“images/”,”thumbs/”,50);

// call createGallery function and pass to it as parameters the path

// to the directory that contains images and the path to the directory

// in which thumbnails will be placed. We are assuming that

// the path will be a relative path working

// both in the filesystem, and through the web for links

createGallery(“images/”,”thumbs/”);

?>

At first we open the directory with images and iterate through it, looking for all .JPG files. Next we create thumbnails for each image in the directory. To create a thumbnail, we read in the file using the imagecreatefromjpeg() function and calculate the new thumbnail size.imagesx() and imagesy() functions return the width and height of the image respectively. Next we create a new image using the imagecreatetruecolor(). Finally, we copy and resize the original file with the imagecopyresized() function and save thumbnail with imagejpeg().

Next function open the directory with thumbnails. Next we iterate through files in the directory and put the HTML into a string variable. The variable contents then written into a file usingfopen()fwrite(), and fclose() functions.

THANX