/** 
  * Test that a basic date out of range test works.
  */
 public function testDateOutOfRange()
 {
     // Need a test rule we can use to check it works
     $ruleArr = array('verification_rule:title' => 'test', 'verification_rule:test_type' => 'PeriodWithinYear', 'verification_rule:error_message' => 'test error', 'metaFields:metadata' => "Tvk=TESTKEY\nStartDate=0801\nEndDate=0831", 'metaFields:data' => "");
     $rule = ORM::Factory('verification_rule');
     $rule->set_submission_data($ruleArr, false);
     if (!$rule->submit()) {
         echo kohana::debug($rule->getAllErrors());
         throw new exception('Failed to create test rule');
     }
     try {
         $response = data_entry_helper::http_post($this->request, array('sample' => json_encode(array('sample:survey_id' => 1, 'sample:date' => '12/09/2012', 'sample:entered_sref' => 'SU1234', 'sample:entered_sref_system' => 'osgb')), 'occurrences' => json_encode(array(array('occurrence:taxa_taxon_list_id' => $this->ttl->id))), 'rule_types' => json_encode(array('PeriodWithinYear'))));
         $errors = json_decode($response['output'], true);
         $this->assertTrue(is_array($errors), 'Errors list not returned');
         $this->assertTrue(isset($errors[0]['taxa_taxon_list_id']) && $errors[0]['taxa_taxon_list_id'] === $this->ttl->id, 'Incorrect taxa_taxon_list_id returned');
         $this->assertTrue(isset($errors[0]['message']) && $errors[0]['message'] === 'test error', 'Incorrect message returned');
         foreach ($rule->verification_rule_metadata as $m) {
             $m->delete();
         }
         $rule->delete();
     } catch (Exception $e) {
         foreach ($rule->verification_rule_metadata as $m) {
             $m->delete();
         }
         $rule->delete();
     }
 }
Exemple #2
0
 protected function _execute()
 {
     if (!isset($this->_data->email) or !$this->_data->email or !isset($this->_data->password) or !$this->_data->password) {
         throw new Exception("Login error: missing email and/or password.");
     }
     $user = ORM::Factory('user')->where('email', 'LIKE', $this->_data->email)->find();
     if (!$user->loaded()) {
         throw new Exception("Login error: that email address was not found.");
     }
     if ($user->password != $this->_beans_auth_password($user->id, $this->_data->password)) {
         throw new Exception("Login error: that password was incorrect.");
     }
     if (!$user->role->loaded()) {
         throw new Exception("Login error: that user does not have any defined role.");
     }
     if ($user->password_change) {
         $user->reset = $this->_generate_reset($user->id);
         $user->reset_expiration = time() + 2 * 60;
         $user->save();
         return (object) array("reset" => $user->reset);
     }
     $expiration = $user->role->auth_expiration_length != 0 ? time() + $user->role->auth_expiration_length : rand(11111, 99999);
     $user->auth_expiration = $expiration;
     $user->save();
     return (object) array("auth" => $this->_return_auth_element($user, $expiration));
 }
