/**
  * create files in db
  */
 protected function store($form, $hash)
 {
     // get files in the temp/hash dir
     $files = FS::files($this->_settings->get('path_temp') . $hash . DIRECTORY_SEPARATOR);
     // set the files in the form
     $form->files($files);
     Event::raise($this, Event::BEFORE_STORE_FORM_PARSE, array('form' => $form));
     if ($form->valid()) {
         // get the hash of the temp dir from qs
         $hash = $this->request->param('id');
         // get the form values
         $values = $form->values();
         // loop through temp files
         for ($i = 0; $i < count($files); $i++) {
             // createmodel
             $model = ORM::factory($this->_settings->get('model'));
             // set group if one is active
             if ($group = $this->_state->get('group', FALSE)) {
                 $model->group_id = $group;
             }
             // undouble filename
             $file = FS::name_unique($files[$i], $this->_settings->get('path_files'));
             // store it
             FS::move($this->_settings->get('path_temp') . $hash . DIRECTORY_SEPARATOR . $files[$i], $this->_settings->get('path_files') . $file);
             // permissions
             FS::permissions($this->_settings->get('path_files') . $file, 0744);
             // set item properties
             $model->created = date('y-m-d H:i:s', time());
             $model->owner_id = Identity::instance()->id;
             $model->editor_id = Identity::instance()->id;
             $model->website_id = $this->_website;
             // set file
             $model->file = $file;
             // set additional info (mostly title)
             foreach ($values as $key => $value) {
                 if (is_array($value) && isset($value[$i])) {
                     $model->{$key} = $value[$i];
                 }
             }
             // call hook
             Event::raise($this, Event::BEFORE_STORE, array('model' => $model, 'form' => $form));
             //save
             $model->save();
             // call hook
             Event::raise($this, Event::AFTER_STORE, array('model' => $model, 'form' => $form));
         }
         // return true
         return TRUE;
     } else {
         // create viewer
         $viewer = Viewer::factory('Form', $form)->text(Text::instance());
         // render form
         $view = View::factory($this->_settings->get('view.create'), array('viewer' => $viewer));
         // event
         Event::raise($this, Event::BEFORE_STORE_RENDER, array('model' => NULL, 'form' => $form, 'viewer' => $viewer, 'view' => $view));
         // render
         $this->response->body($view->render());
         // return false
         return FALSE;
     }
 }