~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/cart/classes/CartHelper.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: CartHelper.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
22
22
 
23
23
/**
24
24
 * @package Cart
25
 
 * @version $Revision: 1.11 $ $Date: 2005/09/03 13:44:59 $
 
25
 * @version $Revision: 1.13 $ $Date: 2006/01/10 04:38:59 $
26
26
 * @author Bharat Mediratta <bharat@menalto.com>
27
27
 */
28
28
 
52
52
            $cartItemIds = array();
53
53
        }
54
54
 
55
 
        return array(GalleryStatus::success(), $cartItemIds);
 
55
        return array(null, $cartItemIds);
56
56
    }
57
57
 
58
58
    /**
59
59
     * Add the item ids to the user's cart
60
 
     * (Note that permissions should be checked in advance; this function does not check)
 
60
     * (Note that view permission should be checked in advance; this function only checks
 
61
     *  cart.add permission)
61
62
     *
62
63
     * @param array int item ids
63
64
     * @return object GalleryStatus a status code
65
66
     */
66
67
    function addItemsToCart($ids) {
67
68
        list ($ret, $cartItemIds) = CartHelper::fetchCartItemCounts();
68
 
        if ($ret->isError()) {
 
69
        if ($ret) {
69
70
            return $ret->wrap(__FILE__, __LINE__);
70
71
        }
71
72
 
 
73
        if (!empty($ids)) {
 
74
            $ret = GalleryCoreApi::studyPermissions($ids);
 
75
            if ($ret) {
 
76
                return $ret->wrap(__FILE__, __LINE__);
 
77
            }
 
78
        }
 
79
 
72
80
        foreach ($ids as $id) {
73
 
            if (isset($cartItemIds[$id])) {
74
 
                $cartItemIds[$id]++;
75
 
            } else {
76
 
                $cartItemIds[$id] = 1;
 
81
            list ($ret, $canAdd) = GalleryCoreApi::hasItemPermission($id, 'cart.add');
 
82
            if ($ret) {
 
83
                return $ret->wrap(__FILE__, __LINE__);
 
84
            }
 
85
            if ($canAdd) {
 
86
                if (isset($cartItemIds[$id])) {
 
87
                    $cartItemIds[$id]++;
 
88
                } else {
 
89
                    $cartItemIds[$id] = 1;
 
90
                }
77
91
            }
78
92
        }
79
93
 
80
94
        $ret = CartHelper::setCartItemCounts($cartItemIds);
81
 
        if ($ret->isError()) {
 
95
        if ($ret) {
82
96
            return $ret->wrap(__FILE__, __LINE__);
83
97
        }
84
98
 
85
 
        return GalleryStatus::success();
 
99
        return null;
86
100
    }
87
101
 
88
102
    /**
102
116
            $session->put('cart.itemIds', $cartItemIds);
103
117
        }
104
118
 
105
 
        return GalleryStatus::success();
 
119
        return null;
106
120
    }
107
121
 
108
122
    /**
115
129
     */
116
130
    function loadCartItems() {
117
131
        list ($ret, $cartItemIds) = CartHelper::fetchCartItemCounts();
118
 
        if ($ret->isError()) {
 
132
        if ($ret) {
119
133
            return array($ret->wrap(__FILE__, __LINE__), null);
120
134
        }
121
135
        $idList = array_keys($cartItemIds);
122
136
        if (!empty($cartItemIds)) {
123
137
            $ret = GalleryCoreApi::studyPermissions($idList);
124
 
            if ($ret->isError()) {
 
138
            if ($ret) {
125
139
                return array($ret->wrap(__FILE__, __LINE__), null);
126
140
            }
127
141
        }
129
143
        $items = array();
130
144
        foreach ($idList as $itemId) {
131
145
            list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId);
132
 
            if ($ret->isError()) {
 
146
            if ($ret) {
133
147
                if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) {
134
148
                    /* Item deleted from the gallery; remove it from the cart */
135
149
                    unset($cartItemIds[$itemId]);
140
154
                }
141
155
            }
142
156
            list ($ret, $canView) = GalleryCoreApi::hasItemPermission($itemId, 'core.view');
143
 
            if ($ret->isError()) {
 
157
            if ($ret) {
144
158
                return array($ret->wrap(__FILE__, __LINE__), null);
145
159
            }
146
160
            if ($canView) {
152
166
        }
153
167
        if ($changed) {
154
168
            $ret = CartHelper::setCartItemCounts($cartItemIds);
155
 
            if ($ret->isError()) {
 
169
            if ($ret) {
156
170
                return array($ret->wrap(__FILE__, __LINE__), null);
157
171
            }
158
172
        }
159
173
    
160
 
        return array(GalleryStatus::success(), $items);
 
174
        return array(null, $items);
161
175
    }
162
176
}
163
177
?>