diff --git a/admin/inc/class.admin_egw_acl_record.inc.php b/admin/inc/class.admin_egw_acl_record.inc.php new file mode 100644 index 0000000000..3e2d9eaca4 --- /dev/null +++ b/admin/inc/class.admin_egw_acl_record.inc.php @@ -0,0 +1,162 @@ + array('acl_appname'), + 'select-account' => array('acl_account', 'acl_location'), + 'select-bool' => array('acl1', 'acl2','acl4','acl8','acl16','acl64','acl128','acl256'), + ); + + /** + * constructor + * reads record from backend if identifier is given. + * + * @param string $_identifier + */ + public function __construct( $_identifier='' ) { + if(is_array($_identifier)) { + $this->identifier = $_identifier['id']; + $this->set_record($_identifier); + } else { + $this->identifier = $_identifier; + //$GLOBALS['egw']->acl->read($this->identifier); + } + } + + /** + * magic method to set attributes of record + * + * @param string $_attribute_name + */ + public function __get($_attribute_name) { + return $this->record[$_attribute_name]; + } + + /** + * magig method to set attributes of record + * + * @param string $_attribute_name + * @param data $data + */ + public function __set($_attribute_name, $data) { + $this->record[$_attribute_name] = $data; + } + + /** + * converts this object to array. + * @abstract We need such a function cause PHP5 + * dosn't allow objects do define it's own casts :-( + * once PHP can deal with object casts we will change to them! + * + * @return array complete record as associative array + */ + public function get_record_array() { + return $this->record; + } + + /** + * gets title of record + * + *@return string title + */ + public function get_title() { + return Api\Accounts::username($this->identifier); + } + + /** + * sets complete record from associative array + * + * @todo add some checks + * @return void + */ + public function set_record(array $_record) { + $this->record = $_record; + } + + /** + * gets identifier of this record + * + * @return string identifier of current record + */ + public function get_identifier() { + return $this->identifier; + } + + /** + * Gets the URL icon representitive of the record + * This could be as general as the application icon, or as specific as a contact photo + * + * @return string Full URL of an icon, or appname/icon_name + */ + public function get_icon() { + return 'access'; + } + + /** + * saves record into backend + * + * @return string identifier + */ + public function save ( $_dst_identifier ) { + unset($_dst_identifier); // not used, but require by function signature + } + + /** + * copies current record to record identified by $_dst_identifier + * + * @param string $_dst_identifier + * @return string dst_identifier + */ + public function copy ( $_dst_identifier ) { + unset($_dst_identifier); // not used, but require by function signature + } + + /** + * moves current record to record identified by $_dst_identifier + * $this will become moved record + * + * @param string $_dst_identifier + * @return string dst_identifier + */ + public function move ( $_dst_identifier ) { + unset($_dst_identifier); // not used, but require by function signature + } + + /** + * delets current record from backend + * + */ + public function delete () { + + } + + /** + * destructor + * + */ + public function __destruct() { + unset ($this->record); + } +} diff --git a/admin/inc/class.admin_export_acl_csv.inc.php b/admin/inc/class.admin_export_acl_csv.inc.php new file mode 100644 index 0000000000..9cc36f76e0 --- /dev/null +++ b/admin/inc/class.admin_export_acl_csv.inc.php @@ -0,0 +1,189 @@ +plugin_options; + + + $selection = array(); + $query = array( + 'filter' => 'other', + 'filter2' => $_definition->filter['acl_appname'] ? $_definition->filter['acl_appname'] : '', + 'acl_rights' => Hooks::process(array( + 'location' => 'acl_rights' + )) + ); + if($_definition->filter['acl_location']) + { + $query['col_filter']['acl_location'] = $_definition->filter['acl_location']; + } + + // ACL queries only go by one account at a time, so we collect for all + if($_definition->filter['acl_account']) + { + $accounts = array_flip($_definition->filter['acl_account']); + } + else + { + $account_query = array( + 'type' => 'both', + 'active' => $_definition->filter['active'] + ); + $accounts = $GLOBALS['egw']->accounts->search($account_query); + } + foreach($accounts as $account_id => $account_data) + { + $query['account_id'] = $account_id; + $account_acl = array(); + admin_acl::get_rows($query, $account_acl); + $selection = array_merge($selection, $account_acl); + } + + $options['begin_with_fieldnames'] = true; + $export_object = new importexport_export_csv($_stream, (array)$options); + $export_object->set_mapping($options['mapping']); + + $lookups = array( + 'acl_appname' => Select::app_options('installed') + ); + if($selection['sel_options']) + { + $lookups += $selection['sel_options']; + unset($selection['sel_options']); + } + $selection = array_map("unserialize", array_unique(array_map("serialize", $selection))); + + // $_record is an array, that's what search() returns + foreach ($selection as $_record) + { + $record = new admin_egw_acl_record($_record); + // Add in field for all ACLs + $all_acls = array(); + foreach($record->get_record_array() as $key => $value) + { + if(strpos($key, '_') === FALSE && !in_array($key, array('id'))) + { + $all_acls[] = $value; + } + } + + if($options['convert']) + { + importexport_export_csv::convert($record, admin_egw_acl_record::$types, 'admin', $lookups); + } + else + { + // Implode arrays, so they don't say 'Array' + foreach($record->get_record_array() as $key => $value) + { + if(is_array($value)) $record->$key = implode(',', $value); + } + } + $record->all_acls = implode(',', $all_acls); + + $export_object->export_record($record); + unset($record); + } + return $export_object; + } + + /** + * returns translated name of plugin + * + * @return string name + */ + public static function get_name() + { + return lang('ACL CSV export'); + } + + /** + * returns translated (user) description of plugin + * + * @return string descriprion + */ + public static function get_description() + { + return lang("Exports permission settings into a CSV File. "); + } + + /** + * returns file suffix for exported file + * + * @return string suffix + */ + public static function get_filesuffix() + { + return 'csv'; + } + + public static function get_mimetype() + { + return 'text/csv'; + } + + /** + * return html for options. + * this way the plugin has all opportunities for options tab + * + * @return string html + */ + public function get_options_etpl() + { + return false; + } + + /** + * returns slectors of this plugin via xajax + * + */ + public function get_selectors_etpl() + { + return array( + 'name' => 'importexport.export_csv_selectors', + 'content' => array( + 'selection' => 'all', + 'no_search' => true + ), + 'sel_options' => array( + 'acl_appname' => Select::app_options('installed') + ), + 'readonlys' => array( + // 'search' => true + ) + //'preserv' => array('no_error_for_all'), + ); + } + /** + * Get the class name for the egw_record to use while exporting + * + * @return string; + */ + public static function get_egw_record_class() + { + return 'admin_egw_acl_record'; + } +} diff --git a/admin/inc/class.admin_wizard_export_acl_csv.inc.php b/admin/inc/class.admin_wizard_export_acl_csv.inc.php new file mode 100644 index 0000000000..ad125f23bf --- /dev/null +++ b/admin/inc/class.admin_wizard_export_acl_csv.inc.php @@ -0,0 +1,39 @@ +export_fields = array( + 'acl_account' => lang('Account'), + 'acl_appname' => lang('Application'), + 'acl_location' => lang('Data from'), + 'all_acls' => lang('All ACLs'), + 'acl1' => lang('Read'), + 'acl2' => lang('Add'), + 'acl4' => lang('Edit'), + 'acl8' => lang('Delete'), + 'acl16' => lang('Private'), + 'acl64' => lang('Custom') .' 1', + 'acl128' => lang('Custom') .' 2', + 'acl256' => lang('Custom') .' 3', + ); + + // Custom fields - not possible for ACL + unset($this->export_fields['customfields']); + } +} diff --git a/importexport/templates/default/export_csv_selectors.xet b/importexport/templates/default/export_csv_selectors.xet index f2e544d041..0e2c4f5f1d 100644 --- a/importexport/templates/default/export_csv_selectors.xet +++ b/importexport/templates/default/export_csv_selectors.xet @@ -11,7 +11,7 @@ - +