Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/main/glossary/upload_file_form.class.php

100 lines
2.3 KiB

<?php
/* For licensing terms, see /license.txt */
/**
* Glossay UploadFileForm class definition
* @package chamilo.glossary
*/
/**
* Init
*/
namespace Glossary;
use Chamilo;
/**
* Form to upload a CSV file.
*
* @license /licence.txt
* @author Laurent Opprecht <laurent@opprecht.info>
*/
class UploadFileForm extends \FormValidator
{
/**
*
* @param string $action
* @return \Glossary\UploadFileForm
*/
public static function create($action)
{
return new self('upload_file', 'post', $action);
}
function __construct($form_name = 'upload_file', $method = 'post', $action = '', $target = '', $attributes = null, $track_submit = true)
{
parent::__construct($form_name, $method, $action, $target, $attributes, $track_submit);
}
/**
*
*
*/
function init()
{
$form_name = get_lang('ImportGlossary');
$this->addHeader($form_name);
$this->addHidden(Request::PARAM_SEC_TOKEN, Access::instance()->get_token());
$label = get_lang('ImportCSVFileLocation');
$this->addFile('file', $label);
$this->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
$this->addCheckBox('deleteall', '', get_lang('DeleteAllGlossaryTerms'));
$this->addButton('save', get_lang('Save'));
$label = get_lang('CSVMustLookLike');
$label = "$label";
$help = '<pre>
<b>term</b>;<b>definition</b>;
"Hello";"Hola";
"Good";"Bueno";
</pre>';
$this->addHtml($label . $help);
}
public function get_delete_all()
{
return (bool) $this->exportValue('deleteall');
}
/**
*
* @return object
*/
public function get_file()
{
$result = Request::file('file', array());
if (empty($result)) {
return null;
}
$error = isset($result['error']) ? (bool) $result['error'] : false;
if ($error) {
return array();
}
return (object) $result;
}
public function validate()
{
$result = (bool) parent::validate();
if ($result == false) {
return false;
}
$file = $this->get_file();
if (empty($file)) {
return false;
}
return true;
}
}