1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: 11: 12: 13: 14:
15: class Horde_ActiveSync_Request_GetItemEstimate extends Horde_ActiveSync_Request_Base
16: {
17:
18: const STATUS_SUCCESS = 1;
19: const STATUS_INVALIDCOL = 2;
20: const STATUS_NOTPRIMED = 3;
21: const STATUS_KEYMISM = 4;
22:
23:
24: const GETITEMESTIMATE = 'GetItemEstimate:GetItemEstimate';
25: const VERSION = 'GetItemEstimate:Version';
26: const FOLDERS = 'GetItemEstimate:Folders';
27: const FOLDER = 'GetItemEstimate:Folder';
28: const FOLDERTYPE = 'GetItemEstimate:FolderType';
29: const FOLDERID = 'GetItemEstimate:FolderId';
30: const DATETIME = 'GetItemEstimate:DateTime';
31: const ESTIMATE = 'GetItemEstimate:Estimate';
32: const RESPONSE = 'GetItemEstimate:Response';
33: const STATUS = 'GetItemEstimate:Status';
34:
35: 36: 37: 38: 39: 40:
41: public function handle()
42: {
43: parent::handle();
44: $this->_logger->info('[' . $this->_device->id . '] Beginning GETITEMESTIMATE');
45:
46:
47: if (!$this->checkPolicyKey($this->_activeSync->getPolicyKey())) {
48: return false;
49: }
50:
51: $status = array();
52: $collections = array();
53: if (!$this->_decoder->getElementStartTag(self::GETITEMESTIMATE) ||
54: !$this->_decoder->getElementStartTag(self::FOLDERS)) {
55:
56:
57: return false;
58: }
59:
60:
61: while ($this->_decoder->getElementStartTag(self::FOLDER)) {
62:
63:
64: $cStatus = self::STATUS_SUCCESS;
65:
66:
67: if (!$this->_decoder->getElementStartTag(self::FOLDERTYPE)) {
68: return false;
69: }
70: $class = $this->_decoder->getElementContent();
71: if (!$this->_decoder->getElementEndTag()) {
72: return false;
73: }
74:
75:
76: if ($this->_decoder->getElementStartTag(self::FOLDERID)) {
77: $collectionid = $this->_decoder->getElementContent();
78: if (!$this->_decoder->getElementEndTag()) {
79: return false;
80: }
81: }
82:
83:
84: if (!$this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE)) {
85: return false;
86: }
87: $filtertype = $this->_decoder->getElementContent();
88: if (!$this->_decoder->getElementEndTag()) {
89: return false;
90: }
91:
92:
93: if (!$this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SYNCKEY)) {
94: return false;
95: }
96: $synckey = $this->_decoder->getElementContent();
97: if (empty($synckey)) {
98: $cStatus = self::STATUS_NOTPRIMED;
99: }
100: if (!$this->_decoder->getElementEndTag()) {
101: return false;
102: }
103:
104:
105: if (!$this->_decoder->getElementEndTag()) {
106: return false;
107: }
108:
109:
110: $collection = array();
111: $collection['synckey'] = $synckey;
112: $collection['class'] = $class;
113: $collection['filtertype'] = $filtertype;
114:
115:
116: if (!isset($collectionid)) {
117: $collectionid = $this->_state>getFolderData($this->_device->id, $collection['class']);
118: }
119: $collection['id'] = $collectionid;
120: $status[$collection['id']] = $cStatus;
121:
122: array_push($collections, $collection);
123: }
124:
125: $this->_encoder->startWBXML();
126:
127:
128: $this->_encoder->startTag(self::GETITEMESTIMATE);
129: foreach ($collections as $collection) {
130: $this->_state->init($collection);
131: try {
132: $this->_state->loadState($collection['synckey']);
133: } catch (Horde_ActiveSync_Exception $e) {
134: $status[$collection['id']] = self::STATUS_KEYMISM;
135: }
136: $this->_encoder->startTag(self::RESPONSE);
137: $this->_encoder->startTag(self::STATUS);
138: $this->_encoder->content($status[$collection['id']]);
139: $this->_encoder->endTag();
140: $this->_encoder->startTag(self::FOLDER);
141: $this->_encoder->startTag(self::FOLDERTYPE);
142: $this->_encoder->content($collection['class']);
143: $this->_encoder->endTag();
144: $this->_encoder->startTag(self::FOLDERID);
145: $this->_encoder->content($collection['id']);
146: $this->_encoder->endTag();
147: $this->_encoder->startTag(self::ESTIMATE);
148: $sync = $this->_driver->getSyncObject();
149: $sync->init($this->_state, null, $collection);
150: $this->_encoder->content($sync->GetChangeCount());
151: $this->_encoder->endTag();
152: $this->_encoder->endTag();
153: $this->_encoder->endTag();
154: }
155: $this->_encoder->endTag();
156:
157: return true;
158: }
159:
160: }
161: