@@ -24,7 +24,8 @@ |
||
| 24 | 24 | * So this interface just garanties the interaction with userinterfaces. It |
| 25 | 25 | * has nothing to do with datatypes. |
| 26 | 26 | */ |
| 27 | -interface importexport_iface_import_plugin { |
|
| 27 | +interface importexport_iface_import_plugin |
|
| 28 | +{ |
|
| 28 | 29 | |
| 29 | 30 | /** |
| 30 | 31 | * imports entries according to given definition object. |
@@ -90,14 +90,22 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * Called from framework so Import / Export can add links into other apps' sidebox. |
| 92 | 92 | */ |
| 93 | - public static function other_apps() { |
|
| 94 | - if(!$GLOBALS['egw_info']['user']['apps']['importexport']) return array(); |
|
| 95 | - if($GLOBALS['egw_info']['flags']['no_importexport'] === true) return array(); |
|
| 93 | + public static function other_apps() |
|
| 94 | + { |
|
| 95 | + if(!$GLOBALS['egw_info']['user']['apps']['importexport']) |
|
| 96 | + { |
|
| 97 | + return array(); |
|
| 98 | + } |
|
| 99 | + if($GLOBALS['egw_info']['flags']['no_importexport'] === true) |
|
| 100 | + { |
|
| 101 | + return array(); |
|
| 102 | + } |
|
| 96 | 103 | |
| 97 | 104 | $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 98 | 105 | $cache = Api\Cache::getCache(Api\Cache::SESSION, 'importexport', 'sidebox_links'); |
| 99 | 106 | |
| 100 | - if(!$cache[$appname] && $GLOBALS['egw_info']['user']['apps']['importexport']) { |
|
| 107 | + if(!$cache[$appname] && $GLOBALS['egw_info']['user']['apps']['importexport']) |
|
| 108 | + { |
|
| 101 | 109 | $cache[$appname]['import'] = importexport_helper_functions::has_definitions($appname, 'import'); |
| 102 | 110 | $cache[$appname]['export'] = importexport_helper_functions::has_definitions($appname, 'export'); |
| 103 | 111 | Api\Cache::setCache(Api\Cache::SESSION, 'importexport', 'sidebox_links', $cache); |
@@ -117,7 +125,8 @@ discard block |
||
| 117 | 125 | 'app' => 'importexport', |
| 118 | 126 | 'text' => in_array($appname, array('sitemgr')) || count($plugins[$appname]['import']) > 1 ? 'Import' : 'Import CSV' |
| 119 | 127 | ); |
| 120 | - if($GLOBALS['egw_info']['flags']['disable_importexport']['import']) { |
|
| 128 | + if($GLOBALS['egw_info']['flags']['disable_importexport']['import']) |
|
| 129 | + { |
|
| 121 | 130 | $file['Import CSV']['link'] = ''; |
| 122 | 131 | } |
| 123 | 132 | } |
@@ -134,7 +143,8 @@ discard block |
||
| 134 | 143 | 'app' => 'importexport', |
| 135 | 144 | 'text' => in_array($appname, array('sitemgr')) || count($plugins[$appname]['export']) > 1 ? 'Export' : 'Export CSV' |
| 136 | 145 | ); |
| 137 | - if($GLOBALS['egw_info']['flags']['disable_importexport']['export']) { |
|
| 146 | + if($GLOBALS['egw_info']['flags']['disable_importexport']['export']) |
|
| 147 | + { |
|
| 138 | 148 | $file['Export CSV']['link'] = ''; |
| 139 | 149 | } |
| 140 | 150 | } |
@@ -142,15 +152,17 @@ discard block |
||
| 142 | 152 | $config = Api\Config::read('importexport'); |
| 143 | 153 | if($appname != 'admin' && ($config['users_create_definitions'] || $GLOBALS['egw_info']['user']['apps']['admin']) && |
| 144 | 154 | count(importexport_helper_functions::get_plugins($appname)) > 0 |
| 145 | - ) |
|
| 146 | - { |
|
| 155 | + ) { |
|
| 147 | 156 | $file['Define imports|exports'] = Egw::link('/index.php',array( |
| 148 | 157 | 'menuaction' => 'importexport.importexport_definitions_ui.index', |
| 149 | 158 | 'application' => $appname, |
| 150 | 159 | 'ajax' => 'true' |
| 151 | 160 | ),$GLOBALS['egw_info']['user']['apps']['admin'] ? 'admin' : 'preferences'); |
| 152 | 161 | } |
| 153 | - if($file) display_sidebox($appname,lang('importexport'),$file); |
|
| 162 | + if($file) |
|
| 163 | + { |
|
| 164 | + display_sidebox($appname,lang('importexport'),$file); |
|
| 165 | + } |
|
| 154 | 166 | } |
| 155 | 167 | |
| 156 | 168 | /** |
@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | * @todo deal with other types like objects |
| 21 | 21 | * @static only namespace here |
| 22 | 22 | */ |
| 23 | -class importexport_arrayxml {
|
|
| 23 | +class importexport_arrayxml |
|
| 24 | +{ |
|
| 24 | 25 | |
| 25 | 26 | /** |
| 26 | 27 | * converts a php array to an xml string |
@@ -30,29 +31,34 @@ discard block |
||
| 30 | 31 | * @param DOMElement $_node |
| 31 | 32 | * @return string XML string |
| 32 | 33 | */ |
| 33 | - public static function array2xml ( $_data, $_name = 'root', $_node=null ) {
|
|
| 34 | + public static function array2xml ( $_data, $_name = 'root', $_node=null ) |
|
| 35 | + { |
|
| 34 | 36 | $returnXML = false; |
| 35 | - if ( $_node === null ) {
|
|
| 37 | + if ( $_node === null ) |
|
| 38 | + { |
|
| 36 | 39 | $_node = new DOMDocument( '1.0', 'utf-8' ); |
| 37 | 40 | $_node->formatOutput = true; |
| 38 | 41 | $returnXML = true; |
| 39 | 42 | } |
| 40 | 43 | |
| 41 | 44 | $datatype = gettype( $_data ); |
| 42 | - switch ( $datatype ) {
|
|
| 45 | + switch ( $datatype ) |
|
| 46 | + { |
|
| 43 | 47 | case 'array' : |
| 44 | 48 | $subnode = new DOMElement( 'entry' ); |
| 45 | 49 | $_node->appendChild( $subnode ); |
| 46 | 50 | $subnode->setAttribute( 'type', $datatype ); |
| 47 | 51 | $subnode->setAttribute( 'name' , $_name ); |
| 48 | 52 | |
| 49 | - foreach ( $_data as $ikey => $ivalue ) {
|
|
| 53 | + foreach ( $_data as $ikey => $ivalue ) |
|
| 54 | + { |
|
| 50 | 55 | self::array2xml( $ivalue, $ikey, $subnode ); |
| 51 | 56 | } |
| 52 | 57 | break; |
| 53 | 58 | |
| 54 | 59 | default : |
| 55 | - switch ( $datatype ) {
|
|
| 60 | + switch ( $datatype ) |
|
| 61 | + { |
|
| 56 | 62 | case 'boolean' : |
| 57 | 63 | $data = $_data !== false ? 'TRUE' : 'FALSE'; |
| 58 | 64 | break; |
@@ -74,28 +80,43 @@ discard block |
||
| 74 | 80 | * @param string $_xml |
| 75 | 81 | * @return array |
| 76 | 82 | */ |
| 77 | - public static function xml2array( $_xml ) {
|
|
| 78 | - if ( $_xml instanceof DOMElement ) {
|
|
| 83 | + public static function xml2array( $_xml ) |
|
| 84 | + { |
|
| 85 | + if ( $_xml instanceof DOMElement ) |
|
| 86 | + { |
|
| 79 | 87 | $n = &$_xml; |
| 80 | - } else {
|
|
| 88 | + } |
|
| 89 | + else |
|
| 90 | + { |
|
| 81 | 91 | $n = new DOMDocument; |
| 82 | 92 | $loaded = $n->loadXML($_xml); |
| 83 | - if(!$loaded) return array(); |
|
| 93 | + if(!$loaded) |
|
| 94 | + { |
|
| 95 | + return array(); |
|
| 96 | + } |
|
| 84 | 97 | } |
| 85 | 98 | $xml_array = array(); |
| 86 | 99 | |
| 87 | - foreach($n->childNodes as $nc) {
|
|
| 100 | + foreach($n->childNodes as $nc) |
|
| 101 | + { |
|
| 88 | 102 | |
| 89 | - if ( $nc->nodeType != XML_ELEMENT_NODE ) continue; |
|
| 103 | + if ( $nc->nodeType != XML_ELEMENT_NODE ) |
|
| 104 | + { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 90 | 107 | |
| 91 | 108 | $name = $nc->attributes->getNamedItem('name')->nodeValue;
|
| 92 | 109 | $type = $nc->attributes->getNamedItem('type')->nodeValue;
|
| 93 | 110 | |
| 94 | 111 | //echo $nc->nodeType. "(length ): ". $nc->nodeName. " => ". $nc->nodeValue. "; Attriubtes: name=$name, type=$type \n "; |
| 95 | - if( $nc->childNodes->length >= 2) {
|
|
| 112 | + if( $nc->childNodes->length >= 2) |
|
| 113 | + { |
|
| 96 | 114 | $xml_array[$name] = self::xml2array($nc); |
| 97 | - } else {
|
|
| 98 | - switch ( $type ) {
|
|
| 115 | + } |
|
| 116 | + else |
|
| 117 | + { |
|
| 118 | + switch ( $type ) |
|
| 119 | + { |
|
| 99 | 120 | case 'boolean' : |
| 100 | 121 | $value = $nc->nodeValue == 'FALSE' ? false : true; |
| 101 | 122 | break; |
@@ -34,7 +34,8 @@ |
||
| 34 | 34 | * |
| 35 | 35 | * get_selector(); //returns array |
| 36 | 36 | */ |
| 37 | -interface importexport_iface_export_plugin { |
|
| 37 | +interface importexport_iface_export_plugin |
|
| 38 | +{ |
|
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | 41 | * exports entries according to given definition object. |
@@ -93,7 +93,8 @@ discard block |
||
| 93 | 93 | 'get_rows' => 'etemplate.ajax_select_widget.array_rows', |
| 94 | 94 | 'id_field' => ajax_select_widget::ARRAY_KEY, |
| 95 | 95 | ); |
| 96 | - if($field['rows']) { |
|
| 96 | + if($field['rows']) |
|
| 97 | + { |
|
| 97 | 98 | $options['num_rows'] = $field['rows']; |
| 98 | 99 | } |
| 99 | 100 | |
@@ -103,7 +104,9 @@ discard block |
||
| 103 | 104 | { |
| 104 | 105 | $options['values'] = Api\Storage\Customfields::get_options_from_file($field['values']['@']); |
| 105 | 106 | unset($field['values']['@']); |
| 106 | - } else { |
|
| 107 | + } |
|
| 108 | + else |
|
| 109 | + { |
|
| 107 | 110 | $options['values'] = array_diff_key($field['values'], array_flip(ajax_select_widget::$known_options)); |
| 108 | 111 | } |
| 109 | 112 | $options = array_merge($options, array_intersect_key($field['values'], array_flip(ajax_select_widget::$known_options))); |
@@ -113,7 +113,10 @@ discard block |
||
| 113 | 113 | // Remove any left blank |
| 114 | 114 | foreach($schedule as $key => &$value) |
| 115 | 115 | { |
| 116 | - if($value == '') unset($schedule[$key]); |
|
| 116 | + if($value == '') |
|
| 117 | + { |
|
| 118 | + unset($schedule[$key]); |
|
| 119 | + } |
|
| 117 | 120 | } |
| 118 | 121 | $result = $async->set_timer( |
| 119 | 122 | $schedule, |
@@ -283,14 +286,16 @@ discard block |
||
| 283 | 286 | * |
| 284 | 287 | * $data should contain target & type |
| 285 | 288 | */ |
| 286 | - public static function check_target(Array $data) { |
|
| 289 | + public static function check_target(Array $data) |
|
| 290 | + { |
|
| 287 | 291 | $scheme = parse_url($data['target'], PHP_URL_SCHEME); |
| 288 | 292 | if($scheme == '' || $scheme == 'file') |
| 289 | 293 | { |
| 290 | 294 | return 'Direct file access not allowed'; |
| 291 | 295 | } |
| 292 | 296 | |
| 293 | - if($scheme == Vfs::SCHEME && !in_array(Vfs::SCHEME, stream_get_wrappers())) { |
|
| 297 | + if($scheme == Vfs::SCHEME && !in_array(Vfs::SCHEME, stream_get_wrappers())) |
|
| 298 | + { |
|
| 294 | 299 | stream_wrapper_register(Vfs::SCHEME, 'vfs_stream_wrapper', STREAM_IS_URL); |
| 295 | 300 | } |
| 296 | 301 | |
@@ -315,8 +320,14 @@ discard block |
||
| 315 | 320 | // Response code has an integer key, but redirects may add more responses |
| 316 | 321 | for($i = 0; $i < count($headers); $i++) |
| 317 | 322 | { |
| 318 | - if(!$headers[$i]) break; |
|
| 319 | - if(strpos($headers[$i],'200') !== false) return true; |
|
| 323 | + if(!$headers[$i]) |
|
| 324 | + { |
|
| 325 | + break; |
|
| 326 | + } |
|
| 327 | + if(strpos($headers[$i],'200') !== false) |
|
| 328 | + { |
|
| 329 | + return true; |
|
| 330 | + } |
|
| 320 | 331 | } |
| 321 | 332 | return lang('%1 is not readable',$data['target']); |
| 322 | 333 | } |
@@ -16,7 +16,8 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @todo make this class an egw_record_pool! |
| 18 | 18 | */ |
| 19 | -class importexport_definitions_bo { |
|
| 19 | +class importexport_definitions_bo |
|
| 20 | +{ |
|
| 20 | 21 | |
| 21 | 22 | const _appname = 'importexport'; |
| 22 | 23 | const _defintion_table = 'egw_importexport_definitions'; |
@@ -34,10 +35,15 @@ discard block |
||
| 34 | 35 | public function __construct($_query=false, $ignore_acl = false) |
| 35 | 36 | { |
| 36 | 37 | $this->so_sql = new Api\Storage\Base(self::_appname, self::_defintion_table ); |
| 37 | - if ($_query) { |
|
| 38 | + if ($_query) |
|
| 39 | + { |
|
| 38 | 40 | $definitions = $this->so_sql->search($_query, false); |
| 39 | - foreach ((array)$definitions as $definition) { |
|
| 40 | - if(self::is_permitted($definition) || $ignore_acl) $this->definitions[] = $definition['definition_id']; |
|
| 41 | + foreach ((array)$definitions as $definition) |
|
| 42 | + { |
|
| 43 | + if(self::is_permitted($definition) || $ignore_acl) |
|
| 44 | + { |
|
| 45 | + $this->definitions[] = $definition['definition_id']; |
|
| 46 | + } |
|
| 41 | 47 | } |
| 42 | 48 | } |
| 43 | 49 | } |
@@ -45,7 +51,8 @@ discard block |
||
| 45 | 51 | public function get_rows(&$query, &$rows, &$readonlys) |
| 46 | 52 | { |
| 47 | 53 | // Filter only definitions user is allowed to use |
| 48 | - if(!$GLOBALS['egw_info']['user']['apps']['admin']) { |
|
| 54 | + if(!$GLOBALS['egw_info']['user']['apps']['admin']) |
|
| 55 | + { |
|
| 49 | 56 | $this_membership = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
| 50 | 57 | $this_membership[] = $GLOBALS['egw_info']['user']['account_id']; |
| 51 | 58 | $sql .= ' ('; |
@@ -80,7 +87,8 @@ discard block |
||
| 80 | 87 | |
| 81 | 88 | $total = $this->so_sql->get_rows($query, $rows, $readonlys); |
| 82 | 89 | $ro_count = 0; |
| 83 | - foreach($rows as &$row) { |
|
| 90 | + foreach($rows as &$row) |
|
| 91 | + { |
|
| 84 | 92 | // Strip off leading + trailing , |
| 85 | 93 | $row['allowed_users'] = substr($row['allowed_users'],1,-1); |
| 86 | 94 | |
@@ -103,14 +111,19 @@ discard block |
||
| 103 | 111 | * |
| 104 | 112 | * @return array |
| 105 | 113 | */ |
| 106 | - public function get_definitions() { |
|
| 114 | + public function get_definitions() |
|
| 115 | + { |
|
| 107 | 116 | return $this->definitions; |
| 108 | 117 | } |
| 109 | - public function read($definition_id) { |
|
| 110 | - if(is_numeric($definition_id)) { |
|
| 118 | + public function read($definition_id) |
|
| 119 | + { |
|
| 120 | + if(is_numeric($definition_id)) |
|
| 121 | + { |
|
| 111 | 122 | $this->so_sql->read($definition_id); |
| 112 | 123 | $definition = new importexport_definition($this->so_sql->data['name']); |
| 113 | - } else { |
|
| 124 | + } |
|
| 125 | + else |
|
| 126 | + { |
|
| 114 | 127 | $definition = new importexport_definition( $definition_id['name'] ); |
| 115 | 128 | } |
| 116 | 129 | return $definition->get_record_array(); |
@@ -120,18 +133,24 @@ discard block |
||
| 120 | 133 | * |
| 121 | 134 | * @param array $keys |
| 122 | 135 | */ |
| 123 | - public function delete($keys) { |
|
| 124 | - foreach ($keys as $index => $key) { |
|
| 136 | + public function delete($keys) |
|
| 137 | + { |
|
| 138 | + foreach ($keys as $index => $key) |
|
| 139 | + { |
|
| 125 | 140 | // Check for ownership |
| 126 | 141 | $definition = $this->read($key); |
| 127 | - if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) { |
|
| 142 | + if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'] || $GLOBALS['egw_info']['user']['apps']['admin']) |
|
| 143 | + { |
|
| 128 | 144 | // clear private cache |
| 129 | 145 | unset($this->definitions[array_search($key,$this->definitions)]); |
| 130 | - } else { |
|
| 146 | + } |
|
| 147 | + else |
|
| 148 | + { |
|
| 131 | 149 | unset($keys[$index]); |
| 132 | 150 | } |
| 133 | 151 | } |
| 134 | - if(count($keys) > 0) { |
|
| 152 | + if(count($keys) > 0) |
|
| 153 | + { |
|
| 135 | 154 | $this->so_sql->delete(array('definition_id' => $keys)); |
| 136 | 155 | } |
| 137 | 156 | } |
@@ -141,7 +160,8 @@ discard block |
||
| 141 | 160 | * |
| 142 | 161 | * @param definition $definition |
| 143 | 162 | */ |
| 144 | - public function save(Array $data) { |
|
| 163 | + public function save(Array $data) |
|
| 164 | + { |
|
| 145 | 165 | $definition = new importexport_definition(); |
| 146 | 166 | $definition->set_record($data); |
| 147 | 167 | $definition->save($data['definition_id']); |
@@ -153,7 +173,8 @@ discard block |
||
| 153 | 173 | * @param array $_definition |
| 154 | 174 | * @return bool |
| 155 | 175 | */ |
| 156 | - static public function is_permitted($_definition) { |
|
| 176 | + static public function is_permitted($_definition) |
|
| 177 | + { |
|
| 157 | 178 | $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']); |
| 158 | 179 | $this_user_id = $GLOBALS['egw_info']['user']['account_id']; |
| 159 | 180 | $this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true); |
@@ -177,25 +198,30 @@ discard block |
||
| 177 | 198 | )); |
| 178 | 199 | |
| 179 | 200 | $export_data['definitions'] = array(); |
| 180 | - foreach ($keys as $definition_id) { |
|
| 201 | + foreach ($keys as $definition_id) |
|
| 202 | + { |
|
| 181 | 203 | $definition = new importexport_definition( $definition_id ); |
| 182 | 204 | $export_data['definitions'][$definition->name] = $definition->get_record_array(); |
| 183 | 205 | $export_data['definitions'][$definition->name]['allowed_users'] = |
| 184 | 206 | importexport_helper_functions::account_id2name( |
| 185 | 207 | $export_data['definitions'][$definition->name]['allowed_users'] |
| 186 | 208 | ); |
| 187 | - if($export_date['definitions'][$definition->name]['owner']) { |
|
| 209 | + if($export_date['definitions'][$definition->name]['owner']) |
|
| 210 | + { |
|
| 188 | 211 | $export_data['definitions'][$definition->name]['owner'] = |
| 189 | 212 | importexport_helper_functions::account_id2name( |
| 190 | 213 | $export_data['definitions'][$definition->name]['owner'] |
| 191 | 214 | ); |
| 192 | - } else { |
|
| 215 | + } |
|
| 216 | + else |
|
| 217 | + { |
|
| 193 | 218 | unset($export_data['definitions'][$definition->name]['owner']); |
| 194 | 219 | } |
| 195 | 220 | unset($export_data['definitions'][$definition->name]['definition_id']); |
| 196 | 221 | unset($export_data['definitions'][$definition->name]['description']); |
| 197 | 222 | unset($export_data['definitions'][$definition->name]['user_timezone_read']); |
| 198 | - if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) { |
|
| 223 | + if(is_array($export_data['definitions'][$definition->name]['plugin_options'])) |
|
| 224 | + { |
|
| 199 | 225 | unset($export_data['definitions'][$definition->name]['plugin_options']['user_timezone_read']); |
| 200 | 226 | } |
| 201 | 227 | unset($definition); |
@@ -215,7 +241,8 @@ discard block |
||
| 215 | 241 | */ |
| 216 | 242 | public static function import( $_import_file ) |
| 217 | 243 | { |
| 218 | - if ( !is_file( $_import_file ) ) { |
|
| 244 | + if ( !is_file( $_import_file ) ) |
|
| 245 | + { |
|
| 219 | 246 | throw new Exception("'$_import_file' does not exist or is not readable" ); |
| 220 | 247 | } |
| 221 | 248 | |
@@ -233,14 +260,20 @@ discard block |
||
| 233 | 260 | ); |
| 234 | 261 | |
| 235 | 262 | // Avoid warning if no definitions found |
| 236 | - if(!is_array($definitions)) return lang('None found'); |
|
| 263 | + if(!is_array($definitions)) |
|
| 264 | + { |
|
| 265 | + return lang('None found'); |
|
| 266 | + } |
|
| 237 | 267 | |
| 238 | 268 | // save definition(s) into internal table |
| 239 | 269 | foreach ( $definitions as $name => $definition_data ) |
| 240 | 270 | { |
| 241 | 271 | // convert allowed_user |
| 242 | 272 | $definition_data['allowed_users'] = importexport_helper_functions::account_name2id( $definition_data['allowed_users'] ); |
| 243 | - if($definition_data['all_users'] && !$definition_data['allowed_users']) $definition_data['allowed_users'] = 'all'; |
|
| 273 | + if($definition_data['all_users'] && !$definition_data['allowed_users']) |
|
| 274 | + { |
|
| 275 | + $definition_data['allowed_users'] = 'all'; |
|
| 276 | + } |
|
| 244 | 277 | |
| 245 | 278 | $definition_data['owner'] = importexport_helper_functions::account_name2id( $definition_data['owner'] ); |
| 246 | 279 | |
@@ -275,7 +308,10 @@ discard block |
||
| 275 | 308 | public static function export_from_import(importexport_definition $import) |
| 276 | 309 | { |
| 277 | 310 | // Only operates on import definitions |
| 278 | - if($import->type != 'import') throw new Api\Exception\WrongParameter('Only import definitions'); |
|
| 311 | + if($import->type != 'import') |
|
| 312 | + { |
|
| 313 | + throw new Api\Exception\WrongParameter('Only import definitions'); |
|
| 314 | + } |
|
| 279 | 315 | |
| 280 | 316 | // Find export plugin |
| 281 | 317 | $plugin = str_replace('import', 'export',$import->plugin); |
@@ -285,18 +321,30 @@ discard block |
||
| 285 | 321 | $plugins = $type['export']; |
| 286 | 322 | foreach($plugins as $name => $label) |
| 287 | 323 | { |
| 288 | - if($plugin == $name) break; |
|
| 324 | + if($plugin == $name) |
|
| 325 | + { |
|
| 326 | + break; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if($plugin !== $name) |
|
| 330 | + { |
|
| 331 | + $plugin = $name; |
|
| 289 | 332 | } |
| 290 | - if($plugin !== $name) $plugin = $name; |
|
| 291 | 333 | } |
| 292 | 334 | |
| 293 | 335 | $export = new importexport_definition(); |
| 294 | 336 | |
| 295 | 337 | // Common settings |
| 296 | 338 | $export->name = str_replace('import', 'export',$import->name); |
| 297 | - if($export->name == $import->name) $export->name = $export->name . '-export'; |
|
| 339 | + if($export->name == $import->name) |
|
| 340 | + { |
|
| 341 | + $export->name = $export->name . '-export'; |
|
| 342 | + } |
|
| 298 | 343 | $test = new importexport_definition($export->name); |
| 299 | - if($test->name) $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
| 344 | + if($test->name) |
|
| 345 | + { |
|
| 346 | + $export->name = $export->name .'-'.$GLOBALS['egw_info']['user']['account_lid']; |
|
| 347 | + } |
|
| 300 | 348 | |
| 301 | 349 | $export->application = $import->application; |
| 302 | 350 | $export->plugin = $plugin; |
@@ -64,7 +64,11 @@ discard block |
||
| 64 | 64 | 'wizard_step80' => lang('Filters'), |
| 65 | 65 | ); |
| 66 | 66 | list($appname, $part2) = explode('_', get_class($this)); |
| 67 | - if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= '_'.$part2; // Handle apps with _ in the name |
|
| 67 | + if(!$GLOBALS['egw_info']['apps'][$appname]) |
|
| 68 | + { |
|
| 69 | + $appname .= '_'.$part2; |
|
| 70 | + } |
|
| 71 | + // Handle apps with _ in the name |
|
| 68 | 72 | Api\Translation::add_app($appname); |
| 69 | 73 | } |
| 70 | 74 | |
@@ -73,7 +77,10 @@ discard block |
||
| 73 | 77 | */ |
| 74 | 78 | function wizard_step30(&$content, &$sel_options, &$readonlys, &$preserv) |
| 75 | 79 | { |
| 76 | - if($this->debug) error_log(get_class($this) . '::wizard_step30->$content '.print_r($content,true)); |
|
| 80 | + if($this->debug) |
|
| 81 | + { |
|
| 82 | + error_log(get_class($this) . '::wizard_step30->$content '.print_r($content,true)); |
|
| 83 | + } |
|
| 77 | 84 | // return from step30 |
| 78 | 85 | if ($content['step'] == 'wizard_step30') |
| 79 | 86 | { |
@@ -89,12 +96,17 @@ discard block |
||
| 89 | 96 | $content['mapping'][$field_name] = $field_name; |
| 90 | 97 | } |
| 91 | 98 | } |
| 92 | - if($content['mapping']['all_custom_fields']) { |
|
| 99 | + if($content['mapping']['all_custom_fields']) |
|
| 100 | + { |
|
| 93 | 101 | // Need the appname during actual export, to fetch the fields |
| 94 | 102 | $parts = explode('_', get_class($this)); |
| 95 | 103 | $appname = $parts[0]; |
| 96 | - foreach($parts as $name_part) { |
|
| 97 | - if($GLOBALS['egw_info']['apps'][$appname]) break; |
|
| 104 | + foreach($parts as $name_part) |
|
| 105 | + { |
|
| 106 | + if($GLOBALS['egw_info']['apps'][$appname]) |
|
| 107 | + { |
|
| 108 | + break; |
|
| 109 | + } |
|
| 98 | 110 | $appname .= '_'.$name_part; // Handle apps with _ in the name |
| 99 | 111 | } |
| 100 | 112 | $content['mapping']['all_custom_fields'] = $appname; |
@@ -125,15 +137,20 @@ discard block |
||
| 125 | 137 | unset ($preserv['button']); |
| 126 | 138 | unset ($preserv['fields']); |
| 127 | 139 | $content['fields'] = array(''); |
| 128 | - if(!$content['mapping']) $content['mapping'] = $content['plugin_options']['mapping']; |
|
| 140 | + if(!$content['mapping']) |
|
| 141 | + { |
|
| 142 | + $content['mapping'] = $content['plugin_options']['mapping']; |
|
| 143 | + } |
|
| 129 | 144 | |
| 130 | 145 | $row = 1; |
| 131 | - foreach($this->export_fields as $field => $name) { |
|
| 146 | + foreach($this->export_fields as $field => $name) |
|
| 147 | + { |
|
| 132 | 148 | $content['fields'][] = array( |
| 133 | 149 | 'field' => $field, |
| 134 | 150 | 'name' => lang($name), |
| 135 | 151 | ); |
| 136 | - if($content['mapping'][$field]) { |
|
| 152 | + if($content['mapping'][$field]) |
|
| 153 | + { |
|
| 137 | 154 | $content['fields']['export'][$row] = $field; |
| 138 | 155 | } |
| 139 | 156 | $row++; |
@@ -155,11 +172,17 @@ discard block |
||
| 155 | 172 | */ |
| 156 | 173 | function wizard_step40(&$content, &$sel_options, &$readonlys, &$preserv) |
| 157 | 174 | { |
| 158 | - if($this->debug) error_log(get_class($this) . '::wizard_step40->$content '.print_r($content,true)); |
|
| 175 | + if($this->debug) |
|
| 176 | + { |
|
| 177 | + error_log(get_class($this) . '::wizard_step40->$content '.print_r($content,true)); |
|
| 178 | + } |
|
| 159 | 179 | // return from step40 |
| 160 | - if ($content['step'] == 'wizard_step40') { |
|
| 161 | - if($content['begin_with_fieldnames'] == 'label') { |
|
| 162 | - foreach($content['mapping'] as $field => &$label) { |
|
| 180 | + if ($content['step'] == 'wizard_step40') |
|
| 181 | + { |
|
| 182 | + if($content['begin_with_fieldnames'] == 'label') |
|
| 183 | + { |
|
| 184 | + foreach($content['mapping'] as $field => &$label) |
|
| 185 | + { |
|
| 163 | 186 | // Check first, to avoid clearing any pseudo-columns (ex: All custom fields) |
| 164 | 187 | $label = $this->export_fields[$field] ? $this->export_fields[$field] : $label; |
| 165 | 188 | } |
@@ -183,18 +206,24 @@ discard block |
||
| 183 | 206 | $content['step'] = 'wizard_step40'; |
| 184 | 207 | |
| 185 | 208 | // If editing an existing definition, these will be in plugin_options |
| 186 | - if(!$content['delimiter'] && $content['plugin_options']['delimiter']) { |
|
| 209 | + if(!$content['delimiter'] && $content['plugin_options']['delimiter']) |
|
| 210 | + { |
|
| 187 | 211 | $content['delimiter'] = $content['plugin_options']['delimiter']; |
| 188 | - } elseif (!$content['delimiter']) { |
|
| 212 | + } |
|
| 213 | + elseif (!$content['delimiter']) |
|
| 214 | + { |
|
| 189 | 215 | $content['delimiter'] = ';'; |
| 190 | 216 | } |
| 191 | - if(!$content['charset'] && $content['plugin_options']['charset']) { |
|
| 217 | + if(!$content['charset'] && $content['plugin_options']['charset']) |
|
| 218 | + { |
|
| 192 | 219 | $content['charset'] = $content['plugin_options']['charset'] ? $content['plugin_options']['charset'] : 'user'; |
| 193 | 220 | } |
| 194 | - if(!array_key_exists('begin_with_fieldnames', $content) && array_key_exists('begin_with_fieldnames', $content['plugin_options'])) { |
|
| 221 | + if(!array_key_exists('begin_with_fieldnames', $content) && array_key_exists('begin_with_fieldnames', $content['plugin_options'])) |
|
| 222 | + { |
|
| 195 | 223 | $content['begin_with_fieldnames'] = $content['plugin_options']['begin_with_fieldnames']; |
| 196 | 224 | } |
| 197 | - if(!array_key_exists('convert', $content) && array_key_exists('convert', $content['plugin_options'])) { |
|
| 225 | + if(!array_key_exists('convert', $content) && array_key_exists('convert', $content['plugin_options'])) |
|
| 226 | + { |
|
| 198 | 227 | $content['convert'] = $content['plugin_options']['convert']; |
| 199 | 228 | } |
| 200 | 229 | |
@@ -238,15 +267,20 @@ discard block |
||
| 238 | 267 | */ |
| 239 | 268 | function wizard_step80(&$content, &$sel_options, &$readonlys, &$preserv) |
| 240 | 269 | { |
| 241 | - if($this->debug) error_log(get_class($this) . '::' . __METHOD__ .'->$content '.print_r($content,true)); |
|
| 270 | + if($this->debug) |
|
| 271 | + { |
|
| 272 | + error_log(get_class($this) . '::' . __METHOD__ .'->$content '.print_r($content,true)); |
|
| 273 | + } |
|
| 242 | 274 | // return from submit |
| 243 | - if ($content['step'] == 'wizard_step80') { |
|
| 275 | + if ($content['step'] == 'wizard_step80') |
|
| 276 | + { |
|
| 244 | 277 | // Process submitted |
| 245 | 278 | unset($content['filter']); |
| 246 | 279 | unset($content['set_filter']['fields']); |
| 247 | 280 | foreach($content['set_filter'] as $key => $value) |
| 248 | 281 | { |
| 249 | - if($value) { |
|
| 282 | + if($value) |
|
| 283 | + { |
|
| 250 | 284 | $content['filter'][$key] = $value; |
| 251 | 285 | } |
| 252 | 286 | } |
@@ -264,7 +298,9 @@ discard block |
||
| 264 | 298 | default : |
| 265 | 299 | return $this->wizard_step80($content,$sel_options,$readonlys,$preserv); |
| 266 | 300 | } |
| 267 | - } else { |
|
| 301 | + } |
|
| 302 | + else |
|
| 303 | + { |
|
| 268 | 304 | |
| 269 | 305 | // Step 50 - filters |
| 270 | 306 | $content['text'] = $this->steps['wizard_step80']; |
@@ -23,7 +23,8 @@ discard block |
||
| 23 | 23 | --dry-run no real action, just console output |
| 24 | 24 | \n"; |
| 25 | 25 | |
| 26 | -if (php_sapi_name() != 'cli') { |
|
| 26 | +if (php_sapi_name() != 'cli') |
|
| 27 | +{ |
|
| 27 | 28 | die('This script only runs form command line'); |
| 28 | 29 | } |
| 29 | 30 | |
@@ -44,7 +45,8 @@ discard block |
||
| 44 | 45 | $args = Console_Getopt::readPHPArgv(); |
| 45 | 46 | |
| 46 | 47 | // Make sure we got them (for non CLI binaries) |
| 47 | -if (PEAR::isError($args)) { |
|
| 48 | +if (PEAR::isError($args)) |
|
| 49 | +{ |
|
| 48 | 50 | fwrite(STDERR,"importexport_cli: ".$args->getMessage()."\n".$usage); |
| 49 | 51 | exit(NO_ARGS); |
| 50 | 52 | } |
@@ -63,22 +65,28 @@ discard block |
||
| 63 | 65 | ); |
| 64 | 66 | |
| 65 | 67 | // Convert the arguments to options - check for the first argument |
| 66 | -if ( realpath($_SERVER['argv'][0]) == __FILE__ ) { |
|
| 68 | +if ( realpath($_SERVER['argv'][0]) == __FILE__ ) |
|
| 69 | +{ |
|
| 67 | 70 | $options = Console_Getopt::getOpt($args,$short_opts,$long_opts); |
| 68 | -} else { |
|
| 71 | +} |
|
| 72 | +else |
|
| 73 | +{ |
|
| 69 | 74 | $options = Console_Getopt::getOpt2($args,$short_opts,$long_opts); |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | 77 | // Check the options are valid |
| 73 | -if (PEAR::isError($options)) { |
|
| 78 | +if (PEAR::isError($options)) |
|
| 79 | +{ |
|
| 74 | 80 | fwrite(STDERR,"importexport_cli: ".$options->getMessage()."\n".$usage."\n"); |
| 75 | 81 | exit(INVALID_OPTION); |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | 84 | $domain = 'default'; |
| 79 | 85 | $dryrun = false; |
| 80 | -foreach ($options[0] as $option) { |
|
| 81 | - switch ($option[0]) { |
|
| 86 | +foreach ($options[0] as $option) |
|
| 87 | +{ |
|
| 88 | + switch ($option[0]) |
|
| 89 | + { |
|
| 82 | 90 | case '--file' : |
| 83 | 91 | $file = $option[1]; |
| 84 | 92 | break; |
@@ -103,7 +111,8 @@ discard block |
||
| 103 | 111 | } |
| 104 | 112 | } |
| 105 | 113 | // check file |
| 106 | -if ( !$user || !$password ) { |
|
| 114 | +if ( !$user || !$password ) |
|
| 115 | +{ |
|
| 107 | 116 | fwrite(STDERR,'importexport_cli: You have to supply a username / password'."\n".$usage); |
| 108 | 117 | exit(INVALID_OPTION); |
| 109 | 118 | } |
@@ -135,7 +144,8 @@ discard block |
||
| 135 | 144 | } |
| 136 | 145 | |
| 137 | 146 | $definition = new importexport_definition($definition); |
| 138 | -if( $definition->get_identifier() < 1 ) { |
|
| 147 | +if( $definition->get_identifier() < 1 ) |
|
| 148 | +{ |
|
| 139 | 149 | fwrite(STDERR,"importexport_cli: Definition not found! \n"); |
| 140 | 150 | exit(INVALID_OPTION); |
| 141 | 151 | } |