/**
  * forgotten identity
  *
  * @return void
  * @author Dan Chadwick
  **/
 function forgotten_identity($setup = false)
 {
     $d = array('form_name' => 'auth_forgotten_identity', 'model' => $this->model);
     $setup = steamcore::array_object($d, $setup);
     try {
         $setup = SteamForm::normalise_setup($setup);
         $form = SteamForm::factory($setup);
         // has the form been submitted, and does the data validate
         $form->test_form();
         // return the form data
         $fc = steamcore::array_object(array('form' => $form->return_form()));
         $this->model->forgotten_identity($fc);
         Event::run('steamauth.forgotten_identity_sent');
         return true;
     } catch (Exception $e) {
         if ($e->getCode() != -1) {
             // if problems submitting, get the message as to why
             $form->set_form_data('form_error', $e->getMessage());
         }
         // generate the html and throw it
         $f = $form->render();
         Event::run('steamauth.forgotten_identity_form', $f);
         return false;
     }
 }
 /**
  * build and run an XML form
  *
  * @param object $setup 
  * @return void
  * @author Andy Bennett
  */
 public static function run_form($setup = false)
 {
     try {
         $setup = SteamForm::normalise_setup($setup);
         $form = SteamForm::factory($setup);
         // does the form data validate
         $form->test_form();
         // get the data submitted from the form
         $fc = steamcore::array_object(array('form' => $form->return_form()));
         // run the validated event
         Event::run('steamform_' . $setup->form_name . '.validated', $fc);
         if ($setup->exit_point === 'validated') {
             return;
         }
         // do the uploading
         foreach ($_FILES as $file => $file_data) {
             if ($file_data['error'] > 0) {
                 unset($_POST[$file]);
             } else {
                 // insert the upload into the uploads database
                 $_POST[$file] = $setup->model->insert_upload(upload::get_upload_data($file, $file_data));
             }
         }
         // run the uploaded event
         Event::run('steamform_' . $setup->form_name . '.uploaded', $fc);
         if ($setup->exit_point === 'uploaded') {
             return;
         }
         // if this is an update, get the current values, and pass them into the form
         if ($setup->update !== false) {
             $id = isset($setup->id) ? $setup->id : Kohana::instance()->input->post('form_id');
             if (!$id || !preg_match('/^[0-9]+$/', $id)) {
                 throw new Exception("No ID supplied");
             }
             $fc->id = $id;
             // prepare the data for inserting
             $setup->model->prep_update_formdata($fc);
             Event::run('steamform_' . $setup->form_name . '.update_prepped', $fc);
             if ($setup->exit_point === 'prepped') {
                 return $fc;
             }
             if ($setup->db) {
                 // insert the data into the database
                 $r = $setup->model->update_formdata($fc);
                 // run the updated event
                 Event::run('steamform_' . $setup->form_name . '.updated', $r);
             }
         } else {
             // prepare the data for inserting
             $setup->model->prep_insert_formdata($fc);
             Event::run('steamform_' . $setup->form_name . '.insert_prepped', $fc);
             if ($setup->exit_point === 'prepped') {
                 return $fc;
             }
             if ($setup->db) {
                 // insert the data into the database
                 $r = $setup->model->insert_formdata($fc);
                 // run the inserted event
                 Event::run('steamform_' . $setup->form_name . '.inserted', $r);
             }
         }
         if ($setup->exit_point === 'inserted') {
             return;
         }
         if ($setup->exit_point === 'updated') {
             return;
         }
         // if there is a notify item in the form, run the notify event
         if (isset($fc->form->notify)) {
             Event::run('steamform.notify', steamcore::array_object(array('data' => $fc, 'notify' => $fc->form->notify)));
         }
         Event::run('audit.cache', steamcore::array_object(array('action' => $setup->update ? 'edit' : 'add', 'id' => $r, 'data' => $fc->data)));
         // run the inserted event
         Event::run('steamform_' . $setup->form_name . '.complete', steamcore::array_object(array('id' => $r, 'data' => $fc->data)));
     } catch (Exception $e) {
         // if this is an update, get the current values, and pass them into the form
         if ($setup->update !== false) {
             $current = steamform_helper::return_current_values($setup->model, $setup->update, $form);
             $form->set_form_data('current', $current);
         }
         if ($e->getCode() != -1) {
             Kohana::log('error', $e->getMessage());
             $form->set_form_data('error', $e->getMessage());
         }
         // generate the html and throw it
         $f = $form->render();
         // run the show_form event
         Event::run('steamform_' . $setup->form_name . '.show_form', $f);
     }
 }