diff --git a/admin_admins.php b/admin_admins.php index a5bd7447..be65fc44 100644 --- a/admin_admins.php +++ b/admin_admins.php @@ -454,7 +454,7 @@ if ($page == 'admins' } $admin_add_data = include_once dirname(__FILE__).'/lib/formfields/admin/formfield.admin.php'; - $admin_add_form = HTMLform2::genHTMLForm($admin_add_data, true); + $admin_add_form = HTMLform2::genHTMLForm($admin_add_data); eval("echo \"" . getTemplate("admins/admins_add") . "\";"); } @@ -779,7 +779,7 @@ if ($page == 'admins' $result = htmlentities_array($result); $admin_edit_data = include_once dirname(__FILE__).'/lib/formfields/admin/formfield.admin.php'; - $admin_edit_form = HTMLform2::genHTMLForm($admin_edit_data); + $admin_edit_form = HTMLform2::genHTMLForm($admin_edit_data, $result); eval("echo \"" . getTemplate("admins/admins_edit") . "\";"); } diff --git a/admin_cronjobs.php b/admin_cronjobs.php index 32eaaff0..e40ee6f5 100644 --- a/admin_cronjobs.php +++ b/admin_cronjobs.php @@ -107,7 +107,7 @@ if ($page == 'cronjobs' || $page == 'overview') { // interval $interval_nfo = explode(' ', $result['interval']); - $interval_value = $interval_nfo[0]; + $result['interval_value'] = $interval_nfo[0]; $interval_interval = ''; $interval_interval .= makeoption($lng['cronmgmt']['minutes'], 'MINUTE', $interval_nfo[1]); @@ -123,7 +123,7 @@ if ($page == 'cronjobs' || $page == 'overview') { } $cronjobs_edit_data = include_once dirname(__FILE__).'/lib/formfields/admin/formfield.cronjobs.php'; - $cronjobs_edit_form = HTMLform2::genHTMLForm($cronjobs_edit_data); + $cronjobs_edit_form = HTMLform2::genHTMLForm($cronjobs_edit_data, $result); eval("echo \"" . getTemplate('cronjobs/cronjob_edit') . "\";"); } diff --git a/admin_customers.php b/admin_customers.php index a962e8bb..65387d6d 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -988,7 +988,7 @@ if ($page == 'customers' } else { $customer_add_data = include_once dirname(__FILE__).'/lib/formfields/admin/formfield.customer.php'; - $customer_add_form = HTMLform2::genHTMLform($customer_add_data, true); + $customer_add_form = HTMLform2::genHTMLform($customer_add_data); eval("echo \"" . getTemplate("customers/customers_add") . "\";"); } @@ -1561,7 +1561,7 @@ if ($page == 'customers' $result = htmlentities_array($result); $customer_edit_data = include_once dirname(__FILE__).'/lib/formfields/admin/formfield.customer.php'; - $customer_edit_form = HTMLform2::genHTMLform($customer_edit_data); + $customer_edit_form = HTMLform2::genHTMLform($customer_edit_data, $result); eval("echo \"" . getTemplate("customers/customers_edit") . "\";"); } diff --git a/lib/classes/output/class.HTMLform2.php b/lib/classes/output/class.HTMLform2.php index 83d2e96d..b2d182a4 100644 --- a/lib/classes/output/class.HTMLform2.php +++ b/lib/classes/output/class.HTMLform2.php @@ -26,10 +26,10 @@ class HTMLform2 { * @access public * @static * @param array $formdata (default: array()) - * @param int $newForm (default: 0) + * @param array $data (default: array()) * @return void */ - public static function genHTMLform($formdata = array(), $newForm = false) { + public static function genHTMLform($formdata = array(), $data = array()) { global $lng, $theme; self::$_form = ''; @@ -47,25 +47,20 @@ class HTMLform2 { if (isset($fielddata['visible'])) { if ($fielddata['visible'] == false) { continue; - } elseif ($fielddata['visible'] === 'new' && $newForm == false) { + } elseif ($fielddata['visible'] === 'new' && !empty($data)) { continue; - } elseif ($fielddata['visible'] === 'edit' && $newForm == true) { + } elseif ($fielddata['visible'] === 'edit' && empty($data)) { continue; } } - // Set value to default val if new form - if ($newForm) { - $fielddata = self::_checkForValue($fielddata); + // Set value if given + if (!empty($data)) { + $fielddata = self::_setValue($fieldname, $fielddata, $data); } $field = self::_parseDataField($fieldname, $fielddata); - // Addons - foreach ($fielddata['addons'] as $addonname => $addondata) { - $field .= self::_parseDataField($addonname, $addondata); - } - $label = $fielddata['label'] . self::_getMandatoryFlag($fielddata); if (isset($fielddata['desc']) && $fielddata['desc'] != "") { $desc = $fielddata['desc']; @@ -82,29 +77,19 @@ class HTMLform2 { return self::$_form; } - private static function _checkForValue($fielddata) { - switch($fielddata['type']) { - case 'checkbox': - if (isset($fielddata['default'])) { - $fielddata['attributes']['checked'] = $fielddata['default']; - } else { - $fielddata['attributes']['checked'] = false; - } - break; - case 'select': - if (isset($fielddata['default'])) { - $fielddata['selected'] = $fielddata['default']; - } else { - unset($fielddata['selected']); - } - break; - default: - if (isset($fielddata['default'])) { - $fielddata['value'] = $fielddata['default']; - } else { - unset($fielddata['value']); - } - break; + private static function _setValue($fieldname, $fielddata, $data) { + if (isset($data[$fieldname])) { + switch($fielddata['type']) { + case 'checkbox': + $fielddata['attributes']['checked'] = ($data[$fieldname] == 1) ? true : false; + break; + case 'select': + $fielddata['selected'] = $data[$fieldname]; + break; + default: + $fielddata['value'] = $data[$fieldname]; + break; + } } return $fielddata; @@ -399,8 +384,8 @@ class HTMLform2 { $attributes = self::_parseAttributes($fieldname, $fielddata); unset($attributes['value']); $attributes = self::_glueAttributes($attributes); - - $value = $fielddata['value']; + + $value = isset($fielddata['value']) ? $fielddata['value'] : ""; eval("\$return = \"" . getTemplate("htmlform/textarea", "1") . "\";"); return $return; } diff --git a/lib/formfields/admin/formfield.admin.php b/lib/formfields/admin/formfield.admin.php index c79d8295..93fd193a 100644 --- a/lib/formfields/admin/formfield.admin.php +++ b/lib/formfields/admin/formfield.admin.php @@ -22,18 +22,13 @@ return array( 'loginname' => array( 'label' => $lng['login']['username'], 'type' => (isset($result['loginname'])) ? 'static' : 'text', - 'mandatory' => true, - 'value' => $result['loginname'], - ), + 'mandatory' => true, ), 'deactivated' => array( 'label' => $lng['admin']['deactivated_user'], 'type' => 'checkbox', 'value' => '1', 'sublabel' => $lng['panel']['yes'], - 'visible' => (isset($result['loginname']) && $result['adminid'] != $userinfo['userid']) ? true : false, - 'attributes' => array( - 'checked' => ($result['deactivated'] != 0) - ) + 'visible' => (isset($result['loginname']) && $result['adminid'] != $userinfo['userid']), ), 'admin_password' => array( 'label' => $lng['login']['password'], @@ -46,7 +41,6 @@ return array( 'type' => 'text', 'visible' => (Settings::Get('panel.password_regex') == ''), 'value' => generatePassword(), - 'default' => generatePassword(), 'attributes' => array( 'readonly' => true ) @@ -55,8 +49,7 @@ return array( 'label' => $lng['login']['language'], 'type' => 'select', 'generate' => 'languages', - 'default' => Settings::Get('panel.standardlanguage'), - 'selected' => $result['def_language'] + 'selected' => Settings::Get('panel.standardlanguage') ) ) ), @@ -66,20 +59,17 @@ return array( 'name' => array( 'label' => $lng['customer']['name'], 'type' => 'text', - 'mandatory' => true, - 'value' => $result['name'] + 'mandatory' => true ), 'email' => array( 'label' => $lng['customer']['email'], 'type' => 'email', - 'mandatory' => true, - 'value' => $result['email'] + 'mandatory' => true ), 'custom_notes' => array( 'label' => $lng['usersettings']['custom_notes']['title'], 'desc' => $lng['usersettings']['custom_notes']['description'], 'type' => 'textarea', - 'value' => $result['custom_notes'], 'attributes' => array( 'cols' => 60, 'rows' => 12 @@ -89,17 +79,13 @@ return array( 'label' => $lng['usersettings']['custom_notes']['show'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => '1', - 'default' => false, - 'attributes' => array( - 'checked' => ($result['custom_notes_show'] != '0') - ) + 'value' => '1' ) ) ), 'servicedata' => array( 'title' => $lng['admin']['servicedata'], - 'visible' => ($result['adminid'] != $userinfo['userid']), + 'visible' => (isset($result['adminid']) && $result['adminid'] != $userinfo['userid']), 'fields' => array( 'ipaddress' => array( 'label' => $lng['serversettings']['ipaddress']['title'], @@ -110,16 +96,12 @@ return array( 'label' => $lng['admin']['change_serversettings'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => 1, - 'attributes' => array( - 'checked' => ($result['change_serversettings'] != '0') - ) + 'value' => 1 ), 'customers' => array( 'label' => $lng['admin']['customers'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['customers'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 @@ -129,16 +111,12 @@ return array( 'label' => $lng['admin']['customers_see_all'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => '1', - 'attributes' => array( - 'checked' => ($result['customers_see_all'] != 0) - ) + 'value' => '1' ), 'domains' => array( 'label' => $lng['admin']['domains'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['domains'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 @@ -148,25 +126,18 @@ return array( 'label' => $lng['admin']['domains_see_all'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => '1', - 'attributes' => array( - 'checked' => ($result['domains_see_all'] != 0) - ) + 'value' => '1' ), 'caneditphpsettings' => array( 'label' => $lng['admin']['caneditphpsettings'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => '1', - 'attributes' => array( - 'checked' => ($result['caneditphpsettings'] != 0) - ) + 'value' => '1' ), 'diskspace' => array( 'label' => $lng['customer']['diskspace'], 'type' => 'textul', - 'value' => $result['diskspace'], - 'default' => 0, + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 6 @@ -175,8 +146,7 @@ return array( 'traffic' => array( 'label' => $lng['customer']['traffic'], 'type' => 'textul', - 'value' => $result['traffic'], - 'default' => 0, + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 4 @@ -185,8 +155,7 @@ return array( 'subdomains' => array( 'label' => $lng['customer']['subdomains'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['subdomains'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 @@ -195,8 +164,7 @@ return array( 'emails' => array( 'label' => $lng['customer']['emails'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['emails'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 @@ -205,8 +173,7 @@ return array( 'email_accounts' => array( 'label' => $lng['customer']['accounts'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['email_accounts'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 @@ -215,8 +182,7 @@ return array( 'email_forwarders' => array( 'label' => $lng['customer']['forwarders'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['email_forwarders'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 @@ -225,8 +191,7 @@ return array( 'email_quota' => array( 'label' => $lng['customer']['email_quota'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['email_quota'], + 'value' => 0, 'visible' => (Settings::Get('system.mail_quota_enabled') == '1' ? true : false), 'mandatory' => true, 'attributes' => array( @@ -236,8 +201,7 @@ return array( 'ftps' => array( 'label' => $lng['customer']['ftps'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['ftps'], + 'value' => 0, 'attributes' => array( 'maxlength' => 9 ) @@ -245,8 +209,7 @@ return array( 'tickets' => array( 'label' => $lng['customer']['tickets'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['tickets'], + 'value' => 0, 'visible' => (Settings::Get('ticket.enabled') == '1' ? true : false), 'attributes' => array( 'maxlength' => 9 @@ -256,16 +219,12 @@ return array( 'label' => $lng['admin']['tickets_see_all'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => '1', - 'attributes' => array( - 'checked' => ($result['tickets_see_all'] != '0') - ) + 'value' => '1' ), 'mysqls' => array( 'label' => $lng['customer']['mysqls'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['mysqls'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9 diff --git a/lib/formfields/admin/formfield.cronjobs.php b/lib/formfields/admin/formfield.cronjobs.php index e7eae794..ae8219c0 100644 --- a/lib/formfields/admin/formfield.cronjobs.php +++ b/lib/formfields/admin/formfield.cronjobs.php @@ -21,21 +21,16 @@ return array( 'cronfile' => array( 'label' => 'Cronjob', 'type' => ($change_cronfile == 1 ? 'text' : 'static'), - 'value' => $result['cronfile'] ), 'isactive' => array( 'label' => $lng['admin']['activated'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => 1, - 'attributes' => array( - 'checked' => ($result['isactive'] != 0) ? true : false - ) ), 'interval_value' => array( 'label' => $lng['cronjob']['cronjobintervalv'], - 'type' => 'text', - 'value' => $interval_value + 'type' => 'text' ), 'interval_interval' => array( 'label' => $lng['cronjob']['cronjobinterval'], diff --git a/lib/formfields/admin/formfield.customer.php b/lib/formfields/admin/formfield.customer.php index e61e727e..a7053e9b 100644 --- a/lib/formfields/admin/formfield.customer.php +++ b/lib/formfields/admin/formfield.customer.php @@ -27,13 +27,11 @@ return array( 'loginname' => array( 'label' => $lng['login']['username'], 'type' => 'static', - 'value' => $result['loginname'], 'visible' => 'edit' ), 'documentroot' => array( 'label' => $lng['customer']['documentroot'], 'type' => 'static', - 'value' => $result['documentroot'], 'visible' => 'edit' ), 'createstdsubdomain' => array( @@ -41,9 +39,8 @@ return array( 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'default' => true, 'attributes' => array( - 'checked' => ($result['standardsubdomain'] != '0') ? true : false + 'checked' => true ) ), 'store_defaultindex' => array( @@ -51,18 +48,17 @@ return array( 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'default' => true, - 'visible' => 'new' + 'visible' => 'new', + 'attributes' => array( + 'checked' => true + ) ), 'deactivated' => array( 'label' => $lng['admin']['deactivated_user'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'visible' => 'edit', - 'attributes' => array( - 'checked' => $result['deactivated'] - ) + 'visible' => 'edit' ), 'new_customer_password' => array( 'label' => $lng['login']['password'], @@ -76,7 +72,6 @@ return array( 'type' => 'text', 'visible' => (Settings::Get('panel.password_regex') == ''), 'value' => generatePassword(), - 'default' => generatePassword(), 'attributes' => array( 'readonly' => true ) @@ -85,7 +80,6 @@ return array( 'label' => $lng['admin']['sendpassword'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'default' => true, 'visible' => 'new', 'attributes' => array( 'checked' => true @@ -95,8 +89,7 @@ return array( 'label' => $lng['login']['language'], 'type' => 'select', 'generate' => 'languages', - 'default' => Settings::Get('panel.standardlanguage'), - 'selected' => $result['def_language'] + 'selected' => Settings::Get('panel.standardlanguage'), ) ) ), @@ -107,68 +100,56 @@ return array( 'label' => $lng['gender']['title'], 'type' => 'select', 'generate' => 'genders', - 'default' => '0', - 'selected' => $result['gender'] + 'selected' => '0' ), 'name' => array( 'label' => $lng['customer']['name'], 'type' => 'text', - 'mandatory_ex' => true, - 'value' => $result['name'] + 'mandatory_ex' => true ), 'firstname' => array( 'label' => $lng['customer']['firstname'], 'type' => 'text', - 'mandatory_ex' => true, - 'value' => $result['firstname'] + 'mandatory_ex' => true ), 'company' => array( 'label' => $lng['customer']['company'], 'type' => 'text', - 'mandatory_ex' => true, - 'value' => $result['company'] + 'mandatory_ex' => true ), 'street' => array( 'label' => $lng['customer']['street'], - 'type' => 'text', - 'value' => $result['street'] + 'type' => 'text' ), 'zipcode' => array( 'label' => $lng['customer']['zipcode'], - 'type' => 'text', - 'value' => $result['zipcode'] + 'type' => 'text' ), 'city' => array( 'label' => $lng['customer']['city'], - 'type' => 'text', - 'value' => $result['city'] + 'type' => 'text' ), 'phone' => array( 'label' => $lng['customer']['phone'], - 'type' => 'text', - 'value' => $result['phone'] + 'type' => 'text' ), 'fax' => array( 'label' => $lng['customer']['fax'], - 'type' => 'text', - 'value' => $result['fax'] + 'type' => 'text' ), 'email' => array( 'label' => $lng['customer']['email'], 'type' => 'email', - 'mandatory' => true, - 'value' => $result['email'] + 'mandatory' => true ), 'customernumber' => array( 'label' => $lng['customer']['customernumber'], - 'type' => 'text', - 'value' => $result['customernumber'] + 'type' => 'text' ), 'custom_notes' => array( 'label' => $lng['usersettings']['custom_notes']['title'], 'desc' => $lng['usersettings']['custom_notes']['description'], 'type' => 'textarea', - 'value' => $result['custom_notes'], 'attributes' => array( 'cols' => 60, 'rows' => 12 @@ -178,10 +159,7 @@ return array( 'label' => $lng['usersettings']['custom_notes']['show'], 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], - 'value' => '1', - 'attributes' => array( - 'checked' => ($result['custom_notes_show'] != '0') ? true : false - ) + 'value' => '1' ) ) ), @@ -191,8 +169,7 @@ return array( 'diskspace' => array( 'label' => $lng['customer']['diskspace'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['diskspace'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 6, @@ -201,8 +178,7 @@ return array( 'traffic' => array( 'label' => $lng['customer']['traffic'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['traffic'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 4, @@ -211,8 +187,7 @@ return array( 'subdomains' => array( 'label' => $lng['customer']['subdomains'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['subdomains'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9, @@ -221,8 +196,7 @@ return array( 'emails' => array( 'label' => $lng['customer']['emails'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['emails'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9, @@ -231,8 +205,7 @@ return array( 'email_accounts' => array( 'label' => $lng['customer']['accounts'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['email_accounts'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9, @@ -241,8 +214,7 @@ return array( 'email_forwarders' => array( 'label' => $lng['customer']['forwarders'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['email_forwarders'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9, @@ -251,8 +223,7 @@ return array( 'email_quota' => array( 'label' => $lng['customer']['email_quota'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['email_quota'], + 'value' => 0, 'visible' => (Settings::Get('system.mail_quota_enabled') == '1' ? true : false), 'mandatory' => true, 'attributes' => array( @@ -264,9 +235,8 @@ return array( 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'default' => true, 'attributes' => array( - 'checked' => ($result['imap'] != '0') ? true : false + 'checked' => true ) ), 'email_pop3' => array( @@ -274,16 +244,14 @@ return array( 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'default' => true, 'attributes' => array( - 'checked' => ($result['pop3'] != '0') ? true : false + 'checked' => true ) ), 'ftps' => array( 'label' => $lng['customer']['ftps'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['ftps'], + 'value' => 0, 'attributes' => array( 'maxlength' => 9, ) @@ -291,8 +259,7 @@ return array( 'tickets' => array( 'label' => $lng['customer']['tickets'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['tickets'], + 'value' => 0, 'visible' => (Settings::Get('ticket.enabled') == '1' ? true : false), 'attributes' => array( 'maxlength' => 9, @@ -301,8 +268,7 @@ return array( 'mysqls' => array( 'label' => $lng['customer']['mysqls'], 'type' => 'textul', - 'default' => 0, - 'value' => $result['mysqls'], + 'value' => 0, 'mandatory' => true, 'attributes' => array( 'maxlength' => 9, @@ -313,9 +279,8 @@ return array( 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'default' => true, 'attributes' => array( - 'checked' => ($result['phpenabled'] != '0') ? true : false + 'checked' => true ) ), 'perlenabled' => array( @@ -323,20 +288,17 @@ return array( 'type' => 'checkbox', 'sublabel' => $lng['panel']['yes'], 'value' => '1', - 'attributes' => array( - 'checked' => ($result['perlenabled'] != '0') ? true : false - ) ) ) ), 'movetoadmin' => array( 'title' => $lng['admin']['movetoadmin'], - 'visible' => ($admin_select_cnt > 1 && isset($result['loginname'])), + 'visible' => (isset($admin_select_cnt) && $admin_select_cnt > 1 && isset($result['loginname'])), 'fields' => array( 'move_to_admin' => array( 'label' => $lng['admin']['movecustomertoadmin'], 'type' => 'select', - 'values' => $admin_select + 'values' => (isset($admin_select)) ? $admin_select : null ) ) )