Category Archives: PHP

PHP : Installing PhpUnit

Execute CMD as administrator

Go to php directory

pear install phpunit/PHPUnit
(Optional)
pear channel-discover pear.phpunit.de
pear install --alldeps phpunit/PHPUnit
Advertisements

PHP : CDR stuff

// 28, 29, 30

	$fDate = '12/02/28';
	$fTime = '20:30';
	$tDate = '12/03/01';
	$tTime = '21:30';
	
	$from = getYMDHm($fDate, $fTime);		
	$fromTimeStamp = mktime($from['hour'], $from['minute'], $from['second'], $from['month'], $from['day'], $from['year']);
	$to = getYMDHm($tDate, $tTime);
	$toTimeStamp = mktime($to['hour'], $to['minute'], $to['second'], $to['month'], $to['day'], $to['year']);

	$_30min = array('timeUnit' => 48, 'frequency' => 1800); // 24 * 2, 60 * 30
	$_60min = array('timeUnit' => 24, 'frequency' => 3600); // 24 * 1, 60 * 30 * 2
	$_1440min = array('timeUnit' => 1, 'frequency' => 86400); // 24 * (1 / 24), 60 * 60 * 24
	
	//$cdrs = getCdrs30Minutes($fromTimeStamp, $toTimeStamp);
	//$cdrs = getCdrFileNames($fromTimeStamp, $toTimeStamp, (24 * 2), (60 * 30));
	$cdrs = getCdrFileNames($fromTimeStamp, $toTimeStamp, $_1440min['timeUnit'], $_1440min['frequency']);
	foreach ($cdrs as $cdr) {
		echo '<br />' . $cdr;
	}
	
	echo '<br />done';
	//$fromDate = date('Y/m/d H:i:s', $fromTimeStamp);	
	//$toDate = date('Y/m/d H:i:s', $toTimeStamp);	
	//echo $fromDate . '<br />';
	//echo $toDate . '<br />';
	
	function getCdrs30Minutes($from, $to) {
		$numUnits = round(($to - $from) / 86400 * 24 * 2) + 1;
		//echo '<br />' . date('Y/m/d H:i:s', $from);
		//echo '<br />' . date('Y/m/d H:i:s', $to);
		$cdrs = array();        
		for ($i = 0; $i < $numUnits; $i++) {
			$cdr = date('Y/m/d H:i:s', ($from + ($i * 60 * 30)));
			$date_time = explode(" ", $cdr);
			$date = explode("/", $date_time[0]);
			$time = explode(":", $date_time[1]);
			$cdrs[] = substr($date[0], -2) . $date[1] . $date[2] . $time[0] . $time[1];
			//echo $cdr;
		}        
		return $cdrs;
	}
	
	function getCdrs60Minutes($from, $to) {
		$numUnits = round(($to - $from) / 86400 * 24) + 1;
		//echo '<br />' . date('Y/m/d H:i:s', $from);
		//echo '<br />' . date('Y/m/d H:i:s', $to);
		$cdrs = array();        
		for ($i = 0; $i < $numUnits; $i++) {
			$cdr = date('Y/m/d H:i:s', ($from + ($i * 60 * 60)));
			$date_time = explode(" ", $cdr);
			$date = explode("/", $date_time[0]);
			$time = explode(":", $date_time[1]);
			//$cdrs[] = substr($date[0], -2) . $date[1] . $date[2] . $time[0] . $time[1];
			$cdrs[] = substr($date[0], -2) . $date[1] . $date[2] . $time[0] . '*';
		}        
		return $cdrs;
	}
	
	function getCdrs1440Minutes($from, $to) {
		$numUnits = round(($to - $from) / 86400) + 1;
		//echo '<br />' . date('Y/m/d H:i:s', $from);
		//echo '<br />' . date('Y/m/d H:i:s', $to);
		$cdrs = array();        
		for ($i = 0; $i < $numUnits; $i++) {
			$cdr = date('Y/m/d H:i:s', ($from + ($i * 60 * 60 * 24)));
			$date_time = explode(" ", $cdr);
			$date = explode("/", $date_time[0]);
			$time = explode(":", $date_time[1]);
			//$cdrs[] = substr($date[0], -2) . $date[1] . $date[2] . $time[0] . $time[1];
			$cdrs[] = substr($date[0], -2) . $date[1] . $date[2] . '*';
		}        
		return $cdrs;
	}
	
	function getCdrFileNames($from, $to, $timeUnit, $frequency) {
		echo "$from, $to, $timeUnit, $frequency";
		$numUnits = round(($to - $from) / 86400  * $timeUnit) + 1;
		$cdrs = array();        
		for ($i = 0; $i < $numUnits; $i++) {
			$cdr = date('Y/m/d H:i:s', ($from + ($i * $frequency)));
			$date_time = explode(" ", $cdr);
			$date = explode("/", $date_time[0]);
			$time = explode(":", $date_time[1]);
			$cdrs[] = substr($date[0], -2) . $date[1] . $date[2] . $time[0] . $time[1];
			//echo $cdr;
		}        
		return $cdrs;
	}
	
	function getYMDHm($date_, $time_) {
		$date = explode('/', $date_);
		$time = explode(':', $time_);
		// TODO: fix 20
		return array('year' => '20' . $date[0], 'month' => $date[1], 'day' => $date[2], 'hour' => $time[0], 'minute' => $time[1], 'second' => 0);
	}
	
	function getCdr($cdr) {
		$date_time = explode(" ", $cdr);
		$date = explode("/", $date_time[0]);
		$time = explode(":", $date_time[1]);
		return substr($date[0], -2) . $date[1] . $date[2] . $time[0] . $time[1];
	}

