summaryrefslogtreecommitdiffstats
path: root/app/model
diff options
context:
space:
mode:
Diffstat (limited to 'app/model')
-rw-r--r--app/model/common.mod.php151
-rw-r--r--app/model/obj.mod.php30
2 files changed, 180 insertions, 1 deletions
diff --git a/app/model/common.mod.php b/app/model/common.mod.php
index 3d8c200..6cba871 100644
--- a/app/model/common.mod.php
+++ b/app/model/common.mod.php
@@ -17,7 +17,9 @@
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";
class CommonModel extends MasterModel
{
@@ -30,10 +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();
}
@@ -59,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;
+ }
+ }
}
/*
@@ -68,6 +90,8 @@ 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;
@@ -77,6 +101,103 @@ 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 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
*/
function saveSettingUser($input, $attachment)
@@ -343,6 +464,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 "";
+ }
}
?>
diff --git a/app/model/obj.mod.php b/app/model/obj.mod.php
new file mode 100644
index 0000000..159c962
--- /dev/null
+++ b/app/model/obj.mod.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * SCROTT Copyright (C) 2016 Malf Furious
+ *
+ * Scrott is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Scrott is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ * License for more details.
+ */
+
+require_once "model/common.mod.php";
+
+class ObjModel extends CommonModel
+{
+ /*
+ * Constructor
+ */
+ function __construct($guid)
+ {
+ parent::__construct($guid);
+ }
+}
+
+?>