error != UPLOAD_ERR_OK) $form_exception->addError(HTTP::getUploadErrorString($id_document->error)); if($photo->error != UPLOAD_ERR_OK) $form_exception->addError(HTTP::getUploadErrorString($photo->error)); $size = @getimagesize($id_document->tmp_name); if(!$size) $form_exception->addError(_("The uploaded ID document is not an image.")); list($width, $height, $type) = $size; if($type != IMAGETYPE_JPEG) $form_exception->addError(_("The uploaded ID document is not a JPEG.")); $size = @getimagesize($photo->tmp_name); if(!$size) $form_exception->addError(_("The uploaded photo is not an image.")); list($width, $height, $type) = $size; if($type != IMAGETYPE_JPEG) $form_exception->addError(_("The uploaded photo is not a JPEG.")); if($form_exception->hasErrors()) throw $form_exception; $files = [$id_document, $photo]; foreach($files as $index => $file) { if($index == 0) { $name = "ID document"; $type = UserFile::TYPE_ID; } if($index == 1) { $name = "photo"; $type = UserFile::TYPE_PHOTO; } $output_image = Image::normalise($file->tmp_name); $user_file = new UserFile; $user_file->user_id = $user->id; $user_file->type = $type; $user_file->dts_uploaded = Util::getDateTime(); $success = $user_file->commit(); if(!$success) throw new Exception(sprintf(_("Failed to save the %s. Please try again later."), $name)); $output_path = $user->getDirectory() . "/" . $user_file->id . ".jpg"; imagejpeg($output_image, $output_path, 60); imagedestroy($output_image); } $user->level = User::LEVEL_UNVERIFIED; $success = $user->commit(); // TODO: Send out pending verification email Core::addAlert("success", _("ID submitted successfully.")); HTTP::redirect("/account"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } View::includeOnce("header", compact("page_title")); View::include("submit_id"); View::includeOnce("footer"); ?>