Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/application/classes/Controller/Infosite.php |
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Infosite extends Controller_Frontend {
public function action_index() {
$type = !empty( $_GET['type'] ) ? addslashes($_GET['type'] ) : 'zubrowka';
$fn = !empty( $_GET['fn'] ) ? addslashes($_GET['fn'] ) : 'zubr_wiz_01.png';
$category = !empty( $_GET['category'] ) ? addslashes($_GET['category'] ) : 'zabawne';
if( $type == 'wyborowa' )
$fn = 'wyb_wiz_01.png';
if( $type == 'uniwersalna' )
$fn = 'uni_wiz_01.png';
if( $type == 'krupnik' )
$fn = 'krup_wiz_01.png';
if( $type == 'uniwersalna' ) {
$fn = str_replace("10x5_mini", "uni_wiz", $fn);
} else {
$fn = str_replace("mini", "wiz", $fn);
}
$max_page = 0;
$this->template->title = 'Strona główna';
$items = array();
$path = 'uploads/items/etykiety_podglad/'.$type.'/';
if( is_dir( $path ) ) {
$dir=opendir($path);
while($file_name=readdir($dir))
{
if(($file_name!=".")&&($file_name!="..")) {
$items[$file_name] = $file_name;
$max_page++;
}
}
}
sort($items);
$divid = 6;
//if( $type == "wyborowa" ) $divid = 6;
$max_page = floor($max_page/$divid);
$this->template->content = View::factory('infosite/index')
->bind('path', $path)
->bind('items', $items)
->bind('divid', $divid)
->bind('max_page', $max_page)
->bind('fn', $fn)
->bind('category', $category)
->bind('type', $type);
}
public function action_Page($a=null, $page_id=null){
$url = 'Infosite/'.strtolower(Request::current()->param('url'));
$page = ORM::Factory('page')->where('keyname','=', $url)->find();
$this->template->title = strip_tags($page->title);
$mode = !empty( $_GET['mode'] ) ? addslashes($_GET['mode']) : 'kontakt';
$data = array();
$errors = array();
if ($_POST) {
$data = ac_form::clear_form_data($_POST);
$validata = $this->valid_kontakt_form($data);
if (sizeof($validata['errors'])) {
$message = __t('Błędnie wypełniony formularz.');
$errors = $validata['errors'];
} else {
if( $page->keyname == "Infosite/kontakt" ) {
aurora::standardEmail(Kohana::$config->load('site.email_kontakt'), $data['title'], $data['text']."\n\n".$data['email']." (".$data['email'].")");
Message::success(__t('Your message has been sent. We will respond as soon as possible.'));
//$message_ok = __t('Wiadomość została wysłana . Odpowiemy w najkrótszym możliwym terminie.');
$this->redirect('Infosite/kontakt?mode='.$mode);
} else {
if( !empty( $data['comment_text'] ) ) {
$c = ORM::Factory('moderator_page_comment');
$c->title = '';
$c->description = $data['comment_text'];
$c->pages_id = $page->id;
$c->is_change = 1;
$c->user_id = Auth::instance()->get_user()->id;
$c->save();
Message::success(__t('I just added an opinion on the portal. Your opinion is now waiting for verification and will appear on the website after 24 hours!'));
$this->redirect($_SERVER['HTTP_REFERER']);
} else {
Message::success(__t('Please fill in all fields!'));
$this->redirect($_SERVER['HTTP_REFERER']);
}
}
}
}
$this->template->content = View::factory('infosite/page')->bind('page', $page)->bind('message', $message);
}
public function action_Preview(){
$id = Request::current()->param('id');
$page = ORM::Factory('page', $id);
$this->template->content = View::factory('infosite/page_preview')->bind('page', $page)->bind('message', $message);
}
public function action_podsumowanie() {
$this->template->title = $title = __t('Dziękujemy za rejestrację konta!');
$this->template->content = View::factory('infosite/podsumowanie')
->bind('title', $title)
->bind('errors', $errors)
->bind('message', $message);
}
public function action_przypomnij() {
if ($_POST) {
$data = ac_form::clear_form_data($_POST);
$validata = $this->valid_przypomnij_form($data);
if (sizeof($validata['errors'])) {
$message = __t('Błędnie wypełniony formularz.');
Message::success(__t('Błędnie wypełniony formularz.'));
$this->redirect('przypomnij');
$errors = $validata['errors'];
} else {
$user = ORM::Factory('User')->where('email','=', $data['przypomnij_email'])->find();
// $myUser = $rg['user'];
$title = __t('Resetuj hasło');
$link = 'http://' . $_SERVER['HTTP_HOST'] . '/auth/generate?u=' . aurora::uniqueUserLink2($user->username, $user->email);
// $username = $myUser->username;
$session = Session::instance();
$lang_session = $session->get('language');
$lang = (empty( $lang_session ) ) ? 1 : $lang_session;
$lang_code = DB::query(Database::SELECT, "SELECT name FROM `languages` WHERE `id` = '$lang'")->execute();
$lang_code = strtolower($lang_code[0]['name']);
$e_content = View::factory('email/'.$lang_code.'_remind1')
->bind('user', $user)
->bind('link', $link);
aurora::standardEmail($data['przypomnij_email'], $title, $e_content);
// $message = __t('Instrukcje wysłane na Twój email.');
Message::success(__t('Instrukcje wysłane na Twój email.'));
$this->redirect('/');
unset($data);
}
}
$errors = isset($errors) ? $errors : null;
$data = isset($data) ? $data : array();
$message = isset($message) ? $message : null;
$current = 'Przypomnij hasło';
$this->template->title = __t($current);
$this->template->content = View::factory('infosite/przypomnij')
->bind('data', $data)
->bind('current', $current)
->bind('message', $message)
->bind('errors', $errors);
}
private function valid_kontakt_form($data) {
//var_dump($data);
$prefix = 'kontakt';
$errors = array();
return array(
'data' => $data,
'errors' => $errors
);
}
protected function validLoginForm(array $data) {
$errors = array();
$status = true;
foreach ($data as $key => $value) {
$data[$key] = htmlspecialchars(trim($value));
}
if (empty($data['login_login'])) {
$errors['login_login'] = __('Pole wymagane');
$status = false;
}
if (empty($data['login_password'])) {
$errors['login_password'] = __('Pole wymagane');
$status = false;
}
return array('status' => $status, 'errors' => $errors, 'data' => $data);
}
private function valid_przypomnij_form($data) {
//var_dump($data);
$prefix = 'przypomnij';
$errors = array();
/* walidacja poszczególnych pól formularza */
//
$name = ac_form::get_name('email', $prefix);
if (empty($data[$name])) {
$errors[$name] = __t('Pole nie może być puste');
} else {
if ( strstr( "@", $data['przypomnij_email'])) {
$errors['przypomnij_email'] = __('Zły E-mail');
$status = false;
} else {
$test = ORM::Factory('User')->where('email','=',$data['przypomnij_email'])->find_all();
if( $test->count() == 0 ) {
$errors['przypomnij_email'] = __('E-mail nie istnije w bazie.');
$status = false;
}
}
}
return array(
'data' => $data,
'errors' => $errors
);
}
}