public function newContact() { $identity = array('fName' => $_POST['firstName'], 'mName' => $_POST['middleName'], 'lName' => $_POST['lastName'], 'gender' => $_POST['gender'], 'email' => $_POST['email'], 'type' => 2); $contactIdentityId = Identity::newIdentity($identity); if (!$contactIdentityId) { $_SESSION['Error'] = "Unable to create a Contact Identity!"; header("Location: " . $_POST['path']); // TODO: This should go to an error page. return false; } require_once 'helpers/upload.php'; $code = ''; if ($contactIdentityId) { $id = intval($contactIdentityId); $handle = new upload($_FILES['image_field']); if ($handle->uploaded) { $handle->file_new_name_body = $id; $handle->image_resize = true; $handle->image_x = 100; $handle->image_ratio_y = true; $handle->file_overwrite = true; $handle->process($_SERVER['DOCUMENT_ROOT'] . '/EduDB/imageUploads/'); if ($handle->processed) { $handle->clean(); } else { $_SESSION['ERROR'] = $handle->error; // Failure } } Identity::updateImage($id, '/EduDB/imageUploads/' . $handle->file_dst_name); } // If we get here then we have made an identity but have not linked it // to the target contact yet. We will need to set the relationship. if (!session_id()) { session_start(); } $_SESSION['contact']['studentId'] = $_POST['studentId']; $_SESSION['contact']['studentIdentityId'] = $_POST['identityId']; $_SESSION['contact']['contactIdentityId'] = $contactIdentityId; header("Location: ?controller=contact&action=setRelationship"); }
public function addStudent() { $identity = array('fName' => $_POST['firstName'], 'mName' => $_POST['middleName'], 'lName' => $_POST['lastName'], 'gender' => $_POST['gender'], 'email' => $_POST['email'], 'type' => 1); $studentIdentityId = Identity::newIdentity($identity); if (!$studentIdentityId) { $_SESSION['Error'] = "Unable to create Student Identity!"; header("Location: " . $_POST['path']); // TODO: This should go to an error page. return false; } require_once 'helpers/upload.php'; $code = ''; if ($studentIdentityId) { $id = intval($studentIdentityId); $handle = new upload($_FILES['image_field']); if ($handle->uploaded) { $handle->file_new_name_body = $id; $handle->image_resize = true; $handle->image_x = 100; $handle->image_ratio_y = true; $handle->file_overwrite = true; $handle->process($_SERVER['DOCUMENT_ROOT'] . '/EduDB/imageUploads/'); if ($handle->processed) { $handle->clean(); } else { $_SESSION['ERROR'] = $handle->error; // Failure } } Identity::updateImage($id, '/EduDB/imageUploads/' . $handle->file_dst_name); } $student = array('gradeId' => $_POST['grade'], 'identityId' => $studentIdentityId, 'schoolId' => $_POST['school']); $sId = Student::newStudent($student); if (!$sId) { $_SESSION['Error'] = "Unable to update Student!"; } header("Location: ?controller=student&action=viewStudent&id={$sId}"); }