Пример #1
0
 public function action_edit_field()
 {
     $field_id = $this->request->param('options');
     xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
     if (count($_POST) && isset($_POST['field_name'])) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::not_empty', 'field_name');
         if ($post->validate()) {
             $post_values = $post->as_array();
             if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
                 $post->add_error('field_name', 'User::field_name_available');
             }
         }
         // Retry
         if ($post->validate()) {
             $post_values = $post->as_array();
             User::update_field($field_id, $post_values['field_name']);
             $this->add_message('Field ' . $post_values['field_name'] . ' updated');
             $this->set_formdata(array('field_name' => $post_values['field_name']));
         } else {
             $this->add_error('Fix errors and try again');
             $this->add_form_errors($post->errors());
             $this->set_formdata(array_intersect_key($post->as_array(), $_POST));
         }
     } else {
         $this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
     }
 }
Пример #2
0
 function validate()
 {
     $post = new Validation($_POST);
     $post->add_rules('username', 'required');
     $post->add_rules('password', 'required');
     if (!$post->validate()) {
         echo '必须填写用户名和密码';
         return;
     }
     $username = $_POST['username'];
     $password = $_POST['password'];
     $user_orm = ORM::factory('user')->where(array('name' => $username, 'password' => sha1($password)))->find();
     if ($user_orm->loaded) {
         $id = $user_orm->id;
         if ($user_orm->active == 1) {
             $this->session->set('user_id', $id);
             $this->session->set('username', $username);
             $this->session->set('role_id', $user_orm->role_id);
             respOk(array());
         } else {
             $message = "登录失败,用户处于禁止状态";
             respFailed($message);
         }
     } else {
         $message = "登录失败,用户名或密码错误";
         respFailed($message);
     }
     return;
 }
Пример #3
0
 public function handler()
 {
     access::verify_csrf();
     $form = $this->_get_form();
     $errors = array_fill_keys(array_keys($form), "");
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules("updates_enabled", array("valid", "numeric"));
         $post->add_rules("popular_enabled", array("valid", "numeric"));
         $post->add_rules("updates_limit", array("valid", "numeric"));
         $post->add_rules("popular_limit", array("valid", "numeric"));
         $post->add_rules("updates_description", "length[0,2048]");
         $post->add_rules("popular_description", "length[0,2048]");
         if ($post->validate()) {
             foreach (array("updates", "popular") as $album) {
                 $album_defn = unserialize(module::get_var("dynamic", $album));
                 $album_defn->enabled = $post["{$album}_enabled"];
                 $album_defn->description = $post["{$album}_description"];
                 $album_defn->limit = $post["{$album}_limit"] === "" ? null : $post["{$album}_limit"];
                 module::set_var("dynamic", $album, serialize($album_defn));
             }
             message::success(t("Dynamic Albums Configured"));
             url::redirect("admin/dynamic");
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors());
         }
     }
     print $this->_get_view($form, $errors);
 }
Пример #4
0
 public function reset()
 {
     if ($this->owner->logged_in()) {
         url::redirect('/admin/testimonials/display');
     }
     $login_shell = new View('admin/login_shell');
     $login_shell->content = new View('admin/reset');
     if (empty($_POST)) {
         die($login_shell);
     }
     $post = new Validation($_POST);
     $post->pre_filter('trim');
     $post->add_rules('email', 'required', 'valid::email');
     # if Post is good, atttempt to log owner in.
     if ($post->validate()) {
         $owner = ORM::factory('owner')->find($_POST['email']);
         if (!$owner->loaded) {
             die('email does not have an account');
         }
         $pw = text::random('alnum', 8);
         $owner->password = $pw;
         $owner->save();
         $replyto = 'unknown';
         $body = "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda";
         # to do FIX THE HEADERS.
         $subject = 'Your Pluspanda Password Has Been Reset =)';
         $headers = "From: noreply@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion();
         mail($_POST['email'], $subject, $body, $headers);
         die('Please check your email for your new password!');
     }
     # error
     $login_shell->content->alert = alerts::display(array('error' => 'Invalid Email or Password.'));
     $login_shell->content->values = $_POST;
     die($login_shell);
 }
