diff options
author | Malf Furious <m@lfurio.us> | 2016-05-01 01:42:30 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2016-05-01 01:42:30 -0400 |
commit | d431ef2954455ad38454d27f5be866061794b4bf (patch) | |
tree | ceb03f3c9cf27e5c388cbc923476d9df5b49c10b /app | |
parent | 93fa361ba63c8afa2370c43b7918c9dd513a4586 (diff) | |
parent | 395f7ed73b0b868027285512040fbfe3d0adf347 (diff) | |
download | scrott-d431ef2954455ad38454d27f5be866061794b4bf.tar.gz scrott-d431ef2954455ad38454d27f5be866061794b4bf.zip |
Merge branch 'feature/user-img-mgmt' into dev
Diffstat (limited to '')
-rw-r--r-- | app/assets/img/heads/.gitkeep | 0 | ||||
-rw-r--r-- | app/assets/img/heads/null.jpg | bin | 0 -> 8483 bytes | |||
-rw-r--r-- | app/assets/js/scrott.js | 8 | ||||
-rw-r--r-- | app/class/form.class.php | 4 | ||||
-rw-r--r-- | app/class/user.class.php | 19 | ||||
-rw-r--r-- | app/controller/dashboard.control.php | 2 | ||||
-rw-r--r-- | app/model/common.mod.php | 50 | ||||
-rw-r--r-- | app/view/common/setting.modal.view.php | 89 | ||||
-rw-r--r-- | app/view/master/foot.view.php | 1 |
9 files changed, 144 insertions, 29 deletions
diff --git a/app/assets/img/heads/.gitkeep b/app/assets/img/heads/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/app/assets/img/heads/.gitkeep +++ /dev/null diff --git a/app/assets/img/heads/null.jpg b/app/assets/img/heads/null.jpg Binary files differnew file mode 100644 index 0000000..a78f946 --- /dev/null +++ b/app/assets/img/heads/null.jpg diff --git a/app/assets/js/scrott.js b/app/assets/js/scrott.js new file mode 100644 index 0000000..675597b --- /dev/null +++ b/app/assets/js/scrott.js @@ -0,0 +1,8 @@ +/* + * Common Javascript logic for the Scrott application + */ + +function assertConfirm() +{ + return confirm("Are you sure?"); +} diff --git a/app/class/form.class.php b/app/class/form.class.php index 907c0a2..fd85638 100644 --- a/app/class/form.class.php +++ b/app/class/form.class.php @@ -191,7 +191,9 @@ class Form { if ($file['error'] > 0) { - $this->logError("An unknown error occurred"); + if ($file['error'] != UPLOAD_ERR_NO_FILE) + $this->logError("An unknown error occurred"); + return false; } diff --git a/app/class/user.class.php b/app/class/user.class.php index 1130396..1d17dfe 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -187,6 +187,25 @@ class User extends Object return "glyphicon glyphicon-user"; } + + /* + * Get this user's head image + */ + function getHeadImage() + { + return $this->ar() . "/file.php?d=img/heads&f=" . $this->guid; + } + + /* + * Remove this user's head image + */ + function rmHeadImage() + { + if (!is_file("assets/img/heads/" . $this->guid)) + return true; + + return unlink("assets/img/heads/" . $this->guid); + } } ?> diff --git a/app/controller/dashboard.control.php b/app/controller/dashboard.control.php index 53ca160..aa1c0bd 100644 --- a/app/controller/dashboard.control.php +++ b/app/controller/dashboard.control.php @@ -14,7 +14,7 @@ class Dashboard extends Controller function handle($argv) { $mod = new DashboardModel(); - $mod->common_handleFormSubmissions($_REQUEST['input']); + $mod->common_handleFormSubmissions($_REQUEST['input'], $_FILES['attachment']); $mod->common_deflt(); $this->action_default($mod); } 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); } } diff --git a/app/view/common/setting.modal.view.php b/app/view/common/setting.modal.view.php index 11adc69..e43f723 100644 --- a/app/view/common/setting.modal.view.php +++ b/app/view/common/setting.modal.view.php @@ -27,21 +27,46 @@ <div class="tab-pane fade in active" id="settUserTab"> <p> </p> - <?php if ($mod->getCurrentUser()->admin == 1) { ?> - <p class="pull-right"><span class="glyphicon glyphicon-sunglasses"></span> <?=$mod->getCurrentUser()->getDisplayName()?> is a Scrott Administrator</p> - <?php } ?> - - <form method="post" action="<?=$mod->ap()?>"> + <form method="post" action="<?=$mod->ap()?>" enctype="multipart/form-data"> <input type="hidden" name="input[action]" value="common-setting-user" /> - <div class="form-group"> - <label>Username</label> - <input type="text" class="form-control" value="<?=$mod->getCurrentUser()->name?>" disabled /> + + <div class="row"> + <div class="col-md-8"> + <?php if ($mod->getCurrentUser()->admin == 1) { ?> + <p class="pull-right"><span class="glyphicon glyphicon-sunglasses"></span> <?=$mod->getCurrentUser()->getDisplayName()?> is a Scrott Administrator</p> + <?php } ?> + + <div class="form-group"> + <label>Username</label> + <input type="text" class="form-control" value="<?=$mod->getCurrentUser()->name?>" disabled /> + </div> + + <div class="checkbox"> + <label data-toggle="collapse" data-target="#inputUserPasswdCollapse"> + <input type="checkbox" name="input[setPasswd]" value="1" /> Change Password + </label> + </div> + </div> + + <div class="col-md-4 text-center"> + <img src="<?=$mod->getCurrentUser()->getHeadImage()?>" alt="<?=$mod->getCurrentUser()->getDisplayName()?>" class="img-circle" height="100" /> + <br /> + <br /> + <button type="button" class="btn btn-default btn-xs" data-toggle="collapse" data-target="#inputUserImageCollapse"> + <span class="glyphicon glyphicon-camera"></span> Upload new image + </button> + <br /> + <button type="submit" name="input[rmImage]" class="btn btn-danger btn-xs" onclick="return assertConfirm()"> + <span class="glyphicon glyphicon-remove"></span> Remove image + </button> + </div> </div> - <div class="checkbox"> - <label data-toggle="collapse" data-target="#inputUserPasswdCollapse"> - <input type="checkbox" name="input[setPasswd]" value="1" /> Change Password - </label> + <div class="collapse" id="inputUserImageCollapse"> + <div class="form-group"> + <label>User Image</label> + <input type="file" name="attachment" /> + </div> </div> <div class="collapse" id="inputUserPasswdCollapse"> @@ -194,19 +219,43 @@ <div class="panel-collapse collapse" id="common-setting-allusers-<?=$user->guid?>-collapse"> <div class="panel-body"> - <form method="post" action="<?=$mod->ap()?>"> + <form method="post" action="<?=$mod->ap()?>" enctype="multipart/form-data"> <input type="hidden" name="input[action]" value="common-setting-allusers-edituser" /> <input type="hidden" name="input[guid]" value="<?=$user->guid?>" /> - <div class="form-group"> - <label>Username</label> - <input type="text" class="form-control" value="<?=$user->name?>" disabled /> + <div class="row"> + <div class="col-md-8"> + <div class="form-group"> + <label>Username</label> + <input type="text" class="form-control" value="<?=$user->name?>" disabled /> + </div> + + <div class="checkbox"> + <label data-toggle="collapse" data-target="#input<?=$user->guid?>PasswdCollapse"> + <input type="checkbox" name="input[setPasswd]" value="1" /> Change Password + </label> + </div> + </div> + + <div class="col-md-4 text-center"> + <img src="<?=$user->getHeadImage()?>" alt="<?=$user->getDisplayName()?>" class="img-circle" height="100" /> + <br /> + <br /> + <button type="button" class="btn btn-default btn-xs" data-toggle="collapse" data-target="#input<?=$user->guid?>ImageCollapse"> + <span class="glyphicon glyphicon-camera"></span> Upload new image + </button> + <br /> + <button type="submit" name="input[rmImage]" class="btn btn-danger btn-xs" onclick="return assertConfirm()"> + <span class="glyphicon glyphicon-remove"></span> Remove image + </button> + </div> </div> - <div class="checkbox"> - <label data-toggle="collapse" data-target="#input<?=$user->guid?>PasswdCollapse"> - <input type="checkbox" name="input[setPasswd]" value="1" /> Change Password - </label> + <div class="collapse" id="input<?=$user->guid?>ImageCollapse"> + <div class="form-group"> + <label>User Image</label> + <input type="file" name="attachment" /> + </div> </div> <div class="collapse" id="input<?=$user->guid?>PasswdCollapse"> diff --git a/app/view/master/foot.view.php b/app/view/master/foot.view.php index 6220f89..c749ad0 100644 --- a/app/view/master/foot.view.php +++ b/app/view/master/foot.view.php @@ -1,5 +1,6 @@ <script type="text/javascript" src="<?=$mod->ar()?>/assets/js/jquery.min.js"></script> <script type="text/javascript" src="<?=$mod->ar()?>/assets/js/bootstrap.min.js"></script> +<script type="text/javascript" src="<?=$mod->ar()?>/assets/js/scrott.js"></script> <?php if ($mod->isError() || $mod->isWarning() || $mod->isNotice()) { ?> <script type="text/javascript"> |