Esempio n. 1
0
 public function store()
 {
     if ($this->getId() != 0) {
         try {
             $stmt = DB::getInstance()->prepare("UPDATE api_keys SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tapi_key = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tobject_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tobject_type = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdescription = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tupdate_date = NOW()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id=?");
             $stmt->execute(array($this->getApiKey(), $this->getObjectId(), $this->getObjectType(), $this->getDescription(), $this->getId()));
             return $stmt->rowCount();
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
     } elseif ($this->getApiKey() != "" and $this->getObjectId() != 0 and $this->getObjectType() != "") {
         $tmp_api_key = new ApiKey(false, $this->getApiKey());
         if (!$tmp_api_key->fetch()) {
             try {
                 $stmt = DB::getInstance()->prepare("INSERT INTO api_keys (api_key, object_id, object_type, description, create_date, update_date)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, NOW(), NOW())");
                 $stmt->execute(array($this->getApiKey(), $this->getObjectId(), $this->getObjectType(), $this->getDescription()));
                 return DB::getInstance()->lastInsertId();
             } catch (PDOException $e) {
                 echo $e->getMessage();
                 echo $e->getTraceAsString();
             }
         }
     }
     return false;
 }
Esempio n. 2
0
<?php

require_once 'runtime.php';
require_once ROOT_DIR . '/lib/core/ApiKeyList.class.php';
require_once ROOT_DIR . '/lib/core/Router.class.php';
require_once ROOT_DIR . '/lib/core/User.class.php';
if ($_GET['section'] == "insert_add") {
    //add new api key
    do {
        $api_key = new ApiKey(false, ApiKey::generateApiKey(), (int) $_GET['object_id'], $_GET['object_type'], $_POST['description']);
        $api_key_id = $api_key->store();
    } while (!$api_key_id);
    $message[] = array("Es wurde ein neuer API-Key " . $api_key->getApiKey() . " generiert und gespeichert.", 1);
    Message::setMessage($message);
    header('Location: ./api_key_list.php?object_id=' . $_GET['object_id'] . '&object_type=' . $_GET['object_type']);
} elseif ($_GET['section'] == "delete") {
    $api_key = new ApiKey((int) $_GET['api_key_id']);
    $api_key->fetch();
    $message[] = array("Der API-Key " . $api_key->getApiKey() . " wurde gelöscht.", 1);
    $api_key->delete();
    Message::setMessage($message);
    header('Location: ./api_key_list.php?object_id=' . $_GET['object_id'] . '&object_type=' . $_GET['object_type']);
}