2011-06-10 21:55:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
|
|
|
* http://www.mysqldumper.net
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
|
|
|
* @subpackage Forms_Config
|
|
|
|
* @version SVN: $Rev$
|
|
|
|
* @author $Author$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create form to input ftp data on configuration screen
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
|
|
|
* @subpackage Forms_Config
|
|
|
|
*/
|
|
|
|
class Application_Form_Config_Ftp extends Zend_Form_SubForm
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Msd Translator
|
|
|
|
* @var Msd_Language
|
|
|
|
*/
|
|
|
|
protected $_lang;
|
|
|
|
/**
|
|
|
|
* Init form and add all elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2012-08-04 17:09:48 +00:00
|
|
|
$config = Msd_Registry::getConfig();
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->_lang = Msd_Language::getInstance();
|
|
|
|
$this->setDisableLoadDefaultDecorators(true);
|
|
|
|
$this->setDecorators(array('SubForm'));
|
|
|
|
$this->addDisplayGroupPrefixPath(
|
|
|
|
'Msd_Form_Decorator',
|
|
|
|
'Msd/Form/Decorator/'
|
|
|
|
);
|
|
|
|
$this->setDisplayGroupDecorators(array('DisplayGroup'));
|
|
|
|
$this->_addButtonFtpAdd();
|
|
|
|
|
2012-08-04 17:09:48 +00:00
|
|
|
$ftpConfig = $config->getParam('ftp');
|
2011-06-10 21:55:32 +00:00
|
|
|
$ftpKeys = array_keys($ftpConfig);
|
2012-08-05 17:05:08 +00:00
|
|
|
$nrOfFtpProfiles = count($ftpKeys);
|
2011-06-10 21:55:32 +00:00
|
|
|
foreach ($ftpKeys as $ftpConnectionId) {
|
|
|
|
$this->_addRadioActivated($ftpConnectionId);
|
|
|
|
$this->_addInputTimeout($ftpConnectionId);
|
|
|
|
$this->_addCheckboxPassiveMode($ftpConnectionId);
|
|
|
|
$this->_addCheckboxSsl($ftpConnectionId);
|
|
|
|
$this->_addInputServerAndPort($ftpConnectionId);
|
|
|
|
$this->_addInputUserAndPass($ftpConnectionId);
|
|
|
|
$this->_addInputPath($ftpConnectionId);
|
2012-04-30 18:28:18 +00:00
|
|
|
|
2011-08-22 16:59:22 +00:00
|
|
|
if ($nrOfFtpProfiles > 1) {
|
2011-08-22 08:36:28 +00:00
|
|
|
$buttonDelete = 'ftpDelete' . $ftpConnectionId;
|
2011-08-22 10:39:57 +00:00
|
|
|
} else {
|
2011-08-22 08:36:28 +00:00
|
|
|
$buttonDelete = '';
|
|
|
|
}
|
2011-08-22 16:59:22 +00:00
|
|
|
|
2011-08-23 15:08:40 +00:00
|
|
|
$this->_addButtonsTestAndDelete($ftpConnectionId, $buttonDelete);
|
|
|
|
|
2012-08-05 17:05:08 +00:00
|
|
|
$legend = $this->_lang->getTranslator()->_('L_FTP_CONNECTION') . ' ' . ($ftpConnectionId + 1);
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->addDisplayGroup(
|
|
|
|
array(
|
|
|
|
'ftp_' . $ftpConnectionId . '_use',
|
|
|
|
'ftp_' . $ftpConnectionId . '_timeout',
|
|
|
|
'ftp_' . $ftpConnectionId . '_passiveMode',
|
|
|
|
'ftp_' . $ftpConnectionId . '_ssl',
|
|
|
|
'ftp_' . $ftpConnectionId . '_server',
|
|
|
|
'ftp_' . $ftpConnectionId . '_port',
|
|
|
|
'ftp_' . $ftpConnectionId . '_user',
|
|
|
|
'ftp_' . $ftpConnectionId . '_pass',
|
|
|
|
'ftp_' . $ftpConnectionId . '_dir',
|
|
|
|
'ftpCheck' . $ftpConnectionId,
|
2011-08-22 08:36:28 +00:00
|
|
|
$buttonDelete,
|
2011-06-10 21:55:32 +00:00
|
|
|
),
|
|
|
|
'ftp' . $ftpConnectionId,
|
|
|
|
array(
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'decorators' => array('DisplayGroup'),
|
|
|
|
'legend' => $legend,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add button "Add ftp connection"
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addButtonFtpAdd()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'button',
|
|
|
|
'headElement',
|
|
|
|
array(
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'content' =>
|
|
|
|
$this->getView()->getIcon('plus') . ' ' .
|
|
|
|
$this->_lang->getTranslator()->_('L_FTP_ADD_CONNECTION'),
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
'escape' => false,
|
|
|
|
'label' => '',
|
|
|
|
'class' => 'Formbutton',
|
|
|
|
'onclick' => "addFtpConnection();",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add radio "ftp activated"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addRadioActivated($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'radio',
|
|
|
|
'ftp_' . $index . '_use',
|
|
|
|
array(
|
|
|
|
'class' => 'radio toggler',
|
|
|
|
'label' => 'L_FTP_TRANSFER',
|
|
|
|
'onclick' => "myToggle(this, 'y', 'ftpToggle" . $index . "');",
|
|
|
|
'listsep' => ' ',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'multiOptions' => array(
|
|
|
|
'y' => 'L_ACTIVATED',
|
|
|
|
'n' => 'L_NOT_ACTIVATED',
|
|
|
|
),
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add input "ftp timeout"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputTimeout($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_timeout',
|
|
|
|
array(
|
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_TIMEOUT',
|
|
|
|
'secondLabel' => 'L_SECONDS',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'size' => 3,
|
|
|
|
'maxlength' => 3,
|
|
|
|
'decorators' => array('DoubleLabel'),
|
|
|
|
'validators' => array('Digits'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add checkbox "passive mode"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addCheckboxPassiveMode($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'ftp_' . $index . '_passiveMode',
|
|
|
|
array(
|
|
|
|
'class' => 'checkbox ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_CHOOSE_MODE',
|
|
|
|
'secondLabel' => 'L_FTP_PASSIVE',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'checkedValue' => 'y',
|
|
|
|
'uncheckedValue' => 'n',
|
|
|
|
'decorators' => array('DoubleLabel'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add checkbox "ssl"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addCheckboxSsl($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'ftp_' . $index . '_ssl',
|
|
|
|
array(
|
|
|
|
'class' => 'checkbox ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_SSL',
|
|
|
|
'secondLabel' => 'L_FTP_USESSL',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'checkedValue' => 'y',
|
|
|
|
'uncheckedValue' => 'n',
|
|
|
|
'decorators' => array('DoubleLabel'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add input "server"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputServerAndPort($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_server',
|
|
|
|
array(
|
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_SERVER',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_port',
|
|
|
|
array(
|
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_PORT',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'size' => 4,
|
|
|
|
'maxlength' => 5,
|
|
|
|
'validators' => array('Digits'),
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Add input "user"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputUserAndPass($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_user',
|
|
|
|
array(
|
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_USER',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'size' => 60,
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'password',
|
|
|
|
'ftp_' . $index . '_pass',
|
|
|
|
array(
|
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_PASS',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'size' => 60,
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
'renderPassword' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add input server
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputPath($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_dir',
|
|
|
|
array(
|
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_DIR',
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'size' => 60,
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add Button "Test connection"
|
2011-08-23 15:08:40 +00:00
|
|
|
* Add Button "Delete connection"
|
2012-04-30 18:28:18 +00:00
|
|
|
*
|
2011-06-10 21:55:32 +00:00
|
|
|
* @param int $index
|
2011-08-23 15:08:40 +00:00
|
|
|
* @param string $buttonDelete
|
2011-06-10 21:55:32 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-08-23 15:08:40 +00:00
|
|
|
private function _addButtonsTestAndDelete($index, $buttonDelete)
|
2011-06-10 21:55:32 +00:00
|
|
|
{
|
2011-08-23 15:08:40 +00:00
|
|
|
if (!empty($buttonDelete)) {
|
|
|
|
$buttonDecorator = 'LineStart';
|
|
|
|
} else {
|
|
|
|
$buttonDecorator = 'Default';
|
|
|
|
}
|
2012-04-30 18:28:18 +00:00
|
|
|
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->addElement(
|
|
|
|
'button',
|
|
|
|
'ftpCheck' . $index,
|
|
|
|
array(
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'content' =>
|
|
|
|
$this->getView()->getIcon('Connect', '', 16) . ' ' .
|
|
|
|
$this->_lang->getTranslator()->_('L_TESTCONNECTION'),
|
2011-08-23 15:08:40 +00:00
|
|
|
'decorators' => array($buttonDecorator),
|
2011-06-10 21:55:32 +00:00
|
|
|
'escape' => false,
|
|
|
|
'label' => '',
|
|
|
|
'class' => 'Formbutton ftpToggle' . $index,
|
2012-04-30 18:28:18 +00:00
|
|
|
'onclick' => "testFtpConnection(" .
|
|
|
|
$index . ");",
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2011-08-22 08:36:28 +00:00
|
|
|
$this->addElement(
|
|
|
|
'button',
|
|
|
|
'ftpDelete' . $index,
|
|
|
|
array(
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
|
|
|
'content' =>
|
2012-08-05 17:05:08 +00:00
|
|
|
$this->getView()->getIcon('delete') . ' '
|
|
|
|
. $this->_lang->getTranslator()->_('L_FTP_CONNECTION_DELETE'),
|
2011-08-22 08:36:28 +00:00
|
|
|
'decorators' => array('LineEnd'),
|
|
|
|
'escape' => false,
|
|
|
|
'label' => '',
|
|
|
|
'class' => 'Formbutton',
|
|
|
|
'onclick' => "deleteFtpConnection(" .
|
|
|
|
$index . ");",
|
|
|
|
)
|
|
|
|
);
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get valid values
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getValidValues($data)
|
|
|
|
{
|
|
|
|
$values = parent::getValidValues($data, true);
|
|
|
|
while (false !== (list($key, $value) = each($values))) {
|
|
|
|
if (substr($key, 0, 4) != 'ftp_') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list(, $ftpId, $ftpKey) = explode('_', $key);
|
|
|
|
if (!isset($values[$ftpId])) {
|
|
|
|
$values[$ftpId] = array();
|
|
|
|
}
|
|
|
|
$values[$ftpId][$ftpKey] = $value;
|
|
|
|
unset($values[$key]);
|
|
|
|
}
|
|
|
|
return $values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set default values
|
|
|
|
*
|
|
|
|
* @param array $defaults
|
|
|
|
*
|
|
|
|
* @return Zend_Form
|
|
|
|
*/
|
|
|
|
public function setDefaults($defaults)
|
|
|
|
{
|
|
|
|
if (!empty($defaults['ftp'])) {
|
|
|
|
$ftp = array();
|
|
|
|
while (
|
|
|
|
false !== (list($ftpId, $ftpData) = each($defaults['ftp']))
|
|
|
|
) {
|
|
|
|
foreach ($ftpData as $ftpKey => $ftpValue) {
|
|
|
|
$ftp['ftp_' . $ftpId . '_' . $ftpKey] = $ftpValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$defaults['ftp'] = $ftp;
|
|
|
|
}
|
|
|
|
return parent::setDefaults($defaults);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set input default value
|
|
|
|
*
|
2012-08-05 17:05:08 +00:00
|
|
|
* @param string $name Var-Name
|
|
|
|
* @param string $value The Value to set
|
|
|
|
*
|
|
|
|
* @return Zend_Form
|
2011-06-10 21:55:32 +00:00
|
|
|
*/
|
|
|
|
public function setDefault($name, $value)
|
|
|
|
{
|
2012-08-05 17:05:08 +00:00
|
|
|
$name = 'ftp_' . str_replace('.', '_', $name);
|
2011-06-10 21:55:32 +00:00
|
|
|
parent::setDefault($name, $value);
|
|
|
|
}
|
|
|
|
}
|