ea-Geiercode-base
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file config.inc.php

Documentation is available at config.inc.php

  1. <?php 
  2. /**
  3.  * php functions for user configurations
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage code/base
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: config.inc.php 149 2007-09-08 16:35:19Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * html functions for config screen
  29.  */
  30. require_once('code/base/config.html.php');
  31.  
  32. /**
  33.  * generate data for html output of config screen
  34.  *
  35.  * @param    eaDB    database
  36.  * @param    eaInput input data
  37.  * @param    string    state in state machine
  38.  */
  39. function genOptConfig(&$db&$in$state
  40.     $conf =$db->conf;
  41.     $user =$db->user;
  42.     // user configuration
  43.     if (!isset($in->options)) $in->options array();
  44.     $opt =$in->options;
  45.  
  46.     if (($state == 'userconfig'|| ($state == 'configuration')) {
  47.         $opt['userconfig'array();
  48.         $vars array('txtUserName' => $user['name']'mailUser' => $user['mail']'passUser' => '***');
  49.         foreach ($vars as $key => $val
  50.             $opt['userconfig'][array('name' => $key'value' => $val'what' => 'text');
  51.  
  52.         if ($dummy $db->getUserConf()) 
  53.             foreach ($dummy as $varswitch ($var['what']{
  54.                 case 'select':
  55.                     $split explode(';'$var['value']);
  56.                     if (isset($split[1])) $options $split[1]// value;options
  57.                     elseif (isset($split[0])) $options $split[0]// no value
  58.                     else $options $var['value'];
  59.                     if ($split explode(','$options))
  60.                         foreach ($split as $option{
  61.                             $option trim($option);
  62.                             switch ($option{
  63.                                 case 'komma':
  64.                                     $opt['userconfigopt'][$var['name']][$option',';
  65.                                     break;
  66.                                 case 'dot':
  67.                                     $opt['userconfigopt'][$var['name']][$option'.';
  68.                                     break;
  69.                                 default:
  70.                                     $opt['userconfigopt'][$var['name']][$option$option;
  71.                             }
  72.                         }
  73.                     $var['value'$conf[$var['name']];
  74.                     $opt['userconfig'][$var;
  75.                     break;
  76.                 default:
  77.                 $var['value'$conf[$var['name']];
  78.                 $opt['userconfig'][$var;
  79.             }
  80.         
  81.     
  82.         // fill fields with data from database
  83.         foreach ($opt['userconfig'as $var$in->post[$var['name']] $var['value'];
  84.  
  85.     else $opt['userconfig'true;
  86.  
  87.     if ($state == 'sysconfig'{
  88.         // system configuration
  89.         $opt['sysconfig'array()
  90.         if ($dummy $db->getSysConf()) {    
  91.             foreach ($dummy as $var{
  92.                 $var['value'$conf[$var['name']];
  93.                 $opt['sysconfig'][$var;
  94.             }
  95.         }
  96.  
  97.         // fill fields with data from database
  98.         if (isset($opt['sysconfig'])) 
  99.             foreach ($opt['sysconfig'as $var$in->post[$var['name']] $var['value'];
  100.  
  101.     elseif ($db->getSysConf()) $opt['sysconfig'true;
  102.     
  103.     if ($state == 'clientconfig'{
  104.         $opt['clientnew'array();
  105.         $vars array('txtNewClientName' => '');
  106.         foreach ($vars as $key => $val
  107.             $opt['clientnew'][array('name' => $key'value' => $val'what' => 'text');
  108.  
  109.         if (($clientID $in->getClient($db)) && $db->isOwner($clientID)) {
  110.             $client =$db->clients[$clientID];
  111.             $opt['clientconfig'array();
  112.             $vars array('txtClientName' => $client['name']);
  113.             foreach ($vars as $key => $val
  114.                 $opt['clientconfig'][array('name' => $key'value' => $val'what' => 'text');
  115.  
  116.             if ($dummy $db->getClientConf($clientID)) 
  117.                 foreach ($dummy as $varswitch ($var['what']{
  118.                     case 'select':
  119.                         $split explode(';'$var['value']);
  120.                         if (isset($split[1])) $options $split[1]// value;options
  121.                         elseif (isset($split[0])) $options $split[0]// no value
  122.                         else $options $var['value'];
  123.                         if ($split explode(','$options))
  124.                             foreach ($split as $option{
  125.                                 $option trim($option);
  126.                                 switch ($option{
  127.                                     case 'komma':
  128.                                         $opt['clientconfigopt'][$var['name']][$option',';
  129.                                         break;
  130.                                     case 'dot':
  131.                                         $opt['clientconfigopt'][$var['name']][$option'.';
  132.                                         break;
  133.                                     default:
  134.                                         $opt['clientconfigopt'][$var['name']][$option$option;
  135.                                 }
  136.                             }
  137.                         $var['value'$conf[$var['name']];
  138.                         $opt['clientconfig'][$var;
  139.                         break;
  140.                     default:
  141.                         $var['value'$conf[$var['name']];
  142.                         $opt['clientconfig'][$var;
  143.                 }
  144.             
  145.  
  146.             // fill fields with data from database
  147.             if (isset($opt['clientconfig'])) 
  148.                 foreach ($opt['clientconfig'as $var$in->post[$var['name']] $var['value'];
  149.  
  150.             // add user to client
  151.             $opt['clientnewuser'array();
  152.             $vars array('mailNewUser' => '');
  153.             foreach ($vars as $key => $val
  154.                 $opt['clientnewuser'][array('name' => $key'value' => $val'what' => 'text');
  155.  
  156.             // delete users
  157.             if (isset($opt['clientdeluser'])) $opt['clientdeluser'array();
  158.             if ($users $db->getClientUsers($clientID)) 
  159.                 $opt['clientdeluser'][array('name' => 'numDelUser''value' => $users'what' => 'select');
  160.         }
  161.         
  162.         if ($clientID && !$db->isOwner($clientID)) {
  163.             $opt['notowner'true;
  164.         }
  165.  
  166.         
  167.     else $opt['clientconfig'true;
  168.     
  169. }
  170.  
  171. /**
  172.  * saves user configuration
  173.  *
  174.  * validates the input data and saves the changed values
  175.  *
  176.  * @param    eaDB    database
  177.  * @param    eaInput input data
  178.  * @return    boolean status
  179.  */
  180. function saveUserConfig(&$db&$in{
  181.     $user =$db->user;
  182.  
  183.     if (!isset($_POST['buttonUserConfig'])) return false;
  184.     $in->post['buttonUserConfig'true;
  185.     
  186.     $vars array('p:txt:pass''p:mail:mail''p:txt:txt''p:num:num''p:abc:abc');
  187.     $in->check($vars);
  188.  
  189.     if ($in->errorreturn false// wrong input
  190.     
  191.     $changed getChangedVars($db$in'userconfig');
  192.  
  193.     if ($in->errorreturn false// missing vars
  194.  
  195.     if (!$changedreturn true// no change
  196.  
  197.     if (isset($changed['abcLanguage'])) {
  198.         $in->language $changed['abcLanguage'];
  199.         $_SESSION['language'$changed['abcLanguage']
  200.     }
  201.     
  202.     $newUser array();
  203.     $vars array('txtUserName' => 'name''mailUser' => 'mail''passUser' => 'pw');
  204.     foreach ($vars as $key => $valif (isset($changed[$key])) {
  205.         $newUser[$val$changed[$key];
  206.         unset($changed[$key]);
  207.     }
  208.     if ($newUser
  209.         if (!$db->updateUser($user['mail']$newUsertrue))  {
  210.             $in->error['userexists'true;
  211.             $in->error['mailUser'true;
  212.             return false;
  213.         }
  214.     
  215.     if (!$changedreturn true// no change
  216.  
  217.     return $db->updateUserConf($user['id']$changed);
  218. }
  219.  
  220. /**
  221.  * saves system configuration
  222.  *
  223.  * validates the input data and saves the changed values
  224.  *
  225.  * @param    eaDB    database
  226.  * @param    eaInput input data
  227.  * @return    boolean status
  228.  */
  229. function saveSysConfig(&$db&$in{
  230.     $conf =$db->conf;
  231.     $user =$db->user;
  232.     
  233.     if ($user['mail'!= eaSYSADMINreturn false;
  234.     
  235.     if (!isset($_POST['buttonSysConfig'])) return false;
  236.     $in->post['buttonSysConfig'true;
  237.  
  238.     $vars array('p:mail:mail''p:txt:txt''p:num:num''p:dsn:dsn');
  239.     $in->check($vars);
  240.     
  241.     $vars array('dsnNewClientDB');
  242.     allowEmptyVars($in$vars);
  243.  
  244.     if ($in->errorreturn false// wrong input
  245.  
  246.     $changed getChangedVars($db$in'sysconfig'$conf['dsn']);
  247.  
  248.     if ($in->errorreturn false// missing vars
  249.  
  250.     if (!$changedreturn true// no change
  251.  
  252.     return $db->updateSysConf($changed);
  253. }
  254.         
  255. /**
  256.  * saves client configuration
  257.  *
  258.  * validates the input data and saves the changed values
  259.  *
  260.  * @param    eaDB    database
  261.  * @param    eaInput input data
  262.  * @param    array    user data
  263.  * @return    boolean status
  264.  */
  265. function saveClientConfig(&$db&$in{
  266.     if (!isset($_POST['buttonClientConfig'])) return false;
  267.     $in->post['buttonClientConfig'true;
  268.  
  269.     $vars array('p:txt:txt''p:num:num');
  270.     $in->check($vars);
  271.  
  272.     if ($in->errorreturn false// wrong input
  273.  
  274.     $changed getChangedVars($db$in'clientconfig');
  275.  
  276.     if ($in->errorreturn false// missing vars
  277.  
  278.     if (!$changedreturn true// no change
  279.  
  280.     $client $in->options['client'];
  281.     
  282.     if (!$db->isOwner($client)) return false;
  283.     
  284.     $newClient array();
  285.     $vars array('txtClientName' => 'name');
  286.     foreach ($vars as $key => $valif (isset($changed[$key])) {
  287.         if ($val == 'name'$in->options['clients'][$client$changed[$key];
  288.         $newClient[$val$changed[$key];
  289.         unset($changed[$key]);
  290.     }
  291.     
  292.     if ($newClient
  293.         if (!$db->updateClient($client$newClienttrue)) return false;
  294.     
  295.     if (!$changedreturn true// no change
  296.  
  297.     return $db->updateClientConf($client$changed);
  298. }
  299.  
  300. /**
  301.  * saves new client
  302.  *
  303.  * validates the input data and creates the new client
  304.  *
  305.  * @param    eaDB    database
  306.  * @param    eaInput input data
  307.  * @return    boolean status
  308.  */
  309. function saveNewClient(&$db&$in{
  310.     if (!isset($_POST['buttonClientNew'])) return false;
  311.     $in->post['buttonClientNew'true;
  312.  
  313.     $vars array('p:txt:txt');
  314.     $in->check($vars);
  315.  
  316.     if ($in->errorreturn false// wrong input
  317.  
  318.     if (!$client $db->createClient($in->post)) return false;
  319.  
  320.     $db->getClients($in);
  321.     genOptConfig($db$in$in->get('state'));
  322.     $in->options['notowner'false;
  323.     
  324.     return $client;
  325. }
  326.         
  327. /**
  328.  * saves new client user
  329.  *
  330.  * validates the input data and adds the new client
  331.  *
  332.  * @param    eaDB    database
  333.  * @param    eaInput input data
  334.  * @return    boolean status
  335.  */
  336. function saveNewClientUser(&$db&$in{
  337.     if (!isset($_POST['buttonClientNewUser'])) return false;
  338.     $in->post['buttonClientNewUser'true;
  339.  
  340.     $vars array('p:mail:mail');
  341.     $in->check($vars);
  342.  
  343.     if ($in->errorreturn false// wrong input
  344.  
  345.     $mail $in->post['mailNewUser'];
  346.     if (!$db->isUser($mail)) {
  347.         $in->error['usernotexisting'true;
  348.         $in->error['mailNewUser'true;
  349.         return false;
  350.     }
  351.  
  352.     $clientID $in->options['client'];
  353.  
  354.     if (!$db->isOwner($clientID)) return false;
  355.  
  356.     if (!$db->addUserToClient($clientID$mail)) return false;
  357.     
  358.     $in->options['clientdeluser'array();
  359.     if ($users $db->getClientUsers($clientID)) 
  360.         $in->options['clientdeluser'][array('name' => 'numDelUser''value' => $users'what' => 'select');
  361.     return true;
  362. }
  363.  
  364. /**
  365.  * removes client user
  366.  *
  367.  * validates the input data and removes client
  368.  *
  369.  * @param    eaDB    database
  370.  * @param    eaInput input data
  371.  * @return    boolean status
  372.  */
  373. function saveDelClientUser(&$db&$in{
  374.     if (!isset($_POST['buttonClientDelUser'])) return false;
  375.     $in->post['buttonClientDelUser'true;
  376.  
  377.     $vars array('p:num:num');
  378.     $in->check($vars);
  379.  
  380.     if ($in->errorreturn false// wrong input
  381.  
  382.     $clientID $in->options['client'];
  383.  
  384.     if (!$db->isOwner($clientID)) return false;
  385.  
  386.     if (!$db->delUserClient($clientID$in->post('numDelUser'))) return false;
  387.     
  388.     $in->options['clientdeluser'array();
  389.     if ($users $db->getClientUsers($clientID)) 
  390.         $in->options['clientdeluser'][array('name' => 'numDelUser''value' => $users'what' => 'select');
  391.     else unset($in->options['clientdeluser']);
  392.     return true;
  393. }
  394.  
  395. /**
  396.  * finds changed variables
  397.  *
  398.  * @param    eaInput input data
  399.  * @param    string    variable type
  400.  * @return    array    changed variables
  401.  */
  402. function getChangedVars(&$db&$in$what$key 'dummy'{
  403.     $opt =$in->options;
  404.     if (!isset($opt[$what])) return false;
  405.     $changed array()
  406.     foreach ($opt[$whatas $var{
  407.         $name $var['name'];
  408.         if (isset($in->post[$name])) {
  409.             $post =$in->post[$name];
  410.             if ($post == $var['value']continue;
  411.             switch ($var['what']{
  412.                 case 'select':
  413.                     if (!isset($opt[$what 'opt'][$name][$post])) {
  414.                         $in->error[$nametrue;
  415.                         break;
  416.                     }
  417.                     $changed[$name$post;
  418.                     break;
  419.                 case 'encrypt':
  420.                     $changed[$name$db->encrypt($post$key);
  421.                     break;
  422.                 default:
  423.                     $changed[$name$post;
  424.             }
  425.         else $in->error[$nametrue;
  426.     }
  427.     return $changed;
  428. }
  429.  
  430. /**
  431.  * allow empty variables
  432.  *
  433.  * @param    eaInput input data
  434.  * @param    array    variables
  435.  */
  436. function allowEmptyVars(&$in$what{
  437.     foreach ($what as $var{
  438.         if (!isset($in->error[$var])) continue;
  439.         if ($in->error[$var!= 'empty'continue;
  440.         unset($in->error[$var]);
  441.     }
  442. }
  443.  
  444. ?>

Documentation generated on Sun, 09 Sep 2007 17:08:15 +0200 by phpDocumentor 1.3.1