Пример #5
0
 private function _get_record()
 {
     $form = array('txt_name' => '', 'txt_email' => '', 'txt_phone' => '', 'txt_subject' => '', 'txt_content' => '', 'txt_code' => '', 'txt_last_name' => '', 'txt_first_name' => '', 'txt_company' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required');
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_rules('txt_subject', 'required');
         $post->add_rules('txt_content', 'required');
         //$post->add_rules('txt_code','required');
         //$post->add_callbacks('txt_random',array($this,'_check_security_code'));
         //$post->add_rules('sel_send','trim');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             // Retrieve input data
             $this->session->set_flash('input_data', $form);
             // Set input data in session
             $errors = arr::overwrite($errors, $post->errors('contact_validation'));
             $error_msg = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $error_msg .= '<br>' . $name;
                 }
             }
             $this->session->set_flash('error_msg', $error_msg);
             url::redirect('contact');
             die;
         }
     }
 }
Пример #6
0
 private function _get_record_aut_config()
 {
     $form = array('txt_aut_api_login' => '', 'txt_aut_transaction_key' => '', 'sel_aut_post_url' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_aut_api_login', 'trim', 'required');
         $post->add_rules('txt_aut_transaction_key', 'trim', 'required');
         $post->add_rules('sel_aut_post_url', 'trim', 'required');
         $form = arr::overwrite($form, $post->as_array());
         $form = $this->_set_form_aut_config($form);
         if ($post->validate()) {
             return $form;
         } else {
             $this->session->set_flash('frm_aut', $form);
             $errors = arr::overwrite($errors, $post->errors('authorizenet_config_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= '<br>' . $name;
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect('admin_payment_method');
             die;
         }
     }
 }
Пример #7
0
 private function _get_valid_accinfo($old_pass)
 {
     $form = array('txt_old_pass' => '', 'txt_new_pass' => '', 'txt_cf_new_pass' => '', 'txt_email' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         if (!empty($old_pass)) {
             $post->add_rules('txt_new_pass', 'required', 'length[6,50]');
             $post->add_rules('txt_cf_new_pass', 'matches[txt_new_pass]');
             $post->add_callbacks('txt_old_pass', array($this, '_check_old_pass'));
         }
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $this->session->set_flash('input_data', $form);
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->uri->segment(1));
             die;
         }
     }
 }
Пример #8
0
 public function add()
 {
     $argumentarray = Router::$arguments;
     //$id = $argumentarray[0];
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         $post->pre_filter('trim', 'foilName', 'foilHexcode');
         $post->add_rules('foilName', 'required');
         $post->add_rules('foilHexcode', 'required');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             //$id = $argumentarray[0];
             $foils = new Foil_Color_Model();
             $foil = ORM::factory('foil_color');
             $foil->name = $post->foilName;
             $foil->hexcode = $post->foilHexcode;
             try {
                 $foil->save();
                 $foils = new Foil_Color_Model();
                 $id = $foils->getNextID();
                 url::redirect('/foils/edit/' . $foil->id);
             } catch (Exception $ex) {
                 echo 'There was an error adding this foil: ' . $ex->getMessage();
                 //url::redirect('/foils/');
             }
         }
     }
     $this->_renderView();
 }
