• About Sarwar
  • Portfolio
  • আমার বাংলা

sarwar's weblogs

~ story of web applications…..

sarwar's weblogs

Author Archives: Sarwar

print a div – open new window, print and close using javascript

05 Tuesday Oct 2010

Posted by Sarwar in JavaScript

≈ 22 Comments


I’m following the way to print a specific div inside html page.

JS Function


function printContent(div_id)
{
var DocumentContainer = document.getElementById(div_id);
var html = '<html><head>'+
               '<link href="css/template.css" rel="stylesheet" type="text/css" />'+
               '</head><body style="background:#ffffff;">'+
               DocumentContainer.innerHTML+
               '</body></html>';

    var WindowObject = window.open("", "PrintWindow",
    "width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
    WindowObject.document.writeln(html);
    WindowObject.document.close();
    WindowObject.focus();
    WindowObject.print();
    WindowObject.close();
    document.getElementById('print_link').style.display='block';
}
HTML CODE
 <div id='ad_div'> <!-- we want to print only this div and here is the link --> <a href='javascript:printContent("ad_div")' id='print_link'><?php __('Print');?></a> </div>
<pre>

this work for me 🙂

Advertisement

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

joomla Virtumart Redirect Problem Solved

16 Thursday Sep 2010

Posted by Sarwar in Joomla, PHP, Virtumart

≈ 3 Comments


I faced redirection problem on all the form of virtumart. I used joomla 1.5.15 and virtumart 1.1.4.

The problem is when user register and submit the form it move to index.php(home) page. same problem on checkout section for Next button or when I change/add shipping address, its always redirect to home page. I have found some solution someone suggest to change action url from “PHP_SELF” to “REQUEST_URI”, it worked for some form but not all the form.
I have fount one solution which is really great, here is that

1. Find the file ‘libraries/joomla/application/application.php’
2. Find these 2 lines (they are located somewhere around line #191)

// get the full request URI
$uri = clone(JURI::getInstance());

put the following code after the above line

// VM uri fix
		if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid']) || !$uri->getVar('option') && isset($_REQUEST['option'])) {
			if (!$uri->getVar('Itemid') && isset($_REQUEST['Itemid'])) {
				$uri->_query = ($uri->_query ? '&' : '').'Itemid='.(int)$_REQUEST['Itemid'];
			}
			if (!$uri->getVar('option') && isset($_REQUEST['option'])) {
				$uri->_query = ($uri->_query ? '&' : '').'option='.$_REQUEST['option'];
			}
			parse_str($uri->_query, $uri->_vars);
		}
		// end VM uri fix

Its worked, each and every form of virtumart working properly.

source: http://forum.virtuemart.net/index.php?topic=34989.msg168558#msg168558

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

How to hide label when we attempt to create cakephp form input

28 Monday Jun 2010

Posted by Sarwar in CakePHP

≈ Leave a comment

Tags

CakePHP, Form Helper, Input, Label


When I’m trying to create a input using cakephp form helper its automatically generated a label.

// when I'm trying to use 
<?=$form->input("User.name");?>
//it generated the following code
<div class="input text">
  <label for="UserName">Name</label><input type="text" id="UserName" name="data[User][name]">
</div>

I can get rid of label from the following code

<?=$form->input("User.name",array('label'=>false))?>
<div class="input text">
<input type="text" id="UserName" name="data[User][name]">
</div>

its very simple but sometime this type of issues killing our most valuable time.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

check username availability on keypress using jquery

26 Wednesday May 2010

Posted by Sarwar in Ajax, JavaScript, jquery, PHP

≈ 3 Comments

Tags

ajax, availability, jquery, keypress, keyup, validation


Username or email availability or any other types of availability check we can do in this way. When user type on a text box an ajax request has made and check what if its available or not.  we only required jquery.js

HTML CODE:

<input name="username" type="text" id="username" />
<label id="user_msg" style="color:#CC0000;"></label>

Javascirpt:

$(document).ready(function() {

		var timeOut = null;	// this used for hold few seconds to made ajax request

		var loading_html = '<img src="ajax-loader.gif" />'; // just an loading image or we can put any texts here

		//when button is clicked
		$('#username').keyup(function(e){

			// when press the following key we need not to make any ajax request, you can customize it with your own way
			switch(e.keyCode)
			{
				//case 8:   //backspace
				case 9:		//tab
				case 13:	//enter
				case 16:	//shift
				case 17:	//ctrl
				case 18:	//alt
				case 19:	//pause/break
				case 20:	//caps lock
				case 27:	//escape
				case 33:	//page up
				case 34:	//page down
				case 35:	//end
				case 36:	//home
				case 37:	//left arrow
				case 38:	//up arrow
				case 39:	//right arrow
				case 40:	//down arrow
				case 45:	//insert
				//case 46: 	//delete
					return;
			}
			if (timeOut != null)
			    clearTimeout(ajaxCallTimeoutID);
			timeOut = setTimeout(is_available, 1000);  // delay delay ajax request for 1000 milliseconds
			$('#user_msg').html(loading_html); // adding the loading text or image
		});
  });
function is_available(){
	//get the username
	var username = $('#username').val();

	//make the ajax request to check is username available or not
	$.post("availability.php", { username: username },
	function(result)
	{
		if(result != 0)
		{
			$('#user_msg').html('Not Available');
		}
		else
		{
			$('#user_msg').html('<span style="color:#006600;">Available</span>');
		}
	});

}

PHP: Put your way to searching, you can make any array search or you can check it from database or flat file. I check it from database here is the code

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('db_name');
$username = mysql_real_escape_string($_POST['username']);
$result = mysql_query('select username from user_table where username = "'. $username .'"');
$cnt = mysql_num_rows($result);
print($cnt);
?>

Its work with me very well 🙂

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

SVN setup on rackspace clould (Debian 5)

06 Thursday May 2010

Posted by Sarwar in SVN

≈ 1 Comment

Tags

Checkout, Debian, Linux, SVN


Here is the following steps for setup svn server on debian platform. The setup uses svn+ssh

$ apt-get update
$ apt-get install subversion
$ apt-get install libapache2-svn

The package libapache2-svn will install the subversion WebDAV apache module.

The following command used for creating repository

$ mkdir /var/repos/
$ svnadmin create /var/repos/project

Create user and group and assign to user to a group


$ adduser username1 //give the user name and next you'll get some options like password and others just give and continue
$ adduser username2
$  groupadd svngroup // just create  group for svn users
$ addgroup username1 svngroup // add the user username1 to groupsvn
$ addgroup username2 svngroup // add the user username2 to groupsvn

The repository directory need to get proper permission


$ chown -R :svngroup /var/repos/
$ chmod -R 775 /var/repos/

Make the ssh connectivity

$ mkdir ~/.ssh/
$ cd ~/.ssh/
$ ssh-keygen -t dsa
$ cat ~/.ssh/id_dsa.pub | ssh username1@yourdomain.com // or use id of your server

Need to use ssh agent to keep user authenticated,


$ ssh-agent
$ ssh-add
$ ssh username1@yourdoman.com

Done, you can import, checkout from her or you can do from your local machine. I used smartSVN to setup here is the link i’m using for connect

URL: svn+ssh://yourdomain.com/var/repos/project or
Username: username1
Password: mypassword

We can use svnserve by the following command

$  svnserve -d

this way I could connect to server with smartSVN client successfully and I could checkout, commit and doing everything what we svn supports.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

jQuery Mega Menu Customization and Fixed Conflict with jQuery UI

14 Wednesday Apr 2010

Posted by Sarwar in CSS, JavaScript, jquery, jQuery UI

≈ 6 Comments

Tags

conflict, customization, jkmegamenu, jquery, menu


Recently I’ve used jQuery Mega Menu on a site. The default style for this menu it appear from left corner to below the link/button when mouse is over. But I wanted it appear above the link/button when mouse is over, here is the code we need to change  on line 76 of jkmegamenu.js file


//existing line
// megamenu.offsety= megamenu.$anchorobj.offset().top
//Change to
megamenu.offsety= megamenu.$anchorobj.offset().top - (megamenu.$menuobj.outerHeight() + megamenu.$anchorobj.outerHeight())

Just subtract top position with total of menu object height and anchor so the bottom line of new box will appear just above the link/button.

But I got some problem when I was adding this code to a page where already have jQuery UI  items, both jquery ui tabs/accordion/dialog…etc. and mega menu wasn’t work. After check the mega menu js file I got the solution, we just need to comemnted out or remove the following line at the begianing of file


//jQuery.noConflict();

Done, everything working with me properly hope it will work with you as well 🙂

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

how to cakephp in a sub-directory, access it from root using .htaccess

16 Tuesday Mar 2010

Posted by Sarwar in CakePHP, PHP

≈ 13 Comments

Tags

.htaccess, CakePHP, sub-directory, url


Sometime we may need to put cakephp in a sub directory insted of document root directory, and we need to get the site from root.
Our document root directory is /httpdocs/ and we put the cakephp inside it /httpdocs /cake_sub/ and we want access the site from http://www.my-domain-name.com not http://www.my-domain-name.com/cake_sub

1. In this case we need to create a .htaccess file and put it to /httpdocs/ and the content is as follow

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule    ^$ cake_sub/app/webroot/    [L]
RewriteRule    (.*) cake_sub/app/webroot/$1 [L]
</IfModule>

So we need to on the RewriteEngine Now we need to edit the .htaccess files from the following locaiton

  • cake_sub/
  • cake_sub/app
  • cake_sub/webroot

2. Need to edit the .htaccess from /httpdocs/cake_sub as following


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
3. Need to edit the .htaccess from /httpdocs/cake_sub/app as following
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/app/
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
</IfModule>

4. Need to edit the .htaccess from /httpdocs/cake_sub/app/webroot as following

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cake_sub/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>


Done, It worked with me and hope it’ll work with you too. I just put the document root httpdocs and sub directory name as an example.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

make top and bottom position fixed in IE 6

13 Wednesday Jan 2010

Posted by Sarwar in CSS

≈ 3 Comments

Tags

bottom, CSS, html, IE6, Position Fixed, Top


Position fixed is not supported by IE 6, I searched about it in many sites and get the following to be fixed.

here is the html code

<html>
<body>
<div id='banner'>
Top always fixed
</div>
<div id='contents'>
Put your contents here
</div>
<div id='footer'>
Footer or other contents
</div>
</body>
</html>

here is the css for above html

* html #banner
{
position: absolute;
top: expression(0+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px');
left: expression(0+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px');
padding-bottom:2px;
padding-top:2px;
background:#000000;
height:35px;
width:100%;
 z-index:1000;
}
* html #footer
{
position: absolute;
left: expression(0+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px');
top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop +(documentElement.clientHeight-this.clientHeight) : document.body.scrollTop +(document.body.clientHeight-this.clientHeight));
height: 32px;
 width: 100%;
font-size: 12pt;
background: #000000;
overflow: hidden;
 z-index:1000;
}

You can do the rest of thing as your own. The two css gives you to fixed the position in IE 6, for the other browser you can easily use “Position:Fixed;” its work with me hope it’ll work for you 🙂

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

passing get variable in cakephp pagination url

12 Tuesday Jan 2010

Posted by Sarwar in CakePHP, Framework, PHP

≈ 17 Comments

Tags

argument, CakePHP, GET, pagination, paginator, parameter passed, PHP


For searching we many need to pass variable like ?keyword=test, and we may need to add pagination withen the search, Here I describe multiple cases where we may need to use pagination and how we manage the url for pagination when we make some searching

Case 1: if the url like the following
http://www.mydomain.com/controller/method/?keyword=test1&opt=test2

In this case we need to add the paginator option like this
First we retrive the passing variable and assign value, we can get it from “$this->params[‘url’]

$urls = $this->params['url']; $getv = "";
foreach($urls as $key=>$value)
{
if($key == 'url') continue; // we need to ignor the url field
$getv .= urlencode($key)."=".urlencode($value)."&"; // making the passing parameters
}
$getv = substr_replace($getv ,"",-1); // remove the last char '&'

Now we have the all get parameter, lest assign this to paginator option

$paginator->options(array('url' => array("?"=>$getv)));

Now all the pagination links always taking this get parameter so now if we gos to the next page the url look like this
http://www.mydomain.com/controller/method/page:2?keyword=test1&opt=test2

Now If we need passing an argument as id like the following
http://www.mydomain.com/controller/method/1/?keyword=test1&opt=test2
where 1 is an id or something we get this 1 from $this->passedArgs[0] So now we have to set the paginator option like this

$paginator->options(array('url' => array($this->passedArgs[0],"?"=>$getv)));

If we have passed more than one argument, we need to take it

$pass_argument = $this->passedArgs[0]."/"$this->passedArgs[1]."/".$this->passedArgs[2]."/";
$paginator->options(array('url' => array($pass_argument,"?"=>$getv)));

It depend on you how much you want to passed the argument, if you faced any problem print the $this->passedArgs and see how it organize the argument. Its really easy and I’ve already used it. Cheers

–new update
I got the idea from comments, here is update, the following code will useful for multiple arguments or params.

//extract the get variables
$url = $this->params['url'];
unset($url['url']);
$get_var = http_build_query($url);

$arg1 = array(); $arg2 = array();
//take the named url
if(!empty($this->params['named']))
$arg1 = $this->params['named'];

//take the pass arguments
if(!empty($this->params['pass']))
$arg2 = $this->params['pass'];

//merge named and pass
$args = array_merge($arg1,$arg2);

//add get variables
$args["?"] = $get_var;

$paginator->options(array('url' => $args));

done.. But I’m trying to make better solution, will update it soon.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

how to get/configure file/image browser for tinymce editor

08 Wednesday Jul 2009

Posted by Sarwar in JavaScript, PHP, tinymce

≈ 34 Comments

Tags

image browser, session, tinymce, upload, WYSIWYG Editor


tinybrowser is great plugins for tinymce and we can easily upload images/files and file browser.  It’s work with tinyMCE v3.2. I’ve describe the detail configuration here.

  • Download tinymce and extract.
  • Download tinybrowser, its distributed under the GNU General Public License.
  • Extract and copy to \tiny_mce\plugins\
  • Open config_tinybrowser.php file and set the upload directory

$tinybrowser['path']['image'] = '/upload/images/'; // Image files location - also creates a '_thumbs' subdirectory within this path to hold the image thumbnails
$tinybrowser['path']['media'] = '</span><span style="color: #800000;">/upload/images/</span><span style="color: #800000;">'; // Media files location
$tinybrowser['path']['file']  = '</span><span style="color: #800000;">/upload/images/</span><span style="color: #800000;">'; // Other files location

You can change the upload path dynamically, we’ll discuss it end of this session.

  • Ensure that the upload directories are writable (0777 permission)
  • You have to call “tb_tinymce.js.php” before calling “tiny_mce.js”

<script language="javascript" type="text/javascript" src="<?php echo url::js_dir()?>tiny_mce/plugins/tinybrowser/tb_tinymce.js.php>"></script>
<script type="text/javascript" src="<?php echo url::js_dir()?>tiny_mce/tiny_mce.js"></script>
  • In you initialization of tiny_mce you have to add file_browser_callback : “tinyBrowser”,
  • The following is the full code, the bold is for tinybrowser plugins

<script language="javascript" type="text/javascript" src="js/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php>"></script>
<script type="text/javascript" src="js/tiny_mce/tiny_mce.js"></script></span>

<span style="color: #993300;"><textarea id="adesc" name="adesc"></textarea></span>

<span style="color: #993300;"><script>
tinyMCE.init({
// General options
mode : "textareas",
mode : "exact",
elements : "adesc",
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,advhr,advimage,advlink",
<strong> file_browser_callback : "tinyBrowser",</strong></span>

<span style="color: #993300;">theme_advanced_buttons1 : "forecolor,backcolor,|,bold, italic,underline,strikethrough,| ,justifyleft,justifycenter,justifyright,justifyfull, styleselect,formatselect,fontselect, fontsizeselect",
theme_advanced_buttons2 : "pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent, blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup, help,code,|,insertdate, inserttime, preview",
<strong> theme_advanced_buttons3 : "",</strong></span>

<span style="color: #993300;">theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : false,
<strong>convert_urls : false</strong>,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",</span>

<span style="color: #993300;">// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",</span>

<span style="color: #993300;">// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
  • Click on the image button, a popup window open and you can see an icon appear beside image url click on and a another new window open which is our image browser, we can browse images and upload image from there.
  • Now If you run it can work 🙂

Path Change While Add imge to editor:
When we upload an image and put it to editor its path has been changed. If we save the output to database, and we need to show in different location then we have faced some problem, Just add convert_urls : false  to tinyMCE.init(). So the path will not be changed.

Session Control:
We can use session in tinybrowser. See …/tiny_mce/plugins/tinybrowser/config_tinybrowser.php

//session_start();
//$tinybrowser['sessioncheck'] = 'authenticated_user'; //name of session variable to check

Just comment out the above line and the additional line.

$_SESSION[$tinybrowser['sessioncheck']] = "YES";

New you can uses session here.

Dynamic Upload Directroy:
We may need dynamic upload directory, like each user has their own upload folder. It can possible by using session variable.

Step 1:
Just add a get parametter while we diclearning the tb_tinymce.js.php the say in php, $upload_path = “/user1/dir/upload/”

<script language="javascript" type="text/javascript" src="js/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php?upload_path=<?=urlencode($upload_path);?>"></scrip>

Step: 2
Open file “/js/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php” and add the following two line at the top to page.

session_start();
$_SESSION['upath'] = $_GET['upload_path'];

Step: 3
Open “js/tiny_mce/plugins/tinybrowser/config_tinybrowser.php” and change the assignment op upload directory like the following [Note you must comment out the session strat on this page as i’ve describe it above]

$tinybrowser['path']['image'] = $_SESSION['upath'].'images/'; // Image files location - also creates a '_thumbs' subdirectory within this path to hold the image thumbnails
$tinybrowser['path']['media'] = $_SESSION['upath'].'media/'; // Media files location
$tinybrowser['path']['file']  =$_SESSION['upath'].'files/'; // Other files location

I’ve successfully run it and use for different directory for different modules. Just assign value to $upload_path, it depend on you how you change the path but make sure all upload directory always writable (permission 0777)

Share this:

  • Tweet
  • Email

Like this:

Like Loading...
← Older posts
Newer posts →

Author

  • Sarwar

Categories

  • .htaccess
  • Apache
  • API
  • CSS
  • Debug
  • Framework
    • CakePHP
  • HTML
  • JavaScript
    • Ajax
    • ckeditor
    • jquery
    • jQuery UI
    • tinymce
  • Joomla
    • Virtumart
  • Linux
  • MySQL
  • PHP
  • SVN
  • Twitter
  • WHM/cPanel
View Sarwar Hossain's profile on LinkedIn
Follow bdsarwar on Twitter

Tweets

Tweets by bdsarwar

Flickr Photos

From Helipad ViewAbove the CloudHillNear to SkySunset Moment#sunset #beach #ocean #coxsbazar#jamroll #food #deliciousfood #homemade  #homemadefood#seaside #ocean #oceanview #travelphotography #coxsbazar #bayofbengal #travel #longestbeach#beach #lifeguard #seaside #holiday #tour #longestbeach #travel #travelphotography #coxsbazar #bayofbengal#resort #mountains
More Photos

Archives

  • February 2012 (1)
  • January 2012 (2)
  • August 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (2)
  • April 2011 (1)
  • March 2011 (3)
  • December 2010 (3)
  • November 2010 (1)
  • October 2010 (4)
  • September 2010 (1)
  • June 2010 (1)
  • May 2010 (2)
  • April 2010 (1)
  • March 2010 (1)
  • January 2010 (2)
  • July 2009 (1)
  • January 2009 (1)
  • August 2008 (1)

Recent Comments

  • Kush on how to cakephp in a sub-directory, access it from root using .htaccess
  • Mr Griever on Access session data in a model -cakephp
  • apnarahimyarkhan on cakephp- CONCAT in query, Virtual Fields and make a drop down
  • Toko Kunci Pintu Murah on set & reset form text value onfocus, onblur, onclick using javascript
  • nevitaputri1.doodlekit on cakephp- CONCAT in query, Virtual Fields and make a drop down
  • RSS - Posts
  • RSS - Comments

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • sarwar's weblogs
    • Join 328 other followers
    • Already have a WordPress.com account? Log in now.
    • sarwar's weblogs
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d bloggers like this: