Source for file config.inc.php
Documentation is available at config.inc.php
* php functions for user configurations
* This program 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 2 of the License, or
* (at your option) any later version.
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: config.inc.php 149 2007-09-08 16:35:19Z m2mtech $
* @link http://www.ea-geier.at/
* html functions for config screen
require_once('code/base/config.html.php');
* generate data for html output of config screen
* @param eaInput input data
* @param string state in state machine
if (!isset ($in->options)) $in->options = array();
if (($state == 'userconfig') || ($state == 'configuration')) {
$opt['userconfig'] = array();
$vars = array('txtUserName' => $user['name'], 'mailUser' => $user['mail'], 'passUser' => '***');
foreach ($vars as $key => $val)
$opt['userconfig'][] = array('name' => $key, 'value' => $val, 'what' => 'text');
if ($dummy = $db->getUserConf()) {
foreach ($dummy as $var) switch ($var['what']) {
$split = explode(';', $var['value']);
if (isset ($split[1])) $options = $split[1]; // value;options
elseif (isset ($split[0])) $options = $split[0]; // no value
else $options = $var['value'];
if ($split = explode(',', $options))
foreach ($split as $option) {
$opt['userconfigopt'][$var['name']][$option] = ',';
$opt['userconfigopt'][$var['name']][$option] = '.';
$opt['userconfigopt'][$var['name']][$option] = $option;
$var['value'] = $conf[$var['name']];
$opt['userconfig'][] = $var;
$var['value'] = $conf[$var['name']];
$opt['userconfig'][] = $var;
// fill fields with data from database
foreach ($opt['userconfig'] as $var) $in->post[$var['name']] = $var['value'];
} else $opt['userconfig'] = true;
if ($state == 'sysconfig') {
$opt['sysconfig'] = array();
if ($dummy = $db->getSysConf()) {
foreach ($dummy as $var) {
$var['value'] = $conf[$var['name']];
$opt['sysconfig'][] = $var;
// fill fields with data from database
if (isset ($opt['sysconfig']))
foreach ($opt['sysconfig'] as $var) $in->post[$var['name']] = $var['value'];
} elseif ($db->getSysConf()) $opt['sysconfig'] = true;
if ($state == 'clientconfig') {
$opt['clientnew'] = array();
$vars = array('txtNewClientName' => '');
foreach ($vars as $key => $val)
$opt['clientnew'][] = array('name' => $key, 'value' => $val, 'what' => 'text');
if (($clientID = $in->getClient($db)) && $db->isOwner($clientID)) {
$client = & $db->clients[$clientID];
$opt['clientconfig'] = array();
$vars = array('txtClientName' => $client['name']);
foreach ($vars as $key => $val)
$opt['clientconfig'][] = array('name' => $key, 'value' => $val, 'what' => 'text');
if ($dummy = $db->getClientConf($clientID)) {
foreach ($dummy as $var) switch ($var['what']) {
$split = explode(';', $var['value']);
if (isset ($split[1])) $options = $split[1]; // value;options
elseif (isset ($split[0])) $options = $split[0]; // no value
else $options = $var['value'];
if ($split = explode(',', $options))
foreach ($split as $option) {
$opt['clientconfigopt'][$var['name']][$option] = ',';
$opt['clientconfigopt'][$var['name']][$option] = '.';
$opt['clientconfigopt'][$var['name']][$option] = $option;
$var['value'] = $conf[$var['name']];
$opt['clientconfig'][] = $var;
$var['value'] = $conf[$var['name']];
$opt['clientconfig'][] = $var;
// fill fields with data from database
if (isset ($opt['clientconfig']))
foreach ($opt['clientconfig'] as $var) $in->post[$var['name']] = $var['value'];
$opt['clientnewuser'] = array();
$vars = array('mailNewUser' => '');
foreach ($vars as $key => $val)
$opt['clientnewuser'][] = array('name' => $key, 'value' => $val, 'what' => 'text');
if (isset ($opt['clientdeluser'])) $opt['clientdeluser'] = array();
if ($users = $db->getClientUsers($clientID))
$opt['clientdeluser'][] = array('name' => 'numDelUser', 'value' => $users, 'what' => 'select');
if ($clientID && !$db->isOwner($clientID)) {
} else $opt['clientconfig'] = true;
* saves user configuration
* validates the input data and saves the changed values
* @param eaInput input data
if (!isset ($_POST['buttonUserConfig'])) return false;
$in->post['buttonUserConfig'] = true;
$vars = array('p:txt:pass', 'p:mail:mail', 'p:txt:txt', 'p:num:num', 'p:abc:abc');
if ($in->error) return false; // wrong input
if ($in->error) return false; // missing vars
if (!$changed) return true; // no change
if (isset ($changed['abcLanguage'])) {
$in->language = $changed['abcLanguage'];
$_SESSION['language'] = $changed['abcLanguage'];
$vars = array('txtUserName' => 'name', 'mailUser' => 'mail', 'passUser' => 'pw');
foreach ($vars as $key => $val) if (isset ($changed[$key])) {
$newUser[$val] = $changed[$key];
if (!$db->updateUser($user['mail'], $newUser, true)) {
$in->error['userexists'] = true;
$in->error['mailUser'] = true;
if (!$changed) return true; // no change
return $db->updateUserConf($user['id'], $changed);
* saves system configuration
* validates the input data and saves the changed values
* @param eaInput input data
if (!isset ($_POST['buttonSysConfig'])) return false;
$in->post['buttonSysConfig'] = true;
$vars = array('p:mail:mail', 'p:txt:txt', 'p:num:num', 'p:dsn:dsn');
$vars = array('dsnNewClientDB');
if ($in->error) return false; // wrong input
if ($in->error) return false; // missing vars
if (!$changed) return true; // no change
return $db->updateSysConf($changed);
* saves client configuration
* validates the input data and saves the changed values
* @param eaInput input data
if (!isset ($_POST['buttonClientConfig'])) return false;
$in->post['buttonClientConfig'] = true;
$vars = array('p:txt:txt', 'p:num:num');
if ($in->error) return false; // wrong input
if ($in->error) return false; // missing vars
if (!$changed) return true; // no change
$client = $in->options['client'];
if (!$db->isOwner($client)) return false;
$vars = array('txtClientName' => 'name');
foreach ($vars as $key => $val) if (isset ($changed[$key])) {
if ($val == 'name') $in->options['clients'][$client] = $changed[$key];
$newClient[$val] = $changed[$key];
if (!$db->updateClient($client, $newClient, true)) return false;
if (!$changed) return true; // no change
return $db->updateClientConf($client, $changed);
* validates the input data and creates the new client
* @param eaInput input data
if (!isset ($_POST['buttonClientNew'])) return false;
$in->post['buttonClientNew'] = true;
$vars = array('p:txt:txt');
if ($in->error) return false; // wrong input
if (!$client = $db->createClient($in->post)) return false;
$in->options['notowner'] = false;
* validates the input data and adds the new client
* @param eaInput input data
if (!isset ($_POST['buttonClientNewUser'])) return false;
$in->post['buttonClientNewUser'] = true;
$vars = array('p:mail:mail');
if ($in->error) return false; // wrong input
$mail = $in->post['mailNewUser'];
if (!$db->isUser($mail)) {
$in->error['usernotexisting'] = true;
$in->error['mailNewUser'] = true;
$clientID = $in->options['client'];
if (!$db->isOwner($clientID)) return false;
if (!$db->addUserToClient($clientID, $mail)) return false;
$in->options['clientdeluser'] = array();
if ($users = $db->getClientUsers($clientID))
$in->options['clientdeluser'][] = array('name' => 'numDelUser', 'value' => $users, 'what' => 'select');
* validates the input data and removes client
* @param eaInput input data
if (!isset ($_POST['buttonClientDelUser'])) return false;
$in->post['buttonClientDelUser'] = true;
$vars = array('p:num:num');
if ($in->error) return false; // wrong input
$clientID = $in->options['client'];
if (!$db->isOwner($clientID)) return false;
if (!$db->delUserClient($clientID, $in->post('numDelUser'))) return false;
$in->options['clientdeluser'] = array();
if ($users = $db->getClientUsers($clientID))
$in->options['clientdeluser'][] = array('name' => 'numDelUser', 'value' => $users, 'what' => 'select');
else unset ($in->options['clientdeluser']);
* finds changed variables
* @param eaInput input data
* @param string variable type
* @return array changed variables
if (!isset ($opt[$what])) return false;
foreach ($opt[$what] as $var) {
if (isset ($in->post[$name])) {
$post = & $in->post[$name];
if ($post == $var['value']) continue;
if (!isset ($opt[$what . 'opt'][$name][$post])) {
$in->error[$name] = true;
$changed[$name] = $db->encrypt($post, $key);
} else $in->error[$name] = true;
* @param eaInput input data
foreach ($what as $var) {
if (!isset ($in->error[$var])) continue;
if ($in->error[$var] != 'empty') continue;
|