public function put() { $this->requiresLogin(); $event = $this->event()->get(0 + $this->id); if (!Bootstrap::$main->isAdmin()) { if (!isset($event['user']) || $event['user'] != Bootstrap::$main->user['id']) { return $this->error(19); } } $model = new eventModel($event); if (is_array($this->data)) { $this->verify_data($this->data, $model); if ($model->parent) { foreach (['parent', 'name', 'url', 'lat', 'lng', 'address', 'city', 'postal', 'price', 'fb_friends'] as $k) { if (isset($this->data[$k])) { unset($this->data[$k]); } } } else { if (isset($this->data['url']) && $this->data['url'] && $this->data['url'] != $model->url) { if (!$this->data['url']) { return $this->error(23); } if ($model->find_on_url($model->user, $this->data['url'], $this->id + 0)) { return $this->error(17); } } elseif (isset($this->data['name']) && ($this->data['name'] != $model->name || !$this->data('url'))) { $url = Tools::str_to_url($this->data['name'], -1); if ($this->event()->find_on_url(Bootstrap::$main->user['id'], $url, $this->id + 0)) { $i = 1; while ($this->event()->find_on_url(Bootstrap::$main->user['id'], $url . $i, $this->id + 0)) { $i++; } $this->data['url'] = $url . $i; } else { $this->data['url'] = $url; } } } $active = $model->active; if (!$active && isset($this->data['city']) && isset($this->data['country']) && isset($this->data['address']) && isset($this->data['postal']) && (isset($this->data['lat']) && !$this->data['lat'] || isset($this->data['lng']) && !$this->data['lng'] || $this->data['city'] != $model->city || $this->data['country'] != $model->country || $this->data['address'] != $model->address || $this->data['postal'] != $model->postal)) { $url = 'https://maps.google.com/maps/api/geocode/json?address=' . urlencode($this->data['address'] . ', ' . $this->data['postal'] . ' ' . $this->data['city']) . '&sensor=false®ion=' . $this->data['country'] . '&key=' . Bootstrap::$main->getConfig('maps.api_key'); for ($i = 0; $i < 5; $i++) { $place = json_decode($this->req($url), true); if (isset($place['results'][0]['geometry']['location'])) { break; } usleep(rand(1000, 1000000)); } if (isset($place['results'][0]['geometry']['location'])) { $this->data['lat'] = $place['results'][0]['geometry']['location']['lat']; $this->data['lng'] = $place['results'][0]['geometry']['location']['lng']; } if ($this->data('lat') && $this->data('lng')) { $hints = $this->event()->lastHints($this->data('lat'), $this->data('lng')); if ($hints) { $this->data['hints'] = $hints; } } } foreach ($this->data as $k => $v) { if ($k == 'id') { continue; } if ($active && !in_array($k, ['min_guests', 'active', 'unlisted', '_vip', 'img', 'bookafterdeadline']) && (!isset($this->data['active']) || $this->data['active'])) { continue; } $model->{$k} = $v; } $model->d_change = Bootstrap::$main->now; if (!$active) { $this->check_before_save($model); } $model->save(); if (!$active && !$model->parent) { $model->updateFam(['price' => $model->price]); } $this->recalculate_fullhouse($model->id); $data = $model->data(); if (isset($this->data['tags'])) { $data['tags'] = Tools::tags(null, $this->add_tags($data, $this->data['tags'])); } $public = $this->public_data($data); if (isset($public['img'])) { $data['img'] = $public['img']; } if (isset($this->data['active'])) { if ($this->data('active') && !$active) { Bootstrap::$main->human_datetime_format(); $ics = Ics::invitation($model->data(), Bootstrap::$main->user, Bootstrap::$main->user, $model->create, $model->change); Tools::observe('new-event', ['event' => $this->event()->get($model->id), 'host' => Bootstrap::$main->user, 'parent' => $model->parent], [['invite.ics' => $ics]]); } if (!$this->data('active') && $active) { Bootstrap::$main->human_datetime_format(); $ics = Ics::cancelation($model->data(), Bootstrap::$main->user, Bootstrap::$main->user, $model->create, $model->change); Tools::observe('stop-event', ['event' => $this->event()->get($model->id), 'host' => Bootstrap::$main->user, 'parent' => $model->parent], [['invite.ics' => $ics]]); } } return $this->status($data); } }
protected function paid(paymentModel $payment, $amount) { if (0.9 * $payment->amount < $amount) { $image = new imageModel(); $guest = new guestModel($payment->guest); if ($guest->d_payment) { return; } $guest->d_payment = Bootstrap::$main->now; $guest->save(); $e = $this->event()->get($guest->event); Tools::userHasAccessToEvent($guest->event, $guest->user, true); $data = []; $data['event'] = $this->event()->data(); $user = new userModel($data['event']['user']); $data['host'] = $user->data(); Bootstrap::$main->session('time_delta', $user->delta); Bootstrap::$main->human_datetime_format(); $data['event'] = $this->event()->get($guest->event); $data['event']['img'] = $image->get($data['event']['img']); $user->get($guest->user); $data['guest'] = $user->data(); $data['data'] = $guest->data(); $data['payment'] = $payment->data(); if (isset($data['payment']['notify'])) { $data['notify'] = json_decode($data['payment']['notify'], true); } $ics = Ics::invitation($e, $data['host'], $data['guest'], $e['create'], $guest->create); Tools::observe('event-paid-to-host', $data); Tools::observe('event-paid-to-guest', $data, [['invite.ics' => $ics]]); Tools::log('guest', $data); $eventController = new eventController(); $eventController->recalculate_fullhouse($guest->event); } }