Exemple #3
0
 protected function _execute()
 {
     if (!$this->_search_vendor_id) {
         throw new Exception("Missing required parameter: vendor_id");
     }
     // This effectively limits the results only to a vendor with the ID.
     $this->_transactions = $this->_transactions->where('entity_id', '=', $this->_search_vendor_id)->and_where_open()->or_where('payment', '=', 'vendor')->or_where('payment', '=', 'expense')->and_where_close();
     $this->_transactions = $this->_transactions->and_where_open();
     $this->_transactions = $this->_transactions->where('id', 'IS NOT', NULL);
     // $this->_search_keywords
     if ($this->_search_keywords) {
         $forms = ORM::Factory('form')->where('entity_id', '=', $this->_search_vendor_id);
         $query = FALSE;
         foreach (explode(' ', $this->_search_keywords) as $keyword) {
             $term = trim($keyword);
             if ($term) {
                 $query = TRUE;
                 $forms = $forms->and_where_open()->or_where('code', 'LIKE', '%' . $term . '%')->or_where('reference', 'LIKE', '%' . $term . '%')->or_where('alt_reference', 'LIKE', '%' . $term . '%')->or_where('aux_reference', 'LIKE', '%' . $term . '%')->and_where_close();
             }
         }
         if ($query) {
             $forms = $forms->find_all();
         } else {
             $forms = array();
         }
         $form_ids = array();
         foreach ($forms as $form) {
             $form_ids[] = $form->id;
         }
         $account_transactions = ORM::Factory('account_transaction')->join('account_transaction_forms', 'LEFT')->on('account_transaction_forms.account_transaction_id', '=', 'account_transaction.id');
         $account_transactions = $account_transactions->where('account_transaction_forms.form_id', 'IN', $form_ids);
         $account_transactions = $account_transactions->find_all();
         $transaction_ids = array();
         foreach ($account_transactions as $account_transaction) {
             $transaction_ids[] = $account_transaction->transaction_id;
         }
         if ($this->_search_and) {
             $this->_transactions = $this->_transactions->where('id', 'IN', $transaction_ids);
         } else {
             $this->_transactions = $this->_transactions->or_where('id', 'IN', $transaction_ids);
         }
     }
     if ($this->_search_date) {
         if ($this->_search_and) {
             $this->_transactions = $this->_transactions->where('transaction.date', '=', $this->_search_date);
         } else {
             $this->_transactions = $this->_transactions->or_where('transaction.date', '=', $this->_search_date);
         }
     }
     if ($this->_search_check_number) {
         if ($this->_search_and) {
             $this->_transactions = $this->_transactions->where('transaction.reference', 'LIKE', '%' . $this->_search_check_number . '%');
         } else {
             $this->_transactions = $this->_transactions->or_where('transaction.reference', 'LIKE', '%' . $this->_search_check_number . '%');
         }
     }
     $this->_transactions = $this->_transactions->and_where_close();
     $result_object = $this->_find_transactions();
     return (object) array("total_results" => $result_object->total_results, "sort_by" => $this->_sort_by, "pages" => $result_object->pages, "page" => $result_object->page, "transactions" => $this->_return_transactions_array($result_object->transactions));
 }
Exemple #4
0
 protected function _execute()
 {
     if (!$this->_account_id) {
         throw new Exception("Invalid report account: none provided.");
     }
     $account = $this->_load_account($this->_account_id);
     if (!$account->loaded()) {
         throw new Exception("Invalid report account: not found.");
     }
     if (!$this->_date_start) {
         throw new Exception("Invalid report start date: none provided.");
     }
     if ($this->_date_start != date("Y-m-d", strtotime($this->_date_start))) {
         throw new Exception("Invalid report start date: must be in format YYYY-MM-DD.");
     }
     if (!$this->_date_end) {
         throw new Exception("Invalid report end date: none provided.");
     }
     if ($this->_date_end != date("Y-m-d", strtotime($this->_date_end))) {
         throw new Exception("Invalid report end date: must be in format YYYY-MM-DD.");
     }
     $this->_account_transactions = ORM::Factory('account_transaction')->where('account_id', '=', $account->id)->where('date', '>=', $this->_date_start)->where('date', '<=', $this->_date_end)->order_by('date', 'asc')->order_by('close_books', 'desc')->order_by('transaction_id', 'asc')->find_all();
     $balance = NULL;
     // Calculate balance on-the-fly to avoid an error when pulling massive account transactions with balances mid-update.
     foreach ($this->_account_transactions as $i => $account_transaction) {
         if ($balance === NULL) {
             $balance = $this->_beans_round($account_transaction->balance);
         } else {
             $this->_account_transactions[$i]->balance = $this->_beans_round($balance + $account_transaction->amount);
             $balance = $this->_account_transactions[$i]->balance;
         }
     }
     return (object) array('date_start' => $this->_date_start, 'date_end' => $this->_date_end, 'account' => $this->_return_account_element($account), 'account_transactions' => $this->_return_ledger_transactions_array($this->_account_transactions));
 }
