function _update($collection, $id) { $document = json_decode(Slim::getInstance()->request()->getBody(), true); $data = MongoDB::mongoUpdate(MONGO_HOST, MONGO_DB, $collection, $id, $document); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data); }
/** * Returns the layout for this view. This will be either * the 'layout' data value, the applications 'layout' configuration * value, or 'layout.php'. * * @param array $data Any additonal data to be passed to the template. * * @return string|null */ public function getLayout($data = null) { $layout = null; // 1) Check the passed in data if (is_array($data) && array_key_exists(self::LAYOUT_KEY, $data)) { $layout = $data[self::LAYOUT_KEY]; unset($data[self::LAYOUT_KEY]); } // 2) Check the data on the View if ($this->has(self::LAYOUT_KEY)) { $layout = $this->get(self::LAYOUT_KEY); $this->remove(self::LAYOUT_KEY); } // 3) Check the Slim configuration if (is_null($layout)) { $app = Slim::getInstance(); if (isset($app)) { $layout = $app->config(self::LAYOUT_KEY); } } // 4) Use the default layout if (is_null($layout)) { $layout = self::DEFAULT_LAYOUT; } return $layout; }
function CustomerAction() { $request = Slim::getInstance()->request(); $customer = json_decode($request->getBody()); //echo '{"users": ' . json_encode($user) . '}';exit; $token = $customer->access_token; //echo '{"error":{"text":"'.$token.'"}}'; exit; if ($customer->access_token != "") { $status_token = validate_token($customer->access_token); //echo '{"error":{"text":"'.$status_token.'"}}'; exit; if ($status_token == 'valid') { $sql = "INSERT INTO user_profile (firstname, lastname) VALUES ('" . $customer->first_name . "', '" . $customer->last_name . "' )"; $db_host = "127.0.0.1"; $db_user = "******"; $db_pass = ""; $db_name = "myavazone_db"; $db = new DB(); $db->connect($db_host, $db_user, '', false, false, $db_name, 'tbl_'); $res_q = $db->query($sql); echo '{"apidata": "User Added Sucessfully."}'; exit; break; //echo '{"error":{"text":'.mc_encrypt($user->password,$user->key).'}}'; //echo '{"error":{"text":"Token is valid"}}'; } else { echo '{"error":{"text":"Token is not valid"}}'; } } else { echo '{"error":{"text":"Token is NULL"}}'; } /*$user_details=array( 'password_hash' => mc_encrypt('admin@123','d0a7e7997b6d5fcd55f4b5c32611b87cd923e88837b63bf2941ef819dc8ca282') );*/ }
function deleteFriendship() { global $friendTable, $userTable; /* verifica se existe alguma informacao no corpo da mensagem */ $request = Slim::getInstance()->request(); $json = readRequestBody($request); if (!$json) { $response["status"] = 0; echo json_encode($response); return; } /* lendo dados do json */ $appID = $json->appID; $crypt_data = $json->data; $iv = $json->iv; $json = json_decode(decrypt_data($appID, $crypt_data, $iv)); $id1 = $json->idusuario_a; $id2 = $json->idusuario_b; $response["status"] = 1; $dbh = getConnection(); $sql = "DELETE FROM {$friendTable} where (idusuario_a = :id1 and\n\t\t\t\tidusuario_b = :id2) or (idusuario_a = :id2 and\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tidusuario_b = :id1)"; $stmt = $dbh->prepare($sql); $stmt->bindParam(":id1", $id1); $stmt->bindParam(":id2", $id2); $stmt->execute(); closeConnection($dbh); $json = json_encode($response); $data = encrypt_data($appID, $json); echo json_encode($data); }
function updatePerson($id) { $request = Slim::getInstance()->request(); $data = json_decode($request->getBody()); $sql = "UPDATE people SET \n\t\t\t\temail=:email,\n\t\t\t\tfname=:fname,\n\t\t\t\tlname=:lname,\n\t\t\t\tclientId=:clientId,\n\t\t\t\tstatus=:status,\n\t\t\t\tphone=:phone,\n\t\t\t\tnotes=:notes\n\t\t\t\tWHERE id=:id"; try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("email", $data->email); $stmt->bindParam("fname", $data->fname); $stmt->bindParam("lname", $data->lname); $stmt->bindParam("email", $data->email); $stmt->bindParam("email", $data->email); $stmt->bindParam("clientId", $data->clientId); $stmt->bindParam("status", $data->status); $stmt->bindParam("phone", $data->phone); $stmt->bindParam("notes", $data->notes); $stmt->bindParam("id", $id); $stmt->execute(); $db = null; echo json_encode($data); } catch (PDOException $e) { echo '{"error":{"text":' . $e->getMessage() . '}}'; } }
function youtube_oauth() { global $config; $app = Slim::getInstance(); $code = $app->request()->get("code"); if ($code) { //initial $access_params = array("code" => $code, "client_id" => $config["youtube_client_id"], "client_secret" => $config["youtube_client_secret"], "redirect_uri" => $config["youtube_oauth_callback"], "grant_type" => "authorization_code"); $ch = curl_init("https://accounts.google.com/o/oauth2/token"); curl_setopt($ch, CURLOPT_POST, count($access_params)); curl_setopt($ch, CURLOPT_POSTFIELDS, $access_params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $json_string_data = curl_exec($ch); curl_close($ch); if ($json_string_data) { $auth_data = json_decode($json_string_data, true); $_SESSION["youtube_auth"] = $auth_data; dump($auth_data); //make a call to get the author data //log everything in the database } else { $app->redirect('/'); } } else { $app->redirect('/'); } }
function authenticate() { $app = Slim::getInstance(); if (!App::user()) { $app->redirect("/connect/"); } }
public function save() { GUMP::add_validator("unique", function ($field, $input, $param = NULL) { $checkExistingUser = R::findOne('user', 'user=?', array($input)); if ($checkExistingUser == NULL) { return FALSE; } else { return TRUE; } }); GUMP::add_validator("strong", function ($field, $input, $param = NULL) { return checkPasswordStrength($input); }); $rules = array('reseller_username' => 'required|alpha_numeric|max_len,10|min_len,6|unique', 'reseller_password' => 'required|max_len,10|min_len,7|strong'); $filters = array('reseller_username' => 'trim|sanitize_string', 'reseller_password' => 'trim|sanitize_string|md5'); $app = Slim::getInstance(); $post = $app->request()->post(); // $app - Slim main app instance $postValues = $gump->filter($post, $filters); $validated = $gump->validate($gump->filter($postValues, $filters), $rules); if ($validated === TRUE) { $createUser = R::dispense('user'); $createUser->user = $postValues['reseller_username']; $createUser->user = $postValues['reseller_password']; } else { $this->setError($gump->get_readable_errors(true)); } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } }
function updateIcon() { $request = Slim::getInstance()->request(); $body = $request->getBody(); $body = json_decode($body); unset($body->created_date); if (!empty($body->image)) { file_put_contents('./icon_images/' . $body->image->filename, base64_decode($body->image->base64)); $body->image = $body->image->filename; } else { unset($body->image); } $id = $body->id; unset($body->image_url); if (isset($body->imagee)) { unset($body->imagee); } if (isset($body->id)) { unset($body->id); } $allinfo['save_data'] = $body; $coupon_details = edit(json_encode($allinfo), 'icon', $id); if (!empty($coupon_details)) { $result = '{"type":"success","message":"Changed Succesfully"}'; } else { $result = '{"type":"error","message":"Not Changed"}'; } echo $result; }
/** * Constructor * * Initialize things. * */ function __construct() { if (null == self::$_appInstance) { self::$_appInstance = Slim::getInstance(); } Doctrine_Core::loadModels(MODELS_PATH); DoctrineAdapter::getInstance(); }
function addQuote() { $request = Slim::getInstance()->request(); $data = json_decode($request->getBody()); $quoteCrud = new QuotesCrud(); $results = $quoteCrud->post($data); echo json_encode($results, JSON_NUMERIC_CHECK); }
function _update($db, $collection, $id) { $document = json_decode(Slim::getInstance()->request()->getBody(), true); $data = mongoUpdate(MONGO_HOST, $db, $collection, $id, $document); header("Content-Type: application/json"); echo json_encode($data); exit; }
function show_result($data, $template = 'home.html', $error_code = null) { $app = Slim::getInstance(); if ($app->request()->isAjax()) { echo json_encode($data); } else { $app->render($template, $data, $error_code); } }
/** * A function to add a class */ function addScanResults() { $results = json_decode(Slim::getInstance()->request()->post('scanResults'), true); try { $db = getConnection(); $select = "SELECT idVertex FROM Vertices WHERE X=:coordinateX and Y=:coordinateY"; $coordinate = $results['Coordinates']; $stmt = $db->prepare($select); $stmt->bindParam("coordinateX", $coordinate[0]); $stmt->bindParam("coordinateY", $coordinate[1]); $stmt->execute(); $vertexId = $stmt->fetchAll(PDO::FETCH_OBJ); if (empty($vertexId)) { $insertVertex = "INSERT INTO Vertices(X, Y) VALUE(:coordinateX, :coordinateY)"; $stmt = $db->prepare($insertVertex); $stmt->bindParam("coordinateX", $coordinate[0]); $stmt->bindParam("coordinateY", $coordinate[1]); $stmt->execute(); $vertexId = $db->lastInsertId(); } else { $vertexId = $vertexId[0]->idVertex; } $insertDirection = "INSERT INTO DirectionTime(direction) VALUE(:direction)"; $stmt = $db->prepare($insertDirection); $stmt->bindParam("direction", $results['Direction']); $stmt->execute(); $directionId = $db->lastInsertId(); foreach ($results['Tests'] as $test) { foreach ($test as $accesspoint) { $selectMac = "SELECT idMac FROM Mac WHERE macAddress=:address"; $stmt = $db->prepare($selectMac); $stmt->bindParam("address", $accesspoint['AccessPoint']); $stmt->execute(); $macId = $stmt->fetchAll(PDO::FETCH_OBJ); if (empty($macId)) { $insertMac = "INSERT INTO Mac(macAddress) VALUE(:address)"; $stmt = $db->prepare($insertMac); $stmt->bindParam("address", $accesspoint['AccessPoint']); $stmt->execute(); $macId = $db->lastInsertId(); } else { $macId = $macId[0]->idMac; } $finalInsert = "INSERT INTO Data(idVertex, idMac, idDirectionTime, strength) VALUE(:vertex, :mac, :direction, :strength)"; $stmt = $db->prepare($finalInsert); $stmt->bindParam("vertex", $vertexId); $stmt->bindParam("mac", $macId); $stmt->bindParam("direction", $directionId); $stmt->bindParam("strength", $accesspoint['SignalStrength']); $stmt->execute(); } } $db = null; } catch (PDOException $e) { echo '{"error":{"text":' . $e->getMessage() . '}}'; } }
/** * Constructor * * Initialize things. * */ function __construct() { if (null == self::$_appInstance) { self::$_appInstance = Slim::getInstance(); } if (null == self::$_dbInstance) { self::$_dbInstance = PDOAdpter::getInstance(); } }
public function __construct($args) { $app = Slim::getInstance(); $this->setApp($app); $modulo = isset($args[0]) ? $args[0] : "Index"; $action = isset($args[1]) ? $args[1] : "Init"; $args = isset($args[2]) ? $args[2] : array(); $seguros = $app->request()->params(); parent::__construct($app, $modulo, $action, $args, $seguros); }
public function translate($name, $appName = 'default') { $slim = Slim::getInstance($appName); if (!$slim->translator) { throw new \Exception('No translator class found.'); } if (!method_exists($slim->translator, 'trans')) { throw new \Exception('No translate method found in translator class.'); } return $slim->translator->trans($name); }
function updateSiteSettings() { $request = Slim::getInstance()->request(); $body = $request->getBody(); $user = json_decode($body); $user->id = 1; unset($user->id); $allinfo['save_data'] = $user; $result = edit(json_encode($allinfo), 'site_settings', 1); $result = '{"type":"success","message":"Updated Succesfully"}'; echo $result; }
/** * Get file by md5 hash * @param <type> $name */ public function createFile() { $request = Slim::getInstance()->request(); $body = $request->post("content"); $tmpname = ilUtil::ilTempnam(); $path = $this->getPath() . '/' . basename($tmpname); $this->writeToFile($body, $path); $return = basename($tmpname); $GLOBALS['ilLog']->write(__METHOD__ . ' Writing to path ' . $path); Slim::getInstance()->response()->header('Content-Type', 'application/json'); Slim::getInstance()->response()->body($return); }
function updateTask($id) { $request = Slim::getInstance()->request(); $data = json_decode($request->getBody()); $test = print_r($data, 1); $conditions = array(); //1. actual_time //2. MOVED assigned to own table //3. billable //4. drupalId //5. created // back to unix $data->created = strtotime($data->created); //6. expected_time //7. id //8. meeting //9. name //__ MOVED notify // this one needs to go off into a side function to manage the other table as needed //10. project_id // On a new load of the page this is object // if the user changes the select list it is array //11. status //12. notes //13. due !empty($data->due) ? $data->due = strtotime($data->due) : ''; // back to unix $test = print_r($data, 1); error_log("Results of Task Update {$test}", 3, '/var/tmp/pmangular.log'); $sql = "UPDATE tasks SET \n\t\t\t\tproject_id=:project_id,\n\t\t\t\tname=:name,\n\t\t\t\tnotes=:notes,\n\t\t\t\tdue=:due,\n\t\t\t\tcreated=:created,\n\t\t\t\texpected_time=:expected_time,\n\t\t\t\tstatus=:status,\n\t\t\t\tmeeting=:meeting,\n\t\t\t\tactual_time=:actual_time,\n\t\t\t\tbillable=:billable\n\t\t\t\tWHERE id=:id"; try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("project_id", $data->project_id); $stmt->bindParam("name", $data->name); // $stmt->bindParam("assigned", $data->assigned); $stmt->bindParam("notes", $data->notes); $stmt->bindParam("due", $data->due); $stmt->bindParam("created", $data->created); $stmt->bindParam("expected_time", $data->expected_time); $stmt->bindParam("status", $data->status); $stmt->bindParam("meeting", $data->meeting); $stmt->bindParam("actual_time", $data->actual_time); $stmt->bindParam("billable", $data->billable); $stmt->bindParam("id", $id); $stmt->execute(); $db = null; echo json_encode($data); } catch (PDOException $e) { echo '{"error":{"text":' . $e->getMessage() . '}}'; } }
public function show($id) { try { $this->article = new Article($id); if ($this->article->isNews()) { $this->render('article/show'); } else { $this->render('article/show_post'); } } catch (fNotFoundException $e) { Slim::getInstance()->notFound(); } }
function UserAction() { $request = Slim::getInstance()->request(); $user = json_decode($request->getBody()); //echo '{"users": ' . json_encode($user) . '}';exit; $token = $user->access_token; //echo '{"error":{"text":"'.$token.'"}}'; exit; if ($user->access_token != "") { $status_token = validate_token($user->access_token); //echo '{"error":{"text":"'.$status_token.'"}}'; exit; if ($status_token == 'valid') { //update_token($user->access_token); //echo '{"error":{"text":"'.$user->cmd.'"}}'; exit; switch ($user->cmd) { case 'user_login': $params = array('username' => $user->username); $get_user = GetvalidUserDetails($params); if ($get_user == null) { echo '{"error": "Username and password is invalid"}'; } else { //echo '{"error":{"text":"'.$get_user.'"}}'; exit; //echo '{"error":{"text":'.json_encode($get_user).'}}'; exit; $hash_password = md5($user->password); // echo '{"error":{"text":"'.$get_user->hash_password.'"}}'; exit; // echo '{"error":{"text":"hi"}}'; // echo '{"error":{"text":"'.$get_user->hash_password.'"}}'; exit; if ($hash_password == $get_user->hash_password) { if ($get_user->is_active == "Y") { echo '{"error":"","apidata": ' . json_encode($get_user) . '}'; } else { echo '{"error": "User is not active"}'; } } else { echo '{"error": "password is invalid"}'; } } exit; break; } //echo '{"error":{"text":'.mc_encrypt($user->password,$user->key).'}}'; echo '{"error":{"text":"Token is valid"}}'; } else { echo '{"error":{"text":"Token is not valid"}}'; } } else { echo '{"error":{"text":"Token is NULL"}}'; } /*$user_details=array( 'password_hash' => mc_encrypt('admin@123','d0a7e7997b6d5fcd55f4b5c32611b87cd923e88837b63bf2941ef819dc8ca282') );*/ }
public function __construct($table = null) { //db connector config $this->_dbUse = Slim::getInstance()->config('database')['default']; $this->_dbConfigs = Slim::getInstance()->config('database')['connections']; //PDOAdapter config $this->_prefix = $this->_dbConfigs[$this->_dbUse]["prefix"]; $this->_debug = $this->_dbConfigs[$this->_dbUse]["true"]; $this->_fetchType = PDO::FETCH_ASSOC; // get db connection manager $this->_connector = MyPDOConnector::getInstance()->loadConfigs($this->_dbConfigs); $this->_cacher = MyPDOCacher::getInstance(); parent::__construct($table); }
protected function __construct() { $memcacheConfig = Slim::getInstance()->config('memcache'); if ($memcacheConfig && isset($memcacheConfig["memcache_namespace"], $memcacheConfig["memcache_server"])) { $memServer = $memcacheConfig["memcache_server"]; $memNamespace = $memcacheConfig["memcache_namespace"]; $this->memObj = new BaseMemcached($memServer, $memNamespace); if ($this->memObj->checkStatus()) { $this->memObj->setDataVersion($this->cachePrefix); } } else { throw new Exception('PDOCacher Memcache initialize error'); } }
function smarty_function_urlFor($params, $template) { $name = isset($params['name']) ? $params['name'] : ''; $appName = isset($params['appname']) ? $params['appname'] : 'default'; $url = Slim::getInstance($appName)->urlFor($name); if (isset($params['options'])) { $options = explode('|', $params['options']); foreach ($options as $option) { list($key, $value) = explode('.', $option); $opts[$key] = $value; } $url = Slim::getInstance($appName)->urlFor($name, $opts); } return $url; }
function addResult() { $request = Slim::getInstance()->request(); $result = json_decode($request->getBody()); /*If the user already exist then only score is updated if not then user is saved to data base*/ if (userExist($result->email)) { updateScore($result->email, $result->score); } else { createUser($result); } /* get the users list for calculating the your position */ $scores = Model::factory('User')->distinct()->select('score')->order_by_desc('score')->find_many(); /* Prepare the response */ $arr = array("topScorer" => getTop(), "yourranking" => getYourRanking($scores, $result->score)); echo json_encode($arr); }
function addNewBlog() { $rarray = array(); $request = Slim::getInstance()->request(); $body = json_decode($request->getBody()); $allinfo['save_data'] = $body; //$allinfo['save_data']['offer_to_date'] = $body->offer_to_date.' 23:59:59'; $save = add(json_encode($allinfo), 'blogs'); if (!empty($save)) { $rarray = array('type' => 'success', 'offers' => $save); } else { $rarray = array('type' => 'error', 'message' => 'Internal error please try again later.'); } echo json_encode($rarray); //echo $result; }
function update($table = null, $id = null) { $request = Slim::getInstance()->request(); $body = json_decode($request->getBody()); $sql = 'UPDATE ' . $table . ' SET name=:name WHERE id=:id'; try { $db = getConnection(); $stamte = $db->prepare($sql); $stamte->bindParam('name', $body->name); $stamte->bindParam('id', $id); $stamte->execute(); $db = null; echo json_encode($body); } catch (PDOException $e) { echo '{"error":' . $e->getMessage() . '}'; } }
function updateCoupon($id) { $request = Slim::getInstance()->request(); $body = $request->getBody(); $coupon = json_decode($body); if (isset($coupon->id)) { unset($coupon->id); } $allinfo['save_data'] = $coupon; $coupon_details = edit(json_encode($allinfo), 'coupons', $id); if (!empty($coupon_details)) { $result = '{"type":"success","message":"Changed Succesfully"}'; } else { $result = '{"type":"error","message":"Not Changed"}'; } echo $result; }
function addUserObj() { global $patrimonio; /* verifica se existe alguma informacao no corpo da mensagem */ $request = Slim::getInstance()->request(); $json = readRequestBody($request); if (!$json) { $response["status"] = 0; echo json_encode($response); return; } /* lendo dados do json */ $appID = $json->appID; $crypt_data = $json->data; $iv = $json->iv; $json = json_decode(decrypt_data($appID, $crypt_data, $iv)); $userId = $json->userId; $objId = $json->objId; $objType = $json->objType; /* the objType doesn't exist */ if (!isset($patrimonio[$objType])) { $response["status"] = 0; echo json_encode($response); return; } $response["status"] = 1; $dbh = getConnection(); $obj = $patrimonio[$objType][0]; $possui = $patrimonio[$objType][1]; try { /* if the ids exist in their tables and are not linked, add a new row */ $sql = "insert into {$possui} select idusuario, id{$obj} from\n\t\t\t\t\tusuario, obj{$obj} where idusuario = :userID and\n\t\t\t\t\t\tid{$obj} = :objID and (select count(*) from {$possui} where\n\t\t\t\t\t\t\tfk_idUser = :userID and fk_id{$obj} = :objID) = 0"; $stmt = $dbh->prepare($sql); $stmt->bindParam(":userID", $userId); $stmt->bindParam(":objID", $objId); $stmt->execute(); } catch (PDOException $e) { /* couldn't insert */ $response["status"] = 0; } closeConnection($dbh); $json = json_encode($response); $data = encrypt_data($appID, $json); echo json_encode($data); return; }