$query->execute(array(':userid' => (string) $fields['userid'], ':secret' => (string) $fields['secret'])); $result = $query->fetchAll(PDO::FETCH_ASSOC); if (empty($result)) { exit('Invalid userid' . "\n"); } $fields['userid'] = $result[0]['userid']; // Insert the thesis summary statistics $query = $db->prepare('INSERT INTO summary VALUES(:userid, :date, :pages, :citations)'); $query->execute(array(':userid' => (string) $fields['userid'], ':date' => (int) $fields['date'], ':pages' => (int) $fields['pages'], ':citations' => (int) $fields['references'])); // Insert chapter (and total) summary statistics $query = $db->prepare('INSERT INTO chapters VALUES(:userid, :date, :chapter, :unique_words, :total_words, :total_headers, :total_floats, :common_words)'); foreach ($fields['chapters'] as $chapter => $data) { $query->execute(array(':userid' => (string) $fields['userid'], ':date' => (int) $fields['date'], ':chapter' => (string) $chapter, ':unique_words' => (int) $data['unique_words'], ':total_words' => (int) $data['total_words'], ':total_headers' => (int) $data['total_headers'], ':total_floats' => (int) $data['total_floats'], ':common_words' => (string) words_encode($data['common_words']))); } // Insert overall thesis status $query = $db->prepare('INSERT INTO status VALUES(:userid, :date, :position, :level, :title, :state, :weight, :parent_position)'); foreach ($fields['status'] as $position => $data) { // Temp, for old scripts which don't have weighting if (!isset($data['weight'])) { $data['weight'] = $data['include'] ? 1 : 0; } $query->execute(array(':userid' => (string) $fields['userid'], ':date' => (int) $fields['date'], ':position' => (int) $position, ':level' => (int) $data['level'], ':title' => (string) $data['title'], ':state' => (string) $data['state'], ':weight' => (int) $data['weight'], ':parent_position' => (int) $data['parent_idx'] === -1 ? null : $data['parent_idx'])); } $db->commit(); require 'inc/cache.php'; // Generate json cache pre_cache_setup($fields['userid']); generate_all($fields['userid']); } catch (PDOException $e) { exit('Database error: ' . $e->getMessage() . "\n"); }
<?php require_once 'inc/config.php'; require_once 'inc/cache.php'; $userid = empty($_GET['userid']) ? null : trim($_GET['userid']); try { $db = new PDO(DB_DSN, DB_USER, DB_PASS); $query = $db->prepare('SELECT userid FROM users WHERE userid = :userid'); $query->execute(array(':userid' => $userid)); $result = $query->fetchAll(PDO::FETCH_ASSOC); if (empty($result)) { exit('Invalid userid' . "\n"); } $userid = $result[0]['userid']; } catch (PDOException $e) { exit('Database error: ' . $e->getMessage() . "\n"); } if (!userid_has_cachedir($userid)) { pre_cache_setup($userid); generate_all($userid); }