1: <?php
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: class Horde_Kolab_Cli_Module_Folder
29: implements Horde_Kolab_Cli_Module
30: {
31: 32: 33: 34: 35:
36: public function getUsage()
37: {
38: return Horde_Kolab_Cli_Translation::t(" folder - Handle a single folder (the default action is \"show\")
39:
40: - show PATH : Display information about the folder at PATH.
41: - create PATH [TYPE] : Create the folder PATH (with the optional type TYPE).
42: - delete PATH : Delete the folder PATH.
43: - rename OLD NEW : Rename the folder from OLD to NEW.
44: - getacl PATH : Get all ACL on the specified folder.
45: - getmyacl PATH : Get your ACL on the specified folder.
46: - setacl PATH USER ACL: Set the ACL for the specified user on the folder.
47: - deleteacl PATH USER ACL: Delete the ACL for the specified user on the folder.
48: - getdesc PATH : Return the share description of the specified folder.
49: - setdesc PATH DESC : Set the share description of the specified folder to DESC.
50: - getshare PATH : Return the share parameters of the specified folder.
51:
52:
53: ");
54: }
55:
56: 57: 58: 59: 60: 61:
62: public function getBaseOptions()
63: {
64: return array();
65: }
66:
67: 68: 69: 70: 71:
72: public function hasOptionGroup()
73: {
74: return false;
75: }
76:
77: 78: 79: 80: 81:
82: public function getOptionGroupTitle()
83: {
84: return '';
85: }
86:
87: 88: 89: 90: 91:
92: public function getOptionGroupDescription()
93: {
94: return '';
95: }
96:
97: 98: 99: 100: 101:
102: public function getOptionGroupOptions()
103: {
104: return array();
105: }
106:
107: 108: 109: 110: 111: 112: 113: 114: 115:
116: public function handleArguments(&$options, &$arguments, &$world)
117: {
118: }
119:
120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130: public function run($cli, $options, $arguments, &$world)
131: {
132: if (!isset($arguments[1])) {
133: $action = 'show';
134: } else {
135: $action = $arguments[1];
136: }
137: if (!isset($arguments[2])) {
138: $folder_name = 'INBOX';
139: } else {
140: $folder_name = $arguments[2];
141: }
142: switch ($action) {
143: case 'create':
144: if (!isset($arguments[3])) {
145: $folder = $world['storage']->getList()
146: ->createFolder($folder_name);
147: } else {
148: $folder = $world['storage']->getList()
149: ->createFolder($folder_name, $arguments[3]);
150: }
151: $this->_showFolder($folder_name, $world, $cli);
152: break;
153: case 'rename':
154: $folder = $world['storage']->getList()
155: ->renameFolder($folder_name, $arguments[3]);
156: $this->_showFolder($arguments[3], $world, $cli);
157: break;
158: case 'delete':
159: $folder = $world['storage']->getList()
160: ->deleteFolder($folder_name);
161: break;
162: case 'getacl':
163: $acl = $world['storage']->getList()
164: ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
165: ->getAcl($folder_name);
166: $cli->writeln($folder_name);
167: $cli->writeln(str_repeat('=', strlen($folder_name)));
168: $pad = max(array_map('strlen', array_keys($acl))) + 2;
169: foreach ($acl as $user => $rights) {
170: $cli->writeln(Horde_String::pad($user . ':', $pad) . $rights);
171: }
172: break;
173: case 'getmyacl':
174: $acl = $world['storage']->getList()
175: ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
176: ->getMyAcl($folder_name);
177: $cli->writeln('Your rights on ' . $folder_name . ': ' . $acl);
178: break;
179: case 'setacl':
180: $acl = $world['storage']->getList()
181: ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
182: ->setAcl($folder_name, $arguments[3], $arguments[4]);
183: break;
184: case 'deleteacl':
185: $acl = $world['storage']->getList()
186: ->getQuery(Horde_Kolab_Storage_List::QUERY_ACL)
187: ->deleteAcl($folder_name, $arguments[3]);
188: break;
189: case 'getdesc':
190: $list = $world['storage']->getList();
191: $world['storage']->addListQuery(
192: $list,
193: Horde_Kolab_Storage_List::QUERY_SHARE
194: );
195: $cli->writeln(
196: $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)
197: ->getDescription($folder_name)
198: );
199: break;
200: case 'setdesc':
201: $list = $world['storage']->getList();
202: $world['storage']->addListQuery(
203: $list,
204: Horde_Kolab_Storage_List::QUERY_SHARE
205: );
206: $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)
207: ->setDescription($folder_name, $arguments[3]);
208: break;
209: case 'getshare':
210: $list = $world['storage']->getList();
211: $world['storage']->addListQuery(
212: $list,
213: Horde_Kolab_Storage_List::QUERY_SHARE
214: );
215: $parameters = $list->getQuery(Horde_Kolab_Storage_List::QUERY_SHARE)
216: ->getParameters($folder_name);
217: $pad = max(array_map('strlen', array_keys($parameters))) + 2;
218: foreach ($parameters as $key => $value) {
219: $cli->writeln(Horde_String::pad($key . ':', $pad) . $value);
220: }
221: break;
222: case 'show':
223: $this->_showFolder($folder_name, $world, $cli);
224: break;
225: default:
226: $cli->message(
227: sprintf(
228: Horde_Kolab_Cli_Translation::t('Action %s not supported!'),
229: $action
230: ),
231: 'cli.error'
232: );
233: break;
234: }
235: }
236:
237: private function _showFolder($folder_name, $world, $cli)
238: {
239: $folder = $world['storage']->getList()->getFolder($folder_name);
240: $cli->writeln('Path: ' . $folder->getPath());
241: $cli->writeln('Title: ' . $folder->getTitle());
242: $cli->writeln('Owner: ' . $folder->getOwner());
243: $cli->writeln('Type: ' . $folder->getType());
244: $cli->writeln('Parent: ' . $folder->getParent());
245: $cli->writeln('Namespace: ' . $folder->getNamespace());
246: }
247: }