public function run() { $faker = Faker\Factory::create(); // change this to auto create more leave balance records for each user $user_count = 19; // change this if you add or remove a leave type $parents_count = 2; foreach (range(1, $user_count) as $user_id) { foreach (range(1, $parents_count) as $parents_id) { Parents::create(['user_id' => $user_id, 'parent_id' => $parents_id, 'firstname' => $faker->firstName, 'middlename' => $faker->lastName, 'lastname' => $faker->lastName, 'address' => $faker->streetAddress]); } } }
function RegisterParent($email, $password, $title, $sex, $nickname, $firstname, $lastname) { include_once '../config/Config.php'; $conn = new DatabaseConnect(); $mysqli = $conn->connect($db_host, $db_username, $db_password, $mysql_db); //check valid email address if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Please enter a valid email address"; die; } else { //md5 level password encryption $md5_password = md5($password); $hash = md5(rand(1, 10000)); $queryEmReg = "SELECT * FROM parents WHERE email ='" . $email . "'"; $emailCheck = $mysqli->query($queryEmReg); if (!mysqli_num_rows($emailCheck) < 1) { echo 'Email address in use'; } else { $sql = "INSERT INTO parents (email,password,title,sex,nickname,firstname,lastname,hash)\n\t\t\t\t\t\tVALUES (?,?,?,?,?,?,?,?)"; $mail = new Parents(); //prepared query statements if ($stmt = $mysqli->prepare($sql)) { $stmt->bind_param("ssssssss", $email, $md5_password, $title, $sex, $nickname, $firstname, $lastname, $hash); $stmt->execute(); $stmt->bind_result($result); if ($stmt->affected_rows > 0) { echo 'Email sent'; $mail->VerificationEmail($email, $firstname, $hash); } else { echo 'Error - could not register'; } $stmt->close(); } else { echo 'Failed query'; } } } $connect->close(); }
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"; } } } }
public function __sleep() { return array_merge(array("child"), parent::__sleep()); }
function AddRelative($firstname, $lastname, $nickname, $email, $inviteeEmail) { include_once '../config/Config.php'; $conn = new DatabaseConnect(); $mysqli = $conn->connect($db_host, $db_username, $db_password, $mysql_db); //check valid email address if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Please enter a valid email address"; die; } else { $queryEmReg = "SELECT * FROM parents WHERE email ='" . $email . "'"; $emailCheck = $mysqli->query($queryEmReg); if (!mysqli_num_rows($emailCheck) < 1) { echo 'Email address in use'; } else { $sql = "INSERT INTO parents (FirstName, LastName, NickName, Email)\n\t\t\t\t\t\tVALUES (?,?,?,?)"; $sqlFam = "INSERT INTO Families (Parent2)\n\t\t\t\t\t\t\tVALUES (?,?,?,?)"; $mail = new Parents(); //prepared query statements if ($stmt = $mysqli->prepare($sql)) { $stmt->bind_param("ssss", $firstname, $lastname, $nickname, $email); $stmt->execute(); $stmt->bind_result($result); if ($stmt->affected_rows > 0 && scrollParents($email, $inviteeEmail)) { echo 'Email sent'; $mail->RelativeVerification($email, $firstname); } else { echo 'Error - could not register'; } $stmt->close(); } else { echo 'Failed query'; } } } $connect->close(); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Parents the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Parents::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
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 function actionRegistrate() { // asi se crea un usuario (una nueva instancia en memoria volatil) $user = Yii::app()->user->um->createBlankUser(); $profile = new Profile(); /* echo "<pre>"; echo print_r($_POST); echo "</pre>"; Yii::app()->end(); */ if (isset($_POST['CrugeStoredUser']) && isset($_POST['UserType']) && isset($_POST['Profile'])) { $validate = true; $msg = ""; $user->username = $_POST['CrugeStoredUser']['username']; $user->email = $_POST['CrugeStoredUser']['email']; // la establece como "Activada" //Yii::app()->user->um->activateAccount($user); // verifica para no duplicar if (Yii::app()->user->um->loadUser($user->username) != null) { $msg .= "El usuario {$user->username} ya ha sido creado.<br/>"; $validate = false; } if (Yii::app()->user->um->loadUser($user->email) != null) { $msg .= "El email {$user->email} ya ha sido creado."; $validate = false; } if ($validate) { // ahora a ponerle una clave Yii::app()->user->um->changePassword($user, $_POST['CrugeStoredUser']['newPassword']); // IMPORTANTE: guarda usando el API, la cual hace pasar al usuario // por el sistema de filtros, por eso user->um->save() // if (Yii::app()->user->um->save($user)) { //creo un nuevo perfil $profile = new Profile(); $profile->attributes = $_POST['Profile']; $profile->date_of_birth = strtotime($_POST['Profile']['date_of_birth']); $profile->email = $user->email; $profile->status = 0; $profile->cruge_user_iduser = $user->primaryKey; $profile->save(); //guardo el tipo de user $typeuser = $_POST['UserType']; if ($typeuser == '1') { $student = new Students(); $student->profile_id = $profile->id_profile; $student->save(); Yii::app()->db->createCommand()->insert('cruge_authassignment', array('userid' => $user->primaryKey, 'bizrule' => null, 'data' => 'N;', 'itemname' => 'Estudiante')); } else { if ($typeuser == '2') { $parent = new Parents(); $parent->profile_id = $profile->id_profile; $parent->save(); Yii::app()->db->createCommand()->insert('cruge_authassignment', array('userid' => $user->primaryKey, 'bizrule' => null, 'data' => 'N;', 'itemname' => 'Padre')); } else { if ($typeuser == '3') { $tutor = new Tutor(); $tutor->profile_id = $profile->id_profile; $tutor->save(); Yii::app()->db->createCommand()->insert('cruge_authassignment', array('userid' => $user->primaryKey, 'bizrule' => null, 'data' => 'N;', 'itemname' => 'Tutor')); } } } Yii::app()->crugemailer->sendRegistrationUserEmail($user, $_POST['CrugeStoredUser']['newPassword']); $this->redirect(array('welcome', 'id' => $user->primaryKey)); } else { $errores = CHtml::errorSummary($user); Yii::app()->user->setFlash('profile-flash', "no se pudo crear el usuario: " . $errores); $this->redirect(array('error')); //echo "no se pudo crear el usuario: ".$errores; } } else { Yii::app()->user->setFlash('error', $msg); } } $this->render('registrate', array('user' => $user, 'profile' => $profile)); }
public function postEditParents($id) { $user = User::find($id); $father = Parents::where(function ($q) use($id) { $q->where('user_id', $id); $q->where('parent_id', 1); })->first(); $mother = Parents::where(function ($q) use($id) { $q->where('user_id', $id); $q->where('parent_id', 2); })->first(); $father->update(['firstname' => Input::get('fatherfirstname'), 'middlename' => Input::get('fathermiddlename'), 'lastname' => Input::get('fatherlastname'), 'address' => Input::get('fatheraddress')]); $mother->update(['firstname' => Input::get('motherfirstname'), 'middlename' => Input::get('mothermiddlename'), 'lastname' => Input::get('motherlastname'), 'address' => Input::get('motheraddress')]); $audit = AuditTrail::create(['user_id' => Auth::id(), 'role' => 'Employee Management Admin', 'action' => 'edited ' . $user->firstname . ' ' . $user->lastname . '\'s Parent Information.']); return Redirect::route('profile', $id)->with('alert', 'success|Parent Information has been successfully updated')->with('father', $father)->with('mother', $mother); }
//this will get us the individual's data if ($action == 'getIndData') { $check = $_REQUEST['check']; if ($check != 'New Individual') { $line = explode("|| ", $check); $id = $line[2]; $result = array(); $result[] = array_values(get_object_vars($person = Person::getById($id))); $result[] = array_values(get_object_vars($birth = Birth::getById($id))); $result[] = array_values(get_object_vars($death = Death::getById($id))); $result[] = array_values(get_object_vars($burial = Burial::getById($id))); $result[] = array_values(get_object_vars(Place::getById($birth->place))); $result[] = array_values(get_object_vars(Place::getById($death->place))); $result[] = array_values(get_object_vars(Place::getById($burial->place))); $parents = array(); $parent = Parents::getAllParentsById($id); foreach ($parent as $pops) { $temp = array(); $temp[0] = 'parent'; $temp_person = Person::getById($pops->parentId); $temp[1] = "" . $temp_person->lastName . ", " . $temp_person->firstName . " " . $temp_person->middleName . " || Born: " . $temp_person->yearBorn . ", Death: " . $temp_person->yearDead . " || " . $temp_person->id; $parents[] = $temp; } $result[] = $parents; $spouses = array(); $spouse = Spouse::getAllSpousesById($id); foreach ($spouse as $spo) { $temp = array(); $temp[0] = 'spouse'; $temp_spouse = Person::getById($spo->spouse); $temp[1] = "" . $temp_spouse->lastName . ", " . $temp_spouse->firstName . " " . $temp_spouse->middleName . " || Born: " . $temp_spouse->yearBorn . ", Death: " . $temp_spouse->yearDead . " || " . $temp_spouse->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"; } } } }
$this->breadcrumbs = array('Estudiantes' => array('index'), $model->id); $this->menu = array(array('label' => CHtml::image(Yii::app()->theme->baseUrl . "/img/operaciones/list29.png") . 'Listado de Estudiantes', 'url' => array('index')), array('label' => CHtml::image(Yii::app()->theme->baseUrl . "/img/operaciones/cogs3.png") . 'Gestionar Estudiantes', 'url' => array('admin'))); ?> <legend>Vista de Estudiante #<?php echo $model->id; ?> </legend> <section><p><?php echo "<b>Usuario:</b> " . $model->profile->user->username . " | " . "<b>Registrado:</b> " . Yii::app()->dateFormatter->formatDateTime($model->profile->user->regdate, 'medium', false) . " | " . "<b>Status:</b> " . Profile::model()->validarStatus($model->profile->cruge_user_iduser); ?> </p></section> <?php $this->widget('zii.widgets.CDetailView', array('htmlOptions' => array('class' => 'table table-striped table-condensed table-hover'), 'data' => $model, 'attributes' => array(array('name' => 'id', 'label' => 'ID'), array('name' => 'profile.identification', 'label' => 'Nº Identificación'), array('value' => Profile::model()->nombreApellido($model->profile->firstname, $model->profile->secondname, $model->profile->lastname1, $model->profile->lastname2), 'label' => 'Nombres y Apellidos'), array('name' => 'profile.email', 'label' => 'Correo'), array('value' => Profile::model()->validarSexo($model->profile->sex) == "M" ? "Masculino" : "Femenino", 'type' => 'raw', 'label' => 'Sexo'), array('name' => 'profile.date_of_birth', 'value' => Yii::app()->dateFormatter->formatDateTime($model->profile->date_of_birth, 'medium', false), 'type' => 'raw', 'label' => 'Fecha de Nacimiento'), array('name' => 'parents_id', 'label' => 'Padre', 'value' => Parents::model()->getParents($model->parents_id), 'type' => 'raw')))); ?> <!-- Box de Informacion Estudiante VC --> <?php $this->beginWidget('yiiwheels.widgets.box.WhBox', array('title' => 'Datos del usuario en VC', 'headerIcon' => 'icon-th-list')); ?> <?php $this->widget('zii.widgets.CDetailView', array('htmlOptions' => array('class' => 'table table-striped table-condensed table-hover'), 'data' => $model, 'attributes' => array('user_college', 'pass_college', 'tutor_id', 'requirements_id'))); $this->endWidget(); ?> <!-- End Box Informacion Estudiante VC --> <legend> <a href="#" id="mostrarAdd" style="display: none;"><i class="fa fa-chevron-down"></i></a>
public function getUserPdf($id) { $user = User::find($id); $comids = CommonId::where('user_id', $user->id)->first(); $cont = ContactInfo::where('user_id', $user->id)->first(); $parents = Parents::where('user_id', $user->id)->get(); $schools = School::where('user_id', $user->id)->first(); if ($user->gender == 'Male') { $gender = 'his'; } else { $gender = 'her'; } $audit = AuditTrail::create(['user_id' => Auth::id(), 'role' => 'User', 'action' => 'printed ' . $gender . ' User Information']); if (!$user) { App::abort(404); } Fpdf::AddPage(); Fpdf::PageNo(); Fpdf::AliasNbPages('{nb}'); Fpdf::Image('img/dap.jpg', 10, 5, 150); Fpdf::SetFont('Arial', 'B', 10); Fpdf::Ln(25); Fpdf::Cell(300, 10, 'Date Generated: ' . date("F j, Y"), 0, 2, 'C', 0); Fpdf::SetFont('Arial', 'B', 18); Fpdf::Ln(10); Fpdf::Cell(190, 10, $user->formatName(':fn :ln'), 0, 2, 'C', 0); Fpdf::SetFont('Arial', 'B', 9.5); Fpdf::SetTextColor(0, 0, 0); Fpdf::Cell(80, 10, 'Personal Information', 0, 0, 'C', 0); Fpdf::Cell(80, 10, 'Common ID', 0, 1, 'C', 0); Fpdf::SetTextColor(0, 0, 0); Fpdf::SetFont('Arial', '', 8.5); Fpdf::Cell(80, 10, 'Email: ' . $user->email, 0, 0, 'L', 0); Fpdf::Cell(80, 10, 'TIN ID: ' . $comids->tin, 0, 1, 'L', 0); Fpdf::Cell(80, 10, 'Username: '******'L', 0); Fpdf::Cell(80, 10, 'Philhealth: ' . $comids->philhealth, 0, 1, 'L', 0); Fpdf::Cell(80, 10, 'Birthday: ' . $user->birthday, 0, 0, 'L', 0); Fpdf::Cell(80, 10, 'Pag IBIG: ' . $comids->pagibig, 0, 1, 'L', 0); Fpdf::Cell(80, 10, 'Gender: ' . $user->gender, 0, 0, 'L', 0); Fpdf::Cell(80, 10, 'SSS: ' . $comids->sss, 0, 1, 'L', 0); Fpdf::Cell(80, 10, 'Department: ' . $user->department->name, 0, 0, 'L', 0); //Fpdf::Cell(80,10,'Common ID',0,2,'C',0); Fpdf::Ln(15); Fpdf::SetFont('Arial', 'B', 9.5); Fpdf::SetFillColor(90, 90, 90); Fpdf::SetTextColor(0, 0, 0); Fpdf::Cell(150, 10, 'Parents', 0, 1, 'C', 0); foreach ($parents as $parent) { if ($parent->parent_id == 1) { Fpdf::SetFont('Arial', '', 8.5); Fpdf::Cell(10, 10, 'Father', 0, 0, 'C', 0); } else { Fpdf::SetFont('Arial', '', 8.5); Fpdf::Cell(10, 10, 'Mother', 0, 0, 'C', 0); } Fpdf::Cell(65, 10, 'Name: ' . $parent->firstname . " " . $parent->lastname, 0, 0, 'L', 0); Fpdf::Cell(65, 10, 'Address: ' . $parent->address, 0, 1, 'L', 0); } Fpdf::Ln(15); Fpdf::SetFont('Arial', 'B', 9.5); Fpdf::Cell(150, 10, 'Contact Info', 0, 1, 'C', 0); Fpdf::SetFont('Arial', '', 8.5); Fpdf::Cell(80, 10, 'Home Number: ' . $cont->homenum, 0, 0, 'L', 0); Fpdf::Cell(80, 10, 'Office Number: ' . $cont->officenum, 0, 1, 'L', 0); Fpdf::Cell(80, 10, 'Mobile Number: ' . $cont->mobilenum, 0, 0, 'L', 0); Fpdf::Cell(80, 10, 'Street: ' . $cont->street, 0, 1, 'L', 0); Fpdf::Cell(80, 10, 'City: ' . $cont->city, 0, 0, 'L', 0); Fpdf::Ln(5); Fpdf::Ln(5); Fpdf::SetFont('Arial', 'B', 9.5); Fpdf::SetFillColor(90, 90, 90); Fpdf::SetTextColor(0, 0, 0); Fpdf::Cell(180, 10, 'School', 0, 1, 'C', 0); Fpdf::SetTextColor(0, 0, 0); Fpdf::SetFont('Arial', '', 8.5); Fpdf::Cell(65, 10, 'Primary', 0, 0, 'C', 0); Fpdf::Cell(65, 10, 'Secondary', 0, 0, 'C', 0); Fpdf::Cell(65, 10, 'Tertiary', 0, 1, 'C', 0); Fpdf::Cell(65, 10, 'School: ' . $schools->primary_name, 0, 0, 'L', 0); Fpdf::Cell(70, 10, 'School: ' . $schools->secondary_name, 0, 0, 'L', 0); Fpdf::Cell(70, 10, 'School: ' . $schools->tertiary_name, 0, 1, 'L', 0); Fpdf::Cell(65, 10, 'Address: ' . $schools->primary_address, 0, 0, 'L', 0); Fpdf::Cell(70, 10, 'Address: ' . $schools->secondary_address, 0, 0, 'L', 0); Fpdf::Cell(70, 10, 'Address: ' . $schools->tertiary_address, 0, 1, 'L', 0); Fpdf::Cell(65, 10, 'Years: ' . $schools->primary_years, 0, 0, 'L', 0); Fpdf::Cell(70, 10, 'Years: ' . $schools->secondary_years, 0, 0, 'L', 0); Fpdf::Cell(70, 10, 'Years: ' . $schools->tertiary_years, 0, 1, 'L', 0); Fpdf::SetY(-30.5); Fpdf::SetFont('Arial', 'I', 6); Fpdf::SetTextColor(0, 0, 0); Fpdf::Cell(0, 10, 'Page ' . Fpdf::PageNo() . "/{nb}", 0, 0, 'C'); Fpdf::Output(); exit; }