Example #1
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());
 }
Example #2
0
 public function action_createOrUpdateBrand()
 {
     try {
         $post = Validate::factory($_POST)->rule('brand_full_name', 'not_empty')->rule('brand_short_name', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR";
             die;
         }
         $brand_full_name = $_POST['brand_full_name'];
         $brand_short_name = $_POST['brand_short_name'];
         $brand_id = $_POST['brand_id'];
         $brand = new Model_Brand();
         if ($brand_id != 0) {
             $brand = ORM::factory('Brand', $brand_id);
         }
         $brand->fullName = trim($brand_full_name);
         $brand->shortName = trim($brand_short_name);
         $brand->status = $this->GENERAL_STATUS['ACTIVE'];
         $brand->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Example #3
0
 public function action_create()
 {
     // Check if the user has a character already.
     if ($this->character->loaded()) {
         $this->request->redirect('character/create');
     }
     $character = Jelly::factory('character');
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('name', 'not_empty')->rule('name', 'min_length', array(3))->rule('name', 'max_length', array(20))->rule('gender', 'not_empty')->rule('race', 'not_empty')->callback('race', array($this, 'valid_race'));
     if ($post->check()) {
         try {
             $values = array('name' => $post['name'], 'gender' => $post['gender'], 'race' => $post['race'], 'user' => $this->user->id, 'money' => 1000, 'hp' => 100, 'max_hp' => 100, 'level' => 1, 'xp' => 0, 'energy' => 100, 'alignment' => 5000, 'zone' => 1);
             $character->set($values);
             $character->save();
             $this->MG->add_history('Created the character: ' . $post['name']);
             $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');
     }
     // Get the races the user can choose from.
     $races = $this->getRaces();
     $this->template->content = View::factory('character/create')->set('post', $post)->set('races', $races);
 }
Example #4
0
 public function action_index()
 {
     $this->content->bind('errors', $errors);
     $this->content->bind('success', $success);
     $this->content->bind('form', $form);
     $this->content->bind('fields', $fields);
     $form = $this->company;
     $success = FALSE;
     $fields = array('name' => 'Nazwa firmy', 'account' => 'Numer konta', 'address' => 'Adres', 'nip' => 'NIP');
     if ($_POST) {
         $form = array_intersect_key($_POST, $fields);
         $validate = Validate::factory($form)->labels($fields)->rule(TRUE, 'not_empty')->rule('account', 'account_number')->rule('nip', 'nip');
         if (!$validate->check()) {
             $errors = $validate->errors('validate');
             $form = (object) $form;
         } else {
             foreach ($form as $k => $v) {
                 $this->company->set($k, $v);
             }
             $form = $this->company;
             $success = TRUE;
         }
     }
     $fields = (object) $fields;
 }
 public function action_createOrUpdateDiscount()
 {
     try {
         $post = Validate::factory($_POST)->rule('discount_value', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR";
             die;
         }
         $dicount_value = $_POST['discount_value'];
         $discount_id = $_POST['discount_id'];
         $discount = new Model_Discount();
         if ($discount_id != 0) {
             $discount = ORM::factory('Discount', $discount_id);
         } else {
             $discount->registrationDate = Date::formatted_time();
         }
         $discount->discount = trim($dicount_value);
         $discount->status = $this->GENERAL_STATUS['ACTIVE'];
         $discount->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Example #6
0
 function sendorder()
 {
     $check = Validate::factory($_POST)->label('fio', 'ФИО')->label('address', 'адрес')->label('phone', 'телефон')->label('email', 'EMail')->rule('fio', 'not_empty')->rule('address', 'not_empty')->rule('phone', 'not_empty')->rule('phone', 'phone')->rule('email', 'not_empty')->rule('email', 'email');
     if ($check->check()) {
         //$order = ORM::factory('good', $_POST['orderid'])->as_array();
         $session = Session::instance();
         $_SESSION =& $session->as_array();
         $orders = '<b>Наименования:</b><br>';
         $price = 0;
         foreach ($_SESSION['orders'] as $k => $v) {
             $orders .= $_SESSION['orders'][$k]['name'] . ' (ID: ' . $_SESSION['orders'][$k]['id'] . ') - ' . $_SESSION['orders'][$k]['price'] . ' грн. (' . $_SESSION['orders'][$k]['count'] . '&nbsp;' . $_SESSION['orders'][$k]['select'] . ')<br>';
             $cof = $_SESSION['orders'][$k]['select'] == 'kg' ? $_SESSION['orders'][$k]['count'] : $_SESSION['orders'][$k]['count'] / 1000;
             $price += $_SESSION['orders'][$k]['price'] * $cof;
         }
         $text = '<b>ФИО:</b>&nbsp;' . $_POST['fio'] . '<br>
                  <b>Адрес:</b>&nbsp;' . $_POST['address'] . '<br>
                  <b>Телефон:</b>&nbsp;' . $_POST['phone'] . '<br>
                  <b>EMail:</b>&nbsp;' . $_POST['email'] . '<br>' . $orders . '<p><b>Итоговая цена без доставки:</b> ' . $price;
         $mailer = email::connect();
         $message = Swift_Message::NewInstance('Новый заказ', $text, 'text/html', 'utf-8');
         $message->setTo('*****@*****.**');
         $message->setFrom('*****@*****.**');
         $mailer->send($message);
         Session::instance()->delete('orders');
         return TRUE;
     } else {
         return strtolower(implode(' и ', $check->errors('')));
     }
 }
Example #7
0
 public function action_createOrUpdateMenu()
 {
     try {
         $post = Validate::factory($_POST)->rule('menu_name', 'not_empty')->rule('menu_url', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $menu_name = $_POST['menu_name'];
         $menu_url = $_POST['menu_url'];
         $super_menu_id = $_POST['idSuperMenu'];
         $menu_id = $_POST['idMenu'];
         $menu = new Model_Menu();
         if ($menu_id != 0) {
             $menu = ORM::factory('Menu', $menu_id);
         }
         $menu->name = trim($menu_name);
         $menu->url = trim($menu_url);
         if ($_POST['menu_type'] == $this->MENU_TYPE['MENU']) {
             $menu->type = $this->MENU_TYPE['MENU'];
         } else {
             $menu->type = $this->MENU_TYPE['ACTION'];
         }
         if ($super_menu_id != 0) {
             $menu->idSuperMenu = $super_menu_id;
         }
         $menu->status = $this->GENERAL_STATUS['ACTIVE'];
         $menu->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Example #8
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);
 }
Example #9
0
 /**
  * Display login form and perform login
  */
 public function action_login()
 {
     Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Auth::action_login');
     // If user is already logged in, redirect to admin main
     if ($this->a2->logged_in()) {
         Kohana::$log->add('ACCESS', "Attempt to login made by logged-in user");
         Kohana::$log->add(Kohana::DEBUG, "Attempt to login made by logged-in user");
         Message::instance()->error(Kohana::message('a2', 'login.already'));
         $this->request->redirect(Route::get('admin')->uri());
     }
     $this->template->content = View::factory('admin/auth/login')->bind('post', $post)->bind('errors', $errors);
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('password', 'not_empty')->callback('username', array($this, 'check_username'));
     if ($post->check()) {
         if ($this->a1->login($post['username'], $post['password'], !empty($post['remember']))) {
             Kohana::$log->add('ACCESS', 'Successful login made with username, ' . $post['username']);
             Message::instance()->info(Kohana::message('a2', 'login.success'), array(':name' => $post['username']));
             // If external request, redirect to referring URL or admin main
             if (!$this->_internal) {
                 // Get referring URI, if any
                 $referrer = $this->session->get('referrer') ? $this->session->get('referrer') : Route::get('admin')->uri();
                 $this->session->delete('referrer');
                 $this->request->redirect($referrer);
             }
         } else {
             Kohana::$log->add('ACCESS', 'Unsuccessful login attempt made with username, ' . $post['username']);
             $post->error('password', 'incorrect');
         }
     }
     $errors = $post->errors('admin');
 }
Example #10
0
 public function action_index()
 {
     $this->template->content = View::factory('contact/email')->bind('post', $post)->bind('errors', $errors)->bind('work_types', $work)->bind('budget_types', $budget);
     // Project type
     $work = array('development' => 'Web Development', 'database' => 'Database Design', 'review' => 'Code Review', 'kohana' => 'KohanaPHP Consulting', 'other' => 'Other');
     // Project budget
     $budget = array('under_500' => 'Under $500', 'under_1000' => '$500 - $1000', 'under_5000' => '$1000 - $5000', 'over_5000' => '$5000 or more');
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('name', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('work', 'not_empty')->rule('work', 'in_array', array(array_keys($work)))->rule('description', 'not_empty')->rule('budget', 'not_empty')->rule('budget', 'in_array', array(array_keys($budget)));
     if ($post->check()) {
         // Create the email body
         $body = View::factory('template/lead')->set('name', $post['name'])->set('work', $work[$post['work']])->set('budget', $budget[$post['budget']])->set('description', $post['description'])->render();
         // Get the email configuration
         $config = Kohana::config('email');
         // Load Swift Mailer support
         require Kohana::find_file('vendor', 'swift/lib/swift_required');
         // Create an email message
         $message = Swift_Message::newInstance()->setSubject('w.ings consulting: New Lead from ' . $post['name'])->setFrom(array($post['email'] => $post['name']))->setTo(array('*****@*****.**' => 'Woody Gilk'))->setBody(strip_tags($body))->addPart($body, 'text/html');
         // Connect to the server
         $transport = Swift_SmtpTransport::newInstance($config->server, 25)->setUsername($config->username)->setPassword($config->password);
         // Send the message
         Swift_Mailer::newInstance($transport)->send($message);
         // Redirect to the thanks page
         $this->request->redirect(url::site($this->request->uri(array('action' => 'hire'))));
     } else {
         $errors = $post->errors('forms/contact');
     }
 }
Example #11
0
 public function action_index()
 {
     $this->template->content = View::factory('admin/projects/create')->bind('post', $post)->bind('errors', $errors)->bind('associates', $assoc);
     $assoc = DB::query(Database::SELECT, 'SELECT id, name FROM associates ORDER BY name')->execute()->as_array('id', 'name');
     // Add an option for "no associate"
     arr::unshift($assoc, 0, '- none -');
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('title', 'not_empty')->rule('title', 'regex', array('/^[\\pL\\pP\\s]{4,255}$/iu'))->rule('associate_id', 'not_empty')->rule('associate_id', 'in_array', array(array_keys($assoc)))->rule('completed', 'not_empty')->rule('completed', 'date')->rule('website', 'regex', array('#^https?://.+$#'));
     if ($post->check($errors)) {
         if (empty($post['associate_id'])) {
             // Make the associate NULL
             $post['associate_id'] = NULL;
             // Use only the title for the slug
             $post['slug'] = url::title($post['title']);
         } else {
             // Use the title with associate for the slug
             $post['slug'] = url::title($post['title']) . '/with/' . url::title($assoc[$post['associate_id']]);
         }
         if (empty($post['website'])) {
             // Make the website value NULL
             $post['website'] = NULL;
         }
         // Get the values of the array
         $values = $post->as_array();
         // Convert the completed date into a timestamp
         $values['completed'] = strtotime($values['completed']);
         $query = DB::query(Database::INSERT, 'INSERT INTO projects (title, associate_id, completed, website, slug) VALUES (:values)')->bind(':values', $values)->execute();
         // Set a cookie message
         cookie::set('message', 'Created new project with an ID of ' . $query);
         // Redirect back to the same page
         $this->request->redirect(url::site($this->request->uri));
     }
 }
 public function action_createOrDeleteAccess()
 {
     try {
         $post = Validate::factory($_POST)->rule('menu_id', 'not_empty')->rule('group_id', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $menu_id = $_POST['menu_id'];
         $group_id = $_POST['group_id'];
         $privilege = new Model_Privilege();
         $privilege = ORM::factory('Privilege')->where('idMenu', '=', $menu_id)->where('idGroup', '=', $group_id)->find();
         if ($privilege->loaded() == TRUE) {
             $privilege->delete();
         } else {
             $privilege->idMenu = $menu_id;
             $privilege->idGroup = $group_id;
             $privilege->grantDate = Date::formatted_time();
             $privilege->idUser = $this->getSessionParameter('user_id');
             $privilege->save();
         }
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Example #13
0
 public function action_edit($id)
 {
     $message = Jelly::select('forum_post')->where('id', '=', $id)->load();
     // Make sure the post exists
     if (!$message->loaded()) {
         Message::set(Message::ERROR, 'Post does not exist');
         $this->request->redirect('forum');
     }
     if ($this->user->id != $message->user->id) {
         Message::set(Message::ERROR, 'You are not the author of this post.');
         $this->request->redirect('forum');
     } else {
         $this->title = 'Forum - Edit ' . $message->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);
             // Assign the validated data to the Jelly object
             $message->title = $post['title'];
             $message->content = $post['content'];
             $message->save();
             Message::set(Message::SUCCESS, 'Post has been edited.');
             $this->request->redirect('forum');
         }
         $this->template->content = View::factory('forum/post/edit')->set('message', $message)->set('post', $post);
     }
 }
Example #14
0
 public function action_index()
 {
     $supplychain_alias = ORM::factory('supplychain_alias');
     $page = max($this->request->param('page'), 1);
     $items = 20;
     $offset = $items * ($page - 1);
     $count = $supplychain_alias->count_all();
     $pagination = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'page'), 'total_items' => $supplychain_alias->count_all(), 'items_per_page' => $items));
     $this->template->supplychain_alias = $supplychain_alias->limit($pagination->items_per_page)->offset($pagination->offset)->find_all()->as_array(null, array('id', 'site', 'alias', 'supplychain_id'));
     $this->template->page_links = $pagination->render();
     $this->template->offset = $pagination->offset;
     $supplychain_alias_count = $supplychain_alias->count_all();
     $post = Validate::factory($_POST);
     $post->rule('site', 'not_empty')->rule('alias', 'not_empty')->filter('site', 'strip_tags')->filter('alias', 'strip_tags')->rule('supplychain_id', 'not_empty')->filter(true, 'trim');
     if (strtolower(Request::$method) === 'post' && $post->check()) {
         $check = false;
         $post = (object) $post->as_array();
         $site_added = $post->site;
         $alias_added = $post->alias;
         $id = $post->supplychain_id;
         // check if the alias already exists, if not add new alias
         $supplychain_alias = ORM::factory('supplychain_alias');
         $supplychain_alias->supplychain_id = $id;
         $supplychain_alias->site = $site_added;
         $supplychain_alias->alias = $alias_added;
         try {
             $supplychain_alias->save();
         } catch (Exception $e) {
             Message::instance()->set('Could not create alias. Violates the unique (site, alias)');
         }
         $this->request->redirect('admin/aliases');
     }
     Breadcrumbs::instance()->add('Management', 'admin/')->add('Aliases', 'admin/aliases');
 }
Example #15
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());
 }
 public function action_createOrUpdateOfficeLocation()
 {
     try {
         $post = Validate::factory($_POST)->rule('office_location_name', 'not_empty')->rule('office_location_address', 'not_empty')->rule('office_location_country', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $office_location_id = StringHelper::cleanEmptyString4NULL($_POST['office_location_id']);
         $office_location_name = StringHelper::cleanEmptyString4NULL($_POST['office_location_name']);
         $office_location_address = StringHelper::cleanEmptyString4NULL($_POST['office_location_address']);
         $office_location_country = StringHelper::cleanEmptyString4NULL($_POST['office_location_country']);
         $office_location = new Model_Officelocation();
         if ($office_location_id != 0) {
             $office_location = ORM::factory('Officelocation', $office_location_id);
         }
         $office_location->name = trim($office_location_name);
         $office_location->address = trim($office_location_address);
         $office_location->status = $this->GENERAL_STATUS['ACTIVE'];
         $office_location->idCountry = $office_location_country;
         $office_location->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Example #17
0
 public function action_login()
 {
     if ($this->session->get('tsuser')) {
         $this->request->redirect('timesheet/index');
     }
     if (count($_POST)) {
         $post = Validate::factory($_POST)->rule('tsuser', 'not_empty')->rule('tspass', 'not_empty');
         if ($post->check()) {
             $user = ORM::factory('User')->where('USUARIO', '=', $post['tsuser'])->find();
             if ($user->RECNO) {
                 $this->session->set('tsuser', $user->RECNO);
                 $this->session->set('tsdepto', $user->DEPTO);
                 if (strpos(" " . $user->DEPTO, "PG") != 0) {
                     $this->request->redirect('timesheet/alarm');
                 } else {
                     $this->request->redirect('timesheet/index');
                 }
             } else {
                 $errors = array('usuario ou senha invalidos');
             }
         } else {
             $errors = $post->errors('user');
         }
     }
     $this->request->response = View::factory('user.login')->bind('post', $post)->bind('errors', $errors);
 }
Example #18
0
 public function action_rm()
 {
     if (!(strtolower(Request::$method) == 'post')) {
         Message::instance()->set('I\'m not sure what you\'re trying to do, but stop it.');
         $this->request->redirect('admin/taxonomy');
     }
     $post = Validate::factory($_POST);
     $post->rule('taxonomy_id', 'not_empty')->rule('taxonomy_id', 'is_numeric');
     if ($post->check()) {
         $t = ORM::factory('category', $post['taxonomy_id']);
         if ($t->loaded()) {
             try {
                 $t->drop_subtree();
                 $this->request->redirect('admin/taxonomy');
             } catch (Exception $e) {
                 Message::instance()->set('Could not drop subtree: ' . $e->getMessage());
                 $this->request->redirect('admin/taxonomy');
             }
         } else {
             Message::instance()->set('That category does not exist.');
             $this->request->redirect('admin/taxonomy');
         }
     } else {
         Message::instance()->set('Bad request.');
         $this->request->redirect('admin/taxonomy');
     }
 }
 public function action_createOrUpdateWarehouse()
 {
     try {
         $post = Validate::factory($_POST)->rule('warehouse_name', 'not_empty')->rule('warehouse_short_name', 'not_empty')->rule('warehouse_office_location', 'not_empty');
         if (!$post->check()) {
             echo "0|ERROR - Empty Data Post";
             die;
         }
         $warehouse_id = StringHelper::cleanEmptyString4NULL($_POST['warehouse_id']);
         $warehouse_name = StringHelper::cleanEmptyString4NULL($_POST['warehouse_name']);
         $warehouse_short_name = StringHelper::cleanEmptyString4NULL($_POST['warehouse_short_name']);
         $warehouse_office_location = StringHelper::cleanEmptyString4NULL($_POST['warehouse_office_location']);
         $warehouse = new Model_Warehouse();
         if ($warehouse_id != 0) {
             $warehouse = ORM::factory('Warehouse', $warehouse_id);
         }
         $warehouse->name = trim($warehouse_name);
         $warehouse->shortName = trim($warehouse_short_name);
         $warehouse->status = $this->GENERAL_STATUS['ACTIVE'];
         $warehouse->idOfficeLocation = $warehouse_office_location;
         $warehouse->save();
         echo "1|ok";
     } catch (Exception $exc) {
         echo "0|" . $exc->getTraceAsString();
     }
     die;
 }
Example #20
0
 /**
  * Update client
  *
  * @access	public
  * @param	int	    $user_id
  * @param	array	$params
  *      confirm_type: Request confirm, 0: every time; 1: only once; 2: with expired period; 3: once and banned
  *      client_level: diferent client levels have different max request times
  *      expired_date: date time
  *
  * @return	mix     update rows affect or validate object
  */
 public function update($user_id, array $params)
 {
     if (isset($params['expired_date']) and $timetamp = strtotime($params['expired_date'])) {
         $params['expired_date'] = $timetamp;
     } else {
         unset($params['expired_date']);
     }
     $valid = Validate::factory($params);
     $rules = array_intersect_key(array('client_id' => array('not_empty' => NULL, 'max_length' => array(128)), 'redirect_uri' => array('not_empty' => NULL, 'max_length' => array(512)), 'confirm_type' => array('range' => array(0, 255)), 'client_level' => array('range' => array(0, 255)), 'modified' => array('not_empty' => NULL, 'range' => array(0, 4294967295)), 'created' => array('range' => array(0, 4294967295)), 'scope' => array('max_length' => array(512)), 'expired_date' => array('range' => array(0, 4294967295)), 'client_desc' => array('max_length' => array(65535))), $params);
     foreach ($rules as $field => $rule) {
         foreach ($rule as $r => $p) {
             $valid->rule($field, $r, $p);
         }
     }
     if ($valid->check()) {
         $valid = $valid->as_array();
         foreach ($valid as $key => $val) {
             if ($val === '') {
                 $valid[$key] = NULL;
             }
         }
         $valid['update_by'] = OALite::$user['uid'];
         $valid['update_time'] = $_SERVER['REQUEST_TIME'];
         return DB::update('t_oauth_clients')->set($valid)->where('user_id', '=', $user_id)->execute($this->_db);
     } else {
         // Validation failed, collect the errors
         return $valid;
     }
 }
Example #21
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();
 }
 /**
  * 设置
  */
 public function action_set()
 {
     $pay = ORM::factory('payment', $this->getQuery('adapter'));
     if (!$pay->loaded()) {
         echo 'ID错误';
         exit;
     }
     if ($_POST) {
         $post = Validate::factory($this->getPost())->filter(TRUE, 'trim')->rule('adapter', 'not_empty')->rule('pay_name', 'not_empty')->rule('pay_key', 'not_empty');
         if ($post->check()) {
             $pay->pay_name = $_POST['pay_name'];
             $pay->enabled = isset($_POST['enabled']) ? 1 : 0;
             $pay->online = isset($_POST['online']) ? 1 : 0;
             $pay->pay_fee = floatval($_POST['pay_fee']);
             $pay->pay_desc = $_POST['pay_desc'];
             $pay->pay_key = $_POST['pay_key'];
             $pay->receive_url = $_POST['receive_url'];
             $pay->sort_order = intval($_POST['sort_order']);
             $arr_config_new = array();
             $arr_config = $_POST['config'];
             for ($i = 0, $max = count($arr_config['key']); $i < $max; $i++) {
                 $arr_config_new[$arr_config['key'][$i]] = $arr_config['val'][$i];
             }
             $pay->config = serialize($arr_config_new);
             $pay->save();
             $this->request->redirect('/admin/payment');
         } else {
             $errors = $post->errors('/admin/payment');
             $this->show_message($errors);
         }
     }
     $this->template->pay = $pay;
 }
Example #23
0
 /**
  * 提交积分任务
  */
 public function action_sumbit()
 {
     if ($this->isPost()) {
         //数据验证
         $post = Validate::factory($this->getPost())->filter(TRUE, 'trim')->rule('job_title', 'not_empty')->rule('job_url', 'not_empty');
         if ($post->check()) {
             $job_title = trim($this->getPost('job_title'));
             $job_url = trim($this->getPost('job_url'));
             if (!eregi('^https?://', $job_url)) {
                 $job_url = 'http://' . $job_url;
             }
             $rows = DB::select()->from('imgup_job')->where('title', '=', $job_title)->where('url', '=', $job_url)->execute()->current();
             if (!empty($rows)) {
                 $note = '';
                 if ($rows['uid'] != $this->auth['uid']) {
                     $note .= '此帖已被其他会员提交,<br />';
                 }
                 $note .= '请勿重复提交任务';
                 $this->show_message($note, 0, array(), true, 10000);
             }
             $date = array('uid' => $this->auth['uid'], 'uname' => $this->auth['username'], 'submit_date' => date('Y-m-d H:i:s'), 'title' => $job_title, 'url' => $job_url);
             DB::insert('imgup_job', array_keys($date))->values(array_values($date))->execute();
             $links[] = array('text' => '查看任务列表', 'href' => '/job#list');
             $this->show_message('提交任务成功', 1, $links, true);
         } else {
             $this->show_message($post->errors(''));
         }
     }
 }
 public function action_login()
 {
     if (empty($_POST['usernamePost']) || empty($_POST['usernamePost'])) {
         $this->action_logout();
     }
     $user = ORM::factory('User');
     $post = Validate::factory($_POST)->rule('usernamePost', 'not_empty')->rule('passwordPost', 'not_empty');
     if ($post->check()) {
         $user = $user->where('userName', '=', $_POST['usernamePost'])->where('password', '=', $_POST['passwordPost'])->find();
         if ($user->loaded()) {
             Session::instance('database');
             $this->setSessionParameter('session_id', Session::instance('database')->id());
             $this->setSessionParameter('user_name', $user->userName);
             $this->setSessionParameter('user_id', $user->idUser);
             $this->setSessionParameter('user_group_id', $user->group->idGroup);
             $this->setSessionParameter('permited_actions', array());
             //                if ($user->idGroup == 1)
             echo "1|/private/index/index|Ok";
             //                if ($user->idGroup == 2)
             //                    echo "1|/vendedor/index";
             die;
         } else {
             echo "0|0|" . __("Usuario o contraseña no válidos");
             die;
         }
     }
 }
Example #25
0
 public function action_index()
 {
     $view = View::factory('kadldap/index');
     $this->template->content = $view;
     $this->template->title = 'Kadldap';
     $this->template->menu = NULL;
     $this->template->breadcrumb = array(Route::get('docs/guide')->uri() => __('User Guide'), Route::get('docs/guide')->uri() . '/kadldap.about' => $this->template->title, 'Configuration Test');
     $view->message = FALSE;
     if (isset($_POST['login'])) {
         $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('username', 'min_length', array(1))->rule('password', 'not_empty');
         if ($post->check()) {
             $username = $post['username'];
             $password = arr::get($post, 'password', '');
             try {
                 if (Auth::instance()->login($username, $password)) {
                     $view->message = 'Successful login.';
                 } else {
                     $view->message = 'Login failed.';
                 }
             } catch (adLDAPException $e) {
                 $view->message = $e->getMessage();
             }
         } else {
             $view->message = 'You must enter both your username and password.';
         }
     }
     if (Auth::instance()->logged_in()) {
         $username = Auth::instance()->get_user();
         $password = Auth::instance()->password($username);
         $view->kadldap = Kadldap::instance();
         $view->kadldap->authenticate($username, $password);
     }
 }
Example #26
0
 /**
  * Creates validation functionality for Tags, takes $_POST data.
  *
  * @param array $array 
  * @return void
  * @author Merrick Christensen
  */
 public function validate_create(&$array)
 {
     // Initialize the validation library and setup some rules
     $array = Validate::factory($array)->rules('tag', $this->rules['tag'])->filters(TRUE, array('trim' => NULL, 'htmlspecialchars' => NULL, 'strip_tags' => NULL, 'strtolower' => NULL));
     $array->callback('tag', array($this, 'censor'));
     return $array;
 }
Example #27
0
 public function action_index()
 {
     $select = DB::select()->from('imgup_config')->order_by('id', 'DESC')->limit('1')->execute()->current();
     $this->template->rows = $select;
     if ($this->isPost()) {
         $post = Validate::factory($this->getPost())->filter(TRUE, 'trim')->rule('allowed_ext', 'not_empty')->rule('admin_email', 'not_empty')->rule('max_upload', 'not_empty')->rule('max_upload', 'numeric')->rule('unit', 'not_empty');
         if ($post->check()) {
             $id = (int) $this->getPost('id');
             $max_B = $this->getPost('max_upload') . ':' . $this->getPost('unit');
             $set = array('allowed_ext' => trim($this->getPost('allowed_ext')), 'admin_email' => $this->getPost('admin_email'), 'max_upload' => $max_B, 'tmp_message_top' => trim($this->getPost('tmp_message_top')), 'marquee_message' => trim($this->getPost('marquee_message')), 'show_top' => (int) $this->getPost('show_top'));
             if ($id > 0) {
                 DB::update('imgup_config')->set($set)->where('id', '=', $id)->execute();
                 Cache::instance()->delete('sys_configs');
                 @unlink(DOCROOT . 'cache/index.html');
                 @shell_exec('. /server/wal8/www/bin/clearcache.sh http://www.wal8.com/cache/index.html');
                 $links[] = array('text' => '返回列表', 'href' => '/admin/system');
                 $this->show_message('修改资料成功', 1, $links, true);
             }
         } else {
             // 校验失败,获得错误提示
             $str = '';
             $this->template->registerErr = $errors = $post->errors('admin/module');
             foreach ($errors as $item) {
                 $str .= $item . '<br>';
             }
             $this->show_message($str);
         }
     }
 }
Example #28
0
 public function action_get()
 {
     $get = Validate::factory($_GET);
     $get->rule('latitude', 'numeric')->rule('longitude', 'numeric')->rule('placename', 'max_length', array(128))->rule('placename', 'not_empty')->rule('supplychain_id', 'numeric')->rule('projection', 'regex', array('/epsg:[\\w\\d]+/i'))->filter(true, 'trim');
     if ($get->check()) {
         $get = $get->as_array();
         $proj = 'EPSG:4326';
         // wgs84, by default
         if (isset($_GET['projection'])) {
             $proj = $get['projection'];
         }
         if (isset($_GET['latitude'], $_GET['longitude'])) {
             $pt = new Sourcemap_Proj_Point($get['latitude'], $get['longitude']);
         } elseif (isset($_GET['placename'])) {
             $results = Sourcemap_Geocoder::geocode($get['placename']);
             if ($results) {
                 $r = $results[0];
                 $pt = new Sourcemap_Proj_Point($r->longitude, $r->latitude);
             } else {
                 return $this->_internal_server_error('Could not geocode placename.');
             }
         } else {
             return $this->_bad_request('Coordinates or placename required.');
         }
         $pt = Sourcemap_Proj::transform($proj, 'EPSG:900913', $pt);
     } else {
         return $this->_bad_request('Invalid parameters.');
     }
     $this->response = ORM::factory('stop')->nearby($pt);
 }
Example #29
0
 public function add_child($child, $at_root = false)
 {
     if (!$at_root && !$this->loaded()) {
         throw new Exception('No category loaded.');
     }
     $v = Validate::factory((array) $child);
     $v->rule('title', 'not_empty')->rule('title', 'max_length', array(32))->rule('name', 'not_empty')->rule('name', 'max_length', array(16))->filter('name', 'strtolower')->rule('description', 'not_empty');
     if ($v->check()) {
         $newc = ORM::factory('category')->values($v->as_array());
         if ($at_root) {
             $pl = $this->get_max_right();
             $newc->left = $pl + 1;
             $newc->right = $pl + 2;
         } else {
             $pl = $this->left;
             $pr = $this->right;
             $this->_db->begin();
             $sql = sprintf('update category set "left" = "left" + 2 where "left" > %d', $pl);
             $this->_db->query(Database::UPDATE, $sql, true);
             $sql = sprintf('update category set "right" = "right" + 2 where "right" > %d', $pl);
             $this->_db->query(Database::UPDATE, $sql, true);
             $newc->left = $this->left + 1;
             $newc->right = $this->left + 2;
         }
         $newc->save();
     } else {
         throw new Exception('Missing data.');
     }
     $this->_db->commit();
 }
Example #30
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());
 }