function onSubmit() {
global $app, $conf;
// Get the record of the parent domain
//$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"]));
// Set a few fixed values
//$this->dataRecord["server_id"] = $parent_domain["server_id"];
//die(print_r($this->dataRecord));
if(isset($this->dataRecord['username']) && trim($this->dataRecord['username']) == '') $app->tform->errorMessage .= $app->tform->lng('username_error_empty').'<br />';
//if(isset($this->dataRecord['username']) && empty($this->dataRecord['parent_domain_id'])) $app->tform->errorMessage .= $app->tform->lng('parent_domain_id_error_empty').'<br />';
parent::onSubmit();
}
function onBeforeInsert() {
global $app, $conf, $interfaceConf;
$app->uses('getconf');
$global_config = $app->getconf->get_global_config('sites');
//$ftpuser_prefix = ($global_config['ftpuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['ftpuser_prefix']);
$ftpuser_prefix = replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
if ($app->tform->errorMessage == '') {
$this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username'];
}
parent::onBeforeInsert();
}
function ftppath($start){
$directory = $start;
if(substr($directory,0,1) != '/')
$directory = '/'.$directory;
if(substr($directory,-1) != '/')
$directory = $directory.'/';
return '/var/www/clients/'.$_SESSION['s']['user']['username'].$directory;
}
function onAfterInsert() {
global $app, $conf;
$directory = $this->ftppath($this->dataRecord["dir"]);
$sql = "UPDATE ftp_user SET dir = '".$directory."' WHERE ftp_user_id = ".$this->id;
$app->db->query($sql);
return;
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"]));
$server_id = $web["server_id"];
$dir = $web["document_root"];
$uid = $web["system_user"];
$gid = $web["system_group"];
// The FTP user shall be owned by the same group then the website
$sys_groupid = $web['sys_groupid'];
$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;
$app->db->query($sql);
}