Пример #9
0
 public function index()
 {
     $this->template->content = new View('admin/flickrwijit_form');
     // setup and initialize form field names
     $form = array('flickr_tag' => '', 'flickr_id' => '', 'num_of_photos' => '', 'image_width' => '', 'image_height' => '', 'block_position' => '', 'enable_cache' => '', 'block_no_photos' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('flickr_tag', 'required', 'length[0,500]');
         $post->add_rules('flickr_id', 'length[0,20]');
         $post->add_rules('num_of_photos', 'numeric');
         $post->add_rules('image_width', 'length[2,600]', 'numeric');
         $post->add_rules('image_height', 'required', 'length[2,600]', 'numeric');
         $post->add_rules('block_position', 'length[1,6]', 'numeric');
         $post->add_rules('enable_cache', 'between[0,1]', 'numeric');
         $post->add_rules('block_no_photos', 'between[4,10]', 'numeric');
         // passed validation test.
         if ($post->validate()) {
             $flickrwijit_settings = new Flickrwijit_Model(1);
             $flickrwijit_settings->flickr_tag = $post->flickr_tag;
             $flickrwijit_settings->flickr_id = $post->flickr_id;
             $flickrwijit_settings->num_of_photos = $post->num_of_photos;
             $flickrwijit_settings->image_height = $post->image_height;
             $flickrwijit_settings->image_width = $post->image_width;
             $flickrwijit_settings->block_position = $post->block_position;
             $flickrwijit_settings->enable_cache = $post->enable_cache;
             $flickrwijit_settings->block_no_photos = $post->block_no_photos;
             $flickrwijit_settings->save();
             // Delete Settings Cache
             // $this->cache->delete('settings');
             // $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('flickrwijit'));
             $form_error = TRUE;
         }
     } else {
         $flickrwijit_settings = ORM::factory('flickrwijit', 1);
         $form = array('flickr_tag' => $flickrwijit_settings->flickr_tag, 'flickr_id' => $flickrwijit_settings->flickr_id, 'num_of_photos' => $flickrwijit_settings->num_of_photos, 'image_width' => $flickrwijit_settings->image_width, 'image_height' => $flickrwijit_settings->image_height, 'block_position' => $flickrwijit_settings->block_position, 'enable_cache' => $flickrwijit_settings->enable_cache, 'block_no_photos' => $flickrwijit_settings->block_no_photos);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
 }
Пример #10
0
 private function form_handler($page_name, $newsletter)
 {
     $view = new View('public_newsletter/newsletters/form');
     $view->page_name = $page_name;
     $values = array('name' => '', 'email' => '');
     $view->values = $values;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_rules('name', 'required');
         $post->add_rules('email', 'required', 'valid::email');
         if (!$post->validate()) {
             $view->errors = arr::overwrite($values, $post->errors('form_error_messages'));
             $view->values = arr::overwrite($values, $post->as_array());
             return $view;
         }
         include Kohana::find_file('vendor', 'CMBase');
         $cm = new CampaignMonitor(null, null, $newsletter->cm_list_id);
         $result = $cm->subscriberAdd($_POST['email'], $_POST['name']);
         if ($result['Result']['Code'] != 0) {
             kohana::log('error', $result['Result']['Message']);
             return 'There was an error adding you to the emailing list. Please try again later.';
         }
         return 'Thank you! You have been adding to our mailing list.';
     }
     return $view;
 }
Пример #11
0
 public function create()
 {
     if ($post = $this->input->post()) {
         $form = new Validation($post);
         $form->add_rules('title', 'required');
         $form->add_rules('introduction', 'required');
         if ($form->validate()) {
             $island = ORM::factory('island');
             $island->user_id = Auth::instance()->get_user()->id;
             $island->title = $post['title'];
             $island->introduction = $post['introduction'];
             $now = date('Y-m-d H:i:s');
             $island->created = $now;
             $island->modified = $now;
             $island->save();
             if ($island->saved) {
                 $this->session->set_flash('notice', 'Created new island!');
                 url::redirect('/sail/' . $island->code);
             } else {
                 $this->session->set_flash('error', 'Failed to create new island!');
             }
         } else {
             var_dump($form->errors());
             die;
             $this->session->set_flash('error', 'Error validating.');
         }
     }
 }
Пример #12
0
 public function index()
 {
     $this->__set_heading("Profile");
     $view = new View('zest/content');
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules('email', 'required', 'email');
         if ($post->validate()) {
             $this->user->email = $post['email'];
             $this->user->openid = $post['openid'];
             if (isset($post['password']) && trim($post['password'][0]) != "") {
                 if ($post['password'][0] == $post['password'][1]) {
                     $this->user->password = $post['password'][1];
                 } else {
                     $this->throw_error("Both passwords bust be the same");
                 }
             }
             $this->user->save();
             $this->__throw_success("Your profile has been updated");
         } else {
             $this->throw_error("There has been an error updating your profile, please try again");
         }
     }
     $view->content = $this->_form($this->user);
     $this->__set_content($view);
 }
