Locate phone location with GP Aloshbei location API and visualize with google maps API

We have built our main Aloashbei class in the previous post. Now we will extend it to locate any GrameenPhone number. But currently, as a developer you can only track your number for testing purpose.

File Structure:

  • class.Aloashbei.php
  • class.AloashbeiLBS.php
  • location.php
  • includes/WebService_Aloashbei_LBS_WS.wsdl

Read the rest of this entry »

PHP class for sending, receiving and checking SMS status with GrameenPhone’s Aloashbei API

I saw everyone is participating in the GrameenPhone Aloashbei API contest and it’s began and I am late :P . So why not doing something that makes other’s life easy? So I decided to make a PHP class to do that job for you. You don’t need to know how to work with SOAP. Just instantiate a class, set the parameter and send, VOILA!!!

With the Aloashbei SMS API, you can send SMS, Check the SMS status and receive SMS. You can track location of any GP mobile number with the Location Locator API. It will provide you the longitude and latitude of the phone numbers current position. You can send MMS with the MMS API. You can charge any user who buys any content through the Charging API.

So we are going to build php class that will do these thing easily. Here I will built the SMS class. We can send SMS to any number and if it’s successful, it will return us a message ID. With this message ID, we can check the status of that sent message. To make a complete Aloashbei API class, we’ll first make a basic class and will extend it for other purposes. So here is the basic class that we will extend. It’ll hold the values for setting up the variables and will set user/password initially.

The file Structure:

  • class.Aloashbei.php
  • class.AloashbeiSMS.php
  • sms.php
  • includes/WebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl

Read the rest of this entry »

Bangla date as a PHP class

I have worked with Bangla date a long time ago. The first initiative was to make a extension for forum engine punBB. After that, i made a javascript widget to display Bangla date in any site. The third initiative was to make a facebook application that shows current Bangla date to your facebook profile.

I always wanted to publish this as a PHP Class but never got that chance to do so. After a long time i worked with Bangla date today and finally created a PHP Class to use it anywhere by anyone. Sorry for the late.

Usage:

<?php
include_once 'class.banglaDate.php';
$bn_date = new BanglaDate(time());
$date = $bn_date->get_date();
?>

You will get an array of converted date in Bangla.

A few things needed to know. Bangla date counted or changes after the sun rise. That means, where English date changes at 12′O clock at the night, Bangla date changes at the morning after the sunrise.

Class Constructor:
This class constructor has 2 parameters. The first one in timestamp and the second one is the hour of changing the date. If you want to change the Bangla date like English at 12’0 clock at the night, you should use $bn_date = new BanglaDate(time(), 0). But if you want to change the date at 6′O clock at the morning, use as $bn_date = new BanglaDate(time(), 6). If you don’t pass the second parameter, the default value is 6. Use as you like.

After Creating the class object, you can set another date using set_time() like $bn_date->set_time(time(), 4);

Bangla Date class on PHPClasses.org

Image upload & Validation: My first class to phpclasses.org

Recently i had to work with image uploading on my some projects. The issue was to upload the user avatar and rename the avatar’s with their userid. So that it will be easy to work with avatar system.

I first used this idea to one of my project and i did this with procedural method. But again on my current projects i need this facility again. So i thought to finish the job for the last time and decided to make a class to re-use the codes. So here i go…

Firstly, i use my class constructor to define the maximum file size, width, height and also the upload directory. So now create a instance of my class like this-

<?php
//$image = new ImageUloader($max_size, $max_width, $max_height, $upload_dir)
$image = new ImageUploader(26, 200, 150, 'images/avatar/');
?>

Now you need to set the image name to upload. Don’t be afraid, it’s the file input field name of your html form if you have a input file name like this -

<form enctype="multipart/form-data" action="" method="POST">
	<input name="input_field_name" type="file" />
    <input type="submit" name="submit" value="Change Avatar" />
</form>

Then you need to setup the image name like this

<?php
$image->setImage('input_field_name');
?>

Now it’s time for validation process :D
you can check the image size, width, height and also file type by the following method

<?php
$image->checkSize();
$image->checkHeight();
$image->checkWidth();
$image->checkExt();
?>

This method’s return true, if the condition are passed. We have permitted to use only jpg, jped, png and gif files. So lets use them

<?php
if(!$image->checkSize())
	$errors[] = "File size is Big";

if(!$image->checkHeight())
	$errors[] = "File height is Big";

if(!$image->checkWidth())
	$errors[] = "File width is Big";

if(!$image->checkExt())
	$errors[] = "File ext is not supported";
?>

So if the condition are passed, we will set the name of the file to be uploaded and now it’s the time to check if there any file with the same user id. If their is any file with same user id, we delete them for the sake of our need and upload them. By deleting the existing file with same user id clears the confusion of repeating same file name with same user id. Because, their is a possibility to found images with same file name but with different extensions.

<?php
if(!isset($errors)){
		$image->setImageName($userid);
		$image->deleteExisting();
		$image->upload();

		echo "<h2>Avatar Changed Successfully</h2>";
	}
	else{
		echo "<h2>You must correct the errors to proceed</h2><br>";
		print_r($errors);
	}
?>

So here is the complete code for validating and uploading

<?php
if(isset($_POST['submit'])){
	require 'class.imageupload.php';

	//$image = new ImageUloader($max_size, $max_width, $max_height, $upload_dir)
	$image = new ImageUploader(26, 200, 150, 'images/avatar/');
	$image->setImage('input_field_name');

	if(!$image->checkSize())
		$errors[] = "File size is Big";

	if(!$image->checkHeight())
		$errors[] = "File height is Big";

	if(!$image->checkWidth())
		$errors[] = "File width is Big";

	if(!$image->checkExt())
		$errors[] = "File ext is not supported";

	if(!isset($errors)){
		$image->setImageName($userid);
		$image->deleteExisting();
		$image->upload();

		echo "<h2>Avatar Changed Successfully</h2>";
	}
	else{
		echo "<h2>You must correct the errors to proceed</h2><br>";
		print_r($errors);
	}
}
?>

<form enctype="multipart/form-data" action="" method="POST">
	<input name="input_field_name" type="file" />
    <input type="submit" name="submit" value="Change Avatar" />
</form>

Download the class form here