コード例 #1
0
ファイル: mixipop3.php プロジェクト: jmahmood/MixiPOP3
function action($mail_connection, $message)
{
    $subject = strtolower(trim($message->subject));
    if ($title = is_action($subject, 'post')) {
        mixi_post($mail_connection, $message);
        return;
    }
    if ($request = is_action($subject, 'list')) {
        mixi_messages($mail_connection, $message);
        return;
    }
    if ($title = is_action($subject, 'ashiato')) {
        mixi_ashiato($mail_connection, $message);
        return;
    }
    if ($request = is_action($subject, 'refresh')) {
        refresh_mixi_messages($mail_connection, $message);
        return;
    }
    if ($request = is_action($subject, 'bbsthreads')) {
        mixi_bbsthreads($mail_connection, $message);
        return;
    }
    if ($request = is_action($subject, 'bbsposts')) {
        mixi_bbsposts($mail_connection, $message);
        return;
    }
    throw new Exception("Unknown request.");
}
コード例 #2
0
ファイル: ViewEditMainCfg.php プロジェクト: rbarraud/nagvis
 public function parse()
 {
     global $_MAINCFG;
     ob_start();
     js_form_start('edit_config');
     if (is_action()) {
         try {
             $this->handleAction();
         } catch (FieldInputError $e) {
             $this->error = $e;
         }
     }
     $sections = array();
     foreach ($_MAINCFG->getValidConfig() as $sec => $arr) {
         if (!preg_match($this->exclude_pattern, $sec)) {
             $sections[$sec] = $_MAINCFG->getSectionTitle($sec);
         }
     }
     $open = get_open_section('global');
     render_section_navigation($open, $sections);
     foreach ($sections as $sec => $title) {
         $this->renderSection($sec, $open);
     }
     submit(l('save'));
     form_end();
     return ob_get_clean();
 }