Exemple #5
0
 protected function _execute()
 {
     if (!$this->_date) {
         throw new Exception("Invalid report date: none provided.");
     }
     if ($this->_date != date("Y-m-d", strtotime($this->_date))) {
         throw new Exception("Invalid report date: must be in format YYYY-MM-DD.");
     }
     // We'll exclude these two accounts from our generated chart.
     $excluded_account_ids = array($this->_transaction_sale_deferred_income_account_id, $this->_transaction_sale_deferred_liability_account_id);
     // T2 Accounts ( just below top level )
     $t2_accounts = array();
     foreach (ORM::Factory('account')->where('parent_account_id', 'IS', NULL)->find_all() as $top_level_account) {
         foreach ($top_level_account->child_accounts->find_all() as $t2_account) {
             $t2_accounts[] = $t2_account;
         }
     }
     //
     // Query for our accounts - we're interested in
     //
     $account_types = array();
     $account_types['cash'] = new stdClass();
     $account_types['cash']->name = "Cash";
     $account_types['cash']->balance = 0.0;
     $account_types['cash']->direction = 1;
     $account_types['cash']->codes = array('cash', 'bankaccount');
     $account_types['cash']->accounts = array();
     $account_types['accountsreceivable'] = new stdClass();
     $account_types['accountsreceivable']->name = "Accounts Receivable";
     $account_types['accountsreceivable']->balance = 0.0;
     $account_types['accountsreceivable']->direction = 1;
     $account_types['accountsreceivable']->codes = array('accountsreceivable', 'pending_ar');
     $account_types['accountsreceivable']->accounts = array();
     $account_types['shorttermdebt'] = new stdClass();
     $account_types['shorttermdebt']->name = "Short Term Debt";
     $account_types['shorttermdebt']->balance = 0.0;
     $account_types['shorttermdebt']->direction = -1;
     $account_types['shorttermdebt']->codes = array('shorttermdebt', 'accountspayable', 'pending_ap');
     $account_types['shorttermdebt']->accounts = array();
     // $array is blank - fill it in.
     foreach ($account_types as $code => $account_type) {
         foreach ($t2_accounts as $t2_account) {
             $t2_result = $this->_build_code_chart($t2_account, $account_type->codes, TRUE, $excluded_account_ids);
             if ($t2_result) {
                 $account_types[$code]->accounts[] = $t2_result;
             }
         }
     }
     foreach ($account_types as $type => $account_type) {
         foreach ($account_type->accounts as $index => $account) {
             $account_types[$type]->accounts[$index] = $this->_generate_account_balance($account, $this->_date);
         }
     }
     $net = 0.0;
     foreach ($account_types as $type => $account_type) {
         $account_types[$type]->balance_total = $this->_generate_account_balance_total($account_type->accounts);
         $net = $this->_beans_round($net + $account_types[$type]->direction * $account_types[$type]->balance_total);
     }
     return (object) array('date' => $this->_date, 'account_types' => $account_types, 'net' => $net);
 }
Exemple #6
0
 public function index()
 {
     $procedimentos = ORM::Factory('procedimento')->lista_semana();
     $view = View::Factory('home/index');
     $view->set('procedimentos', $procedimentos);
     $this->template->content = $view;
 }
Exemple #7
0
 protected function _execute()
 {
     // One-off use case of looking up role by code.
     if (isset($this->_data->role_code) and $this->_data->role_code) {
         $role = ORM::Factory('role')->where('code', '=', $this->_data->role_code)->find();
         if ($role->loaded()) {
             $this->_data->role_id = $role->id;
         }
     }
     if (isset($this->_data->name)) {
         $this->_user->name = $this->_data->name;
     }
     if (isset($this->_data->email)) {
         $this->_user->email = $this->_data->email;
     }
     if (isset($this->_data->role_id)) {
         $this->_user->role_id = $this->_data->role_id;
     }
     if (isset($this->_data->password)) {
         $this->_user->password = $this->_beans_auth_password($this->_user->id, $this->_data->password);
     }
     $this->_validate_user($this->_user);
     $this->_user->save();
     return (object) array("user" => $this->_return_user_element($this->_user));
 }
 public function cleanup()
 {
     $this->auto_render = false;
     if (empty($_POST['survey_id']) || empty($_POST['mode'])) {
         header(' ', true, 400);
         $this->auto_render = false;
         echo 'Cannot cleanup without a survey ID and mode';
         return;
     }
     $survey = ORM::Factory('survey', $_POST['survey_id']);
     if (!($this->auth->logged_in('CoreAdmin') || $this->auth->has_website_access('admin', $survey->website_id))) {
         header(' ', true, 401);
         echo 'Access denied';
         return;
     }
     $occListQuery = 'select o.id, o.sample_id  into temporary occlist from occurrences o ' . 'join samples s on s.id=o.sample_id and s.survey_id=' . $survey->id;
     switch ($_POST['mode']) {
         case 'deleted':
             $occListQuery .= ' where o.deleted=true';
             break;
         case 'test':
             $occListQuery .= " where o.record_status='T'";
             break;
         case 'all':
             // no extra filter
             break;
         default:
             header(' ', true, 400);
             echo 'Invalid mode parameter';
             return;
     }
     $this->database = new Database();
     $this->database->query($occListQuery);
     $this->database->query('delete from occurrence_attribute_values where occurrence_id in (select id from occlist)');
     $this->database->query('delete from occurrence_comments where occurrence_id in (select id from occlist)');
     $this->database->query('delete from occurrence_images where occurrence_id in (select id from occlist)');
     $this->database->query('delete from determinations where occurrence_id in (select id from occlist)');
     // the number of occurrences deleted is the fact we need to report back
     $qry = $this->database->query('delete from occurrences where id in (select id from occlist)');
     $count = $qry->count();
     $this->database->query('delete from cache_occurrences where id in (select id from occlist)');
     // remove any samples that this query has left as empty
     $this->database->query('select s.id, s.parent_id into temporary smplist from samples s ' . 'join occlist o on o.sample_id=s.id ' . 'left join occurrences occ on occ.sample_id=s.id ' . 'where occ.id is null');
     // first any child samples
     $this->database->query('delete from sample_attribute_values where sample_id in (select id from smplist)');
     $this->database->query('delete from sample_comments where sample_id in (select id from smplist)');
     $this->database->query('delete from sample_images where sample_id in (select id from smplist)');
     $this->database->query('delete from samples where id in (select id from smplist)');
     // then the parents
     $this->database->query('select s.id into temporary parentlist from samples s ' . 'join smplist child on child.parent_id=s.id ' . 'left join samples smpcheck on smpcheck.id=s.id ' . 'where smpcheck.id is null');
     $this->database->query('delete from sample_attribute_values where sample_id in (select id from parentlist)');
     $this->database->query('delete from sample_comments where sample_id in (select id from parentlist)');
     $this->database->query('delete from sample_images where sample_id in (select id from parentlist)');
     $this->database->query('delete from samples where id in (select id from parentlist)');
     // cleanup
     $this->database->query('drop table occlist');
     $this->database->query('drop table smplist');
     $this->database->query('drop table parentlist');
     echo "{$count} occurrences deleted";
 }