Пример #13
0
 private function _get_frm_valid()
 {
     $form = array('txt_name' => '', 'txt_phone' => '', 'txt_fax' => '', 'txt_email' => '', 'txt_address' => '', 'txt_city' => '', 'txt_zipcode' => '', 'txt_contact' => '', 'txt_state' => '', 'txt_slogan' => '', 'txt_title' => '', 'txt_keyword' => '', 'txt_description' => '', 'txt_per_test' => '', 'txt_width' => '', 'txt_height' => '', 'rdo_enable_cart' => '', 'attach_logo' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation(array_merge($_POST, $_FILES));
         if (!empty($_FILES['attach_logo']['name'])) {
             $post->add_rules('attach_logo', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[2M]');
         }
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required');
         $post->add_rules('txt_phone', 'required');
         //$post->add_rules('txt_fax','phone[7,10,11,14]');
         $post->add_rules('txt_email', 'required', 'email');
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_width', 'digit');
         $post->add_rules('txt_height', 'digit');
         $post->add_rules('txt_per_test', 'digit');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $errors = arr::overwrite($errors, $post->errors('site_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
         }
     }
     url::redirect('admin_config');
     die;
 }
Пример #14
0
 public function rename($id)
 {
     access::verify_csrf();
     $tag = ORM::factory("tag", $id);
     if (!$tag->loaded) {
         kohana::show_404();
     }
     // Don't use a form as the form is dynamically created in the js
     $post = new Validation($_POST);
     $post->add_rules("name", "required", "length[1,64]");
     $valid = $post->validate();
     if ($valid) {
         $new_name = $this->input->post("name");
         $new_tag = ORM::factory("tag")->where("name", $new_name)->find();
         if ($new_tag->loaded) {
             $error_msg = t("There is already a tag with that name");
             $valid = false;
         }
     } else {
         $error_msg = $post->errors();
         $error_msg = $error_msg[0];
     }
     if ($valid) {
         $old_name = $tag->name;
         $tag->name = $new_name;
         $tag->save();
         $message = t("Renamed tag %old_name to %new_name", array("old_name" => $old_name, "new_name" => $tag->name));
         message::success($message);
         log::success("tags", $message);
         print json_encode(array("result" => "success", "location" => url::site("admin/tags"), "tag_id" => $tag->id, "new_tagname" => html::clean($tag->name)));
     } else {
         print json_encode(array("result" => "error", "message" => (string) $error_msg));
     }
 }
 public function upload()
 {
     access::verify_csrf();
     $validation = new Validation(array_merge($_POST, $_FILES));
     $validation->add_rules("zip_file", "upload::valid", "upload::required", "upload::type[zip]");
     $validation->add_rules("is_admin", "chars[0,1]");
     $validation->add_callbacks("zip_file", array($this, "_unload_zip"));
     if ($validation->validate()) {
         $session = Session::instance();
         $themeroller_name = $session->get("themeroller_name");
         $is_admin = $validation["is_admin"];
         $counter = 0;
         $theme_name_generated = $theme_name = ($is_admin ? "admin_" : "") . $themeroller_name;
         while (file_exists(THEMEPATH . "{$theme_name_generated}/theme.info")) {
             $counter++;
             $theme_name_generated = "{$theme_name}_{$counter}";
         }
         $theme_name = strtolower(strtr($theme_name_generated, " ", "_"));
         $session->set("theme_name", $theme_name);
         $session->set("themeroller_is_admin", $is_admin);
         print "FILEID: {$validation["zip_file"]["tmp_name"]}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid zip archive");
     }
 }
Пример #16
0
 private function pricing()
 {
     $this->shell->meta = 'Plans and pricing for testimonial and review layouts and templates for your website';
     $this->shell->content = new View('marketing/testimonials/start');
     $this->shell->title = 'Plans and Pricing';
     if (empty($_POST)) {
         die($this->shell);
     }
     # handle the POST.
     $this->shell->content->values = $_POST;
     $post = new Validation($_POST);
     $post->pre_filter('trim');
     $post->add_rules('email', 'required', 'valid::email');
     $post->add_rules('password', 'required', 'matches[password2]', 'valid::alpha_dash');
     if (!$post->validate()) {
         $this->shell->content->errors = $post->errors();
         die($this->shell);
     }
     $new_owner = ORM::factory('owner');
     # unique email.
     if (!$new_owner->email_available($_POST['email'])) {
         $this->shell->content->errors = 'Email Already Exists!';
         die($this->shell);
     }
     $new_owner->email = $_POST['email'];
     $new_owner->password = $_POST['password'];
     $new_owner->save();
     # log the user in and take to admin
     $this->auth->force_login($new_owner);
     url::redirect('/admin/login');
 }
Пример #17
0
 public function login()
 {
     $form = $errors = array("user" => "", "password" => "");
     $post = new Validation($_POST);
     $post->add_rules("user", "required");
     $post->add_rules("password", "required");
     if ($valid = $post->validate()) {
         try {
             $token = G3Remote::instance()->get_access_token($post["user"], $post["password"]);
             Session::instance()->set("g3_client_access_token", $token);
             $response = G3Remote::instance()->get_resource("gallery");
             $valid = true;
             $content = $this->_get_main_view($response->resource);
         } catch (Exception $e) {
             Kohana_Log::add("error", Kohana_Exception::text($e));
             $valid = false;
         }
     }
     if (!$valid) {
         $content = new View('login.html');
         $content->form = arr::overwrite($form, $post->as_array());
         $content->errors = arr::overwrite($errors, $post->errors());
     }
     $this->auto_render = false;
     print json_encode(array("status" => $valid ? "ok" : "error", "content" => (string) $content));
 }
Пример #18
0
 public function create()
 {
     $this->template->content = new View('users/create');
     $form = new Validation($_POST);
     $form->pre_filter('trim', true);
     $form->add_rules('username', 'required')->add_rules('password', 'required')->add_rules('email', 'required', 'valid::email');
     $this->template->content->repopulate = $form;
     if ($form->validate()) {
         // Create new user
         $user = new User_Model();
         if (!$user->username_exists($this->input->post('username'))) {
             foreach ($form->as_array() as $key => $val) {
                 // Set user data
                 $user->{$key} = $val;
             }
             if ($user->validate($form->as_array())) {
                 if ($user->add(ORM::factory('role', 'login')) and $user->save()) {
                     // Redirect to the login page
                     url::redirect('login');
                 }
             }
         }
     }
     // Error
     $this->template->content->error = $form->errors('login');
 }
Пример #19
0
 private function _get_frm_valid()
 {
     $rdo_type = 'image';
     $file_ext = 'jpg,jpeg,gif,png';
     $form = array('hd_id' => '', 'attach_image' => '', 'txt_width' => '', 'txt_height' => '', 'sel_status' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation(array_merge($_FILES, $_POST));
         $post->add_rules('attach_' . $rdo_type, 'upload::type[' . $file_ext . ']', 'upload::size[10M]');
         $post->add_rules('txt_width', 'digit');
         $post->add_rules('txt_height', 'digit');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $errors = $post->errors('banner_validation');
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect($this->site['history']['current']);
             die;
         }
     }
 }
