\n";
}
$out = str_replace('~HEADERS~',$headerHTML,(str_replace('~DATAROWS~',$datarowHTML,$tableHTML)));
return $out;
}
}
if ( ! function_exists('getArrayElements'))
{
/**
* getArrayElements() function
*
* Returns wanter array element, if exists
*
* @param $array , the array
*
* @param $key , key to be checked
*
* @return String, array element value if found, otherwise an empty string
*/
function getArrayElements($array,$key)
{
if(is_array($array))
{
if(array_key_exists($key,$array))
{
return $array[$key];
}
else
return '';
}
else
return '';
}
}
/**
* input() function
*
* Prepares and echoes HTML Code for Input feilds
*
* @param $data Data Array
*
* @param $pkval , Value of the primary key field of data record, to identity record
*
* @param $field, Name of database table field
*
* @param $type Optional, type of input tag, Default Text
*
* @return void
*/
function input($data,$pkval,$field,$type="text")
{
$dataset = $data['dataset']['result_set'];
$pk = explode(",",$data['dataset']['metadata']['PK']);
$nrows = sizeof($dataset) - 1;
for($ix=1;$ix<=$nrows;$ix++)
{
if($ix > 0)
{
unset($pk_g);
foreach($pk as $col){
$pk_g[] = $dataset[$i][$col];
}
$pk_grid=join("_",$pk_g);
unset($pk_g);
if($pk_grid == $pkval)
{
echo '';
}
}
$pk_grid="";
$ix++;
}
}
////////////////////////////////////////////////////////////////////////////////////////////
// old drop down function for dinishika's refference . Pls delete this section after reffering them.
/*
*
*
function dropdown($data,$selectByText=null,$selectByVal,$label, $fieldName, $display,$format='html',$keyfield=true,$multiple=false,$skipfield=false,$optionsOnly=false)
{
$dataset = $data['dataset']['result_set'];
$pk = $data['dataset']['metadata']['PK'];
if ($selectByText && $selectByVal) $selectByText = null; // Choos ByVal if both provided //WCD
//if its calling for multiple select box with or without default selected ids
// IF $selected is a sring of comaseperated values we do not need all below code
switch ($format) {
case 'html':
if (!is_array($pk)) $pk = explode(',', $pk);
$nrows = sizeof($dataset) - 1;
$mul = ($multiple)?'[]':'';
if(!$optionsOnly) {
echo '',"\n";
break;
case 'xml':
if (!is_array($pk)) $pk = explode(',', $pk);
$nrows = sizeof($dataset);
if($multiple) { $type='multiselect'; } else { $type='select';}
$name=$fieldName;
if($skipfield==true) {
$name=$fieldName.'_skip';
}
if(!$optionsOnly) {
echo '';
}
if(empty($selectByVal)&& empty($selectByText)){
echo "\n\t",'';
}else{
echo "\n\t",'';
}
for($ix=1;$ix<=$nrows;$ix++){
if($ix > 0)
{
$val='';
foreach($pk as $key){
$val .= $dataset[$ix][$key].'_';
}
$val=trim($val,'_');
$foundText= false; $foundVal=false;
if(!empty($selectByVal)|| !empty($selectByText)){
//Error suppression used to suppres the empty string error. WCD
$foundText = @strpos($selectByText,(string)$dataset[$ix][$fieldName]);
//(strcasecmp($selectByText, (string)$dataset[$ix][$fieldName]) == 0)? $foundText = true :$foundText = false ;
$foundVal = strpos($selectByVal,$val) ;
//(strcasecmp($selectByVal, $val) == 0)? $foundVal = true :$foundVal = false ;
}
if($foundText !== false || $foundVal !== false ) {
$selectedAttrib = 'selected="true"';
}else{
$selectedAttrib = '';
}
echo "\n\t",'';
}//end if(ix)
}//end for
if(!$optionsOnly) {
echo "\n\t",'';
}
break;
case 'list':
//to do
break;
case 'json':
//todo
break;
}//end switch case
}//end of dropdown();
*
* */
///////////////////////////////////////////////////////////////////////////////////////////
/**
* dropdown() function
*
* Prepares and echoes HTML/DHTMLX Code for Dropdown list
*
* @param $data - required - Data Array
*
* @param $name - required - The name and the id of the dropdown controller.
*
* @param $fieldName - required - The field name of the record set which is to be listed in options.
*
* @param $selectByText - optional - The option text(s) to be selected on load of the dropdown.
*
* @param $selectByVal - optional -The option value(s) to be selected on load of the dropdown
*
* @param $format - optional - The dropdown output format as html or xml
*
* @param $multiple - optional - to specify either multiple select or single select option
*
* @param $optionsOnly - optional - To specify to output only options list without select controller
*
* @return void
*
* Updates:
*
* 1. Rearranged parameter list from required to optional from left to right
* 2. Removed unwanted parameters - $keyfield,$skipfield,$label
*
* Updated on 11/4/2013
*
* By: MRoshan
*
*
* $dataArray = array('data' => $data,
* 'fieldName' => $fieldName, (html name attrib)
* 'label' => $label,
* 'selectByText' => null,
* 'selectByVal' => null,
* 'format' => 'html',
* 'multiple' => false,
* 'optionsOnly' => false
* );
*
* //function dropdown($data, $name, $fieldName,$label, $selectByText=null, $selectByVal=null, $format='html', $multiple=false, $optionsOnly=false)
* */
function dropdown($dataArray)
{
/*
* following set of codes are common for both xml and html code segments.
*
* */
$dataset = $dataArray['data']['dataset']['result_set'];
$pk = $dataArray['data']['dataset']['metadata']['PK'];
$fieldName = isset($dataArray['fieldName'])? $dataArray['fieldName']: null;
$selectByText = isset($dataArray['selectByText'])? $dataArray['selectByText']:null;
$selectByVal = isset($dataArray['selectByVal'])? $dataArray['selectByVal']:null;
$format = isset($dataArray['format'])? $dataArray['format']:null;
$multiple = isset($dataArray['multiple'])? $dataArray['multiple']:false;
$optionsOnly = isset($dataArray['optionsOnly'])? $dataArray['optionsOnly']:false;
$label = isset($dataArray['label'])? $dataArray['label']:null;
$display = isset($dataArray['display'])? $dataArray['display']:null;
$required = isset($dataArray['required'])? $dataArray['required']:null;
if ($selectByText && $selectByVal) $selectByText = null; // Choos ByVal if both provided //WCD
switch ($format) {
case 'html':
if (!is_array($pk)) $pk = explode(',', $pk);
$nrows = sizeof($dataset) ;
$mul = ($multiple)?'[]':'';
if(!$optionsOnly) {
echo '',"\n";
}
break;
case 'xml':
if (!is_array($pk)) $pk = explode(',', $pk);
$nrows = sizeof($dataset);
if($multiple) { $type='multiselect'; } else { $type='select';}
if($required) { $validate='NotEmpty'; }
if(!$optionsOnly) {
if($required) {
echo '';
}else {
echo '';
}
}
if(empty($selectByVal)&& empty($selectByText)){
echo "\n\t",'';
}else{
echo "\n\t",'';
}
$sbt = null;
for($ix=1;$ix<=$nrows;$ix++){
if($ix > 0)
{
$val='';
foreach($pk as $key){
$val .= $dataset[$ix][$key].'_';
}
$val=trim($val,'_');
$foundText= false; $foundVal=false;
if(!empty($selectByVal)|| !empty($selectByText)){
if(!empty($selectByText) && !empty($dataset[$ix][$display])){
//$foundText = strpos($selectByText,(string)$dataset[$ix][$display]);
$sbt = explode(',',$selectByText);
$foundText = in_array($dataset[$ix][$display],$sbt);
}else{
$foundText = false;
}
if(!empty($selectByVal) && !empty($val)){
$foundVal = strpos($selectByVal,$val) ;
}else{
$foundVal = false;
}
}//endif
if($foundText !== false || $foundVal !== false ) {
$selectedAttrib = 'selected="true"';
}else{
$selectedAttrib = '';
}
echo "\n\t",'';
}//end if(ix)
}//end for
if(!$optionsOnly) {
echo "\n\t",'';
}
break;
case 'list':
//to do
break;
case 'json':
//todo
break;
}//end switch case
}//end of dropdown();
/*###################################### Added by Dinishika ####################*/
function formatString($string) {
$string = str_replace ( '&', '&', $string );
return $string;
}
/*###########################################################################*/
if ( ! function_exists('converDHTMLXGrid')) {
/**
* converDHTMLXGrid() function
*
* Prepares and echoes XML for DHTMLX Data Grid
*
* @param $data Data Array
*
* @param $sr Optional, Enable/Disable Smart Rendering, Boolean TRUE/FALSE,
* Default false
*
* @param $start Optional, Start Position of data included in XML, Default 0
*
* @param $nnrows Optional, Number of data rows to included in XML, Default 20
*
* @param $includeHeaders boolean, optional, use true to have headers included
* in XML, otherwise keep it false
*
* @param $widths , array of column widths, optional (e.g. array('col1'=>100,'col2'=>150,'col3'=>200); )
*
* @param $cellStyles , array of CSS styles, optiona (e.g. array('color:red;font-
* weight:bold;','color:#00ff00'); )
*
* @param $colList , array of columns to display, optional (e.g. array('col1','col2','col3'); ) table column names
* @return String, Grid XML
*/
function converDHTMLXGrid($data,$sr = false, $start=0,$nnrows=0,$includeHeaders=false,$widths='',$cellStyles='',$colList = false) {
//error_reporting(0);
$widthStr = '';
$widthArr = array();
$rowStyleStr = '';
$rowStylesArr = array();
$sidx = 0;
// For debuging WCD
log_message('debug',"DATA ARRAY :- ".serialize($data));
if(is_array($widths))
{
/*foreach($widths as $w)
{
$widthArr[] = $w;
} */
$widthArr = $widths ;
}
if(is_array($cellStyles))
{
foreach($cellStyles as $rsty)
{
$rowStylesArr[] = $rsty;
}
}
$dataset = $data['dataset']['result_set'];
$pk = explode(",",$data['dataset']['metadata']['PK']);
//$headerList = getHeadersList($data['dataset']['metadata']);
//$headers = explode(',',$headerList);
$headers =array_slice($data['dataset']['metadata'],1);
$nrows = sizeof($dataset);
$nnrows = ($nrows < $nnrows)?$nrows:$nnrows;
$total_recs = $data['dataset']['total_rows'];
//set header for XML Using DOM to do a clean job
$doc = new DOMDocument('1.0', 'UTF-8');
/*
$doc->formatOutput = true; //To produce output in a nice way
header("Access-Control-Allow-Headers: X-Requested-With");
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml");
} else {
header("Content-type: text/xml");
} */
//Set Row data for XML
$myrows = $doc->createElement("rows");
//Following for smart rendering. Does not work with paging--
if ($sr) {
$myrows->setAttribute('pos', $start);
$myrows->setAttribute('rec_count', $nrows);
}
//Smart rendering End ---------------------------------------
$doc->appendChild($myrows);
//Following needed for paging ------------------
// Put Paging code here (Not needed for DHTMLX Enterprice version)
//Paging End -----------------------------------
//-----For column Headers---------
$listCols = is_array($colList) ? $colList : $headers;
if($includeHeaders)
{
$myhead = $doc->createElement("head");
$myrows->appendChild($myhead);
$hix = 0;
foreach($headers as $key=>$h)
{
if ($colList) {
if (in_array($key,$colList)){
$mycolumn = $doc->createElement("column");
$mycolumn->setAttribute('type', 'ro');
$mycolumn->setAttribute('align', 'center');
$mycolumn->setAttribute('sort', 'str');
//$mycolumn->setAttribute('width', getArrayElements($widthArr,$hix));
//TODO The following code should be modified to get the header width
// as the minimum width if a width is not specified by user. WCD
if (sizeof($widthArr)>0) { //User specified column widths are active
$width=$widthArr[$key];
}else{ //User not specified column widths so use header stuff
if($h['width'] =="" || $h['width'] < "5"){
$width="10";
}else{
$width=$h['width'];
}
}
//The column character width is converted to corrosponding pixel width
$mycolumn->setAttribute('width', ($width * 6.27 + 12));
$mycolumn->appendChild($doc->createTextNode('
'.$h['header'].'
'));
$myhead->appendChild($mycolumn);
unset ($mycolumn);
$hix++;
}
} else {
$mycolumn = $doc->createElement("column");
$mycolumn->setAttribute('type', 'ro');
$mycolumn->setAttribute('align', 'center');
$mycolumn->setAttribute('sort', 'str');
//$mycolumn->setAttribute('width', getArrayElements($widthArr,$hix));
//TODO The following code should be modified to get the header width
// as the minimum width if a width is not specified by user. WCD
if (sizeof($widthArr)>0) { //User specified column widths are active
$width=$widthArr[$key];
}else{ //User not specified column widths so use header stuff
if($h['width'] =="" || $h['width'] < "5"){
$width="10";
}else{
$width=$h['width'];
}
}
//The column character width is converted to corrosponding pixel width
$mycolumn->setAttribute('width', ($width * 6.27 + 12));
$mycolumn->appendChild($doc->createTextNode('
'.$h['header'].'
'));
$myhead->appendChild($mycolumn);
unset ($mycolumn);
$hix++;
}
}
} // End of Header construction
//$pk_grid=join("_",$pk);
$datarowHTML = '';
for($i=($start+1);$i<=($start+$nnrows);$i++)
{
$pk_grid="";
unset($pk_g);
foreach($pk as $col){
$pk_g[] = $dataset[$i][$col];
}
$pk_grid=join("_",$pk_g);
unset($pk_g);
//var_dump($dataset[$i]);
$sidx = 0;
$myrow = $doc->createElement("row");
//$myrow->setAttribute('id',$dataset[$i][$pk]);
$myrow->setAttribute('id',$pk_grid);
$myrows->appendChild($myrow);
foreach($dataset[$i] as $key=>$v)
{
if(!(isset($v))){
$thisValue = '-';
}else {
$thisValue = $v;
}
if (is_array($colList)) {
if (in_array($key,$colList)) {
$mycell = $doc->createElement("cell");
$mycell->setAttribute('style',getArrayElements($rowStylesArr,$sidx));
$mycell->setAttribute('fieldName',$key);
$mycell->appendChild($doc->createTextNode(stripslashes($thisValue)));
$myrow->appendChild($mycell);
}
}else {
$mycell = $doc->createElement("cell");
$mycell->setAttribute('style',getArrayElements($rowStylesArr,$sidx));
$mycell->setAttribute('fieldName',$key);
$mycell->appendChild($doc->createTextNode(stripslashes($thisValue)));
$myrow->appendChild($mycell);
}
unset ($mycell,$thisValue);
unset($pk_g);
$pk_grid="";
}
$sidx++;
unset ($myrow);
}
$myXML=$doc->saveXML();
//var_dump($myXML);
return $myXML;
}
} //-------------------End of converDHTMLXGrid() -------------------
/**
* This function getts the data from a URL using CURL facility
*
* @param string $url - the URL fro which the data to be feched
* @param string $user - User ID if the URL needs authentication
* @param string $pass - User password if the URL needs authentication
* @param int $transfer - should CURL transfer the data direct. This same
* effect is achieved with ob_start by the function
* however the php way is to handle it through CURL
* param. Both does not work.
*
* RETURNS - $client_xml session var which eeds to be converted to
* simpleXml
*
* Author : - Channa Dewamitta
* Creaded on :- 15/08/2013
* Last Modified by :-
* Last modified on :-
* Last Modification :-
*
**/
function get_content($url,$user=null,$pass=null,$transfer=0)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $transfer);
if($user){
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}//End of get content
/**
* This function fetches the client data from the xmlfeed and creates a
* session var with it. If the feched data is existing it just returns it
* if not it will fech the data from the server. This way it will only
* pull the data once per application
*
* TODO Seee if performace can be improved by passing var by referance
*
* RETURNS - $client_xml session var which eeds to be converted to
* simpleXml
*
* Author : - Channa Dewamitta
* Creaded on :- 16/08/2013
* Last Modified by :-
* Last modified on :-
* Last Modification :-
*
**/
function clients_object($args = null){
//$args = 'cid:cfname:cbizname:cweb:clientstatus:cstatus:title:cfirstname:clastname:cmanager:clientservicesofficer';
//Get the Client data and meke it availabe as a simpleXMLObject
//$utils = new ekwa_utils();
if (! isset($_SESSION['clients_xml']) || ! $_SESSION['clients_xml']) {
try{
$_SESSION['clients_xml'] = file_get_contents(CLIENT_FEED_URL.'client_master/index/true/0/0/data_feed_template/XML/'.$args); //_Change_ client_master_gridview
} catch (Exception $e){
show_error('Sorry Could not connect to Server for client data!' );
}
}
try{
return new SimpleXMLElement($_SESSION['clients_xml']);
} catch (Exception $e){
show_error('Sorry Could not connect to Server for client data!' );
}
} // End of Client_object
/**
* This function is used to fetch clients only whom are just joind ekwa but have no live status.
*
* @return SimpleXMLElement
*/
function not_live_clients_object($args = null){
//Get the Client data and meke it availabe as a simpleXMLObject
if (! isset($_SESSION['not_live_clients_xml']) || ! $_SESSION['not_live_clients_xml']) {
try{
$_SESSION['not_live_clients_xml'] = file_get_contents(CLIENT_FEED_URL.'client_master/index/true/0/0/data_feed_template/XML/0/pending-live/'.$args);
} catch (Exception $e){
show_error('Sorry Could not connect to Server for not live client data!' );
}
}
try{
return new SimpleXMLElement($_SESSION['not_live_clients_xml']);
} catch (Exception $e){
show_error('Sorry Could not connect to Server for not live client data!' );
}
} // End of function
/**
* This function fetches the staff data from the xmlfeed and creates a
* session var with it. If the feched data is existing it just returns it
* if not it will fetch the data from the server. This way it will only
* pull the data once per application
*
* TODO Seee if performace can be improved by passing var by referance
*
* RETURNS - $staff_xml session var which eeds to be converted to
* simpleXml
*
* Author : - Channa Dewamitta
* Creaded on :- 16/08/2013
* Last Modified by :-
* Last modified on :-
* Last Modification :-
*
**/
function staff_object(){
//Load staff data
if (! isset($_SESSION['staff_xml']) || ! $_SESSION['staff_xml']) {
try{
$_SESSION['staff_xml'] = get_content(STAFF_FEED_URL.'staff/index/true/0/0/staff_xml_feed/XML/staff_id:full_name:office_email?staff/status_equal=1'); //_Change_
} catch (Exception $e){
show_error('Sorry Could not connect to Server for Staff data!' );
}
}
try{
return new SimpleXMLElement($_SESSION['staff_xml']);
} catch (Exception $e){
show_error('Sorry Could not connect to Server for Staff data!' );
}
}// End of staff_object ----------------
function cidExist($cid){
//get client website based on client id
$clientData = file_get_contents (CLIENT_FEED_URL."client_master/index/true/0/0/data_feed_template/XML/?client_profiles/cid_equal=$cid");
$clientXml = simplexml_load_string($clientData);
$cid = $clientXml->xpath("//row/cell[@fieldName='cid']");
if(empty($cid)){
return false;
}else {
return true;
}
}//end of function
?>