1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
/**
* $Horde: mnemo/notepads.php,v 1.31.2.5 2006/01/01 21:29:05 jan Exp $
*
* Copyright 2002-2006 Joel Vandal <jvandal@infoteck.qc.ca>
* Copyright 2002-2006 Mike Cochrane <mike@graftonhall.co.nz>
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/asl.php.
*
* @author Joel Vandal <jvandal@infoteck.qc.ca>
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @since Mnemo 2.0
* @package Mnemo
*/
@define('MNEMO_BASE', dirname(__FILE__));
require_once MNEMO_BASE . '/lib/base.php';
/* Exit if this isn't an authenticated user. */
if (!Auth::getAuth()) {
require MNEMO_BASE . '/list.php';
exit;
}
/* Run through the action handlers. */
$actionID = Util::getFormData('actionID');
switch ($actionID) {
case 'save':
$to_edit = Util::getFormData('edit_share');
$id = Util::getFormData('id');
if (empty($id)) {
$notification->push(_("Notepads must have a name."), 'horde.error');
break;
}
$notepad = '';
if (!strlen($to_edit)) {
/* Create New Share. */
$notepad = $GLOBALS['mnemo_shares']->newShare(md5(microtime()));
$notepad->set('name', $id);
$notepad->set('desc', Util::getFormData('description', ''));
$result = $GLOBALS['mnemo_shares']->addShare($notepad);
if (is_a($result, 'PEAR_Error')) {
$notification->push(sprintf(_("The notepad \"%s\" couldn't be created: %s"), $id, $result->getMessage()), 'horde.error');
} else {
$notification->push(sprintf(_("The notepad \"%s\" has been created."), $id), 'horde.success');
}
} else {
$notepad = &$GLOBALS['mnemo_shares']->getShare($to_edit);
$notepad->set('name', $id);
$notepad->set('desc', Util::getFormData('description', ''));
$notepad->save();
$notification->push(sprintf(_("The notepad \"%s\" has been saved."), $id), 'horde.success');
}
unset($to_edit);
break;
case 'delete':
$to_delete = Util::getFormData('edit_share');
if (!$to_delete) {
$notification->push(_("You must select a notepad to be deleted."), 'horde.warning');
break;
}
$share = $GLOBALS['mnemo_shares']->getShare($to_delete);
if (is_a($share, 'PEAR_Error')) {
$notification->push($share, 'horde.error');
break;
}
/* Delete the notepad. */
require_once MNEMO_BASE . '/lib/Driver.php';
$storage = &Mnemo_Driver::singleton($to_delete);
$result = $storage->deleteAll();
if (is_a($result, 'PEAR_Error')) {
$notification->push(sprintf(_("Unable to delete \"%s\": %s"), $share->get('name'), $result->getMessage()), 'horde.error');
break;
} else {
/* Remove share and all groups/permissions. */
$GLOBALS['mnemo_shares']->removeShare($share);
$notification->push(sprintf(_("The notepad \"%s\" has been deleted."), $share->get('name')), 'horde.success');
}
/* Make sure we still own at least one notepad. */
if (!count(Mnemo::listNotepads(true))) {
/* If this share doesn't exist then create it. */
if (!$GLOBALS['mnemo_shares']->exists(Auth::getAuth())) {
require_once 'Horde/Identity.php';
$identity = &Identity::singleton();
$name = $identity->getValue('fullname');
if (trim($name) == '') {
$name = Auth::removeHook(Auth::getAuth());
}
$share = $GLOBALS['mnemo_shares']->newShare(Auth::getAuth());
$share->set('name', sprintf(_("%s's Notepad"), $name));
$GLOBALS['mnemo_shares']->addShare($share);
}
}
break;
}
/* Personal Note Lists */
$personal_notepads = Mnemo::listNotepads(true);
Horde::addScriptFile('popup.js', 'horde', true);
$title = _("Note Lists");
require MNEMO_TEMPLATES . '/common-header.inc';
require MNEMO_TEMPLATES . '/menu.inc';
require MNEMO_TEMPLATES . '/notepads/notepads.inc';
require $registry->get('templates', 'horde') . '/common-footer.inc';
|