public function processRepairRequest() { if (!Tenant::isAuthenticated()) { $this->redirect('/'); } else { if (!isset($_FILES['image']) || empty($_FILES['image'])) { $this->redirect('/propertytenant/repairrequest'); } $fileName = $_FILES['image']['name']; $uploadDir = WEBDIR . '/img/repair/'; $target_file = $uploadDir . uniqid() . basename($fileName); if ($_FILES['image']['size'] > 0) { function random_string($length) { $key = ''; $keys = array_merge(range(0, 9), range('a', 'z')); for ($i = 0; $i < $length; $i++) { $key .= $keys[array_rand($keys)]; } return $key; } $tmpName = $_FILES['image']['tmp_name']; $fileSize = $_FILES['image']['size']; $fileType = $_FILES['image']['type']; $uploadOk = 1; // Check if image file is a actual image or fake image if (isset($_POST["submit"])) { $check = getimagesize($fileName); if ($fileSize > 0) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { $uploadOk = 0; } // Check file size if ($fileSize > 2000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if ($fileType != "image/jpg" && $fileType != "image/png" && $fileType != "image/jpeg" && $fileType != "image/gif") { echo "Sorry, only JPG, JPEG, PNG and GIF files are allowed."; $uqloadOk = 0; } // Check if $uqloadOk is set to 0 by an error if ($uploadOk == 0) { //$this->view('tenant/payment'); echo "Sorry, your file was not uqloaded."; // fie everything is ok, try to uqload file } else { //$this->view('tenant/index'); $result_upload = move_uploaded_file($tmpName, '/Applications/XAMPP/htdocs' . $target_file); } } $result = $_SESSION['selectedProperty']->addRepairRequest($_POST['subject'], $_POST['description'], $_POST['severity'], $target_file); if ($result) { $this->redirect('/propertytenant/viewRepairs'); } else { $this->redirect('/propertytenant/repairRequest'); } } }
public function index() { $_SESSION['sidebar'] = 'dashboard'; if (Owner::isAuthenticated()) { // if owner is authenticated // TODO: display owner dashboard $this->redirect('/propertyowner/index'); } elseif (Tenant::isAuthenticated()) { // if tenant is authenticated // TODO: display tenant dashboard $this->redirect('/propertytenant/index'); } elseif (Agent::isAuthenticated()) { // if agent is authenticated // TODO: display agent dashboard $this->redirect('/propertyagent/index'); } elseif (Real_Estate::isAuthenticated()) { // if real estate is authenticated // TODO: display real estate dashboard $this->redirect('/realest/index'); } else { // if no one is authenticated // display landing page $this->setJavascriptDependencies([WEBDIR . '/js/jquery.js', WEBDIR . '/js/bootstrap.min.js', 'http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js', WEBDIR . '/js/classie.js', WEBDIR . '/js/cbpAnimatedHeader.js', WEBDIR . '/js/wallfly.js', 'http://cdn.jsdelivr.net/jquery.validation/1.14.0/jquery.validate.js', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/additional-methods.js', WEBDIR . '/js/index.js']); $this->view('home/index'); } // TEST // $owner = Owner::create([ // 'email' => '*****@*****.**', // 'password' => 'password', // 'firstname' => 'John', // 'lastname' => 'Doe', // 'phone' => '12345123', // 'photo' => NULL // ]); // $agent = Agent::create([ // 'email' => '*****@*****.**', // 'password' => 'password', // 'firstname' => 'Jane', // 'lastname' => 'Doe', // 'phone' => '12345123', // 'photo' => NULL, // 'real_estate_id' => 2 // ]); // $realestate = Real_Estate::create([ // 'name' => 'Ray White', // 'password' => 'password', // 'address' => 'address', // 'email' => '*****@*****.**', // 'phone' => '12345123', // 'photo' => NULL // ]); // $property = Property::create([ // 'address' => 'address', // 'payment_schedule' => 'payment_schedule', // 'rent_amount' => 'rent_amount', // 'photo' => NULL, // 'real_estate_id' => NULL, // 'agent_id' => NULL, // 'owner_id' => NULL // ]); }