MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/wealth_cafsindia_com/bend/mf_model.php
<?php
include('./dbconnect.php');
include('./xml2array.php');
class mf_model extends dbconnect{
	protected  $broker_code = "ARN-70209";
	protected  $appln_id    = "TEST2204";
	protected  $password    = "TEST$258";
	
	public function __construct() {
		$this->open_db();
    }
	
	public function real_escape_string($value){
		$value = mysql_real_escape_string($value);
		if(empty($value)){
			$value = 0;
		}
		return $value;
	}
	
	//CURL GET METHOD TO FETCH MASTER DATA
	public function curl($post_url ,$process_from,$post_data=null){		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_URL,$post_url);
		if($process_from === "TXN"){
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_VERBOSE, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
		}
		$result=curl_exec($ch);
		curl_close($ch);
		$response = new DomDocument('1.0', 'utf-8');
		$response->loadXML($result);
		return $response;
	}
	
	//USED TO CHANGE XML DATA TO ARRAY
	public function xml_to_array($root) {
		$result = array();
		if ($root->hasAttributes()) {
			$attrs = $root->attributes;
			foreach ($attrs as $attr) {
				$result['@attributes'][$attr->name] = $attr->value;
			}
		}
		if ($root->hasChildNodes()) {
			$children = $root->childNodes;
			if ($children->length == 1) {
				$child = $children->item(0);
				if ($child->nodeType == XML_TEXT_NODE) {
					$result['_value'] = $child->nodeValue;
					return count($result) == 1
						? $result['_value']
						: $result;
				}
			}
			$groups = array();
			foreach ($children as $child) {
				if (!isset($result[$child->nodeName])) {
					$result[$child->nodeName] = $this->xml_to_array($child);
				} else {
					if (!isset($groups[$child->nodeName])) {
						$result[$child->nodeName] = array($result[$child->nodeName]);
						$groups[$child->nodeName] = 1;
					}
					$result[$child->nodeName][] = $this->xml_to_array($child);
				}
			}
		}
		return $result;
	}
	
	//GET XML ARRAY ALL NODE's
	public function get_node_list($xml_rslt){
		$node_list = array();
		$columns_name     = $xml_rslt['DataSet']['xs:schema']['xs:element']['xs:complexType']['xs:choice']['xs:element'][1]['@attributes']['name'];
		$columns_list_xml = $xml_rslt['DataSet']['xs:schema']['xs:element']['xs:complexType']['xs:choice']['xs:element'][1]['xs:complexType']['xs:sequence']['xs:element'];
		foreach($columns_list_xml as $list_xml){
			$node_list[] =  $list_xml['@attributes']['name'];
		}
		$node_rlst = array('head_node'=>$columns_name,'node_list'=>$node_list);
		return $node_rlst;
	}
	
	//GET XML ARRAY ALL NODE DATA
	public function get_node_data($xml_rslt,$process_from){
		if($process_from === "MASTER"){
			$xml_count  = $xml_rslt['DataSet']['diffgr:diffgram']['NewDataSet']['service_status']['rows_count'];
			$xml_sts    = $xml_rslt['DataSet']['diffgr:diffgram']['NewDataSet']['service_status']['service_return_code'];
		}else{
			$xml_sts    = $xml_rslt['DataSet']['diffgr:diffgram']['NMFIISERVICES']['service_status']['service_return_code'];
		}		
		$data_rslt = array();
		if((int)$xml_sts === 0){
			$node_rlst        = $this->get_node_list($xml_rslt);
			$head_node        = $node_rlst['head_node'];
			$node_list        = $node_rlst['node_list'];
			if($process_from === "MASTER"){
				$final_head_node  = $xml_rslt['DataSet']['diffgr:diffgram']['NewDataSet'][$head_node];
			}else{
				$final_head_node  = $xml_rslt['DataSet']['diffgr:diffgram']['NMFIISERVICES'][$head_node];
			}						
			foreach($final_head_node as $head_info){
				$data_set = array();
				foreach($node_list as $node_key => $node_value){
					$key   = $node_value;
					$value = $head_info[$node_value];
					$data_set[strtolower($key)] = $value;
				}
				$data_rslt[] = $data_set;
			}
		}
		$final_data_set = array('sts'=>$xml_sts,"data_rslt"=>$data_rslt);
		return $final_data_set;
	}
	
	//GET ALL MASTER DATA BY USING NSE METHOD NAME RETURN IN ARRAY
	public function process_mf_master($process_info){
		$post_url      = "https://uat.nsenmf.com/NMFIIService/NMFService/@METHOD@?BrokerCode=".$this->broker_code."&Appln_id=".$this->appln_id."&Password=".$this->password."&SourceProgram=php";
		$send_to       = $process_info['send_to'];
		$state_code    = $process_info['state_code'];
		$amc_code      = $process_info['amc_code'];
		$city          = $process_info['city'];
		$modified_date = $process_info['modified_date'];
		
		if(strtoupper($send_to) === "CITY"){
			$post_url = str_replace("@METHOD@","$send_to",$post_url)."&StateCode=$state_code";
		}else
		if(strtoupper($send_to) === "GOALTYPE"){ // 
			$post_url = str_replace("@METHOD@","$send_to",$post_url)."&AMCCode=$amc_code";
		}else
		if(strtoupper($send_to) === "PINCODE"){
			$post_url = str_replace("@METHOD@","$send_to",$post_url)."&City=$city";
		}else
		if(strtoupper($send_to) === "PRODUCT"){
			$post_url = str_replace("@METHOD@","$send_to",$post_url)."&AMCCode=$amc_code";
		}else
		if(strtoupper($send_to) === "PRODUCTLIMIT"){
			$post_url = str_replace("@METHOD@","$send_to",$post_url)."&AMCCode=$amc_code";
		}else
		if(strtoupper($send_to) === "SYSTEMATIC_FREQ_MASTER"){
			$post_url = str_replace("@METHOD@","$send_to",$post_url)."&AMCCode=$amc_code";
		}else{
			$post_url = str_replace("@METHOD@","$send_to",$post_url);
		}
		
		$response       = $this->curl($post_url,"MASTER");
		$xml_rslt       = $this->xml_to_array($response);
		echo "<pre>";
		print_r($xml_rslt);
		echo "<pre>";
		$final_data_set = $this->get_node_data($xml_rslt,"MASTER");
		return $final_data_set;
	}
	
	//GET ALL TXN DATA BY USING NSE METHOD NAME RETURN IN ARRAY
	public function process_mf_txn($method){		
		$post_url  = "https://uat.nsenmf.com/NMFIITrxnService/NMFTrxnService/@METHOD@";
		$post_url  = str_replace("@METHOD@","$method",$post_url);
		echo "post_url :: $post_url<br/>";
		$post_data = "<NMFIIService>
						<service_request>
							<appln_id>".$this->appln_id."</appln_id>
							<password>".$this->password."</password>
							<broker_code>".$this->broker_code."</broker_code>
						</service_request>
					</NMFIIService>";
		$response        = $this->curl($post_url,"TXN",$post_data);
		$xml_rslt        = $this->xml_to_array($response);		
		$final_data_set  = $this->get_node_data($xml_rslt,"TXN");
		echo "<pre>";
		print_r($final_data_set);
		echo "<pre>";
		//return $final_data_set;
	}
}
?>