public function action_accountupdate() { $account_update = new Beans_Account_Update($this->_beans_data_auth((object) array('id' => $this->request->post('account_id'), 'parent_account_id' => $this->request->post('parent_account_id'), 'account_type_id' => $this->request->post('account_type_id'), 'name' => $this->request->post('name'), 'code' => substr(strtolower(str_replace(' ', '', $this->request->post('name'))), 0, 16), 'terms' => strlen($this->request->post('terms')) ? $this->request->post('terms') : NULL))); $account_update_result = $account_update->execute(); if (!$account_update_result->success) { return $this->_return_error($this->_beans_result_get_error($account_update_result)); } // Success! $this->_return_object->data->account = $account_update_result->data->account; }
function action_settings() { // Handle $_POST $data = new stdClass(); $data->settings = new stdClass(); if (count($this->request->post())) { // Update every account - THREE LAWS. $accounts_search = new Beans_Account_Search($this->_beans_data_auth()); $accounts_search_result = $accounts_search->execute(); if ($this->_beans_result_check($accounts_search_result)) { foreach ($accounts_search_result->data->accounts as $account) { if ($account->parent_account_id and !$account->reserved) { $account_update_result = FALSE; if (in_array($account->id, $this->request->post('writeoff_account_ids'))) { $account_update = new Beans_Account_Update($this->_beans_data_auth((object) array('id' => $account->id, 'writeoff' => TRUE))); $account_update_result = $account_update->execute(); } else { $account_update = new Beans_Account_Update($this->_beans_data_auth((object) array('id' => $account->id, 'writeoff' => FALSE))); $account_update_result = $account_update->execute(); } if (!$account_update_result) { $this->_view->send_error_message('An unexpected error occurred.'); } // We can ignore the return value - this will post the necessary error. $this->_beans_result_check($account_update_result); } } $data->settings->company_name = $this->request->post('company_name'); $data->settings->company_email = $this->request->post('company_email'); $data->settings->company_phone = $this->request->post('company_phone'); $data->settings->company_fax = $this->request->post('company_fax'); $data->settings->company_address_address1 = $this->request->post('company_address_address1'); $data->settings->company_address_address2 = $this->request->post('company_address_address2'); $data->settings->company_address_city = $this->request->post('company_address_city'); $data->settings->company_address_state = $this->request->post('company_address_state'); $data->settings->company_address_zip = $this->request->post('company_address_zip'); $data->settings->company_address_country = $this->request->post('company_address_country'); $data->settings->company_fye = $this->request->post('company_fye'); $data->settings->company_currency = $this->request->post('company_currency'); $data->settings->account_default_deposit = $this->request->post('account_default_deposit'); $data->settings->account_default_receivable = $this->request->post('account_default_receivable'); $data->settings->account_default_income = $this->request->post('account_default_income'); $data->settings->account_default_returns = $this->request->post('account_default_returns'); $data->settings->account_default_expense = $this->request->post('account_default_expense'); $data->settings->account_default_order = $this->request->post('account_default_order'); $data->settings->account_default_costofgoods = $this->request->post('account_default_costofgoods'); $data->settings->account_default_payable = $this->request->post('account_default_payable'); if (isset($_FILES['logo']) and $_FILES['logo']['error'] == UPLOAD_ERR_OK) { // Do some magic. $type = strtolower(substr($_FILES['logo']['type'], 1 + strpos($_FILES['logo']['type'], '/'))); if (substr($_FILES['logo']['type'], 0, strpos($_FILES['logo']['type'], '/')) == "image" and ($type == "gif" or $type == "png" or $type == "jpeg" or $type == "jpg")) { $image = FALSE; if ($type == "jpeg" or $type == "jpg") { $image = imagecreatefromjpeg($_FILES['logo']['tmp_name']); } else { if ($type == "gif") { $image = imagecreatefromgif($_FILES['logo']['tmp_name']); } else { if ($type == "png") { $image = imagecreatefrompng($_FILES['logo']['tmp_name']); imagealphablending($image, TRUE); imagesavealpha($image, TRUE); } } } if (!$image) { $this->_view->send_error_message("An error occurred when reading your image. Must be JPG/JPEG, PNG, or GIF."); } else { $width = imagesx($image); $height = imagesy($image); if ($width > 150 or $height > 50) { // Resize $new_width = 150; $new_height = 50; if ($width / $height > $new_width / $new_height) { $new_height = $new_width * ($height / $width); } else { $new_width = $new_height * ($width / $height); } $new_image = imagecreatetruecolor($new_width, $new_height); if (strtolower($type) == "png") { imagealphablending($new_image, false); imagesavealpha($new_image, true); $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); imagefilledrectangle($new_image, 0, 0, $new_width, $new_height, $transparent); } imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $image = $new_image; } // Fancy trick to avoid writing to the filesystem. $logo_filename = "logo."; ob_start(); if ($type == "jpeg" or $type == "jpg") { $logo_filename .= "jpg"; imagejpeg($image, NULL, 95); } else { if ($type == "gif") { $logo_filename .= "gif"; imagegif($image); } else { if ($type == "png") { $logo_filename .= "png"; imagepng($image, NULL, 9); } } } $image_string = ob_get_contents(); ob_end_clean(); // Ensure "image/jpeg" if it's JPEG. $type = $type == "jpg" ? "jpeg" : $type; $data->settings->company_logo_data = base64_encode($image_string); $data->settings->company_logo_type = 'image/' . $type; // Not really necessary. $data->settings->company_logo_filename = $logo_filename; } } else { $this->_view->send_error_message("That logo was not an acceptable image format. Must be JPG/JPEG, PNG, or GIF."); } } else { if (isset($_FILES['logo']) and $_FILES['logo']['error'] != UPLOAD_ERR_NO_FILE) { $this->_view->send_error_message("An error occurred when receiving that logo. Please try again with a smaller file." . $_FILES['logo']['error']); } } } } $beans_company_update = new Beans_Setup_Company_Update($this->_beans_data_auth($data)); $beans_company_update_result = $beans_company_update->execute(); if ($this->_beans_result_check($beans_company_update_result)) { $this->_view->beans_company_update_result = $beans_company_update_result; } }