summaryrefslogtreecommitdiffstats
path: root/system/scaffolding
diff options
context:
space:
mode:
Diffstat (limited to 'system/scaffolding')
-rw-r--r--system/scaffolding/Scaffolding.php285
-rw-r--r--system/scaffolding/images/background.jpgbin0 -> 410 bytes
-rw-r--r--system/scaffolding/images/index.html15
-rw-r--r--system/scaffolding/images/logo.jpgbin0 -> 4518 bytes
-rw-r--r--system/scaffolding/index.html15
-rw-r--r--system/scaffolding/views/add.php30
-rw-r--r--system/scaffolding/views/delete.php7
-rw-r--r--system/scaffolding/views/edit.php31
-rw-r--r--system/scaffolding/views/footer.php10
-rw-r--r--system/scaffolding/views/header.php31
-rw-r--r--system/scaffolding/views/index.html15
-rw-r--r--system/scaffolding/views/no_data.php6
-rw-r--r--system/scaffolding/views/stylesheet.css143
-rw-r--r--system/scaffolding/views/view.php25
14 files changed, 613 insertions, 0 deletions
diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php
new file mode 100644
index 000000000..4b6ebeed5
--- /dev/null
+++ b/system/scaffolding/Scaffolding.php
@@ -0,0 +1,285 @@
+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * Code Igniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author Rick Ellis
+ * @copyright Copyright (c) 2006, pMachine, Inc.
+ * @license http://www.codeignitor.com/user_guide/license.html
+ * @link http://www.codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Scaffolding Class
+ *
+ * Provides the Scaffolding framework
+ *
+ * @package CodeIgniter
+ * @subpackage Scaffolding
+ * @author Rick Ellis
+ * @link http://www.codeigniter.com/user_guide/general/scaffolding.html
+ */
+class Scaffolding {
+
+ var $current_table;
+ var $base_url = '';
+ var $lang = array();
+
+ function Scaffolding($db_table)
+ {
+ $obj =& get_instance();
+ foreach ($obj->ci_is_loaded as $val)
+ {
+ $this->$val =& $obj->$val;
+ }
+
+ /**
+ * Set the current table name
+ * This is done when initializing scaffolding:
+ * $this->_ci_init_scaffolding('table_name')
+ *
+ */
+ $this->current_table = $db_table;
+
+ /**
+ * Set the path to the "view" files
+ * We'll manually override the "view" path so that
+ * the load->view function knows where to look.
+ */
+ $this->load->_ci_set_view_path(BASEPATH.'scaffolding/views/');
+
+ // Set the base URL
+ $this->base_url = $this->config->site_url().'/'.$this->uri->segment(1).$this->uri->slash_segment(2, 'both');
+ $this->base_uri = $this->uri->segment(1).$this->uri->slash_segment(2, 'leading');
+
+ // Set a few globals
+ $data = array(
+ 'image_url' => $this->config->system_url().'scaffolding/images/',
+ 'base_uri' => $this->base_uri,
+ 'base_url' => $this->base_url,
+ 'title' => $this->current_table
+ );
+
+ $this->load->vars($data);
+
+ // Load the language file and create variables
+ $this->lang = $this->load->language('scaffolding', '', TRUE);
+ $this->load->vars($this->lang);
+
+ // Load the helper files we plan to use
+ $this->load->helper(array('url', 'form'));
+
+
+ log_message('debug', 'Scaffolding Class Initialized');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * "Add" Page
+ *
+ * Shows a form representing the currently selected DB
+ * so that data can be inserted
+ *
+ * @access public
+ * @return string the HTML "add" page
+ */
+ function add()
+ {
+ $data = array(
+ 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'],
+ 'fields' => $this->db->field_data($this->current_table),
+ 'action' => $this->base_uri.'/insert'
+ );
+
+ $this->load->view('add', $data);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Insert the data
+ *
+ * @access public
+ * @return void redirects to the view page
+ */
+ function insert()
+ {
+ if ($this->db->insert($this->current_table, $_POST) === FALSE)
+ {
+ $this->add();
+ }
+ else
+ {
+ redirect($this->base_uri.'/view/');
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * "View" Page
+ *
+ * Shows a table containing the data in the currently
+ * selected DB
+ *
+ * @access public
+ * @return string the HTML "view" page
+ */
+ function view()
+ {
+ // Fetch the total number of DB rows
+ $total_rows = $this->db->count_all($this->current_table);
+
+ if ($total_rows < 1)
+ {
+ return $this->load->view('no_data');
+ }
+
+ // Set the query limit/offset
+ $per_page = 20;
+ $offset = $this->uri->segment(4, 0);
+
+ // Run the query
+ $query = $this->db->get($this->current_table, $per_page, $offset);
+
+ // Now let's get the field names
+ $fields = $this->db->field_names($this->current_table);
+
+ // We assume that the column in the first position is the primary field.
+ $primary = current($fields);
+
+ // Pagination!
+ $this->pagination->initialize(
+ array(
+ 'base_url' => $this->base_url.'/view',
+ 'total_rows' => $total_rows,
+ 'per_page' => $per_page,
+ 'uri_segment' => 4,
+ 'full_tag_open' => '<p>',
+ 'full_tag_close' => '</p>'
+ )
+ );
+
+ $data = array(
+ 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'],
+ 'query' => $query,
+ 'fields' => $fields,
+ 'primary' => $primary,
+ 'paginate' => $this->pagination->create_links()
+ );
+
+ $this->load->view('view', $data);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * "Edit" Page
+ *
+ * Shows a form representing the currently selected DB
+ * so that data can be edited
+ *
+ * @access public
+ * @return string the HTML "edit" page
+ */
+ function edit()
+ {
+ if (FALSE === ($id = $this->uri->segment(4)))
+ {
+ return $this->view();
+ }
+
+ // Fetch the primary field name
+ $primary = $this->db->primary($this->current_table);
+
+ // Run the query
+ $query = $this->db->getwhere($this->current_table, array($primary => $id));
+
+ $data = array(
+ 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'],
+ 'fields' => $query->field_data(),
+ 'query' => $query->row(),
+ 'action' => $this->base_uri.'/update/'.$this->uri->segment(4)
+ );
+
+ $this->load->view('edit', $data);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Update
+ *
+ * @access public
+ * @return void redirects to the view page
+ */
+ function update()
+ {
+ // Fetch the primary key
+ $primary = $this->db->primary($this->current_table);
+
+ // Now do the query
+ $this->db->update($this->current_table, $_POST, array($primary => $this->uri->segment(4)));
+
+ redirect($this->base_uri.'/view/');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete Confirmation
+ *
+ * @access public
+ * @return string the HTML "delete confirm" page
+ */
+ function delete()
+ {
+ if ( ! isset($this->lang['scaff_del_confirm']))
+ {
+ $message = 'Are you sure you want to delete the following row: '.$this->uri->segment(4);
+ }
+ else
+ {
+ $message = $this->lang['scaff_del_confirm'].' '.$this->uri->segment(4);
+ }
+
+ $data = array(
+ 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'],
+ 'message' => $message,
+ 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']),
+ 'yes' => anchor(array($this->base_uri, 'do_delete', $this->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes'])
+ );
+
+ $this->load->view('delete', $data);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Delete
+ *
+ * @access public
+ * @return void redirects to the view page
+ */
+ function do_delete()
+ {
+ // Fetch the primary key
+ $primary = $this->db->primary($this->current_table);
+
+ // Now do the query
+ $this->db->where($primary, $this->uri->segment(4));
+ $this->db->delete($this->current_table);
+
+ header("Refresh:0;url=".site_url(array($this->base_uri, 'view')));
+ exit;
+ }
+
+}
+?> \ No newline at end of file
diff --git a/system/scaffolding/images/background.jpg b/system/scaffolding/images/background.jpg
new file mode 100644
index 000000000..9d5bdcea1
--- /dev/null
+++ b/system/scaffolding/images/background.jpg
Binary files differ
diff --git a/system/scaffolding/images/index.html b/system/scaffolding/images/index.html
new file mode 100644
index 000000000..5a1f5d6ae
--- /dev/null
+++ b/system/scaffolding/images/index.html
@@ -0,0 +1,15 @@
+<html>
+
+<head>
+
+<title>403 Forbidden</title>
+
+</head>
+
+<body bgcolor='#ffffff'>
+
+<p>Directory access is forbidden.<p>
+
+</body>
+
+</html> \ No newline at end of file
diff --git a/system/scaffolding/images/logo.jpg b/system/scaffolding/images/logo.jpg
new file mode 100644
index 000000000..d6cc9a76d
--- /dev/null
+++ b/system/scaffolding/images/logo.jpg
Binary files differ
diff --git a/system/scaffolding/index.html b/system/scaffolding/index.html
new file mode 100644
index 000000000..5a1f5d6ae
--- /dev/null
+++ b/system/scaffolding/index.html
@@ -0,0 +1,15 @@
+<html>
+
+<head>
+
+<title>403 Forbidden</title>
+
+</head>
+
+<body bgcolor='#ffffff'>
+
+<p>Directory access is forbidden.<p>
+
+</body>
+
+</html> \ No newline at end of file
diff --git a/system/scaffolding/views/add.php b/system/scaffolding/views/add.php
new file mode 100644
index 000000000..a65e3d745
--- /dev/null
+++ b/system/scaffolding/views/add.php
@@ -0,0 +1,30 @@
+<?php $this->load->view('header'); ?>
+
+<p><?php echo anchor(array($base_uri, 'view'), '&lt; '.$scaff_view_all); ?></p>
+
+
+<?php echo form_open($action); ?>
+
+<table border="0" cellpadding="3" cellspacing="1">
+<?php foreach($fields as $field): ?>
+
+<?php if ($field->primary_key == 1) continue; ?>
+
+<tr>
+ <td><?php echo $field->name; echo ' '.$field->default; ?></td>
+
+ <?php if ($field->type == 'blob'): ?>
+ <td><textarea class="textarea" name="<?php echo $field->name; ?>" cols="60" rows="10" ><?php echo form_prep($field->default); ?></textarea></td>
+ <?php else : ?>
+ <td><input class="input" name="<?php echo $field->name; ?>" value="<?php echo form_prep($field->default); ?>" size="60" /></td>
+ <?php endif; ?>
+
+</tr>
+<?php endforeach; ?>
+</table>
+
+<input type="submit" class="submit" value="Insert" />
+
+</form>
+
+<?php $this->load->view('footer'); ?>
diff --git a/system/scaffolding/views/delete.php b/system/scaffolding/views/delete.php
new file mode 100644
index 000000000..75a5c21b8
--- /dev/null
+++ b/system/scaffolding/views/delete.php
@@ -0,0 +1,7 @@
+<?php $this->load->view('header'); ?>
+
+<p><?php echo $message; ?></p>
+
+<p><?php echo $no; ?>&nbsp;&nbsp;|&nbsp;&nbsp;<?php echo $yes; ?>
+
+<?php $this->load->view('footer'); ?>
diff --git a/system/scaffolding/views/edit.php b/system/scaffolding/views/edit.php
new file mode 100644
index 000000000..a7d65c619
--- /dev/null
+++ b/system/scaffolding/views/edit.php
@@ -0,0 +1,31 @@
+<?php $this->load->view('header'); ?>
+
+
+<p><?php echo anchor(array($base_uri, 'view'), '&lt; '.$scaff_view_all);?></p>
+
+
+<?php echo form_open($action); ?>
+
+<table border="0" cellpadding="3" cellspacing="1">
+<?php foreach($fields as $field): ?>
+
+<?php if ($field->primary_key == 1) continue; ?>
+
+<tr>
+ <td><?php echo $field->name; ?></td>
+
+ <?php if ($field->type == 'blob'): ?>
+ <td><textarea class="textarea" name="<?php echo $field->name;?>" cols="60" rows="10" ><?php $f = $field->name; echo form_prep($query->$f); ?></textarea></td>
+ <?php else : ?>
+ <td><input class="input" value="<?php $f = $field->name; echo form_prep($query->$f); ?>" name="<?php echo $field->name; ?>" size="60" /></td>
+ <?php endif; ?>
+
+</tr>
+<?php endforeach; ?>
+</table>
+
+<input type="submit" class="submit" value="Update" />
+
+</form>
+
+<?php $this->load->view('footer'); ?> \ No newline at end of file
diff --git a/system/scaffolding/views/footer.php b/system/scaffolding/views/footer.php
new file mode 100644
index 000000000..36b29d1cd
--- /dev/null
+++ b/system/scaffolding/views/footer.php
@@ -0,0 +1,10 @@
+
+</div>
+
+<div id="footer">
+<p><a href="http://www.codeigniter.com/">Code Igniter</a>, by <a href="http://www.pmachine.com">pMachine</a> - Version <?php echo APPVER ?></p>
+<p>Page rendered in {elapsed_time}</p>
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/system/scaffolding/views/header.php b/system/scaffolding/views/header.php
new file mode 100644
index 000000000..7ab60fd81
--- /dev/null
+++ b/system/scaffolding/views/header.php
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+
+<title><?php echo $title; ?></title>
+
+<style type='text/css'>
+<?php $this->file(BASEPATH.'scaffolding/views/stylesheet.css'); ?>
+</style>
+
+<script src="../../nav.js" type="text/javascript"></script>
+
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv='expires' content='-1' />
+<meta http-equiv= 'pragma' content='no-cache' />
+
+</head>
+<body>
+
+<div id="header">
+<div id="header_left">
+<h3>Scaffolding:&nbsp; <?php echo $title; ?></h3>
+</div>
+<div id="header_right">
+<?php echo anchor(array($base_uri, 'view'), $scaff_view_records); ?> &nbsp;&nbsp;|&nbsp;&nbsp;
+<?php echo anchor(array($base_uri, 'add'), $scaff_create_record); ?>
+</div>
+</div>
+
+<br clear="all">
+<div id="outer"> \ No newline at end of file
diff --git a/system/scaffolding/views/index.html b/system/scaffolding/views/index.html
new file mode 100644
index 000000000..5a1f5d6ae
--- /dev/null
+++ b/system/scaffolding/views/index.html
@@ -0,0 +1,15 @@
+<html>
+
+<head>
+
+<title>403 Forbidden</title>
+
+</head>
+
+<body bgcolor='#ffffff'>
+
+<p>Directory access is forbidden.<p>
+
+</body>
+
+</html> \ No newline at end of file
diff --git a/system/scaffolding/views/no_data.php b/system/scaffolding/views/no_data.php
new file mode 100644
index 000000000..dca477e2d
--- /dev/null
+++ b/system/scaffolding/views/no_data.php
@@ -0,0 +1,6 @@
+<?php $this->load->view('header'); ?>
+
+<p><?php echo $scaff_no_data; ?></p>
+<p><?php echo anchor(array($base_uri, 'add'), $scaff_create_record); ?></p>
+
+<?php $this->load->view('footer'); ?> \ No newline at end of file
diff --git a/system/scaffolding/views/stylesheet.css b/system/scaffolding/views/stylesheet.css
new file mode 100644
index 000000000..55c8d9e59
--- /dev/null
+++ b/system/scaffolding/views/stylesheet.css
@@ -0,0 +1,143 @@
+body {
+ margin: 0;
+ padding: 0;
+ font-family: Lucida Grande, Verdana, Geneva, Sans-serif;
+ font-size: 11px;
+ color: #4F5155;
+ background: #fff url(<?php echo $image_url; ?>background.jpg) repeat-x left top;
+}
+
+a {
+ color: #8B0D00;
+ background-color: transparent;
+ text-decoration: none;
+ font-weight: bold;
+}
+
+a:visited {
+ color: #8B0D00;
+ background-color: transparent;
+ text-decoration: none;
+}
+
+a:hover {
+ color: #000;
+ text-decoration: none;
+ background-color: transparent;
+}
+
+
+#header {
+ margin: 0;
+ padding: 0;
+}
+
+#header_left {
+ background-color: transparent;
+ float: left;
+ padding: 21px 0 0 32px;
+ margin: 0
+}
+
+#header_right {
+ background-color: transparent;
+ float: right;
+ text-align: right;
+ padding: 35px 50px 20px 0;
+ margin: 0
+}
+
+#footer {
+ margin: 20px 0 15px 0;
+ padding: 0;
+}
+
+#footer p {
+ font-size: 10px;
+ color: #999;
+ text-align: center;
+}
+
+#outer {
+ margin: 30px 40px 0 40px;
+}
+
+img {
+ padding:0;
+ border: 0;
+ margin: 0;
+}
+
+.nopad {
+ padding:0;
+ border: 0;
+ margin: 0;
+}
+
+table {
+ background-color: #efefef;
+}
+
+th {
+ background-color: #eee;
+ font-weight: bold;
+ padding: 6px;
+ text-align: left;
+}
+
+td {
+ background-color: #fff;
+ padding: 6px;
+}
+
+
+form {
+ margin: 0;
+ padding: 0;
+}
+
+.input {
+ font-family: Lucida Grande, Verdana, Geneva, Sans-serif;
+ font-size: 11px;
+ width: 600px;
+ color: #333;
+ border: 1px solid #B3B4BD;
+ font-size: 11px;
+ height: 2em;
+ padding: 0;
+ margin: 0;
+}
+
+.textarea {
+ font-family: Lucida Grande, Verdana, Geneva, Sans-serif;
+ font-size: 12px;
+ width: 600px;
+ color: #333;
+ border: 1px solid #B3B4BD;
+ padding: 0;
+ margin: 0;
+}
+
+.select {
+ background-color: #fff;
+ font-size: 11px;
+ font-weight: normal;
+ color: #333;
+ padding: 0;
+ margin: 0 0 3px 0;
+}
+
+.checkbox {
+ background-color: transparent;
+ padding: 0;
+ border: 0;
+}
+
+.submit {
+ background-color: #8B0D00;
+ color: transparent;
+ font-weight: normal;
+ border: 1px solid #000;
+ margin: 6px 0 0 0;
+ padding: 1px 5px 1px 5px;
+}
diff --git a/system/scaffolding/views/view.php b/system/scaffolding/views/view.php
new file mode 100644
index 000000000..fd20a174d
--- /dev/null
+++ b/system/scaffolding/views/view.php
@@ -0,0 +1,25 @@
+<?php $this->load->view('header'); ?>
+
+<table border="0" cellpadding="0" cellspacing="1" style="width:100%">
+ <tr>
+ <th>Edit</th>
+ <th>Delete</th>
+ <?php foreach($fields as $field): ?>
+ <th><?php echo $field; ?></th>
+ <?php endforeach; ?>
+</tr><tr>
+
+<?php foreach($query->result() as $row): ?>
+ <tr>
+ <td>&nbsp;<?php echo anchor(array($base_uri, 'edit', $row->$primary), $scaff_edit); ?>&nbsp;</td>
+ <td><?php echo anchor(array($base_uri, 'delete', $row->$primary), $scaff_delete); ?></td>
+ <?php foreach($fields as $field): ?>
+ <td><?php echo form_prep($row->$field);?></td>
+ <?php endforeach; ?>
+ </tr>
+<?php endforeach; ?>
+</table>
+
+<?php echo $paginate; ?>
+
+<?php $this->load->view('footer'); ?> \ No newline at end of file