Exemple #9
0
 /**
  * Attempt to load the Topic using the 'ID' parameter in the url.
  *
  * @throws HTTP_Exception_404 if topic is not found
  */
 public function before()
 {
     parent::before();
     $this->topic = ORM::Factory('Forum_Topic', $this->request->param('id'));
     if (!$this->topic->loaded()) {
         throw HTTP_Exception::factory('404', 'Forum topic not found');
     }
 }
 public function excluir($id)
 {
     $procedimento = ORM::Factory('procedimento', $id);
     $processo = $procedimento->processo;
     $procedimento->delete();
     html::flash_message('Procedimento excluído com sucesso!', 'success');
     url::redirect('processos/formulario/' . $processo->id);
 }
Exemple #11
0
 protected function _execute()
 {
     if (!$this->_account->loaded()) {
         throw new Exception("Account could not be found.");
     }
     if (ORM::Factory('account')->where('parent_account_id', '=', $this->_account->id)->count_all()) {
         throw new Exception("Please remove all child accounts before deleting.");
     }
     // Query for all transactions associated to this account.
     $transaction_id_rows = DB::query(Database::SELECT, 'SELECT DISTINCT(transaction_id) as transaction_id FROM account_transactions WHERE account_id = "' . $this->_account->id . '"')->execute()->as_array();
     if (count($transaction_id_rows) and !$this->_transfer_account->loaded()) {
         throw new Exception("Please select a transfer account.");
     }
     if (count($transaction_id_rows) and $this->_account->id == $this->_transfer_account->id) {
         throw new Exception("Transfer account cannot match the account being removed.");
     }
     // Loop each transaction and update appropriately.
     foreach ($transaction_id_rows as $transaction_id_row) {
         $transaction = $this->_load_transaction($transaction_id_row['transaction_id']);
         if (!$transaction->loaded()) {
             throw new Exception("An unexpected error has occurred: transaction not found.");
         }
         // Array for $account_id => $amount
         $new_account_transactions = array();
         $new_account_transactions[$this->_transfer_account->id] = 0.0;
         foreach ($transaction->account_transactions->find_all() as $account_transaction) {
             if ($account_transaction->account_reconcile_id) {
                 throw new Exception("Cannot delete accounts that have reconciled transactions.");
             }
             if ($account_transaction->account_transaction_forms->count_all()) {
                 throw new Exception("This account contains transactions that are associated with a form ( invoice, purchase, payment, etc. ).  At this time transactions associated with a form cannot be transferred.");
             }
             if ($account_transaction->account_id == $this->_account->id) {
                 $new_account_transactions[$this->_transfer_account->id] = $this->_beans_round($new_account_transactions[$this->_transfer_account->id] + $account_transaction->amount * $account_transaction->account->account_type->table_sign * $this->_transfer_account->account_type->table_sign);
             } else {
                 if (!isset($new_account_transactions[$account_transaction->account_id])) {
                     $new_account_transactions[$account_transaction->account_id] = 0.0;
                 }
                 $new_account_transactions[$account_transaction->account_id] = $this->_beans_round($new_account_transactions[$account_transaction->account_id] + $account_transaction->amount);
             }
         }
         // Array for $account_id => $amount
         $account_transaction_update_data = new stdClass();
         $account_transaction_update_data->id = $transaction->id;
         $account_transaction_update_data->account_transactions = array();
         foreach ($new_account_transactions as $account_id => $amount) {
             $account_transaction_update_data->account_transactions[] = (object) array('account_id' => $account_id, 'amount' => $amount);
         }
         $account_transaction_update = new Beans_Account_Transaction_Update($this->_beans_data_auth($account_transaction_update_data));
         $account_transaction_update_result = $account_transaction_update->execute();
         if (!$account_transaction_update_result->success) {
             throw new Exception("Error updating account transaction: " . $account_transaction_update_result->error);
         }
     }
     // Now delete account.
     $this->_account->delete();
     return (object) array();
 }
