From 8a29936bf03ede5412d83d5541ba802259a3fc7a Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 1 Jun 2016 22:08:17 -0400 Subject: Implement add group form handler Added handler function to common model to create new use groups from the modal view. --- app/model/common.mod.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/model/common.mod.php') diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 3d8c200..07b86df 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -18,6 +18,7 @@ require_once "model/master.mod.php"; require_once "class/form.class.php"; require_once "class/setting.class.php"; require_once "class/user.class.php"; +require_once "class/group.class.php"; class CommonModel extends MasterModel { @@ -68,6 +69,7 @@ class CommonModel extends MasterModel { switch ($input['action']) { + case "common-group-add": $this->addNewGroup($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; @@ -76,6 +78,24 @@ class CommonModel extends MasterModel } } + /* + * Create a new user group + */ + function addNewGroup($input) + { + $form = new Form(); + $form->field_text("name"); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + $group = new Group(); + $group->createNewGroup($form->name, $this->getCurrentUser()); + } + /* * Save changes to user account settings */ -- cgit v1.2.3 From f8126b70cf8e4c9a744a99a3eb41de158a26a517 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 12 Jun 2016 19:11:04 -0400 Subject: Add functions to Common model for assigning CSS to setting tabs The setting modal window will need to support showing unknown tabs at the beginning of the tab list. These functions handle assigning specific CSS classes to tab-panes ONLY if that tab will appear in the left-most position in the modal's tab list. --- app/model/common.mod.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'app/model/common.mod.php') diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 07b86df..e478e9d 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -34,6 +34,8 @@ class CommonModel extends MasterModel function __construct() { parent::__construct(); + $this->first_setting_tab_active = 0; + $this->first_setting_tab_disp = 0; $this->common_handleFormSubmissions($_REQUEST['input'], $_FILES['attachment']); $this->common_deflt(); } @@ -363,6 +365,34 @@ class CommonModel extends MasterModel $this->redirectTo($this->ar() . "/"); } } + + /* + * Set CSS class for the first tab title in the setting modal only + */ + function getSettingModalTabActiveClass() + { + if (!$this->first_setting_tab_active) + { + $this->first_setting_tab_active = 1; + return "active"; + } + + return ""; + } + + /* + * Set CSS classes for the first tab in the setting modal only + */ + function getSettingModalTabDispClasses() + { + if (!$this->first_setting_tab_disp) + { + $this->first_setting_tab_disp = 1; + return "in active"; + } + + return ""; + } } ?> -- cgit v1.2.3 From 2adba6a387ac93f750cb795bb39a36077aa7b0de Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 12 Jun 2016 20:27:57 -0400 Subject: Move initialization logic from Obj model into Common model Some logic to initialize the current system object, its owner, and members has been moved into the Common model since this code will be relevant to other views and to support a new feature being added to display additional tabs in the setting modal box. --- app/model/common.mod.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/model/common.mod.php') diff --git a/app/model/common.mod.php b/app/model/common.mod.php index e478e9d..232f0c2 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -17,6 +17,7 @@ require_once "model/master.mod.php"; require_once "class/form.class.php"; require_once "class/setting.class.php"; +require_once "class/object.class.php"; require_once "class/user.class.php"; require_once "class/group.class.php"; @@ -31,12 +32,20 @@ class CommonModel extends MasterModel /* * Constructor */ - function __construct() + function __construct($guid = null) { parent::__construct(); $this->first_setting_tab_active = 0; $this->first_setting_tab_disp = 0; $this->common_handleFormSubmissions($_REQUEST['input'], $_FILES['attachment']); + + if (!is_null($guid)) + { + $this->obj = new DBObject($guid); + $this->owner = $this->obj->getOwner(); + $this->members = $this->obj->getMembers(); + } + $this->common_deflt(); } -- cgit v1.2.3 From 076a86c663870be3c4cf6da8059f0f978a7eb3ce Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 12 Jun 2016 21:33:50 -0400 Subject: Add group tab to setting modal Created empty
for the group setting tab. Also added code to the common model for initializing the $mod->group variable and setting a flag marking what tabs to include in the setting modal (group tab in this case). Added logic to the main setting modal view file for picking up these flags and including appropriate additional content. --- app/model/common.mod.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/model/common.mod.php') diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 232f0c2..459c53a 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -71,6 +71,16 @@ class CommonModel extends MasterModel /* Admin all-users settings tab */ $userTbl = new User(); $this->common_settingAllUsers = $userTbl->getAllUsers_orderByAdminByName(); + + /* Setting modal - what tabs to display? */ + if (isset($this->obj)) + { + if ($this->obj->type == "group") + { + $this->group = new Group($this->obj->guid); + $this->common_settingShowTab['group'] = true; + } + } } /* -- cgit v1.2.3 From 63ca3ee23edd66cae4a2cc621cfc1352ea958a27 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 18 Sep 2016 02:56:31 -0400 Subject: Add form submission handler for group settings tab --- app/model/common.mod.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'app/model/common.mod.php') diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 459c53a..6cba871 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -91,6 +91,7 @@ class CommonModel extends MasterModel switch ($input['action']) { case "common-group-add": $this->addNewGroup($input); break; + case "common-setting-group": $this->saveSettingGroup($input, $attachment); 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; @@ -117,6 +118,85 @@ class CommonModel extends MasterModel $group->createNewGroup($form->name, $this->getCurrentUser()); } + /* + * Save changes to user group settings + */ + function saveSettingGroup($input, $attachment) + { + $form = new Form(); + $form->field_text("guid"); + $form->field_text("name"); + $form->field_bool("perm0"); + $form->field_bool("perm1"); + $form->field_bool("perm2"); + $form->field_bool("perm3"); + $form->field_bool("perm4"); + $form->field_bool("perm5"); + $form->field_bool("perm6"); + $form->field_bool("perm7"); + $form->field_bool("perm8"); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + $user = $this->getCurrentUser(); + $group = new Group($form->guid); + + if (!$user || $group->type != "group" || !$group->canModify($user)) + { + $this->logError("You do not have permission to modify this group"); + return; + } + + if (isset($input['rmImage'])) + { + if ($group->rmHeadImage()) + $this->logNotice("Image removed"); + else + $this->logError("Error removing group image"); + + return; + } + + $group->name = $form->name; + + if ($group->canModifyPermissions($user)) + { + $perms = 0; + + if ($form->perm0) + $perms |= 0x100; + if ($form->perm1) + $perms |= 0x080; + if ($form->perm2) + $perms |= 0x040; + if ($form->perm3) + $perms |= 0x020; + if ($form->perm4) + $perms |= 0x010; + if ($form->perm5) + $perms |= 0x008; + if ($form->perm6) + $perms |= 0x004; + if ($form->perm7) + $perms |= 0x002; + if ($form->perm8) + $perms |= 0x001; + + $group->perms = $perms; + } + + $group->saveObj(); + + if ($form->saveFile($attachment, $this->HEAD_IMG_MAX_SIZE, $this->HEAD_IMG_MIME, "assets/img/heads/" . $group->guid)) + $this->logNotice("Image uploaded"); + else + $this->logFormErrors($form); + } + /* * Save changes to user account settings */ -- cgit v1.2.3