SOAP : NuSOAP

Server Code

<?php
require_once ('../lib/nusoap.php');
$server = new soap_server();
$namespace = 'urn:dingdongtictic';
$server -> configureWSDL('ddtt-gen-prov', $namespace);

$server->wsdl->addComplexType(
	'parameter',
	'complexType',
	'struct',
	'sequence',
	'',
	array(
		'key' => array(
			'name' => 'key',
			'type' => 'xsd:string',
		),
		'value' => array(
			'name' => 'value',
			'type' => 'xsd:string',
		),
	)
);

$server->wsdl->addComplexType(
	'parameters',
	'complexType',
	'struct',
	'sequence',
	'',
	array(
		'param' => array(
			'name' => 'param',
			'type' => 'tns:parameter',
			'maxOccurs' => 'unbounded',
			'minOccurs' => '0',
		)
	)
);

$server->wsdl->addComplexType(
	'responseType',
	'complexType',
	'struct',
	'sequence',
	'',
	array(
		'resultCode' => array(
			'name' => 'resultCode',
			'type' => 'xsd:string',
		),
		'resultDesc' => array(
			'name' => 'resultDesc',
			'type' => 'xsd:string',
		),
	)
);

$server->register('login',                							// method name
    array('userName' => 'xsd:string', 'password' => 'xsd:string'),  // input parameters
    array('response' => 'tns:responseType'),    					// output parameters
    $namespace,                      	  							// namespace
    $namespace . '#login',                							// soapaction
    'rpc',                                							// style
    'encoded',                            							// use
    'This command will be used to get the authentication key'      	// documentation
);

$server->register('activateService',
    array('identifier' => 'xsd:string', 'paramMap' => 'tns:parameters'),
	array('response' => 'tns:responseType'),
	$namespace,
	$namespace . '#activateService',
	'rpc',
	'encoded',
	'This command will be used for initial activation & reactivation'
);

function login($username, $password) {
        return array('resultCode' => $username, 'resultDesc' => $password);
}

