diff options
Diffstat (limited to 'app/model')
-rw-r--r-- | app/model/common.mod.php | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/app/model/common.mod.php b/app/model/common.mod.php index b1aa0a0..7630dfa 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -7,6 +7,12 @@ require_once "class/user.class.php"; class CommonModel extends MasterModel { + var $HEAD_IMG_MAX_SIZE = 1048576; // 1MB + var $HEAD_IMG_MIME = array( + "image/jpg", + "image/jpeg" + ); + /* * Default action */ @@ -34,21 +40,21 @@ class CommonModel extends MasterModel /* * Handle form submissions from common views */ - function common_handleFormSubmissions($input) + function common_handleFormSubmissions($input, $attachment) { switch ($input['action']) { - case "common-setting-user": $this->saveSettingUser($input); break; - case "common-setting-admin": $this->saveSettingAdmin($input); break; - case "common-setting-allusers-adduser": $this->saveSettingAllusersAdduser($input); break; - case "common-setting-allusers-edituser": $this->saveSettingAllusersEdituser($input); break; + case "common-setting-user": $this->saveSettingUser($input, $attachment); break; + case "common-setting-admin": $this->saveSettingAdmin($input); break; + case "common-setting-allusers-adduser": $this->saveSettingAllusersAdduser($input); break; + case "common-setting-allusers-edituser": $this->saveSettingAllusersEdituser($input, $attachment); break; } } /* * Save changes to user account settings */ - function saveSettingUser($input) + function saveSettingUser($input, $attachment) { $form = new Form(); $form->field_bool("setPasswd"); @@ -73,6 +79,16 @@ class CommonModel extends MasterModel return; } + if (isset($input['rmImage'])) + { + if ($user->rmHeadImage()) + $this->logNotice("Image removed"); + else + $this->logError("Error removing user image"); + + return; + } + if ($form->setPasswd) { if ($user->validatePassword($form->curPasswd)) @@ -102,6 +118,11 @@ class CommonModel extends MasterModel } $user->saveObj(); + + if ($form->saveFile($attachment, $this->HEAD_IMG_MAX_SIZE, $this->HEAD_IMG_MIME, "assets/img/heads/" . $user->guid)) + $this->logNotice("Image uploaded"); + else + $this->logFormErrors($form); } /* @@ -185,7 +206,7 @@ class CommonModel extends MasterModel /* * Allow an admin to edit user accounts */ - function saveSettingAllusersEdituser($input) + function saveSettingAllusersEdituser($input, $attachment) { $form = new Form(); $form->field_text("guid"); @@ -218,6 +239,16 @@ class CommonModel extends MasterModel return; } + if (isset($input['rmImage'])) + { + if ($user->rmHeadImage()) + $this->logNotice("Image removed"); + else + $this->logError("Error removing user image"); + + return; + } + if ($form->setPasswd) { if ($form->newPasswd == $form->confPasswd) @@ -236,6 +267,11 @@ class CommonModel extends MasterModel $user->setEmail($form->email); $user->saveObj(); + + if ($form->saveFile($attachment, $this->HEAD_IMG_MAX_SIZE, $this->HEAD_IMG_MIME, "assets/img/heads/" . $user->guid)) + $this->logNotice("Image uploaded"); + else + $this->logFormErrors($form); } } |