function run($args, $options) { Bootstrap::connect(); switch ($args['action']) { case 'import': // Properly detect Macintosh style line endings ini_set('auto_detect_line_endings', true); if (!$options['file']) $this->fail('CSV file to import users from is required!'); elseif (!($this->stream = fopen($options['file'], 'rb'))) $this->fail("Unable to open input file [{$options['file']}]"); $extras = array(); if ($options['org']) { if (!($org = Organization::lookup($options['org']))) $this->fail($options['org'].': Unknown organization ID'); $extras['org_id'] = $options['org']; } $status = User::importCsv($this->stream, $extras); if (is_numeric($status)) $this->stderr->write("Successfully imported $status clients\n"); else $this->fail($status); break; case 'export': $stream = $options['file'] ?: 'php://stdout'; if (!($this->stream = fopen($stream, 'c'))) $this->fail("Unable to open output file [{$options['file']}]"); fputcsv($this->stream, array('Name', 'Email')); foreach (User::objects() as $user) fputcsv($this->stream, array((string) $user->getName(), $user->getEmail())); break; default: $this->stderr->write('Unknown action!'); } @fclose($this->stream); }
} break; case 'pwreset': if (!$user || !$user->getAccount()) { $errors['err'] = sprintf(__('%s: Unknown or invalid'), __('end user account')); } elseif ($user->getAccount()->sendResetEmail()) { $msg = sprintf(__('Account password reset email sent to %s'), $user->getEmail()); } else { $errors['err'] = __('Unable to send account password reset email - try again!'); } break; case 'mass_process': if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) { $errors['err'] = sprintf(__('You must select at least %s.'), __('one end user')); } else { $users = User::objects()->filter(array('id__in' => $_POST['ids'])); $count = 0; switch (strtolower($_POST['a'])) { case 'lock': foreach ($users as $U) { if (($acct = $U->getAccount()) && $acct->lock()) { $count++; } } break; case 'unlock': foreach ($users as $U) { if (($acct = $U->getAccount()) && $acct->unlock()) { $count++; } }
$errors['err'] = __('Unable to send account activation email - try again!'); break; case 'pwreset': if (!$user || !$user->getAccount()) $errors['err'] = sprintf(__('%s: Unknown or invalid'), __('end user account')); elseif ($user->getAccount()->sendResetEmail()) $msg = sprintf(__('Account password reset email sent to %s'),$user->getEmail()); else $errors['err'] = __('Unable to send account password reset email - try again!'); break; case 'mass_process': if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) { $errors['err'] = sprintf(__('You must select at least %s.'), __('one end user')); } else { $users = User::objects()->filter( array('id__in' => $_POST['ids']) ); $count = 0; switch (strtolower($_POST['a'])) { case 'lock': foreach ($users as $U) if (($acct = $U->getAccount()) && $acct->lock()) $count++; break; case 'unlock': foreach ($users as $U) if (($acct = $U->getAccount()) && $acct->unlock()) $count++; break;