Пример #20
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $movie = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie")));
             } else {
                 $photo = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo")));
             }
         } catch (Exception $e) {
             unlink($temp_filename);
             throw $e;
         }
         unlink($temp_filename);
     }
     print "File Received";
 }
Пример #21
0
 public function edit()
 {
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         //********  TO DO: trim for shipping info     **************/
         $post->pre_filter('trim', 'msg_text1', 'designpath', 'img_approved');
         $post->add_rules('msg_text1', 'required');
         $post->add_rules('designpath', 'required', 'numeric');
         $post->add_rules('img_approved', 'numeric');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             $id = $this->uri->segment(3);
             $basket = ORM::factory('orders_basket')->find($id);
             $basket->msg_text1 = $post->msg_text1;
             $basket->designpath = $post->designpath;
             $basket->img_approved = $post->img_approved;
             $basket->save();
             /*************** TO DO: delete more than one category ****************/
         }
     }
     $this->_renderView();
 }
Пример #22
0
 public function activate()
 {
     access::verify_csrf();
     $post = new Validation($_POST);
     $post->add_rules("activate_users", "required");
     $post->add_rules("activate", "alpha_numeric");
     if ($post->validate()) {
         $names = array();
         if (!empty($post->activate)) {
             foreach ($post->activate as $id) {
                 $user = register::create_new_user($id);
                 $names[] = $user->name;
             }
             message::success(t("Activated %users.", array("users" => implode(", ", $names))));
         }
         $count = ORM::factory("pending_user")->where("state", "!=", 2)->count_all();
         if ($count == 0) {
             site_status::clear("pending_user_registrations");
         }
         url::redirect("admin/register");
     }
     list($form, $errors) = $this->_get_form();
     $form = array_merge($form, $post->as_array());
     $errors = array_merge($errors, $post->errors());
     print $this->_get_admin_view($form, $errors);
 }
