~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to services/portal/edit.php

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * $Horde: horde/services/portal/edit.php,v 1.44.8.1 2005/01/03 12:25:46 jan Exp $
 
4
 *
 
5
 * Copyright 1999-2005 Chuck Hagenbuch <chuck@horde.org>
 
6
 * Copyright 2003-2005 Mike Cochrane <mike@graftonhall.co.nz>
 
7
 * Copyright 2003-2005 Jan Schneider <jan@horde.org>
 
8
 *
 
9
 * See the enclosed file COPYING for license information (LGPL). If you
 
10
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 
11
 */
 
12
 
 
13
@define('HORDE_BASE', dirname(__FILE__) . '/../..');
 
14
require_once HORDE_BASE . '/lib/base.php';
 
15
require_once 'Horde/Block.php';
 
16
require_once 'Horde/Block/Collection.php';
 
17
require_once 'Horde/Block/Layout.php';
 
18
require_once 'Horde/Identity.php';
 
19
require_once 'Horde/Help.php';
 
20
 
 
21
if (!Auth::isAuthenticated()) {
 
22
    Horde::authenticationFailureRedirect();
 
23
}
 
24
 
 
25
// Get form values.
 
26
$col = (int)Util::getFormData('col');
 
27
$row = (int)Util::getFormData('row');
 
28
$action = Util::getFormData('action');
 
29
$edit_row = null;
 
30
$edit_col = null;
 
31
 
 
32
// Get full name for title.
 
33
$identity = &Identity::singleton();
 
34
$fullname = $identity->getValue('fullname');
 
35
if (empty($fullname)) {
 
36
    $fullname = Auth::getAuth();
 
37
}
 
38
 
 
39
// Instantiate the blocks objects.
 
40
$blocks = &Horde_Block_Collection::singleton('portal');
 
41
$layout = &Horde_Block_Layout::singleton();
 
42
 
 
43
// Handle requested actions.
 
44
switch ($action) {
 
45
case 'moveUp':
 
46
case 'moveDown':
 
47
case 'moveLeft':
 
48
case 'moveRight':
 
49
case 'expandUp':
 
50
case 'expandDown':
 
51
case 'expandLeft':
 
52
case 'expandRight':
 
53
case 'shrinkLeft':
 
54
case 'shrinkRight':
 
55
case 'shrinkUp':
 
56
case 'shrinkDown':
 
57
case 'removeBlock':
 
58
    $result = call_user_func(array(&$layout, $action), $row, $col);
 
59
    if (is_a($result, 'PEAR_Error')) {
 
60
        $notification->push($result);
 
61
    } else {
 
62
        $layout->save();
 
63
    }
 
64
    break;
 
65
 
 
66
// Save the changes made to a block.
 
67
case 'save':
 
68
// Save the changes made to a block and continue editing.
 
69
case 'save-resume':
 
70
    // Get requested block type.
 
71
    list($newapp, $newtype) = explode(':', Util::getFormData('app'));
 
72
 
 
73
    // Is this a new block?
 
74
    $new = false;
 
75
    if ($layout->isEmpty($row, $col) ||
 
76
        !$layout->rowExists($row) ||
 
77
        !$layout->colExists($col)) {
 
78
        $new = true;
 
79
        // Make sure there is somewhere to put it.
 
80
        $layout->addBlock($row, $col);
 
81
    }
 
82
 
 
83
    // Or an existing one?
 
84
    $exists = false;
 
85
    $changed = false;
 
86
    if (!$new) {
 
87
        // Get target block info.
 
88
        $info = $layout->getBlockInfo($row, $col);
 
89
        $exists = $layout->isBlock($row, $col);
 
90
        // Has a different block been selected?
 
91
        if ($exists &&
 
92
            ($info['app'] != $newapp ||
 
93
             $info['block'] != $newtype)) {
 
94
            $changed = true;
 
95
        }
 
96
    }
 
97
 
 
98
    if ($new || $changed) {
 
99
        // Change app or type.
 
100
        $info = array();
 
101
        $info['app'] = $newapp;
 
102
        $info['block'] = $newtype;
 
103
        $params = $blocks->getParams($newapp, $newtype);
 
104
        foreach ($params as $newparam) {
 
105
            $info['params'][$newparam] = $blocks->getDefaultValue($newapp, $newtype, $newparam);
 
106
        }
 
107
        $layout->setBlockInfo($row, $col, $info);
 
108
    } elseif ($exists) {
 
109
        // Change values.
 
110
        $layout->setBlockInfo($row, $col, array('params' => Util::getFormData('params', array())));
 
111
    }
 
112
    $layout->save();
 
113
    if ($action == 'save') {
 
114
        break;
 
115
    }
 
116
 
 
117
// Make a block the current block for editing.
 
118
case 'edit':
 
119
    $edit_row = $row;
 
120
    $edit_col = $col;
 
121
    break;
 
122
}
 
123
 
 
124
$title = _("My Portal Layout");
 
125
require HORDE_TEMPLATES . '/common-header.inc';
 
126
require HORDE_TEMPLATES . '/portal/menu.inc';
 
127
$notification->notify(array('listeners' => 'status'));
 
128
require HORDE_TEMPLATES . '/portal/edit.inc';
 
129
require HORDE_TEMPLATES . '/common-footer.inc';