Exemplo n.º 1
0
 public function action_delete($id)
 {
     $post = Jelly::select('forum_post')->where('id', '=', $id)->load();
     if ($post->loaded()) {
         $this->title = 'Forum - Post - Delete';
     } else {
         Message::set(Message::ERROR, 'Post does not exist');
         $this->request->redirect('forum');
     }
     if ($this->user->id != $post->user->id) {
         Message::set(Message::ERROR, 'You are not the author of this post.');
         $this->request->redirect('forum');
     } else {
         $topic = Jelly::select('forum_topic')->where('id', '=', $post->topic->id)->load();
         if ($topic->posts > 1) {
             $topic->posts = $topic->posts - 1;
             $topic->save();
             $post->delete();
             Message::set(Message::SUCCESS, 'Post has been deleted.');
             $this->request->redirect('forum');
         }
         if ($topic->posts == 1) {
             $topic->delete();
             $post->delete();
             Message::set(Message::SUCCESS, 'Post has been deleted.');
             $this->request->redirect('forum');
         }
     }
     $this->template->content = View::factory('forum/post/delete')->set('post', $post);
 }
Exemplo n.º 2
0
 /**
  * Create a new post.
  */
 public function action_reply($id)
 {
     $topic = Jelly::select('forum_topic')->where('id', '=', $id)->load();
     // Make sure the topic exists
     if (!$topic->loaded()) {
         Message::set(Message::ERROR, 'Topic does not exist');
         $this->request->redirect('forum');
     }
     $this->title = 'Forum - Reply to ' . $topic->title;
     // Validate the form input
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
     if ($post->check()) {
         $values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $id);
         $message = Jelly::factory('forum_post');
         // Assign the validated data to the Jelly object
         $message->set($values);
         $message->save();
         $topic_id = $id;
         $topic = Jelly::select('forum_topic')->where('id', '=', $topic_id)->load();
         $topic->posts = $topic->posts + 1;
         $topic->save();
         Message::set(Message::SUCCESS, 'You posted a new reply.');
         $this->request->redirect('forum/topic/' . $id);
     } else {
         $this->errors = $post->errors('forum');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('forum/post/create')->set('post', $post->as_array());
 }
Exemplo n.º 3
0
 /**
  * Create a new topic.
  */
 public function action_new_topic($id)
 {
     $this->title = 'Forum - New Topic';
     $category = Jelly::select('forum_category')->where('id', '=', $id)->load();
     if (!$category->loaded()) {
         Message::set(Message::ERROR, 'Category does not exist');
         $this->request->redirect('forum');
     }
     // Validate the form input
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
     if ($post->check()) {
         $topic_values = array('title' => $post['title'], 'user' => $this->user->id, 'category' => $id, 'status' => 'open', 'posts' => '1');
         $topic = Jelly::factory('forum_topic');
         // Assign the validated data to the sprig object
         $topic->set($topic_values);
         $topic->save();
         $topic_id = $topic->id;
         $post_values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $topic_id);
         $message = Jelly::factory('forum_post');
         // Assign the validated data to the sprig object
         $message->set($post_values);
         $message->save();
         Message::set(Message::SUCCESS, 'You created a topic.');
         $this->request->redirect('forum/category/' . $id);
     } else {
         $this->errors = $post->errors('forum');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('forum/topic/create')->set('post', $post->as_array());
 }
