executeWithoutParams( $sql ); } /** * Hook to store data to database which is sent as post * method from the forms in this plugin * It also calls the local hook */ function api_key_management_hook_store_db() { global $var_set; global $return_set; // if the form been submited move forward if ( @hook_validate( $_POST['gen_key'] ) ) { // local hook to validate the POST variables hook_variables(); // if validation successfull move forward if ( $return_set['gen_key_validate'] == 'true' && $_GET['plugin_action'] == 'generate_key' ) { // this part generated the access token include 'generate_key.php'; $var_set['AccessToken'] = generate_key :: randomToken( 56, false, true, false ); // database connection $db = new DBLayer( 'lib' ); // insert the form data to the database $db -> insert( 'ams_api_keys', $var_set ); // redirect to the the main page with success code // 1 refers to the successfull addition of key to the database header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=1" ); throw new SystemExit(); } } } /** * Global Hook to load the data from db and set it * into the global array to return it to the template */ function api_key_management_hook_load_db() { global $var_set; global $return_set; $dbl = new DBLayer("lib"); if ( isset( $_SESSION['user'] ) ) { // returns the registered keys $sth = $dbl -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' ); $row = $sth -> fetchAll(); $return_set['api_keys'] = $row; // fetch the character from the array to compare $com = array_column( $return_set['api_keys'], 'UserCharacter' ); // returns the characters with respect to the user id in the ring_tool->characters try { $dbl = new DBLayer( 'ring' ); $sth = $dbl -> selectWithParameter( 'char_name', 'characters' , array(), '1' ); $row = $sth -> fetch(); // loop through the character list and remove the character if already have an api key $return_set['characters'] = array_diff( $row, $com ); }catch( PDOException $e ) { error_log($e->getMessage()); } } } /** * Global Hook to update or delete the data from db */ function api_key_management_hook_update_db() { global $var_set; global $return_set; $db = new DBLayer( 'lib' ); if ( isset( $_GET['delete_id'] ) ) { // removes the registered key using get variable which contains the id of the registered key $db -> delete( 'ams_api_keys', array( 'SNo' => $_GET['delete_id'] ), 'SNo = :SNo' ); // redirecting to the API_key_management plugins template with success code // 2 refers to the succssfull delete condition header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" ); throw new SystemExit(); } } /** * Global Hook to return global variables which contains * the content to use in the smarty templates * * @return $return_set global array returns the template data */ function api_key_management_hook_return_global() { global $return_set; return $return_set; }