Пример #23
0
 private function post_review($page_name, $review_id)
 {
     # validate the form values.
     $post = new Validation($_POST);
     $post->pre_filter('trim');
     $post->add_rules('body', 'required');
     $post->add_rules('name', 'required');
     $post->add_rules('email', 'required');
     # on error
     if (!$post->validate()) {
         $view = new View('public_review/reviews/add_form');
         $view->page_name = $page_name;
         $view->errors = $post->errors();
         $view->values = $_POST;
         return $view;
     }
     # on success
     $new_item = ORM::factory('review_item');
     $new_item->review_id = $review_id;
     $new_item->fk_site = $this->site_id;
     $new_item->body = $_POST['body'];
     $new_item->rating = $_POST['rating'];
     $new_item->name = $_POST['name'];
     $new_item->save();
     $view = new View('public_review/reviews/status');
     $view->success = true;
     return $view;
 }
Пример #24
0
 public function test_data_create()
 {
     access::verify_csrf();
     list($form, $errors) = $this->_get_test_data_form();
     $post = new Validation($_POST);
     $post->add_rules("albums", "numeric");
     $post->add_rules("photos", "numeric");
     $post->add_rules("comments", "numeric");
     $post->add_rules("tags", "numeric");
     $post->add_callbacks("albums", array($this, "_set_default"));
     $post->add_callbacks("photos", array($this, "_set_default"));
     $post->add_callbacks("comments", array($this, "_set_default"));
     $post->add_callbacks("tags", array($this, "_set_default"));
     if ($post->validate()) {
         $task_def = Task_Definition::factory()->callback("developer_task::create_content")->description(t("Create test content"))->name(t("Create Test Data"));
         $total = $post->albums + $post->photos + $post->comments + $post->tags;
         $success_msg = t("Successfully generated test data");
         $error_msg = t("Problems with test data generation was encountered");
         $task = task::create($task_def, array("total" => $total, "batch" => (int) ceil($total / 10), "success_msg" => $success_msg, "current" => 0, "error_msg" => $error_msg, "albums" => $post->albums, "photos" => $post->photos, "comments" => $post->comments, "tags" => $post->tags));
         batch::start();
         print json_encode(array("result" => "started", "max_iterations" => $total + 5, "url" => url::site("admin/developer/run_task/{$task->id}?csrf=" . access::csrf_token()), "task" => $task->as_array()));
     } else {
         $v = $this->_get_test_data_view(arr::overwrite($form, $post->as_array()), arr::overwrite($errors, $post->errors()));
         print json_encode(array("result" => "error", "form" => $v->__toString()));
     }
 }
