From 161c9b1ed2c218ea4f2ad641ff0d9db23e4fc2bc Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Mon, 31 Oct 2011 20:57:43 +0000 Subject: [PATCH] scripts/shells/domain.php: - AddTask: - use $values[$field] instead of a short variable name for input - hand over $values array to __handle as array instead of dozens of variables - ViewTask: use $struct for printing the output model/DomainHandler.php: - use 'created' as label for created git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1259 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/DomainHandler.php | 2 +- scripts/shells/domain.php | 73 +++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/model/DomainHandler.php b/model/DomainHandler.php index 50feb868..80b71a67 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -71,7 +71,7 @@ class DomainHandler extends PFAHandler { 'backupmx' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' ), 'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ), 'default_aliases' => pacol( $this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases', '' , 1,'', /*not in db*/ 1 ), - 'created' => pacol( 0, 0, 1, 'ts', '' /* TODO: "created" label */ , '' ), + 'created' => pacol( 0, 0, 1, 'ts', 'created' , '' ), 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), ); diff --git a/scripts/shells/domain.php b/scripts/shells/domain.php index 8a34ece7..250f94cb 100644 --- a/scripts/shells/domain.php +++ b/scripts/shells/domain.php @@ -96,19 +96,19 @@ class AddTask extends Shell { } $question = "Description:"; - $desc = $this->in($question); + $values['description'] = $this->in($question); $question = "Number of Aliases:"; - $a = $this->in($question); + $values['aliases'] = $this->in($question); $question = "Numer of Mailboxes:"; - $m = $this->in($question); + $values['mailboxes'] = $this->in($question); $question = "Max Quota (in MB):"; - $q = $this->in($question); + $values['maxquota'] = $this->in($question); $question = "Domain Quota (in MB):"; - $d = $this->in($question); + $values['quota'] = $this->in($question); $handler = new DomainHandler(); $struct = $handler->getStruct(); @@ -122,18 +122,18 @@ class AddTask extends Shell { $t = $this->in( join("\n", $qt) ); - $t = $transports[$t-1]; # convert int to transport name + $values['transport'] = $transports[$t-1]; # convert int to transport name $question = "Add default Aliases:"; - $default = $this->in($question, array('y','n')); - ($default == 'y') ? $default = true : $default = false; + $values['default_aliases'] = $this->in($question, array('y','n')); + ($values['default_aliases'] == 'y') ? $values['default_aliases'] = true : $values['default_aliases'] = false; $question = "Use as Backup MX:"; - $backup = $this->in($question, array('y','n')); - ($backup == 'y') ? $backup = true : $backup = false; + $values['backupmx'] = $this->in($question, array('y','n')); + ($values['backupmx'] == 'y') ? $values['backupmx'] = true : $values['backupmx'] = false; - $this->__handle($domain, $desc, $a, $m, $t, $q, $d, $default, $backup); + $this->__handle($domain, $values); } /** @@ -141,7 +141,7 @@ class AddTask extends Shell { * * @access private */ - function __handle($domain, $desc, $a, $m, $t, $q, $d, $default, $backup) { + function __handle($domain, $values) { $handler = new DomainHandler(1); @@ -150,18 +150,6 @@ class AddTask extends Shell { return; } - $values = array( - 'description' => $desc, - 'aliases' => $a, - 'mailboxes' => $m, - 'maxquota' => $q, - 'quota' => $d, - 'transport' => $t, - 'backupmx' => $backup, - 'active' => 1, - 'default_aliases' => $default, - ); - if (!$handler->set($values)) { $this->error("Error:", join("\n", $handler->errormsg)); } @@ -358,21 +346,30 @@ class ViewTask extends Shell { if (!$status) { $this->error("Error:",join("\n", $handler->errormsg)); } else { - $result = $handler->return; - $this->out("Domain: \t".$result['domain']); - $this->out("Description: \t".$result['description']); - $this->out("Aliases: \t".$result['alias_count'] . " / " . $result['aliases']); - $this->out("Mailboxes: \t".$result['mailbox_count'] . " / " . $result['mailboxes']); - $this->out("Max. Quota: \t".$result['maxquota']); - $this->out("Domain Quota: \t".$result['total_quota'] . " / " . $result['quota']); - # TODO: show allocated domain quota (sum of mailbox quota) - $this->out("Transport: \t".$result['transport']); - $this->out("Backup MX: \t".$result['backupmx']); - $this->out("Active: \t".$result['active']); - $this->out("Modified: \t".$result['modified']); - $this->out("Created: \t".$result['created']); + $result = $handler->result(); + $struct = $handler->getStruct(); - return ; + # TODO: $totalfield should be in DomainHandler (in $struct or as separate array) + $totalfield = array( + 'aliases' => 'alias_count', + 'mailboxes' => 'mailbox_count', + 'quota' => 'total_quota', + ); + + foreach($struct as $key => $field) { + if ($field['display_in_list']) { + if (isset($totalfield[$key])) { + # TODO: format based on $field['type'] (also in the else section) + $this->out($field['label'] . ": \t" . $result[$totalfield[$key]] . " / " . $result[$key] ); + } else { + if (!in_array($key, $totalfield)) { # skip if we already displayed the field as part of "x/y" + $this->out($field['label'] . ": \t" . $result[$key]); + } + } + } + } + + return; } }