Quick Configuration Pages

Sometimes our SugarCRM customizations and add-ons require parameters and settings that we want to store for customers, but don’t want to hard-code so they’ll be accessible and editable, e.g. things like API Keys, Legal Mumbo-Jumbo for Quotes. For these situations I have a relatively simple solution to store the contents of said parameters in the SugarCRM Configuration files ($sugar_config). Place the following code into /custom/<some_module>/config.php and then link to it via index.php?module=<some_module>&action=config. How you actually store that link is up to you.

This snippet is what we’re using to store data for our Sage Payments integration.  You’ll see the API’s language, the Merchant ID Key, and Application ID and stored in the Configurator, displayed when called and updated as desired by administrative users.

<?php
if(isset($_POST['sage']) && is_array($_POST['sage'])){
    $sage = $_POST['sage'];
    require_once('modules/Configurator/Configurator.php');
    $configurator = new Configurator();
    $configurator->config['sage_Transactions']['ApplicationID'] = $sage['ApplicationID'];
    $configurator->config['sage_Transactions']['LanguageID'] = $sage['LanguageID'];
    $configurator->config['sage_Transactions']['MerchantID'] = $sage['MerchantID'];
    $configurator->config['sage_Transactions']['MerchantKey'] = $sage['MerchantKey'];
    $configurator->saveConfig();
    echo "<h1 style='color:red;margin-bottom:50px;'>Configuration Saved</h1>";
}

global $sugar_config;
$ApplicationID = isset($sugar_config['sage_Transactions']['ApplicationID']) ? $sugar_config['sage_Transactions']['ApplicationID'] : "";
$LanguageID = isset($sugar_config['sage_Transactions']['LanguageID']) ? $sugar_config['sage_Transactions']['LanguageID'] : "";
$MerchantID = isset($sugar_config['sage_Transactions']['MerchantID']) ? $sugar_config['sage_Transactions']['MerchantID'] : "";
$MerchantKey = isset($sugar_config['sage_Transactions']['MerchantKey']) ? $sugar_config['sage_Transactions']['MerchantKey'] : "";

echo <<<EOHTML
<form action='index.php?module=sage_Transactions&action=config' method='POST'>
    Application ID<br />
    <textarea name='sage[ApplicationID]' cols='75' rows='1'>$ApplicationID</textarea><br />
    Language ID<br />
    <textarea name='sage[LanguageID]' cols='75' rows='1'>$LanguageID</textarea><br />
    Merchant ID<br />
    <textarea name='sage[MerchantID]' cols='75' rows='1'>$MerchantID</textarea><br />
    Merchant Key<br />
    <textarea name='sage[MerchantKey]' cols='75' rows='1'>$MerchantKey</textarea><br />
    <br />
    <input type='submit' value='save' />
</form>
EOHTML;
This entry was posted in PHP, SugarCRM. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Sage President\

Profiling Solutions, Inc
174 Carroll Street
Atlanta, GA 30312
Sales: 1 (866) 515-9959
Office Phone: (404) 525-8003
Office Fax: (404) 525-8005
info@profilingsolutions.com