Skip to content
Browse files

Completed installer.

  • Loading branch information...
1 parent a001328 commit 49243f914848e6144279ac8c6b5cfb5bdb938eba abenson committed Mar 28, 2012
View
2 application/config/config.php
@@ -257,7 +257,7 @@
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
-$config['sess_use_database'] = TRUE;
+$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'user_session';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = FALSE;
View
257 application/controllers/install.php
@@ -21,6 +21,8 @@ public function __construct()
public function index()
{
+ $data['email'] = '';
+
if ($this->is_method_post() == TRUE)
{
// Validate form.
@@ -30,25 +32,35 @@ public function index()
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|matches[password_conf]|sha1');
if ($this->form_validation->run() == TRUE)
{
- $this->create_tables();
-
+ // TODO Perform check for GD2, etc.
+ if ($this->create_tables() == TRUE)
+ {
+ redirect('album');
+ }
+ else
+ {
+ $data['install_error'] = 'An error occurred during installation';
+ }
+ }
+ else
+ {
+ $data['email'] = $this->input->post('email_address');
}
}
+
$this->load->helper('form');
- $this->load->view('category/create');
+ $this->load->view('install/index', $data);
}
protected function create_tables()
{
- // TODO
- exit();
-
$this->load->dbforge();
-
+ // user table
$user = array(
'id' => array(
'type' => 'INT',
- 'auto_increment' => TRUE
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
),
'uuid' => array(
'type' => 'VARCHAR',
@@ -96,10 +108,12 @@ protected function create_tables()
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('user', TRUE);
+ // album table
$album = array(
'id' => array(
'type' => 'INT',
- 'auto_increment' => TRUE
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
),
'name' => array(
'type' => 'VARCHAR',
@@ -112,9 +126,11 @@ protected function create_tables()
),
'created_by' => array(
'type' => 'INT',
+ 'unsigned' => TRUE,
),
'updated_by' => array(
'type' => 'INT',
+ 'unsigned' => TRUE,
),
'created_at' => array(
'type' => 'DATETIME'
@@ -128,14 +144,17 @@ protected function create_tables()
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('album', TRUE);
+ // album_config table
$album_config = array(
'id' => array(
'type' => 'INT',
- 'auto_increment' => TRUE
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
),
'album_id' => array(
'type' => 'INT',
- 'null' => TRUE
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
),
'thumb_width' => array(
'type' => 'INT',
@@ -153,33 +172,241 @@ protected function create_tables()
'auto_publish' => array(
'type' => 'TINYINT',
'constraint' => 1,
- 'default' => 0
+ 'default' => 1
)
);
$this->dbforge->add_field($album_config);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('album_config', TRUE);
+ // category table
$category = array(
'id' => array(
'type' => 'INT',
- 'auto_increment' => TRUE
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => 45
),
'created_by' => array(
- 'type' => 'INT'
+ 'type' => 'INT',
+ 'unsigned' => TRUE,
)
);
$this->dbforge->add_field($category);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('category', TRUE);
- // Add comment, image, image_category, ticket, user_session, create user account.
+ // image table
+ $image = array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'album_id' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'uuid' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'order_num' => array(
+ 'type' => 'INT',
+ 'null' => TRUE
+ ),
+ 'caption' => array(
+ 'type' => 'TEXT',
+ 'null' => TRUE
+ ),
+ 'raw_name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'file_type' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'file_name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'file_ext' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'file_size' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'path' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ ),
+ 'full_path' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 255,
+ 'null' => TRUE
+ ),
+ 'published' => array(
+ 'type' => 'TINYINT',
+ 'constraint' => 1,
+ 'null' => FALSE
+ ),
+ 'created_at' => array(
+ 'type' => 'DATETIME',
+ 'null' => TRUE
+ ),
+ 'updated_at' => array(
+ 'type' => 'DATETIME',
+ 'null' => TRUE
+ ),
+ 'created_by' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'updated_by' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ )
+ );
+
+ $this->dbforge->add_field($image);
+ $this->dbforge->add_key('id', TRUE);
+ $this->dbforge->create_table('image', TRUE);
+
+ // image_comment table
+ $image_comment = array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'image_id' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'published' => array(
+ 'type' => 'TINYINT',
+ 'constraint' => 1,
+ 'default' => 0
+ ),
+ 'comment' => array(
+ 'type' => 'TEXT',
+ 'null' => TRUE
+ )
+ );
+
+ $this->dbforge->add_field($image_comment);
+ $this->dbforge->add_key('id', TRUE);
+ $this->dbforge->create_table('image_comment', TRUE);
+
+ // image_category table
+ $image_category = array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'image_id' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'category_id' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ )
+ );
+
+ $this->dbforge->add_field($image_category);
+ $this->dbforge->add_key('id', TRUE);
+ $this->dbforge->create_table('image_category', TRUE);
+
+ // ticket table
+ $ticket = array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'auto_increment' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'user_id' => array(
+ 'type' => 'INT',
+ 'null' => TRUE,
+ 'unsigned' => TRUE,
+ ),
+ 'uuid' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => TRUE
+ )
+ );
+
+ $this->dbforge->add_field($ticket);
+ $this->dbforge->add_key('id', TRUE);
+ $this->dbforge->create_table('ticket', TRUE);
+
+ // chmod 'uploads' dir
+ chmod('./uploads', 0775);
+
+ // Success, create user & redirect
+ $this->load->model('user_model');
+ $now = date('Y-m-d H:i:s');
+ $user_data = array(
+ 'email_address' => $this->input->post('email_address'),
+ 'password' => $this->input->post('password'),
+ 'is_active' => 1,
+ 'is_admin' => 1,
+ 'created_at' => $now,
+ 'uuid' => $this->create_uuid(),
+ 'updated_at' => $now);
+ $user_id = $this->user_model->create($user_data);
+ // Fetch user record
+ $user = $this->user_model->find_by_id($user_id);
+ // Sign in
+ $this->create_login_session($user);
+
+ $this->session->set_flashdata('flash_message', "User successfully created. You are now logged in");
+
+ return TRUE;
+ }
+
+ /**
+ *
+ * @param type $user
+ */
+ protected function create_login_session($user)
+ {
+ $session_data = array(
+ 'email_address' => $user->email_address,
+ 'user_id' => $user->id,
+ 'logged_in' => TRUE,
+ 'is_admin' => $user->is_admin,
+ 'ip' => $this->input->ip_address()
+ );
+ $this->session->set_userdata($session_data);
}
}
View
4 application/models/image_model.php
@@ -18,9 +18,9 @@ public function __construct()
*/
public function get_images_by_album_id($album_id)
{
- $this->db->select('image.*, COUNT(comment.id) as comments')
+ $this->db->select('image.*, COUNT(image_comment.id) as comments')
->from($this->table_name)
- ->join('comment', 'comment.image_id = image.id', 'left')
+ ->join('image_comment', 'image_comment.image_id = image.id', 'left')
->order_by('image.order_num', 'asc')
->group_by('image.id')
->where('image.album_id', $album_id);
View
10 application/views/album/images.php
@@ -58,15 +58,15 @@
<div class="info" style="left: <?php echo $config->thumb_width + 50; ?>px">
File name: <?php echo $image->name; ?><br />
Caption: <?php echo $image->caption; ?><br />
- Comments: <?php echo $image->comments; ?><br />
- File size: <?php echo $image->file_size; ?> KBbr />
+ <?php /* Comments: <?php echo $image->comments; ?><br /> */ ?>
+ File size: <?php echo $image->file_size; ?> KB<br />
Category: <span class="label label-info">Uncategorized</span>
</div>
<div class="btn-group">
<a href="<?php echo $img_url; ?>" class="btn img-fancy" rel="tooltip" data-original-title="Preview"><i class="icon-zoom-in"></i></a>
<a href="<?php echo site_url("image/download/$image->id"); ?>" class="btn" title="Download" rel="tooltip" data-original-title="Download"><i class="icon-download-alt"></i></a>
<a href="<?php echo site_url("image/edit/$album->id/$image->id"); ?>" class="btn" title="Edit" rel="tooltip" data-original-title="Edit"><i class="icon-pencil"></i></a>
- <a href="<?php echo site_url("image/comments/$album->id/$image->id"); ?>" class="btn" title="Comments" rel="tooltip" data-original-title="Comments"><i class="icon-comment"></i></a>
+ <?php /* <a href="<?php echo site_url("image/comments/$album->id/$image->id"); ?>" class="btn" title="Comments" rel="tooltip" data-original-title="Comments"><i class="icon-comment"></i></a> */ ?>
<?php if ($image->published == 1): ?>
<a href="<?php echo site_url("image/unpublish/$album->id/$image->id"); ?>" class="btn btn-success" title="Published" rel="tooltip" data-original-title="Published"><i class="icon-ok icon-white"></i></a>
<?php else: ?>
@@ -85,8 +85,8 @@
<li class="nav-header"><?php echo $album->name; ?></li>
<li><a href="<?php echo site_url("album/edit/$album->id"); ?>"><i class="icon-pencil"></i>Rename</a></li>
<li><a href="<?php echo site_url("album/configure/$album->id"); ?>"><i class="icon-cog"></i>Configure</a></li>
- <li><a href="<?php echo site_url("api/feed/json/$album->id"); ?>"><i class="icon-book"></i>JSON Feed</a></li>
- <li><a href="<?php echo site_url("api/feed/json/$album->id"); ?>"><i class="icon-book"></i>XML Feed</a></li>
+ <li><a href="<?php echo site_url("api/feed/json/$album->id"); ?>" target="_blank"><i class="icon-book"></i>JSON Feed</a></li>
+ <li><a href="<?php echo site_url("api/feed/xml/$album->id"); ?>" target="_blank"><i class="icon-book"></i>XML Feed</a></li>
<li class="nav-header">Info</li>
<li>Images: <?php echo $total_images; ?></li>
<li>Album file size: <?php echo round($total_file_size / 1024, 2); ?> MB</li>
View
35 application/views/install/index.php
@@ -0,0 +1,35 @@
+<?php $this->load->view('inc/header_guest'); ?>
+
+<div class="well login">
+ <div class="page-header">
+ <h1>Register</h1>
+ </div>
+ <?php
+ echo form_open('install/index');
+
+ if (isset($install_error)) {
+ echo '<div class="alert alert-error"><strong>' . $install_error . '</strong></div>';
+ }
+ echo form_error('email_address');
+ echo form_label('Email Address', 'email_address');
+ echo form_input('email_address', $email);
+
+ echo form_error('password');
+ echo form_label('Password', 'password');
+ echo form_password('password');
+
+ echo form_error('password_conf');
+ echo form_label('Re-type password', 'password_conf');
+ echo form_password('password_conf');
+ ?>
+ <p>
+ <?php
+ echo form_button(array('id' => 'submit', 'value' => 'Register', 'name' => 'submit', 'type' => 'submit', 'content' => 'Register','class' => 'btn btn-primary btn-large'));
+ ?>
+ </p>
+ <?php
+ echo form_close();
+ ?>
+</div>
+
+<?php $this->load->view('inc/footer_guest'); ?>

0 comments on commit 49243f9

Please sign in to comment.
Something went wrong with that request. Please try again.