continue working on a shared friends groups
authorDuck (Jakob Munih) <duck@obala.net>
Mon, 16 Feb 2009 19:34:11 +0000 (20:34 +0100)
committerDuck (Jakob Munih) <duck@obala.net>
Mon, 16 Feb 2009 19:34:11 +0000 (20:34 +0100)
folks/edit/groups.php [new file with mode: 0644]
folks/templates/edit/groups.php [new file with mode: 0644]

diff --git a/folks/edit/groups.php b/folks/edit/groups.php
new file mode 100644 (file)
index 0000000..eba47dc
--- /dev/null
@@ -0,0 +1,128 @@
+<?php
+/**
+ * $Id: blacklist.php 1234 2009-01-28 18:44:02Z duck $
+ *
+ * Copyright Obala d.o.o. (www.obala.si)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Duck <duck@obala.net>
+ * @package Folks
+ */
+
+define('FOLKS_BASE', dirname(__FILE__) . '/..');
+require_once FOLKS_BASE . '/lib/base.php';
+require_once 'tabs.php';
+
+$title = _("Groups");
+
+// Load driver
+require_once FOLKS_BASE . '/lib/Friends.php';
+$friends = Folks_Friends::singleton();
+
+// Get groups
+$groups = $friends->getGroups();
+if ($groups instanceof PEAR_Error) {
+    $notification->push($groups);
+    $groups = array();
+}
+
+// Handle action
+$action = Util::getFormData('action');
+switch ($action) {
+
+    case 'delete':
+
+        $g = Util::getFormdata('g');
+        $result = $friends->removeGroup($g);
+        if ($result instanceof PEAR_Error) {
+            $notification->push($result);
+        } elseif ($result) {
+            $notification->push(sprintf(_("Group \"%s\" has been deleted."), $groups[$g]), 'horde.success');
+        }
+
+        header('Location: ' . Horde::applicationUrl('edit/groups.php'));
+        exit;
+
+    break;
+
+    case 'edit':
+
+        $g = Util::getFormdata('g');
+        $form = new Horde_Form($vars, _("Rename group"), 'editgroup');
+        $form->addHidden('action', 'action', 'text', 'edit');
+        $form->addHidden('g', 'g', 'text', 'edit');
+        $form->setButtons(array(_("Rename"), _("Cancel")), _("Reset"));
+        $v = $form->addVariable(_("Old name"), 'old_name', 'text', false, true);
+        $v->setDefault($groups[$g]);
+        $v = $form->addVariable(_("New name"), 'new_name', 'text', true);
+        $v->setDefault($groups[$g]);
+
+        if (Util::getFormData('submitbutton') == _("Cancel")) {
+            $notification->push(sprintf(_("Group \"%s\" has not been renamed."), $groups[$g]), 'horde.warning');
+            header('Location: ' . Horde::applicationUrl('edit/groups.php'));
+            exit;
+        } elseif (Util::getFormData('submitbutton') == _("Rename")) {
+            $new_name = Util::getFormData('new_name');
+            $result = $friends->renameGroup($g, $new_name);
+            if ($result instanceof PEAR_Error) {
+                $notification->push($result);
+            } else {
+                $notification->push(sprintf(_("Group \"%s\" has been renamed to \"%s\"."), $groups[$g], $new_name), 'horde.success');
+                header('Location: ' . Horde::applicationUrl('edit/groups.php'));
+                exit;
+            }
+        }
+
+    break;
+
+    default:
+
+        // Manage adding groups
+        $form = new Horde_Form($vars, _("Add group"), 'addgroup');
+        $translated = Horde::loadConfiguration('groups.php', 'groups', 'folks');
+        asort($translated);
+        $form->addHidden('action', 'action', 'text', 'add');
+        $form->addVariable(_("Name"), 'translated_name', 'radio', false, false, null, array($translated, true));
+        $form->addVariable(_("Name"), 'custom_name', 'text', false, false, _("Enter custom name"));
+
+        if ($form->validate()) {
+            $form->getInfo(null, $info);
+            if (empty($info['custom_name'])) {
+                $name = $info['translated_name'];
+            } else {
+                $name = $info['custom_name'];
+            }
+            $result = $friends->addGroup($name);
+            if ($result instanceof PEAR_Error) {
+                $notification->push($result);
+            } else {
+                if (empty($info['custom_name'])) {
+                    $name = $translated[$info['translated_name']];
+                }
+                $notification->push(sprintf(_("Group \"%s\" was success added."), $name), 'horde.success');
+                header('Location: ' . Horde::applicationUrl('edit/groups.php'));
+                exit;
+            }
+        }
+
+    break;
+}
+
+$remove_url = Util::addParameter(Horde::applicationUrl('edit/groups.php'), 'action', 'delete');
+$remove_img = Horde::img('delete.png', '', '', $registry->getImageDir('horde'));
+$edit_url = Util::addParameter(Horde::applicationUrl('edit/groups.php'), 'action', 'edit');
+$edit_img = Horde::img('edit.png', '', '', $registry->getImageDir('horde'));
+$perms_url = Horde::applicationUrl('perms.php');
+$perms_img = Horde::img('perms.png', '', '', $registry->getImageDir('horde'));
+
+Horde::addScriptFile('popup.js', 'horde', true);
+
+require FOLKS_TEMPLATES . '/common-header.inc';
+require FOLKS_TEMPLATES . '/menu.inc';
+
+echo $tabs->render('groups');
+require FOLKS_TEMPLATES . '/edit/groups.php';
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';
\ No newline at end of file
diff --git a/folks/templates/edit/groups.php b/folks/templates/edit/groups.php
new file mode 100644 (file)
index 0000000..a34663b
--- /dev/null
@@ -0,0 +1,22 @@
+<?php echo $form->renderActive(null, null, '', 'post'); ?>
+
+<h1 class="header"><?php echo $title ?></h1>
+<table id="groups" class="sortable striped">
+<thead>
+<tr>
+    <th><?php echo _("Group") ?></th>
+    <th><?php echo _("Actions") ?></th>
+</tr>
+</thead>
+<tbody>
+<?php
+foreach ($groups as $group_id => $grouo_name) {
+    echo '<tr><td>' . $grouo_name . '</td>';
+    echo '<td><a href="' . Util::addParameter($edit_url, 'g', $group_id) . '">' . $edit_img . ' ' . _("Rename") . '</a></td>';
+    echo '<td><a href="#" onclick="if (confirm(\'' . _("Do you really want to delete this group?") . '\')) {window.location=\'' .  Util::addParameter($remove_url, 'g', $group_id) . '\'}">' . $remove_img . ' ' . _("Delete") . '</a></td>';
+    echo '<td><a href="#" onclick="popup(\'' . Util::addParameter($perms_url, 'cid', $group_id) . '\')">' . $perms_img . ' ' .  _("Permissions") . '</a></td>';
+    echo '</tr>';
+}
+?>
+</tbody>
+</table>