function activateService($identifier, $paramMap) {
		return array('resultCode' => $identifier, 'resultDesc' => print_r($paramMap, TRUE));
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>

Client Code

<?php

require_once 'lib/nusoap.php';

class GenProxy {

	private static $singleton;
	private $client;
	private $wsdl_path;
	private $username;
	private $password;
	private $authKey;

	private function __construct($url) {
		$this -> wsdl_path = $url;
		$this -> client = new nusoap_client($this -> wsdl_path, true);
	}

	public static function getProxy($url) {
		if (!isset(self::$singleton)) {
			self::$singleton = new GenProxy($url);
		}
		return self::$singleton;
	}

	public function getWsdl() {
		echo $this -> wsdl_path;
	}

	// change the access modifier to private
	public function getAuthKey() {
		echo $this -> authKey;
	}

	private function debugRequest() {
		echo '<h2>Request</h2>';
		echo '<pre>' . htmlspecialchars($this -> client -> request, ENT_QUOTES) . '</pre>';
	}

	private function debugResponse() {
		echo '<h2>Response</h2>';
		echo '<pre>' . htmlspecialchars($this -> client -> response, ENT_QUOTES) . '</pre>';
	}

	private function debugResult($client, $result) {
		if ($client -> fault) {
			echo '<h2>Fault</h2><pre>';
			print_r($result);
			echo '</pre>';
		} else {
			// Check for errors
			$err = $client -> getError();
			if ($err) {
				// Display the error
				echo '<h2>Error</h2><pre>' . $err . '</pre>';
			} else {
				// Display the result
				echo '<h2>Result</h2><pre>';
				print_r($result);
				echo '</pre>';
			}
		}
	}

	public function login($username, $password) {
		$this -> username = $username;
		$this -> password = $password;
		$result = $this -> client -> call('login', array('userName' => $username, 'password' => $password));
		$this -> debugRequest();
		//$this -> debugResponse();
		// check result for errors
		// store auth key
		$this -> authKey = $result['resultCode'];
	}

	public function activate() {
		$arr = array('identifier' => '506', 'paramMap' => array('param' => array( array('key' => 'key1', 'value' => 'value1'), array('key' => 'key2', 'value' => 'value2'))));
		echo print_r($arr);
		$result = $this -> client -> call('activateService', $arr);
		$this -> debugRequest();
		$this -> debugResponse();
		//echo $result['resultDesc'];
	}

	public function deactivate() {
		echo $this -> client -> call('deactivateService', array('identifier' => '506', 'paramMap' => array('key' => 'key 1', 'value' => 'value 1')));
	}

	public function modify() {
		echo $this -> client -> call('modifyService', array('identifier' => '507', 'oldParamMap' => 'should be an array type thing', 'newParamMap' => 'should be an array type thing'));
	}

}
?>

Usage

<?php
require_once 'GenProxy.php';
$proxy = GenProxy::getProxy(<path to server wsdl>);
$proxy -> login('banda', 'bandapwd');
$proxy -> activate();
$proxy -> getAuthKey();
?>
Tagged

Yii : How to get raw POST

public function actionIndex() {
		//print_r($_POST);
		if (Yii::app()->request->isAjaxRequest) {
			$postdata = file_get_contents("php://input");
			if ($postdata) {
        		// do something
         		$outObj = array('success' => true);
      		echo CJSON::encode($outObj);
			}
		}
}

“php://input allows you to read raw POST data.
It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives.”
php://
took it from StackOverflow

Tagged , , ,

Yii : How to call a controller of a module

http://localhost/mmsx/index.php?r=mms/service

mms – module
service – controller

index action of service controller will be called

Tagged ,

Joomla : error reporting

Strict Standards: Accessing static property JCache::$_handler as non static

To disable error reporting

  1. Login as an Administrator
  2. Go to Main Menu bar
  3. Site drop down menu
  4. Click on Global Configuration menu item
  5. Under Global Configuration click on Site menu
  6. Click on Error Reporting in Server settings area
  7. Select none
Tagged ,

XAMPP : Access forbidden

XAMPP Access Forbidden

I got this message because i have changed the document root in httpd.conf (xampp\apache\conf)