saveLeadRelatedCampaigns($id, $contact_id);
}
//Up to this, Contact related data save finshed
//Saving Potential - starts
if ((!isset($createpotential) || !$createpotential == "on") && !empty($potential_name) && isPermitted("Potentials", "EditView") == 'yes' && ($crmid != '' || $crmcontactid != '') && vtlib_isModuleActive('Potentials')) {
    $log->info("createpotential is not set");
    $date_entered = $adb->formatDate(date('Y-m-d H:i:s'), true);
    $date_modified = $adb->formatDate(date('Y-m-d H:i:s'), true);
    $oppid = $adb->getUniqueID("vtiger_crmentity");
    $sql_crmentity = "insert into vtiger_crmentity(crmid,smcreatorid,smownerid,setype,presence,deleted,createdtime,modifiedtime,description) values(?,?,?,?,?,?,?,?,?)";
    $sql_params = array($oppid, $current_user_id, $assigned_user_id, 'Potentials', 0, 0, $date_entered, $date_modified, $row['description']);
    $adb->pquery($sql_crmentity, $sql_params);
    // Module Sequence Numbering
    require_once 'modules/Potentials/Potentials.php';
    $pot_no_focus = new Potentials();
    $potential_no = $pot_no_focus->setModuleSeqNumber("increment", 'Potentials');
    // END
    if (!isset($potential_amount) || $potential_amount == null) {
        $potential_amount = 0;
    }
    if ($crmid != '') {
        $related_to = $crmid;
    } else {
        $related_to = $crmcontactid;
    }
    $sql_insert_opp = "INSERT INTO vtiger_potential (potential_no,potentialid,related_to,potentialname,leadsource,closingdate,sales_stage,amount) VALUES (?,?,?,?,?,?,?,?)";
    $opp_params = array($potential_no, $oppid, $related_to, $potential_name, $row['leadsource'], $close_date, $potential_sales_stage, $potential_amount);
    $adb->pquery($sql_insert_opp, $opp_params);
    //Getting the customfield values from leads and inserting into the respected PotentialCustomfield to which it is mapped - Jaguar
    $col_val = getInsertValues("Potentials", $oppid);
    $insert_columns = $col_val['columns'];