Permalink
Browse files

add edit method

  • Loading branch information...
freefcw committed Mar 22, 2012
1 parent e561dfd commit e8a9d7c6f739b868d4add00e443469b89f776f4d
Showing with 85 additions and 4 deletions.
  1. +47 −4 approot/application/classes/controller/client.php
  2. +38 −0 approot/application/views/client/edit.php
@@ -16,22 +16,51 @@ public function action_list()
$client_list = $m->get_page($page);
$body = View::factory('client/list');
+
+ $body->set_global('title', "Client Page {$page}");
$body->bind('client_list', $client_list);
$this->body = $body;
}
public function action_edit()
{
- $client_id = $this->request->param('cid', null);
+ if ($this->request->method() == 'POST')
+ {
+ $post = $this->request->post();
+ var_dump($post);
+ exit();
- if ($client_id === null) $this->request->redirect('/login');
+ // logo will save by another way
+ $data = array(
+ 'client_name' => $post['client_name'],
+ 'client_log' => $post['client_logo'],
+ 'content' => $post['content'],
+ );
+
+ $m = new Model_Client();
+
+ $client_id = Arr::get($post, 'client_id');
+
+ if ($client_id === null)
+ {
+ list($client_id, $row) = $m->new_client($data);
+ } else {
+ $m->update_client($data);
+ }
+ } else {
+ $client_id = $this->request->param('cid', null);
+ if ($client_id === null) $this->request->redirect('/login');
+
+ $m = new Model_Client();
+ }
- $m = new Model_Client();
$client = $m->get_client($client_id);
$body = View::factory('client/edit');
+ $body->set_global('title', "Edit Client {$client['name']}");
+
$this->body = $body;
}
@@ -41,6 +70,20 @@ public function action_del()
}
public function action_new()
- {}
+ {
+ $client = array(
+// 'client_id' => '',
+ 'client_name' => '',
+ 'client_log' => '',
+ 'content' =>''
+ );
+
+ $body = View::factory('client/edit');
+
+ $body->set_global('title', 'Add new Client');
+ $body->bind('client', $client);
+
+ $this->body = $body;
+ }
} // End Welcome
@@ -0,0 +1,38 @@
+<form class="form-horizontal" action="/client/edit" method="POST">
+<?php if (array_key_exists('client_id', $client)):?>
+ <input type="hidden" name="client_id" id="client_id" value="<?php echo $client['client_id'];?>" />
+ <legend>Edit Client</legend>
+<?php else: ?>
+ <legend>Add Client</legend>
+<?php endif;?>
+ <fieldset>
+ <div class="control-group">
+ <label class="control-label" for="client_name">Name</label>
+ <div class="controls">
+ <input type="text" class="input-xlarge" id="client_name" name="client_name" value="<?php echo $client['client_name'];?>" />
+ <p class="help-block">Client Name</p>
+ </div>
+ </div>
+ <div class="control-group">
+<?php if (array_key_exists('client_id', $client)):?>
+ <img class="client_log" src="<?php echo $client['client_log'];?>"/>
+ <input type="hidden" name="client_log" value="<?php echo $client['client_log'];?>" />
+<?php endif;?>
+ <label class="control-label" for="fileInput">Client Logo</label>
+ <div class="controls">
+ <input class="input-file" id="fileInput" type="file">
+ <p class="help-block">If not modify then left blank.</p>
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="content">Content</label>
+ <div class="controls">
+ <textarea rows="10" cols="50" class="input-xxlarge" name="content" id="content"><?php echo $client['content'];?></textarea>
+ </div>
+ </div>
+ <div class="form-actions">
+ <button type="submit" class="btn btn-primary">Save changes</button>
+ <button class="btn">Cancel</button>
+ </div>
+ </fieldset>
+ </form>

0 comments on commit e8a9d7c

Please sign in to comment.