Exemple #12
0
 /**
  * Create a new movie.
  * @param integer $parent_id id of parent album
  * @param string  $filename path to the photo file on disk
  * @param string  $name the filename to use for this photo in the album
  * @param integer $title the title of the new photo
  * @param string  $description (optional) the longer description of this photo
  * @return Item_Model
  */
 static function create($parent, $filename, $name, $title, $description = null, $owner_id = null)
 {
     if (!$parent->loaded || !$parent->is_album()) {
         throw new Exception("@todo INVALID_PARENT");
     }
     if (!is_file($filename)) {
         throw new Exception("@todo MISSING_MOVIE_FILE");
     }
     if (strpos($name, "/")) {
         throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
     }
     // We don't allow trailing periods as a security measure
     // ref: http://dev.kohanaphp.com/issues/684
     if (rtrim($name, ".") != $name) {
         throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
     }
     $movie_info = movie::getmoviesize($filename);
     // Force an extension onto the name
     $pi = pathinfo($filename);
     if (empty($pi["extension"])) {
         $pi["extension"] = image_type_to_extension($movie_info[2], false);
         $name .= "." . $pi["extension"];
     }
     $movie = ORM::factory("item");
     $movie->type = "movie";
     $movie->title = $title;
     $movie->description = $description;
     $movie->name = $name;
     $movie->owner_id = $owner_id ? $owner_id : user::active();
     $movie->width = $movie_info[0];
     $movie->height = $movie_info[1];
     $movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv";
     $movie->thumb_dirty = 1;
     $movie->resize_dirty = 1;
     $movie->sort_column = "weight";
     $movie->rand_key = (double) mt_rand() / (double) mt_getrandmax();
     // Randomize the name if there's a conflict
     while (ORM::Factory("item")->where("parent_id", $parent->id)->where("name", $movie->name)->find()->id) {
         // @todo Improve this.  Random numbers are not user friendly
         $movie->name = rand() . "." . $pi["extension"];
     }
     // This saves the photo
     $movie->add_to_parent($parent);
     // If the thumb or resize already exists then rename it
     if (file_exists($movie->resize_path()) || file_exists($movie->thumb_path())) {
         $movie->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
         $movie->save();
     }
     copy($filename, $movie->file_path());
     module::event("item_created", $movie);
     // Build our thumbnail
     graphics::generate($movie);
     // If the parent has no cover item, make this it.
     if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
         item::make_album_cover($movie);
     }
     return $movie;
 }
Exemple #13
0
 public function __construct($data = NULL)
 {
     parent::__construct($data);
     $this->_addresses = ORM::Factory('entity_address')->distinct(TRUE);
     $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0;
     $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50;
     $this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest";
     $this->_search_customer_id = isset($data->search_customer_id) ? (int) $data->search_customer_id : FALSE;
 }
 public function diff($id = FALSE)
 {
     if (!$id) {
         throw new Kohana_404_Exception();
     }
     $this->template->this_page = 'revision';
     $this->template->content = new View('admin/reports/revision');
     $this->template->content->revisions = ORM::Factory('revision_incident')->where('incident_id', $id)->orderby('time', 'DESC')->find_all();
 }
 /**
  * Setup the default values to use when loading this controller to edit an existing code.   
  */
 protected function getModelValues()
 {
     $r = parent::getModelValues();
     // The code is linked to a taxon meaning, but we need to use this to link back to the
     // preferred taxa in taxon list, so when you save it knows where to go back to.
     $ttl = ORM::Factory('taxa_taxon_list')->where(array('taxon_meaning_id' => $this->model->taxon_meaning_id, 'preferred' => 'true'))->find();
     $r['taxa_taxon_list:id'] = $ttl->id;
     return $r;
 }
