function update($f3) { $uuid = $f3->get('REQUEST.uuid'); print_r($f3->get('REQUEST')); if (!empty($uuid)) { $db = new \DB\Jig('db/', \DB\Jig::FORMAT_JSON); $item = new \DB\Jig\Mapper($db, 'units.json'); $item->load(array('@uuid==?', $uuid)); if ($item->dry()) { echo 'New Unit'; } foreach ($f3->get('REQUEST') as $k => $v) { if ($k == "message") { $db_mess = new \DB\Jig('db/', \DB\Jig::FORMAT_JSON); $message = new \DB\Jig\Mapper($db_mess, 'messages.json'); $message->copyFrom('REQUEST.message'); $message->save(); } else { $item->{$k} = $v; } } $item->save(); echo 'Ok !'; } else { echo 'UUID not set.'; } }
public function check_configuration() { $config = new DB\Jig\Mapper($this->db, 'sysconfig.json'); if (!$config->load()) { self::show_error('No config file found', 428); exit; } }
public function check_configuration() { $config = new DB\Jig\Mapper($this->db, 'sysconfig.json'); if (!$config->load()) { echo json_encode(array('message' => 'No config file found')); F3::error(428); exit; } }
function update($f3) { $uuid = $f3->get('REQUEST.uuid'); //print_r($f3->get('REQUEST')); if (!empty($uuid)) { $db = new DB\Jig('db/', DB\Jig::FORMAT_JSON); $item = new DB\Jig\Mapper($db, 'victims'); $item->load(array('@uuid==?', $uuid)); if ($item->dry()) { echo 'New Victim'; } foreach ($f3->get('REQUEST') as $k => $v) { $item->{$k} = $v; } $item->save(); } else { echo 'UUID not set.'; } }
public function put_data($f3, $args) { $table = explode('=', $args[0])[1]; if ($table) { Common::check_permissions('U', $table, $this->token); $params = json_decode($f3->get('BODY')); $records = new \DB\Jig\Mapper($this->db, $table . '.json'); $record = $records->load(['@_id == ?', $args['id']]); foreach ($params as $key => $value) { if (!preg_match('/id/', $key)) { if ($table == 'users') { // users table "special" if ($key == 'userName' && $value && $value != $record[$key]) { Common::check_uniq_value($value, 'users', 'userName'); $record[$key] = $value; } if ($key == 'password' && $value) { $record[$key] = password_hash($value, PASSWORD_DEFAULT); } } else { $record[$key] = $value; } } } $result = $record->update(); if ($table == 'users') { unset($result['password']); } echo json_encode($result); } else { Common::show_error('Table name required', 500); } }