Location: PHPKode > projects > Knowledge Box > knowledgebox/wizard/authentication.php
<?php

  /*
   * Free IT Foundation
   * Free Technology Serving Knowledge
   * http://www.free-it-foundation.org
   * 
   * This file is part of Knowledge Box.
   * 
   * Knowledge Box is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   * 
   * Knowledge Box is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with Knowledge Box.  If not, see <http://www.gnu.org/licenses/>.
   */

  
  // restrict access
  if (!KB_IS_ADMINISTRATOR)
    $AppUI->redirect (KB_ACCESS_DENIED);

  // title block
  $titleBlock = new CTitleBlock (utf8_encode (html_entity_decode ($AppUI->_('titleExternalAuthentication'))), KB_MODULE_ICON);

  // breadcrumb
  $titleBlock->addCrumb ('?m=' . KB_MODULE, utf8_encode (html_entity_decode ($AppUI->_('backToBox'))));

  // show the title block
  $titleBlock->show ();

  // config
  $configAuthenticationUsername = KBModuleConfig::getConfig (KB_BASE_UNDEFINED, KB_CONFIG_PROPERTY_AUTHENTICATION_USERNAME);
  $configAuthenticationPassword = KBModuleConfig::getConfig (KB_BASE_UNDEFINED, KB_CONFIG_PROPERTY_AUTHENTICATION_PASSWORD);
  $configAuthenticationRecovery = KBModuleConfig::getConfig (KB_BASE_UNDEFINED, KB_CONFIG_PROPERTY_AUTHENTICATION_RECOVERY);

  // get resources
  $bases = KBModuleBase::getBases ();

?>

<script type="text/javascript">
  
  function checkMapping ()
  {
    var f = document.authenticationForm;
    var fields = new Array ();

    var base_username = 0;
    var base_password = 0;
    var base_recovery = 0;

    <?
      // iterate over bases
      foreach ($bases as $base)
      {
        // fields
        $fields = KBModuleField::getFieldsByBase ($base->getId ());
        
        // iterate
        foreach ($fields as $field)
        {
    ?>
      fields [<?= $field->getId () ?>] = <?= $base->getId () ?>;
    <?  }
      }
    ?>
    
    // username
    if (f.username.value < 0)
      base_username = -f.username.value;
    else if (f.username.value > 0)
      base_username = fields [f.username.value];

    // password
    if (f.password.value > 0)
      base_password = fields [f.password.value];
    
    // recovery
    if (f.recovery.value > 0)
      base_recovery = fields [f.recovery.value];

    // mapping on same kb
    if (base_username != base_password)
      return false;
    
    // recovery optional
    if (base_recovery == 0)
      return true;
      
    // recovery mapping on same kb
    return base_username == base_recovery;
  }
  
  function submitIt ()
  {
    if (!checkMapping ())
    {
      alert ("<?= utf8_encode (html_entity_decode ($AppUI->_('alertExternalAuthenticationMapping'))) ?>");
      return false;
    }
    
    return true;
  }
  
  function cancelIt ()
  {
    location.href = "index.php?m=<?= KB_MODULE ?>";
  }
  
</script>

<form name="authenticationForm" action="index.php?m=<?= KB_MODULE ?>" method="post" onSubmit="return submitIt();">
<input type="hidden" name="dosql" value="authentication" />

