diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Console/ProjectDailyColumnStatsExport.php | 4 | ||||
-rw-r--r-- | app/Console/SubtaskExport.php | 4 | ||||
-rw-r--r-- | app/Console/TaskExport.php | 4 | ||||
-rw-r--r-- | app/Console/TransitionExport.php | 4 | ||||
-rw-r--r-- | app/Controller/TaskImport.php | 73 | ||||
-rw-r--r-- | app/Controller/UserImport.php | 67 | ||||
-rw-r--r-- | app/Core/Csv.php | 212 | ||||
-rw-r--r-- | app/Core/Request.php | 12 | ||||
-rw-r--r-- | app/Core/Response.php | 3 | ||||
-rw-r--r-- | app/Core/Router.php | 3 | ||||
-rw-r--r-- | app/Core/Tool.php | 21 | ||||
-rw-r--r-- | app/Helper/Form.php | 17 | ||||
-rw-r--r-- | app/Model/Acl.php | 3 | ||||
-rw-r--r-- | app/Model/TaskImport.php | 158 | ||||
-rw-r--r-- | app/Model/TaskValidator.php | 1 | ||||
-rw-r--r-- | app/Model/User.php | 12 | ||||
-rw-r--r-- | app/Model/UserImport.php | 110 | ||||
-rw-r--r-- | app/ServiceProvider/ClassProvider.php | 2 | ||||
-rw-r--r-- | app/Template/project/sidebar.php | 3 | ||||
-rw-r--r-- | app/Template/task_import/step1.php | 34 | ||||
-rw-r--r-- | app/Template/user/index.php | 3 | ||||
-rw-r--r-- | app/Template/user_import/step1.php | 46 |
22 files changed, 763 insertions, 33 deletions
diff --git a/app/Console/ProjectDailyColumnStatsExport.php b/app/Console/ProjectDailyColumnStatsExport.php index b9830662..4db33b6a 100644 --- a/app/Console/ProjectDailyColumnStatsExport.php +++ b/app/Console/ProjectDailyColumnStatsExport.php @@ -2,7 +2,7 @@ namespace Console; -use Core\Tool; +use Core\Csv; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,7 +28,7 @@ class ProjectDailyColumnStatsExport extends Base ); if (is_array($data)) { - Tool::csv($data); + Csv::output($data); } } } diff --git a/app/Console/SubtaskExport.php b/app/Console/SubtaskExport.php index 167a9225..9816574b 100644 --- a/app/Console/SubtaskExport.php +++ b/app/Console/SubtaskExport.php @@ -2,7 +2,7 @@ namespace Console; -use Core\Tool; +use Core\Csv; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,7 +28,7 @@ class SubtaskExport extends Base ); if (is_array($data)) { - Tool::csv($data); + Csv::output($data); } } } diff --git a/app/Console/TaskExport.php b/app/Console/TaskExport.php index 2ecd45e5..862c1b0d 100644 --- a/app/Console/TaskExport.php +++ b/app/Console/TaskExport.php @@ -2,7 +2,7 @@ namespace Console; -use Core\Tool; +use Core\Csv; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,7 +28,7 @@ class TaskExport extends Base ); if (is_array($data)) { - Tool::csv($data); + Csv::output($data); } } } diff --git a/app/Console/TransitionExport.php b/app/Console/TransitionExport.php index ad988c54..27d8de64 100644 --- a/app/Console/TransitionExport.php +++ b/app/Console/TransitionExport.php @@ -2,7 +2,7 @@ namespace Console; -use Core\Tool; +use Core\Csv; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,7 +28,7 @@ class TransitionExport extends Base ); if (is_array($data)) { - Tool::csv($data); + Csv::output($data); } } } diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php new file mode 100644 index 00000000..0343b1dc --- /dev/null +++ b/app/Controller/TaskImport.php @@ -0,0 +1,73 @@ +<?php + +namespace Controller; + +use Core\Csv; + +/** + * Task Import controller + * + * @package controller + * @author Frederic Guillot + */ +class TaskImport extends Base +{ + /** + * Upload the file and ask settings + * + */ + public function step1(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + + $this->response->html($this->projectLayout('task_import/step1', array( + 'project' => $project, + 'values' => $values, + 'errors' => $errors, + 'max_size' => ini_get('upload_max_filesize'), + 'delimiters' => Csv::getDelimiters(), + 'enclosures' => Csv::getEnclosures(), + 'title' => t('Import tasks from CSV file'), + ))); + } + + /** + * Process CSV file + * + */ + public function step2() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + $filename = $this->request->getFilePath('file'); + + if (! file_exists($filename)) { + $this->step1($values, array('file' => array(t('Unable to read your file')))); + } + + $this->taskImport->projectId = $project['id']; + + $csv = new Csv($values['delimiter'], $values['enclosure']); + $csv->setColumnMapping($this->taskImport->getColumnMapping()); + $csv->read($filename, array($this->taskImport, 'import')); + + if ($this->taskImport->counter > 0) { + $this->session->flash(t('%d task(s) have been imported successfully.', $this->taskImport->counter)); + } + else { + $this->session->flashError(t('Nothing have been imported!')); + } + + $this->response->redirect($this->helper->url->to('taskImport', 'step1', array('project_id' => $project['id']))); + } + + /** + * Generate template + * + */ + public function template() + { + $this->response->forceDownload('tasks.csv'); + $this->response->csv(array($this->taskImport->getColumnMapping())); + } +} diff --git a/app/Controller/UserImport.php b/app/Controller/UserImport.php new file mode 100644 index 00000000..9c27aa06 --- /dev/null +++ b/app/Controller/UserImport.php @@ -0,0 +1,67 @@ +<?php + +namespace Controller; + +use Core\Csv; + +/** + * User Import controller + * + * @package controller + * @author Frederic Guillot + */ +class UserImport extends Base +{ + /** + * Upload the file and ask settings + * + */ + public function step1(array $values = array(), array $errors = array()) + { + $this->response->html($this->template->layout('user_import/step1', array( + 'values' => $values, + 'errors' => $errors, + 'max_size' => ini_get('upload_max_filesize'), + 'delimiters' => Csv::getDelimiters(), + 'enclosures' => Csv::getEnclosures(), + 'title' => t('Import users from CSV file'), + ))); + } + + /** + * Process CSV file + * + */ + public function step2() + { + $values = $this->request->getValues(); + $filename = $this->request->getFilePath('file'); + + if (! file_exists($filename)) { + $this->step1($values, array('file' => array(t('Unable to read your file')))); + } + + $csv = new Csv($values['delimiter'], $values['enclosure']); + $csv->setColumnMapping($this->userImport->getColumnMapping()); + $csv->read($filename, array($this->userImport, 'import')); + + if ($this->userImport->counter > 0) { + $this->session->flash(t('%d user(s) have been imported successfully.', $this->userImport->counter)); + } + else { + $this->session->flashError(t('Nothing have been imported!')); + } + + $this->response->redirect($this->helper->url->to('userImport', 'step1')); + } + + /** + * Generate template + * + */ + public function template() + { + $this->response->forceDownload('users.csv'); + $this->response->csv(array($this->userImport->getColumnMapping())); + } +} diff --git a/app/Core/Csv.php b/app/Core/Csv.php new file mode 100644 index 00000000..6e7816f6 --- /dev/null +++ b/app/Core/Csv.php @@ -0,0 +1,212 @@ +<?php + +namespace Core; + +use SplFileObject; + +/** + * CSV Writer/Reader + * + * @package core + * @author Frederic Guillot + */ +class Csv +{ + /** + * CSV delimiter + * + * @access private + * @var string + */ + private $delimiter = ','; + + /** + * CSV enclosure + * + * @access private + * @var string + */ + private $enclosure = '"'; + + /** + * CSV/SQL columns + * + * @access private + * @var array + */ + private $columns = array(); + + /** + * Constructor + * + * @access public + * @param string $delimiter + * @param string $enclosure + */ + public function __construct($delimiter = ',', $enclosure = '"') + { + $this->delimiter = $delimiter; + $this->enclosure = $enclosure; + } + + /** + * Get list of delimiters + * + * @static + * @access public + * @return array + */ + public static function getDelimiters() + { + return array( + ',' => t('Comma'), + ';' => t('Semi-colon'), + '\t' => t('Tab'), + '|' => t('Vertical bar'), + ); + } + + /** + * Get list of enclosures + * + * @static + * @access public + * @return array + */ + public static function getEnclosures() + { + return array( + '"' => t('Double Quote'), + "'" => t('Single Quote'), + '' => t('None'), + ); + } + + /** + * Check boolean field value + * + * @static + * @access public + * @return integer + */ + public static function getBooleanValue($value) + { + if (! empty($value)) { + $value = trim(strtolower($value)); + return $value === '1' || $value{0} === 't' ? 1 : 0; + } + + return 0; + } + + /** + * Output CSV file to standard output + * + * @static + * @access public + * @param array $rows + */ + public static function output(array $rows) + { + $csv = new static; + $csv->write('php://output', $rows); + } + + /** + * Define column mapping between CSV and SQL columns + * + * @access public + * @param array $columns + * @return Csv + */ + public function setColumnMapping(array $columns) + { + $this->columns = $columns; + return $this; + } + + /** + * Read CSV file + * + * @access public + * @param string $filename + * @param \Closure $callback Example: function(array $row, $line_number) + * @return Csv + */ + public function read($filename, $callback) + { + $file = new SplFileObject($filename); + $file->setFlags(SplFileObject::READ_CSV); + $file->setCsvControl($this->delimiter, $this->enclosure); + $line_number = 0; + + foreach ($file as $row) { + $row = $this->filterRow($row); + + if (! empty($row) && $line_number > 0) { + call_user_func_array($callback, array($this->associateColumns($row), $line_number)); + } + + $line_number++; + } + + return $this; + } + + /** + * Write CSV file + * + * @access public + * @param string $filename + * @param array $rows + * @return Csv + */ + public function write($filename, array $rows) + { + $file = new SplFileObject($filename, 'w'); + + foreach ($rows as $row) { + $file->fputcsv($row, $this->delimiter, $this->enclosure); + } + + return $this; + } + + /** + * Associate columns header with row values + * + * @access private + * @param array $row + * @return array + */ + private function associateColumns(array $row) + { + $line = array(); + $index = 0; + + foreach ($this->columns as $sql_name => $csv_name) { + if (isset($row[$index])) { + $line[$sql_name] = $row[$index]; + } + else { + $line[$sql_name] = ''; + } + + $index++; + } + + return $line; + } + + /** + * Filter empty rows + * + * @access private + * @param array $row + * @return array + */ + private function filterRow(array $row) + { + return array_filter($row); + } +} diff --git a/app/Core/Request.php b/app/Core/Request.php index 1eff66fa..d0fcdb8e 100644 --- a/app/Core/Request.php +++ b/app/Core/Request.php @@ -103,6 +103,18 @@ class Request } /** + * Get the path of an uploaded file + * + * @access public + * @param string $name Form file name + * @return string + */ + public function getFilePath($name) + { + return isset($_FILES[$name]['tmp_name']) ? $_FILES[$name]['tmp_name'] : ''; + } + + /** * Return true if the HTTP request is sent with the POST method * * @access public diff --git a/app/Core/Response.php b/app/Core/Response.php index f8ca015c..71d99524 100644 --- a/app/Core/Response.php +++ b/app/Core/Response.php @@ -87,8 +87,9 @@ class Response { $this->status($status_code); $this->nocache(); + header('Content-Type: text/csv'); - Tool::csv($data); + Csv::output($data); exit; } diff --git a/app/Core/Router.php b/app/Core/Router.php index 93d266bb..55ebe4a8 100644 --- a/app/Core/Router.php +++ b/app/Core/Router.php @@ -197,7 +197,7 @@ class Router extends Base */ public function sanitize($value, $default_value) { - return ! ctype_alpha($value) || empty($value) ? $default_value : strtolower($value); + return ! preg_match('/^[a-zA-Z_0-9]+$/', $value) ? $default_value : $value; } /** @@ -218,6 +218,7 @@ class Router extends Base list($this->controller, $this->action) = $this->findRoute($this->getPath($uri, $query_string)); // TODO: add plugin for routes $plugin = ''; } + $class = empty($plugin) ? '\Controller\\'.ucfirst($this->controller) : '\Plugin\\'.ucfirst($plugin).'\Controller\\'.ucfirst($this->controller); $instance = new $class($this->container); diff --git a/app/Core/Tool.php b/app/Core/Tool.php index 887c8fb3..39e42b83 100644 --- a/app/Core/Tool.php +++ b/app/Core/Tool.php @@ -13,27 +13,6 @@ use Pimple\Container; class Tool { /** - * Write a CSV file - * - * @static - * @access public - * @param array $rows Array of rows - * @param string $filename Output filename - */ - public static function csv(array $rows, $filename = 'php://output') - { - $fp = fopen($filename, 'w'); - - if (is_resource($fp)) { - foreach ($rows as $fields) { - fputcsv($fp, $fields); - } - - fclose($fp); - } - } - - /** * Get the mailbox hash from an email address * * @static diff --git a/app/Helper/Form.php b/app/Helper/Form.php index a37cc81a..e8664771 100644 --- a/app/Helper/Form.php +++ b/app/Helper/Form.php @@ -178,6 +178,23 @@ class Form extends \Core\Base } /** + * Display file field + * + * @access public + * @param string $name + * @param array $errors + * @param boolean $multiple + * @return string + */ + public function file($name, array $errors = array(), $multiple = false) + { + $html = '<input type="file" name="'.$name.'" id="form-'.$name.'" '.($multiple ? 'multiple' : '').'>'; + $html .= $this->errorList($errors, $name); + + return $html; + } + + /** * Display a input field * * @access public diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 675ca36e..35488c63 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -63,6 +63,7 @@ class Acl extends Base 'category' => '*', 'column' => '*', 'export' => '*', + 'taskimport' => '*', 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), 'swimlane' => '*', 'gantt' => array('project', 'savetaskdate', 'task', 'savetask'), @@ -88,6 +89,7 @@ class Acl extends Base */ private $admin_acl = array( 'user' => array('index', 'create', 'save', 'remove', 'authentication'), + 'userimport' => '*', 'config' => '*', 'link' => '*', 'currency' => '*', @@ -117,6 +119,7 @@ class Acl extends Base */ public function matchAcl(array $acl, $controller, $action) { + $controller = strtolower($controller); $action = strtolower($action); return isset($acl[$controller]) && $this->hasAction($action, $acl[$controller]); } diff --git a/app/Model/TaskImport.php b/app/Model/TaskImport.php new file mode 100644 index 00000000..2eb4eb8f --- /dev/null +++ b/app/Model/TaskImport.php @@ -0,0 +1,158 @@ +<?php + +namespace Model; + +use Core\Csv; +use SimpleValidator\Validator; +use SimpleValidator\Validators; + +/** + * Task Import + * + * @package model + * @author Frederic Guillot + */ +class TaskImport extends Base +{ + /** + * Number of successful import + * + * @access public + * @var integer + */ + public $counter = 0; + + /** + * Project id to import tasks + * + * @access public + * @var integer + */ + public $projectId; + + /** + * Get mapping between CSV header and SQL columns + * + * @access public + * @return array + */ + public function getColumnMapping() + { + return array( + 'reference' => 'Reference', + 'title' => 'Title', + 'description' => 'Description', + 'assignee' => 'Assignee Username', + 'creator' => 'Creator Username', + 'color' => 'Color Name', + 'column' => 'Column Name', + 'category' => 'Category Name', + 'swimlane' => 'Swimlane Name', + 'score' => 'Complexity', + 'time_estimated' => 'Time Estimated', + 'time_spent' => 'Time Spent', + 'date_due' => 'Due Date', + 'is_active' => 'Closed', + ); + } + + /** + * Import a single row + * + * @access public + * @param array $row + * @param integer $line_number + */ + public function import(array $row, $line_number) + { + $row = $this->prepare($row); + + if ($this->validateCreation($row)) { + if ($this->taskCreation->create($row) > 0) { + $this->logger->debug('TaskImport: imported successfully line '.$line_number); + $this->counter++; + } + else { + $this->logger->error('TaskImport: creation error at line '.$line_number); + } + } + else { + $this->logger->error('TaskImport: validation error at line '.$line_number); + } + } + + /** + * Format row before validation + * + * @access public + * @param array $data + * @return array + */ + public function prepare(array $row) + { + $values = array(); + $values['project_id'] = $this->projectId; + $values['reference'] = $row['reference']; + $values['title'] = $row['title']; + $values['description'] = $row['description']; + $values['is_active'] = Csv::getBooleanValue($row['is_active']) == 1 ? 0 : 1; + $values['score'] = (int) $row['score']; + $values['time_estimated'] = (float) $row['time_estimated']; + $values['time_spent'] = (float) $row['time_spent']; + + if (! empty($row['assignee'])) { + $values['owner_id'] = $this->user->getIdByUsername($row['assignee']); + } + + if (! empty($row['creator'])) { + $values['creator_id'] = $this->user->getIdByUsername($row['creator']); + } + + if (! empty($row['color'])) { + $values['color_id'] = $this->color->find($row['color']); + } + + if (! empty($row['column'])) { + $values['column_id'] = $this->board->getColumnIdByTitle($this->projectId, $row['column']); + } + + if (! empty($row['category'])) { + $values['category_id'] = $this->category->getIdByName($this->projectId, $row['category']); + } + + if (! empty($row['swimlane'])) { + $values['swimlane_id'] = $this->swimlane->getIdByName($this->projectId, $row['swimlane']); + } + + if (! empty($row['date_due'])) { + $values['date_due'] = $this->dateParser->getTimestampFromIsoFormat($row['date_due']); + } + + $this->removeEmptyFields( + $values, + array('owner_id', 'creator_id', 'color_id', 'column_id', 'category_id', 'swimlane_id', 'date_due') + ); + + return $values; + } + + /** + * Validate user creation + * + * @access public + * @param array $values + * @return boolean + */ + public function validateCreation(array $values) + { + $v = new Validator($values, array( + new Validators\Integer('project_id', t('This value must be an integer')), + new Validators\Required('project_id', t('The project is required')), + new Validators\Required('title', t('The title is required')), + new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), + new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50), + )); + + return $v->execute(); + } +} diff --git a/app/Model/TaskValidator.php b/app/Model/TaskValidator.php index 95b8a26c..89c66f2f 100644 --- a/app/Model/TaskValidator.php +++ b/app/Model/TaskValidator.php @@ -38,6 +38,7 @@ class TaskValidator extends Base new Validators\Integer('recurrence_trigger', t('This value must be an integer')), new Validators\Integer('recurrence_status', t('This value must be an integer')), new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), + new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50), new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getDateFormats()), new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getAllFormats()), new Validators\Numeric('time_spent', t('This value must be numeric')), diff --git a/app/Model/User.php b/app/Model/User.php index fd2ec954..2b6436f8 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -167,6 +167,18 @@ class User extends Base } /** + * Get user_id by username + * + * @access public + * @param string $username Username + * @return array + */ + public function getIdByUsername($username) + { + return $this->db->table(self::TABLE)->eq('username', $username)->findOneColumn('id'); + } + + /** * Get a specific user by the email address * * @access public diff --git a/app/Model/UserImport.php b/app/Model/UserImport.php new file mode 100644 index 00000000..3d7c0feb --- /dev/null +++ b/app/Model/UserImport.php @@ -0,0 +1,110 @@ +<?php + +namespace Model; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; +use Core\Csv; + +/** + * User Import + * + * @package model + * @author Frederic Guillot + */ +class UserImport extends Base +{ + /** + * Number of successful import + * + * @access public + * @var integer + */ + public $counter = 0; + + /** + * Get mapping between CSV header and SQL columns + * + * @access public + * @return array + */ + public function getColumnMapping() + { + return array( + 'username' => 'Username', + 'password' => 'Password', + 'email' => 'Email', + 'name' => 'Full Name', + 'is_admin' => 'Administrator', + 'is_project_admin' => 'Project Administrator', + 'is_ldap_user' => 'Remote User', + ); + } + + /** + * Import a single row + * + * @access public + * @param array $row + * @param integer $line_number + */ + public function import(array $row, $line_number) + { + $row = $this->prepare($row); + + if ($this->validateCreation($row)) { + if ($this->user->create($row)) { + $this->logger->debug('UserImport: imported successfully line '.$line_number); + $this->counter++; + } + else { + $this->logger->error('UserImport: creation error at line '.$line_number); + } + } + else { + $this->logger->error('UserImport: validation error at line '.$line_number); + } + } + + /** + * Format row before validation + * + * @access public + * @param array $data + * @return array + */ + public function prepare(array $row) + { + $row['username'] = strtolower($row['username']); + + foreach (array('is_admin', 'is_project_admin', 'is_ldap_user') as $field) { + $row[$field] = Csv::getBooleanValue($row[$field]); + } + + $this->removeEmptyFields($row, array('password', 'email', 'name')); + + return $row; + } + + /** + * Validate user creation + * + * @access public + * @param array $values + * @return boolean + */ + public function validateCreation(array $values) + { + $v = new Validator($values, array( + new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), + new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), User::TABLE, 'id'), + new Validators\MinLength('password', t('The minimum length is %d characters', 6), 6), + new Validators\Email('email', t('Email address invalid')), + new Validators\Integer('is_admin', t('This value must be an integer')), + new Validators\Integer('is_project_admin', t('This value must be an integer')), + new Validators\Integer('is_ldap_user', t('This value must be an integer')), + )); + + return $v->execute(); + } +} diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 5d157749..2db0ec54 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -63,8 +63,10 @@ class ClassProvider implements ServiceProviderInterface 'TaskPosition', 'TaskStatus', 'TaskValidator', + 'TaskImport', 'Transition', 'User', + 'UserImport', 'UserSession', 'Webhook', ), diff --git a/app/Template/project/sidebar.php b/app/Template/project/sidebar.php index d8b35e3b..971ed950 100644 --- a/app/Template/project/sidebar.php +++ b/app/Template/project/sidebar.php @@ -45,6 +45,9 @@ <?= $this->url->link(t('Enable'), 'project', 'enable', array('project_id' => $project['id']), true) ?> <?php endif ?> </li> + <li <?= $this->app->getRouterController() === 'taskImport' && $this->app->getRouterAction() === 'step1' ? 'class="active"' : '' ?>> + <?= $this->url->link(t('Import'), 'taskImport', 'step1', array('project_id' => $project['id'])) ?> + </li> <?php if ($this->user->isProjectAdministrationAllowed($project['id'])): ?> <li <?= $this->app->getRouterController() === 'project' && $this->app->getRouterAction() === 'remove' ? 'class="active"' : '' ?>> <?= $this->url->link(t('Remove'), 'project', 'remove', array('project_id' => $project['id'])) ?> diff --git a/app/Template/task_import/step1.php b/app/Template/task_import/step1.php new file mode 100644 index 00000000..7619216a --- /dev/null +++ b/app/Template/task_import/step1.php @@ -0,0 +1,34 @@ +<div class="page-header"> + <h2><?= t('Tasks Importation') ?></h2> +</div> +<form action="<?= $this->url->href('taskImport', 'step2', array('project_id' => $project['id'])) ?>" method="post" enctype="multipart/form-data"> + <?= $this->form->csrf() ?> + + <?= $this->form->label(t('Delimiter'), 'delimiter') ?> + <?= $this->form->select('delimiter', $delimiters, $values) ?> + + <?= $this->form->label(t('Enclosure'), 'enclosure') ?> + <?= $this->form->select('enclosure', $enclosures, $values) ?> + + <?= $this->form->label(t('CSV File'), 'file') ?> + <?= $this->form->file('file', $errors) ?> + + <p class="form-help"><?= t('Maximum size: ') ?><?= is_integer($max_size) ? $this->text->bytes($max_size) : $max_size ?></p> + + <div class="form-actions"> + <input type="submit" value="<?= t('Import') ?>" class="btn btn-blue"> + </div> +</form> +<div class="page-header"> + <h2><?= t('Instructions') ?></h2> +</div> +<div class="alert"> + <ul> + <li><?= t('Your file must use the predefined CSV format') ?></li> + <li><?= t('Your file must be encoded in UTF-8') ?></li> + <li><?= t('The first row must be the header') ?></li> + <li><?= t('Duplicates are not verified for you') ?></li> + <li><?= t('The due date must use the ISO format: YYYY-MM-DD') ?></li> + </ul> +</div> +<p><i class="fa fa-download fa-fw"></i><?= $this->url->link(t('Download CSV template'), 'taskImport', 'template', array('project_id' => $project['id'])) ?></p>
\ No newline at end of file diff --git a/app/Template/user/index.php b/app/Template/user/index.php index d74aa748..4008b920 100644 --- a/app/Template/user/index.php +++ b/app/Template/user/index.php @@ -4,10 +4,10 @@ <ul> <li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'user', 'create') ?></li> <li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?></li> + <li><i class="fa fa-upload fa-fw"></i><?= $this->url->link(t('Import'), 'userImport', 'step1') ?></li> </ul> <?php endif ?> </div> - <section> <?php if ($paginator->isEmpty()): ?> <p class="alert"><?= t('No user') ?></p> <?php else: ?> @@ -62,5 +62,4 @@ <?= $paginator ?> <?php endif ?> - </section> </section> diff --git a/app/Template/user_import/step1.php b/app/Template/user_import/step1.php new file mode 100644 index 00000000..7256bfa6 --- /dev/null +++ b/app/Template/user_import/step1.php @@ -0,0 +1,46 @@ +<section id="main"> + <div class="page-header"> + <?php if ($this->user->isAdmin()): ?> + <ul> + <li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('All users'), 'user', 'index') ?></li> + <li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'user', 'create') ?></li> + <li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'user', 'create', array('remote' => 1)) ?></li> + </ul> + <?php endif ?> + </div> + <div class="page-header"> + <h2><?= t('Import') ?></h2> + </div> + <form action="<?= $this->url->href('userImport', 'step2') ?>" method="post" enctype="multipart/form-data"> + <?= $this->form->csrf() ?> + + <?= $this->form->label(t('Delimiter'), 'delimiter') ?> + <?= $this->form->select('delimiter', $delimiters, $values) ?> + + <?= $this->form->label(t('Enclosure'), 'enclosure') ?> + <?= $this->form->select('enclosure', $enclosures, $values) ?> + + <?= $this->form->label(t('CSV File'), 'file') ?> + <?= $this->form->file('file', $errors) ?> + + <p class="form-help"><?= t('Maximum size: ') ?><?= is_integer($max_size) ? $this->text->bytes($max_size) : $max_size ?></p> + + <div class="form-actions"> + <input type="submit" value="<?= t('Import') ?>" class="btn btn-blue"> + </div> + </form> + <div class="page-header"> + <h2><?= t('Instructions') ?></h2> + </div> + <div class="alert"> + <ul> + <li><?= t('Your file must use the predefined CSV format') ?></li> + <li><?= t('Your file must be encoded in UTF-8') ?></li> + <li><?= t('The first row must be the header') ?></li> + <li><?= t('Duplicates are not imported') ?></li> + <li><?= t('Usernames must be lowercase and unique') ?></li> + <li><?= t('Passwords will be encrypted if present') ?></li> + </ul> + </div> + <p><i class="fa fa-download fa-fw"></i><?= $this->url->link(t('Download CSV template'), 'userImport', 'template') ?></p> +</section>
\ No newline at end of file |