Guest
Public paste!

Untitled

By: a guest | Jul 15th, 2010 | Syntax: PHP | Size: 2.39 KB | Hits: 88 | Expires: Never
Copy text to clipboard
  1. function onSubmit() {
  2.                 global $app, $conf;
  3.                
  4.                 // Get the record of the parent domain
  5.                 //$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
  6.                
  7.                 // Set a few fixed values
  8.                 //$this->dataRecord["server_id"] = $parent_domain["server_id"];
  9.                
  10.                 //die(print_r($this->dataRecord));
  11.                
  12.                 if(isset($this->dataRecord['username']) && trim($this->dataRecord['username']) == '') $app->tform->errorMessage .= $app->tform->lng('username_error_empty').'<br />';
  13.                 //if(isset($this->dataRecord['username']) && empty($this->dataRecord['parent_domain_id'])) $app->tform->errorMessage .= $app->tform->lng('parent_domain_id_error_empty').'<br />';
  14.                
  15.                 parent::onSubmit();
  16.         }
  17.        
  18.         function onBeforeInsert() {
  19.                 global $app, $conf, $interfaceConf;
  20.                
  21.                 $app->uses('getconf');
  22.                 $global_config = $app->getconf->get_global_config('sites');
  23.                 //$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']);
  24.                 $ftpuser_prefix = replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
  25.                
  26.                 if ($app->tform->errorMessage == '') {
  27.                         $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username'];
  28.                 }
  29.                
  30.                 parent::onBeforeInsert();
  31.         }
  32.  
  33.         function ftppath($start){
  34.                 $directory = $start;
  35.                
  36.                 if(substr($directory,0,1) != '/')
  37.                         $directory = '/'.$directory;
  38.        
  39.                 if(substr($directory,-1) != '/')
  40.                         $directory = $directory.'/';
  41.  
  42.                 return '/var/www/clients/'.$_SESSION['s']['user']['username'].$directory;
  43.         }
  44.  
  45.         function onAfterInsert() {
  46.                 global $app, $conf;
  47.                
  48.                 $directory = $this->ftppath($this->dataRecord["dir"]);
  49.                
  50.                 $sql = "UPDATE ftp_user SET dir = '".$directory."' WHERE ftp_user_id = ".$this->id;
  51.                 $app->db->query($sql);
  52.                 return;
  53.                
  54.                 $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
  55.                 $server_id = $web["server_id"];
  56.                 $dir = $web["document_root"];
  57.                 $uid = $web["system_user"];
  58.                 $gid = $web["system_group"];
  59.                
  60.                 // The FTP user shall be owned by the same group then the website
  61.                 $sys_groupid = $web['sys_groupid'];
  62.                
  63.                 $sql = "UPDATE ftp_user SET server_id = $server_id, dir = '$dir', uid = '$uid', gid = '$gid', sys_groupid = '$sys_groupid' WHERE ftp_user_id = ".$this->id;
  64.                 $app->db->query($sql);
  65.                
  66.                
  67.         }