<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">
<tr>
  <td width="50%" valign="top">
    <br />
    <table cellspacing="0" cellpadding="2" border="0">
    <tr>
      <td align="right" nowrap="nowrap" valign="top"><?= $AppUI->_('inputAuthenticationUsername') ?></td>
      <td width="35">
        <? if ($configAuthenticationUsername->getIntValue () == KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED) { ?>
          <?= dPshowImage ('./images/obj/warning.gif', '14', '14') ?>
        <? } else { ?>
          &nbsp;
        <? } ?>
        <br />&nbsp;
      </td>
      <td width="100%" valign="top">
        <select name="username">
          <optgroup label="<?= $AppUI->_('inputAuthenticationUndefined') ?>">
            <option value="<?= KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED ?>"<? if ($configAuthenticationUsername->getIntValue () == KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED) print (' selected="selected"'); ?>><?= $AppUI->_('inputAuthenticationUndefined') ?></option>
          </optgroup>
          <?
            // iterate over bases
            foreach ($bases as $base)
            {
          ?>
            <optgroup label="<?= $base->getName () ?>">
              <option value="-<?= $base->getId () ?>"<? if ($configAuthenticationUsername->getIntValue () < 0 && $base->getId () == abs ($configAuthenticationUsername->getIntValue ())) print (' selected="selected"'); ?>><?= $AppUI->_('fieldTypeName') ?></option>
              <?
                // fields
                $fields = KBModuleField::getFieldsByBase ($base->getId ());
                
                // iterate
                foreach ($fields as $field)
                {
                  if ($field->isType (KB_FIELD_TEXT) || $field->isType (KB_FIELD_EMAIL))
                  {
              ?>
                <option value="<?= $field->getId () ?>"<? if ($configAuthenticationUsername->getIntValue () == $field->getId ()) print (' selected="selected"'); ?>><?= $field->getName () ?></option>
              <?
                  }
                }
              ?>
            </optgroup>
          <? } ?>
        </select>
        
        <br />
        <?= $AppUI->_('inputAuthenticationLimitUsername') ?>
      </td>
    </tr>
    <tr>
      <td colspan="3" height="10"></td>
    </tr>
    <tr>
      <td align="right" nowrap="nowrap" valign="top"><?= $AppUI->_('inputAuthenticationPassword') ?></td>
      <td>
        <? if ($configAuthenticationPassword->getIntValue () == KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED) { ?>
          <?= dPshowImage ('./images/obj/warning.gif', '14', '14') ?>
        <? } else { ?>
          &nbsp;
        <? } ?>
        <br />&nbsp;
      </td>
      <td valign="top">
        <select name="password">
          <optgroup label="<?= $AppUI->_('inputAuthenticationUndefined') ?>">
            <option value="<?= KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED ?>"<? if ($configAuthenticationPassword->getIntValue () == KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED) print (' selected="selected"'); ?>><?= $AppUI->_('inputAuthenticationUndefined') ?></option>
          </optgroup>
          <?
            // iterate over bases
            foreach ($bases as $base)
            {
              $capable = array ();
            
              // fields
              $fields = KBModuleField::getFieldsByBase ($base->getId ());
              
              // iterate
              foreach ($fields as $field)
              {
                if ($field->isType (KB_FIELD_PASSWORD))
                  $capable [] = $field;
              }
              
              // only capable bases
              if (count ($capable) > 0)
              {
          ?>
            <optgroup label="<?= $base->getName () ?>">
              <?                
                // iterate
                foreach ($capable as $field)
                {
              ?>
                <option value="<?= $field->getId () ?>"<? if ($configAuthenticationPassword->getIntValue () == $field->getId ()) print (' selected="selected"'); ?>><?= $field->getName () ?></option>
              <?
                }
              ?>
            </optgroup>
          <?
              }
            }
          ?>
        </select>
        
        <br />
        <?= $AppUI->_('inputAuthenticationLimitPassword') ?>
      </td>
    </tr>
    <tr>
      <td colspan="3" height="10"></td>
    </tr>
    <tr>
      <td align="right" nowrap="nowrap" valign="top"><?= $AppUI->_('inputAuthenticationRecovery') ?></td>
      <td>
        <? if ($configAuthenticationRecovery->getIntValue () == KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED) { ?>
          <?= dPshowImage ('./images/obj/warning.gif', '14', '14') ?>
        <? } else { ?>
          &nbsp;
        <? } ?>
        <br />&nbsp;
      </td>
      <td valign="top">
        <select name="recovery">
          <optgroup label="<?= $AppUI->_('inputAuthenticationUndefined') ?>">
            <option value="<?= KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED ?>"<? if ($configAuthenticationRecovery->getIntValue () == KB_CONFIG_DEFAULT_AUTHENTICATION_UNDEFINED) print (' selected="selected"'); ?>><?= $AppUI->_('inputAuthenticationUndefined') ?></option>
          </optgroup>
          <?
            // iterate over bases
            foreach ($bases as $base)
            {
              $capable = array ();
            
              // fields
              $fields = KBModuleField::getFieldsByBase ($base->getId ());
              
              // iterate
              foreach ($fields as $field)
              {
                if ($field->isType (KB_FIELD_EMAIL))
                  $capable [] = $field;
              }
              
              // only capable bases
              if (count ($capable) > 0)
              {
          ?>
            <optgroup label="<?= $base->getName () ?>">
              <?                
                // iterate
                foreach ($capable as $field)
                {
              ?>
                <option value="<?= $field->getId () ?>"<? if ($configAuthenticationRecovery->getIntValue () == $field->getId ()) print (' selected="selected"'); ?>><?= $field->getName () ?></option>
              <?
                }
              ?>
            </optgroup>
          <?
              }
            }
          ?>
        </select>
        
        <br />
        <?= $AppUI->_('inputAuthenticationLimitRecovery') ?>
      </td>
    </tr>
    </table>
  </td>
  <td></td>
</tr>
<tr>
  <td>
    <input class="button" type="button" name="cancel" value="<?= $AppUI->_('actionCancel') ?>" onClick="cancelIt();" />
  </td>
  <td align="right">
    <input class="button" type="submit" name="btnFuseAction" value="<?= $AppUI->_('actionSubmit') ?>"/>
  </td>
</tr>
</table>

</form>
Return current item: Knowledge Box