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;
|
2012-10-27 13:56:04 +00:00
|
|
|
|
2011-06-10 21:55:32 +00:00
|
|
|
/**
|
|
|
|
* Init form and add all elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2012-10-27 13:56:04 +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-10-27 13:56:04 +00:00
|
|
|
$ftpConfig = $config->getParam('ftp');
|
|
|
|
$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,
|
2012-10-27 13:56:04 +00:00
|
|
|
'decorators' => array('DisplayGroup'),
|
|
|
|
'legend' => $legend,
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add button "Add ftp connection"
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addButtonFtpAdd()
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'button',
|
|
|
|
'headElement',
|
|
|
|
array(
|
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'content' =>
|
|
|
|
$this->getView()->getIcon('plus') . ' ' .
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->_lang->getTranslator()->_('L_FTP_ADD_CONNECTION'),
|
2012-10-27 13:56:04 +00:00
|
|
|
'decorators' => array('Default'),
|
|
|
|
'escape' => false,
|
|
|
|
'label' => '',
|
|
|
|
'class' => 'Formbutton',
|
|
|
|
'onclick' => "addFtpConnection();",
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add radio "ftp activated"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addRadioActivated($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'radio',
|
|
|
|
'ftp_' . $index . '_use',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'radio toggler',
|
|
|
|
'label' => 'L_FTP_TRANSFER',
|
|
|
|
'onclick' => "myToggle(this, 'y', 'ftpToggle" . $index . "');",
|
|
|
|
'listsep' => ' ',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'multiOptions' => array(
|
2011-06-10 21:55:32 +00:00
|
|
|
'y' => 'L_ACTIVATED',
|
|
|
|
'n' => 'L_NOT_ACTIVATED',
|
|
|
|
),
|
2012-10-27 13:56:04 +00:00
|
|
|
'decorators' => array('Default'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add input "ftp timeout"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputTimeout($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_timeout',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_TIMEOUT',
|
|
|
|
'secondLabel' => 'L_SECONDS',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'size' => 3,
|
|
|
|
'maxlength' => 3,
|
|
|
|
'decorators' => array('DoubleLabel'),
|
|
|
|
'validators' => array('Digits'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add checkbox "passive mode"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addCheckboxPassiveMode($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'ftp_' . $index . '_passiveMode',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'checkbox ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_CHOOSE_MODE',
|
|
|
|
'secondLabel' => 'L_FTP_PASSIVE',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'checkedValue' => 'y',
|
|
|
|
'uncheckedValue' => 'n',
|
|
|
|
'decorators' => array('DoubleLabel'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add checkbox "ssl"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addCheckboxSsl($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'ftp_' . $index . '_ssl',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'checkbox ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_SSL',
|
|
|
|
'secondLabel' => 'L_FTP_USESSL',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'checkedValue' => 'y',
|
|
|
|
'uncheckedValue' => 'n',
|
|
|
|
'decorators' => array('DoubleLabel'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add input "server"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputServerAndPort($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_server',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_SERVER',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'decorators' => array('Default'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_port',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_PORT',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'size' => 4,
|
|
|
|
'maxlength' => 5,
|
|
|
|
'validators' => array('Digits'),
|
|
|
|
'decorators' => array('Default'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-10-27 13:56:04 +00:00
|
|
|
|
|
|
|
/**
|
2011-06-10 21:55:32 +00:00
|
|
|
* Add input "user"
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputUserAndPass($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_user',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_USER',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'size' => 60,
|
|
|
|
'decorators' => array('Default'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'password',
|
|
|
|
'ftp_' . $index . '_pass',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_FTP_PASS',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'size' => 60,
|
|
|
|
'decorators' => array('Default'),
|
|
|
|
'renderPassword' => true,
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add input server
|
|
|
|
*
|
|
|
|
* @param int $index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _addInputPath($index)
|
|
|
|
{
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'ftp_' . $index . '_dir',
|
|
|
|
array(
|
2012-10-27 13:56:04 +00:00
|
|
|
'class' => 'text ftpToggle' . $index,
|
|
|
|
'label' => 'L_DIR',
|
2011-06-10 21:55:32 +00:00
|
|
|
'disableLoadDefaultDecorators' => true,
|
2012-10-27 13:56:04 +00:00
|
|
|
'size' => 60,
|
|
|
|
'decorators' => array('Default'),
|
2011-06-10 21:55:32 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2012-10-27 13:56:04 +00:00
|
|
|
'content' =>
|
|
|
|
$this->getView()->getIcon('Connect', '', 16) . ' ' .
|
2011-06-10 21:55:32 +00:00
|
|
|
$this->_lang->getTranslator()->_('L_TESTCONNECTION'),
|
2012-10-27 13:56:04 +00:00
|
|
|
'decorators' => array($buttonDecorator),
|
|
|
|
'escape' => false,
|
|
|
|
'label' => '',
|
|
|
|
'class' => 'Formbutton ftpToggle' . $index,
|
|
|
|
'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,
|
2012-10-27 13:56:04 +00:00
|
|
|
'content' =>
|
|
|
|
$this->getView()->getIcon('delete') . ' '
|
|
|
|
. $this->_lang->getTranslator()->_('L_FTP_CONNECTION_DELETE'),
|
|
|
|
'decorators' => array('LineEnd'),
|
|
|
|
'escape' => false,
|
|
|
|
'label' => '',
|
|
|
|
'class' => 'Formbutton',
|
|
|
|
'onclick' => "deleteFtpConnection(" . $index . ");",
|
2011-08-22 08:36:28 +00:00
|
|
|
)
|
|
|
|
);
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get valid values
|
|
|
|
*
|
|
|
|
* @param array $data
|
2012-10-27 13:56:04 +00:00
|
|
|
* @param bool $suppressArrayNotation
|
2011-06-10 21:55:32 +00:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-10-27 13:56:04 +00:00
|
|
|
public function getValidValues($data, $suppressArrayNotation = false)
|
2011-06-10 21:55:32 +00:00
|
|
|
{
|
2012-08-21 20:22:56 +00:00
|
|
|
$ftpData = array();
|
|
|
|
foreach ($data as $key => $value) {
|
2011-06-10 21:55:32 +00:00
|
|
|
if (substr($key, 0, 4) != 'ftp_') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list(, $ftpId, $ftpKey) = explode('_', $key);
|
2012-08-21 20:22:56 +00:00
|
|
|
if (!isset($ftpData[$ftpId])) {
|
|
|
|
$ftpData[$ftpId] = array();
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
2012-08-21 20:22:56 +00:00
|
|
|
$ftpData[$ftpId][$ftpKey] = $value;
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
2012-08-21 20:22:56 +00:00
|
|
|
return $ftpData;
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set default values
|
|
|
|
*
|
|
|
|
* @param array $defaults
|
|
|
|
*
|
|
|
|
* @return Zend_Form
|
|
|
|
*/
|
2012-10-27 13:56:04 +00:00
|
|
|
public function setDefaults(array $defaults)
|
2011-06-10 21:55:32 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|