Custom admin config page for new settings

Hello,

I would like to share with you the way to add a custom admin page for new settings.

For example (SugarCrm 6.5), we would add a setting to access to another system from sugarcrm; we need:

     * URL

     *USER

     * PASSWORD

Instead of adding code in config.php or config_override.php, we can do it:

=======================================================================

Step 1:  Create Authentication.php in custom/Extension/modules/Administration/Ext/Administration

=======================================================================

Authentication.php

<?php

  //Authentification Panel

  $admin_option_defs=array();

  $admin_option_defs['Administration']['DashboardManager_DashboardManager'] = array(

  'ModuleLoader',

  'LBL_AUTHENTICATION',

  'LBL_AUTHENTICATION_DESCRIPTION',

  'index.php?module=Administration&action=authentication'

  );

  $admin_group_header[]= array('LBL_AUTHENTICATION_MANAGEMENT', '', false, $admin_option_defs, '');

========================================================================

Step 2:  Create en_us.Authentication.php in custom/Extension/modules/Administration/Ext/Language

========================================================================

en_us.Authentication.php

<?php

  // Authentication Manager

  $mod_strings['LBL_AUTHENTICATION_MANAGEMENT'] = 'Authentication information ';

  $mod_strings['LBL_AUTHENTICATION'] = 'Authentication information ';

  $mod_strings['LBL_AUTHENTICATION_DESCRIPTION'] = 'Authentication information management';

  $mod_strings['LBL_CANCEL_BUTTON_TITLE'] = 'Cancel';

  $mod_strings['AUTHENTICATION_SETTINGS'] = 'Authentication information';

  $mod_strings['URL'] = 'URL';

  $mod_strings['USER'] = 'User';

  $mod_strings['PASSWORD'] = 'Password';

========================================================================

Step 3:  Create fr_FR.Authentication.php in custom/Extension/modules/Administration/Ext/Language

========================================================================

fr_FRAuthentication.php

<?php

  //Authentication Manager

  $mod_strings['LBL_AUTHENTICATION_MANAGEMENT'] = 'Authentication information ';

  $mod_strings['LBL_AUTHENTICATION'] = 'Authentication information ';

  $mod_strings['LBL_AUTHENTICATION_DESCRIPTION'] = 'Authentication information management';

  $mod_strings['LBL_CANCEL_BUTTON_TITLE'] = 'Cancel';

  $mod_strings['AUTHENTICATION_SETTINGS'] = 'Authentication information';

  $mod_strings['URL'] = 'URL';

  $mod_strings['USER'] = 'User';

  $mod_strings['PASSWORD'] = 'Password;

==============================================

Step 4:  Create controller.php in custom/modules/Administration

==============================================

controller.php

<?php

  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

  class AdministrationController extends SugarController

  {

  public function action_authentication() {

  $this->view = 'authentication';

  ///////////////////////////////////////////////////////////////////////////////

  //// HANDLE CHANGES AFTER SUBMIT

  if(isset($_REQUEST['process']) && $_REQUEST['process'] == 'true') {

  $admin = new Administration();

  $admin->retrieveSettings();

  if (!empty($_REQUEST["url"])) {

  $admin->saveSetting("authentication", "url", html_entity_decode($_REQUEST["url"]));

  }

  if (!empty($_REQUEST["user"])) {

  $admin->saveSetting("authentication", "user", $_REQUEST["user"]);

  }

  if (!empty($_REQUEST["password"])) {

  $admin->saveSetting("authentication", "password", $_REQUEST["password"]);

  }

  header('Location: index.php?module=Administration&action=index');

  }

  }

  }

==========================================================

Step 5:  Create view.authentication.php in custom/modules/Administration/views

==========================================================

If views directory does not exist, create it.

view.authentication.php

