function saveTags($tag, $table, $id, $group, $personId, $type, $link) { $database = cbSQLConnect::connect('object'); if (isset($database)) { $fields = array(); $fields['name'] = $tag; $fields['ftable'] = $table; $fields['fid'] = $id; $fields['category'] = $group; $fields['personid'] = $personId > 0 ? $personId : -1; $fields['type'] = $type; // return data // return $fields; $insert = $database->SQLInsert($fields, "tags"); // return true if sucess or false if ($insert && $personId > 0) { $person = Person::getById($personId); $person = recast("Person", $person); $message = ' <html> <head> <title>Recent upload to a person on your watch list.</title> </head> <body> <p>Something has been uploaded for ' . $person->displayName() . '</p> <p>Click <a href="' . $link . '">HERE</a> to view the new document, or go to their page to view new content <a href="/?controller=individual&action=homepage&id=' . $person->id . '">HERE</a></p> <br/> <p>Thank you for your continued membership!</p> <br/> <p>Sincerely</p> <p>-The Familyhistorydatabase crew</p> </body> </html> '; Favorites::sendUpdate($personId, $message); return $insert; } else { return "Insert didn't compute"; } } }
function handleIndividualAPI($args, $that) { $session = mySession::getInstance(); if ($that->method === 'GET') { if ($that->verb === '') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { $person->appendNames(); $person->birth = Birth::getById($id); if ($person->birth) { $person->birth->birthPlace = Place::getById($person->birth->place); } $person->death = Death::getById($id); if ($person->death) { $person->death->deathPlace = Place::getById($person->death->place); } $person->burial = Burial::getById($id); if ($person->burial) { $person->burial->burialPlace = Place::getById($person->burial->place); } $person->parents = Parents::getParentsOf($id); $person->children = Parents::getChildrenOf($id); $person->spouse = Spouse::getById($id); $person->profilePicture = File::getById($person->profile_pic); return $person; } else { return false; } } else { return false; } } } else { if ($that->verb === 'submissions') { $user = User::current_user(); $submissions = Person::getSubmissions($user); return $submissions; } else { if ($that->verb === 'allSubmissions' && $session->isAdmin()) { $submissions = Person::getSubmissions(); return $submissions; } else { if ($that->verb === 'children') { if (count($args) > 2 || count($args) < 2) { return array(); } else { $id = intval(array_shift($args)); $spouseid = intval(array_shift($args)); if ($id && is_numeric($id) && $spouseid && is_numeric($spouseid)) { $children = Person::getChildrenByParents($id, $spouseid); $result = array(); if ($children && is_array($children) && count($children)) { foreach ($children as $child) { $person = Person::getById($child->child); $person->appendNames(); $person->profilePicture = File::getById($person->profile_pic); $result[] = $person; } } return $result; } else { return array(); } } } else { if ($that->verb === 'families') { if (!empty($args)) { $letter = array_shift($args); } else { $letter = 'a'; } $all = array_shift($args); $all = $all === "true" ? true : false; $names = array(); $families = Person::getLastNames($letter, $all); if ($families) { foreach ($families as $key) { $names[] = $key['lastName']; } } return $names; } else { if ($that->verb === 'family') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $person = Person::getById($id); $person->appendNames(); $family = new stdClass(); $family->self = $person; $family->parents = array(); // $family->siblings = array(); $children = $person->getChildren(); $family->children = array(); foreach ($children as $child) { $temp = Person::getById($child->child); $temp->appendNames(); $family->children[] = $temp; } $spouses = $person->getSpouse(); $family->spouses = array(); foreach ($spouses as $spouse) { $temp = Person::getById($spouse->spouse); $temp->appendNames(); $family->spouses[] = $temp; } $siblings = array(); $tempsiblings = array(); $person->getParentsGen(4); $family->parents = $person->parents; // foreach ($parents as $key) { // $parent = Person::getById($key->parentId); // $parent->appendNames(); // $family->parents[] = $parent; // // $siblings[] = $parent->getChildren(); // } // foreach ($siblings as $sibling) { // foreach ($sibling as $key) { // $test = true; // foreach ($tempsiblings as $value) { // if ($key->child === $value->child) { // $test = false; // } // } // if ($test) { // $tempsiblings[] = $key; // } // } // } // foreach ($tempsiblings as $sibling) { // if ($sibling->child !== $person->id) { // $family->siblings[] = Person::getById($sibling->child); // } // } // foreach ($family->parents as $parent) { // $grandparents = $parent->getParents(); // foreach ($grandparents as $grandparent) { // $temp = Person::getById($grandparent->parentId); // $temp->child = $parent->id; // $temp->appendNames(); // $family->grandParents[] = $temp; // } // } // foreach ($family->grandParents as $parent) { // $grandparents = $parent->getParents(); // foreach ($grandparents as $grandparent) { // $temp = Person::getById($grandparent->parentId); // $temp->child = $parent->id; // $temp->appendNames(); // $family->greatGrandParents[] = $temp; // } // } // foreach ($family->greatGrandParents as $parent) { // $grandparents = $parent->getParents(); // foreach ($grandparents as $grandparent) { // $temp = Person::getById($grandparent->parentId); // $temp->child = $parent->id; // $temp->appendNames(); // $family->greatGreatGrandParents[] = $temp; // } // } return $family; } else { return new stdClass(); } } else { if ($that->verb === 'familyNames') { if (!empty($args)) { $lastName = array_shift($args); } else { $lastName = 'Law'; } $all = array_shift($args); $all = $all === "true" ? true : false; $names = array(); $user = User::current_user(); $familyNames = Person::getFirstNames($lastName, $all, $user); if ($familyNames) { foreach ($familyNames as $key) { $key = recast('Person', arrayToObject($key)); $key->appendNames(); $names[] = $key; } } return $names; } else { if ($that->verb === 'pictures') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { return File::getByInd($person->id, 'image'); } } } else { return false; } } else { if ($that->verb === 'documents') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { return File::getByInd($person->id, 'document'); } } } else { return false; } } } } } } } } } } // } else { // return false; // } } else { if ($that->method === 'DELETE' && $session->isLoggedIn() && $session->isAdmin()) { // } else if ($that->method === 'DELETE'){ $id = intval($args[0]); if (is_numeric($id)) { $person = Person::getById($id); if ($person) { $birth = Birth::getById($id); if ($birth) { $birth = recast('Birth', $birth); $birth->delete(); //delete } $death = Death::getById($id); if ($death) { $death = recast('Death', $death); $death->delete(); //delete } $burial = Burial::getById($id); if ($burial) { $burial = recast('Burial', $burial); $burial->delete(); //delete } $parents = Parents::getParentsOf($id); if ($parents) { foreach ($parents as $parent) { $parent = recast('Parents', $parent); $parent->delete(); //delete $parent } } $children = Parents::getChildrenOf($id); if ($children) { foreach ($children as $child) { $child = recast('Parents', $child); $child->delete(); //delete $child } } $mySpouse = Spouse::getById($id); if ($mySpouse) { foreach ($mySpouse as $spouse) { $spouse = recast('Spouse', $spouse); $theirSpouse = Spouse::getById($spouse->personId); if ($theirSpouse) { foreach ($theirSpouse as $otherSpouse) { $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); //delete $otherSpouse } } $spouse->delete(); //delete $spouse } } $tags = Tag::getByIndId($id); if ($tags) { foreach ($tags as $tag) { $tag = recast('Tag', $tag); $tag->delete(); } } $person->delete(); return true; } else { return true; } } return false; } else { if (($that->method === 'POST' || $that->method === 'PUT') && $session->isLoggedIn()) { $user = User::current_user(); if (!$user->id) { return false; } $result = $that->file; if (empty($result) || empty($result->person) || empty($result->birth) || empty($result->death)) { return 'we failed on check1'; return false; } // return $result; $person = recast('Person', $result->person); if ($person->id) { $tempPerson = Person::getById($person->id); $person->submitter = $tempPerson->submitter; $person->status = $tempPerson->status; if ($person->submitter !== $user->id && !($user->rights === 'super' || $user->rights === 'admin')) { return 'we failed on check2'; return false; } } if (!empty($person)) { $personId = $person->save($user); } else { return false; } if (!!$personId) { $person->id = $personId; $birth = recast('Birth', $result->birth); $birth->personId = $personId; $birthId = $birth->save(); $birth->id = $birthId; $death = recast('Death', $result->death); $death->personId = $personId; $deathId = $death->save(); $death->id = $deathId; if ($result->burial) { $burial = recast('Burial', $result->burial); $burial->personId = $personId; $burialId = $burial->save(); $burial->id = $burialId; } else { $burial = false; } if (empty($personId) || empty($birthId) || empty($deathId)) { return 'test'; return false; } if ($result->birthPlace) { $birthPlace = recast('Place', $result->birthPlace); $birthPlace->ft_name = "birth"; $birthPlace->fkey = $birthId; $birth->place = $birthPlace->save(); $birth->save(); } else { $birth->place = null; $birth->save(); } if ($result->deathPlace) { $deathPlace = recast('Place', $result->deathPlace); $deathPlace->ft_name = "death"; $deathPlace->fkey = $deathId; $death->place = $deathPlace->save(); $death->save(); } else { $death->place = null; $death->save(); } if ($burial) { if ($result->burialPlace) { $burialPlace = recast('Place', $result->burialPlace); $burialPlace->ft_name = "burial"; $burialPlace->fkey = $burial->id; $burial->place = $burialPlace->save(); $burial->save(); } else { $burial->place = null; $burial->save(); } } else { $burial = Burial::getById($person->id); if ($burial && $burial->id) { $burial = recast('Burial', $burial); $burial->delete(); } } if ($result->parents) { if ($person->id) { $parents = Parents::getParentsOf($person->id); if ($parents) { $missing = array(); foreach ($parents as $parent) { if (!objectListContains($result->parents, 'id', $parent->parentId)) { $missing[] = $parent; } } foreach ($missing as $parent) { $parent = recast('Parents', $parent); $parent->delete(); } foreach ($result->parents as $key) { if (!objectListContains($parents, 'parentId', $key->id)) { $newPadre = new Parents(); $newPadre->child = $person->id; $newPadre->gender = $key->sex === 'male' ? 'father' : 'mother'; $newPadre->parentId = $key->id; $newPadre->save(); } } } else { foreach ($result->parents as $key) { $newPadre = new Parents(); $newPadre->child = $person->id; $newPadre->gender = $key->sex === 'male' ? 'father' : 'mother'; $newPadre->parentId = $key->id; $newPadre->save(); } } } else { return 'We have an error'; } } else { $parents = Parents::getParentsOf($person->id); if ($parents) { foreach ($parents as $parent) { $parent = recast('Parents', $parent); $parent->delete(); } } } if ($result->spouse) { $spouses = Spouse::getAllSpousesById($person->id); if ($spouses) { $missing = array(); foreach ($spouses as $spouse) { if (!objectListContains($result->spouse, 'id', $spouse->spouse)) { $missing[] = $spouse; } } foreach ($missing as $spouse) { $spouse = recast('Spouse', $spouse); $place = Place::getById($spouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = Spouse::getByPair($spouse->personId, $spouse->spouse); if ($otherSpouse) { $place = Place::getById($otherSpouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); } $spouse->delete(); } foreach ($result->spouse as $spouse) { if (!objectListContains($spouses, 'spouse', $spouse->id)) { Spouse::addSpouse($spouse, $person->id, $spouse->id); Spouse::addSpouse($spouse, $spouse->id, $person->id); } else { Spouse::updateSpouse($spouse, $spouse->id, $person->id); Spouse::updateSpouse($spouse, $person->id, $spouse->id); } } } else { foreach ($result->spouse as $spouse) { Spouse::addSpouse($spouse, $person->id, $spouse->id); Spouse::addSpouse($spouse, $spouse->id, $person->id); } } } else { $spouses = Spouse::getAllSpousesById($person->id); if ($spouses) { foreach ($spouses as $spouse) { $spouse = recast('Spouse', $spouse); $place = Place::getById($spouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = Spouse::getByPair($spouse->personId, $spouse->spouse); if ($otherSpouse) { $place = Place::getById($otherSpouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); } $spouse->delete(); } } } return $person; } return false; } else { return "Only accepts POST and GET requests"; } } } }
if ($action = 'getFilteredData') { // error_reporting(E_ALL); // ini_set('display_errors', '1'); $database = cbSQLConnect::connect('array'); $search_query = getRequest("key"); $search_result_data = array(); $search_result_tags = array(); $results = array(); if (isset($database) && !empty($search_query)) { $data = $database->QuerySingle("SELECT *, MATCH(title, author, comments) AGAINST('" . $search_query . "*' IN BOOLEAN MODE) AS score FROM `file` WHERE MATCH(title, author, comments) AGAINST('" . $search_query . "*' IN BOOLEAN MODE) ORDER BY score DESC"); //$results[] = $data; if (count($data) == 0) { //echo "Search found nothing in File\n"; } else { foreach ($data as $instance) { $temp = recast("File", arrayToObject($instance)); if ($temp->comments !== null) { $results[] = $temp->comments; } if ($temp->title != null) { $results[] = $temp->title; } if ($temp->author != null) { $results[] = $temp->author; } } } unset($data); $data = $database->QuerySingle("SELECT *, MATCH(name) AGAINST('" . $search_query . "*' IN BOOLEAN MODE) AS score FROM `tags` WHERE MATCH(name) AGAINST('" . $search_query . "*' IN BOOLEAN MODE) ORDER BY score DESC"); //$results[] = $data; if (count($data) == 0) {
protected function create() { if (empty($this->newName) || empty($this->file)) { return false; } // return $this; // error_reporting(E_ALL); // ini_set('display_errors', '1'); // echo "<pre>"; // print_r($files); // echo "</pre>"; // echo "<pre>"; // print_r($data); // echo "</pre>"; if (isset($this->tags)) { $person = isset($this->tags->person) ? $this->tags->person : array(); $other = isset($this->tags->other) ? $this->tags->other : array(); $place = isset($this->tags->place) ? $this->tags->place : array(); } $title = isset($this->title) ? $this->title : "No Title"; $author = isset($this->author) ? $this->author : "Unknown"; $comments = $this->description; $newname = $this->newName; $split = explode(".", $this->file->name); $extension = end($split); $savename = $newname . "." . $extension; $link = UPLOAD . "{$savename}"; $temp = File::getByLink($link); // return $temp; if (!$temp) { // return UPLOAD.$savename; $file_path = "upload/" . $savename; if (file_exists($file_path)) { clearstatcache(); //the file already exists return -1; } if ($this->file->error > 0) { //there was an error uploading the file return -2; } else { $result = array(); if (move_uploaded_file($this->file->tmp_name, IMAGEPATH . $link)) { if ($this->file->type == "image/gif" || $this->file->type == "image/jpeg" || $this->file->type == "image/jpg" || $this->file->type == "image/bmp" || $this->file->type == "image/png") { $im = File::thumbnail(IMAGEPATH . $link, 75); $im2 = File::thumbnail(IMAGEPATH . $link, 800); $view_link = UPLOAD . "view/" . $newname . " view." . $extension; $temp_thumblink = UPLOAD . "thumbs/" . $newname . " thumbnail." . $extension; if ($im && $im2) { $imageMade = File::imageToFile($im, IMAGEPATH . $temp_thumblink); if ($imageMade) { $viewMade = File::imageToFile($im2, IMAGEPATH . $view_link); if (!$viewMade) { unlink($link); return -6; } } else { unlink($temp_thumblink); unlink($link); return -6; } } else { unlink($link); return -6; } $type = $this->docType; } else { $view_link = null; $temp_thumblink = "changeMeToDocThumb"; $type = "other"; } $result[] = "Stored in: " . "upload/" . $savename; $init = new File(); $init->id = null; $init->link = $link; $init->thumblink = $temp_thumblink; $init->viewlink = $view_link; $init->title = $title ? $title : "Untitled"; $init->author = $author; $init->comments = $comments; $init->date = null; $init->type = $this->docType; $init_id = $init->save(); if ($init_id) { if (isset($this->tags) && !empty($this->tags)) { foreach ($this->tags as $key => $value) { if ($key === 'person') { foreach ($value as $person) { $tag = new Tag(); $tag->enum = 'person'; $tag->fileid = $init_id; $tag->foreignid = $person->id; $tag->save(); } } else { if ($key === 'place') { foreach ($value as $place) { $tag = new Tag(); $tag->enum = 'place'; $tag->foreignid = false; $tempPlace = Place::getByAll($place); if ($tempPlace) { $tag->foreignid = $tempPlace->id; } else { $tempPlace = recast('Place', $place); $tpId = $tempPlace->save(); if ($tpId) { $tag->foreignid = $tpId; } } if ($tag->foreignid) { $tag->fileid = $init_id; $tag->save(); } } } else { if ($key === 'other') { foreach ($value as $tag) { $tag = recast('Tag', $tag); if ($tag) { $tag->fileid = $init_id; $tag->enum = 'other'; $tag->id = NULL; $tag->save(); } } } } } } } return 1; } else { unlink($temp_thumblink); unlink($link); //database connection wasn't saved return -4; } } else { //file wasn't moved return -3; } } } //the database entry already exists return -5; // save file }
/** * Recasts a {@link SObject} to its associated {@link StorablePrimitive} class and returns the new object. * @param ref object $primitive * @param string $type The type of data contained in the primitive (ie, "integer" or "string") * @access public * @return ref object */ function recastAsStorablePrimitive($primitive, $type) { $type = strtolower($type); $class = strtolower(get_class($primitive)); if (!isset($this->_registeredTypes[$type]) || strtolower($this->_registeredTypes[$type]["primitive"]) != $class) { // this means that either we can't do anything with this primitive (we dont' know it) or // it's already a storable. return $primitive; } $newClass = $this->_registeredTypes[$type]["storable"]; $newObj = recast($primitive, $newClass); // now call the constructor in case any setup has to be done. // ----> i (gabe) am not sure why this is here. it is intefering // with re-casting and retaining values, so it cannot be used. // if (method_exists($newObj, $newClass)) $newObj->$newClass(); return $newObj; }
public static function getByFileId($id = NULL) { if ($id) { $database = cbSQLConnect::connect('object'); if (isset($database)) { $query = "SELECT * FROM `tag` WHERE `fileid`=" . $id; $result = $database->QuerySingle($query); $tags = array(); $tags['person'] = array(); $tags['place'] = array(); $tags['other'] = array(); foreach ($result as $tag) { if ($tag->enum === 'person') { $tempPerson = Person::getById($tag->foreignid); if ($tempPerson) { $tempPerson->text = $tempPerson->selectName() . " (" . $tempPerson->yearBorn . ")"; $tags['person'][] = $tempPerson; } } else { if ($tag->enum === 'place') { $place = Place::getById($tag->foreignid); if ($place) { $place = recast('Place', $place); $place->text = $place->getTypeaheadName(); $tags['place'][] = $place; } } else { $tags['other'][] = $tag; } } } return $tags; } } else { return NULL; } }
public static function createInstance($parentId = NULL, $gender = NULL, $child = NULL) { $temp = Parents::getByField($parentId, $child); // return $temp; if (!$temp) { $init = new Parents(); $init->id = null; $init->parentId = $parentId; if ($gender == 'male') { $init->gender = 'father'; } else { $init->gender = 'mother'; } $init->child = $child; return $init; } else { $temp->parentId = $parentId; if ($gender == 'male') { $temp->gender = 'father'; } else { $temp->gender = 'mother'; } $temp->child = $child; } $init = recast('Parents', $temp); return $init; }
public static function createInstance($t1_name = NULL, $t2_name = NULL, $t1_id = NULL, $t2_id = NULL) { $temp = Connections::getByField($t1_name, $t1_id); // return $temp; if (!$temp) { $flag = true; foreach ($temp as $item) { if ($item->t2_name == $t2_name && $item->t2_id == $t2_id) { $flag = false; $found = $item; } } if ($flag) { $init = new Connections(); $init->id = null; $init->t1_name = $t1_name; $init->t2_name = $t2_name; $init->t1_id = $t1_id; $init->t2_id = $t2_id; $init->save(); return $init; } } $init = recast('Connections', $found); return $init; }
$object->id = $object_id; } return $object; } function getPlaceInfo($data, $ft_name, $key, $test) { $object_id = Place::getSomething('id', $ft_name, $key); $object = Place::createInstance($data); if ($test == "New Individual") { $temp_id = $object->save(); $object->id = $temp_id; } else { $object->id = $object_id; } return $object; } if ($session->isLoggedIn()) { $user = User::current_user(); $user = recast('User', $user); if ($user->rights == "super") { $session->save("content", "admin/admin.php"); include_page('home.php'); } else { $session->save("content", "home.php"); include_page('home.php'); } } else { $session->save("content", "home.php"); include_page('home.php'); } exit;
public function delete() { $database = cbSQLConnect::adminConnect('object'); if (isset($database)) { $tags = $this->getTagListById($this->id); foreach ($tags as $tag) { $temp = recast('Tag', $tag); $temp->delete(); } return $database->SQLDelete(self::$table_name, 'id', $this->id); } }
function doInd($that, $args) { $that = recast('MyAPI', $that); $session = mySession::getInstance(); if ($that->method === 'GET') { if ($that->verb === '') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { $person->appendNames(); $person->birth = Birth::getById($id); if ($person->birth) { $person->birth->birthPlace = Place::getById($person->birth->place); } $person->death = Death::getById($id); if ($person->death) { $person->death->deathPlace = Place::getById($person->death->place); } $person->burial = Burial::getById($id); if ($person->burial) { $person->burial->burialPlace = Place::getById($person->burial->place); } $person->parents = Parents::getParentsOf($id); $person->children = Parents::getChildrenOf($id); $person->spouse = Spouse::getById($id); return $person; } else { return false; } } else { return false; } } } else { if ($that->verb === 'families') { if (!empty($args)) { $letter = array_shift($args); } else { $letter = 'a'; } $names = array(); $families = Person::getLastNames($letter); if ($families) { foreach ($families as $key) { $names[] = $key['lastName']; } } return $names; } else { if ($that->verb === 'familyNames') { if (!empty($args)) { $lastName = array_shift($args); } else { $lastName = 'Law'; } $names = array(); $familyNames = Person::getFirstNames($lastName); if ($familyNames) { foreach ($familyNames as $key) { $key = recast('Person', arrayToObject($key)); $key->appendNames(); $names[] = $key; } } return $names; } } } } else { if ($that->method === 'DELETE' && $session->isLoggedIn() && $session->isAdmin()) { $id = intval($args[0]); if (is_numeric($id)) { $person = Person::getById($id); if ($person) { $birth = Birth::getById($id); if ($birth) { $birth = recast('Birth', $birth); $birth->delete(); //delete } $death = Death::getById($id); if ($death) { $death = recast('Death', $death); $death->delete(); //delete } $burial = Burial::getById($id); if ($burial) { $burial = recast('Burial', $burial); $burial->delete(); //delete } $parents = Parents::getParentsOf($id); if ($parents) { foreach ($parents as $parent) { $parent = recast('Parents', $parent); $parent->delete(); //delete $parent } } $children = Parents::getChildrenOf($id); if ($children) { foreach ($children as $child) { $child = recast('Parents', $child); $child->delete(); //delete $child } } $mySpouse = Spouse::getById($id); if ($mySpouse) { foreach ($mySpouse as $spouse) { $spouse = recast('Spouse', $spouse); $theirSpouse = Spouse::getById($spouse->personId); if ($theirSpouse) { foreach ($theirSpouse as $otherSpouse) { $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); //delete $otherSpouse } } $spouse->delete(); //delete $spouse } } $tags = Tag::getByIndId($id); if ($tags) { foreach ($tags as $tag) { $tag = recast('Tag', $tag); $tag->delete(); } } $person->delete(); return true; } else { return true; } } return false; } else { if (($that->method === 'POST' || $that->method === 'PUT') && $session->isLoggedIn() && $session->isAdmin()) { $result = $that->file; if (empty($result) || empty($result->person) || empty($result->birth) || empty($result->death)) { return false; } // return $result; $person = recast('Person', $result->person); if (!empty($person)) { $personId = $person->save(); } else { return false; } if ($personId) { $person->id = $personId; $birth = recast('Birth', $result->birth); $birth->personId = $personId; $birthId = $birth->save(); $birth->id = $birthId; $death = recast('Death', $result->death); $death->personId = $personId; $deathId = $death->save(); $death->id = $deathId; if ($result->burial) { $burial = recast('Burial', $result->burial); $burial->personId = $personId; $burialId = $burial->save(); $burial->id = $burialId; } else { $burial = false; } if (empty($personId) || empty($birthId) || empty($deathId)) { return false; } if ($result->birthPlace) { $birthPlace = recast('Place', $result->birthPlace); $birthPlace->ft_name = "birth"; $birthPlace->fkey = $birthId; $birth->place = $birthPlace->save(); $birth->save(); } else { if ($birth && $birth->birthPlace) { $birthPlace = Place::getById($birth->birthPlace->id); if ($birthPlace) { $birthPlace = recast('Place', $birthPlace); if ($birthPlace) { $birthPlace->delete(); } } } $birthPlace = null; } if ($result->deathPlace) { $deathPlace = recast('Place', $result->deathPlace); $deathPlace->ft_name = "death"; $deathPlace->fkey = $deathId; $death->place = $deathPlace->save(); $death->save(); } else { $deathPlace = Place::getById($death->deathPlace->id); if ($death && $death->deathPlace) { $deathPlace = recast('Place', Place::getById($death->deathPlace->id)); if ($deathPlace) { $deathPlace->delete(); } } $deathPlace = null; } if ($burial) { if ($result->burialPlace) { $burialPlace = recast('Place', $result->burialPlace); $burialPlace->ft_name = "burial"; $burialPlace->fkey = $burial->id; $burial->place = $burialPlace->save(); $burial->save(); } else { $burialPlace = Place::getById($burial->place); if ($burial && $burialPlace) { $burialPlace = recast('Place', Place::getById($burial->place)); if ($burialPlace) { $burialPlace->delete(); } } } } else { $burial = Burial::getById($person->id); if ($burial && $burial->id) { $burial = recast('Burial', $burial); $burialPlace = Place::getById($burial->place); if ($burialPlace) { $burialPlace = recast('Place', Place::getById($burial->place)); if ($burialPlace) { $burialPlace->delete(); } } $burial->delete(); } } if ($result->parents) { if ($person->id) { $parents = Parents::getParentsOf($person->id); if ($parents) { $missing = array(); foreach ($parents as $parent) { if (!objectListContains($result->parents, 'id', $parent->parentId)) { $missing[] = $parent; } } foreach ($missing as $parent) { $parent = recast('Parents', $parent); $parent->delete(); } foreach ($result->parents as $key) { if (!objectListContains($parents, 'parentId', $key->id)) { $newPadre = new Parents(); $newPadre->child = $person->id; $newPadre->gender = $key->sex === 'male' ? 'father' : 'mother'; $newPadre->parentId = $key->id; $newPadre->save(); } } } else { foreach ($result->parents as $key) { $newPadre = new Parents(); $newPadre->child = $person->id; $newPadre->gender = $key->sex === 'male' ? 'father' : 'mother'; $newPadre->parentId = $key->id; $newPadre->save(); } } } else { return 'We have an error'; } } else { $parents = Parents::getParentsOf($person->id); if ($parents) { foreach ($parents as $parent) { $parent = recast('Parents', $parent); $parent->delete(); } } } if ($result->spouse) { $spouses = Spouse::getAllSpousesById($person->id); if ($spouses) { $missing = array(); foreach ($spouses as $spouse) { if (!objectListContains($result->spouse, 'id', $spouse->spouse)) { $missing[] = $spouse; } } foreach ($missing as $spouse) { $spouse = recast('Spouse', $spouse); $place = Place::getById($spouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = Spouse::getByPair($spouse->personId, $spouse->spouse); if ($otherSpouse) { $place = Place::getById($otherSpouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); } $spouse->delete(); } foreach ($result->spouse as $spouse) { if (!objectListContains($spouses, 'spouse', $spouse->id)) { Spouse::addSpouse($spouse, $person->id, $spouse->id); Spouse::addSpouse($spouse, $spouse->id, $person->id); } else { Spouse::updateSpouse($spouse, $spouse->id, $person->id); Spouse::updateSpouse($spouse, $person->id, $spouse->id); } } } else { foreach ($result->spouse as $spouse) { Spouse::addSpouse($spouse, $person->id, $spouse->id); Spouse::addSpouse($spouse, $spouse->id, $person->id); } } } else { $spouses = Spouse::getAllSpousesById($person->id); if ($spouses) { foreach ($spouses as $spouse) { $spouse = recast('Spouse', $spouse); $place = Place::getById($spouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = Spouse::getByPair($spouse->personId, $spouse->spouse); if ($otherSpouse) { $place = Place::getById($otherSpouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); } $spouse->delete(); } } } return true; } return false; } else { return "Only accepts POST and GET requests"; } } } }
public static function createInstance($individual = NULL, $spouse = NULL, $date = NULL, $dateoveride = NULL) { $temp = Spouse::getByField($spouse, $individual); if (!$temp) { $init = new Spouse(); $init->id = NULL; $init->place = NULL; } else { $init = $temp; } $init->spouse = $spouse; $init->personId = $individual; if ($date) { $date = explode("/", $date); $init->year = $date[2]; $init->month = $date[1]; $init->day = $date[0]; if ($date_overide == 'true') { $init->yearM = false; } else { $init->yearM = true; } } if ($temp) { $response = recast('Spouse', $init); } else { $response = $init; } return $response; }
public static function getByUsername($username = null) { $database = cbSQLConnect::connect('object'); if (isset($database)) { $sql = "SELECT * "; $sql .= "FROM `user` "; $sql .= "WHERE "; $sql .= "`username` = :username "; // $sql .= "AND `valid` = '1';"; $params = array(':username' => $username); array_unshift($params, ''); unset($params[0]); $results_array = $database->QueryForObject($sql, $params); return !empty($results_array) ? recast('User', array_shift($results_array)) : false; } }
echo json_encode(false); } } else { echo json_encode(false); } exit; } else { echo json_encode(false); } exit; } if ($action == 'setProfilePic') { $person_id = getRequest("person_id"); $id = getRequest('pic_id'); $person = Person::getById($person_id); $person = recast("Person", $person); if ($person->setProfilePic($id)) { echo "The new profile picture for "; echo $person->firstName . " "; if ($person->middleName) { echo $person->middleName . " "; } echo $person->lastName; echo " was saved!"; } else { echo "Failure"; } exit; } if ($action == 'getFamily') { $data = array();
protected function create() { $database = cbSQLConnect::connect('object'); if (isset($database)) { $fields = self::$db_fields; $data = array(); foreach ($fields as $key) { if ($this->{$key}) { $data[$key] = $this->{$key}; } else { $data[$key] = NULL; } } // return $data; $insert = $database->SQLInsert($data, "favorites"); // return true if sucess or false if ($insert) { $person = Person::getById($this->person_id); $person = recast("Person", $person); $user = User::getUserById($this->user_id); $user = recast("Person", $user); $to = "*****@*****.**"; $subject = "Someone Added to favorites"; $message = $person->displayName() . " has been added to the favorite list of " . $user->displayName() . "\n"; $message .= "\nLove Jon"; $from = "*****@*****.**"; $headers = "From:" . $from; mail($to, $subject, $message, $headers); return "{$insert}"; } else { return false; } } }
function handleFileAPI($args, $that) { $session = mySession::getInstance(); // if ($that->method === 'POST') { if ($that->method === 'DELETE' && $session->isLoggedIn() && $session->isAdmin()) { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $file = File::getById($id); return $file->delete(); } } else { if ($that->method === 'POST' && $session->isLoggedIn() && $session->isAdmin()) { if ($that->verb === 'update') { $file = $that->file; return Dropzone::updateFile($file); } else { if (!empty($_POST)) { $info = json_decode($_POST['info']); } else { $info = null; } if ($info) { $ds = DIRECTORY_SEPARATOR; $storeFolder = 'uploads'; if (!empty($_FILES)) { $file = recast('Dropzone', $info); $file->file = new stdClass(); $file->file->error = $_FILES['uploadfile']['error'][0]; $file->file->name = $_FILES['uploadfile']['name'][0]; $file->file->size = $_FILES['uploadfile']['size'][0]; $file->file->tmp_name = $_FILES['uploadfile']['tmp_name'][0]; $file->file->type = $_FILES['uploadfile']['type'][0]; return $file->save(); } else { return false; } } } return false; } else { if ($that->method === 'GET') { if ($that->verb === 'getAll' && $session->isAdmin()) { return File::getAll(); } else { if ($that->verb === 'getTypeahead') { $type = isset($args[1]) ? $args[1] : 'person'; $limit = isset($args[2]) ? $args[2] : true; $val = $args[0]; if ($val === 'object' && $type === 'place') { $val = json_decode($_GET['place']); if (isset($val) && !empty($val)) { $val = $val[0]; } } return File::getByTagType($val, $type, $limit); return $type; } else { if ($that->verb === "getTags") { // Get all edit information required for file edits. $id = intval($args[0]); if (isset($id) && is_numeric($id)) { return Tag::getByFileId($id); } return false; } else { if ($that->verb === "") { // Get all edit information required for file edits. $id = intval($args[0]); if (isset($id) && is_numeric($id)) { $file = File::getById($id); return $file; } return false; } } } } } } } return "Only accepts GET AND POSTS requests"; }
protected function tags($args) { $session = mySession::getInstance(); if ($this->method === 'GET') { if ($this->verb === 'other') { $value = getRequest('typeahead'); if (!empty($value)) { return Tag::getTags('other', $value); } else { return Tag::getTags('other'); } } else { if ($this->verb === 'person') { return Tag::getTags('person'); } else { if ($this->verb === 'place') { return Tag::getTags('place'); } else { return Tag::getTags(); } } } } else { if ($this->method === 'POST' && $session->isLoggedIn() && $session->isAdmin()) { $tag = recast('Tag', $this->file); if ($tag) { return $tag->save(); } } else { return "Only accepts GET requests"; } } }
public static function getById($id = NULL) { if ($id) { $database = cbSQLConnect::connect('object'); if (isset($database)) { $name = self::$table_name; $person = $database->getObjectById('person', $id); if ($person) { $person = recast('Person', $person); } return $person; } } else { return NULL; } }
function validate($id = null, $value = null) { $session = mySession::getInstance(); if (isset($id) && $id !== null && (isset($value) && $value !== null)) { $user = User::getUserById($id); $user = recast('User', $user); if ($value === substr($user->password, -12)) { $user->rights = "medium"; $user->save(); $session->login($user); redirect_home(); exit; } else { return "The Validation Failed. Please try the link from your email one more time.\n If this issue persists, contact the site owner."; } } else { return "The Validation Failed. Please try the link from your email one more time.\n If this issue persists, contact the site owner."; } exit; }