"Fossies" - the Fresh Open Source Software Archive

Member "ispconfig3_install/interface/web/client/client_edit.php" (8 Jun 2021, 23507 Bytes) of package /linux/privat/ISPConfig-3.2.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "client_edit.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.2.4_vs_3.2.5.

    1 <?php
    2 /*
    3 Copyright (c) 2005 - 2012, Till Brehm, projektfarm Gmbh, ISPConfig UG
    4 All rights reserved.
    5 
    6 Redistribution and use in source and binary forms, with or without modification,
    7 are permitted provided that the following conditions are met:
    8 
    9     * Redistributions of source code must retain the above copyright notice,
   10       this list of conditions and the following disclaimer.
   11     * Redistributions in binary form must reproduce the above copyright notice,
   12       this list of conditions and the following disclaimer in the documentation
   13       and/or other materials provided with the distribution.
   14     * Neither the name of ISPConfig nor the names of its contributors
   15       may be used to endorse or promote products derived from this software without
   16       specific prior written permission.
   17 
   18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
   19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
   25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
   27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   28 */
   29 
   30 
   31 /******************************************
   32 * Begin Form configuration
   33 ******************************************/
   34 
   35 $tform_def_file = "form/client.tform.php";
   36 
   37 /******************************************
   38 * End Form configuration
   39 ******************************************/
   40 
   41 require_once '../../lib/config.inc.php';
   42 require_once '../../lib/app.inc.php';
   43 
   44 //* Check permissions for module
   45 $app->auth->check_module_permissions('client');
   46 
   47 // Loading classes
   48 $app->uses('tpl,tform,tform_actions');
   49 $app->load('tform_actions');
   50 
   51 class page_action extends tform_actions {
   52     var $_template_additional = array();
   53 
   54     function onShowNew() {
   55         global $app, $conf;
   56 
   57         // we will check only users, not admins
   58         if($_SESSION["s"]["user"]["typ"] == 'user') {
   59 
   60             // Get the limits of the client
   61             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
   62             $client = $app->db->queryOneRecord("SELECT limit_client FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
   63 
   64             // Check if the user may add another website.
   65             if($client["limit_client"] >= 0) {
   66                 $tmp = $app->db->queryOneRecord("SELECT count(client_id) as number FROM client WHERE sys_groupid = ?", $client_group_id);
   67                 if($tmp["number"] >= $client["limit_client"]) {
   68                     $app->error($app->tform->wordbook["limit_client_txt"]);
   69                 }
   70             }
   71         }
   72 
   73         parent::onShowNew();
   74     }
   75 
   76 
   77     function onSubmit() {
   78         global $app, $conf;
   79 
   80         // we will check only users, not admins
   81         if($_SESSION["s"]["user"]["typ"] == 'user' && $this->id == 0) {
   82 
   83             // Get the limits of the client
   84             $client_group_id = $_SESSION["s"]["user"]["default_group"];
   85             $client = $app->db->queryOneRecord("SELECT limit_client FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
   86 
   87             // Check if the user may add another website.
   88             if($client["limit_client"] >= 0) {
   89                 $tmp = $app->db->queryOneRecord("SELECT count(client_id) as number FROM client WHERE sys_groupid = ?", $client_group_id);
   90                 if($tmp["number"] >= $client["limit_client"]) {
   91                     $app->error($app->tform->wordbook["limit_client_txt"]);
   92                 }
   93             }
   94         }
   95 
   96         //* Resellers shall not be able to create another reseller
   97         if($_SESSION["s"]["user"]["typ"] == 'user') {
   98             $this->dataRecord['limit_client'] = 0;
   99         } else {
  100             if($this->dataRecord["reseller"]) {
  101                 $this->dataRecord["limit_client"] = 1; // allow 1 client, template limits will be applied later, if we set -1 it would override template limits
  102             }
  103         }
  104 
  105         if($this->id != 0) {
  106             $this->oldTemplatesAssigned = $app->db->queryAllRecords('SELECT * FROM `client_template_assigned` WHERE `client_id` = ?', $this->id);
  107             if(!is_array($this->oldTemplatesAssigned) || count($this->oldTemplatesAssigned) < 1) {
  108                 // check previous type of storing templates
  109                 $tpls = explode('/', $this->oldDataRecord['template_additional']);
  110                 $this->oldTemplatesAssigned = array();
  111                 foreach($tpls as $item) {
  112                     $item = trim($item);
  113                     if(!$item) continue;
  114                     $this->oldTemplatesAssigned[] = array('assigned_template_id' => 0, 'client_template_id' => $item, 'client_id' => $this->id);
  115                 }
  116                 unset($tpls);
  117             }
  118         } else {
  119             $this->oldTemplatesAssigned = array();
  120         }
  121 
  122         $this->_template_additional = explode('/', $this->dataRecord['template_additional']);
  123         $this->dataRecord['template_additional'] = '';
  124 
  125         parent::onSubmit();
  126     }
  127 
  128     function onShowEnd() {
  129 
  130         global $app;
  131 
  132         $sql = "SELECT template_id,template_name FROM client_template WHERE template_type = 'a' and ".$app->tform->getAuthSQL('r')." ORDER BY template_name ASC";
  133         $tpls = $app->db->queryAllRecords($sql);
  134         $option = '';
  135         $tpl = array();
  136         $tpls = $app->functions->htmlentities($tpls);
  137         foreach($tpls as $item){
  138             $option .= '<option value="' . $item['template_id'] . '|' .  $item['template_name'] . '">' . $item['template_name'] . '</option>';
  139             $tpl[$item['template_id']] = $item['template_name'];
  140         }
  141         $app->tpl->setVar('tpl_add_select', $option);
  142 
  143         // check for new-style records
  144         $result = $app->db->queryAllRecords('SELECT assigned_template_id, client_template_id FROM client_template_assigned WHERE client_id = ?', $this->id);
  145         if($result && count($result) > 0) {
  146             // new style
  147             $items = array();
  148             $text = '';
  149             foreach($result as $item){
  150                 if (trim($item['client_template_id']) != ''){
  151                     if ($text != '') $text .= '';
  152                     $text .= '<li rel="' . $item['assigned_template_id'] . '">' . $tpl[$item['client_template_id']];
  153                     $text .= '&nbsp;<a href="#" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></a>';
  154                     $tmp = new stdClass();
  155                     $tmp->id = $item['assigned_template_id'];
  156                     $tmp->data = '';
  157                     $app->plugin->raiseEvent('get_client_template_details', $tmp);
  158                     if($tmp->data != '') $text .= '<br /><em>' . $app->functions->htmlentities($tmp->data) . '</em>';
  159 
  160                     $text .= '</li>';
  161                     $items[] = $item['assigned_template_id'] . ':' . $item['client_template_id'];
  162                 }
  163             }
  164 
  165             $tmprec = $app->tform->getHTML(array('template_additional' => implode('/', $items)), $this->active_tab, 'EDIT');
  166             $app->tpl->setVar('template_additional', $tmprec['template_additional']);
  167             unset($tmprec);
  168         } else {
  169             // old style
  170             $sql = "SELECT template_additional FROM client WHERE client_id = ?";
  171             $result = $app->db->queryOneRecord($sql, $this->id);
  172             $tplAdd = explode("/", $result['template_additional']);
  173             $text = '';
  174             foreach($tplAdd as $item){
  175                 if (trim($item) != ''){
  176                     if ($text != '') $text .= '';
  177                     $text .= '<li>' . $tpl[$item]. '&nbsp;<a href="#" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></a></li>';
  178                 }
  179             }
  180         }
  181 
  182         $app->tpl->setVar('template_additional_list', $text);
  183         $app->tpl->setVar('app_module', 'client');
  184 
  185         // Check wether per domain relaying is enabled or not
  186         $global_config = $app->getconf->get_global_config('mail');
  187         if($global_config['show_per_domain_relay_options'] == 'y') {
  188             $app->tpl->setVar("show_per_domain_relay_options", 1);
  189         } else {
  190             $app->tpl->setVar("show_per_domain_relay_options", 0);
  191         }
  192 
  193         // APS is enabled or not
  194         $global_config = $app->getconf->get_global_config('sites');
  195         if($global_config['show_aps_menu'] == 'y') {
  196             $app->tpl->setVar("show_aps_menu", 1);
  197         } else {
  198             $app->tpl->setVar("show_aps_menu", 0);
  199         }
  200 
  201 
  202 
  203         //* Set the 'customer no' default value
  204         if($this->id == 0) {
  205 
  206             if($app->auth->is_admin()) {
  207                 //* Logged in User is admin
  208                 //* get the system config
  209                 $app->uses('getconf');
  210                 $system_config = $app->getconf->get_global_config();
  211                 if($system_config['misc']['customer_no_template'] != '') {
  212 
  213                     //* Set customer no default
  214                     $customer_no = $app->functions->intval($system_config['misc']['customer_no_start']+$system_config['misc']['customer_no_counter']);
  215                     $customer_no_string = str_replace('[CUSTOMER_NO]',$customer_no,$system_config['misc']['customer_no_template']);
  216                     $app->tpl->setVar('customer_no',$customer_no_string);
  217                 }
  218             } else {
  219                 //* Logged in user must be a reseller
  220                 //* get the record of the reseller
  221                 $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  222                 $reseller = $app->db->queryOneRecord("SELECT client.client_id, client.customer_no_template, client.customer_no_counter, client.customer_no_start FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = ?", $client_group_id);
  223 
  224                 if($reseller['customer_no_template'] != '') {
  225                     if(isset($this->dataRecord['customer_no'])&& $this->dataRecord['customer_no']!='') $customer_no_string = $this->dataRecord['customer_no'];
  226                     else {
  227                         //* Set customer no default
  228                         $customer_no = $app->functions->intval($reseller['customer_no_start']+$reseller['customer_no_counter']);
  229                         $customer_no_string = str_replace(array('[CUSTOMER_NO]','[CLIENTID]'),array($customer_no, $reseller['client_id']),$reseller['customer_no_template']);
  230                     }
  231                     $app->tpl->setVar('customer_no',$customer_no_string);
  232                 }
  233             }
  234         }
  235 
  236         if($app->auth->is_admin()) {
  237             // Fill the client select field
  238             $sql = "SELECT client.client_id, sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 AND client.limit_client != 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
  239             $clients = $app->db->queryAllRecords($sql);
  240             $clients = $app->functions->htmlentities($clients);
  241             $client_select = "<option value='0'>- ".$app->tform->lng('none_txt')." -</option>";
  242             //$tmp_data_record = $app->tform->getDataRecord($this->id);
  243             if(is_array($clients)) {
  244                 $selected_client_id = 0; // needed to get list of PHP versions
  245                 foreach($clients as $client) {
  246                     if(is_array($this->dataRecord) && ($client["client_id"] == $this->dataRecord['parent_client_id']) && !$selected_client_id) $selected_client_id = $client["client_id"];
  247                     $selected = @(is_array($this->dataRecord) && ($client["client_id"] == $this->dataRecord['parent_client_id']))?'SELECTED':'';
  248                     if($selected == 'SELECTED') $selected_client_id = $client["client_id"];
  249                     $client_select .= "<option value='$client[client_id]' $selected>$client[contactname]</option>\r\n";
  250                 }
  251             }
  252             $app->tpl->setVar("parent_client_id", $client_select);
  253         }
  254 
  255         parent::onShowEnd();
  256 
  257     }
  258 
  259     /*
  260      This function is called automatically right after
  261      the data was successful inserted in the database.
  262     */
  263     function onAfterInsert() {
  264         global $app, $conf;
  265         // Create the group for the client
  266         $groupid = $app->db->datalogInsert('sys_group', array("name" => $this->dataRecord["username"], "description" => '', "client_id" => $this->id), 'groupid');
  267         $groups = $groupid;
  268 
  269         $username = $this->dataRecord["username"];
  270         $password = $this->dataRecord["password"];
  271         $modules = $conf['interface_modules_enabled'];
  272         if(isset($this->dataRecord["limit_client"]) && $this->dataRecord["limit_client"] > 0) $modules .= ',client';
  273         $startmodule = (stristr($modules, 'dashboard'))?'dashboard':'client';
  274         $usertheme = (isset($this->dataRecord["usertheme"]) && $this->dataRecord["usertheme"] != ''? $this->dataRecord["usertheme"] : 'default');
  275         $type = 'user';
  276         $active = 1;
  277         $language = $this->dataRecord["language"];
  278         $password = $app->auth->crypt_password($password);
  279 
  280         // Create the controlpaneluser for the client
  281         //Generate ssh-rsa-keys
  282         $app->uses('functions');
  283         $app->functions->generate_ssh_key($this->id, $username);
  284 
  285         // Create the controlpaneluser for the client
  286         $sql = "INSERT INTO sys_user (`username`,`passwort`,`modules`,`startmodule`,`app_theme`,`typ`,`active`,`language`,`groups`,`default_group`,`client_id`)
  287         VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  288         $app->db->query($sql, $username, $password, $modules, $startmodule, $usertheme, $type, $active, $language, $groups, $groupid, $this->id);
  289 
  290         //* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
  291         //* to his groups, so he can administrate the records of this client.
  292         if($_SESSION['s']['user']['typ'] == 'user') {
  293             $app->auth->add_group_to_user($_SESSION['s']['user']['userid'], $groupid);
  294             $app->db->query("UPDATE client SET parent_client_id = ? WHERE client_id = ?", $_SESSION['s']['user']['client_id'], $this->id);
  295         } else {
  296             if($this->dataRecord['parent_client_id'] > 0) {
  297                 //* get userid of the reseller and add it to the group of the client
  298                 $tmp = $app->db->queryOneRecord("SELECT sys_user.userid FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ?", $this->dataRecord['parent_client_id']);
  299                 $app->auth->add_group_to_user($tmp['userid'], $groupid);
  300                 $app->db->query("UPDATE client SET parent_client_id = ? WHERE client_id = ?", $this->dataRecord['parent_client_id'], $this->id);
  301                 unset($tmp);
  302             }
  303         }
  304 
  305         //* Set the default servers
  306         $tmp = $app->getconf->get_global_config('mail');
  307         $default_mailserver = $app->functions->intval($tmp['default_mailserver']);
  308         if (!$default_mailserver) {
  309             $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE mail_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
  310             $default_mailserver = $app->functions->intval($tmp['server_id']);
  311         }
  312         $tmp = $app->getconf->get_global_config('sites');
  313         $default_webserver = $app->functions->intval($tmp['default_webserver']);
  314         $default_dbserver = $app->functions->intval($tmp['default_dbserver']);
  315         if (!$default_webserver) {
  316             $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE web_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
  317             $default_webserver = $app->functions->intval($tmp['server_id']);
  318         }
  319         if (!$default_dbserver) {
  320             $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE db_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
  321             $default_dbserver = $app->functions->intval($tmp['server_id']);
  322         }
  323         $tmp = $app->getconf->get_global_config('dns');
  324         $default_dnsserver = $app->functions->intval($tmp['default_dnsserver']);
  325         if (!$default_dnsserver) {
  326             $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE dns_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
  327             $default_dnsserver = $app->functions->intval($tmp['server_id']);
  328         }
  329 
  330         $sql = "UPDATE client SET mail_servers = ?, web_servers = ?, dns_servers = ?, default_slave_dnsserver = ?, db_servers = ? WHERE client_id = ?";
  331         $app->db->query($sql, $default_mailserver, $default_webserver, $default_dnsserver, $default_dnsserver, $default_dbserver, $this->id);
  332 
  333         if(isset($this->dataRecord['template_master'])) {
  334             $app->uses('client_templates');
  335             $app->client_templates->update_client_templates($this->id, $this->_template_additional);
  336         }
  337 
  338         if($this->dataRecord['customer_no'] == $this->dataRecord['customer_no_org']) {
  339             if($app->auth->is_admin()) {
  340                 //* Logged in User is admin
  341                 //* get the system config
  342                 $app->uses('getconf');
  343                 $system_config = $app->getconf->get_global_config();
  344                 if($system_config['misc']['customer_no_template'] != '') {
  345 
  346                     //* save new counter value
  347                     $system_config['misc']['customer_no_counter']++;
  348                     $system_config_str = $app->ini_parser->get_ini_string($system_config);
  349                     $app->db->datalogUpdate('sys_ini', array("config" => $system_config_str), 'sysini_id', 1);
  350                 }
  351             } else {
  352                 //* Logged in user must be a reseller
  353                 //* get the record of the reseller
  354                 $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  355                 $reseller = $app->db->queryOneRecord("SELECT client.client_id, client.customer_no_template, client.customer_no_counter, client.customer_no_start FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = ?", $client_group_id);
  356 
  357                 if($reseller['customer_no_template'] != '') {
  358                     //* save new counter value
  359                     $customer_no_counter = $app->functions->intval($reseller['customer_no_counter']+1);
  360                     $app->db->query("UPDATE client SET customer_no_counter = ? WHERE client_id = ?", $customer_no_counter, $reseller['client_id']);
  361                 }
  362             }
  363         }
  364 
  365         //* Send welcome email
  366         $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  367         $sql = "SELECT * FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = ?";
  368         $email_template = $app->db->queryOneRecord($sql, $client_group_id);
  369         $client = $app->tform->getDataRecord($this->id);
  370         if(is_array($email_template) && $email_template['subject'] != '' && $email_template['message'] != '' && $client['email'] != '') {
  371             //* Parse client details into message
  372             $message = $email_template['message'];
  373             $subject = $email_template['subject'];
  374             foreach($client as $key => $val) {
  375                 switch ($key) {
  376                 case 'password':
  377                     $message = str_replace('{password}', $this->dataRecord['password'], $message);
  378                     $subject = str_replace('{password}', $this->dataRecord['password'], $subject);
  379                     break;
  380                 case 'gender':
  381                     $message = str_replace('{salutation}', $app->tform->lng('gender_'.$val.'_txt'), $message);
  382                     $subject = str_replace('{salutation}', $app->tform->lng('gender_'.$val.'_txt'), $subject);
  383                     break;
  384                 default:
  385                     $message = str_replace('{'.$key.'}', $val, $message);
  386                     $subject = str_replace('{'.$key.'}', $val, $subject);
  387                 }
  388             }
  389 
  390             //* Get sender address
  391             if($app->auth->is_admin()) {
  392                 $app->uses('getconf');
  393                 $system_config = $app->getconf->get_global_config('mail');
  394                 $from = $system_config['admin_mail'];
  395             } else {
  396                 $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  397                 $reseller = $app->db->queryOneRecord("SELECT client.email FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = ?", $client_group_id);
  398                 $from = $reseller["email"];
  399             }
  400 
  401             //* Send the email
  402             $app->functions->mail($client['email'], $subject, $message, $from);
  403         }
  404 
  405 
  406         parent::onAfterInsert();
  407     }
  408 
  409 
  410     /*
  411      This function is called automatically right after
  412      the data was successful updated in the database.
  413     */
  414     function onAfterUpdate() {
  415         global $app, $conf;
  416         // username changed
  417         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['username']) && $this->dataRecord['username'] != '' && $this->oldDataRecord['username'] != $this->dataRecord['username']) {
  418             $username = $this->dataRecord["username"];
  419             $client_id = $this->id;
  420             $sql = "UPDATE sys_user SET username = ? WHERE client_id = ?";
  421             $app->db->query($sql, $username, $client_id);
  422 
  423             $tmp = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = ?", $client_id);
  424             $app->db->datalogUpdate("sys_group", array("name" => $username), 'groupid', $tmp['groupid']);
  425             unset($tmp);
  426         }
  427 
  428         // password changed
  429         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord["password"]) && $this->dataRecord["password"] != '') {
  430             $password = $this->dataRecord["password"];
  431             $password = $app->auth->crypt_password($password);
  432             $client_id = $this->id;
  433             $sql = "UPDATE sys_user SET passwort = ? WHERE client_id = ?";
  434             $app->db->query($sql, $password, $client_id);
  435         }
  436 
  437         // lock and cancel
  438         if(!isset($this->dataRecord['locked'])) $this->dataRecord['locked'] = 'n';
  439         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && $this->dataRecord["locked"] != $this->oldDataRecord['locked']) 
  440         {
  441             $lock = $app->functions->func_client_lock($this->id,$this->dataRecord["locked"]);
  442         }
  443 
  444         if(!isset($this->dataRecord['canceled'])) $this->dataRecord['canceled'] = 'n';
  445         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && $this->dataRecord["canceled"] != $this->oldDataRecord['canceled']) {
  446             $cancel = $app->functions->func_client_cancel($this->id,$this->dataRecord["canceled"]);
  447         }
  448 
  449         // language changed
  450         if(isset($conf['demo_mode']) && $conf['demo_mode'] != true && isset($this->dataRecord['language']) && $this->dataRecord['language'] != '' && $this->oldDataRecord['language'] != $this->dataRecord['language']) {
  451             $language = $this->dataRecord["language"];
  452             $client_id = $this->id;
  453             $sql = "UPDATE sys_user SET language = ? WHERE client_id = ?";
  454             $app->db->query($sql, $language, $client_id);
  455         }
  456 
  457         //* reseller status changed
  458         if(isset($this->dataRecord["limit_client"]) && $this->dataRecord["limit_client"] != $this->oldDataRecord["limit_client"]) {
  459             $modules = $conf['interface_modules_enabled'];
  460             if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
  461             $client_id = $this->id;
  462             $sql = "UPDATE sys_user SET modules = ? WHERE client_id = ?";
  463             $app->db->query($sql, $modules, $client_id);
  464         }
  465 
  466         //* Client has been moved to another reseller
  467         if($_SESSION['s']['user']['typ'] == 'admin' && isset($this->dataRecord['parent_client_id']) && $this->dataRecord['parent_client_id'] != $this->oldDataRecord['parent_client_id']) {
  468             //* Get groupid of the client
  469             $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $this->id);
  470             $groupid = $tmp['groupid'];
  471             unset($tmp);
  472 
  473             //* Remove sys_user of old reseller from client group
  474             if($this->oldDataRecord['parent_client_id'] > 0) {
  475                 //* get userid of the old reseller remove it from the group of the client
  476                 $tmp = $app->db->queryOneRecord("SELECT sys_user.userid FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ?", $this->oldDataRecord['parent_client_id']);
  477                 $app->auth->remove_group_from_user($tmp['userid'], $groupid);
  478                 unset($tmp);
  479             }
  480 
  481             //* Add sys_user of new reseller to client group
  482             if($this->dataRecord['parent_client_id'] > 0) {
  483                 //* get userid of the reseller and add it to the group of the client
  484                 $tmp = $app->db->queryOneRecord("SELECT sys_user.userid, sys_user.default_group FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = ?", $this->dataRecord['parent_client_id']);
  485                 $app->auth->add_group_to_user($tmp['userid'], $groupid);
  486                 $app->db->query("UPDATE client SET sys_userid = ?, sys_groupid = ?, parent_client_id = ? WHERE client_id = ?", $tmp['userid'], $tmp['default_group'], $this->dataRecord['parent_client_id'], $this->id);
  487                 unset($tmp);
  488             } else {
  489                 //* Client is not assigned to a reseller anymore, so we assign it to the admin
  490                 $app->db->query("UPDATE client SET sys_userid = 1, sys_groupid = 1, parent_client_id = 0 WHERE client_id = ?", $this->id);
  491             }
  492         }
  493 
  494         if(isset($this->dataRecord['template_master'])) {
  495             $app->uses('client_templates');
  496             $app->client_templates->update_client_templates($this->id, $this->_template_additional);
  497         }
  498 
  499         parent::onAfterUpdate();
  500     }
  501 
  502 }
  503 
  504 $page = new page_action;
  505 $page->onLoad();
  506 
  507 ?>