<?php



$data['vtiger_url']= "http://iamdemo.com/vision4/amoln/vtiger/webservice.php";
			$data['vtiger_user']= "admin";
			$data['vtiger_key']= "RYTQy9BCYR7EKKSS";
			$data['vtiger_lic'] = 1;
			
			$d = get_vtiger('module_list',$data);
			echo '<pre>';print_r($d);echo '</pre>';













function get_vtiger($methodName='module_list',$data=''){	
			$vtiger_url		= $data['vtiger_url'];
			$vtiger_user 	= $data['vtiger_user'];
			$vtiger_key 	= $data['vtiger_key'];
			$vtiger_lic 	= $data['vtiger_lic'];
			
			$moduleidx	=	array();
			 if($vtiger_lic==1){
				$moduleidx["Campaigns"] = "1x";
				$moduleidx["Vendors"] = "2x";
				$moduleidx["Faq"] = "3x";
				$moduleidx["Quotes"] = "4x";
				$moduleidx["PurchaseOrder"] = "5x";
				$moduleidx["SalesOrder"] = "6x";
				$moduleidx["Invoice"] = "7x";
				$moduleidx["PriceBooks"] = "8x";
				$moduleidx["Calendar"] = "9x";
				$moduleidx["Leads"] = "10x";
				$moduleidx["Accounts"] = "11x";
				$moduleidx["Contacts"] = "12x";
				$moduleidx["Potentials"] = "13x";
				$moduleidx["Products"] = "14x";
				$moduleidx["Documents"] = "15x";
				$moduleidx["Emails"] = "16x";
				$moduleidx["HelpDesk"] = "17x";
				$moduleidx["Events"] = "18x";
				$moduleidx["Users"] = "19x";
				$moduleidx["Services"] = "24x";
				$moduleidx["ServiceContracts"] = "25x";
				$moduleidx["PBXManager"] = "26x";
				$moduleidx["Assets"] = "27x";
				$moduleidx["ModComments"] = "28x";
				$moduleidx["SMSNotifier"] = "29x";
				$moduleidx["ProjectMilestone"] = "30x";
				$moduleidx["ProjectTask"] = "31x";
				$moduleidx["Project"] = "32x";
				$moduleidx["Groups"] = "20x";
				$moduleidx["Currency"] = "21x";
				$moduleidx["DocumentFolders"] = "22x";
				$moduleidx["CompanyDetails"] = "23x";
				$moduleidx["LineItem"] = "33x";
				$moduleidx["Tax"] = "34x";
				$moduleidx["ProductTaxes"] = "35x";
			 }else if($vtiger_lic==2){
				$moduleidx["Calendar"] = "1x";
				$moduleidx["Leads"] = "2x";
				$moduleidx["Accounts"] = "3x";
				$moduleidx["Contacts"] = "4x";
				$moduleidx["Potentials"] = "5x";
				$moduleidx["Products"] = "6x";
				$moduleidx["Documents"] = "7x";
				$moduleidx["Emails"] = "8x";
				$moduleidx["Faq"] = "10x";
				$moduleidx["Vendors"] = "11x";
				$moduleidx["PriceBooks"] = "12x";
				$moduleidx["Quotes"] = "13x";
				$moduleidx["PurchaseOrder"] = "14x";
				$moduleidx["SalesOrder"] = "15x";
				$moduleidx["Invoice"] = "16x";
				$moduleidx["Campaigns"] = "17x";
				$moduleidx["Events"] = "18x";
				$moduleidx["Users"] = "19x";
				$moduleidx["ServiceContracts"] = "23x";
				$moduleidx["PBXManager"] = "24x";
				$moduleidx["Services"] = "25x";
				$moduleidx["Assets"] = "27x";
				$moduleidx["ModComments"] = "28x";
				$moduleidx["ProjectMilestone"] = "29x";
				$moduleidx["ProjectTask"] = "30x";
				$moduleidx["Project"] = "31x";
				$moduleidx["EmailCampaigns"] = "37x";
				$moduleidx["SLA"] = "38x";
				$moduleidx["Cases"] = "39x";
				$moduleidx["Olark"] = "40x";
				$moduleidx["PrintTemplates"] = "41x";
				$moduleidx["EventForms"] = "42x";
				$moduleidx["Groups"] = "20x";
				$moduleidx["Currency"] = "21x";
				$moduleidx["DocumentFolders"] = "22x";
				$moduleidx["CompanyDetails"] = "26x";
				$moduleidx["LineItem"] = "33x";
				$moduleidx["Tax"] = "34x";
				$moduleidx["ProductTaxes"] = "35x";
			 }else{ 
				return "Set Vtiger License type";
			}			 
			include_once('vtwsclib/Vtiger/WSClient.php');
			
			#integration		
			$client = new Vtiger_WSClient($vtiger_url.'/webservice.php');
			$login = $client->doLogin($vtiger_user, $vtiger_key);
			
			
			if(!$login){ echo 'Vtiger Login Failed'; }
			else {						
				switch($methodName){
					##modules delais & lists
					case 'module_list' : return $modules = $client->doListTypes();
					break; 
					
					##Creating new records in the module can be done using this method. 
					##doCreate(module, valuesmap)
					/**************************************************************************
						=> Here used only mandatory fields if extra foelds require then refer $describe Array 
						
						-Leads
							$arr = array('firstname'=>'tejas','lastname'=>'JADHAV', 'company'=>'Vision pro'); 
						
						-Contacts 
							$arr = array('lastname'=>'Test description')
						
						-Cases  
							$arr = array("description"=>"descriptiondescription","title"=>"titletitle","casestatus"=>"New","casepriority"=>"Urgent","contact_id"=>$moduleidx["Contacts"]."247");
						
						-Project 
							$arr = array("projectname"=>"ProjectNName","assigned_user_id"=>$moduleidx["Users"]."6");
						
						-Accounts(organization) 
							$arr = array("accountname"=>"MY ACCOUNT NAME","assigned_user_id"=>$moduleidx["Users"]."6");
						
						-Assets  
							$arr = array("assetname"=>"Asset Name","serialnumber"=>"123456789","product"=>$moduleidx["Products"]."268","assetstatus"=>"In Service","assigned_user_id"=>$moduleidx["Users"]."6","dateinservice"=>"19-08-2016","datesold"=>"19-08-2016","account"=>$moduleidx["Accounts"]."45");
						
						-Vendors
							$arr = array("vendorname"=>"Vendor Name","assigned_user_id"=>$moduleidx["Users"]."6");
						
						-Products
							$arr = array("productname"=>"product Name","assigned_user_id"=>$moduleidx["Users"]."6");	
						
						-Services
							$arr = array("servicename"=>"servicename Name","assigned_user_id"=>$moduleidx["Users"]."6");	
						
						-ServiceContracts
							$arr = array("subject"=>"subject Name","assigned_user_id"=>$moduleidx["Users"]."6");	
						
						-Faq
							$arr = array("question"=>"question Name","faq_answer"=>"faq_answer","faqstatus"=>"faqstatus");	
						
						-Campaigns
							$arr = array("campaignname"=>"campaignname Name","closingdate"=>"19-08-2016","assigned_user_id"=>$moduleidx["Users"]."6");
						
						-Groups
							$arr = array("groupname"=>"groupname Name","description"=>"description");
							
						-Potentials (Opportunities)
							$arr = array("potentialname"=>"potentialname Name","closingdate"=>"30-08-2016","sales_stage"=>"Prospecting","assigned_user_id"=>$moduleidx["Users"]."6");
							
					/********************************************************************/
					case 'create_record' :    $record = $client->doCreate($data['module'],$data['arr']);
											if($record) {
												return $recordid = $client->getRecordId($record['id']);
											}else{ return -1; }
					break;
								
					##Rerive record  doRetrieve(record)
					##record – identifier having the format <moduleid>'x'<recordid>
					case 'retrieve_record' :    $record = $moduleidx[$data['module']].$data['contact_id'];
												$recordInfo = $client->doRetrieve($record);
												if($recordInfo) {
													return $recordInfo;
												}else{ return -1; }
					break;
					
					##doQuery(query)
					##query – SELECT query to use for fetching the records.
					//Accounts , Contacts , Cases{HelpDesk} , Assets , Vendors , Products , Services , ServiceContracts ,Faq, Campaigns , Leads, Project, Invoice, PurchaseOrder, PriceBooks, ProjectTask, ProjectMilestone ,Potentials
					
					case 'do_query' :    	$query = $data['query']; 	 
											$records = $client->doQuery($query);
											if($records) {
												$columns = $client->getResultColumns($records);
												return $records;
											}else{ return -1; }
					break;
					
					##lastError()
					##Map containing (code, message) if the last operation failed or else false
					case 'last_error' :    	$wasError= $client->lastError();
											if($wasError) {
												return $wasError['code'].':'.$wasError['message'];
											}else{ return 0; }
					break;
									
					default: return 0;			
				}//switch			
			}//else
	
	}


?>