public function postAction() { $data = array(); try { $auth = Zend_Auth::getInstance(); $user_id = 0; if ($auth->hasIdentity()) { $user_id = $auth->getIdentity()->id; if ($this->getRequest()->isPost()) { $d = date('Y-m-d'); $ride_id = $this->_getParam("id", ""); $mapper = new Application_Model_TableMapper(); $table_name = "riders"; $values = array("date_created" => $d, "last_updated" => $d, "active" => 1, "ride_id" => $ride_id, "user_id" => $user_id, "group_id" => 0, "rsvp" => 0, "status" => "ON TIME", "complete" => 0, "rating" => 0); $i = $mapper->insertItem($table_name, $values); $id = $mapper->getLastInsertId($table_name); if ($i > 0) { $data["success"] = true; $data["message"] = "Rider added: {$id}"; $data["code"] = 0; } else { $error = array(); $error["code"] = "104"; $error["message"] = "Ride could not be added."; $data["success"] = false; $data["message"] = "Ride could not be added."; $data["code"] = 104; $data["error"] = $error; } } else { $error = array(); $error["code"] = "102"; $error["message"] = "Possible security violation. Please check log(s)."; $data["success"] = false; $data["message"] = "Bad HTTP Request Type."; $data["code"] = 102; $data["error"] = $error; } } else { $error = array(); $error["code"] = "100"; $error["message"] = "User is not authenticated."; $data["success"] = false; $data["message"] = "Rider add fail."; $data["code"] = 102; $data["error"] = $error; } } catch (Exception $ex) { $error = array(); $error["code"] = "Code: " . $ex->getCode(); $error["message"] = "Exception: " . $ex->getMessage(); $data["success"] = false; $data["message"] = "Rider add exception."; $data["error"] = $error; } $this->view->data = json_encode($data); $this->view->layout()->disableLayout(); }
public function registerAction() { $email = $this->_getParam('email', 'Missing User ID'); $password = $this->_getParam('password', ''); $data = array(); try { $date = date('Y-m-d'); $salt = $this->_helper->utilities->create_salt(); $hash = $this->_helper->utilities->create_hash($password, $salt); $insert = array("date_created" => $date, "last_updated" => $date, "active" => 1, "user_name_internal" => "", "user_name_external" => "", "first_name" => "", "last_name" => "", "password" => $hash, "role_id" => 1, "email" => $email, "skill" => "Beginner", "experience" => 0, "type" => "Mellow", "guide" => 0, "salt" => $salt, "viewable" => "", "avatar" => "", "gender" => "M"); $mapper = new Application_Model_TableMapper(); $table_name = "users"; $i = $mapper->insertItem($table_name, $insert); if ($i > 0) { $query = "select * from users where email='{$email}';"; $users = $mapper->getCustomSelect($query); if (count($users) > 0) { $values = array('email' => $email, 'password' => $hash); if ($this->_process($table_name, $values)) { $data["success"] = true; $data["message"] = "Registration success"; $data["code"] = 0; $data["user"] = $users[0]; } else { $data["success"] = false; $data["message"] = "Account created, authentication failed"; $data["code"] = -1; } } } } catch (Exception $ex) { $data["success"] = false; $data["message"] = "Registration failed: " . $ex->getMessage(); $data["code"] = $ex->getCode(); } $this->view->data = json_encode($data); $this->view->layout()->disableLayout(); }
public function saveAction() { $data = array(); try { $auth = Zend_Auth::getInstance(); $user_id = 0; if ($auth->hasIdentity()) { $user_id = $id = $auth->getIdentity()->id; if ($this->getRequest()->isPost()) { $group_id = $this->_getParam("group_id", -1); $name = $this->_getParam("group_name", ""); $description = $this->_getParam("group_description", ""); $deputy = $this->_getParam("group_deputy", 0); $type = $this->_getParam("group_type", ""); $join = $this->_getParam("group_join", ""); $locked = $this->_getParam("group_locked", ""); $m = $this->_getParam("members", ""); $members = explode('|', $m); $f = $this->_getParam("friends", ""); $friends = explode('|', $f); $mapper = new Application_Model_TableMapper(); $table_name = "groups"; $date = date('Y-m-d'); $values = array("last_updated" => $date, "active" => 1, "name" => $name, "description" => $description, "owner" => $user_id, "deputy" => $deputy, "type" => $type, "join" => $join, "locked" => $locked); // update main group info $i = $mapper->updateItem($table_name, $values, $group_id); // after update, remove members, add friends if ($i >= 0) { $table_name = "group_members"; $failed_add = array(); $failed_remove = array(); // delete members (remove checkbox processing) foreach ($members as $id) { if (!empty($id)) { $j = $mapper->deleteItem($table_name, $id); // if you are removing the deputy member // update the group row if ($id == intval($deputy)) { $values = array("last_updated" => $date, "deputy" => 0); $z = $mapper->updateItem("groups", $values, $group_id); } if ($j <= 0) { array_push($failed_remove, $id); } } } foreach ($friends as $id) { if (!empty($id)) { // insert friend $values = array("date_created" => $date, "last_updated" => $date, "active" => 1, "group_id" => $group_id, "user_id" => $id, "role" => "MEMBER"); $j = $mapper->insertItem($table_name, $values); if ($j <= 0) { array_push($failed_add, $id); } } } if (intval($deputy) > 0) { // update deputy $values = array("last_updated" => $date, "active" => 1, "group_id" => $group_id, "user_id" => intval($deputy), "role" => "DEPUTY"); $wheres = array(); $wheres[] = "group_id = {$group_id}"; $wheres[] = "user_id = " . intval($deputy); $k = $mapper->updateSpecific($table_name, $values, $wheres); } if (count($failed_remove) > 0 || count($failed_add) > 0) { $error = array(); $error["code"] = "101"; //$error["message"] = "Failed to remove: ".join($failed_remove, ","); $error["message"] = "Failed to modify members: " . join($failed_remove, ",") . " or add friends: " . join($failed_add, ","); $data["success"] = false; $data["message"] = "Some members failed to remove members or add friends from/to group."; $data["code"] = 101; $data["error"] = $error; } else { $data["success"] = true; $data["message"] = "Group and members edited successfully!"; $data["code"] = 0; } } else { $error = array(); $error["code"] = "104"; $error["message"] = "Failed to edit group"; $data["success"] = false; $data["message"] = "Failed to edit group."; $data["code"] = 104; $data["error"] = $error; } } else { $error = array(); $error["code"] = "102"; $error["message"] = "Possible security violation. Please check log(s)."; $data["success"] = false; $data["message"] = "Bad HTTP Request Type."; $data["code"] = 102; $data["error"] = $error; } } else { $error = array(); $error["code"] = "100"; $error["message"] = "User is not authenticated."; $data["success"] = false; $data["message"] = "Friend update fail."; $data["error"] = $error; } } catch (Exception $ex) { $error = array(); $error["code"] = "Code: " . $ex->getCode(); $error["message"] = "Exception: " . $ex->getMessage(); $data["success"] = false; $data["message"] = "Friend add exception."; $data["error"] = $error; } $this->view->data = json_encode($data); $this->view->layout()->disableLayout(); }
public function saveAction() { $mapper = new Application_Model_TableMapper(); $id = $this->_getParam("id", 0); $action = $this->_getParam("action", ""); $date_created = date('Y-m-d'); $last_updated = date('Y-m-d'); $active = 1; $name = $this->_getParam("name", ""); $description = $this->_getParam("description", ""); $owner = $this->_getParam("owner", ""); $group = $this->_getParam("group", ""); $location = $this->_getParam("location", ""); $address = $this->_getParam("address", ""); $date = $this->_getParam("date", ""); $time = $this->_getParam("time", ""); $status = $this->_getParam("status", ""); $join = $this->_getParam("join", ""); $tempo = $this->_getParam("tempo", ""); $drop = $this->_getParam("drop", ""); $public = $this->_getParam("public", ""); $post = array('date_created' => $date_created, 'last_updated' => $last_updated, 'active' => $active, 'name' => $name, 'description' => $description, 'owner' => $owner, 'group' => $group, 'location' => $location, 'address' => $address, 'date' => $date, 'time' => $time, 'status' => $status, 'join' => $join, 'tempo' => $tempo, 'drop' => $drop, 'public' => $public); if ($this->getRequest()->isPost()) { if ($action == "add") { $table_name = "rides"; $i = $mapper->insertItem($table_name, $post); $id = $mapper->getLastInsertId($table_name); $data = $mapper->getItemById($table_name, $id); } } $this->view->data = json_encode($data); $this->view->layout()->disableLayout(); }
public function postAction() { $data = array(); try { $auth = Zend_Auth::getInstance(); $user_id = 0; if ($auth->hasIdentity()) { $user_id = $id = $auth->getIdentity()->id; if ($this->getRequest()->isPost()) { $friends = $this->_getParam("friends"); $ids = explode('|', $friends); $mapper = new Application_Model_TableMapper(); $table_name = "friends"; $date = date('Y-m-d'); foreach ($ids as $id) { $values = array("date_created" => $date, "last_updated" => $date, "active" => 1, "user_id" => $user_id, "friend_id" => $id, "clique_id" => 0); $i = $mapper->insertItem($table_name, $values); $failed = array(); if ($i <= 0) { array_push($failed, $id); } } if (count($failed) > 0) { $error = array(); $error["code"] = "101"; $error["message"] = "Failed to add: " . join($failed, ","); $data["success"] = false; $data["message"] = "Some friends failed to add."; $data["code"] = 101; $data["error"] = $error; } else { $data["success"] = true; $data["message"] = "Friends added successfully!"; $data["code"] = 0; } } else { $error = array(); $error["code"] = "102"; $error["message"] = "Possible security violation. Please check log(s)."; $data["success"] = false; $data["message"] = "Bad HTTP Request Type."; $data["code"] = 102; $data["error"] = $error; } } else { $error = array(); $error["code"] = "100"; $error["message"] = "User is not authenticated."; $data["success"] = false; $data["message"] = "Friend update fail."; $data["error"] = $error; } } catch (Exception $ex) { $error = array(); $error["code"] = "Code: " . $ex->getCode(); $error["message"] = "Exception: " . $ex->getMessage(); $data["success"] = false; $data["message"] = "Friend add exception."; $data["error"] = $error; } $this->view->data = json_encode($data); $this->view->layout()->disableLayout(); }
public function uploadAction() { $data = array(); try { $auth = Zend_Auth::getInstance(); $user_id = 0; if ($auth->hasIdentity()) { $user_id = $id = $auth->getIdentity()->id; } if ($user_id > 0) { $destination = realpath(APPLICATION_PATH . "/../public/users/{$user_id}/photos/"); $response = Application_Plugin_Lib::upload($destination); if ($response["success"]) { $data["jsonrpc"] = "2.0"; $data["result"] = null; $data["id"] = "id"; // TODO - insert into photos table if ($response["filedetails"] != null) { $filedetails = $response["filedetails"]; $table_name = "photos"; $mapper = new Application_Model_TableMapper(); $date = date('Y-m-d'); $values = array("date_created" => $date, "last_updated" => $date, "active" => 1, "user_id" => intval($user_id), "ride_id" => 0, "url" => $filedetails["name"], "alt" => "", "height" => 0, "width" => 0, "description" => ""); $i = $mapper->insertItem($table_name, $values); } } else { $error = array(); $error["message"] = $response["message"]; $error["code"] = $response["code"]; $data["jsonrpc"] = "2.0"; $data["error"] = $error; $data["id"] = "id"; } } else { $error = array(); $error["code"] = "100"; $error["message"] = "User is not authenticated."; $data["jsonrpc"] = "2.0"; $data["error"] = $error; $data["id"] = "id"; } } catch (Exception $ex) { $error = array(); $error["code"] = $ex->getCode(); $error["message"] = $ex->getMessage(); $data["jsonrpc"] = "2.0"; $data["error"] = $error; $data["id"] = "id"; } $this->view->data = json_encode($data); $this->view->layout()->disableLayout(); }