/**
  * This produces a form for editing the copy and headers in a page
  *
  * @return void
  * @author Dan Chadwick
  **/
 function edit_inline()
 {
     // $d = array(
     // 	'model' => steamcore::get_controls_model( 'pages' ),
     // 	'form_name' => 'pages_edit',
     // 	'form_data' => array(),
     // 	'update' => ($r->count())?$r->current()->id:0
     // 	);
     // $setup = steamcore::array_object( $d );
     //
     // /* Clear events */
     // Event::clear('steamform_'.$setup->form_name.'.complete');
     // Event::clear('steamform_'.$setup->form_name.'.show_form');
     //
     // Event::add('steamform_'.$setup->form_name.'.complete', array('admin_helpers', 'response_complete_listener') );
     // Event::add('steamform_'.$setup->form_name.'.show_form', array('admin_helpers', 'show_form_listener') );
     //
     try {
         $p = Kohana::instance()->uri->segment(2, 'home');
         $p = str_replace('.html', '', $p);
         $m = ORM::factory('page')->where('name', $p)->find();
         $form = Xform::factory()->name('xpage_contents_edit');
         // create the form
         $form->set_form_data('current', $m);
         $form->run();
         // run the form
         // handle form completion
         if (!$form->complete) {
             return $form->render();
         } else {
             $cols = array_keys($m->table_columns);
             foreach ($form->final_data as $k => $v) {
                 if (!in_array($k, $cols)) {
                     continue;
                 }
                 $m->{$k} = $v;
             }
         }
     } catch (Exception $e) {
         throw new Kohana_User_Exception('SteamCore Add Error', $e->getMessage());
     }
     // Assets::instance()->add_javascript('/cache/js/steamform');
     // Assets::instance()->add_javascript('/steamform/index/steamform');
     return $e;
 }
 public static function run_form($name, $model, $id = false, $action = null, $data = null)
 {
     $update = (is_numeric($id) and $id > 0);
     if (is_null($action)) {
         $action = $update ? 'edit' : 'add';
     }
     try {
         if ($update) {
             $model = ORM::factory($model, $id);
             if (!$model->loaded) {
                 throw new Exception("cannot_return_current_values");
             }
         } else {
             $model = ORM::factory($model);
         }
         $form = Xform::factory()->name('x' . $name . '_' . $action)->update($id)->set_form_data('current', $model);
         if (!empty($data) && is_array($data) && count($data)) {
             foreach ($data as $key => $value) {
                 $form->set_form_data($key, $value);
             }
         }
         $form = $form->run();
         if (!$form->complete) {
             // run the show_form event
             Event::run('xform_x' . $name . '_' . $action . '.show_form', $form->render());
         } else {
             // $has = $model->has_many;
             $cols = array_keys($model->table_columns);
             foreach ($form->final_data as $k => $v) {
                 if (!in_array($k, $cols)) {
                     continue;
                 }
                 $model->{$k} = $v;
             }
             $model->save();
             Event::run('steamcore.crud_upload', $model);
             Event::run('steamcore.' . $action . '_complete', $model);
         }
     } catch (Xform_Exception $e) {
         echo $e->getMessage();
     }
 }
 /**
  * send url to reset credential
  *
  * @param object $setup 
  * @return void
  * @author Andy Bennett
  */
 public function forgotten_identity()
 {
     try {
         $form = Xform::factory()->name('xauth_forgotten_identity')->run();
         if ($form->complete) {
             // run the show_form event
             Event::run('steamauth.forgotten_identity_complete', $form);
         } else {
             // run the show_form event
             Event::run('steamauth.forgotten_identity_form', $form->render());
         }
     } catch (Exception $e) {
         Kohana::log('error', __FILE__ . ':' . __METHOD__ . ':' . $e->getMessage());
     }
 }
示例#4
0
 /**
  * comment
  *
  * @return void
  * @author Andy Bennett
  */
 public function comment($post = null)
 {
     if (is_null($post)) {
         $ra = Router::$arguments;
         $post = $ra[1];
     }
     $root = ORM::factory('blogpost', $post);
     $update = (is_numeric($post) and $post > 0);
     $model = 'blogpost';
     $name = '';
     try {
         $model = ORM::factory($model);
         $form = Xform::factory()->name('xblog_comment')->update(false)->set_form_data('post_id', $post)->run();
         if (!$form->complete) {
             // run the show_form event
             return $form->render();
         } else {
             // Submit the form
             if (property_exists($form->final_data, 'status')) {
                 $model->status = $form->final_data->status;
             }
             $model->name = $form->final_data->name;
             $model->website = $form->final_data->website;
             $model->email = $form->final_data->email;
             $model->copy = $form->final_data->copy;
             $model->date_added = date("Y-m-d H:i:s");
             $model->blog_id = $root->blog_id;
             $model->user_id = User::instance()->id;
             $post_parent = $post;
             // We may want this to be a reply of a reply
             $post_id = Input::instance()->post('form_post_id', false);
             if (is_numeric($post_id) and $post_id > 0) {
                 $post_parent = $post_id;
             }
             // Update the last activity time for the root node
             $root->date_last_activity = date("Y-m-d H:i:s");
             $root->save();
             $model->insert_as_last_child($post_parent);
             $u = URI::instance()->string();
             url::redirect($u);
         }
     } catch (Xform_Exception $e) {
         echo $e->getMessage();
     }
 }