コード例 #3
0
ファイル: ViewToNewMap.php プロジェクト: rlugojr/nagvis
 public function parse($orig_name)
 {
     global $CORE;
     ob_start();
     if (is_action()) {
         try {
             $name = post('name');
             if (!$name) {
                 throw new FieldInputError('name', l('Please provide a map name.'));
             }
             if (!preg_match(MATCH_MAP_NAME, $name)) {
                 throw new FieldInputError('name', l('This is not a valid map name (need to match [M])', array('M' => MATCH_MAP_NAME)));
             }
             if (count($CORE->getAvailableMaps('/^' . $name . '$/')) > 0) {
                 throw new FieldInputError('name', l('A map with this name already exists.'));
             }
             // Read the old config
             $MAPCFG = new GlobalMapCfg($orig_name);
             $MAPCFG->readMapConfig();
             // Create a new map config
             $NEW = new GlobalMapCfg($name);
             $NEW->createMapConfig();
             foreach ($MAPCFG->getMapObjects() as $object_id => $cfg) {
                 $NEW->addElement($cfg['type'], $cfg, $perm = true, $object_id);
             }
             success(l('The map has been created.'));
             reload(cfg('paths', 'htmlbase') . '/frontend/nagvis-js/index.php?mod=Map&show=' . $name, 1);
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     echo '<div class="simple_form">' . N;
     js_form_start('to_new_map');
     input('name');
     submit(l('Save'));
     focus('name');
     // Keep the view parameters the users has set
     $params = ltrim(req('view_params'), '&');
     if ($params) {
         $parts = explode('&', $params);
         foreach ($parts as $part) {
             list($key, $val) = explode('=', $part);
             hidden($key, $val);
         }
     }
     form_end();
     echo '</div>' . N;
     return ob_get_clean();
 }
コード例 #4
0
ファイル: CsvExporter.php プロジェクト: moiseh/codegen
 public function __construct(View $view)
 {
     // csv download check
     if (is_action('export_csv') && get_safe('object_id') == $view->identifier) {
         // send the download file and halt script
         $this->generateCsv($view);
     }
     // add "Export CSV" button on navbar
     $args = url_args();
     $args['action'] = 'export_csv';
     $args['object_id'] = $view->identifier;
     $url = url(current_path(), $args);
     $view->nav->addItem(new Item(array('label' => t('Export CSV'), 'icon' => 'glyphicon-download-alt', 'url' => $url)));
 }
コード例 #5
0
ファイル: LoginPage.php プロジェクト: moiseh/codegen
 public function onBeforeRender()
 {
     // logout actin
     if (is_action('logout')) {
         User::logout();
         redirect(page_home());
     }
     // login form
     if (is_post()) {
         $username = filter_input(INPUT_POST, 'username');
         $password = filter_input(INPUT_POST, 'password');
         $backTo = filter_input(INPUT_GET, 'back_to');
         if (User::authenticate($username, $password)) {
             $url = strlen($backTo) > 0 ? urldecode($backTo) : page_home();
             redirect($url);
         } else {
             Flash::error(t('Invalid username or password!'));
         }
     }
     $this->add(render('user-login.php'));
 }
コード例 #6
0
ファイル: ViewChangePassword.php プロジェクト: rlugojr/nagvis
 private function changeForm()
 {
     global $CORE, $AUTH;
     if (is_action()) {
         try {
             $user = $AUTH->getUser();
             $password_old = post('password_old');
             if (!$password_old) {
                 throw new FieldInputError('password_old', l('You need to specify the old password.'));
             }
             $password_new1 = post('password_new1');
             if (!$password_new1) {
                 throw new FieldInputError('password_new1', l('You need to specify the new password.'));
             }
             $password_new2 = post('password_new2');
             if (!$password_new2) {
                 throw new FieldInputError('password_new2', l('You need to specify to confirm the new password.'));
             }
             if ($password_new1 != $password_new2) {
                 throw new FieldInputError('password_new1', l('The new passwords do not match.'));
             }
             if ($password_old == $password_new1) {
                 throw new FieldInputError('password_new1', l('The new and old passwords are equal. Won\'t change anything.'));
             }
             // Set new passwords in authentication module, then change it
             $AUTH->passNewPassword(array('user' => $user, 'password' => $password_old, 'passwordNew' => $password_new1));
             if (!$AUTH->changePassword()) {
                 throw new NagVisException(l('Your password could not be changed.'));
             }
             success(l('Your password has been changed.'));
             js('setTimeout(popupWindowClose, 1000);');
             // close window after 1 sec
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('change_password');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Old password') . '</td>';
     echo '<td class="tdfield">';
     password('password_old');
     echo '</td></tr>';
     echo '<tr><td class="tdlabel">' . l('New password') . '</td>';
     echo '<td class="tdfield">';
     password('password_new1');
     echo '</td></tr>';
     echo '<tr><td class="tdlabel">' . l('New password (confirm)') . '</td>';
     echo '<td class="tdfield">';
     password('password_new2');
     echo '</td></tr>';
     echo '</table>';
     js('try{document.getElementById(\'password_old\').focus();}catch(e){}');
     submit(l('Change password'));
     form_end();
 }
コード例 #7
0
ファイル: ViewManageShapes.php プロジェクト: rbarraud/nagvis
 private function deleteForm()
 {
     global $CORE;
     echo '<h2>' . l('Delete Shape') . '</h2>';
     if (is_action() && post('mode') == 'delete') {
         try {
             $name = post('name');
             if (!$name) {
                 throw new FieldInputError('name', l('Please choose a shape'));
             }
             $shapes = $CORE->getAvailableShapes();
             if (!isset($shapes[$name])) {
                 throw new FieldInputError('name', l('The shape does not exist.'));
             }
             // Check whether or not the shape is in use
             $using = array();
             foreach ($CORE->getAvailableMaps() as $map) {
                 $MAPCFG = new GlobalMapCfg($map);
                 try {
                     $MAPCFG->readMapConfig();
                 } catch (Exception $e) {
                     continue;
                     // don't fail on broken map configs
                 }
                 foreach ($MAPCFG->getDefinitions('shape') as $key => $obj) {
                     if (isset($obj['icon']) && $obj['icon'] == $name) {
                         $using[] = $MAPCFG->getName();
                     }
                 }
             }
             if ($using) {
                 throw new FieldInputError('name', l('Unable to delete this shape, because it is ' . 'currently used by these maps: [M].', array('M' => implode(',', $using))));
             }
             $path = path('sys', '', 'shapes', $name);
             if ($path !== '') {
                 unlink($path);
             }
             success(l('The shape has been deleted.'));
             //reload(null, 1);
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('delete_shape');
     hidden('mode', 'delete');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Shape') . '</td>';
     echo '<td class="tdfield">';
     $shapes = array('' => l('Choose a shape'));
     foreach ($CORE->getAvailableShapes() as $name) {
         $shapes[$name] = $name;
     }
     select('name', $shapes);
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }
コード例 #8
0
ファイル: ViewMapAddModify.php プロジェクト: rlugojr/nagvis
 public function parse()
 {
     global $CORE;
     ob_start();
     // mode is set to view_params if only the "view parameters" dialog is handled in this request.
     // This dialog has less options and is primary saved for the user and not for all users in the
     // map configuration
     $this->mode = req('mode', 'addmodify');
     $map_name = req('show');
     if ($this->mode != 'view_params' && $map_name == null) {
         throw new NagVisException(l('You need to provide a map name.'));
     }
     if ($map_name !== null && (!preg_match(MATCH_MAP_NAME, $map_name) || count($CORE->getAvailableMaps('/^' . $map_name . '$/')) == 0)) {
         throw new NagVisException(l('The map does not exist.'));
     }
     $this->MAPCFG = new GlobalMapCfg($map_name);
     try {
         // FIXME: When to ignore?
         //$this->MAPCFG->skipSourceErrors();
         $this->MAPCFG->readMapConfig();
     } catch (MapCfgInvalid $e) {
     }
     $this->clone_id = req('clone_id');
     if ($this->clone_id !== null && !preg_match(MATCH_OBJECTID, $this->clone_id)) {
         throw new NagVisException(l('Invalid clone object id'));
     }
     $this->object_id = req('object_id');
     if ($this->object_id !== null) {
         // Give the sources the chance to load the object
         $this->MAPCFG->handleSources('load_obj', $this->object_id);
         if (!$this->MAPCFG->objExists($this->object_id)) {
             throw new NagVisException(l('The object does not exist.'));
         }
         // 'object_id' is only set when modifying existing objects
         $this->object_type = $this->MAPCFG->getValue($this->object_id, 'type');
     } else {
         // Creating/Cloning new object. The type is set by URL
         $this->object_type = req('type');
         $this->object_id = null;
     }
     $this->filterMapAttrs();
     // Don't handle submit actions when the 'update' POST attribute is set
     if (is_action()) {
         try {
             if (!$this->handleAddModify()) {
                 return ob_get_clean();
             }
         } catch (FieldInputError $e) {
             form_error($e->field, $e->message());
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     $this->drawForm();
     return ob_get_clean();
 }
コード例 #9
0
 private function delForm()
 {
     global $CORE;
     echo '<h2>' . l('Delete Backend') . '</h2>';
     if (is_action() && post('mode') == 'delete') {
         try {
             $backend_id = post('backend_id');
             if (!isset($this->editable_backends[$backend_id])) {
                 throw new FieldInputError('backend_id', l('The choosen backend does not exist.'));
             }
             // FIXME: Check whether or not the backend is used anywhere
             $CORE->getUserMainCfg()->delSection('backend_' . $backend_id);
             $CORE->getUserMainCfg()->writeConfig();
             success(l('The backend has been deleted.'));
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('delete');
     hidden('mode', 'delete');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Backend ID') . '</td>';
     echo '<td class="tdfield">';
     $choices = array('' => l('Please choose'));
     foreach ($this->editable_backends as $choice) {
         $choices[$choice] = $choice;
     }
     select('backend_id', $choices);
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }
コード例 #10
0
ファイル: ViewMapManageTmpl.php プロジェクト: rlugojr/nagvis
 private function deleteForm()
 {
     global $CORE;
     echo '<h2>' . l('Delete Template') . '</h2>';
     $map_name = req('show');
     if (!$map_name) {
         throw new NagVisException(l('Map name missing'));
     }
     if (count($CORE->getAvailableMaps('/^' . preg_quote($map_name) . '$/')) == 0) {
         throw new NagVisException(l('A map with this name does not exists'));
     }
     $MAPCFG = new GlobalMapCfg($map_name);
     $MAPCFG->readMapConfig(!ONLY_GLOBAL, false, false);
     if (is_action() && post('mode') == 'delete') {
         try {
             $name = post('name');
             if (count($MAPCFG->getTemplateNames('/^' . $name . '$/')) == 0) {
                 throw new FieldInputError('name', l('A template with this name does not exist.'));
             }
             $obj_id = $MAPCFG->getTemplateIdByName($name);
             $MAPCFG->deleteElement($obj_id, true);
             success(l('The template has been deleted.'));
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('delete');
     hidden('mode', 'delete');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Name') . '</td>';
     echo '<td class="tdfield">';
     $choices = array('' => l('Please choose'));
     foreach (array_keys($MAPCFG->getTemplateNames()) as $tmpl_name) {
         $choices[$tmpl_name] = $tmpl_name;
     }
     select('name', $choices, '', 'updateForm(this.form)');
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }
コード例 #11
0
ファイル: ViewAck.php プロジェクト: rbarraud/nagvis
 public function parse()
 {
     global $CORE, $_BACKEND, $AUTH;
     ob_start();
     $map = req('map');
     if (!$map || count($CORE->getAvailableMaps('/^' . $map . '$/')) == 0) {
         throw new NagVisException(l('Please provide a valid map name.'));
     }
     $object_id = req('object_id');
     if (!$object_id || !preg_match(MATCH_OBJECTID, $object_id)) {
         throw new NagVisException(l('Please provide a valid object id.'));
     }
     $MAPCFG = new GlobalMapCfg($map);
     $MAPCFG->skipSourceErrors();
     $MAPCFG->readMapConfig();
     if (!$MAPCFG->objExists($object_id)) {
         throw new NagVisException(l('The object does not exist.'));
     }
     $backendIds = $MAPCFG->getValue($object_id, 'backend_id');
     foreach ($backendIds as $backendId) {
         if (!$_BACKEND->checkBackendFeature($backendId, 'actionAcknowledge', false)) {
             return '<div class=err>' . l('The requested feature is not available for this backend. ' . 'The MKLivestatus backend supports this feature.') . '</div>';
         }
     }
     if (is_action()) {
         try {
             $type = $MAPCFG->getValue($object_id, 'type');
             if ($type == 'host') {
                 $spec = $MAPCFG->getValue($object_id, 'host_name');
             } else {
                 $spec = $MAPCFG->getValue($object_id, 'host_name') . ';' . $MAPCFG->getValue($object_id, 'service_description');
             }
             $comment = post('comment');
             if (!$comment) {
                 throw new FieldInputError('comment', l('You need to provide a comment.'));
             }
             $sticky = get_checkbox('sticky');
             $notify = get_checkbox('notify');
             $persist = get_checkbox('persist');
             // Now send the acknowledgement
             foreach ($backendIds as $backendId) {
                 $BACKEND = $_BACKEND->getBackend($backendId);
                 $BACKEND->actionAcknowledge($type, $spec, $comment, $sticky, $notify, $persist, $AUTH->getUser());
             }
             success(l('The problem has been acknowledged.'));
             js('window.setTimeout(function() {' . 'popupWindowClose(); refreshMapObject(null, \'' . $object_id . '\');}, 2000);');
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('acknowledge');
     echo '<label>' . l('Comment');
     input('comment');
     echo '</label>';
     echo '<label>';
     checkbox('sticky', cfg('global', 'dialog_ack_sticky'));
     echo l('Sticky') . '</label>';
     echo '<label>';
     checkbox('notify', cfg('global', 'dialog_ack_notify'));
     echo l('Notify contacts') . '</label>';
     echo '<label>';
     checkbox('persist', cfg('global', 'dialog_ack_persist'));
     echo l('Persist comment') . '</label>';
     submit(l('Acknowledge'));
     form_end();
     focus('comment');
     return ob_get_clean();
 }
コード例 #12
0
ファイル: ViewManageMaps.php プロジェクト: rlugojr/nagvis
 private function importForm()
 {
     global $CORE;
     echo '<h2>' . l('Import Map') . '</h2>';
     if (is_action() && post('mode') == 'import') {
         try {
             if (!isset($_FILES['map_file'])) {
                 throw new FieldInputError('map_file', l('You need to select a file to import.'));
             }
             $file = $_FILES['map_file'];
             if (!is_uploaded_file($file['tmp_name'])) {
                 throw new FieldInputError('map_file', l('The file could not be uploaded (Error: [ERROR]).', array('ERROR' => $file['error'] . ': ' . $CORE->getUploadErrorMsg($file['error']))));
             }
             $file_name = $file['name'];
             $file_path = cfg('paths', 'mapcfg') . $file_name;
             $map_name = substr($file_name, 0, -4);
             if (!preg_match(MATCH_CFG_FILE, $file_name)) {
                 throw new FieldInputError('map_file', l('The uploaded file is no map configuration file.'));
             }
             if (!preg_match(MATCH_MAP_NAME, $map_name)) {
                 throw new FieldInputError('map_file', l('This is not a valid map name (need to match [M])', array('M' => MATCH_MAP_NAME)));
             }
             // FIXME: We really should validate the contents of the file
             move_uploaded_file($file['tmp_name'], $file_path);
             $CORE->setPerms($file_path);
             success(l('The map has been imported. Changing to the new map...'));
             reload('index.php?mod=Map&act=view&show=' . $map_name, 1);
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('import_map');
     hidden('mode', 'import');
     echo '<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="1000000" />';
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Map file') . '</td>';
     echo '<td class="tdfield">';
     upload('map_file');
     echo '</td></tr>';
     echo '</table>';
     submit(l('Import'));
     form_end();
 }
コード例 #13
0
 private function deleteForm()
 {
     global $CORE;
     echo '<h2>' . l('Delete Background') . '</h2>';
     if (is_action() && post('mode') == 'delete') {
         try {
             $name = post('name');
             if (!$name) {
                 throw new FieldInputError('name', l('Please choose a background'));
             }
             if (count($CORE->getAvailableBackgroundImages('/^' . preg_quote($name) . '$/')) == 0) {
                 throw new FieldInputError('name', l('The background does not exist.'));
             }
             // Check whether or not the backgroun is in use
             $using = array();
             foreach ($CORE->getAvailableMaps() as $map) {
                 $MAPCFG = new GlobalMapCfg($map);
                 try {
                     $MAPCFG->readMapConfig(ONLY_GLOBAL);
                 } catch (Exception $e) {
                     continue;
                     // don't fail on broken map configs
                 }
                 $bg = $MAPCFG->getValue(0, 'map_image');
                 if (isset($bg) && $bg == $name) {
                     $using[] = $MAPCFG->getName();
                 }
             }
             if ($using) {
                 throw new FieldInputError('name', l('Unable to delete this background, because it is ' . 'currently used by these maps: [M].', array('M' => implode(',', $using))));
             }
             $BACKGROUND = new GlobalBackground($name);
             $BACKGROUND->deleteImage();
             success(l('The background has been deleted.'));
             //reload(null, 1);
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('delete');
     hidden('mode', 'delete');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Background') . '</td>';
     echo '<td class="tdfield">';
     $images = array('' => l('Choose a background'));
     foreach ($CORE->getAvailableBackgroundImages() as $name) {
         $images[$name] = $name;
     }
     select('name', $images);
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }
コード例 #14
0
ファイル: ViewManageRoles.php プロジェクト: rlugojr/nagvis
 private function deleteForm()
 {
     global $AUTHORISATION;
     echo '<h2>' . l('Delete Role') . '</h2>';
     if (is_action() && post('mode') == 'delete') {
         try {
             $role_id = post('role_id');
             if ($role_id === null || $role_id === '') {
                 throw new FieldInputError('role_id', l('Please choose a role to delete.'));
             }
             if (!is_numeric($role_id)) {
                 throw new FieldInputError('role_id', l('Invalid value provided.'));
             }
             $role_id = intval($role_id);
             // Check not to delete any referenced role
             $used_by = $AUTHORISATION->roleUsedBy($role_id);
             if (count($used_by) > 0) {
                 throw new NagVisException(l('Not deleting this role, the role is in use by the users [U].', array('U' => implode(', ', $used_by))));
             }
             if ($AUTHORISATION->deleteRole($role_id)) {
                 success(l('The role has been deleted.'));
             } else {
                 throw new NagVisException(l('Problem while deleting the role.'));
             }
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('delete');
     hidden('mode', 'delete');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Name') . '</td>';
     echo '<td class="tdfield">';
     $choices = array('' => l('Please choose'));
     foreach ($AUTHORISATION->getAllRoles() as $role) {
         $choices[$role['roleId']] = $role['name'];
     }
     select('role_id', $choices);
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }
コード例 #15
0
ファイル: ViewManageUsers.php プロジェクト: rlugojr/nagvis
 private function resetPwForm()
 {
     global $AUTH, $AUTHORISATION;
     if (!$AUTH->checkFeature('changePassword') || $AUTH->authedTrusted()) {
         return;
     }
     // reset not supported
     echo '<h2>' . l('Reset Password') . '</h2>';
     if (is_action() && post('mode') == 'reset_pw') {
         try {
             $user_id = post('user_id');
             if ($user_id === null || $user_id === '') {
                 throw new FieldInputError('user_id', l('Please choose a user.'));
             }
             if (!is_numeric($user_id)) {
                 throw new FieldInputError('user_id', l('Invalid value provided.'));
             }
             $user_id = intval($user_id);
             //if ($AUTH->getUserId() == $user_id)
             //    throw new FieldInputError('user_id', l('Unable to delete your own user.'));
             $password1 = post('password1');
             if (!$password1) {
                 throw new FieldInputError('password1', l('Please specify a password.'));
             }
             if (count($password1) > AUTH_MAX_PASSWORD_LENGTH) {
                 throw new FieldInputError('password1', l('This password is too long.'));
             }
             $password2 = post('password2');
             if (!$password2) {
                 throw new FieldInputError('password2', l('Please confirm your password.'));
             }
             if ($password1 != $password2) {
                 throw new FieldInputError('password2', l('The two passwords are not equal.'));
             }
             if ($AUTH->resetPassword($user_id, $password2)) {
                 success(l('The password has been reset.'));
             } else {
                 throw new NagVisException('Failed to reset the password.');
             }
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     js_form_start('reset_pw');
     hidden('mode', 'reset_pw');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Name') . '</td>';
     echo '<td class="tdfield">';
     $choices = array('' => l('Please choose'));
     foreach ($AUTH->getAllUsers() as $user) {
         $choices[$user['userId']] = $user['name'];
     }
     select('user_id', $choices);
     echo '</td></tr>';
     echo '<tr><td class="tdlabel">' . l('Password') . '</td>';
     echo '<td class="tdfield">';
     password('password1');
     echo '</td></tr>';
     echo '<tr><td class="tdlabel">' . l('Password Confirm') . '</td>';
     echo '<td class="tdfield">';
     password('password2');
     echo '</td></tr>';
     echo '</table>';
     submit(l('Save'));
     form_end();
 }