Exemple #16
0
 /**
 Loads a correspoding page from the DB and return that if its present in Table
 */
 public function load_page()
 {
     $page = ORM::Factory('page', $this->request->action());
     if ($page->loaded()) {
         $this->response->body($page->page_text);
         return true;
     }
     return false;
 }
Exemple #17
0
 protected function getWebsiteIds($personId)
 {
     $person = ORM::Factory('person', $personId);
     $websiteIds = array();
     $r = $this->db->select('users_websites.website_id')->from('people')->join('users', 'users.person_id', 'people.id')->join('users_websites', 'users_websites.user_id', 'users.id')->where(array('people.id' => $personId, 'users.deleted' => 'f'))->where('users_websites.site_role_id is not null')->get()->result_array(false);
     foreach ($r as $website) {
         $websiteIds[] = $website['website_id'];
     }
     return $websiteIds;
 }
Exemple #18
0
 public function __construct($data = NULL)
 {
     parent::__construct($data);
     $this->_account_reconciles = ORM::Factory('account_reconcile');
     $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0;
     $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50;
     $this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest";
     // Check for search fields.
     $this->_search_account_id = isset($data->account_id) ? $data->account_id : FALSE;
 }
Exemple #19
0
 public function lista_semana()
 {
     $semana = date::week_days();
     //echo Kohana::debug($semana);
     $lista = array();
     foreach ($semana as $dia) {
         $lista[$dia] = ORM::Factory('procedimento')->where('data', $dia)->find_all();
     }
     return $lista;
 }
Exemple #20
0
 /**
  * Checks if a model object already exists for a field with the given values.
  *
  * @param   array    Validation object
  * @param   string   model name
  * @param   string   primary field name
  * @param   array    array with other field names
  * @return  boolean
  */
 public static function not_exists($array, $model, $field, $other_fields)
 {
     $obj = ORM::Factory($model)->where($field, '=', $array[$field]);
     foreach ($other_fields as $fld) {
         $obj = $obj->and_where($fld, '=', $array[$fld]);
     }
     if (isset($array['id'])) {
         $obj = $obj->and_where('id', '!=', $array['id']);
     }
     return $obj->count_all() == 0;
 }
Exemple #21
0
 protected function _execute()
 {
     if (!isset($this->_data->email)) {
         throw new Exception("Please provide a valid email address.");
     }
     $user = ORM::Factory('user')->where('email', 'LIKE', $this->_data->email)->find();
     if (!$user->loaded()) {
         throw new Exception("Login error: that email address was not found.");
     }
     if (isset($this->_data->resetkey) && strlen($this->_data->resetkey)) {
         if (!isset($this->_data->password) or !strlen($this->_data->password)) {
             throw new Exception("Please provide a valid password.");
         }
         if ($user->reset != $this->_data->resetkey) {
             throw new Exception("Invalid reset key.  Please try sending the email again.");
         }
         if ($user->reset_expiration < time()) {
             throw new Exception("Reset key expired.  Please try sending the email again.");
         }
         $user->reset = NULL;
         $user->reset_expiration = NULL;
         $user->password_change = FALSE;
         $user->password = $this->_beans_auth_password($user->id, $this->_data->password);
         // And auto-login...
         $expiration = $user->role->auth_expiration_length != 0 ? time() + $user->role->auth_expiration_length : rand(11111, 99999);
         // Generate a random for salt.
         $user->auth_expiration = $expiration;
         $user->save();
         return (object) array("auth" => $this->_return_auth_element($user, $expiration));
     } else {
         // Generate Key
         $user->reset = $this->_generate_reset($user->id);
         $user->reset_expiration = time() + 10 * 60;
         $user->save();
         // This is the one email we send from within the app for security.
         $auth_print_reset = new View_Auth_Print_Reset();
         $auth_print_reset->user = $user;
         $message = Swift_Message::newInstance();
         $message->setSubject('BeansBooks Password Reset')->setFrom(array($this->_beans_setting_get('company_email') ? $this->_beans_setting_get('company_email') : '*****@*****.**'))->setTo(array($user->email));
         $auth_print_reset->swift_email_message = $message;
         $message = $auth_print_reset->render();
         try {
             if (!Email::connect()) {
                 throw new Exception("Could not send email. Does your config have correct email settings?");
             }
             if (!Email::sendMessage($message)) {
                 throw new Exception("Could not send email. Does your config have correct email settings?");
             }
         } catch (Exception $e) {
             throw new Exception("An error occurred when sending the email: have you setup email properly in config.php?");
         }
     }
     return (object) array();
 }
