public function action_add() { $post = $this->request->post(); if ($post) { $this->template->data["post"] = $post; if ($post['role'] == "") { array_push($this->template->data["errors"], array("Role" => __("User role must be set."))); } else { /* automatically obtain password if user set none */ if (empty($post['password'])) { $post['password'] = Auth::randomPassword(); $post['password_confirm'] = $post['password']; } try { $user = ORM::factory('User')->create_user($post, array('email', 'password')); $user->add('roles', ORM::factory('Role', array('name' => $post['role']))); $this->template->data["post"] = NULL; } catch (ORM_Validation_Exception $e) { $this->template->data["errors"] = $e->errors('models'); } if (empty($this->template->data["errors"])) { Notifications::factory()->new_user_account($post['email'], $post); $this->redirect('/admin/user/all'); } } } $this->template->data["roles"] = ORM::factory("Role")->get_roles(); }
public function create_new($post, $discussion_id, $reply_comment_id = NULL) { $comment = NULL; if (isset($post['text']) && isset($discussion_id)) { $user = Auth::instance()->get_user(); $comment = Model::factory('Comment'); $values = array(); $values["text"] = $post['text']; $values["discussion_id"] = $discussion_id; if ($user) { $values["user_id"] = $user->id; } else { if ($post['author_visitor'] != "") { $values["author_visitor"] = $post['author_visitor']; } } $values["reply_comment_id"] = $reply_comment_id; $comment->values($values, array_keys($values)); try { $comment->save(); Notifications::factory()->new_comment($comment->reload()); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); } } return $comment; }
private function save_note($post) { $note = new Model_Note(); $note_data = array_filter($this->parse_post_data($post)); $note->values($note_data, array_keys($note_data)); try { $note->save(); Notifications::factory()->new_note($note->reload()); } catch (Exception $exc) { return false; } return true; }
public function action_add() { $error = FALSE; if ($this->request->post()) { $this->template->data["values"] = $this->request->post(); if ($_FILES['files']['name'][0] != "") { for ($i = 0; $i < count($_FILES['files']['name']); $i++) { $image = Model::factory('Image'); $discussion = new Model_Discussion(); $discussion->save(); $post = $this->request->post(); $post["filename"] = "temp"; $post["discussion_id"] = $discussion->id; $image->values($post, array_keys($post)); try { $image->save(); $filename = $this->_save_image(array("name" => $_FILES['files']['name'][$i], "type" => $_FILES['files']['type'][$i], "tmp_name" => $_FILES['files']['tmp_name'][$i], "error" => $_FILES['files']['error'][$i], "size" => $_FILES['files']['size'][$i]), $this->request->post("project_id"), $image->id); // set new name into DB: if ($filename) { $image->filename = $filename; $image->save(); } $discussion->image_id = $image->id; $discussion->save(); Notifications::factory()->new_image($image); } catch (ORM_Validation_Exception $e) { $this->template->data["errors"] = $e->errors('models'); $error = TRUE; $discussion->delete(); } } } else { $error = TRUE; array_push($this->template->data["errors"], "You must choose file/s."); } if (!$error) { $this->redirect('admin/projects/detail/' . $this->request->post("project_id")); } } else { if (isset($_GET["project_id"])) { $this->template->data["values"] = array("project_id" => $_GET["project_id"]); } } $this->template->data["projects"] = ORM::factory("Project")->order_by('id', 'desc')->find_all()->as_array("id", "name"); }