Пример #25
0
 /**
  * Show latest PER_PAGE news on page
  * @return void
  */
 public function index($module = NULL, $page = 1)
 {
     $this->set_title(Kohana::lang('search.search'));
     if ($page == 1) {
         $this->add_breadcrumb(Kohana::lang('search.the_best_results'), url::current());
     } else {
         $this->add_breadcrumb(Kohana::lang('search.page_no') . ' ' . $page, url::current());
     }
     // Default values
     $form = array('value' => '');
     $errors = array();
     if ($_POST) {
         $post = new Validation($_POST);
         // Some filters
         $post->pre_filter('trim', TRUE);
         // Rules
         $post->add_rules('value', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // Repopulate form with error and original values
             $form = arr::overwrite($form, $post->as_array());
             $errors = $post->errors('search_errors');
         }
     }
     $this->template->content = new View('search');
     $data = $this->products->search($post['value']);
     $data2 = $this->page->search($post['value']);
     $data3 = $this->news->search($post['value']);
     $this->template->content->data = $data;
     $this->template->content->data2 = $data2;
     $this->template->content->data3 = $data3;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
 }
Пример #26
0
 public function add()
 {
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         $post->pre_filter('trim', 'typeName', 'typeDescription', 'typeShortDescription', 'metaTitle', 'metaDescription', 'metaKeywords');
         $post->add_rules('typeName', 'required');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             $id = $this->uri->segment(3);
             $type = ORM::factory('products_type')->find($id);
             $type->name = $post->typeName;
             $type->category_id = $post->category;
             $type_desc = ORM::factory('products_types_description')->where('id', $type->products_types_description_id)->find();
             $type_desc->short_description = $post->typeShortDescription;
             $type_desc->description = $post->typeDescription;
             $type_desc->meta_title = $post->metaTitle;
             $type_desc->meta_description = $post->metaDescription;
             $type_desc->meta_keywords = $post->metaKeywords;
             $type_desc->title_url = $post->metaUrl;
             $type_desc->image_alt = $post->image_alt;
             $type_desc->video = $post->video;
             if (!empty($_FILES['image']['name'])) {
                 // uses Kohana upload helper
                 $_FILES = Validation::factory($_FILES)->add_rules('image', 'upload::valid', 'upload::type[gif,jpg,jpeg,png]', 'upload::size[2M]');
                 if ($_FILES->validate()) {
                     // Temporary file name
                     $filename = upload::save('image', basename($_FILES['image']['tmp_name']));
                     $file = basename($_FILES['image']['name']);
                     // Resize, sharpen, and save the image
                     Image::factory($filename)->save(DOCROOT . '../../env/product_type_images/' . $file);
                     // Remove the temporary file
                     unlink($filename);
                     $type_desc->image = $file;
                     $type_desc->save();
                 } else {
                     $errors = $_FILES->errors('form_user');
                 }
             }
             $type_desc->save();
             $type->products_types_description_id = $type_desc->id;
             $type->save();
             if (!empty($post->productTypeSites)) {
                 foreach ($post->productTypeSites as $site_id) {
                     $sc = ORM::factory('sites_types')->where('products_type_id', $type->id)->where('site_id', $site_id)->find();
                     if ($sc->id == 0) {
                         $sc->products_type_id = $type->id;
                         $sc->site_id = $site_id;
                         $sc->save();
                     }
                 }
             }
             url::redirect(url::base() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $type->id);
         }
     }
     $this->_renderView();
 }
Пример #27
0
 public function add()
 {
     $form = array('building_id' => '', 'name' => '', 'index' => '', 'img_uri' => '', 'active' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', true);
         $post->add_rules('buildings_id', 'required', 'digit');
         $post->add_rules('name', 'required');
         $post->add_rules('index', 'required');
         $post->add_rules('img_uri', 'required');
         $post->add_rules('active', 'required');
         if ($post->validate()) {
             // check for invilid
             $form = arr::overwrite($form, $post->as_array());
             $people = new Person_Model();
             $result = $people->save($this->input->get('person'), $person_id);
         } else {
             $form = arr::overwrite($form, $post->as_array());
             client::validation_results(arr::overwrite($errors, $post->errors('hiring_employee_form_validations')));
             client::messageSend("There were errors in some fields", E_USER_WARNING);
         }
     }
     $building = new Building_Model();
     $buildings_list = $building->select_list();
     $this->template->title = 'Seating::Spaces::Add';
     $this->template->content = new View('pages/spaces_add');
     $this->template->content->form = $form;
     $this->template->content->buildings_list = $buildings_list;
 }
