From 97b3ca7a117859f4f8539bedcdee045792e5e07f Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 10 Nov 2011 15:52:45 -0500 Subject: [PATCH] Add untested import functionality for transitioning from existing screens system. --- application/controllers/import.php | 98 +++++++++++++++++++++++++++ application/views/import/complete.php | 32 +++++++++ application/views/import/index.php | 8 +++ application/views/import/onetime.php | 8 +++ css/style.css | 34 ++++++++++ 5 files changed, 180 insertions(+) create mode 100644 application/controllers/import.php create mode 100644 application/views/import/complete.php create mode 100644 application/views/import/index.php create mode 100644 application/views/import/onetime.php diff --git a/application/controllers/import.php b/application/controllers/import.php new file mode 100644 index 0000000..6120e70 --- /dev/null +++ b/application/controllers/import.php @@ -0,0 +1,98 @@ +load->model('fileupload'); + $total_uploads = $this->fileupload->count_uploads(); + + if($total_uploads == 0) { + $this->template->load('template','/import/index'); + } else { + $this->template->load('template','/import/onetime'); + } + } + + public function process() { + $old_uploads = '/home/ncaguild/nca-guild.com/screens/old_uploads/'; + $new_uploads = '/home/ncaguild/nca-guild.com/screens/uploads/'; + // load all file + $uploads = scandir($old_uploads); + + $this->load->model('fileupload'); + + $data['uploads'] = array(); + // foreach file + foreach($uploads as $upload) { + // if it is formatted correctly + if(preg_match('/^([0-9]+)(\..*)/', $upload, $matches) != 0) continue; + $extension = $matches[1]; + $old_id = $matches[0]; + $size = getimagesize($old_uploads . $upload); + $width = $size[0]; + $height = $size[1]; + $file_size = filesize($old_uploads . $upload) / 1024; + $hash = md5_file($old_uploads . $upload); + $duplicate = $this->fileupload->check_duplicate($hash); + + if($file_size > 2048) { + $data['uploads'][] = array( + 'old' => $upload, + 'error' => 'File size exceeds 2048kb', + ); + continue; + } + if(preg_match('/(gif|jpg|jpeg|png|bmp)/',$upload) == 0) { + $data['uploads'][] = array( + 'old' => $upload, + 'error' => 'File extension not supported', + ); + continue; + } + if($duplicate) { + $data['uploads'][] = array( + 'old' => $upload, + 'error' => 'File is a duplicate of id '. $duplicate . '', + ); + continue; + } + + // add a row to the database + $file_name = $this->fileupload->add_upload($extension, 'unknown', $width, $height, $file_size, $hash); + + // copy in case we screwed up and can fix later + copy($old_uploads . $upload, $new_uploads . $file_name . $extension); + + // create the new thumbmail + $config = array( + 'image_library' => 'gd2', + 'source_image' => $upload['file_path'] . $file_name . $upload['file_ext'], + 'create_thumb' => true, + 'maintain_ratio' => true, + 'width' => 175, + 'height' => 175, + 'new_image' => './thumbs/' . $file_name . $upload['file_ext'], + 'thumb_marker' => '', + ); + + $this->load->library('image_lib',$config); + $this->image_lib->resize(); + + $data['uploads'][] = array( + 'old' => $upload, + 'new_id' => $new_id, + 'height' => $height, + 'width' => $width, + 'file_size' => $file_size, + 'hash' => $hash, + 'extension' => $extension, + ); + } + + $this->load->vars($data); + $this->template->load('template','/import/complete'); + } + +} + +?> \ No newline at end of file diff --git a/application/views/import/complete.php b/application/views/import/complete.php new file mode 100644 index 0000000..e35cad9 --- /dev/null +++ b/application/views/import/complete.php @@ -0,0 +1,32 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + +
File NameNew IDDimensionsFile SizeHashExtension
+ "> + + + + + xkb
+
\ No newline at end of file diff --git a/application/views/import/index.php b/application/views/import/index.php new file mode 100644 index 0000000..b218e69 --- /dev/null +++ b/application/views/import/index.php @@ -0,0 +1,8 @@ +
+
+ Confirmation +
+
+

Are you sure you are ready to import? Yes!

+
+
\ No newline at end of file diff --git a/application/views/import/onetime.php b/application/views/import/onetime.php new file mode 100644 index 0000000..310f31c --- /dev/null +++ b/application/views/import/onetime.php @@ -0,0 +1,8 @@ +
+
+ Confirmation +
+
+

You cannot import to a database that has existing data.

+
+
\ No newline at end of file diff --git a/css/style.css b/css/style.css index 966c42f..cc4e62b 100644 --- a/css/style.css +++ b/css/style.css @@ -369,4 +369,38 @@ h1{ .underline { text-decoration: underline; +} + + + +/*------------------------- + Import +--------------------------*/ + + + +#uploadTable { + border-collapse: collapse; + border: 2px solid black; + margin-left: auto; + margin-right: auto; +} + +#uploadTable th { + font-weight: bold; + border: 2px solid black; + padding: 5px; +} + +#uploadTable td { + border: 2px solid black; + padding: 1px; +} + +.error { + color: red; +} + +.success { + color: green; } \ No newline at end of file