Exemple #22
0
 /**
  * Search by ID.
  * @param array $data Array of parameters by keys:
  *                    'id' => ID of the tax to lookup.
  */
 public function __construct($data = NULL)
 {
     parent::__construct($data);
     $this->_taxes = ORM::Factory('tax')->distinct(TRUE);
     $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0;
     $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50;
     $this->_search_and = isset($data->search_and) ? $data->search_and ? TRUE : FALSE : FALSE;
     $this->_search_code = (isset($data->search_code) and strlen($data->search_code)) ? $data->search_code : FALSE;
     $this->_search_name = (isset($data->search_name) and strlen($data->search_name)) ? $data->search_name : FALSE;
     $this->_search_include_hidden = (isset($data->search_include_hidden) and $data->search_include_hidden) ? TRUE : FALSE;
 }
Exemple #23
0
 public function genre_list()
 {
     $genre_list = array();
     $genre_model = ORM::Factory('genre');
     foreach ($genre_model->find_all()->as_array() as $genre) {
         $genre = $genre->as_array();
         $genre['selected'] = $genre['id'] == $this->album['genre_id'];
         $genre_list[] = $genre;
     }
     return $genre_list;
 }
Exemple #24
0
 public function __construct($data = NULL)
 {
     parent::__construct($data);
     $this->_transactions = ORM::Factory('transaction')->distinct(TRUE)->join('entities', 'LEFT')->on('entities.id', '=', 'transaction.entity_id');
     $this->_page = (isset($data->page) and (int) $data->page >= 0) ? (int) $data->page : 0;
     $this->_page_size = (isset($data->page_size) and (int) $data->page_size > 0) ? (int) $data->page_size : 50;
     $this->_sort_by = isset($data->sort_by) ? strtolower($data->sort_by) : "newest";
     $this->_form_id = isset($data->form_id) ? $data->form_id : FALSE;
     // Re-declare $this->_transactions to use proper joins for a form search.
     $this->_transactions = ORM::Factory('transaction')->DISTINCT(TRUE)->join('account_transactions', 'RIGHT')->on('account_transactions.transaction_id', '=', 'transaction.id')->join('account_transaction_forms', 'RIGHT')->on('account_transaction_forms.account_transaction_id', '=', 'account_transactions.id');
 }
 protected function getDefaults()
 {
     $r = parent::getDefaults();
     // as you can't create an occurrence in the warehouse, no logic yet for which attributes
     // to display
     if ($this->uri->method(false) !== 'create') {
         $sample = ORM::Factory('sample', $_POST['occurrence:sample_id']);
         $this->loadAttributes($r, array('website_id' => array($_POST['occurrence:website_id']), 'restrict_to_survey_id' => array(null, $sample->survey_id)));
     }
     return $r;
 }
