Beispiel #1
0
 public function SaveAction()
 {
     $id = Utils::me();
     $item = req('item');
     try {
         $this->Validate($id, $item);
         $vars = FormUtils::form2dbhash($item, 'email fname lname address1 address2 city state zip phone');
         $this->model->update($id, $vars);
         $this->fw->flash("record_updated", true);
         fw::redirect($this->base_url);
     } catch (ApplicationException $ex) {
         $this->set_form_error($ex->getMessage());
         $this->route_redirect("ShowForm");
     }
 }
 public function SaveAction($form_id)
 {
     $id = $form_id + 0;
     $item = req('item');
     try {
         $this->Validate($id, $item);
         #load old record if necessary
         #$item_old = $this->model->one($id);
         $itemdb = FormUtils::form2dbhash($item, $this->save_fields);
         $id = $this->model_add_or_update($id, $itemdb);
         fw::redirect($this->base_url . '/' . $id . '/edit');
     } catch (ApplicationException $ex) {
         $this->set_form_error($ex->getMessage());
         $this->route_redirect("ShowForm");
     }
 }
Beispiel #3
0
 public function SaveAction($form_id)
 {
     $id = $form_id + 0;
     $item = req('item');
     try {
         $this->Validate($id, $item);
         #load old record if necessary
         #$item_old = $this->model->one($id);
         $itemdb = FormUtils::form2dbhash($item, $this->save_fields);
         #TODO - checkboxes support
         #FormUtils::form2dbhash_checkboxes($itemdb, $item, 'is_checkbox');
         $id = $this->model->update($id, $itemdb);
         #TODO cleanup any caches that depends on settings
         #FwCache::remove("XXX");
         fw::redirect($this->base_url . '/' . $id . '/edit');
     } catch (ApplicationException $ex) {
         $this->set_form_error($ex->getMessage());
         $this->route_redirect("ShowForm");
     }
 }
Beispiel #4
0
 public function SaveAction($form_id)
 {
     $id = $form_id + 0;
     $item = req('item');
     if (!is_array($item)) {
         $item = array();
     }
     $files = UploadUtils::get_posted_files('file1');
     try {
         $this->Validate($id, $item, $files);
         #load old record if necessary
         #$item_old = $this->model->one($id);
         $itemdb = FormUtils::form2dbhash($item, $this->save_fields);
         if (!strlen($itemdb["iname"])) {
             $itemdb["iname"] = 'new file upload';
         }
         $is_add = $id == 0;
         $id = $this->model_add_or_update($id, $itemdb);
         #Proceed upload
         if (count($files)) {
             $this->model->upload($id, $files[0], $is_add);
         }
         logger($this->fw->get_response_expected_format());
         if ($this->fw->get_response_expected_format() == 'json') {
             $item = $this->model->one($id);
             return array('success' => true, 'id' => $id, 'item' => $item, 'url' => $this->model->get_url_direct($item));
         } else {
             fw::redirect($this->base_url . '/' . $id . '/edit');
         }
     } catch (ApplicationException $ex) {
         logger($this->fw->get_response_expected_format());
         logger($ex->getMessage());
         if ($this->fw->get_response_expected_format() == 'json') {
             return array('success' => false, 'err_msg' => $ex->getMessage(), 'id' => $id);
         } else {
             $this->set_form_error($ex->getMessage());
             $this->route_redirect("ShowForm");
         }
     }
 }
Beispiel #5
0
 public function SaveAction($form_id)
 {
     global $CONFIG;
     $id = $form_id + 0;
     $item = req('item');
     try {
         $this->Validate($id, $item);
         #load old record if necessary
         #$item_old = $this->model->one($id);
         $itemdb = FormUtils::form2dbhash($item, $this->save_fields);
         $id = $this->model_add_or_update($id, $itemdb);
         #signup confirmaiton email
         $user = $this->model->one($id);
         $ps = array('user' => $user);
         $this->fw->send_email_tpl($user['email'], 'signup.txt', $ps);
         $this->model->do_login($id);
         fw::redirect($CONFIG['LOGGED_DEFAULT_URL']);
     } catch (ApplicationException $ex) {
         $this->set_form_error($ex->getMessage());
         $this->route_redirect("ShowForm");
     }
 }