<?php

  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

  global $current_user, $sugar_config;

  if (!is_admin($current_user)) sugar_die("Unauthorized access to administration.");

  require_once('include/MVC/View/SugarView.php');

  class Viewauthentication extends SugarView {

  public function __construct() {

  parent::SugarView();

  }

  public function preDisplay() {

  $this->dv->tpl = 'custom/modules/Administration/tpl/authentication.tpl';

  }

  public function display() {

  global $sugar_config, $mod_strings, $app_strings;

  $smarty = new Sugar_Smarty();

  $smarty->assign('MOD', $mod_strings);

  $smarty->assign('APP', $app_strings);

  $smarty->assign('config', $sugar_config['authentication']);

  $admin = new Administration();

  $admin->retrieveSettings();

  if (array_key_exists('authentication_url', $admin->settings))

  $smarty->assign('URL', $admin->settings['authentication_url']);

  if (array_key_exists('authentication_user', $admin->settings))

  $smarty->assign('USER', $admin->settings['authentication_user']);

  if (array_key_exists('authentication_password', $admin->settings))

  $smarty->assign('PASSWORD', $admin->settings['authentication_password']);

  $smarty->display($this->dv->tpl);

  }

  }

  ?>

===================================================

Step 6:  Create authentication.tpl in custom/modules/Administration/tpl

===================================================

If tpl directory does not exist, create it.

authentication.tpl

<script type="text/javascript">

  var ERR_NO_SINGLE_QUOTE = '{$APP.ERR_NO_SINGLE_QUOTE}';

  var cannotEq = "{$APP.ERR_DECIMAL_SEP_EQ_THOUSANDS_SEP}";

  {literal}

  function verify_data(formName) {

  var f = document.getElementById(formName);

  for(i=0; i<f.elements.length; i++) {

  if(f.elements[i].value == "'") {

  alert(ERR_NO_SINGLE_QUOTE + " " + f.elements[i].name);

  return false;

  }

  }

  return true;

  }

  </script>

  {/literal}

  <BR>

  <form id="ConfigureSettings" name="ConfigureSettings" enctype='multipart/form-data' method="POST"

  action="index.php?module=Administration&action=authentication&process=true">

  <span class='error'>{$error.main}</span>

  <table width="100%" cellpadding="0" cellspacing="0" border="0" class="actionsContainer">

  <tr>

  <td>

  <input title="{$APP.LBL_SAVE_BUTTON_TITLE}"

  accessKey="{$APP.LBL_SAVE_BUTTON_KEY}"

  class="button primary"

  type="submit"

  name="save"

  onclick="return verify_data('ConfigureSettings');"

  value="  {$APP.LBL_SAVE_BUTTON_LABEL}  " >

   <input title="{$MOD.LBL_CANCEL_BUTTON_TITLE}"  onclick="document.location.href='index.php?module=Administration&action=index'" class="button"  type="button" name="cancel" value="  {$APP.LBL_CANCEL_BUTTON_LABEL}  " > </td>

  </tr>

  </table>

  <table width="100%" border="0" cellspacing="1" cellpadding="0" class="edit view">

  <tr>

  <th align="left" scope="row" colspan="4"><h4>{$MOD.AUTHENTICATION_SETTINGS}</h4></th>

  </tr>

  <tr>

  <td nowrap width="10%" scope="row">{$MOD.URL}: </td>

  <td width="25%" >

  <input type='text' name='url' size="60" value='{$URL}'>

  </td>

  <td nowrap width="10%" scope="row">{$MOD.USER}: </td>

  <td width="25%" >

  <input type='text' name='user' size="60" value='{$USER}'>

  </td>

  </tr>

  <tr>

  <td nowrap width="10%" scope="row">{$MOD.PASSWORD}: </td>

  <td width="25%" >

  <input type='text' name='password' size="60" value='{$PASSWORD}'>

  </td>

  <td nowrap width="10%" scope="row"></td>

  <td width="25%" >

  </td>

  </tr>

  </table>

  <div style="padding-top: 2px;">

  <input title="{$APP.LBL_SAVE_BUTTON_TITLE}" class="button primary"  type="submit" name="save" value="  {$APP.LBL_SAVE_BUTTON_LABEL}  " onclick="return verify_data('ConfigureSettings');"/>

   <input title="{$MOD.LBL_CANCEL_BUTTON_TITLE}"  onclick="document.location.href='index.php?module=Administration&action=index'" class="button"  type="button" name="cancel" value="  {$APP.LBL_CANCEL_BUTTON_LABEL}  " />

  </div>

  {$JAVASCRIPT}

  </form>

==========================================================

Step 7:  Quick repair and rebuild

=========================================================

Navigate to Admin > Repair and click "Quick Repair and Rebuild".

==========================================================

Step 8:  Return to Admin menu

=========================================================

In Admin, you will see a new panel : Authentication Information

Please, add your comments.

Thanks

Parents Reply Children
No Data