Exemple #26
0
 protected function _execute()
 {
     if ($this->_customer_id and !$this->_load_customer($this->_customer_id)->loaded()) {
         throw new Exception("Invalid report customer ID: customer not found.");
     }
     // Look up all sale IDs
     $sale_ids_query = 'SELECT id FROM forms WHERE type = "sale" AND date_due IS NULL AND date_cancelled IS NULL ';
     if ($this->_customer_id) {
         $sale_ids_query .= ' AND entity_id = "' . $this->_customer_id . '" ';
     }
     if ($this->_days_old_minimum) {
         $sale_ids_query .= ' AND date_created <= DATE("' . date("Y-m-d", strtotime("-" . $this->_days_old_minimum . " Days")) . '") ';
     }
     if ($this->_balance_filter) {
         if ($this->_balance_filter == "unpaid") {
             $sale_ids_query .= ' AND ( balance + total ) = 0 ';
         } else {
             if ($this->_balance_filter == "paid") {
                 $sale_ids_query .= ' AND ( balance + total ) != 0 ';
             } else {
                 throw new Exception("Invalid balance_filter: must be paid or unpaid.");
             }
         }
     }
     $sale_ids_query .= ' ORDER BY date_created ASC, id ASC ';
     $sale_ids = DB::Query(Database::SELECT, $sale_ids_query)->execute()->as_array();
     $customers = array();
     $timestamp_today = strtotime(date("Y-m-d"));
     $total_total = 0.0;
     $paid_total = 0.0;
     $balance_total = 0.0;
     foreach ($sale_ids as $sale_id) {
         $sale = ORM::Factory('form_sale', $sale_id);
         if (!isset($customers[$sale->entity_id])) {
             $customers[$sale->entity_id] = new stdClass();
             $customers[$sale->entity_id]->customer_name = $sale->entity->first_name . ' ' . $sale->entity->last_name;
             $customers[$sale->entity_id]->customer_company_name = $sale->entity->company_name;
             $customers[$sale->entity_id]->customer_phone_number = $sale->entity->phone_number;
             $customers[$sale->entity_id]->sales = array();
             $customers[$sale->entity_id]->total_total = 0.0;
             $customers[$sale->entity_id]->paid_total = 0.0;
             $customers[$sale->entity_id]->balance_total = 0.0;
         }
         $report_sale = (object) array('id' => $sale->id, 'date_created' => $sale->date_created, 'date_due' => $sale->date_due, 'sale_number' => $sale->code, 'balance' => $sale->balance * -1, 'total' => $sale->total, 'paid' => $sale->total - $sale->balance * -1, 'days_late' => round(($timestamp_today - strtotime($sale->date_created)) / 86400));
         $customers[$sale->entity_id]->total_total = $this->_beans_round($customers[$sale->entity_id]->total_total + $report_sale->total);
         $customers[$sale->entity_id]->paid_total = $this->_beans_round($customers[$sale->entity_id]->paid_total + $report_sale->paid);
         $customers[$sale->entity_id]->balance_total = $this->_beans_round($customers[$sale->entity_id]->balance_total + $report_sale->balance);
         $total_total = $this->_beans_round($total_total + $report_sale->total);
         $paid_total = $this->_beans_round($paid_total + $report_sale->paid);
         $balance_total = $this->_beans_round($balance_total + $report_sale->balance);
         $customers[$sale->entity_id]->sales[] = $report_sale;
     }
     return (object) array('date' => date("Y-m-d"), 'customer_id' => $this->_customer_id, 'days_old_minimum' => $this->_days_old_minimum, 'balance_filter' => $this->_balance_filter, 'customers' => $customers, 'total_customers' => count($customers), 'total_total' => $total_total, 'paid_total' => $paid_total, 'balance_total' => $balance_total);
 }
 public function index($id = FALSE)
 {
     header("Content-type: text/plain; charset=UTF-8\n");
     $this->template->this_page = 'revision';
     $this->template->content = '';
     foreach (ORM::Factory('revision_incident')->find_all() as $revision) {
         var_dump(unserialize($revision->data));
         //var_dump($revision);
     }
     exit;
 }
Exemple #28
0
 public function excluir($id)
 {
     $usuario = ORM::Factory('usuario', $id);
     //se exclui usuarios q nao seja o root
     if ($id > 1) {
         $nome = $usuario->nome;
         $usuario->delete();
         html::flash_message('Usuário <b>' . $nome . '</b> excluído com sucesso!', 'success');
     }
     url::redirect('usuarios/');
 }
Exemple #29
0
 /**
  * Controller action to display the parameters editing page for the report associated with this
  * trigger. Displayed after clicking Next on the main edit page.
  */
 public function edit_params($id = null)
 {
     $this->model = ORM::Factory($this->model->object_name, $id);
     if ($id) {
         // existing record, so we can get the params json data to convert it to individual params
         $params = json_decode($this->model->params_json, true);
     } else {
         $params = array();
     }
     $this->setView('trigger/params_edit', 'Parameters for ' . $this->model->caption(), array('values' => $_POST, 'other_data' => array('defaults' => $params)));
     $this->defineEditBreadcrumbs();
 }
Exemple #30
0
 public function select_list_with_childrens()
 {
     $lista = array();
     $armarios = ORM::Factory('armario')->find_all();
     foreach ($armarios as $armario) {
         $gavetas = $armario->gavetas->select_list('id', 'nome');
         if (sizeof($gavetas)) {
             $lista[$armario->nome] = $gavetas;
         }
     }
     return $lista;
 }