From f73c7cbad25416177a8103686e4d680079a82baf Mon Sep 17 00:00:00 2001 From: Valkum Date: Sun, 2 Jan 2011 14:16:19 +0000 Subject: [PATCH] added some things to model class added user_model.php for user handling added user_controller.php for controlling user missgin view for output. git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@933 a1433add-5e2c-0410-b055-b7f2511e0802 --- scripts/snippets/model.php | 55 +++++++++++++++++-------- scripts/snippets/user_controller.php | 60 ++++++++++++++++++++++++++++ scripts/snippets/user_model.php | 24 +++++++++++ 3 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 scripts/snippets/user_controller.php create mode 100644 scripts/snippets/user_model.php diff --git a/scripts/snippets/model.php b/scripts/snippets/model.php index 5c36ba0d..389870e5 100644 --- a/scripts/snippets/model.php +++ b/scripts/snippets/model.php @@ -1,41 +1,62 @@ insert($this->table, $this->values); + $db->insert( $this->table, $this->values ); #pseudocode else $db->update( $this->table, $this->id, $this->values ); } - public load( $parameter = array() ) { - ##pseudocode if where is key in parameters + public function load( $parameter = array() ) { + $sql = ''; + $db = new Database; + if (array_key_exists( 'where', $parameter) ) { $w = $parameters['where']; # where = array('column', 'value' ) - $sql = " WHERE $where['column'] = $where['value']"; - ## elseif limit is key in parameters - $l = $parameter['limit'] - $sq = " LIMIT $l[1], $l[2]"; + $sql .= " WHERE $w[0] = $w[1]"; + } elseif ( array_key_exists('limit', $parameter ) ) { + $l = $parameter['limit'] # limit = array(start, length) + $sql .= " LIMIT $l[0], $l[1]"; + } - $db->query("SELECT * FROM $this->table $sql"); + $this->query = $db->query("SELECT * FROM \{ $this->table \} $sql"); + } + + public function delete( $parameter = array() ) { + + } + public function Assoc() { + $db = new Database(); + return $db->getAssoc($this->query); + } + public function Array() { + $db = new Database(); + return $db->getArray($this->query); + } + public function Object() { + $db = new Database(); + return $db->getObject($this->query); + } + public function Row() { + $db = new Database(); + return $db->getRow($this->query); } - } diff --git a/scripts/snippets/user_controller.php b/scripts/snippets/user_controller.php new file mode 100644 index 00000000..66899e6c --- /dev/null +++ b/scripts/snippets/user_controller.php @@ -0,0 +1,60 @@ +User->load( array( 'where' => array( $this->User->coloumn_id, $id ) ) ); + } else { + $this->Userload(); + } + + //function for sending the layout the arg $this->User->Assoc(); + //return $this->User->Assoc(); + } + public function edit($id) { + if($id == NULL) { + $this->errormsg[] = 'The User is nonexistent.'; + return false; + } + $this->User->load(array( 'where' => array( $this->User->coloumn_id, $id ))); + //function for sending the layout the arg $this->User->Assoc(); + + //postswtich + //bla bla smarty stuff for getting the values + //$this->User->values = array('frit@example.com', 'hased HMAC_MD5 PW', 'Fritz', '/home/fritz/maildir', 51200000, 'fritz', 'example.com', '{[CREATED]}', '{[MODIFIED]}'); {} = Model should replace something, [] = constant not tablenames + + if( ! $this->User->save() ) { + $this->errormsg[] = 'The data can't be saved.'; + return false; + } + + //redirect to view($id) + } + + public function add() { + + + //only if $_POST of $_GET + + //bla bla smarty stuff for filling the values + //$this->User->values = array('frit@example.com', 'hased HMAC_MD5 PW', 'Fritz', '/home/fritz/maildir', 51200000, 'fritz', 'example.com', '{[CREATED]}', '{[MODIFIED]}'); {} = Model should replace something, [] = constant not tablenames + + if( ! $this->User->save() ) { + $this->errormsg[] = 'The data can't be saved.'; + return false; + } + //redirect to view($id) + } + public function delete($id) { + + } + public function activate() { + + } + public function deactivate() { + + } \ No newline at end of file diff --git a/scripts/snippets/user_model.php b/scripts/snippets/user_model.php new file mode 100644 index 00000000..be42216a --- /dev/null +++ b/scripts/snippets/user_model.php @@ -0,0 +1,24 @@ +table = 'mailbox'; + $this->columns = array('username' => array('varchar(255)', false), + 'password' => array('varchar(255)', false), + 'name' => array('varchar(255)', false), + 'maildir' => array('varchar(255)', false), + 'quota' => array('bigint', false, 0), + 'local_part' => array('varchar(255)', false), + 'domain' => array('varchar(255)', false), + 'created' => array('datetime', false), + 'modified' => array('datetime', false), + 'active' => array('tinyint(1)', false, 1) ); + $this->coloumn_id = 'username'; + } + +} + \ No newline at end of file