Exemplo n.º 4
0
 public function action_heal()
 {
     // Check if the user has a character already.
     if (!$this->character->loaded()) {
         $this->request->redirect('character/create');
     }
     $character = $this->character;
     // Initialize the character class, and set the players character as the default.
     $char = new Character($character);
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('amount', 'not_empty')->rule('amount', 'digit')->callback('amount', array($this, 'can_heal'));
     if ($post->check()) {
         try {
             $character->hp = $character->hp + $post['amount'];
             $character->money = $character->money - $post['amount'] * $this->heal_cost;
             $character->save();
             $this->request->redirect('character');
         } catch (Validate_Exception $e) {
             // Get the errors using the Validate::errors() method
             $this->errors = $e->array->errors('register');
         }
     } else {
         $this->errors = $post->errors('character/create');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('character/heal')->set('character', $character)->set('char', $char)->set('post', $post);
 }
Exemplo n.º 5
0
 /**
  * Редактирование новости автосервиса
  * @return void
  */
 function action_edit()
 {
     $id = $this->request->param('id', null);
     if (!empty($id)) {
         $payment = ORM::factory('payment', $id);
         if (!$payment->loaded()) {
             Message::set(Message::ERROR, "Платежная система не найдена");
             $this->request->redirect('admin/payment');
         }
         $this->values = $payment->as_array();
     } else {
         Message::set(Message::ERROR, "Платежная система не найдена");
         $this->request->redirect('admin/payment');
     }
     if ($_POST) {
         try {
             $payment->values($_POST, array('payment_name', 'status', 'position', 'tips', 'description'));
             $payment->save();
             Message::set(Message::SUCCESS, 'Платежная система сохранена');
             $this->request->redirect('admin/payment');
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     }
     $this->view = View::factory('backend/payment/form')->set('errors', $this->errors)->set('values', $this->values)->set('url', 'admin/payment/main/edit/' . $id);
     $this->template->title = 'Редактирование "' . $payment->payment_name;
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 6
0
 public function action_view($id2, $id)
 {
     if (!is_numeric($id)) {
         Message::set(Message::ERROR, 'Invalid ID');
         $this->request->redirect('zone');
     }
     $item = Model_Shop::get_one_item($this->shop->id, $id);
     $this->title = $item->name;
     $this->item = $item;
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('amount', 'digit')->callback('amount', array($this, 'shop_got_item'));
     if ($post->check()) {
         $item2 = Model_User::get_item($this->user->id, $id);
         // User got the item in his relation table.
         if ($item2) {
             DB::update('user_items')->set(array('amount' => new Database_Expression('amount + ' . $post['amount'])))->where('user_id', '=', $this->user->id)->and_where('item_id', '=', $id)->execute();
         } else {
             DB::insert('user_items', array('user_id', 'item_id', 'amount'))->values(array($this->user->id, $id, $post['amount']))->execute();
         }
         DB::update('shop_items')->set(array('amount' => new Database_Expression('amount - ' . $post['amount'])))->where('shop_id', '=', $this->shop_id)->and_where('item_id', '=', $id)->execute();
         $item->amount = $item->amount - $post['amount'];
         Message::set(Message::SUCCESS, 'You bought ' . $post['amount'] . ' ' . $item->name);
     } else {
         if ($post->errors()) {
             Message::set(Message::ERROR, $post->errors('shop'));
         }
     }
     $this->template->content = View::factory('shop/view')->set('shop', $this->shop)->set('item', $item);
 }
Exemplo n.º 7
0
 public function action_add()
 {
     $cities = ORM::factory('city')->get_cities();
     $services = ORM::factory('service')->get_services_as_array();
     if ($_POST) {
         if (isset($_POST['city_id']) and $_POST['city_id'] != 0) {
             $services = ORM::factory('service')->get_services_as_array(array('city_id' => $_POST['city_id']));
         }
         $review = ORM::factory('review');
         try {
             $review->values($_POST, array('name', 'email', 'text', 'service_id'));
             if ($this->user) {
                 $review->user_id = $this->user->id;
             }
             $review->active = 0;
             $review->date = Date::formatted_time();
             $review->save();
             Message::set(Message::SUCCESS, __('review_adding_complete'));
             $this->request->redirect('reviews');
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     }
     $this->view = View::factory('frontend/review/add')->set('values', $this->values)->set('errors', $this->errors)->set('cities', $cities)->set('services', $services);
     $this->template->title = 'Написать отзыв';
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 8
0
 public function action_register()
 {
     if ($this->user) {
         Request::instance()->redirect('');
     }
     // Experimental facebook connection
     $this->facebook = new Fb();
     // User accessed from facebook!
     if ($this->facebook->validate_fb_params()) {
         $this->facebook->require_frame();
         $_SESSION['fb_uid'] = $this->facebook->require_login();
     } elseif (!isset($_SESSION['fb_uid'])) {
         Request::instance()->redirect('');
     }
     // Check if the user got an account.
     $user_facebook = Jelly::select('user_facebook')->where('facebook_id', '=', $_SESSION['fb_uid'])->load();
     // If we found it, log him in.
     if ($user_facebook->loaded()) {
         $this->a1->force_login($user_facebook->user->username);
         $_SESSION['facebook'] = 'TRUE';
         // Used for verifying if logged in using facebook.
         Request::instance()->redirect('');
     }
     $user = Jelly::factory('user');
     // Validate the form input
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('username', 'min_length', array(3))->rule('username', 'max_length', array(20))->rule('username', 'alpha_numeric')->rule('email', 'email')->rule('tos', 'not_empty');
     if ($post->check()) {
         $values = array('username' => $post['username'], 'email' => $post['email']);
         // Assign the validated data to the sprig object
         $user->set($values);
         // Hash the password
         $user->password = '';
         // Set the default role for registered user.
         $user->role = 'facebook';
         try {
             // Create the new user
             $testy = $user->save();
             //print_r($testy);
             $user_id = mysql_insert_id();
             $ufb = Jelly::factory('user_facebook');
             $ufb->facebook_id = $_SESSION['fb_uid'];
             $ufb->user = $user_id;
             $ufb->save();
             $this->a1->force_login($values['username']);
             $_SESSION['facebook'] = 'TRUE';
             // Used for verifying if logged in using facebook.
             // Redirect the user to the login page
             $this->request->redirect('');
         } catch (Validate_Exception $e) {
             // Get the errors using the Validate::errors() method
             $this->errors = $e->array->errors('register');
         }
     } else {
         $this->errors = $post->errors('account/register');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('facebook/register')->set('post', $post->as_array());
 }
Exemplo n.º 9
0
 /**
  * Просмотр запроса
  * @return void
  */
 public function action_view()
 {
     $feedback = ORM::factory('feedback', $this->request->param('id', NULL));
     if (!$feedback->loaded()) {
         Message::set(Message::ERROR, Kohana::message('admin', 'feedback_not_found'));
         $this->request->redirect('admin/feedback');
     }
     /*
     switch ($feedback->type)
     {
         case 1:
             $this->view = View::factory('backend/feedback/view_feedback');
             break;
         case 2:
             $this->view = View::factory('backend/feedback/view_adv');
             break;
     }
     $this->view->set('feedback', $feedback);
     
     $this->template->title = $title_pie.' от пользователя '.$feedback->user->username;
     */
     $this->view = View::factory('backend/feedback/view')->set('feedback', $feedback);
     $title_pie = $feedback->type == 1 ? 'Запрос' : 'Заявка на рекламу';
     $this->template->title = $title_pie . ' от пользователя ' . $feedback->user->username;
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 10
0
 function action_index()
 {
     $services[0] = 'Выбрать компанию';
     foreach ($this->user->services->find_all() as $service) {
         $services[$service->id] = $service->name;
     }
     if ($_POST) {
         $feedback = ORM::factory('feedback');
         try {
             $feedback->values($_POST, array('title', 'text'));
             $feedback->type = 2;
             $feedback->user_id = $this->user->id;
             $feedback->service_id = Arr::get($_POST, 'service_id', 0);
             $feedback->date = Date::formatted_time();
             $feedback->save();
             $email_view = View::factory('email/adv')->set('username', $this->user->username)->set('title', $feedback->title)->set('text', $feedback->text);
             if ($feedback->service_id != 0) {
                 $email_view->set('service', $this->user->services->where('id', '=', $feedback->service_id)->find());
             }
             $email_view->render();
             Email::send('*****@*****.**', array('*****@*****.**', 'Ассоциация автосервисов'), $feedback->title, $email_view, TRUE);
             Message::set(Message::SUCCESS, 'Спасибо! Ваше заявка принята на рассмотрение администрацией сайта');
             $this->request->redirect('cabinet');
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     }
     $this->view = View::factory('frontend/cabinet/adv/create_blank')->set('services', $services)->set('errors', $this->errors)->set('values', $this->values);
     $this->template->title = 'Реклама на сайте';
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 11
0
 /**
  * Удаление новости автосервиса
  * @return void
  */
 function action_delete()
 {
     $settings = ORM::factory('payment_settings', $this->request->param('id', null));
     if (!$settings->loaded()) {
         Message::set(Message::ERROR, Kohana::message('admin', 'payment.settings_not_found'));
         $this->request->redirect('admin/payment/settings');
     }
     if ($settings->system == 'Y') {
         Message::set(Message::NOTICE, 'Нельзя удалять системные настройки');
         $this->request->redirect('admin/payment/settings');
     }
     if ($_POST) {
         $action = Arr::extract($_POST, array('submit', 'cancel'));
         if ($action['cancel']) {
             $this->request->redirect('admin/payment/settings');
         }
         if ($action['submit']) {
             $name = $settings->name;
             $settings->delete();
             Message::set(Message::SUCCESS, 'Платежная настройка <strong>' . $name . '</strong> удалена');
             $this->request->redirect('admin/payment/settings');
         }
     }
     $this->view = View::factory('backend/delete')->set('url', 'admin/payment/settings/delete/' . $settings->id)->set('from_url', 'admin/payment/settings')->set('title', 'Удаление платежной настройки: ' . $settings->name)->set('text', 'Вы действительно хотите удалить "' . $settings->name . '?');
     $this->template->title = 'Удаление новости "' . $settings->name . '"';
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 12
0
 /**
  * Отправка сообщения на Email
  * @return void
  */
 public function action_send()
 {
     $user = ORM::factory('user', $this->request->param('id', NULL));
     if (!$user->loaded()) {
         $this->request->redirect('admin');
     }
     $feedback_id = Arr::get($_GET, 'feedback', 0);
     $email_from = array('no-reply' => '*****@*****.**', 'sekretar' => '*****@*****.**');
     if ($_POST) {
         $message = ORM::factory('message');
         $message->values($_POST, array('title', 'text', 'from'));
         $message->user_id = $user->id;
         $message->feedback_id = $feedback_id;
         $message->date = Date::formatted_time();
         try {
             $message->save();
             $this->add_to_email_queue($user->id, $message->id, $message->from);
             Message::set(Message::SUCCESS, 'Сообщения пользователю "' . $user->username . '" отправлено в очередь на отправку');
             $this->request->redirect('admin/message');
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     }
     $this->view = View::factory('backend/message/send')->set('values', $this->values)->set('errors', $this->errors)->set('email_from', $email_from)->set('user', $user);
     $this->template->title = 'Отправка сообщения';
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 13
0
 public function action_save()
 {
     if ($_POST && $_FILES) {
         $imageChanged = false;
         $data = (object) $this->sanitize($_POST);
         $update = false;
         if ($data->id == "") {
             $editorial = ORM::factory("editorial");
         } else {
             $editorial = ORM::factory("editorial", $data->id);
         }
         if (in_array($_FILES['image']['type'], $this->allowed)) {
             Upload::$default_directory = Kohana::config('myshot.basePath');
             if ($stage_path = Upload::save($_FILES['image'])) {
                 $imageChanged = true;
                 Library_Akamai::factory()->addToDir($stage_path, 'editorials');
             }
         }
         $editorial->title = $data->title;
         $editorial->image = $imageChanged ? Kohana::config('myshot.cdn') . 'editorials/' . basename($stage_path) : $editorial->image;
         $editorial->image_alt = $data->image_alt;
         $editorial->link = $data->link;
         $editorial->link_text = $data->link_text;
         $editorial->text = $data->text;
         $editorial->save();
         Message::set(Message::SUCCESS, $update ? "You have sucessfully updated the editorial." : "You have sucessfully added the editorial.");
     }
     Request::instance()->redirect('admin/editorials');
 }
Exemplo n.º 14
0
 /**
  * Moves the character to a new zone
  * 
  * @param  integer  $id
  */
 public function action_travel($id)
 {
     // Make sure id is an integer.
     if (!is_numeric($id)) {
         Message::set(Message::ERROR, 'Invalid ID');
         $this->request->redirect('travel');
     }
     if ($id == $this->character->zone->id) {
         Message::set(Message::ERROR, 'You cannot move to where you already are.');
         $this->request->redirect('travel');
     }
     // Load the zone
     $zone = Jelly::select('zone')->where('id', '=', $id)->load();
     $character = $this->character;
     // Make sure the character got enough of engery
     if ($character->energy < $zone->energy) {
         Message::set(Message::ERROR, 'Not enough energy.');
         $this->request->redirect('travel');
     }
     // Set the new zone, and energy
     $character->zone = $zone->id;
     $character->energy = $character->energy - $zone->energy;
     $character->save();
     $this->request->redirect('character');
 }
Exemplo n.º 15
0
 /**
  * Log in
  */
 public function action_login()
 {
     $this->title = __('user.authorization');
     if ($this->request->is_post()) {
         // If not logged
         if (!$this->auth->login($this->request->post('email'), $this->request->post('password'), (bool) $this->request->post('remember'))) {
             Message::error(__('user.error_authorization'));
             HTTP::redirect(Route::url('b_auth', ['action' => 'login']));
         }
     }
     $this->user = $this->auth->get_user();
     if ($this->user and !$this->user->confirmed) {
         Message::warning(__('user.email_сheck_and_confirm', [':email' => $this->user->email]));
         $this->auth->logout();
         HTTP::redirect(Route::url('b_auth', ['action' => 'login']));
     }
     // If user is admin
     if ($this->auth->logged_in('admin')) {
         Message::success(__('user.hello_username', [':username' => $this->user->username]));
         HTTP::redirect(Route::url('b_dashboard'));
     }
     // If user is user
     if ($this->auth->logged_in()) {
         Message::set('success', __('user.hello_username', [':username' => $this->user->username]));
         HTTP::redirect(Route::url('f_user_profile'));
     }
     $this->content = View::factory('auth/backend/v_login');
 }
Exemplo n.º 16
0
 function action_index()
 {
     if ($_POST) {
         $feedback = ORM::factory('feedback');
         try {
             $feedback->values($_POST, array('title', 'text'));
             $feedback->type = 1;
             $feedback->user_id = $this->user->id;
             $feedback->date = Date::formatted_time();
             $feedback->save();
             $email_view = View::factory('email/feedback')->set('username', $this->user->username)->set('title', $feedback->title)->set('text', $feedback->text)->render();
             Email::send('*****@*****.**', array('*****@*****.**', 'Ассоциация автосервисов'), $feedback->title, $email_view, TRUE);
             Message::clear();
             Message::set(Message::SUCCESS, 'Спасибо! Ваше сообщение отправлено администрации сайта');
             $this->request->redirect('cabinet');
         } catch (ORM_Validation_Exception $e) {
             Message::set(Message::ERROR, 'Произошла ошибка при отправке сообщения');
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     }
     $this->view = View::factory('frontend/cabinet/feedback/create_feedback')->set('errors', $this->errors)->set('values', $this->values);
     $this->template->title = 'Обратная связь';
     $this->template->content = $this->view;
 }
Exemplo n.º 17
0
 /**
  * Редактирование страницы фильтра
  * @return void
  */
 public function action_edit()
 {
     $content = ORM::factory('content_filter', $this->request->param('id', NULL));
     if (!$content->loaded()) {
         Message::set(Message::ERROR, Kohana::message('admin', 'content_not_found'));
         $this->request->redirect('admin/content/filter');
     }
     // Город страницы
     $city = $content->city->name;
     $type = __('filter_type_' . $content->type);
     if ($_POST) {
         try {
             $content->text = Arr::get($_POST, 'text', NULL);
             $content->date_edited = Date::formatted_time();
             $content->update();
             Message::set(Message::SUCCESS, 'Страница фильтра для города ' . $city . ' успешно отредактирована');
             $this->request->redirect('admin/content/filter/index/' . $content->type);
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     } else {
         $this->values = $content->as_array();
     }
     $this->view = View::factory('backend/content/filter/edit')->set('url', 'admin/content/filter/edit/' . $content->id)->set('city', $city)->set('type', $type)->set('values', $this->values)->set('errors', $this->errors);
     $this->template->title = 'Редактирование страницы фильтра для г. ' . $city;
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 18
0
 public function leiratkozas($user_id, $unsubscribe_code)
 {
     // lekérdezzük, hogy helyes-e a user_id és a unsubscribe_code (tehát van-e ilyen aktív user)
     $this->query->set_table(array('site_users'));
     $this->query->set_columns('user_id');
     $this->query->set_where('user_id', '=', $user_id, 'and');
     $this->query->set_where('user_active', '=', 1, 'and');
     $this->query->set_where('user_unsubscribe_code', '=', $unsubscribe_code);
     $result = $this->query->select();
     //ha a találatok száma 1, akkor töröljük az adott user_id-jü rekordot
     if (count($result) == 1) {
         //töröljük az adatbázisból
         $delete_user = $result[0]['user_id'];
         $this->query->reset();
         $this->query->set_table(array('site_users'));
         $this->query->set_where('user_id', '=', $delete_user);
         $result = $this->query->delete();
         if (count($result == 1)) {
             //pozitív üzenet
             Message::set('success', 'Sikeresen leiratkozott a hírlevelünkről.');
         } else {
             //negatív üzenet
             Message::set('error', 'A leiratkozás nem sikerült!');
         }
     } else {
         //HIBA: 0 vagy több találat - nem torolheto az adatbazisbol;
         Message::set('error', 'Adatbázis hiba. A leiratkozás nem sikerült!');
     }
 }
Exemplo n.º 19
0
 public function action_index()
 {
     $this->template->title = __('Contact');
     $this->template->content = View::factory('page/contact')->bind('errors', $errors);
     // Validate the required fields
     $data = Validate::factory($_POST)->filter('name', 'trim')->rule('name', 'not_empty')->filter('email', 'trim')->rule('email', 'not_empty')->rule('email', 'email')->filter('message', 'trim')->filter('message', 'Security::xss_clean')->filter('message', 'strip_tags')->rule('message', 'not_empty');
     if ($data->check()) {
         // Load Swift Mailer
         require Kohana::find_file('vendor', 'swiftmailer/lib/swift_required');
         $transport = Swift_MailTransport::newInstance();
         $mailer = Swift_Mailer::newInstance($transport);
         // Get the email config
         $config = Kohana::config('site.contact');
         $recipient = $config['recipient'];
         $subject = $config['subject'];
         // Create an email message
         $message = Swift_Message::newInstance()->setSubject(__($subject, array(':name' => $data['name'])))->setFrom(array($data['email'] => $data['name']))->setTo($recipient)->addPart($data['message'], 'text/plain');
         // Send the message
         Swift_Mailer::newInstance($transport)->send($message);
         // Set the activity and flash message
         Activity::set(Activity::SUCCESS, __('Message sent from :email', array(':email' => $data['email'])));
         Message::set(Message::SUCCESS, __('Message successfully sent.'));
         // Redirect to prevent POST refresh
         $this->request->redirect($this->request->uri);
     }
     if ($errors = $data->errors('contact')) {
         // Set the error flash message
         Message::set(Message::ERROR, __('Please correct the errors.'));
     }
     $_POST = $data->as_array();
 }
Exemplo n.º 20
0
 /**
  * Inserts the NG Comment for a given comment / photo / avatar
  * 
  * @author Vladimir Kokovic
  * @return string
  */
 public static function insert_comment($user_id, $item_id, $item_type_id, $comment)
 {
     $ng_comment = ORM::factory('ngcomment')->where('item_type_id', '=', $item_type_id)->where('item_id', '=', $item_id)->find();
     if ($ng_comment->loaded()) {
         if ($comment != '') {
             $ng_comment->comment = $comment;
             $ng_comment->user_id = $user_id;
             $ng_comment->save();
             Message::set(Message::SUCCESS, 'NG Comment successfully added.');
         } else {
             $ng_comment->delete();
             Message::set(Message::SUCCESS, 'NG Comment successfully removed.');
         }
     } else {
         if ($comment != '') {
             $ng_comment = ORM::factory('ngcomment');
             $ng_comment->user_id = $user_id;
             $ng_comment->item_type_id = $item_type_id;
             $ng_comment->item_id = $item_id;
             $ng_comment->comment = $comment;
             $ng_comment->save();
             Message::set(Message::SUCCESS, 'NG Comment successfully added.');
         } else {
             Message::set(Message::ERROR, 'Cannot insert empty NG Comment.');
         }
     }
 }
Exemplo n.º 21
0
 function before()
 {
     parent::before();
     if (!$this->auth->logged_in()) {
         Message::set(Message::ERROR, 'Доступ закрыт, авторизуйтесь');
         $this->request->redirect('login');
     }
     if (empty($this->user->expires)) {
         $user_expires = new DateTime();
         $user_expires->modify("-1 day");
     } else {
         $user_expires = new DateTime($this->user->expires);
     }
     //  проверка на позможность использования кабинета
     /*if (!$this->allow_expired && Date::diff($user_expires->format("Y-m-d 23:59:59"),date("Y-m-d")) <= 0 ) {
     			Message::set(Message::ERROR, 'Аккаунт заблокирован. Пожалуйста, пополните счет');
     			$this->request->redirect('/cabinet/payment/add');
     		}*/
     if (!empty($this->user->expires)) {
         $exp = Date::diff($user_expires->format("Y-m-d"), date("Y-m-d"), 'days');
         $exp++;
         // текущий день - опказываем как день
         if ($exp >= 0 && $exp <= 5) {
             Message::set(Message::NOTICE, 'Внимание, осталось <strong>' . $exp . " " . MyHelper::morph($exp, "день", "дня", "дней") . ' </strong> использования аккаунтом');
         }
     }
     $this->template->bc['cabinet'] = 'Личный кабиент';
 }
Exemplo n.º 22
0
 public function action_approvals($key)
 {
     $settings = ORM::factory('key')->where('key', '=', $key)->find();
     if ($settings->type == "settings" && $settings->user->id) {
         if (!empty($_POST)) {
             $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
             foreach ($data as $name => $dtItem) {
                 $nameParts = explode("_", $name);
                 if (is_numeric($nameParts[1])) {
                     $editUser = ORM::factory("user", $nameParts[1]);
                     if ($editUser->loaded()) {
                         $editUser->sendmessages = $dtItem;
                         $editUser->save();
                     }
                 }
             }
             Message::set(Message::SUCCESS, "Your settings have been updated.");
         }
         $users = ORM::factory("user")->where("email", "=", $settings->user->email)->find_all();
         $this->template->content = View::factory("settings/approvals");
         $this->template->content->users = $users;
         $this->template->content->key = $settings->key;
     } else {
         $this->template->content = "Invalid link. Please try the next email.";
     }
 }
Exemplo n.º 23
0
 private function addAward()
 {
     $success = true;
     $errors = array();
     $data = Arr::merge($this->sanitize($_POST), $_FILES);
     Upload::$default_directory = Kohana::config('myshot.basePath');
     if ($stage_path = Upload::save($data['photo'])) {
         $award = $this->site->createAward($this->sanitize($data['name']), $data);
         foreach ($this->site->imageTypes as $imageType) {
             $name = $imageType->name;
             if ($name == self::FULL) {
                 Library_Akamai::factory()->addToDir($stage_path, Kohana::config('akamai.honordir'));
                 $award->addImage(self::FULL, $this->webPath($stage_path));
             } else {
                 if (ImageTypes::types()->{$name}) {
                     $resized = $this->resizeHonor($stage_path, ImageTypes::types()->{$name}->size);
                     $award->addImage($name, $this->webPath($resized));
                 }
             }
         }
     } else {
         $success = false;
         $errors[] = "Image failed to load.";
     }
     if ($success) {
         Message::set(Message::SUCCESS, 'You have successfully added an award.');
         Request::instance()->redirect('admin/awards');
     } else {
         Message::set(Message::ERROR, Arr::flatten($errors));
     }
 }
Exemplo n.º 24
0
 public function action_delete()
 {
     $dispute = ORM::factory('admin_dispute', $this->request->param('id', NULL));
     if (!$dispute->loaded()) {
         Message::set(Message::ERROR, 'Такое дополнение не найдено');
         $this->request->redirect('admin/development');
     }
     $task_url = 'admin/development/task/view/' . $dispute->task->id;
     if ($_POST) {
         $actions = Arr::extract($_POST, array('submit', 'cancel'), FALSE);
         /*
         if ($actions['cancel'])
             $this->request->redirect('admin/development/task/view/'.$dispute->task->id);
         */
         if ($actions['submit']) {
             $dispute->delete();
             Message::set(Message::SUCCESS, 'Дополнение к задаче удалено');
         }
         $this->request->redirect($task_url);
     }
     $this->view = View::factory('backend/delete')->set('url', $this->request->uri())->set('from_url', $task_url)->set('title', 'Удаление дополнения к задаче')->set('text', 'Вы действительно хотите удалить дополнение к задаче "' . $dispute->task->title . '"');
     $this->template->title = 'Удаление дополнения к задаче';
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemplo n.º 25
0
 /**
  * Checkout
  */
 public function action_checkout()
 {
     $errors = [];
     $cart_contents = $this->cart->contents();
     if (empty($cart_contents)) {
         $this->redirect(Route::url('f_cart'));
     }
     /**
      * @var $obj_customer Model_Shop_Customer
      */
     $obj_customer = ORM::factory('Shop_Customer');
     /**
      * @var $obj_order Model_Shop_Order
      */
     $obj_order = ORM::factory('Shop_Order');
     $sel_deliveries = ORM::factory('Shop_Order_Delivery')->find_for_select('id', 'title');
     $delivery_id = Arr::get($_POST, 'delivery_id', 1);
     if (!in_array($delivery_id, Model_Shop_Order_Delivery::get_arr_valid_ids())) {
         $delivery_id = 1;
     }
     if ($this->request->is_post()) {
         $obj_customer->pre_post();
         $obj_customer->where('phone', '=', Arr::get($_POST, 'phone'))->find();
         if (!$obj_customer->loaded()) {
             $obj_customer = ORM::factory('Shop_Customer');
         }
         $obj_customer->values($_POST);
         try {
             $obj_customer->save();
         } catch (ORM_Validation_Exception $e) {
             Message::set('error', 'Ошибка при оформлении заказа!');
             $errors = $e->errors('validation');
         }
         if (empty($errors)) {
             // Сохраняем новый заказ
             $order_id = $obj_order->add_order($obj_customer->id, $delivery_id, $this->cart->total());
             /**
              * @var $obj_order_product Model_Shop_Order_Product
              */
             $obj_order_product = ORM::factory('Shop_Order_Product');
             // Сохраняем заказанные товары
             $obj_order_product->add_order_products($order_id, $cart_contents);
             // Отправляем mail
             if (Mail::order($obj_customer->email, $order_id)) {
                 //Message::set('success', 'Mail sent');
             } else {
                 //Message::set('error', 'Mail not send');
             }
             $this->cart->destroy();
             //Message::set('success', 'Ваш заказ успешно отправлен на обработку!');
             $this->redirect(Route::url('f_cart', ['action' => 'checked', 'rowid' => $order_id]));
         }
     }
     // Views
     $this->breadcrumbs = View::factory('frontend/v_breadcrumbs')->set('page_title', __('Оформление заказа'));
     $v_delivery_address = View::factory('shop/frontend/cart/v_delivery_addr_' . $delivery_id, ['obj_order' => $obj_order, 'errors' => $errors])->bind('v_addresses', $v_addresses);
     $this->content = View::factory('shop/frontend/cart/v_cart_checkout', ['v_delivery_address' => $v_delivery_address, 'sel_deliveries' => $sel_deliveries, 'obj_customer' => $obj_customer, 'obj_order' => $obj_order, 'cart' => $this->cart, 'errors' => $errors]);
 }
Exemplo n.º 26
0
 public function action_set($id)
 {
     $photo = ORM::factory("photo", filter_var($id, FILTER_SANITIZE_NUMBER_INT));
     if ($photo->loaded() && !empty($_POST['day'])) {
         Model_DailyPhoto::setPhoto($photo, $_POST['day']);
         Message::set(Message::SUCCESS, "Photo set as photo of the day!");
     }
     $this->request->redirect("photos/view/{$photo->id}");
 }
Exemplo n.º 27
0
 public function action_preview($id)
 {
     $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
     $homeSpot = ORM::factory("homespot", $id);
     if (!$homeSpot->loaded()) {
         Message::set(Message::ERROR, "Sorry, that could not be found.");
         $this->request->redirect("admin/home/create");
         return;
     }
     $this->template->title = 'Share Your Photos - National Geographic Kids My Shot Community';
     $this->template->scripts = array('public/js/vendor/jquery.jcarousel.js', 'public/js/categories/slideshow.js', 'public/js/home/home.js');
     $awards = array();
     $badges = array();
     $events = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Model_Game_Site::HONOR_GIVEN))->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all();
     foreach ($events as $event) {
         $eventUser = ORM::factory('user', $event->user->user_id);
         if ($eventUser->id) {
             if ($event->data->type == "game_Badge") {
                 $obj = new stdClass();
                 $obj->data = $event->data;
                 $obj->honor = ORM::factory($event->data->type, $event->data->honor_id);
                 $obj->user = ORM::factory('user', $event->user->user_id);
                 $badges[] = $obj;
             }
         }
         if (count($badges) >= $this->maxBadges) {
             break;
         }
     }
     if (count($awards) < $this->maxAwards) {
         $aevents = ORM::factory('game_EventLog')->where('event_id', '=', Helper_Game::getSite()->getEvent(Helper_Game::AWARD_GIVEN)->id)->order_by('time_stamp', 'DESC')->limit($this->sampleSize)->find_all();
         foreach ($aevents as $event) {
             $obj = new stdClass();
             $obj->data = $event->data;
             $obj->honor = ORM::factory($event->data->type, $event->data->honor_id);
             $obj->user = ORM::factory('user', $event->user->user_id);
             $obj->photo = ORM::factory('photo', $event->item->item_id);
             $awards[] = $obj;
             if (count($awards) >= $this->maxAwards) {
                 break;
             }
         }
     }
     $honors = array_merge($awards, $badges);
     if (count($honors) == 0) {
         $honors = false;
     }
     $slider = Model_DLSliderGroup::getCurrentSlider();
     if ($slider) {
         $this->template->top = View::factory("home/slider");
         $this->template->top->slider = $slider;
     }
     $this->template->content = View::factory('home/index');
     $this->template->content->set(array('user' => $this->user, 'recently_added' => Reel_More::factory(ORM::factory('photo')->order_by('created', 'desc')), 'top_rated' => Reel_More::factory(Helper_Photos::get_top_rated()), 'honors' => $honors, 'potd' => Model_DailyPhoto::todaysPhoto(), 'homeSpot' => $homeSpot, 'homeSpotEditLink' => HTML::anchor("admin/home/edit/{$homeSpot->id}", "Edit")));
     $this->template->sidebar = Widget::factory()->add(Helper_Default::sidebar());
 }
Exemplo n.º 28
0
 private function add_category()
 {
     $category = ORM::factory('category');
     if ($category->values($_POST)->check()) {
         $category->save();
         Message::set(Message::SUCCESS, 'You have successfully added a category.');
         Request::instance()->redirect('admin/categories');
     } else {
         Message::set(Message::ERROR, Arr::flatten($category->validate()->errors('admin/category')));
     }
 }
Exemplo n.º 29
0
 public function action_edit($id)
 {
     $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
     $page = ORM::factory("page", $id);
     if (!$page->loaded()) {
         Message::set(Message::ERROR, "Sorry, that page could not be found.");
         $this->request->redirect("admin/pages/create");
         return;
     }
     $this->editorPublic();
     $this->template->content = View::factory("admin/pages/edit")->set("page", $page);
 }
Exemplo n.º 30
0
 public function action_view()
 {
     $article = ORM::factory('content_article', $this->request->param('id', NULL));
     if (!$article->loaded()) {
         Message::set(Message::ERROR, 'Статья не найдена');
         $this->request->redirect('articles');
     }
     $this->template->title = $article->title;
     $this->template->bc['#'] = $this->template->title;
     $this->view = View::factory('frontend/article/view')->set('article', $article);
     $this->template->content = $this->view;
 }