@@ -20,7 +20,7 @@ |
||
| 20 | 20 | /** |
| 21 | 21 | * Constructor |
| 22 | 22 | * |
| 23 | - * @param boolean|array $allow true=give rights, false=remove rights, or array with all 3 params |
|
| 23 | + * @param boolean $allow true=give rights, false=remove rights, or array with all 3 params |
|
| 24 | 24 | * @param string|int $account =null account name or id |
| 25 | 25 | * @param array|string $apps =null app-names |
| 26 | 26 | */ |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @param string|int $account =null account name or id |
| 25 | 25 | * @param array|string $apps =null app-names |
| 26 | 26 | */ |
| 27 | - function __construct($allow,$account=null,$apps=null) |
|
| 27 | + function __construct($allow, $account = null, $apps = null) |
|
| 28 | 28 | { |
| 29 | 29 | if (!is_array($allow)) |
| 30 | 30 | { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | if (isset($allow['apps']) && !is_array($allow['apps'])) |
| 38 | 38 | { |
| 39 | - $allow['apps'] = explode(',',$allow['apps']); |
|
| 39 | + $allow['apps'] = explode(',', $allow['apps']); |
|
| 40 | 40 | } |
| 41 | 41 | admin_cmd::__construct($allow); |
| 42 | 42 | } |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | * @throws Api\Exception\WrongUserinput(lang("Unknown account: %1 !!!",$this->account),15); |
| 51 | 51 | * @throws Api\Exception\WrongUserinput(lang("Application '%1' not found (maybe not installed or misspelled)!",$name),8); |
| 52 | 52 | */ |
| 53 | - protected function exec($check_only=false) |
|
| 53 | + protected function exec($check_only = false) |
|
| 54 | 54 | { |
| 55 | 55 | $account_id = admin_cmd::parse_account($this->account); |
| 56 | 56 | // check creator is still admin and not explicitly forbidden to edit accounts/groups |
| 57 | - if ($this->creator) $this->_check_admin($account_id > 0 ? 'account_access' : 'group_access',16); |
|
| 57 | + if ($this->creator) $this->_check_admin($account_id > 0 ? 'account_access' : 'group_access', 16); |
|
| 58 | 58 | |
| 59 | 59 | $apps = admin_cmd::parse_apps($this->apps); |
| 60 | 60 | |
@@ -62,15 +62,15 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | //echo "account=$this->account, account_id=$account_id, apps: ".implode(', ',$apps)."\n"; |
| 64 | 64 | admin_cmd::_instanciate_acl($account_id); |
| 65 | - foreach($apps as $app) |
|
| 65 | + foreach ($apps as $app) |
|
| 66 | 66 | { |
| 67 | 67 | if ($this->allow) |
| 68 | 68 | { |
| 69 | - admin_cmd::$acl->add_repository($app,'run',$account_id,1); |
|
| 69 | + admin_cmd::$acl->add_repository($app, 'run', $account_id, 1); |
|
| 70 | 70 | } |
| 71 | 71 | else |
| 72 | 72 | { |
| 73 | - admin_cmd::$acl->delete_repository($app,'run',$account_id); |
|
| 73 | + admin_cmd::$acl->delete_repository($app, 'run', $account_id); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | return lang('Applications run rights updated.'); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | function __tostring() |
| 85 | 85 | { |
| 86 | - return lang('%1 rights for %2 and applications %3',$this->allow ? lang('Grant') : lang('Remove'), |
|
| 87 | - admin_cmd::display_account($this->account),implode(', ',$this->apps)); |
|
| 86 | + return lang('%1 rights for %2 and applications %3', $this->allow ? lang('Grant') : lang('Remove'), |
|
| 87 | + admin_cmd::display_account($this->account), implode(', ', $this->apps)); |
|
| 88 | 88 | } |
| 89 | 89 | } |
@@ -54,11 +54,17 @@ |
||
| 54 | 54 | { |
| 55 | 55 | $account_id = admin_cmd::parse_account($this->account); |
| 56 | 56 | // check creator is still admin and not explicitly forbidden to edit accounts/groups |
| 57 | - if ($this->creator) $this->_check_admin($account_id > 0 ? 'account_access' : 'group_access',16); |
|
| 57 | + if ($this->creator) |
|
| 58 | + { |
|
| 59 | + $this->_check_admin($account_id > 0 ? 'account_access' : 'group_access',16); |
|
| 60 | + } |
|
| 58 | 61 | |
| 59 | 62 | $apps = admin_cmd::parse_apps($this->apps); |
| 60 | 63 | |
| 61 | - if ($check_only) return true; |
|
| 64 | + if ($check_only) |
|
| 65 | + { |
|
| 66 | + return true; |
|
| 67 | + } |
|
| 62 | 68 | |
| 63 | 69 | //echo "account=$this->account, account_id=$account_id, apps: ".implode(', ',$apps)."\n"; |
| 64 | 70 | admin_cmd::_instanciate_acl($account_id); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * Exports records as defined in $_definition |
| 21 | 21 | * |
| 22 | - * @param egw_record $_definition |
|
| 22 | + * @param importexport_definition $_definition |
|
| 23 | 23 | */ |
| 24 | 24 | public function export( $_stream, importexport_definition $_definition) { |
| 25 | 25 | $options = $_definition->plugin_options; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * return html for options. |
| 89 | 89 | * this way the plugin has all opportunities for options tab |
| 90 | 90 | * |
| 91 | - * @return string html |
|
| 91 | + * @return boolean html |
|
| 92 | 92 | */ |
| 93 | 93 | public function get_options_etpl() { |
| 94 | 94 | return false; |
@@ -81,8 +81,8 @@ |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public static function get_mimetype() { |
| 84 | - return 'text/csv'; |
|
| 85 | - } |
|
| 84 | + return 'text/csv'; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * return html for options. |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param egw_record $_definition |
| 23 | 23 | */ |
| 24 | - public function export( $_stream, importexport_definition $_definition) { |
|
| 24 | + public function export($_stream, importexport_definition $_definition) { |
|
| 25 | 25 | $options = $_definition->plugin_options; |
| 26 | 26 | |
| 27 | 27 | $query = array( |
@@ -40,12 +40,12 @@ discard block |
||
| 40 | 40 | // $_record is an array, that's what search() returns |
| 41 | 41 | foreach ($selection as $_record) { |
| 42 | 42 | $record = new admin_egw_group_record($_record); |
| 43 | - if($options['convert']) { |
|
| 43 | + if ($options['convert']) { |
|
| 44 | 44 | importexport_export_csv::convert($record, admin_egw_group_record::$types, 'admin', $lookups); |
| 45 | 45 | } else { |
| 46 | 46 | // Implode arrays, so they don't say 'Array' |
| 47 | - foreach($record->get_record_array() as $key => $value) { |
|
| 48 | - if(is_array($value)) $record->$key = implode(',', $value); |
|
| 47 | + foreach ($record->get_record_array() as $key => $value) { |
|
| 48 | + if (is_array($value)) $record->$key = implode(',', $value); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | $export_object->export_record($record); |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param egw_record $_definition |
| 23 | 23 | */ |
| 24 | - public function export( $_stream, importexport_definition $_definition) { |
|
| 24 | + public function export( $_stream, importexport_definition $_definition) |
|
| 25 | + { |
|
| 25 | 26 | $options = $_definition->plugin_options; |
| 26 | 27 | |
| 27 | 28 | $query = array( |
@@ -38,14 +39,22 @@ discard block |
||
| 38 | 39 | ); |
| 39 | 40 | |
| 40 | 41 | // $_record is an array, that's what search() returns |
| 41 | - foreach ($selection as $_record) { |
|
| 42 | + foreach ($selection as $_record) |
|
| 43 | + { |
|
| 42 | 44 | $record = new admin_egw_group_record($_record); |
| 43 | - if($options['convert']) { |
|
| 45 | + if($options['convert']) |
|
| 46 | + { |
|
| 44 | 47 | importexport_export_csv::convert($record, admin_egw_group_record::$types, 'admin', $lookups); |
| 45 | - } else { |
|
| 48 | + } |
|
| 49 | + else |
|
| 50 | + { |
|
| 46 | 51 | // Implode arrays, so they don't say 'Array' |
| 47 | - foreach($record->get_record_array() as $key => $value) { |
|
| 48 | - if(is_array($value)) $record->$key = implode(',', $value); |
|
| 52 | + foreach($record->get_record_array() as $key => $value) |
|
| 53 | + { |
|
| 54 | + if(is_array($value)) |
|
| 55 | + { |
|
| 56 | + $record->$key = implode(',', $value); |
|
| 57 | + } |
|
| 49 | 58 | } |
| 50 | 59 | } |
| 51 | 60 | $export_object->export_record($record); |
@@ -58,7 +67,8 @@ discard block |
||
| 58 | 67 | * |
| 59 | 68 | * @return string name |
| 60 | 69 | */ |
| 61 | - public static function get_name() { |
|
| 70 | + public static function get_name() |
|
| 71 | + { |
|
| 62 | 72 | return lang('Group CSV export'); |
| 63 | 73 | } |
| 64 | 74 | |
@@ -67,7 +77,8 @@ discard block |
||
| 67 | 77 | * |
| 68 | 78 | * @return string descriprion |
| 69 | 79 | */ |
| 70 | - public static function get_description() { |
|
| 80 | + public static function get_description() |
|
| 81 | + { |
|
| 71 | 82 | return lang("Exports groups into a CSV File. "); |
| 72 | 83 | } |
| 73 | 84 | |
@@ -76,11 +87,13 @@ discard block |
||
| 76 | 87 | * |
| 77 | 88 | * @return string suffix |
| 78 | 89 | */ |
| 79 | - public static function get_filesuffix() { |
|
| 90 | + public static function get_filesuffix() |
|
| 91 | + { |
|
| 80 | 92 | return 'csv'; |
| 81 | 93 | } |
| 82 | 94 | |
| 83 | - public static function get_mimetype() { |
|
| 95 | + public static function get_mimetype() |
|
| 96 | + { |
|
| 84 | 97 | return 'text/csv'; |
| 85 | 98 | } |
| 86 | 99 | |
@@ -90,7 +103,8 @@ discard block |
||
| 90 | 103 | * |
| 91 | 104 | * @return string html |
| 92 | 105 | */ |
| 93 | - public function get_options_etpl() { |
|
| 106 | + public function get_options_etpl() |
|
| 107 | + { |
|
| 94 | 108 | return false; |
| 95 | 109 | } |
| 96 | 110 | |
@@ -98,7 +112,8 @@ discard block |
||
| 98 | 112 | * returns slectors of this plugin via xajax |
| 99 | 113 | * |
| 100 | 114 | */ |
| 101 | - public function get_selectors_etpl() { |
|
| 115 | + public function get_selectors_etpl() |
|
| 116 | + { |
|
| 102 | 117 | return array( |
| 103 | 118 | 'preserv' => array('no_error_for_no_selection'), |
| 104 | 119 | ); |
@@ -77,8 +77,7 @@ |
||
| 77 | 77 | /** |
| 78 | 78 | * imports entries according to given definition object. |
| 79 | 79 | * @param resource $_stream |
| 80 | - * @param string $_charset |
|
| 81 | - * @param definition $_definition |
|
| 80 | + * @param importexport_definition $_definition |
|
| 82 | 81 | */ |
| 83 | 82 | public function import( $_stream, importexport_definition $_definition ) { |
| 84 | 83 | $import_csv = new importexport_import_csv( $_stream, array( |
@@ -15,15 +15,15 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * class import_csv for admin (groups) |
| 17 | 17 | */ |
| 18 | -class admin_import_groups_csv implements importexport_iface_import_plugin { |
|
| 18 | +class admin_import_groups_csv implements importexport_iface_import_plugin { |
|
| 19 | 19 | |
| 20 | 20 | private static $plugin_options = array( |
| 21 | - 'fieldsep', // char |
|
| 22 | - 'charset', // string |
|
| 21 | + 'fieldsep', // char |
|
| 22 | + 'charset', // string |
|
| 23 | 23 | 'num_header_lines', // int number of header lines |
| 24 | 24 | 'field_conversion', // array( $csv_col_num => conversion) |
| 25 | - 'field_mapping', // array( $csv_col_num => adb_filed) |
|
| 26 | - 'conditions', /* => array containing condition arrays: |
|
| 25 | + 'field_mapping', // array( $csv_col_num => adb_filed) |
|
| 26 | + 'conditions', /* => array containing condition arrays: |
|
| 27 | 27 | 'type' => exists, // exists |
| 28 | 28 | 'string' => '#kundennummer', |
| 29 | 29 | 'true' => array( |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * actions which could be done to data entries |
| 42 | 42 | */ |
| 43 | - protected static $actions = array( 'none', 'update', 'create', 'delete'); |
|
| 43 | + protected static $actions = array('none', 'update', 'create', 'delete'); |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * conditions for actions |
| 47 | 47 | * |
| 48 | 48 | * @var array |
| 49 | 49 | */ |
| 50 | - protected static $conditions = array( 'exists' ); |
|
| 50 | + protected static $conditions = array('exists'); |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @var definition |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * @param string $_charset |
| 81 | 81 | * @param definition $_definition |
| 82 | 82 | */ |
| 83 | - public function import( $_stream, importexport_definition $_definition ) { |
|
| 84 | - $import_csv = new importexport_import_csv( $_stream, array( |
|
| 83 | + public function import($_stream, importexport_definition $_definition) { |
|
| 84 | + $import_csv = new importexport_import_csv($_stream, array( |
|
| 85 | 85 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
| 86 | 86 | 'charset' => $_definition->plugin_options['charset'], |
| 87 | 87 | )); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $this->definition = $_definition; |
| 90 | 90 | |
| 91 | 91 | // dry run? |
| 92 | - $this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false; |
|
| 92 | + $this->dry_run = isset($_definition->plugin_options['dry_run']) ? $_definition->plugin_options['dry_run'] : false; |
|
| 93 | 93 | |
| 94 | 94 | // set FieldMapping. |
| 95 | 95 | $import_csv->mapping = $_definition->plugin_options['field_mapping']; |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | $import_csv->conversion = $_definition->plugin_options['field_conversion']; |
| 99 | 99 | |
| 100 | 100 | //check if file has a header lines |
| 101 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
| 101 | + if (isset($_definition->plugin_options['num_header_lines']) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
| 102 | 102 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
| 103 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
| 103 | + } elseif (isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
| 104 | 104 | // First method is preferred |
| 105 | 105 | $import_csv->skip_records(1); |
| 106 | 106 | } |
@@ -112,22 +112,22 @@ discard block |
||
| 112 | 112 | // Failures |
| 113 | 113 | $this->errors = array(); |
| 114 | 114 | |
| 115 | - while ( $record = $import_csv->get_record() ) { |
|
| 115 | + while ($record = $import_csv->get_record()) { |
|
| 116 | 116 | $success = false; |
| 117 | 117 | // don't import empty records |
| 118 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
| 118 | + if (count(array_unique($record)) < 2) continue; |
|
| 119 | 119 | |
| 120 | 120 | importexport_import_csv::convert($record, admin_egw_group_record::$types, 'admin'); |
| 121 | 121 | |
| 122 | - if ( $_definition->plugin_options['conditions'] ) { |
|
| 123 | - foreach ( $_definition->plugin_options['conditions'] as $condition ) { |
|
| 124 | - switch ( $condition['type'] ) { |
|
| 122 | + if ($_definition->plugin_options['conditions']) { |
|
| 123 | + foreach ($_definition->plugin_options['conditions'] as $condition) { |
|
| 124 | + switch ($condition['type']) { |
|
| 125 | 125 | // exists |
| 126 | 126 | case 'exists' : |
| 127 | 127 | $accounts = array(); |
| 128 | 128 | |
| 129 | 129 | // Skip the search if the field is empty |
| 130 | - if($record[$condition['string']] !== '') { |
|
| 130 | + if ($record[$condition['string']] !== '') { |
|
| 131 | 131 | |
| 132 | 132 | $accounts = $GLOBALS['egw']->accounts->search(array( |
| 133 | 133 | 'type' => 'groups', |
@@ -136,25 +136,25 @@ discard block |
||
| 136 | 136 | )); |
| 137 | 137 | } |
| 138 | 138 | // Search looks in the given field, but doesn't do an exact match |
| 139 | - foreach ( (array)$accounts as $key => $account ) |
|
| 139 | + foreach ((array)$accounts as $key => $account) |
|
| 140 | 140 | { |
| 141 | - if($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]); |
|
| 141 | + if ($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]); |
|
| 142 | 142 | } |
| 143 | - if ( is_array( $accounts ) && count( $accounts ) >= 1 ) { |
|
| 143 | + if (is_array($accounts) && count($accounts) >= 1) { |
|
| 144 | 144 | $account = current($accounts); |
| 145 | 145 | // apply action to all contacts matching this exists condition |
| 146 | 146 | $action = $condition['true']; |
| 147 | - foreach ( (array)$accounts as $account ) { |
|
| 147 | + foreach ((array)$accounts as $account) { |
|
| 148 | 148 | // Read full account, and copy needed info for accounts->save() |
| 149 | 149 | $account = $GLOBALS['egw']->accounts->read($account['account_id']); |
| 150 | 150 | $record['account_id'] = $account['account_id']; |
| 151 | 151 | $record['account_firstname'] = $account['account_firstname']; |
| 152 | 152 | $record['account_lastname'] = $account['account_lastname']; |
| 153 | - $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
|
| 153 | + $success = $this->action($action['action'], $record, $import_csv->get_current_position()); |
|
| 154 | 154 | } |
| 155 | 155 | } else { |
| 156 | 156 | $action = $condition['false']; |
| 157 | - $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
|
| 157 | + $success = ($this->action($action['action'], $record, $import_csv->get_current_position())); |
|
| 158 | 158 | } |
| 159 | 159 | break; |
| 160 | 160 | |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | } else { |
| 169 | 169 | // unconditional insert |
| 170 | - $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
|
| 170 | + $success = $this->action('insert', $record, $import_csv->get_current_position()); |
|
| 171 | 171 | } |
| 172 | - if($success) $count++; |
|
| 172 | + if ($success) $count++; |
|
| 173 | 173 | } |
| 174 | 174 | return $count; |
| 175 | 175 | } |
@@ -181,18 +181,18 @@ discard block |
||
| 181 | 181 | * @param array $_data contact data for the action |
| 182 | 182 | * @return bool success or not |
| 183 | 183 | */ |
| 184 | - private function action ( $_action, $_data, $record_num = 0 ) { |
|
| 184 | + private function action($_action, $_data, $record_num = 0) { |
|
| 185 | 185 | switch ($_action) { |
| 186 | 186 | case 'none' : |
| 187 | 187 | return true; |
| 188 | 188 | case 'update' : |
| 189 | 189 | case 'create' : |
| 190 | - if(count($_data['account_members']) < 1) { |
|
| 190 | + if (count($_data['account_members']) < 1) { |
|
| 191 | 191 | $this->errors[$record_num] = lang('You must select at least one group member.'); |
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | $command = new admin_cmd_edit_group($_action == 'create' ? false : $_data['account_lid'], $_data); |
| 195 | - if($this->dry_run) { |
|
| 195 | + if ($this->dry_run) { |
|
| 196 | 196 | $this->results[$_action]++; |
| 197 | 197 | return true; |
| 198 | 198 | } |
@@ -15,7 +15,8 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * class import_csv for admin (groups) |
| 17 | 17 | */ |
| 18 | -class admin_import_groups_csv implements importexport_iface_import_plugin { |
|
| 18 | +class admin_import_groups_csv implements importexport_iface_import_plugin |
|
| 19 | +{ |
|
| 19 | 20 | |
| 20 | 21 | private static $plugin_options = array( |
| 21 | 22 | 'fieldsep', // char |
@@ -80,7 +81,8 @@ discard block |
||
| 80 | 81 | * @param string $_charset |
| 81 | 82 | * @param definition $_definition |
| 82 | 83 | */ |
| 83 | - public function import( $_stream, importexport_definition $_definition ) { |
|
| 84 | + public function import( $_stream, importexport_definition $_definition ) |
|
| 85 | + { |
|
| 84 | 86 | $import_csv = new importexport_import_csv( $_stream, array( |
| 85 | 87 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
| 86 | 88 | 'charset' => $_definition->plugin_options['charset'], |
@@ -98,9 +100,12 @@ discard block |
||
| 98 | 100 | $import_csv->conversion = $_definition->plugin_options['field_conversion']; |
| 99 | 101 | |
| 100 | 102 | //check if file has a header lines |
| 101 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) { |
|
| 103 | + if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) |
|
| 104 | + { |
|
| 102 | 105 | $import_csv->skip_records($_definition->plugin_options['num_header_lines']); |
| 103 | - } elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) { |
|
| 106 | + } |
|
| 107 | + elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) |
|
| 108 | + { |
|
| 104 | 109 | // First method is preferred |
| 105 | 110 | $import_csv->skip_records(1); |
| 106 | 111 | } |
@@ -112,22 +117,30 @@ discard block |
||
| 112 | 117 | // Failures |
| 113 | 118 | $this->errors = array(); |
| 114 | 119 | |
| 115 | - while ( $record = $import_csv->get_record() ) { |
|
| 120 | + while ( $record = $import_csv->get_record() ) |
|
| 121 | + { |
|
| 116 | 122 | $success = false; |
| 117 | 123 | // don't import empty records |
| 118 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
| 124 | + if( count( array_unique( $record ) ) < 2 ) |
|
| 125 | + { |
|
| 126 | + continue; |
|
| 127 | + } |
|
| 119 | 128 | |
| 120 | 129 | importexport_import_csv::convert($record, admin_egw_group_record::$types, 'admin'); |
| 121 | 130 | |
| 122 | - if ( $_definition->plugin_options['conditions'] ) { |
|
| 123 | - foreach ( $_definition->plugin_options['conditions'] as $condition ) { |
|
| 124 | - switch ( $condition['type'] ) { |
|
| 131 | + if ( $_definition->plugin_options['conditions'] ) |
|
| 132 | + { |
|
| 133 | + foreach ( $_definition->plugin_options['conditions'] as $condition ) |
|
| 134 | + { |
|
| 135 | + switch ( $condition['type'] ) |
|
| 136 | + { |
|
| 125 | 137 | // exists |
| 126 | 138 | case 'exists' : |
| 127 | 139 | $accounts = array(); |
| 128 | 140 | |
| 129 | 141 | // Skip the search if the field is empty |
| 130 | - if($record[$condition['string']] !== '') { |
|
| 142 | + if($record[$condition['string']] !== '') |
|
| 143 | + { |
|
| 131 | 144 | |
| 132 | 145 | $accounts = $GLOBALS['egw']->accounts->search(array( |
| 133 | 146 | 'type' => 'groups', |
@@ -138,13 +151,18 @@ discard block |
||
| 138 | 151 | // Search looks in the given field, but doesn't do an exact match |
| 139 | 152 | foreach ( (array)$accounts as $key => $account ) |
| 140 | 153 | { |
| 141 | - if($account[$condition['string']] != $record[$condition['string']]) unset($accounts[$key]); |
|
| 154 | + if($account[$condition['string']] != $record[$condition['string']]) |
|
| 155 | + { |
|
| 156 | + unset($accounts[$key]); |
|
| 157 | + } |
|
| 142 | 158 | } |
| 143 | - if ( is_array( $accounts ) && count( $accounts ) >= 1 ) { |
|
| 159 | + if ( is_array( $accounts ) && count( $accounts ) >= 1 ) |
|
| 160 | + { |
|
| 144 | 161 | $account = current($accounts); |
| 145 | 162 | // apply action to all contacts matching this exists condition |
| 146 | 163 | $action = $condition['true']; |
| 147 | - foreach ( (array)$accounts as $account ) { |
|
| 164 | + foreach ( (array)$accounts as $account ) |
|
| 165 | + { |
|
| 148 | 166 | // Read full account, and copy needed info for accounts->save() |
| 149 | 167 | $account = $GLOBALS['egw']->accounts->read($account['account_id']); |
| 150 | 168 | $record['account_id'] = $account['account_id']; |
@@ -152,7 +170,9 @@ discard block |
||
| 152 | 170 | $record['account_lastname'] = $account['account_lastname']; |
| 153 | 171 | $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
| 154 | 172 | } |
| 155 | - } else { |
|
| 173 | + } |
|
| 174 | + else |
|
| 175 | + { |
|
| 156 | 176 | $action = $condition['false']; |
| 157 | 177 | $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
| 158 | 178 | } |
@@ -163,13 +183,21 @@ discard block |
||
| 163 | 183 | die('condition / action not supported!!!'); |
| 164 | 184 | break; |
| 165 | 185 | } |
| 166 | - if ($action['last']) break; |
|
| 186 | + if ($action['last']) |
|
| 187 | + { |
|
| 188 | + break; |
|
| 189 | + } |
|
| 167 | 190 | } |
| 168 | - } else { |
|
| 191 | + } |
|
| 192 | + else |
|
| 193 | + { |
|
| 169 | 194 | // unconditional insert |
| 170 | 195 | $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
| 171 | 196 | } |
| 172 | - if($success) $count++; |
|
| 197 | + if($success) |
|
| 198 | + { |
|
| 199 | + $count++; |
|
| 200 | + } |
|
| 173 | 201 | } |
| 174 | 202 | return $count; |
| 175 | 203 | } |
@@ -181,24 +209,29 @@ discard block |
||
| 181 | 209 | * @param array $_data contact data for the action |
| 182 | 210 | * @return bool success or not |
| 183 | 211 | */ |
| 184 | - private function action ( $_action, $_data, $record_num = 0 ) { |
|
| 185 | - switch ($_action) { |
|
| 212 | + private function action ( $_action, $_data, $record_num = 0 ) |
|
| 213 | + { |
|
| 214 | + switch ($_action) |
|
| 215 | + { |
|
| 186 | 216 | case 'none' : |
| 187 | 217 | return true; |
| 188 | 218 | case 'update' : |
| 189 | 219 | case 'create' : |
| 190 | - if(count($_data['account_members']) < 1) { |
|
| 220 | + if(count($_data['account_members']) < 1) |
|
| 221 | + { |
|
| 191 | 222 | $this->errors[$record_num] = lang('You must select at least one group member.'); |
| 192 | 223 | return false; |
| 193 | 224 | } |
| 194 | 225 | $command = new admin_cmd_edit_group($_action == 'create' ? false : $_data['account_lid'], $_data); |
| 195 | - if($this->dry_run) { |
|
| 226 | + if($this->dry_run) |
|
| 227 | + { |
|
| 196 | 228 | $this->results[$_action]++; |
| 197 | 229 | return true; |
| 198 | 230 | } |
| 199 | 231 | try { |
| 200 | 232 | $command->run(); |
| 201 | - } catch (Exception $e) { |
|
| 233 | + } |
|
| 234 | + catch (Exception $e) { |
|
| 202 | 235 | $this->errors[$record_num] = $e->getMessage(); |
| 203 | 236 | return false; |
| 204 | 237 | } |
@@ -215,7 +248,8 @@ discard block |
||
| 215 | 248 | * |
| 216 | 249 | * @return string name |
| 217 | 250 | */ |
| 218 | - public static function get_name() { |
|
| 251 | + public static function get_name() |
|
| 252 | + { |
|
| 219 | 253 | return lang('Group CSV import'); |
| 220 | 254 | } |
| 221 | 255 | |
@@ -224,7 +258,8 @@ discard block |
||
| 224 | 258 | * |
| 225 | 259 | * @return string descriprion |
| 226 | 260 | */ |
| 227 | - public static function get_description() { |
|
| 261 | + public static function get_description() |
|
| 262 | + { |
|
| 228 | 263 | return lang("Creates / updates user groups from CSV file"); |
| 229 | 264 | } |
| 230 | 265 | |
@@ -233,7 +268,8 @@ discard block |
||
| 233 | 268 | * |
| 234 | 269 | * @return string suffix (comma seperated) |
| 235 | 270 | */ |
| 236 | - public static function get_filesuffix() { |
|
| 271 | + public static function get_filesuffix() |
|
| 272 | + { |
|
| 237 | 273 | return 'csv'; |
| 238 | 274 | } |
| 239 | 275 | |
@@ -249,7 +285,8 @@ discard block |
||
| 249 | 285 | * preserv => array, |
| 250 | 286 | * ) |
| 251 | 287 | */ |
| 252 | - public function get_options_etpl() { |
|
| 288 | + public function get_options_etpl() |
|
| 289 | + { |
|
| 253 | 290 | // lets do it! |
| 254 | 291 | } |
| 255 | 292 | |
@@ -258,7 +295,8 @@ discard block |
||
| 258 | 295 | * |
| 259 | 296 | * @return string etemplate name |
| 260 | 297 | */ |
| 261 | - public function get_selectors_etpl() { |
|
| 298 | + public function get_selectors_etpl() |
|
| 299 | + { |
|
| 262 | 300 | // lets do it! |
| 263 | 301 | } |
| 264 | 302 | |
@@ -270,7 +308,8 @@ discard block |
||
| 270 | 308 | * record_# => warning message |
| 271 | 309 | * ) |
| 272 | 310 | */ |
| 273 | - public function get_warnings() { |
|
| 311 | + public function get_warnings() |
|
| 312 | + { |
|
| 274 | 313 | return $this->warnings; |
| 275 | 314 | } |
| 276 | 315 | |
@@ -282,7 +321,8 @@ discard block |
||
| 282 | 321 | * record_# => error message |
| 283 | 322 | * ) |
| 284 | 323 | */ |
| 285 | - public function get_errors() { |
|
| 324 | + public function get_errors() |
|
| 325 | + { |
|
| 286 | 326 | return $this->errors; |
| 287 | 327 | } |
| 288 | 328 | |
@@ -294,7 +334,8 @@ discard block |
||
| 294 | 334 | * action => record count |
| 295 | 335 | * ) |
| 296 | 336 | */ |
| 297 | - public function get_results() { |
|
| 337 | + public function get_results() |
|
| 338 | + { |
|
| 298 | 339 | return $this->results; |
| 299 | 340 | } |
| 300 | 341 | } |
@@ -291,7 +291,7 @@ |
||
| 291 | 291 | * Check if next submission is due, in which case we call submit and NOT return to the admin hook |
| 292 | 292 | * |
| 293 | 293 | * @param boolean $redirect should we redirect or return true |
| 294 | - * @return boolean true if statistic submission is due |
|
| 294 | + * @return boolean|null true if statistic submission is due |
|
| 295 | 295 | */ |
| 296 | 296 | public static function check($redirect=true) |
| 297 | 297 | { |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | const SUBMIT_URL = 'https://www.egroupware.org/usage-statistic'; |
| 31 | 31 | const STATISTIC_URL = 'http://www.egroupware.org/usage-statistic'; |
| 32 | 32 | |
| 33 | - const SUBMISION_RATE = 2592000; // 30 days |
|
| 33 | + const SUBMISION_RATE = 2592000; // 30 days |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Which methods of this class can be called as menuation |
@@ -46,27 +46,27 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @param array $_content =null |
| 48 | 48 | */ |
| 49 | - public function submit($_content=null) |
|
| 49 | + public function submit($_content = null) |
|
| 50 | 50 | { |
| 51 | 51 | if (is_array($_content)) |
| 52 | 52 | { |
| 53 | 53 | $config = new Api\Config(self::CONFIG_APP); |
| 54 | 54 | if ($_content['postpone']) |
| 55 | 55 | { |
| 56 | - Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT,time()+$_content['postpone'],self::CONFIG_APP); |
|
| 56 | + Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT, time() + $_content['postpone'], self::CONFIG_APP); |
|
| 57 | 57 | $what = 'postpone'; |
| 58 | 58 | } |
| 59 | - elseif(!$_content['cancel']) |
|
| 59 | + elseif (!$_content['cancel']) |
|
| 60 | 60 | { |
| 61 | - Api\Config::save_value(self::CONFIG_LAST_SUBMIT,time(),self::CONFIG_APP); |
|
| 62 | - Api\Config::save_value(self::CONFIG_SUBMIT_ID,empty($_content['submit_id']) ? '***none***' : $_content['submit_id'],self::CONFIG_APP); |
|
| 63 | - Api\Config::save_value(self::CONFIG_COUNTRY,empty($_content['country']) ? '***multinational***' : $_content['country'],self::CONFIG_APP); |
|
| 64 | - Api\Config::save_value(self::CONFIG_USAGE_TYPE,$_content['usage_type'],self::CONFIG_APP); |
|
| 65 | - Api\Config::save_value(self::CONFIG_INSTALL_TYPE,$_content['install_type'],self::CONFIG_APP); |
|
| 66 | - Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT,null,self::CONFIG_APP); // remove evtl. postpone time |
|
| 61 | + Api\Config::save_value(self::CONFIG_LAST_SUBMIT, time(), self::CONFIG_APP); |
|
| 62 | + Api\Config::save_value(self::CONFIG_SUBMIT_ID, empty($_content['submit_id']) ? '***none***' : $_content['submit_id'], self::CONFIG_APP); |
|
| 63 | + Api\Config::save_value(self::CONFIG_COUNTRY, empty($_content['country']) ? '***multinational***' : $_content['country'], self::CONFIG_APP); |
|
| 64 | + Api\Config::save_value(self::CONFIG_USAGE_TYPE, $_content['usage_type'], self::CONFIG_APP); |
|
| 65 | + Api\Config::save_value(self::CONFIG_INSTALL_TYPE, $_content['install_type'], self::CONFIG_APP); |
|
| 66 | + Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT, null, self::CONFIG_APP); // remove evtl. postpone time |
|
| 67 | 67 | $what = 'submitted'; |
| 68 | 68 | } |
| 69 | - Egw::redirect_link('/admin/index.php','ajax=true&statistics='.($what ? $what : 'canceled'),'admin'); |
|
| 69 | + Egw::redirect_link('/admin/index.php', 'ajax=true&statistics='.($what ? $what : 'canceled'), 'admin'); |
|
| 70 | 70 | } |
| 71 | 71 | $sel_options['usage_type'] = array( |
| 72 | 72 | 'commercial' => lang('Commercial: all sorts of companies'), |
@@ -86,19 +86,19 @@ discard block |
||
| 86 | 86 | $sel_options['postpone'] = array( |
| 87 | 87 | //10 => '10 secs', |
| 88 | 88 | 3600 => lang('one hour'), |
| 89 | - 2*3600 => lang('two hours'), |
|
| 90 | - 24*3600 => lang('one day'), |
|
| 91 | - 2*24*3600 => lang('two days'), |
|
| 92 | - 7*24*3600 => lang('one week'), |
|
| 93 | - 14*24*3600 => lang('two weeks'), |
|
| 94 | - 30*24*3600 => lang('one month'), |
|
| 95 | - 60*24*3600 => lang('two months'), |
|
| 89 | + 2 * 3600 => lang('two hours'), |
|
| 90 | + 24 * 3600 => lang('one day'), |
|
| 91 | + 2 * 24 * 3600 => lang('two days'), |
|
| 92 | + 7 * 24 * 3600 => lang('one week'), |
|
| 93 | + 14 * 24 * 3600 => lang('two weeks'), |
|
| 94 | + 30 * 24 * 3600 => lang('one month'), |
|
| 95 | + 60 * 24 * 3600 => lang('two months'), |
|
| 96 | 96 | ); |
| 97 | 97 | $config = Api\Config::read(self::CONFIG_APP); |
| 98 | 98 | //_debug_array($config); |
| 99 | - $content = array_merge(self::gather_data(),array( |
|
| 99 | + $content = array_merge(self::gather_data(), array( |
|
| 100 | 100 | 'statistic_url' => self::STATISTIC_URL, |
| 101 | - 'submit_host' => parse_url(self::SUBMIT_URL,PHP_URL_HOST), |
|
| 101 | + 'submit_host' => parse_url(self::SUBMIT_URL, PHP_URL_HOST), |
|
| 102 | 102 | 'submit_url' => self::SUBMIT_URL, |
| 103 | 103 | 'last_submitted' => $config[self::CONFIG_LAST_SUBMIT], |
| 104 | 104 | )); |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | $sel_options['install_type'] = array($content['install_type'] => $sel_options['install_type'][$content['install_type']]); |
| 126 | 126 | } |
| 127 | 127 | // else default to previous type |
| 128 | - elseif($config[self::CONFIG_INSTALL_TYPE]) |
|
| 128 | + elseif ($config[self::CONFIG_INSTALL_TYPE]) |
|
| 129 | 129 | { |
| 130 | 130 | $content['install_type'] = $config[self::CONFIG_INSTALL_TYPE]; |
| 131 | 131 | } |
| 132 | 132 | // check if we are due for a new submission |
| 133 | - if (!isset($config[self::CONFIG_LAST_SUBMIT]) || $config[self::CONFIG_LAST_SUBMIT ] <= time()-self::SUBMISION_RATE) |
|
| 133 | + if (!isset($config[self::CONFIG_LAST_SUBMIT]) || $config[self::CONFIG_LAST_SUBMIT] <= time() - self::SUBMISION_RATE) |
|
| 134 | 134 | { |
| 135 | 135 | // clear etemplate_exec_id and replace form.action, before submitting the form |
| 136 | 136 | $content['onclick'] = "return app.admin.submit_statistic(this.form,'$content[submit_url]');"; |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | { |
| 140 | 140 | $readonlys['submit'] = $readonlys['postpone'] = true; |
| 141 | 141 | $content['msg'] = lang('Your last submission was less then %1 days ago!', |
| 142 | - ceil((time()-$config[self::CONFIG_LAST_SUBMIT])/24/3600)); |
|
| 142 | + ceil((time() - $config[self::CONFIG_LAST_SUBMIT]) / 24 / 3600)); |
|
| 143 | 143 | } |
| 144 | 144 | $GLOBALS['egw_info']['flags']['app_header'] = lang('Submit statistic information'); |
| 145 | 145 | $tmpl = new Etemplate('admin.statistics'); |
| 146 | - $tmpl->exec('admin.admin_statistics.submit',$content,$sel_options,$readonlys); |
|
| 146 | + $tmpl->exec('admin.admin_statistics.submit', $content, $sel_options, $readonlys); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $data['version'] .= ' '.$GLOBALS['egw_info']['apps']['stylite']['version'].'EPL'; |
| 167 | 167 | } |
| 168 | 168 | // sessions in the last 30 days |
| 169 | - $data['sessions'] = $GLOBALS['egw']->db->query('SELECT COUNT(*) FROM egw_access_log WHERE li > '.(time()-30*24*3600))->fetchColumn(); |
|
| 169 | + $data['sessions'] = $GLOBALS['egw']->db->query('SELECT COUNT(*) FROM egw_access_log WHERE li > '.(time() - 30 * 24 * 3600))->fetchColumn(); |
|
| 170 | 170 | |
| 171 | 171 | // total accounts from accounts table or ldap |
| 172 | 172 | $GLOBALS['egw']->accounts->search(array( |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | // @ required to get ride of warning, if files are outside of open_basedir |
| 181 | 181 | if (@file_exists($file = '/etc/SuSE-release') || @file_exists($file = '/etc/redhat-release') || @file_exists($file = '/etc/debian_version')) |
| 182 | 182 | { |
| 183 | - $data['os'] .= ': '.str_replace(array("\n","\r"),'',implode(',',file($file))); |
|
| 183 | + $data['os'] .= ': '.str_replace(array("\n", "\r"), '', implode(',', file($file))); |
|
| 184 | 184 | } |
| 185 | - if(file_exists(EGW_INCLUDE_ROOT.'/.git')) |
|
| 185 | + if (file_exists(EGW_INCLUDE_ROOT.'/.git')) |
|
| 186 | 186 | { |
| 187 | 187 | $data['install_type'] = 'git'; |
| 188 | 188 | } |
@@ -190,22 +190,22 @@ discard block |
||
| 190 | 190 | { |
| 191 | 191 | $data['install_type'] = 'svn'; |
| 192 | 192 | } |
| 193 | - elseif(EGW_INCLUDE_ROOT == '/usr/share/egroupware' && PHP_OS == 'Linux' && is_link('/usr/share/egroupware/header.inc.php')) |
|
| 193 | + elseif (EGW_INCLUDE_ROOT == '/usr/share/egroupware' && PHP_OS == 'Linux' && is_link('/usr/share/egroupware/header.inc.php')) |
|
| 194 | 194 | { |
| 195 | 195 | $data['install_type'] = 'package'; |
| 196 | 196 | } |
| 197 | - foreach(array_keys($GLOBALS['egw_info']['apps']) as $app) |
|
| 197 | + foreach (array_keys($GLOBALS['egw_info']['apps']) as $app) |
|
| 198 | 198 | { |
| 199 | - if (in_array($app,array( |
|
| 200 | - 'admin','phpgwapi','api','sambaadmin','developer_tools', |
|
| 201 | - 'home','preferences','etemplate','registration','manual', |
|
| 199 | + if (in_array($app, array( |
|
| 200 | + 'admin', 'phpgwapi', 'api', 'sambaadmin', 'developer_tools', |
|
| 201 | + 'home', 'preferences', 'etemplate', 'registration', 'manual', |
|
| 202 | 202 | ))) |
| 203 | 203 | { |
| 204 | - continue; // --> ignore to not submit too much |
|
| 204 | + continue; // --> ignore to not submit too much |
|
| 205 | 205 | } |
| 206 | 206 | if (($users = self::gather_app_users($app))) // ignore apps noone is allowed to run |
| 207 | 207 | { |
| 208 | - $data['apps'][$app] = $app.':'.round(100.0*$users/$data['users']).'%'; |
|
| 208 | + $data['apps'][$app] = $app.':'.round(100.0 * $users / $data['users']).'%'; |
|
| 209 | 209 | if (($entries = self::gather_app_entries($app))) |
| 210 | 210 | { |
| 211 | 211 | $data['apps'][$app] .= ':'.$entries; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | ksort($data['apps']); |
| 216 | - $data['apps'] = implode("\n",$data['apps']); |
|
| 216 | + $data['apps'] = implode("\n", $data['apps']); |
|
| 217 | 217 | |
| 218 | 218 | return $data; |
| 219 | 219 | } |
@@ -227,17 +227,17 @@ discard block |
||
| 227 | 227 | static function gather_app_users($app) |
| 228 | 228 | { |
| 229 | 229 | $users = array(); |
| 230 | - if (($access = $GLOBALS['egw']->acl->get_ids_for_location('run',1,$app))) |
|
| 230 | + if (($access = $GLOBALS['egw']->acl->get_ids_for_location('run', 1, $app))) |
|
| 231 | 231 | { |
| 232 | - foreach($access as $uid) |
|
| 232 | + foreach ($access as $uid) |
|
| 233 | 233 | { |
| 234 | 234 | if ($uid > 0) |
| 235 | 235 | { |
| 236 | 236 | $users[] = $uid; |
| 237 | 237 | } |
| 238 | - elseif (($members = $GLOBALS['egw']->accounts->members($uid,true))) |
|
| 238 | + elseif (($members = $GLOBALS['egw']->accounts->members($uid, true))) |
|
| 239 | 239 | { |
| 240 | - $users = array_merge($users,$members); |
|
| 240 | + $users = array_merge($users, $members); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | $users = array_unique($users); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | 'infolog' => 'egw_infolog', |
| 262 | 262 | 'filemanager' => 'egw_sqlfs', |
| 263 | 263 | 'gallery' => 'g2_Item', |
| 264 | - 'news_admin' => 'egw_news WHERE news_submittedby > 0', // exclude imported rss feeds |
|
| 264 | + 'news_admin' => 'egw_news WHERE news_submittedby > 0', // exclude imported rss feeds |
|
| 265 | 265 | 'polls' => 'egw_polls', |
| 266 | 266 | 'projectmanager' => 'egw_pm_projects', |
| 267 | 267 | 'phpbrain' => 'egw_kb_articles', |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | $entries = (int)$GLOBALS['egw']->db->query('SELECT COUNT(*) FROM '.$table)->fetchColumn(); |
| 280 | 280 | //echo "$app ($table): $entries<br />\n"; |
| 281 | 281 | } |
| 282 | - catch(Api\Db\Exception $e) { |
|
| 282 | + catch (Api\Db\Exception $e) { |
|
| 283 | 283 | unset($e); |
| 284 | 284 | $entries = null; |
| 285 | 285 | } |
@@ -293,19 +293,19 @@ discard block |
||
| 293 | 293 | * @param boolean $redirect should we redirect or return true |
| 294 | 294 | * @return boolean true if statistic submission is due |
| 295 | 295 | */ |
| 296 | - public static function check($redirect=true) |
|
| 296 | + public static function check($redirect = true) |
|
| 297 | 297 | { |
| 298 | 298 | $config = Api\Config::read(self::CONFIG_APP); |
| 299 | 299 | |
| 300 | 300 | if (isset($config[self::CONFIG_POSTPONE_SUBMIT]) && $config[self::CONFIG_POSTPONE_SUBMIT] > time() || |
| 301 | - isset($config[self::CONFIG_LAST_SUBMIT ]) && $config[self::CONFIG_LAST_SUBMIT ] > time()-self::SUBMISION_RATE) |
|
| 301 | + isset($config[self::CONFIG_LAST_SUBMIT]) && $config[self::CONFIG_LAST_SUBMIT] > time() - self::SUBMISION_RATE) |
|
| 302 | 302 | { |
| 303 | 303 | return false; |
| 304 | 304 | } |
| 305 | 305 | if (!$redirect) return true; |
| 306 | 306 | |
| 307 | 307 | //die('Due for new statistics submission: last_submit='.$config[self::CONFIG_LAST_SUBMIT ].', postpone='.$config[self::CONFIG_POSTPONE_SUBMIT].', '.function_backtrace()); |
| 308 | - Egw::redirect_link('/index.php',array( |
|
| 308 | + Egw::redirect_link('/index.php', array( |
|
| 309 | 309 | 'menuaction' => 'admin.admin_ui.index', |
| 310 | 310 | 'ajax' => 'true', |
| 311 | 311 | 'load' => 'admin.admin_statistics.submit', |
@@ -203,9 +203,12 @@ discard block |
||
| 203 | 203 | { |
| 204 | 204 | continue; // --> ignore to not submit too much |
| 205 | 205 | } |
| 206 | - if (($users = self::gather_app_users($app))) // ignore apps noone is allowed to run |
|
| 206 | + if (($users = self::gather_app_users($app))) |
|
| 207 | + { |
|
| 208 | + // ignore apps noone is allowed to run |
|
| 207 | 209 | { |
| 208 | 210 | $data['apps'][$app] = $app.':'.round(100.0*$users/$data['users']).'%'; |
| 211 | + } |
|
| 209 | 212 | if (($entries = self::gather_app_entries($app))) |
| 210 | 213 | { |
| 211 | 214 | $data['apps'][$app] .= ':'.$entries; |
@@ -302,7 +305,10 @@ discard block |
||
| 302 | 305 | { |
| 303 | 306 | return false; |
| 304 | 307 | } |
| 305 | - if (!$redirect) return true; |
|
| 308 | + if (!$redirect) |
|
| 309 | + { |
|
| 310 | + return true; |
|
| 311 | + } |
|
| 306 | 312 | |
| 307 | 313 | //die('Due for new statistics submission: last_submit='.$config[self::CONFIG_LAST_SUBMIT ].', postpone='.$config[self::CONFIG_POSTPONE_SUBMIT].', '.function_backtrace()); |
| 308 | 314 | Egw::redirect_link('/index.php',array( |
@@ -491,6 +491,10 @@ |
||
| 491 | 491 | protected static function call_hook() |
| 492 | 492 | { |
| 493 | 493 | self::$hook_data = array(); |
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param string $appname |
|
| 497 | + */ |
|
| 494 | 498 | function display_section($appname,$file,$file2=False) |
| 495 | 499 | { |
| 496 | 500 | admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file; |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param array $content |
| 42 | 42 | */ |
| 43 | - public function index(array $content=null) |
|
| 43 | + public function index(array $content = null) |
|
| 44 | 44 | { |
| 45 | 45 | if (admin_statistics::check(false)) |
| 46 | 46 | { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | //$content['msg'] = 'Hi Ralf ;-)'; |
| 66 | 66 | $sel_options['tree'] = $this->tree_data(); |
| 67 | 67 | $sel_options['filter'] = array('' => lang('All groups')); |
| 68 | - foreach(self::$accounts->search(array( |
|
| 68 | + foreach (self::$accounts->search(array( |
|
| 69 | 69 | 'type' => 'groups', |
| 70 | 70 | 'start' => false, |
| 71 | 71 | 'order' => 'account_lid', |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | else |
| 98 | 98 | { |
| 99 | - $content['iframe'] = 'about:blank'; // we show accounts-list be default now |
|
| 99 | + $content['iframe'] = 'about:blank'; // we show accounts-list be default now |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $tpl->exec('admin.admin_ui.index', $content, $sel_options); |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | 'caption' => 'Show members', |
| 118 | 118 | 'enableId' => '^/groups/-\\d+', |
| 119 | 119 | 'default' => true, |
| 120 | - 'group' => $group=1, |
|
| 120 | + 'group' => $group = 1, |
|
| 121 | 121 | ), |
| 122 | 122 | 'add' => array( |
| 123 | 123 | 'group' => $group, |
| 124 | - )+$user_actions['add'], |
|
| 124 | + ) + $user_actions['add'], |
|
| 125 | 125 | 'acl' => array( |
| 126 | 126 | 'onExecute' => 'javaScript:app.admin.group', |
| 127 | 127 | 'caption' => 'Access control', |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | 'group' => 2, |
| 133 | 133 | ), |
| 134 | 134 | ); |
| 135 | - if (!$GLOBALS['egw']->acl->check('account_access',64,'admin')) // no rights to set ACL-rights |
|
| 135 | + if (!$GLOBALS['egw']->acl->check('account_access', 64, 'admin')) // no rights to set ACL-rights |
|
| 136 | 136 | { |
| 137 | 137 | $actions['deny'] = array( |
| 138 | 138 | 'caption' => 'Deny access', |
@@ -143,16 +143,16 @@ discard block |
||
| 143 | 143 | 'group' => 2, |
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | - $group = 5; // allow to place actions in different groups by hook, this is the default |
|
| 146 | + $group = 5; // allow to place actions in different groups by hook, this is the default |
|
| 147 | 147 | // supporting both old way using $GLOBALS['menuData'] and new just returning data in hook |
| 148 | 148 | $apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_group'))); |
| 149 | - foreach($apps as $app) |
|
| 149 | + foreach ($apps as $app) |
|
| 150 | 150 | { |
| 151 | 151 | $GLOBALS['menuData'] = $data = array(); |
| 152 | 152 | $data = Api\Hooks::single('edit_group', $app); |
| 153 | 153 | if (!is_array($data)) $data = $GLOBALS['menuData']; |
| 154 | 154 | //error_log(__METHOD__."() app $app returned ".array2string($data)); |
| 155 | - foreach($data as $item) |
|
| 155 | + foreach ($data as $item) |
|
| 156 | 156 | { |
| 157 | 157 | // allow hook to return "real" actions, but still support legacy: description, url, extradata, options |
| 158 | 158 | if (empty($item['caption'])) |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | 'default' => true, |
| 204 | 204 | 'allowOnMultiple' => false, |
| 205 | 205 | 'onExecute' => 'javaScript:app.admin.account', |
| 206 | - 'group' => $group=0, |
|
| 206 | + 'group' => $group = 0, |
|
| 207 | 207 | ), |
| 208 | 208 | 'add' => array( |
| 209 | 209 | 'caption' => 'Add user', |
@@ -214,25 +214,25 @@ discard block |
||
| 214 | 214 | // generate urls for add/edit accounts via addressbook |
| 215 | 215 | $edit = Link::get_registry('addressbook', 'edit'); |
| 216 | 216 | $edit['account_id'] = '$id'; |
| 217 | - foreach($edit as $name => $val) |
|
| 217 | + foreach ($edit as $name => $val) |
|
| 218 | 218 | { |
| 219 | 219 | $actions['edit']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val; |
| 220 | 220 | } |
| 221 | 221 | unset($edit['account_id']); |
| 222 | 222 | $edit['owner'] = 0; |
| 223 | - foreach($edit as $name => $val) |
|
| 223 | + foreach ($edit as $name => $val) |
|
| 224 | 224 | { |
| 225 | 225 | $actions['add']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val; |
| 226 | 226 | } |
| 227 | 227 | ++$group; |
| 228 | 228 | // supporting both old way using $GLOBALS['menuData'] and new just returning data in hook |
| 229 | 229 | $apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_user'))); |
| 230 | - foreach($apps as $app) |
|
| 230 | + foreach ($apps as $app) |
|
| 231 | 231 | { |
| 232 | 232 | $GLOBALS['menuData'] = $data = array(); |
| 233 | 233 | $data = Api\Hooks::single('edit_user', $app); |
| 234 | 234 | if (!is_array($data)) $data = $GLOBALS['menuData']; |
| 235 | - foreach($data as $item) |
|
| 235 | + foreach ($data as $item) |
|
| 236 | 236 | { |
| 237 | 237 | // allow hook to return "real" actions, but still support legacy: description, url, extradata, options |
| 238 | 238 | if (empty($item['caption'])) |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @param array &$rows=null |
| 282 | 282 | * @return int total number of rows available |
| 283 | 283 | */ |
| 284 | - public static function get_users(array $query, array &$rows=null) |
|
| 284 | + public static function get_users(array $query, array &$rows = null) |
|
| 285 | 285 | { |
| 286 | 286 | $params = array( |
| 287 | 287 | 'type' => (int)$query['filter'] ? (int)$query['filter'] : 'accounts', |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | $params['query'] = $query['searchletter']; |
| 297 | 297 | $params['query_type'] = 'start'; |
| 298 | 298 | } |
| 299 | - elseif($query['search']) |
|
| 299 | + elseif ($query['search']) |
|
| 300 | 300 | { |
| 301 | 301 | $params['query'] = $query['search']; |
| 302 | 302 | $params['query_type'] = 'all'; |
@@ -305,13 +305,10 @@ discard block |
||
| 305 | 305 | $rows = array_values(self::$accounts->search($params)); |
| 306 | 306 | //error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total); |
| 307 | 307 | |
| 308 | - foreach($rows as &$row) |
|
| 308 | + foreach ($rows as &$row) |
|
| 309 | 309 | { |
| 310 | 310 | $row['status'] = self::$accounts->is_expired($row) ? |
| 311 | - lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) : |
|
| 312 | - (!self::$accounts->is_active($row) ? lang('Disabled') : |
|
| 313 | - ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : |
|
| 314 | - lang('Enabled'))); |
|
| 311 | + lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) : (!self::$accounts->is_active($row) ? lang('Disabled') : ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : lang('Enabled'))); |
|
| 315 | 312 | |
| 316 | 313 | if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive'; |
| 317 | 314 | } |
@@ -352,14 +349,14 @@ discard block |
||
| 352 | 349 | if ($root == '/') |
| 353 | 350 | { |
| 354 | 351 | $hook_data = self::call_hook(); |
| 355 | - foreach($hook_data as $app => $app_data) |
|
| 352 | + foreach ($hook_data as $app => $app_data) |
|
| 356 | 353 | { |
| 357 | - if(!is_array($app_data)) |
|
| 354 | + if (!is_array($app_data)) |
|
| 358 | 355 | { |
| 359 | 356 | // Application has no data |
| 360 | 357 | continue; |
| 361 | 358 | } |
| 362 | - foreach($app_data as $text => $data) |
|
| 359 | + foreach ($app_data as $text => $data) |
|
| 363 | 360 | { |
| 364 | 361 | if (!is_array($data)) |
| 365 | 362 | { |
@@ -390,18 +387,17 @@ discard block |
||
| 390 | 387 | } |
| 391 | 388 | } |
| 392 | 389 | unset($data['icon']); |
| 393 | - $parent =& $tree['item']; |
|
| 390 | + $parent = & $tree['item']; |
|
| 394 | 391 | $parts = explode('/', $data['id']); |
| 395 | - if ($data['id'][0] == '/') array_shift($parts); // remove root |
|
| 392 | + if ($data['id'][0] == '/') array_shift($parts); // remove root |
|
| 396 | 393 | array_pop($parts); |
| 397 | 394 | $path = ''; |
| 398 | - foreach($parts as $part) |
|
| 395 | + foreach ($parts as $part) |
|
| 399 | 396 | { |
| 400 | 397 | $path .= ($path == '/' ? '' : '/').$part; |
| 401 | 398 | if (!isset($parent[$path])) |
| 402 | 399 | { |
| 403 | - $icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : |
|
| 404 | - (($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav'))); |
|
| 400 | + $icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : (($i = Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav'))); |
|
| 405 | 401 | $parent[$path] = array( |
| 406 | 402 | 'id' => $path, |
| 407 | 403 | 'text' => $part == 'apps' ? lang('Applications') : lang($part), |
@@ -413,7 +409,7 @@ discard block |
||
| 413 | 409 | ); |
| 414 | 410 | if ($path == '/admin') $parent[$path]['open'] = true; |
| 415 | 411 | } |
| 416 | - $parent =& $parent[$path]['item']; |
|
| 412 | + $parent = & $parent[$path]['item']; |
|
| 417 | 413 | } |
| 418 | 414 | $data['text'] = lang($data['text']); |
| 419 | 415 | if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']); |
@@ -425,7 +421,7 @@ discard block |
||
| 425 | 421 | } |
| 426 | 422 | elseif ($root == '/groups') |
| 427 | 423 | { |
| 428 | - foreach($GLOBALS['egw']->accounts->search(array( |
|
| 424 | + foreach ($GLOBALS['egw']->accounts->search(array( |
|
| 429 | 425 | 'type' => 'groups', |
| 430 | 426 | 'order' => 'account_lid', |
| 431 | 427 | 'sort' => 'ASC', |
@@ -452,8 +448,8 @@ discard block |
||
| 452 | 448 | private static function fix_userdata(array $data) |
| 453 | 449 | { |
| 454 | 450 | // store link as userdata, maybe we should store everything not directly understood by tree this way ... |
| 455 | - foreach(array_diff_key($data, array_flip(array( |
|
| 456 | - 'id','text','tooltip','im0','im1','im2','item','child','select','open','call', |
|
| 451 | + foreach (array_diff_key($data, array_flip(array( |
|
| 452 | + 'id', 'text', 'tooltip', 'im0', 'im1', 'im2', 'item', 'child', 'select', 'open', 'call', |
|
| 457 | 453 | ))) as $name => $content) |
| 458 | 454 | { |
| 459 | 455 | $data['userdata'][] = array( |
@@ -473,7 +469,7 @@ discard block |
||
| 473 | 469 | private static function strip_item_keys(array &$items) |
| 474 | 470 | { |
| 475 | 471 | $items = array_values($items); |
| 476 | - foreach($items as &$item) |
|
| 472 | + foreach ($items as &$item) |
|
| 477 | 473 | { |
| 478 | 474 | if (is_array($item) && isset($item['item'])) |
| 479 | 475 | { |
@@ -491,7 +487,7 @@ discard block |
||
| 491 | 487 | protected static function call_hook() |
| 492 | 488 | { |
| 493 | 489 | self::$hook_data = array(); |
| 494 | - function display_section($appname,$file,$file2=False) |
|
| 490 | + function display_section($appname, $file, $file2 = False) |
|
| 495 | 491 | { |
| 496 | 492 | admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file; |
| 497 | 493 | //error_log(__METHOD__."(".array2string(func_get_args()).")"); |
@@ -48,7 +48,10 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | $tpl = new Etemplate('admin.index'); |
| 50 | 50 | |
| 51 | - if (!is_array($content)) $content = array(); |
|
| 51 | + if (!is_array($content)) |
|
| 52 | + { |
|
| 53 | + $content = array(); |
|
| 54 | + } |
|
| 52 | 55 | $content['nm'] = array( |
| 53 | 56 | 'get_rows' => 'admin_ui::get_users', |
| 54 | 57 | 'no_cat' => true, |
@@ -132,7 +135,9 @@ discard block |
||
| 132 | 135 | 'group' => 2, |
| 133 | 136 | ), |
| 134 | 137 | ); |
| 135 | - if (!$GLOBALS['egw']->acl->check('account_access',64,'admin')) // no rights to set ACL-rights |
|
| 138 | + if (!$GLOBALS['egw']->acl->check('account_access',64,'admin')) |
|
| 139 | + { |
|
| 140 | + // no rights to set ACL-rights |
|
| 136 | 141 | { |
| 137 | 142 | $actions['deny'] = array( |
| 138 | 143 | 'caption' => 'Deny access', |
@@ -143,6 +148,7 @@ discard block |
||
| 143 | 148 | 'group' => 2, |
| 144 | 149 | ); |
| 145 | 150 | } |
| 151 | + } |
|
| 146 | 152 | $group = 5; // allow to place actions in different groups by hook, this is the default |
| 147 | 153 | // supporting both old way using $GLOBALS['menuData'] and new just returning data in hook |
| 148 | 154 | $apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_group'))); |
@@ -150,7 +156,10 @@ discard block |
||
| 150 | 156 | { |
| 151 | 157 | $GLOBALS['menuData'] = $data = array(); |
| 152 | 158 | $data = Api\Hooks::single('edit_group', $app); |
| 153 | - if (!is_array($data)) $data = $GLOBALS['menuData']; |
|
| 159 | + if (!is_array($data)) |
|
| 160 | + { |
|
| 161 | + $data = $GLOBALS['menuData']; |
|
| 162 | + } |
|
| 154 | 163 | //error_log(__METHOD__."() app $app returned ".array2string($data)); |
| 155 | 164 | foreach($data as $item) |
| 156 | 165 | { |
@@ -170,15 +179,33 @@ discard block |
||
| 170 | 179 | { |
| 171 | 180 | $item['popup'] = $matches[2].'x'.$matches[3]; |
| 172 | 181 | $item['onExecute'] = 'javaScript:nm_action'; |
| 173 | - if (isset($matches[5])) $item['tooltip'] = $matches[5]; |
|
| 182 | + if (isset($matches[5])) |
|
| 183 | + { |
|
| 184 | + $item['tooltip'] = $matches[5]; |
|
| 185 | + } |
|
| 174 | 186 | unset($item['options']); |
| 175 | 187 | } |
| 176 | 188 | } |
| 177 | - if (empty($item['icon'])) $item['icon'] = $app.'/navbar'; |
|
| 178 | - if (empty($item['group'])) $item['group'] = $group; |
|
| 179 | - if (empty($item['onExecute'])) $item['onExecute'] = 'javaScript:app.admin.group'; |
|
| 180 | - if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false; |
|
| 181 | - if (!isset($item['enableId'])) $item['enableId'] = '^/groups/-\\d+'; |
|
| 189 | + if (empty($item['icon'])) |
|
| 190 | + { |
|
| 191 | + $item['icon'] = $app.'/navbar'; |
|
| 192 | + } |
|
| 193 | + if (empty($item['group'])) |
|
| 194 | + { |
|
| 195 | + $item['group'] = $group; |
|
| 196 | + } |
|
| 197 | + if (empty($item['onExecute'])) |
|
| 198 | + { |
|
| 199 | + $item['onExecute'] = 'javaScript:app.admin.group'; |
|
| 200 | + } |
|
| 201 | + if (!isset($item['allowOnMultiple'])) |
|
| 202 | + { |
|
| 203 | + $item['allowOnMultiple'] = false; |
|
| 204 | + } |
|
| 205 | + if (!isset($item['enableId'])) |
|
| 206 | + { |
|
| 207 | + $item['enableId'] = '^/groups/-\\d+'; |
|
| 208 | + } |
|
| 182 | 209 | |
| 183 | 210 | $actions[$item['id']] = $item; |
| 184 | 211 | } |
@@ -231,7 +258,10 @@ discard block |
||
| 231 | 258 | { |
| 232 | 259 | $GLOBALS['menuData'] = $data = array(); |
| 233 | 260 | $data = Api\Hooks::single('edit_user', $app); |
| 234 | - if (!is_array($data)) $data = $GLOBALS['menuData']; |
|
| 261 | + if (!is_array($data)) |
|
| 262 | + { |
|
| 263 | + $data = $GLOBALS['menuData']; |
|
| 264 | + } |
|
| 235 | 265 | foreach($data as $item) |
| 236 | 266 | { |
| 237 | 267 | // allow hook to return "real" actions, but still support legacy: description, url, extradata, options |
@@ -249,15 +279,30 @@ discard block |
||
| 249 | 279 | if ($item['options'] && preg_match('/(egw_openWindowCentered2?|window.open)\([^)]+,(\d+),(\d+).*(title="([^"]+)")?/', $item['options'], $matches)) |
| 250 | 280 | { |
| 251 | 281 | $item['popup'] = $matches[2].'x'.$matches[3]; |
| 252 | - if (isset($matches[5])) $item['tooltip'] = $matches[5]; |
|
| 282 | + if (isset($matches[5])) |
|
| 283 | + { |
|
| 284 | + $item['tooltip'] = $matches[5]; |
|
| 285 | + } |
|
| 253 | 286 | unset($item['options']); |
| 254 | 287 | } |
| 255 | 288 | } |
| 256 | - if (empty($item['icon'])) $item['icon'] = $app.'/navbar'; |
|
| 257 | - if (empty($item['group'])) $item['group'] = $group; |
|
| 258 | - if (empty($item['onExecute'])) $item['onExecute'] = $item['popup'] ? |
|
| 289 | + if (empty($item['icon'])) |
|
| 290 | + { |
|
| 291 | + $item['icon'] = $app.'/navbar'; |
|
| 292 | + } |
|
| 293 | + if (empty($item['group'])) |
|
| 294 | + { |
|
| 295 | + $item['group'] = $group; |
|
| 296 | + } |
|
| 297 | + if (empty($item['onExecute'])) |
|
| 298 | + { |
|
| 299 | + $item['onExecute'] = $item['popup'] ? |
|
| 259 | 300 | 'javaScript:nm_action' : 'javaScript:app.admin.iframe_location'; |
| 260 | - if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false; |
|
| 301 | + } |
|
| 302 | + if (!isset($item['allowOnMultiple'])) |
|
| 303 | + { |
|
| 304 | + $item['allowOnMultiple'] = false; |
|
| 305 | + } |
|
| 261 | 306 | |
| 262 | 307 | $actions[$item['id']] = $item; |
| 263 | 308 | } |
@@ -313,7 +358,10 @@ discard block |
||
| 313 | 358 | ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : |
| 314 | 359 | lang('Enabled'))); |
| 315 | 360 | |
| 316 | - if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive'; |
|
| 361 | + if (!self::$accounts->is_active($row)) |
|
| 362 | + { |
|
| 363 | + $row['status_class'] = 'adminAccountInactive'; |
|
| 364 | + } |
|
| 317 | 365 | } |
| 318 | 366 | |
| 319 | 367 | return self::$accounts->total; |
@@ -367,7 +415,10 @@ discard block |
||
| 367 | 415 | 'link' => $data, |
| 368 | 416 | ); |
| 369 | 417 | } |
| 370 | - if (empty($data['text'])) $data['text'] = $text; |
|
| 418 | + if (empty($data['text'])) |
|
| 419 | + { |
|
| 420 | + $data['text'] = $text; |
|
| 421 | + } |
|
| 371 | 422 | if (empty($data['id'])) |
| 372 | 423 | { |
| 373 | 424 | $data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/'; |
@@ -392,7 +443,11 @@ discard block |
||
| 392 | 443 | unset($data['icon']); |
| 393 | 444 | $parent =& $tree['item']; |
| 394 | 445 | $parts = explode('/', $data['id']); |
| 395 | - if ($data['id'][0] == '/') array_shift($parts); // remove root |
|
| 446 | + if ($data['id'][0] == '/') |
|
| 447 | + { |
|
| 448 | + array_shift($parts); |
|
| 449 | + } |
|
| 450 | + // remove root |
|
| 396 | 451 | array_pop($parts); |
| 397 | 452 | $path = ''; |
| 398 | 453 | foreach($parts as $part) |
@@ -411,14 +466,23 @@ discard block |
||
| 411 | 466 | 'item' => array(), |
| 412 | 467 | 'child' => 1, |
| 413 | 468 | ); |
| 414 | - if ($path == '/admin') $parent[$path]['open'] = true; |
|
| 469 | + if ($path == '/admin') |
|
| 470 | + { |
|
| 471 | + $parent[$path]['open'] = true; |
|
| 472 | + } |
|
| 415 | 473 | } |
| 416 | 474 | $parent =& $parent[$path]['item']; |
| 417 | 475 | } |
| 418 | 476 | $data['text'] = lang($data['text']); |
| 419 | - if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']); |
|
| 477 | + if (!empty($data['tooltip'])) |
|
| 478 | + { |
|
| 479 | + $data['tooltip'] = lang($data['tooltip']); |
|
| 480 | + } |
|
| 420 | 481 | // make sure keys are unique, as we overwrite tree entries otherwise |
| 421 | - if (isset($parent[$data['id']])) $data['id'] .= md5($data['link']); |
|
| 482 | + if (isset($parent[$data['id']])) |
|
| 483 | + { |
|
| 484 | + $data['id'] .= md5($data['link']); |
|
| 485 | + } |
|
| 422 | 486 | $parent[$data['id']] = self::fix_userdata($data); |
| 423 | 487 | } |
| 424 | 488 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * If no account_id is set in data the account is added and the new id is set in $data. |
| 191 | 191 | * |
| 192 | 192 | * @param array $data array with account-data |
| 193 | - * @return int|boolean the account_id or false on error |
|
| 193 | + * @return false|string the account_id or false on error |
|
| 194 | 194 | */ |
| 195 | 195 | function save(&$data) |
| 196 | 196 | { |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | * |
| 996 | 996 | * @param int $_account_id |
| 997 | 997 | * @param string $ip |
| 998 | - * @return int lastlogin time |
|
| 998 | + * @return boolean lastlogin time |
|
| 999 | 999 | */ |
| 1000 | 1000 | function update_lastlogin($_account_id, $ip) |
| 1001 | 1001 | { |
@@ -1097,7 +1097,6 @@ discard block |
||
| 1097 | 1097 | * @param int $gid gidnumber of group to set |
| 1098 | 1098 | * @param array $objectclass =null should we set the member and uniqueMember attributes (groupOf(Unique)Names|univentionGroup) (default detect it) |
| 1099 | 1099 | * @param string $use_cn =null if set $cn is used instead $gid and the attributes are returned, not written to ldap |
| 1100 | - * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it) |
|
| 1101 | 1100 | * @return boolean/array false on failure, array or true otherwise |
| 1102 | 1101 | */ |
| 1103 | 1102 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
@@ -962,7 +962,7 @@ |
||
| 962 | 962 | 'account_fullname' => 'cn', |
| 963 | 963 | ); |
| 964 | 964 | if (!isset($to_ldap[$which]) || $account_type === 'g') { |
| 965 | - return False; |
|
| 965 | + return False; |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | $test = @$allVals['uid'][0]; |
| 776 | 776 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
| 777 | 777 | { |
| 778 | - $account = Array( |
|
| 778 | + $account = array( |
|
| 779 | 779 | 'account_id' => $allVals['uidnumber'][0], |
| 780 | 780 | 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'), |
| 781 | 781 | 'account_type' => 'u', |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | $test = $allVals['cn'][0]; |
| 836 | 836 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
| 837 | 837 | { |
| 838 | - $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
|
| 838 | + $accounts[(string)-$allVals['gidnumber'][0]] = array( |
|
| 839 | 839 | 'account_id' => -$allVals['gidnumber'][0], |
| 840 | 840 | 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
| 841 | 841 | 'account_type' => 'g', |
@@ -175,7 +175,10 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | function read($account_id) |
| 177 | 177 | { |
| 178 | - if (!(int)$account_id) return false; |
|
| 178 | + if (!(int)$account_id) |
|
| 179 | + { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 179 | 182 | |
| 180 | 183 | if ($account_id < 0) |
| 181 | 184 | { |
@@ -238,17 +241,23 @@ discard block |
||
| 238 | 241 | $this->delete($data['account_id']); |
| 239 | 242 | unset($old['dn']); |
| 240 | 243 | // removing the namedObject object-class, if it's included |
| 241 | - if ($key !== false) unset($old['objectclass'][$key]); |
|
| 244 | + if ($key !== false) |
|
| 245 | + { |
|
| 246 | + unset($old['objectclass'][$key]); |
|
| 247 | + } |
|
| 242 | 248 | $to_write = $old; |
| 243 | 249 | unset($old); |
| 244 | 250 | } |
| 245 | 251 | } |
| 246 | 252 | } |
| 247 | - if (!$data['account_id']) // new account |
|
| 253 | + if (!$data['account_id']) |
|
| 254 | + { |
|
| 255 | + // new account |
|
| 248 | 256 | { |
| 249 | 257 | if (!($data['account_id'] = $data_utf8['account_id'] = $this->_get_nextid($is_group ? 'g' : 'u'))) |
| 250 | 258 | { |
| 251 | 259 | return false; |
| 260 | + } |
|
| 252 | 261 | } |
| 253 | 262 | } |
| 254 | 263 | // check if we need to write the objectclass: new entry or required object classes are missing |
@@ -259,11 +268,14 @@ discard block |
||
| 259 | 268 | { |
| 260 | 269 | $to_write['objectclass'] = $old ? $old['objectclass'] : array(); |
| 261 | 270 | } |
| 262 | - if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
|
| 271 | + if (!$old) |
|
| 272 | + { |
|
| 273 | + // for new accounts add additional addressbook object classes, if supported by server |
|
| 263 | 274 | { // as setting them later might loose eg. password, if we are not allowed to read them |
| 264 | 275 | foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
| 265 | 276 | { |
| 266 | 277 | $add = array(); |
| 278 | + } |
|
| 267 | 279 | if (is_array($additional)) |
| 268 | 280 | { |
| 269 | 281 | $add = $additional; |
@@ -272,7 +284,10 @@ discard block |
||
| 272 | 284 | if ($this->ldapServerInfo->supportsObjectClass($additional)) |
| 273 | 285 | { |
| 274 | 286 | $to_write['objectclass'][] = $additional; |
| 275 | - if ($add) $to_write += $add; |
|
| 287 | + if ($add) |
|
| 288 | + { |
|
| 289 | + $to_write += $add; |
|
| 290 | + } |
|
| 276 | 291 | } |
| 277 | 292 | } |
| 278 | 293 | } |
@@ -281,7 +296,10 @@ discard block |
||
| 281 | 296 | } |
| 282 | 297 | if (!($dn = $old['dn'])) |
| 283 | 298 | { |
| 284 | - if (!$data['account_lid']) return false; |
|
| 299 | + if (!$data['account_lid']) |
|
| 300 | + { |
|
| 301 | + return false; |
|
| 302 | + } |
|
| 285 | 303 | |
| 286 | 304 | $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
| 287 | 305 | 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
@@ -302,24 +320,36 @@ discard block |
||
| 302 | 320 | { |
| 303 | 321 | $extra_attr = false; |
| 304 | 322 | $keep_objectclass = false; |
| 305 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
| 323 | + if (is_array($forward)) |
|
| 324 | + { |
|
| 325 | + list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
| 326 | + } |
|
| 306 | 327 | |
| 307 | 328 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
| 308 | 329 | ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
| 309 | 330 | { |
| 310 | - if ($data_utf8['account_email']) // setting an email |
|
| 331 | + if ($data_utf8['account_email']) |
|
| 332 | + { |
|
| 333 | + // setting an email |
|
| 311 | 334 | { |
| 312 | 335 | if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
| 313 | 336 | { |
| 314 | 337 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
| 338 | + } |
|
| 315 | 339 | $to_write['objectclass'][] = $objectclass; |
| 316 | 340 | } |
| 317 | - if ($extra_attr) $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
| 341 | + if ($extra_attr) |
|
| 342 | + { |
|
| 343 | + $to_write[$extra_attr] = $data_utf8['account_lid']; |
|
| 344 | + } |
|
| 318 | 345 | $to_write[static::MAIL_ATTR] = $data_utf8['account_email']; |
| 319 | 346 | |
| 320 | 347 | if ($forward) |
| 321 | 348 | { |
| 322 | - if (!$members) $members = $this->members($data['account_id']); |
|
| 349 | + if (!$members) |
|
| 350 | + { |
|
| 351 | + $members = $this->members($data['account_id']); |
|
| 352 | + } |
|
| 323 | 353 | $to_write[$forward] = array(); |
| 324 | 354 | foreach (array_keys($members) as $member) |
| 325 | 355 | { |
@@ -330,11 +360,20 @@ discard block |
||
| 330 | 360 | } |
| 331 | 361 | } |
| 332 | 362 | } |
| 333 | - elseif($old) // remove the mail and forwards only for existing entries |
|
| 363 | + elseif($old) |
|
| 364 | + { |
|
| 365 | + // remove the mail and forwards only for existing entries |
|
| 334 | 366 | { |
| 335 | 367 | $to_write[static::MAIL_ATTR] = array(); |
| 336 | - if ($forward) $to_write[$forward] = array(); |
|
| 337 | - if ($extra_attr) $to_write[$extra_attr] = array(); |
|
| 368 | + } |
|
| 369 | + if ($forward) |
|
| 370 | + { |
|
| 371 | + $to_write[$forward] = array(); |
|
| 372 | + } |
|
| 373 | + if ($extra_attr) |
|
| 374 | + { |
|
| 375 | + $to_write[$extra_attr] = array(); |
|
| 376 | + } |
|
| 338 | 377 | if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
| 339 | 378 | { |
| 340 | 379 | $to_write['objectclass'] = $old['objectclass']; |
@@ -368,7 +407,8 @@ discard block |
||
| 368 | 407 | } |
| 369 | 408 | |
| 370 | 409 | // remove memberuid when adding a group |
| 371 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
| 410 | + if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) |
|
| 411 | + { |
|
| 372 | 412 | unset($to_write['memberuid']); |
| 373 | 413 | } |
| 374 | 414 | // modifying or adding the entry |
@@ -405,7 +445,10 @@ discard block |
||
| 405 | 445 | */ |
| 406 | 446 | function delete($account_id) |
| 407 | 447 | { |
| 408 | - if (!(int)$account_id) return false; |
|
| 448 | + if (!(int)$account_id) |
|
| 449 | + { |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 409 | 452 | |
| 410 | 453 | if ($account_id < 0) |
| 411 | 454 | { |
@@ -418,10 +461,16 @@ discard block |
||
| 418 | 461 | |
| 419 | 462 | $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
| 420 | 463 | } |
| 421 | - if (!$sri) return false; |
|
| 464 | + if (!$sri) |
|
| 465 | + { |
|
| 466 | + return false; |
|
| 467 | + } |
|
| 422 | 468 | |
| 423 | 469 | $allValues = ldap_get_entries($this->ds, $sri); |
| 424 | - if (!$allValues['count']) return false; |
|
| 470 | + if (!$allValues['count']) |
|
| 471 | + { |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 425 | 474 | |
| 426 | 475 | return ldap_delete($this->ds, $allValues[0]['dn']); |
| 427 | 476 | } |
@@ -593,14 +642,20 @@ discard block |
||
| 593 | 642 | $utc_diff = date('Z'); |
| 594 | 643 | if (isset($data['account_passwd']) && $data['account_passwd']) |
| 595 | 644 | { |
| 596 | - if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) // md5 --> ldap md5 |
|
| 645 | + if (preg_match('/^[a-f0-9]{32}$/', $data['account_passwd'])) |
|
| 646 | + { |
|
| 647 | + // md5 --> ldap md5 |
|
| 597 | 648 | { |
| 598 | 649 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
| 599 | 650 | } |
| 600 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
| 651 | + } |
|
| 652 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) |
|
| 653 | + { |
|
| 654 | + // if it's not already entcrypted, do so now |
|
| 601 | 655 | { |
| 602 | 656 | $data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']); |
| 603 | 657 | } |
| 658 | + } |
|
| 604 | 659 | $to_write['userpassword'] = $data['account_passwd']; |
| 605 | 660 | $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
| 606 | 661 | } |
@@ -620,16 +675,28 @@ discard block |
||
| 620 | 675 | unset($to_write['shadowexpire']); // gives protocoll error otherwise |
| 621 | 676 | } |
| 622 | 677 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
| 623 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
| 624 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
| 678 | + if ($data['account_lastpwd_change']) |
|
| 679 | + { |
|
| 680 | + $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
| 681 | + } |
|
| 682 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) |
|
| 683 | + { |
|
| 684 | + $to_write['shadowlastchange'] = 0; |
|
| 685 | + } |
|
| 625 | 686 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
| 626 | 687 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
| 627 | 688 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
| 628 | 689 | |
| 629 | 690 | if ($this->frontend->config['ldap_extra_attributes']) |
| 630 | 691 | { |
| 631 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
| 632 | - if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
| 692 | + if (isset($data['homedirectory'])) |
|
| 693 | + { |
|
| 694 | + $to_write['homedirectory'] = $data['homedirectory']; |
|
| 695 | + } |
|
| 696 | + if (isset($data['loginshell'])) |
|
| 697 | + { |
|
| 698 | + $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
|
| 699 | + } |
|
| 633 | 700 | } |
| 634 | 701 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
| 635 | 702 | { |
@@ -676,8 +743,14 @@ discard block |
||
| 676 | 743 | } |
| 677 | 744 | // if it's a limited query, check if the unlimited query is cached |
| 678 | 745 | $start = $param['start']; |
| 679 | - if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15; |
|
| 680 | - if (!($offset = $param['offset'])) $offset = $maxmatchs; |
|
| 746 | + if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) |
|
| 747 | + { |
|
| 748 | + $maxmatchs = 15; |
|
| 749 | + } |
|
| 750 | + if (!($offset = $param['offset'])) |
|
| 751 | + { |
|
| 752 | + $offset = $maxmatchs; |
|
| 753 | + } |
|
| 681 | 754 | unset($param['start']); |
| 682 | 755 | unset($param['offset']); |
| 683 | 756 | $unl_serial = serialize($param); |
@@ -748,12 +821,18 @@ discard block |
||
| 748 | 821 | $fullSet = array(); |
| 749 | 822 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
| 750 | 823 | { |
| 751 | - if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
| 824 | + if ($key !== 'count') |
|
| 825 | + { |
|
| 826 | + $fullSet[$entry['uid'][0]] = $entry[$order][0]; |
|
| 827 | + } |
|
| 752 | 828 | } |
| 753 | 829 | |
| 754 | - if (is_numeric($param['type'])) // return only group-members |
|
| 830 | + if (is_numeric($param['type'])) |
|
| 831 | + { |
|
| 832 | + // return only group-members |
|
| 755 | 833 | { |
| 756 | 834 | $relevantAccounts = array(); |
| 835 | + } |
|
| 757 | 836 | $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
| 758 | 837 | $group = ldap_get_entries($this->ds, $sri); |
| 759 | 838 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
@@ -791,7 +870,10 @@ discard block |
||
| 791 | 870 | //error_log(__METHOD__."() ldap=".array2string($allVals)." --> account=".array2string($account)); |
| 792 | 871 | if ($param['active'] && !$this->frontend->is_active($account)) |
| 793 | 872 | { |
| 794 | - if (isset($totalcount)) --$totalcount; |
|
| 873 | + if (isset($totalcount)) |
|
| 874 | + { |
|
| 875 | + --$totalcount; |
|
| 876 | + } |
|
| 795 | 877 | continue; |
| 796 | 878 | } |
| 797 | 879 | $account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], |
@@ -844,7 +926,10 @@ discard block |
||
| 844 | 926 | 'account_status' => 'A', |
| 845 | 927 | 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
| 846 | 928 | ); |
| 847 | - if (isset($totalcount)) ++$totalcount; |
|
| 929 | + if (isset($totalcount)) |
|
| 930 | + { |
|
| 931 | + ++$totalcount; |
|
| 932 | + } |
|
| 848 | 933 | } |
| 849 | 934 | } |
| 850 | 935 | } |
@@ -945,10 +1030,13 @@ discard block |
||
| 945 | 1030 | { |
| 946 | 1031 | $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8')); |
| 947 | 1032 | |
| 948 | - if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
|
| 1033 | + if ($which == 'account_lid' && $account_type !== 'u') |
|
| 1034 | + { |
|
| 1035 | + // groups only support account_lid |
|
| 949 | 1036 | { |
| 950 | 1037 | |
| 951 | 1038 | $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
| 1039 | + } |
|
| 952 | 1040 | $allValues = ldap_get_entries($this->ds, $sri); |
| 953 | 1041 | |
| 954 | 1042 | if (@$allValues[0]['gidnumber'][0]) |
@@ -961,7 +1049,8 @@ discard block |
||
| 961 | 1049 | 'account_email' => static::MAIL_ATTR, |
| 962 | 1050 | 'account_fullname' => 'cn', |
| 963 | 1051 | ); |
| 964 | - if (!isset($to_ldap[$which]) || $account_type === 'g') { |
|
| 1052 | + if (!isset($to_ldap[$which]) || $account_type === 'g') |
|
| 1053 | + { |
|
| 965 | 1054 | return False; |
| 966 | 1055 | } |
| 967 | 1056 | |
@@ -1011,13 +1100,19 @@ discard block |
||
| 1011 | 1100 | */ |
| 1012 | 1101 | function memberships($account_id) |
| 1013 | 1102 | { |
| 1014 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
| 1103 | + if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) |
|
| 1104 | + { |
|
| 1105 | + return false; |
|
| 1106 | + } |
|
| 1015 | 1107 | |
| 1016 | 1108 | $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber')); |
| 1017 | 1109 | $memberships = array(); |
| 1018 | 1110 | foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
| 1019 | 1111 | { |
| 1020 | - if ($key === 'count') continue; |
|
| 1112 | + if ($key === 'count') |
|
| 1113 | + { |
|
| 1114 | + continue; |
|
| 1115 | + } |
|
| 1021 | 1116 | |
| 1022 | 1117 | $memberships[(string) -$data['gidnumber'][0]] = $data['cn'][0]; |
| 1023 | 1118 | } |
@@ -1037,7 +1132,10 @@ discard block |
||
| 1037 | 1132 | { |
| 1038 | 1133 | // try to recover |
| 1039 | 1134 | $_gid = $this->name2id($_gid,'account_lid','g'); |
| 1040 | - if (!is_numeric($_gid)) return false; |
|
| 1135 | + if (!is_numeric($_gid)) |
|
| 1136 | + { |
|
| 1137 | + return false; |
|
| 1138 | + } |
|
| 1041 | 1139 | } |
| 1042 | 1140 | |
| 1043 | 1141 | $gid = abs($_gid); // our gid is negative! |
@@ -1085,7 +1183,10 @@ discard block |
||
| 1085 | 1183 | // adding new memberships |
| 1086 | 1184 | foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
| 1087 | 1185 | { |
| 1088 | - if (!($members = $this->members($gid))) $members = array(); |
|
| 1186 | + if (!($members = $this->members($gid))) |
|
| 1187 | + { |
|
| 1188 | + $members = array(); |
|
| 1189 | + } |
|
| 1089 | 1190 | $members[$account_id] = $this->id2name($account_id); |
| 1090 | 1191 | $this->set_members($members,$gid); |
| 1091 | 1192 | } |
@@ -1103,16 +1204,25 @@ discard block |
||
| 1103 | 1204 | */ |
| 1104 | 1205 | function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
| 1105 | 1206 | { |
| 1106 | - if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
|
| 1207 | + if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) |
|
| 1208 | + { |
|
| 1209 | + return false; |
|
| 1210 | + } |
|
| 1107 | 1211 | |
| 1108 | 1212 | // do that group is a groupOf(Unique)Names or univentionGroup? |
| 1109 | - if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass'); |
|
| 1213 | + if (is_null($objectclass)) |
|
| 1214 | + { |
|
| 1215 | + $objectclass = $this->id2name($gid,'objectclass'); |
|
| 1216 | + } |
|
| 1110 | 1217 | |
| 1111 | 1218 | $to_write = array('memberuid' => array()); |
| 1112 | 1219 | foreach((array)$members as $key => $member) |
| 1113 | 1220 | { |
| 1114 | 1221 | $member_dn = $this->id2name($member, 'account_dn'); |
| 1115 | - if (is_numeric($member)) $member = $this->id2name($member); |
|
| 1222 | + if (is_numeric($member)) |
|
| 1223 | + { |
|
| 1224 | + $member = $this->id2name($member); |
|
| 1225 | + } |
|
| 1116 | 1226 | |
| 1117 | 1227 | if ($member) |
| 1118 | 1228 | { |
@@ -1136,21 +1246,33 @@ discard block |
||
| 1136 | 1246 | { |
| 1137 | 1247 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
| 1138 | 1248 | } |
| 1139 | - if ($use_cn) return $to_write; |
|
| 1249 | + if ($use_cn) |
|
| 1250 | + { |
|
| 1251 | + return $to_write; |
|
| 1252 | + } |
|
| 1140 | 1253 | |
| 1141 | 1254 | // set the member email addresses as forwards |
| 1142 | 1255 | if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
| 1143 | 1256 | { |
| 1144 | 1257 | $forward = $this->group_mail_classes[$objectclass]; |
| 1145 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
| 1146 | - if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
|
| 1258 | + if (is_array($forward)) |
|
| 1259 | + { |
|
| 1260 | + list($forward,$extra_attr) = $forward; |
|
| 1261 | + } |
|
| 1262 | + if ($extra_attr && ($uid = $this->id2name($gid))) |
|
| 1263 | + { |
|
| 1264 | + $to_write[$extra_attr] = $uid; |
|
| 1265 | + } |
|
| 1147 | 1266 | |
| 1148 | 1267 | if ($forward) |
| 1149 | 1268 | { |
| 1150 | 1269 | $to_write[$forward] = array(); |
| 1151 | 1270 | foreach($members as $key => $member) |
| 1152 | 1271 | { |
| 1153 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
| 1272 | + if (($email = $this->id2name($member,'account_email'))) |
|
| 1273 | + { |
|
| 1274 | + $to_write[$forward][] = $email; |
|
| 1275 | + } |
|
| 1154 | 1276 | } |
| 1155 | 1277 | } |
| 1156 | 1278 | } |
@@ -1176,7 +1298,10 @@ discard block |
||
| 1176 | 1298 | |
| 1177 | 1299 | // prefer ids above 1000 (below reserved for system users under AD or Linux), |
| 1178 | 1300 | // if that's possible within what is configured, or nothing is configured |
| 1179 | - if ($min < 1000 && (!$max || $max > 1000)) $min = 1000; |
|
| 1301 | + if ($min < 1000 && (!$max || $max > 1000)) |
|
| 1302 | + { |
|
| 1303 | + $min = 1000; |
|
| 1304 | + } |
|
| 1180 | 1305 | |
| 1181 | 1306 | if ($account_type == 'g') |
| 1182 | 1307 | { |
@@ -1229,7 +1354,10 @@ discard block |
||
| 1229 | 1354 | } |
| 1230 | 1355 | ++$id; |
| 1231 | 1356 | |
| 1232 | - if($id < $min) $id = $min; |
|
| 1357 | + if($id < $min) |
|
| 1358 | + { |
|
| 1359 | + $id = $min; |
|
| 1360 | + } |
|
| 1233 | 1361 | |
| 1234 | 1362 | Api\Config::save_value($key, $id, 'phpgwapi', true); |
| 1235 | 1363 | $GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id; |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | var $requiredObjectClasses = array( |
| 91 | 91 | 'user' => array( |
| 92 | - 'top','person','organizationalperson','inetorgperson','posixaccount','shadowaccount' |
|
| 92 | + 'top', 'person', 'organizationalperson', 'inetorgperson', 'posixaccount', 'shadowaccount' |
|
| 93 | 93 | ), |
| 94 | 94 | 'user-if-supported' => array( // these classes get added, if server supports them |
| 95 | 95 | 'mozillaabpersonalpha', 'mozillaorgperson', 'evolutionperson', |
| 96 | 96 | 'univentionperson', 'univentionmail', array('univentionobject', 'univentionObjectType' => 'users/user'), |
| 97 | 97 | ), |
| 98 | 98 | 'group' => array( |
| 99 | - 'top','posixgroup','groupofnames' |
|
| 99 | + 'top', 'posixgroup', 'groupofnames' |
|
| 100 | 100 | ), |
| 101 | 101 | 'group-if-supported' => array( // these classes get added, if servers supports them |
| 102 | 102 | 'univentiongroup', array('univentionobject', 'univentionObjectType' => 'groups/group'), |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | var $group_mail_classes = array( |
| 117 | 117 | 'dbmailforwardingaddress' => 'mailforwardingaddress', |
| 118 | - 'dbmailuser' => array('mailforwardingaddress','uid'), |
|
| 119 | - 'qmailuser' => array('mailforwardingaddress','uid'), |
|
| 118 | + 'dbmailuser' => array('mailforwardingaddress', 'uid'), |
|
| 119 | + 'qmailuser' => array('mailforwardingaddress', 'uid'), |
|
| 120 | 120 | 'mailaccount' => 'mailalias', |
| 121 | 121 | 'univentiongroup' => array(false, false, true), |
| 122 | 122 | ); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $this->use_session_cache = true; |
| 159 | 159 | |
| 160 | 160 | $this->ldap = Api\Ldap::factory(false, $this->frontend->config['ldap_host'], |
| 161 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
| 161 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
| 162 | 162 | $this->ds = $this->ldap->ds; |
| 163 | 163 | |
| 164 | 164 | $this->user_context = $this->frontend->config['ldap_context']; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | { |
| 197 | 197 | $is_group = $data['account_id'] < 0 || $data['account_type'] === 'g'; |
| 198 | 198 | |
| 199 | - $data_utf8 = Api\Translation::convert($data,Api\Translation::charset(),'utf-8'); |
|
| 199 | + $data_utf8 = Api\Translation::convert($data, Api\Translation::charset(), 'utf-8'); |
|
| 200 | 200 | $members = $data['account_members']; |
| 201 | 201 | |
| 202 | 202 | if (!is_object($this->ldapServerInfo)) |
@@ -208,8 +208,7 @@ discard block |
||
| 208 | 208 | if ($data_utf8['account_id'] && $data_utf8['account_lid']) |
| 209 | 209 | { |
| 210 | 210 | // read the entry first, to check if the dn (account_lid) has changed |
| 211 | - $sri = $is_group ? ldap_search($this->ds,$this->group_context,'gidnumber='.abs($data['account_id'])) : |
|
| 212 | - ldap_search($this->ds,$this->user_context,'uidnumber='.$data['account_id']); |
|
| 211 | + $sri = $is_group ? ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($data['account_id'])) : ldap_search($this->ds, $this->user_context, 'uidnumber='.$data['account_id']); |
|
| 213 | 212 | $old = ldap_get_entries($this->ds, $sri); |
| 214 | 213 | |
| 215 | 214 | if (!$old['count']) |
@@ -221,9 +220,9 @@ discard block |
||
| 221 | 220 | $old = Api\Ldap::result2array($old[0]); |
| 222 | 221 | $old['objectclass'] = array_map('strtolower', $old['objectclass']); |
| 223 | 222 | $key = false; |
| 224 | - if ($is_group && ($key = array_search('namedobject',$old['objectclass'])) !== false || |
|
| 225 | - $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'],0,3) != 'cn=') || |
|
| 226 | - !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'],0,4) != 'uid=')) |
|
| 223 | + if ($is_group && ($key = array_search('namedobject', $old['objectclass'])) !== false || |
|
| 224 | + $is_group && ($old['cn'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 3) != 'cn=') || |
|
| 225 | + !$is_group && ($old['uid'] != $data_utf8['account_lid'] || substr($old['dn'], 0, 4) != 'uid=')) |
|
| 227 | 226 | { |
| 228 | 227 | // query the memberships to set them again later |
| 229 | 228 | if (!$is_group) |
@@ -252,7 +251,7 @@ discard block |
||
| 252 | 251 | } |
| 253 | 252 | } |
| 254 | 253 | // check if we need to write the objectclass: new entry or required object classes are missing |
| 255 | - if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'],$old['objectclass'])) |
|
| 254 | + if (!$old || array_diff($this->requiredObjectClasses[$is_group ? 'group' : 'user'], $old['objectclass'])) |
|
| 256 | 255 | { |
| 257 | 256 | // additional objectclasse might be already set in $to_write or $old |
| 258 | 257 | if (!is_array($to_write['objectclass'])) |
@@ -261,7 +260,7 @@ discard block |
||
| 261 | 260 | } |
| 262 | 261 | if (!$old) // for new accounts add additional addressbook object classes, if supported by server |
| 263 | 262 | { // as setting them later might loose eg. password, if we are not allowed to read them |
| 264 | - foreach($this->requiredObjectClasses[$is_group?'group-if-supported':'user-if-supported'] as $additional) |
|
| 263 | + foreach ($this->requiredObjectClasses[$is_group ? 'group-if-supported' : 'user-if-supported'] as $additional) |
|
| 265 | 264 | { |
| 266 | 265 | $add = array(); |
| 267 | 266 | if (is_array($additional)) |
@@ -283,8 +282,7 @@ discard block |
||
| 283 | 282 | { |
| 284 | 283 | if (!$data['account_lid']) return false; |
| 285 | 284 | |
| 286 | - $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : |
|
| 287 | - 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
| 285 | + $dn = $is_group ? 'cn='.$data_utf8['account_lid'].','.$this->group_context : 'uid='.$data_utf8['account_lid'].','.$this->user_context; |
|
| 288 | 286 | } |
| 289 | 287 | // now we merge the user or group data |
| 290 | 288 | if ($is_group) |
@@ -293,23 +291,23 @@ discard block |
||
| 293 | 291 | $data['account_type'] = 'g'; |
| 294 | 292 | |
| 295 | 293 | $objectclass = $old ? $old['objectclass'] : $to_write['objectclass']; |
| 296 | - if ($members || !$old && array_intersect(array('groupofnames','groupofuniquenames','univentiongroup'), $objectclass)) |
|
| 294 | + if ($members || !$old && array_intersect(array('groupofnames', 'groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
| 297 | 295 | { |
| 298 | 296 | $to_write = array_merge($to_write, $this->set_members($members, $data['account_id'], $objectclass, $dn)); |
| 299 | 297 | } |
| 300 | 298 | // check if we should set a mail address and forwards for each member |
| 301 | - foreach($this->group_mail_classes as $objectclass => $forward) |
|
| 299 | + foreach ($this->group_mail_classes as $objectclass => $forward) |
|
| 302 | 300 | { |
| 303 | 301 | $extra_attr = false; |
| 304 | 302 | $keep_objectclass = false; |
| 305 | - if (is_array($forward)) list($forward,$extra_attr,$keep_objectclass) = $forward; |
|
| 303 | + if (is_array($forward)) list($forward, $extra_attr, $keep_objectclass) = $forward; |
|
| 306 | 304 | |
| 307 | 305 | if ($this->ldapServerInfo->supportsObjectClass($objectclass) && |
| 308 | - ($old && in_array($objectclass,$old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
| 306 | + ($old && in_array($objectclass, $old['objectclass']) || $data_utf8['account_email'] || $old[static::MAIL_ATTR])) |
|
| 309 | 307 | { |
| 310 | 308 | if ($data_utf8['account_email']) // setting an email |
| 311 | 309 | { |
| 312 | - if (!in_array($objectclass,$old ? $old['objectclass'] : $to_write['objectclass'])) |
|
| 310 | + if (!in_array($objectclass, $old ? $old['objectclass'] : $to_write['objectclass'])) |
|
| 313 | 311 | { |
| 314 | 312 | if ($old) $to_write['objectclass'] = $old['objectclass']; |
| 315 | 313 | $to_write['objectclass'][] = $objectclass; |
@@ -323,19 +321,19 @@ discard block |
||
| 323 | 321 | $to_write[$forward] = array(); |
| 324 | 322 | foreach (array_keys($members) as $member) |
| 325 | 323 | { |
| 326 | - if (($email = $this->id2name($member,'account_email'))) |
|
| 324 | + if (($email = $this->id2name($member, 'account_email'))) |
|
| 327 | 325 | { |
| 328 | 326 | $to_write[$forward][] = $email; |
| 329 | 327 | } |
| 330 | 328 | } |
| 331 | 329 | } |
| 332 | 330 | } |
| 333 | - elseif($old) // remove the mail and forwards only for existing entries |
|
| 331 | + elseif ($old) // remove the mail and forwards only for existing entries |
|
| 334 | 332 | { |
| 335 | 333 | $to_write[static::MAIL_ATTR] = array(); |
| 336 | 334 | if ($forward) $to_write[$forward] = array(); |
| 337 | 335 | if ($extra_attr) $to_write[$extra_attr] = array(); |
| 338 | - if (!$keep_objectclass && ($key = array_search($objectclass,$old['objectclass']))) |
|
| 336 | + if (!$keep_objectclass && ($key = array_search($objectclass, $old['objectclass']))) |
|
| 339 | 337 | { |
| 340 | 338 | $to_write['objectclass'] = $old['objectclass']; |
| 341 | 339 | unset($to_write['objectclass'][$key]); |
@@ -349,7 +347,7 @@ discard block |
||
| 349 | 347 | } |
| 350 | 348 | else |
| 351 | 349 | { |
| 352 | - $to_write = $this->_merge_user($to_write,$data_utf8,!$old); |
|
| 350 | + $to_write = $this->_merge_user($to_write, $data_utf8, !$old); |
|
| 353 | 351 | // make sure multiple email-addresses in the mail attribute "survive" |
| 354 | 352 | if (isset($to_write[static::MAIL_ATTR]) && count($old[static::MAIL_ATTR]) > 1) |
| 355 | 353 | { |
@@ -368,21 +366,21 @@ discard block |
||
| 368 | 366 | } |
| 369 | 367 | |
| 370 | 368 | // remove memberuid when adding a group |
| 371 | - if(!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
| 369 | + if (!$old && is_array($to_write['memberuid']) && empty($to_write['memberuid'])) { |
|
| 372 | 370 | unset($to_write['memberuid']); |
| 373 | 371 | } |
| 374 | 372 | // modifying or adding the entry |
| 375 | - if ($old && !@ldap_modify($this->ds,$dn,$to_write) || |
|
| 376 | - !$old && !@ldap_add($this->ds,$dn,$to_write)) |
|
| 373 | + if ($old && !@ldap_modify($this->ds, $dn, $to_write) || |
|
| 374 | + !$old && !@ldap_add($this->ds, $dn, $to_write)) |
|
| 377 | 375 | { |
| 378 | 376 | $err = true; |
| 379 | - if ($is_group && ($key = array_search('groupofnames',$to_write['objectclass'])) !== false) |
|
| 377 | + if ($is_group && ($key = array_search('groupofnames', $to_write['objectclass'])) !== false) |
|
| 380 | 378 | { |
| 381 | 379 | // try again with removed groupOfNames stuff, as I cant detect if posixGroup is a structural object |
| 382 | 380 | unset($to_write['objectclass'][$key]); |
| 383 | 381 | $to_write['objectclass'] = array_values($to_write['objectclass']); |
| 384 | 382 | unset($to_write['member']); |
| 385 | - $err = $old ? !ldap_modify($this->ds,$dn,$to_write) : !ldap_add($this->ds,$dn,$to_write); |
|
| 383 | + $err = $old ? !ldap_modify($this->ds, $dn, $to_write) : !ldap_add($this->ds, $dn, $to_write); |
|
| 386 | 384 | } |
| 387 | 385 | if ($err) |
| 388 | 386 | { |
@@ -392,7 +390,7 @@ discard block |
||
| 392 | 390 | } |
| 393 | 391 | if ($memberships) |
| 394 | 392 | { |
| 395 | - $this->set_memberships($memberships,$data['account_id']); |
|
| 393 | + $this->set_memberships($memberships, $data['account_id']); |
|
| 396 | 394 | } |
| 397 | 395 | return $data['account_id']; |
| 398 | 396 | } |
@@ -409,14 +407,14 @@ discard block |
||
| 409 | 407 | |
| 410 | 408 | if ($account_id < 0) |
| 411 | 409 | { |
| 412 | - $sri = ldap_search($this->ds, $this->group_context, 'gidnumber=' . abs($account_id)); |
|
| 410 | + $sri = ldap_search($this->ds, $this->group_context, 'gidnumber='.abs($account_id)); |
|
| 413 | 411 | } |
| 414 | 412 | else |
| 415 | 413 | { |
| 416 | 414 | // remove the user's memberships |
| 417 | - $this->set_memberships(array(),$account_id); |
|
| 415 | + $this->set_memberships(array(), $account_id); |
|
| 418 | 416 | |
| 419 | - $sri = ldap_search($this->ds, $this->user_context, 'uidnumber=' . $account_id); |
|
| 417 | + $sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$account_id); |
|
| 420 | 418 | } |
| 421 | 419 | if (!$sri) return false; |
| 422 | 420 | |
@@ -440,7 +438,7 @@ discard block |
||
| 440 | 438 | { |
| 441 | 439 | $this->ldapServerInfo = $this->ldap->getLDAPServerInfo($this->frontend->config['ldap_host']); |
| 442 | 440 | } |
| 443 | - foreach(array_keys($this->group_mail_classes) as $objectclass) |
|
| 441 | + foreach (array_keys($this->group_mail_classes) as $objectclass) |
|
| 444 | 442 | { |
| 445 | 443 | if ($this->ldapServerInfo->supportsObjectClass($objectclass)) |
| 446 | 444 | { |
@@ -448,15 +446,15 @@ discard block |
||
| 448 | 446 | break; |
| 449 | 447 | } |
| 450 | 448 | } |
| 451 | - $sri = ldap_search($this->ds, $this->group_context,'(&(objectClass=posixGroup)(gidnumber=' . abs($account_id).'))', |
|
| 449 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(gidnumber='.abs($account_id).'))', |
|
| 452 | 450 | array('dn', 'gidnumber', 'cn', 'objectclass', static::MAIL_ATTR, 'memberuid', 'description')); |
| 453 | 451 | |
| 454 | 452 | $ldap_data = ldap_get_entries($this->ds, $sri); |
| 455 | 453 | if (!$ldap_data['count']) |
| 456 | 454 | { |
| 457 | - return false; // group not found |
|
| 455 | + return false; // group not found |
|
| 458 | 456 | } |
| 459 | - $data = Api\Translation::convert($ldap_data[0],'utf-8'); |
|
| 457 | + $data = Api\Translation::convert($ldap_data[0], 'utf-8'); |
|
| 460 | 458 | unset($data['objectclass']['count']); |
| 461 | 459 | |
| 462 | 460 | $group += array( |
@@ -477,7 +475,7 @@ discard block |
||
| 477 | 475 | { |
| 478 | 476 | unset($data['memberuid']['count']); |
| 479 | 477 | |
| 480 | - foreach($data['memberuid'] as $lid) |
|
| 478 | + foreach ($data['memberuid'] as $lid) |
|
| 481 | 479 | { |
| 482 | 480 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
| 483 | 481 | { |
@@ -498,16 +496,16 @@ discard block |
||
| 498 | 496 | */ |
| 499 | 497 | protected function _read_user($account_id) |
| 500 | 498 | { |
| 501 | - $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$account_id.'))', |
|
| 502 | - array('dn','uidnumber','uid','gidnumber','givenname','sn','cn',static::MAIL_ATTR,'userpassword','telephonenumber', |
|
| 503 | - 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp')); |
|
| 499 | + $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber='.(int)$account_id.'))', |
|
| 500 | + array('dn', 'uidnumber', 'uid', 'gidnumber', 'givenname', 'sn', 'cn', static::MAIL_ATTR, 'userpassword', 'telephonenumber', |
|
| 501 | + 'shadowexpire', 'shadowlastchange', 'homedirectory', 'loginshell', 'createtimestamp', 'modifytimestamp')); |
|
| 504 | 502 | |
| 505 | 503 | $ldap_data = ldap_get_entries($this->ds, $sri); |
| 506 | 504 | if (!$ldap_data['count']) |
| 507 | 505 | { |
| 508 | - return false; // user not found |
|
| 506 | + return false; // user not found |
|
| 509 | 507 | } |
| 510 | - $data = Api\Translation::convert($ldap_data[0],'utf-8'); |
|
| 508 | + $data = Api\Translation::convert($ldap_data[0], 'utf-8'); |
|
| 511 | 509 | |
| 512 | 510 | $utc_diff = date('Z'); |
| 513 | 511 | $user = array( |
@@ -527,13 +525,13 @@ discard block |
||
| 527 | 525 | // - if it's set to 0, the account is disabled |
| 528 | 526 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
| 529 | 527 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
| 530 | - 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0]*24*3600+$utc_diff < time() ? false : 'A', |
|
| 531 | - 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
| 532 | - 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0]*24*3600+($data['shadowlastchange'][0]!=0?$utc_diff:0) : null, |
|
| 528 | + 'account_status' => isset($data['shadowexpire']) && $data['shadowexpire'][0] * 24 * 3600 + $utc_diff < time() ? false : 'A', |
|
| 529 | + 'account_expires' => isset($data['shadowexpire']) && $data['shadowexpire'][0] ? $data['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
| 530 | + 'account_lastpwd_change' => isset($data['shadowlastchange']) ? $data['shadowlastchange'][0] * 24 * 3600 + ($data['shadowlastchange'][0] != 0 ? $utc_diff : 0) : null, |
|
| 533 | 531 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
| 534 | 532 | // 'account_lastlogin' => $data['phpgwaccountlastlogin'][0], |
| 535 | 533 | // 'account_lastloginfrom' => $data['phpgwaccountlastloginfrom'][0], |
| 536 | - 'person_id' => $data['uid'][0], // id of associated contact |
|
| 534 | + 'person_id' => $data['uid'][0], // id of associated contact |
|
| 537 | 535 | 'account_created' => isset($data['createtimestamp'][0]) ? self::accounts_ldap2ts($data['createtimestamp'][0]) : null, |
| 538 | 536 | 'account_modified' => isset($data['modifytimestamp'][0]) ? self::accounts_ldap2ts($data['modifytimestamp'][0]) : null, |
| 539 | 537 | ); |
@@ -554,7 +552,7 @@ discard block |
||
| 554 | 552 | * @param array $data array with account-data in utf-8 |
| 555 | 553 | * @return array merged data |
| 556 | 554 | */ |
| 557 | - protected function _merge_group($to_write,$data,$old=null) |
|
| 555 | + protected function _merge_group($to_write, $data, $old = null) |
|
| 558 | 556 | { |
| 559 | 557 | $to_write['gidnumber'] = abs($data['account_id']); |
| 560 | 558 | $to_write['cn'] = $data['account_lid']; |
@@ -574,7 +572,7 @@ discard block |
||
| 574 | 572 | * @param boolean $new_entry |
| 575 | 573 | * @return array merged data |
| 576 | 574 | */ |
| 577 | - protected function _merge_user($to_write,$data,$new_entry) |
|
| 575 | + protected function _merge_user($to_write, $data, $new_entry) |
|
| 578 | 576 | { |
| 579 | 577 | $to_write['uidnumber'] = $data['account_id']; |
| 580 | 578 | $to_write['uid'] = $data['account_lid']; |
@@ -583,12 +581,12 @@ discard block |
||
| 583 | 581 | { |
| 584 | 582 | $to_write['givenname'] = $data['account_firstname'] ? $data['account_firstname'] : array(); |
| 585 | 583 | } |
| 586 | - $to_write['sn'] = $data['account_lastname']; |
|
| 584 | + $to_write['sn'] = $data['account_lastname']; |
|
| 587 | 585 | if (!$new_entry || $data['account_email']) |
| 588 | 586 | { |
| 589 | - $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
| 587 | + $to_write[static::MAIL_ATTR] = $data['account_email'] ? $data['account_email'] : array(); |
|
| 590 | 588 | } |
| 591 | - $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
| 589 | + $to_write['cn'] = $data['account_fullname'] ? $data['account_fullname'] : $data['account_firstname'].' '.$data['account_lastname']; |
|
| 592 | 590 | |
| 593 | 591 | $utc_diff = date('Z'); |
| 594 | 592 | if (isset($data['account_passwd']) && $data['account_passwd']) |
@@ -597,47 +595,46 @@ discard block |
||
| 597 | 595 | { |
| 598 | 596 | $data['account_passwd'] = setup_cmd_ldap::hash_sql2ldap($data['account_passwd']); |
| 599 | 597 | } |
| 600 | - elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i',$data['account_passwd'])) // if it's not already entcrypted, do so now |
|
| 598 | + elseif (!preg_match('/^\\{[a-z5]{3,5}\\}.+/i', $data['account_passwd'])) // if it's not already entcrypted, do so now |
|
| 601 | 599 | { |
| 602 | 600 | $data['account_passwd'] = Api\Auth::encrypt_ldap($data['account_passwd']); |
| 603 | 601 | } |
| 604 | 602 | $to_write['userpassword'] = $data['account_passwd']; |
| 605 | - $to_write['shadowlastchange'] = round((time()-$utc_diff) / (24*3600)); |
|
| 603 | + $to_write['shadowlastchange'] = round((time() - $utc_diff) / (24 * 3600)); |
|
| 606 | 604 | } |
| 607 | 605 | // both status and expires are encoded in the single shadowexpire value in LDAP |
| 608 | 606 | // - if it's unset an account is enabled AND does never expire |
| 609 | 607 | // - if it's set to 0, the account is disabled |
| 610 | 608 | // - if it's set to > 0, it will or already has expired --> acount is active if it not yet expired |
| 611 | 609 | // shadowexpire is in days since 1970/01/01 (equivalent to a timestamp (int UTC!) / (24*60*60) |
| 612 | - $shadowexpire = ($data['account_expires']-$utc_diff) / (24*3600); |
|
| 610 | + $shadowexpire = ($data['account_expires'] - $utc_diff) / (24 * 3600); |
|
| 613 | 611 | |
| 614 | 612 | $to_write['shadowexpire'] = !$data['account_status'] ? |
| 615 | - ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : |
|
| 616 | - ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
| 613 | + ($data['account_expires'] != -1 && $data['account_expires'] < time() ? round($shadowexpire) : 0) : ($data['account_expires'] != -1 ? round($shadowexpire) : array()); // array() = unset value |
|
| 617 | 614 | |
| 618 | 615 | if ($new_entry && is_array($to_write['shadowexpire']) && !count($to_write['shadowexpire'])) |
| 619 | 616 | { |
| 620 | - unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
| 617 | + unset($to_write['shadowexpire']); // gives protocoll error otherwise |
|
| 621 | 618 | } |
| 622 | 619 | //error_log(__METHOD__.__LINE__.$data['account_lid'].'#'.$data['account_lastpwd_change'].'#'); |
| 623 | - if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change']-$utc_diff)/(24*3600)); |
|
| 624 | - if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change']==0) $to_write['shadowlastchange'] = 0; |
|
| 620 | + if ($data['account_lastpwd_change']) $to_write['shadowlastchange'] = round(($data['account_lastpwd_change'] - $utc_diff) / (24 * 3600)); |
|
| 621 | + if (isset($data['account_lastpwd_change']) && $data['account_lastpwd_change'] == 0) $to_write['shadowlastchange'] = 0; |
|
| 625 | 622 | // lastlogin and lastlogin from are not availible via the shadowAccount object class |
| 626 | 623 | // $to_write['phpgwaccountlastlogin'] = $data['lastlogin']; |
| 627 | 624 | // $to_write['phpgwaccountlastloginfrom'] = $data['lastloginfrom']; |
| 628 | 625 | |
| 629 | 626 | if ($this->frontend->config['ldap_extra_attributes']) |
| 630 | 627 | { |
| 631 | - if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
| 628 | + if (isset($data['homedirectory'])) $to_write['homedirectory'] = $data['homedirectory']; |
|
| 632 | 629 | if (isset($data['loginshell'])) $to_write['loginshell'] = $data['loginshell'] ? $data['loginshell'] : array(); |
| 633 | 630 | } |
| 634 | 631 | if (($new_entry || isset($to_write['homedirectory'])) && empty($to_write['homedirectory'])) |
| 635 | 632 | { |
| 636 | - $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
| 633 | + $to_write['homedirectory'] = '/dev/null'; // is a required attribute of posixAccount |
|
| 637 | 634 | } |
| 638 | 635 | if ($new_entry && empty($to_write['loginshell'])) |
| 639 | 636 | { |
| 640 | - unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
| 637 | + unset($to_write['loginshell']); // setting array() for new entry gives "Protocol error", must not set it |
|
| 641 | 638 | } |
| 642 | 639 | return $to_write; |
| 643 | 640 | } |
@@ -665,7 +662,7 @@ discard block |
||
| 665 | 662 | function search($param) |
| 666 | 663 | { |
| 667 | 664 | //error_log(__METHOD__."(".array2string($param).")"); |
| 668 | - $account_search =& Api\Accounts::$cache['account_search']; |
|
| 665 | + $account_search = & Api\Accounts::$cache['account_search']; |
|
| 669 | 666 | |
| 670 | 667 | // check if the query is cached |
| 671 | 668 | $serial = serialize($param); |
@@ -691,12 +688,12 @@ discard block |
||
| 691 | 688 | $query = Api\Ldap::quote(strtolower($param['query'])); |
| 692 | 689 | |
| 693 | 690 | $accounts = array(); |
| 694 | - if($param['type'] != 'groups') |
|
| 691 | + if ($param['type'] != 'groups') |
|
| 695 | 692 | { |
| 696 | 693 | $filter = "(&(objectclass=posixaccount)"; |
| 697 | 694 | if (!empty($query) && $query != '*') |
| 698 | 695 | { |
| 699 | - switch($param['query_type']) |
|
| 696 | + switch ($param['query_type']) |
|
| 700 | 697 | { |
| 701 | 698 | case 'all': |
| 702 | 699 | default: |
@@ -725,7 +722,7 @@ discard block |
||
| 725 | 722 | } |
| 726 | 723 | } |
| 727 | 724 | // add account_filter to filter (user has to be '*', as we otherwise only search uid's) |
| 728 | - $filter .= str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$this->account_filter); |
|
| 725 | + $filter .= str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $this->account_filter); |
|
| 729 | 726 | $filter .= ')'; |
| 730 | 727 | |
| 731 | 728 | if ($param['type'] != 'both') |
@@ -744,9 +741,9 @@ discard block |
||
| 744 | 741 | 'account_fullname' => 'cn', |
| 745 | 742 | 'account_primary_group' => 'gidnumber', |
| 746 | 743 | ); |
| 747 | - $orders = explode(',',$param['order']); |
|
| 744 | + $orders = explode(',', $param['order']); |
|
| 748 | 745 | $order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid'; |
| 749 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order)); |
|
| 746 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', $order)); |
|
| 750 | 747 | $fullSet = array(); |
| 751 | 748 | foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry) |
| 752 | 749 | { |
@@ -756,7 +753,7 @@ discard block |
||
| 756 | 753 | if (is_numeric($param['type'])) // return only group-members |
| 757 | 754 | { |
| 758 | 755 | $relevantAccounts = array(); |
| 759 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); |
|
| 756 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=".abs($param['type'])."))", array('memberuid')); |
|
| 760 | 757 | $group = ldap_get_entries($this->ds, $sri); |
| 761 | 758 | $fullSet = $group[0]['memberuid'] ? array_intersect_key($fullSet, array_flip($group[0]['memberuid'])) : array(); |
| 762 | 759 | } |
@@ -765,26 +762,26 @@ discard block |
||
| 765 | 762 | $sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort'; |
| 766 | 763 | $sortFn($fullSet); |
| 767 | 764 | $relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet); |
| 768 | - $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')'; |
|
| 769 | - $filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); |
|
| 765 | + $filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=', $relevantAccounts).'))'.$this->account_filter.')'; |
|
| 766 | + $filter = str_replace(array('%user', '%domain'), array('*', $GLOBALS['egw_info']['user']['domain']), $filter); |
|
| 770 | 767 | } |
| 771 | - $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn',static::MAIL_ATTR,'shadowExpire','createtimestamp','modifytimestamp','objectclass','gidNumber')); |
|
| 768 | + $sri = ldap_search($this->ds, $this->user_context, $filter, array('uid', 'uidNumber', 'givenname', 'sn', static::MAIL_ATTR, 'shadowExpire', 'createtimestamp', 'modifytimestamp', 'objectclass', 'gidNumber')); |
|
| 772 | 769 | |
| 773 | 770 | $utc_diff = date('Z'); |
| 774 | - foreach(ldap_get_entries($this->ds, $sri) as $allVals) |
|
| 771 | + foreach (ldap_get_entries($this->ds, $sri) as $allVals) |
|
| 775 | 772 | { |
| 776 | - settype($allVals,'array'); |
|
| 773 | + settype($allVals, 'array'); |
|
| 777 | 774 | $test = @$allVals['uid'][0]; |
| 778 | 775 | if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) |
| 779 | 776 | { |
| 780 | 777 | $account = Array( |
| 781 | 778 | 'account_id' => $allVals['uidnumber'][0], |
| 782 | - 'account_lid' => Api\Translation::convert($allVals['uid'][0],'utf-8'), |
|
| 779 | + 'account_lid' => Api\Translation::convert($allVals['uid'][0], 'utf-8'), |
|
| 783 | 780 | 'account_type' => 'u', |
| 784 | - 'account_firstname' => Api\Translation::convert($allVals['givenname'][0],'utf-8'), |
|
| 785 | - 'account_lastname' => Api\Translation::convert($allVals['sn'][0],'utf-8'), |
|
| 786 | - 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0]*24*3600-$utc_diff < time() ? false : 'A', |
|
| 787 | - 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0]*24*3600+$utc_diff : -1, // LDAP date is in UTC |
|
| 781 | + 'account_firstname' => Api\Translation::convert($allVals['givenname'][0], 'utf-8'), |
|
| 782 | + 'account_lastname' => Api\Translation::convert($allVals['sn'][0], 'utf-8'), |
|
| 783 | + 'account_status' => isset($allVals['shadowexpire'][0]) && $allVals['shadowexpire'][0] * 24 * 3600 - $utc_diff < time() ? false : 'A', |
|
| 784 | + 'account_expires' => isset($allVals['shadowexpire']) && $allVals['shadowexpire'][0] ? $allVals['shadowexpire'][0] * 24 * 3600 + $utc_diff : -1, // LDAP date is in UTC |
|
| 788 | 785 | 'account_email' => $allVals[static::MAIL_ATTR][0], |
| 789 | 786 | 'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null, |
| 790 | 787 | 'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null, |
@@ -810,13 +807,13 @@ discard block |
||
| 810 | 807 | } |
| 811 | 808 | if ($param['type'] == 'groups' || $param['type'] == 'both') |
| 812 | 809 | { |
| 813 | - if(empty($query) || $query == '*') |
|
| 810 | + if (empty($query) || $query == '*') |
|
| 814 | 811 | { |
| 815 | 812 | $filter = '(objectclass=posixgroup)'; |
| 816 | 813 | } |
| 817 | 814 | else |
| 818 | 815 | { |
| 819 | - switch($param['query_type']) |
|
| 816 | + switch ($param['query_type']) |
|
| 820 | 817 | { |
| 821 | 818 | case 'all': |
| 822 | 819 | default: |
@@ -830,21 +827,21 @@ discard block |
||
| 830 | 827 | } |
| 831 | 828 | $filter = "(&(objectclass=posixgroup)(cn=$query))"; |
| 832 | 829 | } |
| 833 | - $sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber')); |
|
| 834 | - foreach((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
| 830 | + $sri = ldap_search($this->ds, $this->group_context, $filter, array('cn', 'gidNumber')); |
|
| 831 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $allVals) |
|
| 835 | 832 | { |
| 836 | - settype($allVals,'array'); |
|
| 833 | + settype($allVals, 'array'); |
|
| 837 | 834 | $test = $allVals['cn'][0]; |
| 838 | 835 | if (!$this->frontend->config['global_denied_groups'][$test] && $allVals['cn'][0]) |
| 839 | 836 | { |
| 840 | 837 | $accounts[(string)-$allVals['gidnumber'][0]] = Array( |
| 841 | 838 | 'account_id' => -$allVals['gidnumber'][0], |
| 842 | - 'account_lid' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
| 839 | + 'account_lid' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
| 843 | 840 | 'account_type' => 'g', |
| 844 | - 'account_firstname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
| 841 | + 'account_firstname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
| 845 | 842 | 'account_lastname' => lang('Group'), |
| 846 | 843 | 'account_status' => 'A', |
| 847 | - 'account_fullname' => Api\Translation::convert($allVals['cn'][0],'utf-8'), |
|
| 844 | + 'account_fullname' => Api\Translation::convert($allVals['cn'][0], 'utf-8'), |
|
| 848 | 845 | ); |
| 849 | 846 | if (isset($totalcount)) ++$totalcount; |
| 850 | 847 | } |
@@ -852,9 +849,9 @@ discard block |
||
| 852 | 849 | } |
| 853 | 850 | // sort the array |
| 854 | 851 | $this->_callback_sort = strtoupper($param['sort']); |
| 855 | - $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']); |
|
| 852 | + $this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']); |
|
| 856 | 853 | $sortedAccounts = $accounts; |
| 857 | - uasort($sortedAccounts,array($this,'_sort_callback')); |
|
| 854 | + uasort($sortedAccounts, array($this, '_sort_callback')); |
|
| 858 | 855 | $this->total = isset($totalcount) ? $totalcount : count($accounts); |
| 859 | 856 | |
| 860 | 857 | // if totalcount is set, $sortedAccounts is NOT the full set, but already a limited set! |
@@ -866,7 +863,7 @@ discard block |
||
| 866 | 863 | } |
| 867 | 864 | // return only the wanted accounts |
| 868 | 865 | reset($sortedAccounts); |
| 869 | - if(is_numeric($start) && is_numeric($offset)) |
|
| 866 | + if (is_numeric($start) && is_numeric($offset)) |
|
| 870 | 867 | { |
| 871 | 868 | $account_search[$serial]['total'] = $this->total; |
| 872 | 869 | return $account_search[$serial]['data'] = isset($totalcount) ? $sortedAccounts : array_slice($sortedAccounts, $start, $offset); |
@@ -894,19 +891,19 @@ discard block |
||
| 894 | 891 | * @param array $b |
| 895 | 892 | * @return int |
| 896 | 893 | */ |
| 897 | - function _sort_callback($a,$b) |
|
| 894 | + function _sort_callback($a, $b) |
|
| 898 | 895 | { |
| 899 | - foreach($this->_callback_order as $col ) |
|
| 896 | + foreach ($this->_callback_order as $col) |
|
| 900 | 897 | { |
| 901 | - if($this->_callback_sort != 'DESC') |
|
| 898 | + if ($this->_callback_sort != 'DESC') |
|
| 902 | 899 | { |
| 903 | - $cmp = strcasecmp( $a[$col], $b[$col] ); |
|
| 900 | + $cmp = strcasecmp($a[$col], $b[$col]); |
|
| 904 | 901 | } |
| 905 | 902 | else |
| 906 | 903 | { |
| 907 | - $cmp = strcasecmp( $b[$col], $a[$col] ); |
|
| 904 | + $cmp = strcasecmp($b[$col], $a[$col]); |
|
| 908 | 905 | } |
| 909 | - if ( $cmp != 0 ) |
|
| 906 | + if ($cmp != 0) |
|
| 910 | 907 | { |
| 911 | 908 | return $cmp; |
| 912 | 909 | } |
@@ -925,8 +922,8 @@ discard block |
||
| 925 | 922 | { |
| 926 | 923 | if (!empty($date)) |
| 927 | 924 | { |
| 928 | - return gmmktime(substr($date,8,2),substr($date,10,2),substr($date,12,2), |
|
| 929 | - substr($date,4,2),substr($date,6,2),substr($date,0,4)); |
|
| 925 | + return gmmktime(substr($date, 8, 2), substr($date, 10, 2), substr($date, 12, 2), |
|
| 926 | + substr($date, 4, 2), substr($date, 6, 2), substr($date, 0, 4)); |
|
| 930 | 927 | } |
| 931 | 928 | return NULL; |
| 932 | 929 | } |
@@ -943,14 +940,14 @@ discard block |
||
| 943 | 940 | * @param string $account_type u = user, g = group, default null = try both |
| 944 | 941 | * @return int|false numeric account_id or false on error ($name not found) |
| 945 | 942 | */ |
| 946 | - function name2id($_name,$which='account_lid',$account_type=null) |
|
| 943 | + function name2id($_name, $which = 'account_lid', $account_type = null) |
|
| 947 | 944 | { |
| 948 | - $name = Api\Ldap::quote(Api\Translation::convert($_name,Api\Translation::charset(),'utf-8')); |
|
| 945 | + $name = Api\Ldap::quote(Api\Translation::convert($_name, Api\Translation::charset(), 'utf-8')); |
|
| 949 | 946 | |
| 950 | 947 | if ($which == 'account_lid' && $account_type !== 'u') // groups only support account_lid |
| 951 | 948 | { |
| 952 | 949 | |
| 953 | - $sri = ldap_search($this->ds, $this->group_context, '(&(cn=' . $name . ')(objectclass=posixgroup))', array('gidNumber')); |
|
| 950 | + $sri = ldap_search($this->ds, $this->group_context, '(&(cn='.$name.')(objectclass=posixgroup))', array('gidNumber')); |
|
| 954 | 951 | $allValues = ldap_get_entries($this->ds, $sri); |
| 955 | 952 | |
| 956 | 953 | if (@$allValues[0]['gidnumber'][0]) |
@@ -967,7 +964,7 @@ discard block |
||
| 967 | 964 | return False; |
| 968 | 965 | } |
| 969 | 966 | |
| 970 | - $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'=' . $name . ')(objectclass=posixaccount))', array('uidNumber')); |
|
| 967 | + $sri = ldap_search($this->ds, $this->user_context, '(&('.$to_ldap[$which].'='.$name.')(objectclass=posixaccount))', array('uidNumber')); |
|
| 971 | 968 | |
| 972 | 969 | $allValues = ldap_get_entries($this->ds, $sri); |
| 973 | 970 | |
@@ -987,9 +984,9 @@ discard block |
||
| 987 | 984 | * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ... |
| 988 | 985 | * @return string/false converted value or false on error ($account_id not found) |
| 989 | 986 | */ |
| 990 | - function id2name($account_id,$which='account_lid') |
|
| 987 | + function id2name($account_id, $which = 'account_lid') |
|
| 991 | 988 | { |
| 992 | - return $this->frontend->id2name($account_id,$which); |
|
| 989 | + return $this->frontend->id2name($account_id, $which); |
|
| 993 | 990 | } |
| 994 | 991 | |
| 995 | 992 | /** |
@@ -1002,7 +999,7 @@ discard block |
||
| 1002 | 999 | function update_lastlogin($_account_id, $ip) |
| 1003 | 1000 | { |
| 1004 | 1001 | unset($_account_id, $ip); |
| 1005 | - return false; // not longer supported |
|
| 1002 | + return false; // not longer supported |
|
| 1006 | 1003 | } |
| 1007 | 1004 | |
| 1008 | 1005 | /** |
@@ -1013,11 +1010,11 @@ discard block |
||
| 1013 | 1010 | */ |
| 1014 | 1011 | function memberships($account_id) |
| 1015 | 1012 | { |
| 1016 | - if (!(int) $account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
| 1013 | + if (!(int)$account_id || !($account_lid = $this->id2name($account_id))) return false; |
|
| 1017 | 1014 | |
| 1018 | - $sri = ldap_search($this->ds,$this->group_context,'(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))',array('cn','gidnumber')); |
|
| 1015 | + $sri = ldap_search($this->ds, $this->group_context, '(&(objectClass=posixGroup)(memberuid='.Api\Ldap::quote($account_lid).'))', array('cn', 'gidnumber')); |
|
| 1019 | 1016 | $memberships = array(); |
| 1020 | - foreach((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
| 1017 | + foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $data) |
|
| 1021 | 1018 | { |
| 1022 | 1019 | if ($key === 'count') continue; |
| 1023 | 1020 | |
@@ -1038,13 +1035,13 @@ discard block |
||
| 1038 | 1035 | if (!is_numeric($_gid)) |
| 1039 | 1036 | { |
| 1040 | 1037 | // try to recover |
| 1041 | - $_gid = $this->name2id($_gid,'account_lid','g'); |
|
| 1038 | + $_gid = $this->name2id($_gid, 'account_lid', 'g'); |
|
| 1042 | 1039 | if (!is_numeric($_gid)) return false; |
| 1043 | 1040 | } |
| 1044 | 1041 | |
| 1045 | - $gid = abs($_gid); // our gid is negative! |
|
| 1042 | + $gid = abs($_gid); // our gid is negative! |
|
| 1046 | 1043 | |
| 1047 | - $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=$gid))",array('memberuid')); |
|
| 1044 | + $sri = ldap_search($this->ds, $this->group_context, "(&(objectClass=posixGroup)(gidnumber=$gid))", array('memberuid')); |
|
| 1048 | 1045 | $group = ldap_get_entries($this->ds, $sri); |
| 1049 | 1046 | |
| 1050 | 1047 | $members = array(); |
@@ -1052,7 +1049,7 @@ discard block |
||
| 1052 | 1049 | { |
| 1053 | 1050 | unset($group[0]['memberuid']['count']); |
| 1054 | 1051 | |
| 1055 | - foreach($group[0]['memberuid'] as $lid) |
|
| 1052 | + foreach ($group[0]['memberuid'] as $lid) |
|
| 1056 | 1053 | { |
| 1057 | 1054 | if (($id = $this->name2id($lid, 'account_lid', 'u'))) |
| 1058 | 1055 | { |
@@ -1069,27 +1066,27 @@ discard block |
||
| 1069 | 1066 | * @param array $groups array with gidnumbers |
| 1070 | 1067 | * @param int $account_id uidnumber |
| 1071 | 1068 | */ |
| 1072 | - function set_memberships($groups,$account_id) |
|
| 1069 | + function set_memberships($groups, $account_id) |
|
| 1073 | 1070 | { |
| 1074 | 1071 | // remove not longer existing memberships |
| 1075 | 1072 | if (($old_memberships = $this->memberships($account_id))) |
| 1076 | 1073 | { |
| 1077 | 1074 | $old_memberships = array_keys($old_memberships); |
| 1078 | - foreach(array_diff($old_memberships,$groups) as $gid) |
|
| 1075 | + foreach (array_diff($old_memberships, $groups) as $gid) |
|
| 1079 | 1076 | { |
| 1080 | 1077 | if (($members = $this->members($gid))) |
| 1081 | 1078 | { |
| 1082 | 1079 | unset($members[$account_id]); |
| 1083 | - $this->set_members($members,$gid); |
|
| 1080 | + $this->set_members($members, $gid); |
|
| 1084 | 1081 | } |
| 1085 | 1082 | } |
| 1086 | 1083 | } |
| 1087 | 1084 | // adding new memberships |
| 1088 | - foreach($old_memberships ? array_diff($groups,$old_memberships) : $groups as $gid) |
|
| 1085 | + foreach ($old_memberships ? array_diff($groups, $old_memberships) : $groups as $gid) |
|
| 1089 | 1086 | { |
| 1090 | 1087 | if (!($members = $this->members($gid))) $members = array(); |
| 1091 | 1088 | $members[$account_id] = $this->id2name($account_id); |
| 1092 | - $this->set_members($members,$gid); |
|
| 1089 | + $this->set_members($members, $gid); |
|
| 1093 | 1090 | } |
| 1094 | 1091 | } |
| 1095 | 1092 | |
@@ -1103,15 +1100,15 @@ discard block |
||
| 1103 | 1100 | * @param boolean $uniqueMember =null should we set the uniqueMember attribute (default detect it) |
| 1104 | 1101 | * @return boolean/array false on failure, array or true otherwise |
| 1105 | 1102 | */ |
| 1106 | - function set_members($members, $gid, array $objectclass=null, $use_cn=null) |
|
| 1103 | + function set_members($members, $gid, array $objectclass = null, $use_cn = null) |
|
| 1107 | 1104 | { |
| 1108 | 1105 | if (!($cn = $use_cn) && !($cn = $this->id2name($gid))) return false; |
| 1109 | 1106 | |
| 1110 | 1107 | // do that group is a groupOf(Unique)Names or univentionGroup? |
| 1111 | - if (is_null($objectclass)) $objectclass = $this->id2name($gid,'objectclass'); |
|
| 1108 | + if (is_null($objectclass)) $objectclass = $this->id2name($gid, 'objectclass'); |
|
| 1112 | 1109 | |
| 1113 | 1110 | $to_write = array('memberuid' => array()); |
| 1114 | - foreach((array)$members as $key => $member) |
|
| 1111 | + foreach ((array)$members as $key => $member) |
|
| 1115 | 1112 | { |
| 1116 | 1113 | $member_dn = $this->id2name($member, 'account_dn'); |
| 1117 | 1114 | if (is_numeric($member)) $member = $this->id2name($member); |
@@ -1123,7 +1120,7 @@ discard block |
||
| 1123 | 1120 | { |
| 1124 | 1121 | $to_write['member'][] = $member_dn; |
| 1125 | 1122 | } |
| 1126 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass)) |
|
| 1123 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass)) |
|
| 1127 | 1124 | { |
| 1128 | 1125 | $to_write['uniquemember'][] = $member_dn; |
| 1129 | 1126 | } |
@@ -1134,31 +1131,31 @@ discard block |
||
| 1134 | 1131 | { |
| 1135 | 1132 | $to_write['member'][] = 'uid=dummy'.','.$this->user_context; |
| 1136 | 1133 | } |
| 1137 | - if (array_intersect(array('groupofuniquenames','univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
| 1134 | + if (array_intersect(array('groupofuniquenames', 'univentiongroup'), $objectclass) && !$to_write['uniquemember']) |
|
| 1138 | 1135 | { |
| 1139 | 1136 | $to_write['uniquemember'][] = 'uid=dummy'.','.$this->user_context; |
| 1140 | 1137 | } |
| 1141 | 1138 | if ($use_cn) return $to_write; |
| 1142 | 1139 | |
| 1143 | 1140 | // set the member email addresses as forwards |
| 1144 | - if ($this->id2name($gid,'account_email') && ($objectclass = $this->id2name($gid,'mailAllowed'))) |
|
| 1141 | + if ($this->id2name($gid, 'account_email') && ($objectclass = $this->id2name($gid, 'mailAllowed'))) |
|
| 1145 | 1142 | { |
| 1146 | 1143 | $forward = $this->group_mail_classes[$objectclass]; |
| 1147 | - if (is_array($forward)) list($forward,$extra_attr) = $forward; |
|
| 1144 | + if (is_array($forward)) list($forward, $extra_attr) = $forward; |
|
| 1148 | 1145 | if ($extra_attr && ($uid = $this->id2name($gid))) $to_write[$extra_attr] = $uid; |
| 1149 | 1146 | |
| 1150 | 1147 | if ($forward) |
| 1151 | 1148 | { |
| 1152 | 1149 | $to_write[$forward] = array(); |
| 1153 | - foreach($members as $key => $member) |
|
| 1150 | + foreach ($members as $key => $member) |
|
| 1154 | 1151 | { |
| 1155 | - if (($email = $this->id2name($member,'account_email'))) $to_write[$forward][] = $email; |
|
| 1152 | + if (($email = $this->id2name($member, 'account_email'))) $to_write[$forward][] = $email; |
|
| 1156 | 1153 | } |
| 1157 | 1154 | } |
| 1158 | 1155 | } |
| 1159 | - if (!ldap_modify($this->ds,'cn='.Api\Ldap::quote($cn).','.$this->group_context,$to_write)) |
|
| 1156 | + if (!ldap_modify($this->ds, 'cn='.Api\Ldap::quote($cn).','.$this->group_context, $to_write)) |
|
| 1160 | 1157 | { |
| 1161 | - echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write,true)."))\n"; |
|
| 1158 | + echo "ldap_modify(,'cn=$cn,$this->group_context',".print_r($to_write, true)."))\n"; |
|
| 1162 | 1159 | return false; |
| 1163 | 1160 | } |
| 1164 | 1161 | return true; |
@@ -1171,7 +1168,7 @@ discard block |
||
| 1171 | 1168 | * @param string $account_type ='u' (optional, default to 'u') |
| 1172 | 1169 | * @return int|boolean integer account_id (negative for groups) or false if none is free anymore |
| 1173 | 1170 | */ |
| 1174 | - protected function _get_nextid($account_type='u') |
|
| 1171 | + protected function _get_nextid($account_type = 'u') |
|
| 1175 | 1172 | { |
| 1176 | 1173 | $min = $this->frontend->config['account_min_id'] ? $this->frontend->config['account_min_id'] : 0; |
| 1177 | 1174 | $max = $this->frontend->config['account_max_id'] ? $this->frontend->config['account_max_id'] : 0; |
@@ -1193,16 +1190,16 @@ discard block |
||
| 1193 | 1190 | /* Loop until we find a free id */ |
| 1194 | 1191 | do |
| 1195 | 1192 | { |
| 1196 | - $account_id = (int) self::next_id($type,$min,$max); |
|
| 1193 | + $account_id = (int)self::next_id($type, $min, $max); |
|
| 1197 | 1194 | } |
| 1198 | - while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
| 1195 | + while ($account_id && ($this->frontend->exists($sign * $account_id) || // check need to include the sign! |
|
| 1199 | 1196 | $this->frontend->exists(-1 * $sign * $account_id) || |
| 1200 | 1197 | // if sambaadmin is installed, call it to check there's not yet a relative id (last part of SID) with that number |
| 1201 | 1198 | // to ease migration to AD or Samba4 |
| 1202 | 1199 | file_exists(EGW_SERVER_ROOT.'/sambaadmin') && $GLOBALS['egw_info']['apps']['sambaadmin'] && |
| 1203 | 1200 | ExecMethod2('sambaadmin.sosambaadmin.sidExists', $account_id))); |
| 1204 | 1201 | |
| 1205 | - if (!$account_id || $max && $account_id > $max) |
|
| 1202 | + if (!$account_id || $max && $account_id > $max) |
|
| 1206 | 1203 | { |
| 1207 | 1204 | return False; |
| 1208 | 1205 | } |
@@ -1217,14 +1214,14 @@ discard block |
||
| 1217 | 1214 | * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false |
| 1218 | 1215 | * @return int|boolean the next id or false if $max given and exceeded |
| 1219 | 1216 | */ |
| 1220 | - static function next_id($location,$min=0,$max=0) |
|
| 1217 | + static function next_id($location, $min = 0, $max = 0) |
|
| 1221 | 1218 | { |
| 1222 | 1219 | if (!$location) |
| 1223 | 1220 | { |
| 1224 | 1221 | return -1; |
| 1225 | 1222 | } |
| 1226 | 1223 | |
| 1227 | - $id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location]; |
|
| 1224 | + $id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location]; |
|
| 1228 | 1225 | |
| 1229 | 1226 | if ($max && $id >= $max) |
| 1230 | 1227 | { |
@@ -1232,10 +1229,10 @@ discard block |
||
| 1232 | 1229 | } |
| 1233 | 1230 | ++$id; |
| 1234 | 1231 | |
| 1235 | - if($id < $min) $id = $min; |
|
| 1232 | + if ($id < $min) $id = $min; |
|
| 1236 | 1233 | |
| 1237 | 1234 | Api\Config::save_value($key, $id, 'phpgwapi', true); |
| 1238 | - $GLOBALS['egw_info']['server'][$key='last_id_'.$location] = $id; |
|
| 1235 | + $GLOBALS['egw_info']['server'][$key = 'last_id_'.$location] = $id; |
|
| 1239 | 1236 | |
| 1240 | 1237 | return (int)$id; |
| 1241 | 1238 | } |
@@ -1248,18 +1245,18 @@ discard block |
||
| 1248 | 1245 | * @param int $max =0 if != 0 maximum id allowed, if it would be exceeded we return false |
| 1249 | 1246 | * @return int|boolean current id in the next_id table for a particular app/class or -1 for no app and false if $max is exceeded. |
| 1250 | 1247 | */ |
| 1251 | - static function last_id($location,$min=0,$max=0) |
|
| 1248 | + static function last_id($location, $min = 0, $max = 0) |
|
| 1252 | 1249 | { |
| 1253 | 1250 | if (!$location) |
| 1254 | 1251 | { |
| 1255 | 1252 | return -1; |
| 1256 | 1253 | } |
| 1257 | 1254 | |
| 1258 | - $id = (int)$GLOBALS['egw_info']['server'][$key='last_id_'.$location]; |
|
| 1255 | + $id = (int)$GLOBALS['egw_info']['server'][$key = 'last_id_'.$location]; |
|
| 1259 | 1256 | |
| 1260 | 1257 | if (!$id || $id < $min) |
| 1261 | 1258 | { |
| 1262 | - return self::next_id($location,$min,$max); |
|
| 1259 | + return self::next_id($location, $min, $max); |
|
| 1263 | 1260 | } |
| 1264 | 1261 | if ($max && $id > $max) |
| 1265 | 1262 | { |
@@ -1274,6 +1271,6 @@ discard block |
||
| 1274 | 1271 | function __wakeup() |
| 1275 | 1272 | { |
| 1276 | 1273 | $this->ds = Api\Ldap::factory(true, $this->frontend->config['ldap_host'], |
| 1277 | - $this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']); |
|
| 1274 | + $this->frontend->config['ldap_root_dn'], $this->frontend->config['ldap_root_pw']); |
|
| 1278 | 1275 | } |
| 1279 | 1276 | } |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | * If no account_id is set in data the account is added and the new id is set in $data. |
| 48 | 48 | * |
| 49 | 49 | * @param array $data array with account-data |
| 50 | - * @return int|boolean the account_id or false on error |
|
| 50 | + * @return false|string the account_id or false on error |
|
| 51 | 51 | */ |
| 52 | 52 | function save(&$data) |
| 53 | 53 | { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | if (!$data['account_id'] && $data['account_type'] !== 'g') |
| 63 | 63 | { |
| 64 | 64 | $params = array( |
| 65 | - 'users/user','create', |
|
| 65 | + 'users/user', 'create', |
|
| 66 | 66 | '--binddn', $config['ldap_root_dn'], |
| 67 | 67 | '--bindpwd', 5=>$config['ldap_root_pw'], |
| 68 | 68 | '--position', $config['ldap_context'], |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | $hostname = $account->acc_imap_host; |
| 89 | 89 | } |
| 90 | - catch(\Exception $e) { |
|
| 90 | + catch (\Exception $e) { |
|
| 91 | 91 | unset($e); |
| 92 | 92 | } |
| 93 | 93 | if (empty($hostname)) $hostname = trim(system('hostname -f')); |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | $output = implode("\n", $output_arr); |
| 100 | 100 | if ($ret || !preg_match('/^Object created: (uid=.*)$/mui', $output, $matches)) |
| 101 | 101 | { |
| 102 | - $params[5] = '********'; // mask out password! |
|
| 102 | + $params[5] = '********'; // mask out password! |
|
| 103 | 103 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
| 104 | 104 | throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output); |
| 105 | 105 | } |
| 106 | 106 | $data['account_dn'] = $matches[1]; |
| 107 | 107 | $data['account_id'] = $this->name2id($data['account_lid'], 'account_lid', 'u'); |
| 108 | 108 | } |
| 109 | - elseif($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) && |
|
| 109 | + elseif ($data['account_id'] && ($data['old_loginid'] || ($data['old_loginid'] = $this->id2name($data['account_id']))) && |
|
| 110 | 110 | $data['account_lid'] != $data['old_loginid'] && |
| 111 | 111 | ($data['account_dn'] = $this->id2name($data['account_id'], 'account_dn'))) |
| 112 | 112 | { |
@@ -123,12 +123,11 @@ discard block |
||
| 123 | 123 | $output = implode("\n", $output_arr); |
| 124 | 124 | if ($ret || !preg_match('/^Object modified: ((uid|cn)=.*)$/mui', $output, $matches)) |
| 125 | 125 | { |
| 126 | - $params[5] = '********'; // mask out password! |
|
| 126 | + $params[5] = '********'; // mask out password! |
|
| 127 | 127 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
| 128 | 128 | throw new Api\Exception\WrongUserinput($cmd."\nreturned\n".$output); |
| 129 | 129 | } |
| 130 | - $data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : |
|
| 131 | - // duno why but directory-manager returns old dn for groups ... |
|
| 130 | + $data['account_dn'] = $data['account_type'] !== 'g' ? $matches[1] : // duno why but directory-manager returns old dn for groups ... |
|
| 132 | 131 | preg_replace('/^cn=[^,]+,/', 'cn='.$data['account_lid'].',', $data['account_dn']); |
| 133 | 132 | } |
| 134 | 133 | } |
@@ -90,7 +90,10 @@ |
||
| 90 | 90 | catch(\Exception $e) { |
| 91 | 91 | unset($e); |
| 92 | 92 | } |
| 93 | - if (empty($hostname)) $hostname = trim(system('hostname -f')); |
|
| 93 | + if (empty($hostname)) |
|
| 94 | + { |
|
| 95 | + $hostname = trim(system('hostname -f')); |
|
| 96 | + } |
|
| 94 | 97 | $params[] = '--set'; $params[] = 'mailHomeServer='.$hostname; |
| 95 | 98 | } |
| 96 | 99 | $cmd = self::DIRECTORY_MANAGER_BIN.' '.implode(' ', array_map('escapeshellarg', $params)); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * Delete ACL record in the repository of the class |
| 167 | 167 | * |
| 168 | 168 | * @param string $appname appname or '' for $GLOBALS['egw_info']['flags']['currentapp'] |
| 169 | - * @param string/boolean $location location or false for all locations |
|
| 169 | + * @param boolean $location location or false for all locations |
|
| 170 | 170 | * @return array all ACL records from $this->data. |
| 171 | 171 | */ |
| 172 | 172 | function delete($appname,$location) |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * check required rights agains the internal repository (included rights of $this->account_id and all it's memberships) |
| 269 | 269 | * |
| 270 | - * @param $location app location |
|
| 271 | - * @param $required required right to check against |
|
| 270 | + * @param string $location app location |
|
| 271 | + * @param integer $required required right to check against |
|
| 272 | 272 | * @param $appname optional defaults to currentapp |
| 273 | 273 | * @return boolean |
| 274 | 274 | */ |
@@ -111,7 +111,10 @@ discard block |
||
| 111 | 111 | else |
| 112 | 112 | { |
| 113 | 113 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
| 114 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 114 | + if (is_array($no_groups)) |
|
| 115 | + { |
|
| 116 | + $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 117 | + } |
|
| 115 | 118 | array_unshift($acl_acc_list,$this->account_id); |
| 116 | 119 | } |
| 117 | 120 | |
@@ -149,7 +152,10 @@ discard block |
||
| 149 | 152 | */ |
| 150 | 153 | function add($appname,$location,$rights) |
| 151 | 154 | { |
| 152 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 155 | + if (!$appname) |
|
| 156 | + { |
|
| 157 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 158 | + } |
|
| 153 | 159 | |
| 154 | 160 | $row = array( |
| 155 | 161 | 'appname' => $appname, |
@@ -171,7 +177,10 @@ discard block |
||
| 171 | 177 | */ |
| 172 | 178 | function delete($appname,$location) |
| 173 | 179 | { |
| 174 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 180 | + if (!$appname) |
|
| 181 | + { |
|
| 182 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | foreach($this->data as $idx => $value) |
| 177 | 186 | { |
@@ -209,10 +218,13 @@ discard block |
||
| 209 | 218 | } |
| 210 | 219 | } |
| 211 | 220 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 212 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 221 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 222 | + { |
|
| 223 | + // egw object in setup is limited |
|
| 213 | 224 | { |
| 214 | 225 | $GLOBALS['egw']->invalidate_session_cache(); |
| 215 | 226 | } |
| 227 | + } |
|
| 216 | 228 | return $this->data; |
| 217 | 229 | } |
| 218 | 230 | |
@@ -240,7 +252,10 @@ discard block |
||
| 240 | 252 | { |
| 241 | 253 | $this->read_repository(); |
| 242 | 254 | } |
| 243 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 255 | + if (!$appname) |
|
| 256 | + { |
|
| 257 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 258 | + } |
|
| 244 | 259 | |
| 245 | 260 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
| 246 | 261 | { |
@@ -289,7 +304,10 @@ discard block |
||
| 289 | 304 | */ |
| 290 | 305 | function get_specific_rights($location, $appname = '', $memberships=array()) |
| 291 | 306 | { |
| 292 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 307 | + if (!$appname) |
|
| 308 | + { |
|
| 309 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 310 | + } |
|
| 293 | 311 | |
| 294 | 312 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
| 295 | 313 | { |
@@ -353,10 +371,13 @@ discard block |
||
| 353 | 371 | ),__LINE__,__FILE__); |
| 354 | 372 | |
| 355 | 373 | if ($account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 356 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 374 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 375 | + { |
|
| 376 | + // egw object in setup is limited |
|
| 357 | 377 | { |
| 358 | 378 | $GLOBALS['egw']->invalidate_session_cache(); |
| 359 | 379 | } |
| 380 | + } |
|
| 360 | 381 | return True; |
| 361 | 382 | } |
| 362 | 383 | |
@@ -387,11 +408,17 @@ discard block |
||
| 387 | 408 | $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
| 388 | 409 | } |
| 389 | 410 | } |
| 390 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 411 | + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 412 | + { |
|
| 413 | + // egw object in setup is limited |
|
| 391 | 414 | { |
| 392 | 415 | $GLOBALS['egw']->invalidate_session_cache(); |
| 393 | 416 | } |
| 394 | - if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
|
| 417 | + } |
|
| 418 | + if ($app == '%' || $app == '%%') |
|
| 419 | + { |
|
| 420 | + unset($where['acl_appname']); |
|
| 421 | + } |
|
| 395 | 422 | |
| 396 | 423 | $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
| 397 | 424 | |
@@ -408,7 +435,10 @@ discard block |
||
| 408 | 435 | */ |
| 409 | 436 | function get_specific_rights_for_account($account_id,$location,$appname='') |
| 410 | 437 | { |
| 411 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 438 | + if (!$appname) |
|
| 439 | + { |
|
| 440 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 441 | + } |
|
| 412 | 442 | |
| 413 | 443 | return $this->db->select(self::TABLE,'acl_rights',array( |
| 414 | 444 | 'acl_location' => $location, |
@@ -426,7 +456,10 @@ discard block |
||
| 426 | 456 | */ |
| 427 | 457 | function get_all_rights($location,$appname='') |
| 428 | 458 | { |
| 429 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 459 | + if (!$appname) |
|
| 460 | + { |
|
| 461 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 462 | + } |
|
| 430 | 463 | |
| 431 | 464 | $rights = array(); |
| 432 | 465 | foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
@@ -449,7 +482,10 @@ discard block |
||
| 449 | 482 | */ |
| 450 | 483 | function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
| 451 | 484 | { |
| 452 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 485 | + if (!$appname) |
|
| 486 | + { |
|
| 487 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 488 | + } |
|
| 453 | 489 | |
| 454 | 490 | $accounts = array($account_id); |
| 455 | 491 | if ($use_memberships && (int)$account_id > 0) |
@@ -553,7 +589,10 @@ discard block |
||
| 553 | 589 | */ |
| 554 | 590 | function get_ids_for_location($location, $required, $app = '') |
| 555 | 591 | { |
| 556 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 592 | + if (!$app) |
|
| 593 | + { |
|
| 594 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 595 | + } |
|
| 557 | 596 | |
| 558 | 597 | $accounts = false; |
| 559 | 598 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
@@ -577,7 +616,10 @@ discard block |
||
| 577 | 616 | */ |
| 578 | 617 | function get_locations_for_app($app='') |
| 579 | 618 | { |
| 580 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 619 | + if (!$app) |
|
| 620 | + { |
|
| 621 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 622 | + } |
|
| 581 | 623 | |
| 582 | 624 | $locations = false; |
| 583 | 625 | foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
@@ -613,7 +655,10 @@ discard block |
||
| 613 | 655 | $account_id = get_account_id($accountid,$this->account_id); |
| 614 | 656 | $cache_accountid[$accountid] = $account_id; |
| 615 | 657 | } |
| 616 | - if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
| 658 | + if ($use_memberships && (int)$account_id > 0) |
|
| 659 | + { |
|
| 660 | + $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
| 661 | + } |
|
| 617 | 662 | $memberships[] = (int)$account_id; |
| 618 | 663 | |
| 619 | 664 | $apps = array(); |
@@ -647,15 +692,24 @@ discard block |
||
| 647 | 692 | */ |
| 648 | 693 | function get_grants($app='',$enum_group_acls=true,$user=null) |
| 649 | 694 | { |
| 650 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 651 | - if (!$user) $user = $this->account_id; |
|
| 695 | + if (!$app) |
|
| 696 | + { |
|
| 697 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 698 | + } |
|
| 699 | + if (!$user) |
|
| 700 | + { |
|
| 701 | + $user = $this->account_id; |
|
| 702 | + } |
|
| 652 | 703 | |
| 653 | 704 | static $cache = array(); // some caching withing the request |
| 654 | 705 | |
| 655 | 706 | $grants =& $cache[$app][$user]; |
| 656 | 707 | if (!isset($grants)) |
| 657 | 708 | { |
| 658 | - if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
| 709 | + if ((int)$user > 0) |
|
| 710 | + { |
|
| 711 | + $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
| 712 | + } |
|
| 659 | 713 | $memberships[] = $user; |
| 660 | 714 | |
| 661 | 715 | $grants = $accounts = Array(); |
@@ -680,7 +734,11 @@ discard block |
||
| 680 | 734 | // return the grant for each member of the group (false = also for no longer active users) |
| 681 | 735 | foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
| 682 | 736 | { |
| 683 | - if (!$grantor) continue; // can happen if group has no members |
|
| 737 | + if (!$grantor) |
|
| 738 | + { |
|
| 739 | + continue; |
|
| 740 | + } |
|
| 741 | + // can happen if group has no members |
|
| 684 | 742 | |
| 685 | 743 | // Don't allow to override private with group ACL's! |
| 686 | 744 | $rights &= ~self::PRIVAT; |
@@ -734,7 +792,10 @@ discard block |
||
| 734 | 792 | */ |
| 735 | 793 | function get_location_grants($location,$app='') |
| 736 | 794 | { |
| 737 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 795 | + if (!$app) |
|
| 796 | + { |
|
| 797 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 798 | + } |
|
| 738 | 799 | |
| 739 | 800 | $locations = array(); |
| 740 | 801 | foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * @var array $data internal repository with acl rows for the given app and account-id (incl. memberships) |
| 34 | 34 | */ |
| 35 | - var $data = Array(); |
|
| 35 | + var $data = array(); |
|
| 36 | 36 | /** |
| 37 | 37 | * internal reference to global db-object |
| 38 | 38 | * |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | array_unshift($acl_acc_list,$this->account_id); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $this->data = Array(); |
|
| 136 | + $this->data = array(); |
|
| 137 | 137 | foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row) |
| 138 | 138 | { |
| 139 | 139 | $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_'); |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
| 677 | 677 | $memberships[] = $user; |
| 678 | 678 | |
| 679 | - $grants = $accounts = Array(); |
|
| 679 | + $grants = $accounts = array(); |
|
| 680 | 680 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array( |
| 681 | 681 | 'acl_appname' => $app, |
| 682 | 682 | 'acl_location' => $memberships, |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Constants for acl rights, like old EGW_ACL_* defines |
| 49 | 49 | */ |
| 50 | - const READ = 1; // EGW_ACL_READ |
|
| 51 | - const ADD = 2; // EGW_ACL_ADD |
|
| 52 | - const EDIT = 4; // EGW_ACL_EDIT |
|
| 53 | - const DELETE = 8; // EGW_ACL_DELETE |
|
| 54 | - const PRIVAT = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead! |
|
| 55 | - const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS |
|
| 56 | - const CUSTOM1 = 64; // EGW_ACL_CUSTOM_1 |
|
| 57 | - const CUSTOM2 = 128; // EGW_ACL_CUSTOM_2 |
|
| 58 | - const CUSTOM3 = 256; // EGW_ACL_CUSTOM_3 |
|
| 50 | + const READ = 1; // EGW_ACL_READ |
|
| 51 | + const ADD = 2; // EGW_ACL_ADD |
|
| 52 | + const EDIT = 4; // EGW_ACL_EDIT |
|
| 53 | + const DELETE = 8; // EGW_ACL_DELETE |
|
| 54 | + const PRIVAT = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead! |
|
| 55 | + const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS |
|
| 56 | + const CUSTOM1 = 64; // EGW_ACL_CUSTOM_1 |
|
| 57 | + const CUSTOM2 = 128; // EGW_ACL_CUSTOM_2 |
|
| 58 | + const CUSTOM3 = 256; // EGW_ACL_CUSTOM_3 |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * ACL constructor for setting account id |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | if ((int)$this->account_id != (int)$account_id) |
| 80 | 80 | { |
| 81 | - $this->account_id = get_account_id((int)$account_id,@$GLOBALS['egw_info']['user']['account_id']); |
|
| 81 | + $this->account_id = get_account_id((int)$account_id, @$GLOBALS['egw_info']['user']['account_id']); |
|
| 82 | 82 | } |
| 83 | 83 | $this->data = array(); |
| 84 | 84 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function __sleep() |
| 93 | 93 | { |
| 94 | - return array('account_id','db'); |
|
| 94 | + return array('account_id', 'db'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /**************************************************************************\ |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @param boolean|array $no_groups = false if true, do not use memberships, if array do not use given groups |
| 105 | 105 | * @return array along with storing it in $acl->data. <br> |
| 106 | 106 | */ |
| 107 | - function read_repository($no_groups=false) |
|
| 107 | + function read_repository($no_groups = false) |
|
| 108 | 108 | { |
| 109 | 109 | // For some reason, calling this via XML-RPC doesn't call the constructor. |
| 110 | 110 | // Here is yet another work around(tm) (jengo) |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | else |
| 120 | 120 | { |
| 121 | 121 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
| 122 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 123 | - array_unshift($acl_acc_list,$this->account_id); |
|
| 122 | + if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list, $no_groups); |
|
| 123 | + array_unshift($acl_acc_list, $this->account_id); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $this->data = Array(); |
| 127 | - foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row) |
|
| 127 | + foreach ($this->db->select(self::TABLE, '*', array('acl_account' => $acl_acc_list), __LINE__, __FILE__) as $row) |
|
| 128 | 128 | { |
| 129 | - $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_'); |
|
| 129 | + $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row, 'acl_'); |
|
| 130 | 130 | } |
| 131 | 131 | return $this->data; |
| 132 | 132 | } |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | * @param int $rights rights |
| 156 | 156 | * @return array all ACL records from $this->data. |
| 157 | 157 | */ |
| 158 | - function add($appname,$location,$rights) |
|
| 158 | + function add($appname, $location, $rights) |
|
| 159 | 159 | { |
| 160 | 160 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 161 | 161 | |
| 162 | 162 | $row = array( |
| 163 | 163 | 'appname' => $appname, |
| 164 | 164 | 'location' => $location, |
| 165 | - 'account' => (int) $this->account_id, |
|
| 166 | - 'rights' => (int) $rights |
|
| 165 | + 'account' => (int)$this->account_id, |
|
| 166 | + 'rights' => (int)$rights |
|
| 167 | 167 | ); |
| 168 | 168 | $this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row; |
| 169 | 169 | |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | * @param string/boolean $location location or false for all locations |
| 178 | 178 | * @return array all ACL records from $this->data. |
| 179 | 179 | */ |
| 180 | - function delete($appname,$location) |
|
| 180 | + function delete($appname, $location) |
|
| 181 | 181 | { |
| 182 | 182 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 183 | 183 | |
| 184 | - foreach($this->data as $idx => $value) |
|
| 184 | + foreach ($this->data as $idx => $value) |
|
| 185 | 185 | { |
| 186 | 186 | if ($value['appname'] == $appname && |
| 187 | 187 | ($location === false || $value['location'] == $location) && |
@@ -200,24 +200,24 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | function save_repository() |
| 202 | 202 | { |
| 203 | - $this->db->delete(self::TABLE,array( |
|
| 203 | + $this->db->delete(self::TABLE, array( |
|
| 204 | 204 | 'acl_account' => $this->account_id, |
| 205 | - ),__LINE__,__FILE__); |
|
| 205 | + ), __LINE__, __FILE__); |
|
| 206 | 206 | |
| 207 | - foreach($this->data as $value) |
|
| 207 | + foreach ($this->data as $value) |
|
| 208 | 208 | { |
| 209 | 209 | if ($value['account'] == $this->account_id) |
| 210 | 210 | { |
| 211 | - $this->db->insert(self::TABLE,array( |
|
| 211 | + $this->db->insert(self::TABLE, array( |
|
| 212 | 212 | 'acl_appname' => $value['appname'], |
| 213 | 213 | 'acl_location' => $value['location'], |
| 214 | 214 | 'acl_account' => $this->account_id, |
| 215 | 215 | 'acl_rights' => $value['rights'], |
| 216 | - ),false,__LINE__,__FILE__); |
|
| 216 | + ), false, __LINE__, __FILE__); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 220 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 220 | + method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 221 | 221 | { |
| 222 | 222 | $GLOBALS['egw']->invalidate_session_cache(); |
| 223 | 223 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @param string $appname optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
| 236 | 236 | * @return int all rights or'ed together |
| 237 | 237 | */ |
| 238 | - function get_rights($location,$appname = '') |
|
| 238 | + function get_rights($location, $appname = '') |
|
| 239 | 239 | { |
| 240 | 240 | // For XML-RPC, change this once its working correctly for passing parameters (jengo) |
| 241 | 241 | if (is_array($location)) |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | return True; |
| 256 | 256 | } |
| 257 | 257 | $rights = 0; |
| 258 | - foreach($this->data as $value) |
|
| 258 | + foreach ($this->data as $value) |
|
| 259 | 259 | { |
| 260 | 260 | if ($value['appname'] == $appname) |
| 261 | 261 | { |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function check($location, $required, $appname = False) |
| 284 | 284 | { |
| 285 | - $rights = $this->get_rights($location,$appname); |
|
| 285 | + $rights = $this->get_rights($location, $appname); |
|
| 286 | 286 | |
| 287 | - return !!($rights & $required); |
|
| 287 | + return !!($rights&$required); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param array $memberships = array() additional account_id, eg. memberships to match beside $this->account_id, default none |
| 296 | 296 | * @return int $rights |
| 297 | 297 | */ |
| 298 | - function get_specific_rights($location, $appname = '', $memberships=array()) |
|
| 298 | + function get_specific_rights($location, $appname = '', $memberships = array()) |
|
| 299 | 299 | { |
| 300 | 300 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 301 | 301 | |
@@ -305,10 +305,10 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | $rights = 0; |
| 307 | 307 | |
| 308 | - foreach($this->data as $value) |
|
| 308 | + foreach ($this->data as $value) |
|
| 309 | 309 | { |
| 310 | 310 | if ($value['appname'] == $appname && |
| 311 | - ($value['location'] == $location || $value['location'] == 'everywhere') && |
|
| 311 | + ($value['location'] == $location || $value['location'] == 'everywhere') && |
|
| 312 | 312 | ($value['account'] == $this->account_id || $memberships && in_array($value['account'], $memberships))) |
| 313 | 313 | { |
| 314 | 314 | if ($value['rights'] == 0) |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | function check_specific($location, $required, $appname = '') |
| 333 | 333 | { |
| 334 | - $rights = $this->get_specific_rights($location,$appname); |
|
| 334 | + $rights = $this->get_specific_rights($location, $appname); |
|
| 335 | 335 | |
| 336 | - return !!($rights & $required); |
|
| 336 | + return !!($rights&$required); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /**************************************************************************\ |
@@ -352,16 +352,16 @@ discard block |
||
| 352 | 352 | function add_repository($app, $location, $account_id, $rights) |
| 353 | 353 | { |
| 354 | 354 | //echo "<p>self::add_repository('$app','$location',$account_id,$rights);</p>\n"; |
| 355 | - $this->db->insert(self::TABLE,array( |
|
| 355 | + $this->db->insert(self::TABLE, array( |
|
| 356 | 356 | 'acl_rights' => $rights, |
| 357 | - ),array( |
|
| 357 | + ), array( |
|
| 358 | 358 | 'acl_appname' => $app, |
| 359 | 359 | 'acl_location' => $location, |
| 360 | 360 | 'acl_account' => $account_id, |
| 361 | - ),__LINE__,__FILE__); |
|
| 361 | + ), __LINE__, __FILE__); |
|
| 362 | 362 | |
| 363 | 363 | if ($account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 364 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 364 | + method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 365 | 365 | { |
| 366 | 366 | $GLOBALS['egw']->invalidate_session_cache(); |
| 367 | 367 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | * @param int/boolean $accountid = '' account id, default 0=$this->account_id, or false to delete all entries for $app/$location |
| 377 | 377 | * @return int number of rows deleted |
| 378 | 378 | */ |
| 379 | - function delete_repository($app, $location, $accountid='') |
|
| 379 | + function delete_repository($app, $location, $accountid = '') |
|
| 380 | 380 | { |
| 381 | 381 | static $cache_accountid = array(); |
| 382 | 382 | |
@@ -386,22 +386,22 @@ discard block |
||
| 386 | 386 | ); |
| 387 | 387 | if ($accountid !== false) |
| 388 | 388 | { |
| 389 | - if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid]) |
|
| 389 | + if (isset($cache_accountid[$accountid]) && $cache_accountid[$accountid]) |
|
| 390 | 390 | { |
| 391 | 391 | $where['acl_account'] = $cache_accountid[$accountid]; |
| 392 | 392 | } |
| 393 | 393 | else |
| 394 | 394 | { |
| 395 | - $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
|
| 395 | + $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 398 | + if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 399 | 399 | { |
| 400 | 400 | $GLOBALS['egw']->invalidate_session_cache(); |
| 401 | 401 | } |
| 402 | 402 | if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
| 403 | 403 | |
| 404 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
| 404 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
| 405 | 405 | |
| 406 | 406 | return $this->db->affected_rows(); |
| 407 | 407 | } |
@@ -414,15 +414,15 @@ discard block |
||
| 414 | 414 | * @param string $appname = '' defaults to current app |
| 415 | 415 | * @return int/boolean rights or false if none exist |
| 416 | 416 | */ |
| 417 | - function get_specific_rights_for_account($account_id,$location,$appname='') |
|
| 417 | + function get_specific_rights_for_account($account_id, $location, $appname = '') |
|
| 418 | 418 | { |
| 419 | 419 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 420 | 420 | |
| 421 | - return $this->db->select(self::TABLE,'acl_rights',array( |
|
| 421 | + return $this->db->select(self::TABLE, 'acl_rights', array( |
|
| 422 | 422 | 'acl_location' => $location, |
| 423 | 423 | 'acl_account' => $account_id, |
| 424 | 424 | 'acl_appname' => $appname, |
| 425 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
| 425 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -432,15 +432,15 @@ discard block |
||
| 432 | 432 | * @param string $appname = '' defaults to current app |
| 433 | 433 | * @return array with account => rights pairs |
| 434 | 434 | */ |
| 435 | - function get_all_rights($location,$appname='') |
|
| 435 | + function get_all_rights($location, $appname = '') |
|
| 436 | 436 | { |
| 437 | 437 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 438 | 438 | |
| 439 | 439 | $rights = array(); |
| 440 | - foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
|
| 440 | + foreach ($this->db->select(self::TABLE, 'acl_account,acl_rights', array( |
|
| 441 | 441 | 'acl_location' => $location, |
| 442 | 442 | 'acl_appname' => $appname, |
| 443 | - ),__LINE__,__FILE__) as $row) |
|
| 443 | + ), __LINE__, __FILE__) as $row) |
|
| 444 | 444 | { |
| 445 | 445 | $rights[$row['acl_account']] = $row['acl_rights']; |
| 446 | 446 | } |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * @param boolean $use_memberships = true |
| 456 | 456 | * @return array with location => rights pairs |
| 457 | 457 | */ |
| 458 | - function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
|
| 458 | + function get_all_location_rights($account_id, $appname = '', $use_memberships = true) |
|
| 459 | 459 | { |
| 460 | 460 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 461 | 461 | |
@@ -466,10 +466,10 @@ discard block |
||
| 466 | 466 | $accounts[] = $account_id; |
| 467 | 467 | } |
| 468 | 468 | $rights = array(); |
| 469 | - foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array( |
|
| 469 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array( |
|
| 470 | 470 | 'acl_account' => $accounts, |
| 471 | 471 | 'acl_appname' => $appname, |
| 472 | - ),__LINE__,__FILE__) as $row) |
|
| 472 | + ), __LINE__, __FILE__) as $row) |
|
| 473 | 473 | { |
| 474 | 474 | $rights[$row['acl_location']] |= $row['acl_rights']; |
| 475 | 475 | } |
@@ -488,28 +488,28 @@ discard block |
||
| 488 | 488 | { |
| 489 | 489 | static $cache_accountid = array(); |
| 490 | 490 | |
| 491 | - if(isset($cache_accountid[$accountid])) |
|
| 491 | + if (isset($cache_accountid[$accountid])) |
|
| 492 | 492 | { |
| 493 | 493 | $account_id = $cache_accountid[$accountid]; |
| 494 | 494 | } |
| 495 | 495 | else |
| 496 | 496 | { |
| 497 | - $account_id = get_account_id($accountid,$this->account_id); |
|
| 497 | + $account_id = get_account_id($accountid, $this->account_id); |
|
| 498 | 498 | $cache_accountid[$accountid] = $account_id; |
| 499 | 499 | } |
| 500 | 500 | $rights = 0; |
| 501 | 501 | $apps = false; |
| 502 | - foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array( |
|
| 502 | + foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array( |
|
| 503 | 503 | 'acl_location' => $location, |
| 504 | 504 | 'acl_account' => $account_id, |
| 505 | - ),__LINE__,__FILE__) as $row) |
|
| 505 | + ), __LINE__, __FILE__) as $row) |
|
| 506 | 506 | { |
| 507 | 507 | if ($row['acl_rights'] == 0) |
| 508 | 508 | { |
| 509 | 509 | return False; |
| 510 | 510 | } |
| 511 | 511 | $rights |= $row['acl_rights']; |
| 512 | - if (!!($rights & $required)) |
|
| 512 | + if (!!($rights&$required)) |
|
| 513 | 513 | { |
| 514 | 514 | $apps[] = $row['acl_appname']; |
| 515 | 515 | } |
@@ -529,21 +529,21 @@ discard block |
||
| 529 | 529 | { |
| 530 | 530 | static $cache_accountid = array(); |
| 531 | 531 | |
| 532 | - if(isset($cache_accountid[$accountid])) |
|
| 532 | + if (isset($cache_accountid[$accountid])) |
|
| 533 | 533 | { |
| 534 | 534 | $accountid = $cache_accountid[$accountid]; |
| 535 | 535 | } |
| 536 | 536 | else |
| 537 | 537 | { |
| 538 | - $accountid = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
|
| 538 | + $accountid = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id); |
|
| 539 | 539 | } |
| 540 | 540 | $locations = false; |
| 541 | - foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array( |
|
| 541 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array( |
|
| 542 | 542 | 'acl_appname' => $app, |
| 543 | 543 | 'acl_account' => $accountid, |
| 544 | - ),__LINE__,__FILE__) as $row) |
|
| 544 | + ), __LINE__, __FILE__) as $row) |
|
| 545 | 545 | { |
| 546 | - if ($row['acl_rights'] & $required) |
|
| 546 | + if ($row['acl_rights']&$required) |
|
| 547 | 547 | { |
| 548 | 548 | $locations[] = $row['acl_location']; |
| 549 | 549 | } |
@@ -564,14 +564,14 @@ discard block |
||
| 564 | 564 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 565 | 565 | |
| 566 | 566 | $accounts = false; |
| 567 | - foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
|
| 567 | + foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights'), array( |
|
| 568 | 568 | 'acl_appname' => $app, |
| 569 | 569 | 'acl_location' => $location, |
| 570 | - ),__LINE__,__FILE__) as $row) |
|
| 570 | + ), __LINE__, __FILE__) as $row) |
|
| 571 | 571 | { |
| 572 | - if (!!($row['acl_rights'] & $required)) |
|
| 572 | + if (!!($row['acl_rights']&$required)) |
|
| 573 | 573 | { |
| 574 | - $accounts[] = (int) $row['acl_account']; |
|
| 574 | + $accounts[] = (int)$row['acl_account']; |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | return $accounts; |
@@ -583,14 +583,14 @@ discard block |
||
| 583 | 583 | * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
| 584 | 584 | * @return boolean/array false if there are no matching location in the db or array of locations |
| 585 | 585 | */ |
| 586 | - function get_locations_for_app($app='') |
|
| 586 | + function get_locations_for_app($app = '') |
|
| 587 | 587 | { |
| 588 | 588 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 589 | 589 | |
| 590 | 590 | $locations = false; |
| 591 | - foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
|
| 591 | + foreach ($this->db->select(self::TABLE, 'DISTINCT '.'acl_location', array( |
|
| 592 | 592 | 'acl_appname' => $app, |
| 593 | - ),__LINE__,__FILE__) as $row) |
|
| 593 | + ), __LINE__, __FILE__) as $row) |
|
| 594 | 594 | { |
| 595 | 595 | if (($location = $row['acl_location']) != 'run') |
| 596 | 596 | { |
@@ -608,38 +608,38 @@ discard block |
||
| 608 | 608 | * @param boolean $add_implicit_apps = true true: add apps every user has implicit rights |
| 609 | 609 | * @return array containing list of apps |
| 610 | 610 | */ |
| 611 | - function get_user_applications($accountid = '', $use_memberships=true, $add_implicit_apps=true) |
|
| 611 | + function get_user_applications($accountid = '', $use_memberships = true, $add_implicit_apps = true) |
|
| 612 | 612 | { |
| 613 | 613 | static $cache_accountid = array(); |
| 614 | 614 | |
| 615 | - if(isset($cache_accountid[$accountid])) |
|
| 615 | + if (isset($cache_accountid[$accountid])) |
|
| 616 | 616 | { |
| 617 | 617 | $account_id = $cache_accountid[$accountid]; |
| 618 | 618 | } |
| 619 | 619 | else |
| 620 | 620 | { |
| 621 | - $account_id = get_account_id($accountid,$this->account_id); |
|
| 621 | + $account_id = get_account_id($accountid, $this->account_id); |
|
| 622 | 622 | $cache_accountid[$accountid] = $account_id; |
| 623 | 623 | } |
| 624 | 624 | if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
| 625 | 625 | $memberships[] = (int)$account_id; |
| 626 | 626 | |
| 627 | 627 | $apps = array(); |
| 628 | - foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array( |
|
| 628 | + foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array( |
|
| 629 | 629 | 'acl_location' => 'run', |
| 630 | 630 | 'acl_account' => $memberships, |
| 631 | - ),__LINE__,__FILE__) as $row) |
|
| 631 | + ), __LINE__, __FILE__) as $row) |
|
| 632 | 632 | { |
| 633 | 633 | $app = $row['acl_appname']; |
| 634 | - if(!isset($apps[$app])) |
|
| 634 | + if (!isset($apps[$app])) |
|
| 635 | 635 | { |
| 636 | 636 | $apps[$app] = 0; |
| 637 | 637 | } |
| 638 | - $apps[$app] |= (int) $row['acl_rights']; |
|
| 638 | + $apps[$app] |= (int)$row['acl_rights']; |
|
| 639 | 639 | } |
| 640 | 640 | if ($add_implicit_apps) |
| 641 | 641 | { |
| 642 | - $apps['api'] = 1; // give everyone implicit rights for the home app |
|
| 642 | + $apps['api'] = 1; // give everyone implicit rights for the home app |
|
| 643 | 643 | } |
| 644 | 644 | return $apps; |
| 645 | 645 | } |
@@ -653,29 +653,29 @@ discard block |
||
| 653 | 653 | * @param int $user = null user whos grants to return, default current user |
| 654 | 654 | * @return array with account-ids (of owners) and granted rights as values |
| 655 | 655 | */ |
| 656 | - function get_grants($app='',$enum_group_acls=true,$user=null) |
|
| 656 | + function get_grants($app = '', $enum_group_acls = true, $user = null) |
|
| 657 | 657 | { |
| 658 | 658 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 659 | 659 | if (!$user) $user = $this->account_id; |
| 660 | 660 | |
| 661 | - static $cache = array(); // some caching withing the request |
|
| 661 | + static $cache = array(); // some caching withing the request |
|
| 662 | 662 | |
| 663 | - $grants =& $cache[$app][$user]; |
|
| 663 | + $grants = & $cache[$app][$user]; |
|
| 664 | 664 | if (!isset($grants)) |
| 665 | 665 | { |
| 666 | 666 | if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
| 667 | 667 | $memberships[] = $user; |
| 668 | 668 | |
| 669 | 669 | $grants = $accounts = Array(); |
| 670 | - foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array( |
|
| 670 | + foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights', 'acl_location'), array( |
|
| 671 | 671 | 'acl_appname' => $app, |
| 672 | 672 | 'acl_location' => $memberships, |
| 673 | - ),__LINE__,__FILE__) as $row) |
|
| 673 | + ), __LINE__, __FILE__) as $row) |
|
| 674 | 674 | { |
| 675 | 675 | $grantor = $row['acl_account']; |
| 676 | 676 | $rights = $row['acl_rights']; |
| 677 | 677 | |
| 678 | - if(!isset($grants[$grantor])) |
|
| 678 | + if (!isset($grants[$grantor])) |
|
| 679 | 679 | { |
| 680 | 680 | $grants[$grantor] = 0; |
| 681 | 681 | } |
@@ -683,17 +683,17 @@ discard block |
||
| 683 | 683 | |
| 684 | 684 | // if the right is granted from a group and we enummerated group ACL's |
| 685 | 685 | if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls && |
| 686 | - (!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls))) |
|
| 686 | + (!is_array($enum_group_acls) || !in_array($grantor, $enum_group_acls))) |
|
| 687 | 687 | { |
| 688 | 688 | // return the grant for each member of the group (false = also for no longer active users) |
| 689 | - foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
|
| 689 | + foreach ((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
|
| 690 | 690 | { |
| 691 | - if (!$grantor) continue; // can happen if group has no members |
|
| 691 | + if (!$grantor) continue; // can happen if group has no members |
|
| 692 | 692 | |
| 693 | 693 | // Don't allow to override private with group ACL's! |
| 694 | 694 | $rights &= ~self::PRIVAT; |
| 695 | 695 | |
| 696 | - if(!isset($grants[$grantor])) |
|
| 696 | + if (!isset($grants[$grantor])) |
|
| 697 | 697 | { |
| 698 | 698 | $grants[$grantor] = 0; |
| 699 | 699 | } |
@@ -715,21 +715,21 @@ discard block |
||
| 715 | 715 | */ |
| 716 | 716 | function delete_account($account_id) |
| 717 | 717 | { |
| 718 | - if ((int) $account_id) |
|
| 718 | + if ((int)$account_id) |
|
| 719 | 719 | { |
| 720 | 720 | // Delete all grants from this account |
| 721 | - $this->db->delete(self::TABLE,array( |
|
| 721 | + $this->db->delete(self::TABLE, array( |
|
| 722 | 722 | 'acl_account' => $account_id |
| 723 | - ),__LINE__,__FILE__); |
|
| 723 | + ), __LINE__, __FILE__); |
|
| 724 | 724 | // Delete all grants to this account |
| 725 | - $this->db->delete(self::TABLE,array( |
|
| 725 | + $this->db->delete(self::TABLE, array( |
|
| 726 | 726 | 'acl_location' => $account_id |
| 727 | - ),__LINE__, __FILE__); |
|
| 727 | + ), __LINE__, __FILE__); |
|
| 728 | 728 | // delete all memberships in account_id (if it is a group) |
| 729 | - $this->db->delete(self::TABLE,array( |
|
| 729 | + $this->db->delete(self::TABLE, array( |
|
| 730 | 730 | 'acl_appname' => 'phpgw_group', |
| 731 | 731 | 'acl_location' => $account_id, |
| 732 | - ),__LINE__,__FILE__); |
|
| 732 | + ), __LINE__, __FILE__); |
|
| 733 | 733 | } |
| 734 | 734 | } |
| 735 | 735 | |
@@ -740,15 +740,15 @@ discard block |
||
| 740 | 740 | * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
| 741 | 741 | * @return array with location => array(account => rights) pairs |
| 742 | 742 | */ |
| 743 | - function get_location_grants($location,$app='') |
|
| 743 | + function get_location_grants($location, $app = '') |
|
| 744 | 744 | { |
| 745 | 745 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 746 | 746 | |
| 747 | 747 | $locations = array(); |
| 748 | - foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
|
| 748 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_account,acl_rights', array( |
|
| 749 | 749 | 'acl_appname' => $app, |
| 750 | 750 | 'acl_location LIKE '.$this->db->quote($location), |
| 751 | - ),__LINE__,__FILE__) as $row) |
|
| 751 | + ), __LINE__, __FILE__) as $row) |
|
| 752 | 752 | { |
| 753 | 753 | if (($location = $row['acl_location']) != 'run') |
| 754 | 754 | { |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * cancels a timer |
| 325 | 325 | * |
| 326 | 326 | * @param string $id has to be the one used to set it. |
| 327 | - * @return boolean True if the timer exists and is not expired. |
|
| 327 | + * @return integer True if the timer exists and is not expired. |
|
| 328 | 328 | */ |
| 329 | 329 | function cancel_timer($id) |
| 330 | 330 | { |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | /** |
| 471 | 471 | * reads all matching db-rows / jobs |
| 472 | 472 | * |
| 473 | - * @param string $id =0 reads all expired rows / jobs ready to run\ |
|
| 473 | + * @param integer $id =0 reads all expired rows / jobs ready to run\ |
|
| 474 | 474 | * != 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used) |
| 475 | 475 | * @param array|string $cols ='*' string or array of column-names / select-expressions |
| 476 | 476 | * @param int|bool $offset =False offset for a limited query or False (default) |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | /** |
| 559 | 559 | * delete db-row / job with $id |
| 560 | 560 | * |
| 561 | - * @return boolean False if $id not found else True |
|
| 561 | + * @return integer False if $id not found else True |
|
| 562 | 562 | */ |
| 563 | 563 | function delete($id) |
| 564 | 564 | { |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $this->db = $GLOBALS['egw_setup']->db; |
| 51 | 51 | } |
| 52 | - $this->cronline = EGW_SERVER_ROOT . '/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
| 52 | + $this->cronline = EGW_SERVER_ROOT.'/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
| 53 | 53 | |
| 54 | - $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
| 54 | + $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -71,10 +71,10 @@ discard block |
||
| 71 | 71 | * @param boolean $debug =false |
| 72 | 72 | * @return boolean False if $id already exists, else True |
| 73 | 73 | */ |
| 74 | - function set_timer($times,$id,$method,$data=null,$account_id=False,$debug=false) |
|
| 74 | + function set_timer($times, $id, $method, $data = null, $account_id = False, $debug = false) |
|
| 75 | 75 | { |
| 76 | 76 | if (empty($id) || empty($method) || $this->read($id) || |
| 77 | - !($next = $this->next_run($times,$debug))) |
|
| 77 | + !($next = $this->next_run($times, $debug))) |
|
| 78 | 78 | { |
| 79 | 79 | return False; |
| 80 | 80 | } |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | * @param int $now Use this time to calculate then next run from. Defaults to time(). |
| 108 | 108 | * @return int a unix timestamp of the next execution time or False if no more executions |
| 109 | 109 | */ |
| 110 | - function next_run($times,$debug=False, $now = null) |
|
| 110 | + function next_run($times, $debug = False, $now = null) |
|
| 111 | 111 | { |
| 112 | 112 | if ($this->debug) |
| 113 | 113 | { |
| 114 | - echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
|
| 115 | - $debug = True; // enable syntax-error messages too |
|
| 114 | + echo "<p>next_run("; print_r($times); echo ",'$debug', ".date('Y-m-d H:i', $now).")</p>\n"; |
|
| 115 | + $debug = True; // enable syntax-error messages too |
|
| 116 | 116 | } |
| 117 | - if(is_null($now)) { |
|
| 117 | + if (is_null($now)) { |
|
| 118 | 118 | $now = time(); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | 'dow' => 6, |
| 143 | 143 | 'day' => 31, |
| 144 | 144 | 'month' => 12, |
| 145 | - 'year' => date('Y')+10 // else */[0-9] would never stop returning numbers |
|
| 145 | + 'year' => date('Y') + 10 // else */[0-9] would never stop returning numbers |
|
| 146 | 146 | ); |
| 147 | 147 | $min_unit = array( |
| 148 | 148 | 'min' => 0, |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | // get set to the minimum after |
| 159 | 159 | // |
| 160 | 160 | $i = $first_set = $last_set = 0; |
| 161 | - foreach($units as $u => $date_pattern) |
|
| 161 | + foreach ($units as $u => $date_pattern) |
|
| 162 | 162 | { |
| 163 | 163 | ++$i; |
| 164 | 164 | if (isset($times[$u])) |
@@ -176,24 +176,24 @@ discard block |
||
| 176 | 176 | // (as descript above), enumerations are arrays with unit-values as keys |
| 177 | 177 | // |
| 178 | 178 | $n = 0; |
| 179 | - foreach($units as $u => $date_pattern) |
|
| 179 | + foreach ($units as $u => $date_pattern) |
|
| 180 | 180 | { |
| 181 | 181 | ++$n; |
| 182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
| 182 | + if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u]) ? 'True' : 'False')."</p>\n"; } |
|
| 183 | 183 | if (isset($times[$u])) |
| 184 | 184 | { |
| 185 | - if(is_array($times[$u])) { |
|
| 185 | + if (is_array($times[$u])) { |
|
| 186 | 186 | $time = array_keys($times[$u]); |
| 187 | 187 | } else { |
| 188 | - $time = explode(',',$times[$u]); |
|
| 188 | + $time = explode(',', $times[$u]); |
|
| 189 | 189 | } |
| 190 | 190 | $times[$u] = array(); |
| 191 | 191 | |
| 192 | - foreach($time as $t) |
|
| 192 | + foreach ($time as $t) |
|
| 193 | 193 | { |
| 194 | - if (strpos($t,'-') !== False && strpos($t,'/') === False) |
|
| 194 | + if (strpos($t, '-') !== False && strpos($t, '/') === False) |
|
| 195 | 195 | { |
| 196 | - list($min,$max) = $arr = explode('-',$t); |
|
| 196 | + list($min, $max) = $arr = explode('-', $t); |
|
| 197 | 197 | |
| 198 | 198 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
| 199 | 199 | { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | if ((string)$t == '*') $t = '*/1'; |
| 212 | 212 | |
| 213 | - list($one,$inc) = $arr = explode('/',$t); |
|
| 213 | + list($one, $inc) = $arr = explode('/', $t); |
|
| 214 | 214 | |
| 215 | 215 | if (!(is_numeric($one) && count($arr) == 1 || |
| 216 | 216 | count($arr) == 2 && is_numeric($inc))) |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | else |
| 227 | 227 | { |
| 228 | - list($min,$max) = $arr = explode('-',$one); |
|
| 228 | + list($min, $max) = $arr = explode('-', $one); |
|
| 229 | 229 | if (empty($one) || $one == '*') |
| 230 | 230 | { |
| 231 | 231 | $min = $min_unit[$u]; |
@@ -266,20 +266,19 @@ discard block |
||
| 266 | 266 | { |
| 267 | 267 | $future = False; |
| 268 | 268 | |
| 269 | - foreach($units as $u => $date_pattern) |
|
| 269 | + foreach ($units as $u => $date_pattern) |
|
| 270 | 270 | { |
| 271 | - $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : |
|
| 272 | - (int)date($date_pattern,mktime(12,0,0,$found['month'],$found['day'],$found['year'])); |
|
| 271 | + $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : (int)date($date_pattern, mktime(12, 0, 0, $found['month'], $found['day'], $found['year'])); |
|
| 273 | 272 | |
| 274 | 273 | if (isset($found[$u])) |
| 275 | 274 | { |
| 276 | 275 | $future = $future || $found[$u] > $unit_now; |
| 277 | 276 | if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
| 278 | - continue; // already set |
|
| 277 | + continue; // already set |
|
| 279 | 278 | } |
| 280 | - foreach(array_keys($times[$u]) as $unit_value) |
|
| 279 | + foreach (array_keys($times[$u]) as $unit_value) |
|
| 281 | 280 | { |
| 282 | - switch($u) |
|
| 281 | + switch ($u) |
|
| 283 | 282 | { |
| 284 | 283 | case 'dow': |
| 285 | 284 | $valid = $unit_value == $unit_now; |
@@ -302,12 +301,12 @@ discard block |
||
| 302 | 301 | if (!isset($found[$u])) // we have to try the next one, if it exists |
| 303 | 302 | { |
| 304 | 303 | $nexts = array_keys($units); |
| 305 | - if (!isset($nexts[count($found)-1])) |
|
| 304 | + if (!isset($nexts[count($found) - 1])) |
|
| 306 | 305 | { |
| 307 | 306 | if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
| 308 | 307 | return False; |
| 309 | 308 | } |
| 310 | - $next = $nexts[count($found)-1]; |
|
| 309 | + $next = $nexts[count($found) - 1]; |
|
| 311 | 310 | $over = $found[$next]; |
| 312 | 311 | unset($found[$next]); |
| 313 | 312 | if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
@@ -317,7 +316,7 @@ discard block |
||
| 317 | 316 | } |
| 318 | 317 | if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
| 319 | 318 | |
| 320 | - return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
|
| 319 | + return mktime($found['hour'], $found['min'], 0, $found['month'], $found['day'], $found['year']); |
|
| 321 | 320 | } |
| 322 | 321 | |
| 323 | 322 | /** |
@@ -339,7 +338,7 @@ discard block |
||
| 339 | 338 | * @return mixed if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end, \ |
| 340 | 339 | * !$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False |
| 341 | 340 | */ |
| 342 | - function last_check_run($semaphore=False,$release=False,$run_by='') |
|
| 341 | + function last_check_run($semaphore = False, $release = False, $run_by = '') |
|
| 343 | 342 | { |
| 344 | 343 | //echo "<p>last_check_run(semaphore=".($semaphore?'True':'False').",release=".($release?'True':'False').")</p>\n"; |
| 345 | 344 | if (($exists = $this->read('##last-check-run##'))) |
@@ -361,7 +360,7 @@ discard block |
||
| 361 | 360 | } |
| 362 | 361 | else |
| 363 | 362 | { |
| 364 | - @set_time_limit(0); // dont stop for an execution-time-limit |
|
| 363 | + @set_time_limit(0); // dont stop for an execution-time-limit |
|
| 365 | 364 | ignore_user_abort(True); |
| 366 | 365 | |
| 367 | 366 | $last_run = array( |
@@ -377,7 +376,7 @@ discard block |
||
| 377 | 376 | ); |
| 378 | 377 | // as the async_next column is used as a semaphore we only update it, |
| 379 | 378 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
| 380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
| 379 | + if ($exists) $where = array('async_next=0 OR async_next<'.(time() - 600)); |
|
| 381 | 380 | } |
| 382 | 381 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
| 383 | 382 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -386,20 +385,20 @@ discard block |
||
| 386 | 385 | /** |
| 387 | 386 | * checks if there are any jobs ready to run (timer expired) and executes them |
| 388 | 387 | */ |
| 389 | - function check_run($run_by='') |
|
| 388 | + function check_run($run_by = '') |
|
| 390 | 389 | { |
| 391 | 390 | if ($run_by === 'fallback') flush(); |
| 392 | 391 | |
| 393 | - if (!$this->last_check_run(True,False,$run_by)) |
|
| 392 | + if (!$this->last_check_run(True, False, $run_by)) |
|
| 394 | 393 | { |
| 395 | - return False; // cant obtain semaphore |
|
| 394 | + return False; // cant obtain semaphore |
|
| 396 | 395 | } |
| 397 | 396 | // mark enviroment as async-service, check with isset()! |
| 398 | 397 | $GLOBALS['egw_info']['flags']['async-service'] = $run_by; |
| 399 | 398 | |
| 400 | 399 | if (($jobs = $this->read())) |
| 401 | 400 | { |
| 402 | - foreach($jobs as $job) |
|
| 401 | + foreach ($jobs as $job) |
|
| 403 | 402 | { |
| 404 | 403 | // checking / setting up egw_info/user |
| 405 | 404 | // |
@@ -408,7 +407,7 @@ discard block |
||
| 408 | 407 | // run notifications, before changing account_id of enviroment |
| 409 | 408 | Link::run_notifies(); |
| 410 | 409 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
| 411 | - foreach($GLOBALS as $name => $value) |
|
| 410 | + foreach ($GLOBALS as $name => $value) |
|
| 412 | 411 | { |
| 413 | 412 | if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
| 414 | 413 | } |
@@ -420,7 +419,7 @@ discard block |
||
| 420 | 419 | { |
| 421 | 420 | $GLOBALS['egw']->session->account_lid = $GLOBALS['egw']->accounts->id2name($job['account_id']); |
| 422 | 421 | $GLOBALS['egw']->session->account_domain = $domain; |
| 423 | - $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
| 422 | + $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
| 424 | 423 | |
| 425 | 424 | if ($lang != $GLOBALS['egw_info']['user']['preferences']['common']['lang']) |
| 426 | 425 | { |
@@ -435,12 +434,11 @@ discard block |
||
| 435 | 434 | $GLOBALS['egw_info']['user']['domain'] = $domain; |
| 436 | 435 | } |
| 437 | 436 | } |
| 438 | - list($app) = strpos($job['method'],'::') !== false ? explode('_',$job['method']) : |
|
| 439 | - explode('.',$job['method']); |
|
| 437 | + list($app) = strpos($job['method'], '::') !== false ? explode('_', $job['method']) : explode('.', $job['method']); |
|
| 440 | 438 | Translation::add_app($app); |
| 441 | 439 | if (is_array($job['data'])) |
| 442 | 440 | { |
| 443 | - $job['data'] += array_diff_key($job,array('data' => false)); |
|
| 441 | + $job['data'] += array_diff_key($job, array('data' => false)); |
|
| 444 | 442 | } |
| 445 | 443 | // update job before running it, to cope with jobs taking longer then async-frequency |
| 446 | 444 | if (($job['next'] = $this->next_run($job['times']))) |
@@ -453,16 +451,16 @@ discard block |
||
| 453 | 451 | } |
| 454 | 452 | try |
| 455 | 453 | { |
| 456 | - ExecMethod($job['method'],$job['data']); |
|
| 454 | + ExecMethod($job['method'], $job['data']); |
|
| 457 | 455 | } |
| 458 | - catch(Exception $e) |
|
| 456 | + catch (Exception $e) |
|
| 459 | 457 | { |
| 460 | 458 | // log the exception to error_log, but continue running other async jobs |
| 461 | 459 | _egw_log_exception($e); |
| 462 | 460 | } |
| 463 | 461 | } |
| 464 | 462 | } |
| 465 | - $this->last_check_run(True,True,$run_by); // release semaphore |
|
| 463 | + $this->last_check_run(True, True, $run_by); // release semaphore |
|
| 466 | 464 | |
| 467 | 465 | return $jobs ? count($jobs) : 0; |
| 468 | 466 | } |
@@ -478,7 +476,7 @@ discard block |
||
| 478 | 476 | * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs |
| 479 | 477 | * @return array/boolean db-rows / jobs as array or False if no matches |
| 480 | 478 | */ |
| 481 | - function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
|
| 479 | + function read($id = 0, $cols = '*', $offset = False, $append = 'ORDER BY async_next', $num_rows = 0) |
|
| 482 | 480 | { |
| 483 | 481 | if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
| 484 | 482 | |
@@ -486,7 +484,7 @@ discard block |
||
| 486 | 484 | { |
| 487 | 485 | $where = "async_id != '##last-check-run##'"; |
| 488 | 486 | } |
| 489 | - elseif (!is_array($id) && (strpos($id,'%') !== False || strpos($id,'_') !== False)) |
|
| 487 | + elseif (!is_array($id) && (strpos($id, '%') !== False || strpos($id, '_') !== False)) |
|
| 490 | 488 | { |
| 491 | 489 | $id = $this->db->quote($id); |
| 492 | 490 | $where = "async_id LIKE $id AND async_id != '##last-check-run##'"; |
@@ -500,21 +498,21 @@ discard block |
||
| 500 | 498 | $where = array('async_id' => $id); |
| 501 | 499 | } |
| 502 | 500 | $jobs = array(); |
| 503 | - foreach($this->db->select($this->db_table,$cols,$where,__LINE__,__FILE__,$offset,$append,False,$num_rows) as $row) |
|
| 501 | + foreach ($this->db->select($this->db_table, $cols, $where, __LINE__, __FILE__, $offset, $append, False, $num_rows) as $row) |
|
| 504 | 502 | { |
| 505 | 503 | $row['async_times'] = json_php_unserialize($row['async_times']); |
| 506 | 504 | // check for broken value during migration |
| 507 | 505 | if ($row['async_data'][0] == '"' && substr($row['async_data'], 0, 7) == '"\\"\\\\\\"') |
| 508 | 506 | { |
| 509 | 507 | $row['async_data'] = null; |
| 510 | - $this->write(Db::strip_array_keys($row,'async_'), true); |
|
| 508 | + $this->write(Db::strip_array_keys($row, 'async_'), true); |
|
| 511 | 509 | } |
| 512 | 510 | else |
| 513 | 511 | { |
| 514 | 512 | $row['async_data'] = !empty($row['async_data']) ? |
| 515 | - json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
| 513 | + json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
| 516 | 514 | } |
| 517 | - $jobs[$row['async_id']] = Db::strip_array_keys($row,'async_'); |
|
| 515 | + $jobs[$row['async_id']] = Db::strip_array_keys($row, 'async_'); |
|
| 518 | 516 | } |
| 519 | 517 | if (!count($jobs)) |
| 520 | 518 | { |
@@ -531,7 +529,7 @@ discard block |
||
| 531 | 529 | * @param array $where additional where statemetn to update only if a certain condition is met, used for the semaphore |
| 532 | 530 | * @return int affected rows, can be 0 if an additional where statement is given |
| 533 | 531 | */ |
| 534 | - function write($job, $exists = False, $where=array()) |
|
| 532 | + function write($job, $exists = False, $where = array()) |
|
| 535 | 533 | { |
| 536 | 534 | if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
| 537 | 535 | |
@@ -562,7 +560,7 @@ discard block |
||
| 562 | 560 | */ |
| 563 | 561 | function delete($id) |
| 564 | 562 | { |
| 565 | - $this->db->delete($this->db_table,array('async_id' => $id),__LINE__,__FILE__); |
|
| 563 | + $this->db->delete($this->db_table, array('async_id' => $id), __LINE__, __FILE__); |
|
| 566 | 564 | |
| 567 | 565 | return $this->db->affected_rows(); |
| 568 | 566 | } |
@@ -587,38 +585,38 @@ discard block |
||
| 587 | 585 | { |
| 588 | 586 | $binarys = array( |
| 589 | 587 | 'php' => '/usr/bin/php', |
| 590 | - 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
| 588 | + 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
| 591 | 589 | 'crontab' => '/usr/bin/crontab' |
| 592 | 590 | ); |
| 593 | 591 | foreach ($binarys as $name => $path) |
| 594 | 592 | { |
| 595 | - $this->$name = $path; // a reasonable default for *nix |
|
| 593 | + $this->$name = $path; // a reasonable default for *nix |
|
| 596 | 594 | |
| 597 | 595 | if (!($Ok = @is_executable($this->$name))) |
| 598 | 596 | { |
| 599 | 597 | if (file_exists($this->$name)) |
| 600 | 598 | { |
| 601 | - echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
|
| 599 | + echo '<p>'.lang('%1 is not executable by the webserver !!!', $this->$name)."</p>\n"; |
|
| 602 | 600 | $perms = fileperms($this->$name); |
| 603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 601 | + if (!($perms&0x0001) && ($perms&0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 604 | 602 | { |
| 605 | 603 | $group = posix_getgrgid(filegroup($this->$name)); |
| 606 | - $webserver = posix_getpwuid(posix_getuid ()); |
|
| 607 | - echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
|
| 604 | + $webserver = posix_getpwuid(posix_getuid()); |
|
| 605 | + echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.", $webserver['name'], $group['name'])."</p>\n"; } |
|
| 608 | 606 | } |
| 609 | - if (($fd = popen('/bin/sh -c "type -p '.$name.'"','r'))) |
|
| 607 | + if (($fd = popen('/bin/sh -c "type -p '.$name.'"', 'r'))) |
|
| 610 | 608 | { |
| 611 | - $this->$name = fgets($fd,256); |
|
| 609 | + $this->$name = fgets($fd, 256); |
|
| 612 | 610 | @pclose($fd); |
| 613 | 611 | } |
| 614 | - if (($pos = strpos($this->$name,"\n"))) |
|
| 612 | + if (($pos = strpos($this->$name, "\n"))) |
|
| 615 | 613 | { |
| 616 | - $this->$name = substr($this->$name,0,$pos); |
|
| 614 | + $this->$name = substr($this->$name, 0, $pos); |
|
| 617 | 615 | } |
| 618 | 616 | } |
| 619 | 617 | if (!$Ok && !@is_executable($this->$name)) |
| 620 | 618 | { |
| 621 | - $this->$name = $name; // hopefully its in the path |
|
| 619 | + $this->$name = $name; // hopefully its in the path |
|
| 622 | 620 | } |
| 623 | 621 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
| 624 | 622 | } |
@@ -649,15 +647,15 @@ discard block |
||
| 649 | 647 | } |
| 650 | 648 | $times = False; |
| 651 | 649 | $this->other_cronlines = array(); |
| 652 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1','r')) !== False) |
|
| 650 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1', 'r')) !== False) |
|
| 653 | 651 | { |
| 654 | 652 | $n = 0; |
| 655 | - while ($line = fgets($crontab,256)) |
|
| 653 | + while ($line = fgets($crontab, 256)) |
|
| 656 | 654 | { |
| 657 | 655 | if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
| 658 | - $parts = explode(' ',$line,6); |
|
| 656 | + $parts = explode(' ', $line, 6); |
|
| 659 | 657 | |
| 660 | - if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
|
| 658 | + if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5], 0, 3) != 'php')) |
|
| 661 | 659 | { |
| 662 | 660 | // ignore comments |
| 663 | 661 | if ($line{0} != '#') |
@@ -665,12 +663,12 @@ discard block |
||
| 665 | 663 | $times['error'] .= $line; |
| 666 | 664 | } |
| 667 | 665 | } |
| 668 | - elseif (strpos($line,$this->cronline) !== False || |
|
| 666 | + elseif (strpos($line, $this->cronline) !== False || |
|
| 669 | 667 | // also check of old phpgwapi/cron path |
| 670 | 668 | strpos($line, str_replace('/api/', '/phpgwapi/cron/', $this->cronline)) !== False) |
| 671 | 669 | { |
| 672 | - $cron_units = array('min','hour','day','month','dow'); |
|
| 673 | - foreach($cron_units as $n => $u) |
|
| 670 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
| 671 | + foreach ($cron_units as $n => $u) |
|
| 674 | 672 | { |
| 675 | 673 | $times[$u] = $parts[$n]; |
| 676 | 674 | } |
@@ -701,29 +699,29 @@ discard block |
||
| 701 | 699 | if ($this->only_fallback && $times !== False) { |
| 702 | 700 | return 0; |
| 703 | 701 | } |
| 704 | - $this->installed(); // find other installed cronlines |
|
| 702 | + $this->installed(); // find other installed cronlines |
|
| 705 | 703 | |
| 706 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1','w')) !== False) |
|
| 704 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1', 'w')) !== False) |
|
| 707 | 705 | { |
| 708 | 706 | if (is_array($this->other_cronlines)) |
| 709 | 707 | { |
| 710 | 708 | foreach ($this->other_cronlines as $cronline) |
| 711 | 709 | { |
| 712 | - fwrite($crontab,$cronline); // preserv the other lines on install |
|
| 710 | + fwrite($crontab, $cronline); // preserv the other lines on install |
|
| 713 | 711 | } |
| 714 | 712 | } |
| 715 | 713 | if ($times !== False) |
| 716 | 714 | { |
| 717 | - $cron_units = array('min','hour','day','month','dow'); |
|
| 715 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
| 718 | 716 | $cronline = ''; |
| 719 | - foreach($cron_units as $cu) |
|
| 717 | + foreach ($cron_units as $cu) |
|
| 720 | 718 | { |
| 721 | - $cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' '; |
|
| 719 | + $cronline .= (isset($times[$cu]) ? $times[$cu] : '*').' '; |
|
| 722 | 720 | } |
| 723 | 721 | // -d memory_limit=-1 --> no memory limit |
| 724 | 722 | $cronline .= $this->php.' -q -d memory_limit=-1 '.$this->cronline."\n"; |
| 725 | 723 | //echo "<p>Installing: '$cronline'</p>\n"; |
| 726 | - fwrite($crontab,$cronline); |
|
| 724 | + fwrite($crontab, $cronline); |
|
| 727 | 725 | } |
| 728 | 726 | @pclose($crontab); |
| 729 | 727 | } |
@@ -114,7 +114,8 @@ discard block |
||
| 114 | 114 | echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
| 115 | 115 | $debug = True; // enable syntax-error messages too |
| 116 | 116 | } |
| 117 | - if(is_null($now)) { |
|
| 117 | + if(is_null($now)) |
|
| 118 | + { |
|
| 118 | 119 | $now = time(); |
| 119 | 120 | } |
| 120 | 121 | |
@@ -179,12 +180,17 @@ discard block |
||
| 179 | 180 | foreach($units as $u => $date_pattern) |
| 180 | 181 | { |
| 181 | 182 | ++$n; |
| 182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
| 183 | + if ($this->debug) |
|
| 184 | + { |
|
| 185 | +echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
| 183 | 186 | if (isset($times[$u])) |
| 184 | 187 | { |
| 185 | - if(is_array($times[$u])) { |
|
| 188 | + if(is_array($times[$u])) |
|
| 189 | + { |
|
| 186 | 190 | $time = array_keys($times[$u]); |
| 187 | - } else { |
|
| 191 | + } |
|
| 192 | + else |
|
| 193 | + { |
|
| 188 | 194 | $time = explode(',',$times[$u]); |
| 189 | 195 | } |
| 190 | 196 | $times[$u] = array(); |
@@ -197,7 +203,10 @@ discard block |
||
| 197 | 203 | |
| 198 | 204 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
| 199 | 205 | { |
| 200 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
| 206 | + if ($debug) |
|
| 207 | + { |
|
| 208 | + echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
| 209 | + } |
|
| 201 | 210 | |
| 202 | 211 | return False; |
| 203 | 212 | } |
@@ -208,14 +217,20 @@ discard block |
||
| 208 | 217 | } |
| 209 | 218 | else |
| 210 | 219 | { |
| 211 | - if ((string)$t == '*') $t = '*/1'; |
|
| 220 | + if ((string)$t == '*') |
|
| 221 | + { |
|
| 222 | + $t = '*/1'; |
|
| 223 | + } |
|
| 212 | 224 | |
| 213 | 225 | list($one,$inc) = $arr = explode('/',$t); |
| 214 | 226 | |
| 215 | 227 | if (!(is_numeric($one) && count($arr) == 1 || |
| 216 | 228 | count($arr) == 2 && is_numeric($inc))) |
| 217 | 229 | { |
| 218 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
| 230 | + if ($debug) |
|
| 231 | + { |
|
| 232 | + echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
| 233 | + } |
|
| 219 | 234 | |
| 220 | 235 | return False; |
| 221 | 236 | } |
@@ -233,7 +248,10 @@ discard block |
||
| 233 | 248 | } |
| 234 | 249 | elseif (count($arr) != 2 || $min > $max) |
| 235 | 250 | { |
| 236 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
| 251 | + if ($debug) |
|
| 252 | + { |
|
| 253 | + echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
| 254 | + } |
|
| 237 | 255 | return False; |
| 238 | 256 | } |
| 239 | 257 | for ($i = $min; $i <= $max; $i += $inc) |
@@ -244,9 +262,13 @@ discard block |
||
| 244 | 262 | } |
| 245 | 263 | } |
| 246 | 264 | } |
| 247 | - elseif ($n < $last_set || $u == 'dow') // before last value set (or dow) => empty gets enumerated |
|
| 265 | + elseif ($n < $last_set || $u == 'dow') |
|
| 266 | + { |
|
| 267 | + // before last value set (or dow) => empty gets enumerated |
|
| 248 | 268 | { |
| 249 | - for ($i = $min_unit[$u]; $i <= $max_unit[$u]; ++$i) |
|
| 269 | + for ($i = $min_unit[$u]; |
|
| 270 | + } |
|
| 271 | + $i <= $max_unit[$u]; ++$i) |
|
| 250 | 272 | { |
| 251 | 273 | $times[$u][$i] = True; |
| 252 | 274 | } |
@@ -256,7 +278,9 @@ discard block |
||
| 256 | 278 | $times[$u][$min_unit[$u]] = True; |
| 257 | 279 | } |
| 258 | 280 | } |
| 259 | - if ($this->debug) { echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
| 281 | + if ($this->debug) |
|
| 282 | + { |
|
| 283 | +echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
| 260 | 284 | |
| 261 | 285 | // now we have the times enumerated, lets find the first not expired one |
| 262 | 286 | // |
@@ -274,7 +298,10 @@ discard block |
||
| 274 | 298 | if (isset($found[$u])) |
| 275 | 299 | { |
| 276 | 300 | $future = $future || $found[$u] > $unit_now; |
| 277 | - if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
| 301 | + if ($this->debug) |
|
| 302 | + { |
|
| 303 | + echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
| 304 | + } |
|
| 278 | 305 | continue; // already set |
| 279 | 306 | } |
| 280 | 307 | foreach(array_keys($times[$u]) as $unit_value) |
@@ -292,30 +319,44 @@ discard block |
||
| 292 | 319 | break; |
| 293 | 320 | |
| 294 | 321 | } |
| 295 | - if ($valid && ($u != $next || $unit_value > $over)) // valid and not over |
|
| 322 | + if ($valid && ($u != $next || $unit_value > $over)) |
|
| 323 | + { |
|
| 324 | + // valid and not over |
|
| 296 | 325 | { |
| 297 | 326 | $found[$u] = $unit_value; |
| 327 | + } |
|
| 298 | 328 | $future = $future || $unit_value > $unit_now; |
| 299 | 329 | break; |
| 300 | 330 | } |
| 301 | 331 | } |
| 302 | - if (!isset($found[$u])) // we have to try the next one, if it exists |
|
| 332 | + if (!isset($found[$u])) |
|
| 333 | + { |
|
| 334 | + // we have to try the next one, if it exists |
|
| 303 | 335 | { |
| 304 | 336 | $nexts = array_keys($units); |
| 337 | + } |
|
| 305 | 338 | if (!isset($nexts[count($found)-1])) |
| 306 | 339 | { |
| 307 | - if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
|
| 340 | + if ($this->debug) |
|
| 341 | + { |
|
| 342 | + echo "<p>Nothing found, exiting !!!</p>\n"; |
|
| 343 | + } |
|
| 308 | 344 | return False; |
| 309 | 345 | } |
| 310 | 346 | $next = $nexts[count($found)-1]; |
| 311 | 347 | $over = $found[$next]; |
| 312 | 348 | unset($found[$next]); |
| 313 | - if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
| 349 | + if ($this->debug) |
|
| 350 | + { |
|
| 351 | + echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
| 352 | + } |
|
| 314 | 353 | break; |
| 315 | 354 | } |
| 316 | 355 | } |
| 317 | 356 | } |
| 318 | - if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
| 357 | + if ($this->debug) |
|
| 358 | + { |
|
| 359 | +echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
| 319 | 360 | |
| 320 | 361 | return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
| 321 | 362 | } |
@@ -377,7 +418,10 @@ discard block |
||
| 377 | 418 | ); |
| 378 | 419 | // as the async_next column is used as a semaphore we only update it, |
| 379 | 420 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
| 380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
| 421 | + if ($exists) |
|
| 422 | + { |
|
| 423 | + $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
| 424 | + } |
|
| 381 | 425 | } |
| 382 | 426 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
| 383 | 427 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -388,7 +432,10 @@ discard block |
||
| 388 | 432 | */ |
| 389 | 433 | function check_run($run_by='') |
| 390 | 434 | { |
| 391 | - if ($run_by === 'fallback') flush(); |
|
| 435 | + if ($run_by === 'fallback') |
|
| 436 | + { |
|
| 437 | + flush(); |
|
| 438 | + } |
|
| 392 | 439 | |
| 393 | 440 | if (!$this->last_check_run(True,False,$run_by)) |
| 394 | 441 | { |
@@ -410,7 +457,10 @@ discard block |
||
| 410 | 457 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
| 411 | 458 | foreach($GLOBALS as $name => $value) |
| 412 | 459 | { |
| 413 | - if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
|
| 460 | + if ($name !== 'egw' && is_object($value)) |
|
| 461 | + { |
|
| 462 | + unset($GLOBALS[$name]); |
|
| 463 | + } |
|
| 414 | 464 | } |
| 415 | 465 | $domain = $GLOBALS['egw_info']['user']['domain']; |
| 416 | 466 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
@@ -480,7 +530,10 @@ discard block |
||
| 480 | 530 | */ |
| 481 | 531 | function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
| 482 | 532 | { |
| 483 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
|
| 533 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
| 534 | + { |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 484 | 537 | |
| 485 | 538 | if ($id === '%') |
| 486 | 539 | { |
@@ -533,9 +586,15 @@ discard block |
||
| 533 | 586 | */ |
| 534 | 587 | function write($job, $exists = False, $where=array()) |
| 535 | 588 | { |
| 536 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
|
| 589 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
| 590 | + { |
|
| 591 | + return 0; |
|
| 592 | + } |
|
| 537 | 593 | |
| 538 | - if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) $job['data']['next'] = $job['next']; |
|
| 594 | + if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) |
|
| 595 | + { |
|
| 596 | + $job['data']['next'] = $job['next']; |
|
| 597 | + } |
|
| 539 | 598 | $data = array( |
| 540 | 599 | 'async_next' => $job['next'], |
| 541 | 600 | 'async_times' => json_encode($job['times']), |
@@ -600,9 +659,12 @@ discard block |
||
| 600 | 659 | { |
| 601 | 660 | echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
| 602 | 661 | $perms = fileperms($this->$name); |
| 603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 662 | + if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) |
|
| 663 | + { |
|
| 664 | + // only executable by group |
|
| 604 | 665 | { |
| 605 | 666 | $group = posix_getgrgid(filegroup($this->$name)); |
| 667 | + } |
|
| 606 | 668 | $webserver = posix_getpwuid(posix_getuid ()); |
| 607 | 669 | echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
| 608 | 670 | } |
@@ -622,10 +684,13 @@ discard block |
||
| 622 | 684 | } |
| 623 | 685 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
| 624 | 686 | } |
| 625 | - if ($this->php5[0] == '/') // we found a php5 binary |
|
| 687 | + if ($this->php5[0] == '/') |
|
| 688 | + { |
|
| 689 | + // we found a php5 binary |
|
| 626 | 690 | { |
| 627 | 691 | $this->php = $this->php5; |
| 628 | 692 | } |
| 693 | + } |
|
| 629 | 694 | } |
| 630 | 695 | } |
| 631 | 696 | |
@@ -637,7 +702,8 @@ discard block |
||
| 637 | 702 | */ |
| 638 | 703 | function installed() |
| 639 | 704 | { |
| 640 | - if ($this->only_fallback) { |
|
| 705 | + if ($this->only_fallback) |
|
| 706 | + { |
|
| 641 | 707 | return 0; |
| 642 | 708 | } |
| 643 | 709 | $this->find_binarys(); |
@@ -654,7 +720,10 @@ discard block |
||
| 654 | 720 | $n = 0; |
| 655 | 721 | while ($line = fgets($crontab,256)) |
| 656 | 722 | { |
| 657 | - if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
|
| 723 | + if ($this->debug) |
|
| 724 | + { |
|
| 725 | + echo 'line '.++$n.": $line<br>\n"; |
|
| 726 | + } |
|
| 658 | 727 | $parts = explode(' ',$line,6); |
| 659 | 728 | |
| 660 | 729 | if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
@@ -698,7 +767,8 @@ discard block |
||
| 698 | 767 | */ |
| 699 | 768 | function install($times) |
| 700 | 769 | { |
| 701 | - if ($this->only_fallback && $times !== False) { |
|
| 770 | + if ($this->only_fallback && $times !== False) |
|
| 771 | + { |
|
| 702 | 772 | return 0; |
| 703 | 773 | } |
| 704 | 774 | $this->installed(); // find other installed cronlines |