public function call() { $output = array(); $pdo = core\paDB::conn(); if ($this->args['id']) { $old = core\paMain::call(array('module' => 'loadCharacters', 'charID' => $this->args['id'])); if ($old['success']) { $old = $old['results'][0]; } else { throw new core\paException('Failed to load existing character #' . $this->args['id']); } $chquery = $this->charUpdate($pdo); $pdo->query($chquery); $output['id'] = $this->args['id']; $spquery = $this->spriteUpdate($pdo); $pdo->query($spquery); $output['spriteID'] = $this->args['spriteID']; } else { $chquery = $this->charInsert($pdo); $pdo->query($chquery); $output['id'] = $pdo->lastInsertId(); $spquery = $this->spriteInsert($pdo); $pdo->query($spquery); $output['spriteID'] = $pdo->lastInsertId(); } return $output; }
public function call() { $output = array(); $pdo = core\paDB::conn(); $queries = array(); if ($this->args['id']) { $old = core\paMain::call(array('module' => 'loadScenes', 'sceneID' => $this->args['id'])); if ($old['success']) { $old = $old['results'][0]; } else { throw new core\paException('Failed to load existing scene #' . $this->args['id']); } $scquery = $this->sceneUpdate($pdo); $pdo->query($scquery); $output['id'] = $this->args['id']; foreach ($this->args['exits'] as $exit) { if ($this->hasExitId($exit, $old['exits'])) { //exit being saved matches an existing one? $queries[] = $this->exitUpdate($pdo, $exit, $output['id']); //then update it } else { //otherwise insert it. $queries[] = $this->exitInsert($pdo, $exit, $this->args['id']); } } foreach ($old['exits'] as $oexit) { if (!$this->hasExitId($oexit, $this->args['exits'])) { //existing exit isn't in the exit list being saved? $queries[] = $this->exitDelete($pdo, $oexit, $output['id']); //then delete it. } } } else { $scquery = $this->sceneInsert($pdo); $pdo->query($scquery); $output['id'] = $pdo->lastInsertId(); foreach ($this->args['exits'] as $exit) { $queries[] = $this->exitInsert($pdo, $exit, $output['id']); } } foreach ($queries as $query) { try { if ($query) { $pdo->query($query); } } catch (\Exception $e) { print "Error with query"; die; } } return $output; }
<?php /** * Generic PHP entry point for AJAX calls. * Outputs JSON encoded version of output array. * Required input in $_POST / $_GET: * @param module string The requested ajax class. * All other request args are passed into the class as arguments. */ use sdcAdventure\core; require_once "pasetup.php"; $ajaxOutput = core\paMain::call(array_merge($_POST, $_GET)); print json_encode($ajaxOutput); exit;