<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

print sly_Helper_Message::renderFlashMessage();

////////////////////////////////////////////////////////
// init form

$form = new sly_Form($_router->getPlainUrl(null, 'sync'), 'POST', t('sync_files'), '', 'sly-form-mediapool-sync');
$this->appendParamsToForm($form);

////////////////////////////////////////////////////////
// files title

$title = new sly_Form_Input_Text('ftitle', t('title'));
$form->add($title);

////////////////////////////////////////////////////////
// category select box

$select = $this->getCategorySelect();
$select->setLabel(t('category'));
$select->setAttribute('value', $this->getCurrentCategory());

$form->add($select);

////////////////////////////////////////////////////////
// setup buttons

$submit = $form->getSubmitButton();
$submit->setAttribute('name', 'save');
$submit->setAttribute('value', t('synchronize'));

$form->setResetButton(null);
$form->setSubmitButton(null);

$buttons['submit'] = $submit;
$form->add(new sly_Form_ButtonBar($buttons));

////////////////////////////////////////////////////////
// start list of dangling files

$diffCount = count($diffFiles);
$label     = t('affected_files');
$title     = $label.' ('.$diffCount.')';

foreach ($diffFiles as $hash => $filename) {
	$diffFiles[$hash] = sly_Util_Directory::fixWindowsDisplayFilename($filename);
}

$form->beginFieldset($title);
$form->add(new sly_Form_Select_Checkbox('sync_files', $label, array(), $diffFiles));

////////////////////////////////////////////////////////
// and here we go!

$form = sly_Core::dispatcher()->filter('SLY_MEDIA_FORM_SYNC', $form);

if ($form instanceof sly_Form) {
	print $form->render();
}