Пример #28
0
 private function _get_frm_valid()
 {
     $hd_id = $this->input->post('hd_id');
     $form = $this->data_template_model->get_frm();
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_name', 'required', 'length[1,200]');
         $post->add_rules('txt_content', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $errors = arr::overwrite($errors, $post->errors('account_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             if ($hd_id) {
                 url::redirect('admin_emailtemplate/edit/' . $hd_id);
             }
             die;
         }
     }
 }
Пример #29
0
 public function process_post($post)
 {
     $post = new Validation($post);
     $post->add_rules('form', 'required');
     if ($post->validate()) {
         switch ($post->form) {
             case 'update_translation':
                 $post->add_rules('id', 'numeric');
                 if ($post->validate()) {
                     Message_Model::update_translation($post->id, $post->translation);
                 }
                 break;
         }
     } else {
         echo 'FAILED VALIDATION';
     }
 }
Пример #30
0
 /**
  * Customer profile
  * @return void
  * @param state to show after return
  */
 public function profile($state = NULL)
 {
     // Messages about success
     $success = array();
     if ($state == "changed") {
         $success[] = Kohana::lang('eshop.succesfully_changed');
     }
     // Check user permission
     if (user::is_logged()) {
         // Settings
         $this->set_title(Kohana::lang('eshop.customer_profile'));
         $this->add_breadcrumb(Kohana::lang('eshop.profile'), url::current());
         // Default values
         if ($this->customer->profile_exists(user::user_email())) {
             $row = $this->customer->get_one(user::user_email());
             $form = array('customer_street' => $row['customer_street'], 'customer_city' => $row['customer_city'], 'customer_postal_code' => $row['customer_postal_code'], 'customer_phone' => $row['customer_phone'], 'billing_name' => $row['billing_name'], 'billing_street' => $row['billing_street'], 'billing_city' => $row['billing_city'], 'billing_postal_code' => $row['billing_postal_code'], 'billing_identity_number' => $row['billing_identity_number'], 'billing_vat_number' => $row['billing_vat_number']);
         } else {
             // empty data
             $form = array('customer_street' => '', 'customer_city' => '', 'customer_postal_code' => '', 'customer_phone' => '', 'billing_name' => '', 'billing_street' => '', 'billing_city' => '', 'billing_postal_code' => '', 'billing_identity_number' => '', 'billing_vat_number' => '');
         }
         $errors = array();
         if ($state == "needed") {
             $errors[] = Kohana::lang('eshop.informations_needed');
         }
         // Validation
         if ($_POST) {
             $post = new Validation($_POST);
             // Some filters
             $post->pre_filter('trim', TRUE);
             // Rules
             $post->add_rules('customer_street', 'required');
             $post->add_rules('customer_city', 'required');
             $post->add_rules('customer_postal_code', 'required', 'length[0,255]');
             $post->add_rules('billing_name', 'length[0,255]');
             $post->add_rules('billing_postal_code', 'length[0,255]');
             $post->add_rules('billing_identity_number', 'length[0,8]');
             $post->add_rules('billing_vat_number', 'length[0,12]');
             if ($post->validate()) {
                 // Everything seems to be ok, insert to db
                 $this->customer->change_data($post, user::user_email());
                 url::redirect('/customer/profile/changed');
             } else {
                 // Repopulate form with error and original values
                 $form = arr::overwrite($form, $post->as_array());
                 $errors = $post->errors('customer_errors');
                 $success = array();
             }
         }
         // View
         $this->template->content = new View('customer_profile');
         $this->template->content->form = $form;
         $this->template->content->errors = $errors;
         $this->template->content->success = $success;
     } else {
         url::redirect('/denied');
     }
 }