Beispiel #6
0
 public function SaveAction($form_id)
 {
     $id = $form_id + 0;
     $item = req('item');
     try {
         $this->Validate($id, $item);
         #load old record if necessary
         #$item_old = $this->model->one($id);
         $itemdb = FormUtils::form2dbhash($item, $this->save_fields);
         FormUtils::form2dbhash_checkboxes($itemdb, $item, 'is_checkbox');
         $itemdb['dict_link_auto_id'] = $this->model_related->add_or_update_quick($item['dict_link_auto_id_iname']);
         $itemdb['dict_link_multi'] = FormUtils::multi2ids(req('dict_link_multi'));
         #TODO $itemdb['fdate_combo'] = FormUtils::date4combo($item, 'fdate_combo');
         $itemdb['ftime'] = DateUtils::timestr2int($item['ftime_str']);
         #ftime - convert from HH:MM to int (0-24h in seconds)
         $id = $this->model_add_or_update($id, $itemdb);
         fw::redirect($this->base_url . '/' . $id . '/edit');
     } catch (ApplicationException $ex) {
         $this->set_form_error($ex->getMessage());
         $this->route_redirect("ShowForm");
     }
 }
Beispiel #7
0
 public function SaveFacebook()
 {
     $item = FormUtils::form2dbhash($_REQUEST, 'access_token id email first_name last_name name username gender link locale timezone verified');
     #TODO better validate
     if (!$item['access_token'] || !$item['id']) {
         throw new ApplicationException("Wrong facebook data", 1);
     }
     /*
     $fb = new Facebook(array(
         'appId'  => $GLOBALS['FACEBOOK_APP_ID'],
         'secret' => $GLOBALS['FACEBOOK_APP_SECRET'],
     ));
     $fb_user_id = $facebook->getUser();
     $user_profile = $facebook->api('/me');
     */
     #check if such user exists
     $users_id = 0;
     #first - check by email
     $hU = $this->model->one_by_email($item['email']);
     if ($hU['id']) {
         $users_id = $hU['id'];
     }
     if (!$users_id) {
         #now check by facebook email
         $hU = db_row("select * from users where fb_email=" . dbq($item['email']));
         if ($hU['id']) {
             $users_id = $hU['id'];
         }
     }
     if (!$users_id) {
         #now check by facebook id
         $hU = db_row("select * from users where fb_id=" . dbq($item['id']));
         if ($hU['id']) {
             $users_id = $hU['id'];
         }
     }
     if ($users_id) {
         #update user's missing data from facebook
         $vars = array('fb_access_token' => $item['access_token']);
         if ($hU['sex'] != ($item['gender'] == 'male' ? 1 : 0)) {
             $vars['sex'] = $item['gender'] == 'male' ? 1 : 0;
         }
         if (!$hU['fname']) {
             $vars['fname'] = $item['first_name'];
         }
         if (!$hU['lname']) {
             $vars['lname'] = $item['last_name'];
         }
         if ($hU['fb_email'] != $item['email'] && $item['email']) {
             $vars['fb_email'] = $item['email'];
         }
         if (!$hU['fb_id']) {
             $vars['fb_id'] = $item['id'];
         }
         if (!$hU['fb_link']) {
             $vars['fb_link'] = $item['link'];
         }
         if (!$hU['fb_locale']) {
             $vars['fb_locale'] = $item['locale'];
         }
         if (!$hU['fb_name']) {
             $vars['fb_name'] = $item['name'];
         }
         if (!$hU['fb_timezone']) {
             $vars['fb_timezone'] = $item['timezone'];
         }
         if (!$hU['fb_username']) {
             $vars['fb_username'] = $item['username'];
         }
         if (!$hU['fb_verified']) {
             $vars['fb_verified'] = $item['verified'] == 'true' ? 1 : 0;
         }
         if (!$hU['fb_picture_url']) {
             $vars['fb_picture_url'] = 'http://graph.facebook.com/' . $item['username'] . '/picture';
         }
         db_update('users', $vars, $users_id);
     } else {
         #register user first if new
         $users_id = $this->model->add(array('email' => $item['email'], 'nick' => $item['name'], 'sex' => $item['gender'] == 'male' ? 1 : 0, 'fname' => $item['first_name'], 'lname' => $item['last_name'], 'fb_id' => $item['id'], 'fb_link' => $item['link'], 'fb_locale' => $item['locale'], 'fb_name' => $item['name'], 'fb_timezone' => $item['timezone'], 'fb_username' => $item['username'], 'fb_verified' => $item['verified'] == 'true' ? 1 : 0, 'fb_picture_url' => 'http://graph.facebook.com/' . $item['username'] . '/picture', 'fb_access_token' => $item['access_token']));
     }
     #automatically login the user
     $_SESSION['is_just_registered'] = 1;
     $this->model->do_login($users_id);
     $ps = array('status' => 0, 'err_msg' => '');
     parse_json($ps);
 }