latitude', '$geocode->longitude')"; $connection->beginTransaction(); $connection->exec($insertaddr); $cq = "select last_insert_id()"; $idres = $connection->query($cq); while($idres->next()) { $addrid = $idres->get(1); } unset($idres); // At least temporary place holder for the image. $modified_image_name = Olio::$config['includes'] . "userphotomissing.gif"; $imagethumb = Olio::$config['includes'] . "userphotomissing.gif"; $insertsql = "insert into PERSON (username, password, firstname, lastname,". " email, telephone, imageurl, imagethumburl, summary,". " timezone,"."ADDRESS_addressid) values('$username', '$pwd',". " '$fname', '$lname', '$email', '$telephone',". " '$modified_image_name', '$imagethumb', '$summary',". " '$timezone', '$addrid')"; $insertresult = $connection->exec($insertsql); $idres = $connection->query($cq); while ($idres->next()) { $userid = $idres->get(1); } } else if (isset($_POST['addpersonsubmitupdate'])) { $connection->beginTransaction(); if ($summary == "" ) { $sumquery = "select summary from PERSON where username='$username' "; $sumresult = $connection->query($sumquery); while ($sumresult->next()) { $summary = $sumresult->get(1); } unset($sumresult); } $insertaddr = "insert into ADDRESS (street1, street2, city, state, zip, country, latitude, longitude) ". "values ('$strt1', '$street2', '$cty', '$state', '$zip', '$country', ". "'$geocode->latitude', '$geocode->longitude')"; $connection->exec($insertaddr); $cq = "select last_insert_id()"; $idres = $connection->query($cq); while($idres->next()) { $addrid = $idres->get(1); } unset($idres); $updatesql ="update PERSON set password='$pwd', firstname='$fname', lastname='$lname', email='$email', telephone='$telephone',"; if ($summary != "") { $updatesql .= " summary='$summary',"; } $updatesql .= " timezone='$timezone', ADDRESS_addressid='$addrid' where username='$username' "; $connection->exec($updatesql); $userid_query = "select userid from PERSON where username='$username'"; $idres = $connection->query($userid_query); while ($idres->next()) { $userid = $idres.get(1); } unset($idres); } // 4. End the DB transaction here. $connection->commit(); if ($image_name != "") { // 5. Determine the image id. $pos=strpos($image_name,'.'); $img_ext = substr($image_name,$pos,strlen($image_name)); $modified_image_name = "P".$userid.$img_ext; $resourcedir = '/tmp/'; $imagethumb = "P".$userid."T".$img_ext; $user_image_location = $resourcedir . $modified_image_name; if (!move_uploaded_file($_FILES['user_image']['tmp_name'], $user_image_location)) { throw new Exception("Error moving uploaded file to $user_image_location"); } // 6. Generate the thumbnails. $thumb_location = $resourcedir . $imagethumb; ImageUtil::createThumb($user_image_location, $thumb_location, 120, 120); // 7. Store the image. $fs = FileSystem::getInstance(); if (!$fs->create($user_image_location, "NO_OP", "NO_OP")) { error_log("Error copying image " . $user_image_location); } if (!$fs->create($thumb_location, "NO_OP", "NO_OP")) { error_log("Error copying thumb " . $thumb_location); } unlink($user_image_location); unlink($thumb_location); // 8. Update the DB. $updateimage = "update PERSON set imageurl = '$modified_image_name', ". "imagethumburl = '$imagethumb' ". "where userid = '$userid'"; $updated = $connection->exec($updateimage); } header("Location:users.php?username=".$username); ?>