1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: 13: 14: 15: 16:
17: class Horde_ActiveSync_Request_FolderCreate extends Horde_ActiveSync_Request_Base
18: {
19: 20: 21: 22: 23:
24: public function handle()
25: {
26: $el = $this->_decoder->getElement();
27: if ($el[Horde_ActiveSync_Wbxml::EN_TYPE] != Horde_ActiveSync_Wbxml::EN_TYPE_STARTTAG) {
28: return false;
29: }
30:
31: $create = $update = $delete = false;
32:
33: if ($el[Horde_ActiveSync_Wbxml::EN_TAG] == self::FOLDERHIERARCHY_FOLDERCREATE) {
34: $create = true;
35: } elseif ($el[Horde_ActiveSync_Wbxml::EN_TAG] == self::FOLDERHIERARCHY_FOLDERUPDATE) {
36: $update = true;
37: } elseif ($el[Horde_ActiveSync_Wbxml::EN_TAG] == self::FOLDERHIERARCHY_FOLDERDELETE) {
38: $delete = true;
39: }
40:
41: if (!$create && !$update && !$delete) {
42: return false;
43: }
44:
45:
46: if (!$this->_decoder->getElementStartTag(self::FOLDERHIERARCHY_SYNCKEY)) {
47: return false;
48: }
49: $synckey = $this->_decoder->getElementContent();
50: if (!$this->_decoder->getElementEndTag()) {
51: return false;
52: }
53:
54:
55: $serverid = false;
56: if ($this->_decoder->getElementStartTag(self::FOLDERHIERARCHY_SERVERENTRYID)) {
57: $serverid = $this->_decoder->getElementContent();
58: if (!$this->_decoder->getElementEndTag()) {
59: return false;
60: }
61: }
62:
63:
64: if (!$delete) {
65:
66: $parentid = false;
67: if ($this->_decoder->getElementStartTag(self::FOLDERHIERARCHY_PARENTID)) {
68: $parentid = $this->_decoder->getElementContent();
69: if (!$this->_decoder->getElementEndTag()) {
70: return false;
71: }
72: }
73:
74:
75: if (!$this->_decoder->getElementStartTag(self::FOLDERHIERARCHY_DISPLAYNAME)) {
76: return false;
77: }
78: $displayname = $this->_decoder->getElementContent();
79: if (!$this->_decoder->getElementEndTag()) {
80: return false;
81: }
82:
83:
84: $type = false;
85: if ($this->_decoder->getElementStartTag(self::FOLDERHIERARCHY_TYPE)) {
86: $type = $this->_decoder->getElementContent();
87: if (!$this->_decoder->getElementEndTag()) {
88: return false;
89: }
90: }
91: }
92:
93: if (!$this->_decoder->getElementEndTag()) {
94: return false;
95: }
96:
97:
98: try {
99: $syncstate = $this->_stateMachine->loadState($synckey);
100: $newsynckey = $this->_stateMachine->getNewSyncKey($synckey);
101: } catch (Horde_ActiveSync_Exception $e) {
102:
103: }
104:
105:
106: $seenfolders = unserialize($this->_stateMachine->loadState('s' . $synckey));
107: if (!$seenfolders) {
108: $seenfolders = array();
109: }
110:
111: $importer = $this->_driver->getHierarchyImporter();
112: $importer->Config($syncstate);
113:
114: if (!$delete) {
115:
116: $serverid = $importer->importFolderChange($serverid, $parentid, $displayname, $type);
117: } else {
118:
119: $deletedstat = $importer->importFolderDeletion($serverid, 0);
120: }
121:
122: $this->_encoder->startWBXML();
123: if ($create) {
124:
125: $seenfolders[] = $serverid;
126:
127: $this->_encoder->startTag(self::FOLDERHIERARCHY_FOLDERCREATE);
128:
129:
130: $this->_encoder->startTag(self::FOLDERHIERARCHY_STATUS);
131: $this->_encoder->content(1);
132: $this->_encoder->endTag();
133:
134: $this->_encoder->startTag(self::FOLDERHIERARCHY_SYNCKEY);
135: $this->_encoder->content($newsynckey);
136: $this->_encoder->endTag();
137:
138: $this->_encoder->startTag(self::FOLDERHIERARCHY_SERVERENTRYID);
139: $this->_encoder->content($serverid);
140: $this->_encoder->endTag();
141:
142: $this->_encoder->endTag();
143:
144: $this->_encoder->endTag();
145: } elseif ($update) {
146:
147: $this->_encoder->startTag(self::FOLDERHIERARCHY_FOLDERUPDATE);
148:
149: $this->_encoder->startTag(self::FOLDERHIERARCHY_STATUS);
150: $this->_encoder->content(1);
151: $this->_encoder->endTag();
152:
153: $this->_encoder->startTag(self::FOLDERHIERARCHY_SYNCKEY);
154: $this->_encoder->content($newsynckey);
155: $this->_encoder->endTag();
156:
157: $this->_encoder->endTag();
158: } elseif ($delete) {
159: $this->_encoder->startTag(self::FOLDERHIERARCHY_FOLDERDELETE);
160:
161: $this->_encoder->startTag(self::FOLDERHIERARCHY_STATUS);
162: $this->_encoder->content($deletedstat);
163: $this->_encoder->endTag();
164:
165: $this->_encoder->startTag(self::FOLDERHIERARCHY_SYNCKEY);
166: $this->_encoder->content($newsynckey);
167: $this->_encoder->endTag();
168:
169: $this->_encoder->endTag();
170:
171:
172: if (($sid = array_search($serverid, $seenfolders)) !== false) {
173: unset($seenfolders[$sid]);
174: $seenfolders = array_values($seenfolders);
175: $this->_logger->debug('Deleted from seenfolders: ' . $serverid);
176: }
177: }
178:
179: $this->_encoder->endTag();
180:
181: $this->_stateMachine->setState($newsynckey, $importer->GetState());
182: $this->_stateMachine->setState('s' . $newsynckey, serialize($seenfolders));
183: $this->_stateMachine->save();
184:
185: return true;
186: }
187: }