I have a php file, say A.php, where I have defined a function log_campaign_activity, which is returning 2-arrays, as shown below:
function log_campaign_activity($identifier, $activity, $update=true, $clicked_url_key=null) {
$return_array = array();
$db = DBManagerFactory::getInstance();
//check to see if the identifier has been replaced with Banner string
if($identifier == 'BANNER' && isset($clicked_url_key) && !empty($clicked_url_key))
{
// create md5 encrypted string using the client ip, this will be used for tracker id purposes
$enc_id = 'BNR'.md5($_SERVER['REMOTE_ADDR']);
//default the identifier to ip address
$identifier = $enc_id;
//if user has chosen to not use this mode of id generation, then replace identifier with plain guid.
//difference is that guid will generate a new campaign log for EACH CLICK!!
//encrypted generation will generate 1 campaign log and update the hit counter for each click
if(isset($sugar_config['campaign_banner_id_generation']) && $sugar_config['campaign_banner_id_generation'] != 'md5'){
$identifier = create_guid();
}
//retrieve campaign log.
$trkr_query = "select * from campaign_log where target_tracker_key='$identifier' and related_id = '$clicked_url_key'";
$current_trkr=$db->query($trkr_query);
$row=$db->fetchByAssoc($current_trkr);
//if campaign log is not retrieved (this is a new ip address or we have chosen to create
//unique entries for each click
if($row==null || empty($row)){
//retrieve campaign id
$trkr_query = "select ct.campaign_id from campaign_trkrs ct, campaigns c where c.id = ct.campaign_id and ct.id = '$clicked_url_key'";
$current_trkr=$db->query($trkr_query);
$row=$db->fetchByAssoc($current_trkr);
//create new campaign log with minimal info. Note that we are creating new unique id
//as target id, since we do not link banner/web campaigns to any users
$data['target_id']="'" . create_guid() . "'";
$data['target_type']= "'Prospects'";
$data['id']="'" . create_guid() . "'";
$data['campaign_id']="'" . $row['campaign_id'] . "'";
$data['target_tracker_key']="'" . $identifier . "'";
$data['activity_type']="'" . $activity . "'";
$data['activity_date']="'" . TimeDate::getInstance()->nowDb() . "'";
$data['hits']=1;
$data['deleted']=0;
if (!empty($clicked_url_key)) {
$data['related_id']="'".$clicked_url_key."'";
$data['related_type']="'".'CampaignTrackers'."'";
}
//values for return array..
$return_array['target_id']=$data['target_id'];
$return_array['target_type']=$data['target_type'];
//create insert query for new campaign log
$insert_query="INSERT into campaign_log (" . implode(",",array_keys($data)) . ")";
$insert_query.=" VALUES (" . implode(",",array_values($data)) . ")";
$db->query($insert_query);
}else{
//campaign log already exists, so just set the return array and update hits column
$return_array['target_id']= $row['target_id'];
$return_array['target_type']= $row['target_type'];
$query1="update campaign_log set hits=hits+1 where id='{$row['id']}'";
$current=$db->query($query1);
}
//return array and exit
return $return_array;
}
You can observe that in the end, it is returning 2-arrays:
I want to call this function and store these values in 2-variables of another php-file, say B.php:
How can I do this? What is better method?
With thanks,
RK
In B.php
//Require A.php, so you can call your function
require_once("A.php");
//Call your function with needed parameters
$result = log_campaign_activity($param1, $param2, $param3...);
//Save result into vars
$targetID = $result["target_id"];
$targetType = $result["target_type"];