/** * Public method. Called when user wants to edit a composite. * @param HTTP::id the composite ID */ public function edit() { $GLOBALS['phpgw_info']['flags']['app_header'] .= '::' . lang('edit'); // Get the composite ID $composite_id = (int) phpgw::get_var('id'); // Retrieve the party object or create a new one if correct permissions if ($this->isExecutiveOfficer() || $this->isAdministrator()) { if (isset($composite_id) && $composite_id > 0) { $composite = rental_socomposite::get_instance()->get_single($composite_id); } else { $composite = new rental_composite(); } } else { $this->render('permission_denied.php', array('error' => lang('permission_denied_edit'))); } if (isset($_POST['save_composite'])) { if (isset($composite)) { $composite->set_name(phpgw::get_var('name')); $composite->set_custom_address_1(phpgw::get_var('address_1')); $composite->set_has_custom_address(phpgw::get_var('has_custom_address') == 'on' ? true : false); $composite->set_custom_house_number(phpgw::get_var('house_number')); $composite->set_custom_address_2(phpgw::get_var('address_2')); $composite->set_custom_postcode(phpgw::get_var('postcode')); $composite->set_custom_place(phpgw::get_var('place')); $composite->set_is_active(phpgw::get_var('is_active') == 'on' ? true : false); $composite->set_description(phpgw::get_var('description')); $composite->set_furnish_type_id(phpgw::get_var('furnish_type_id')); $composite->set_standard_id(phpgw::get_var('composite_standard_id', 'int')); if (rental_socomposite::get_instance()->store($composite)) { $message = lang('messages_saved_form'); } else { $error = lang('messages_form_error'); } } } return $this->render('composite.php', array('composite' => $composite, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'cancel_link' => self::link(array('menuaction' => 'rental.uicomposite.index', 'populate_form' => 'yes')))); }
function populate(int $composite_id, &$composite) { if ($composite == null) { $composite = new rental_composite($composite_id); $composite->set_description($this->unmarshal($this->db->f('description', true), 'string')); $composite->set_is_active($this->db->f('is_active')); $composite_name = $this->unmarshal($this->db->f('name', true), 'string'); if ($composite_name == null || $composite_name == '') { $composite_name = lang('no_name_composite', $composite_id); } $composite->set_name($composite_name); $composite->set_has_custom_address($this->unmarshal($this->db->f('has_custom_address', true), 'bool')); $composite->set_custom_address_1($this->unmarshal($this->db->f('address_1', true), 'string')); $composite->set_custom_address_2($this->unmarshal($this->db->f('address_2', true), 'string')); $composite->set_custom_house_number($this->unmarshal($this->db->f('house_number', true), 'string')); $composite->set_custom_postcode($this->unmarshal($this->db->f('postcode', true), 'string')); $composite->set_custom_place($this->unmarshal($this->db->f('place', true), 'string')); $composite->set_area($this->unmarshal($this->db->f('area', true), 'float')); $composite->set_furnish_type_id($this->unmarshal($this->db->f('furnish_type_id'), 'int')); $composite->set_standard_id($this->unmarshal($this->db->f('standard_id'), 'int')); } // Location code $location_code = $this->unmarshal($this->db->f('location_code', true), 'string'); //Status $database_status = $this->unmarshal($this->db->f('status', true), 'string'); $composite_status = $composite->get_status(); if ($composite_status != 'Ikke ledig') { $composite->set_status($database_status); } $contract_id = $this->unmarshal($this->db->f('contract_id', true), 'int'); // Adds contract to array in composite object if it's not already added if ($contract_id != 0 & !$composite->contains_contract($contract_id)) { $contract = new rental_contract($contract_id); $start_date = $this->unmarshal($this->db->f('date_start', true), 'int'); $end_date = $this->unmarshal($this->db->f('date_end', true), 'int'); $old_contract_id = $this->unmarshal($this->db->f('old_contract_id', true), 'string'); // Adds contract if end date is not specified or greater than todays date if ($end_date == 0 || $end_date > time()) { $contract_date = new rental_contract_date($start_date, $end_date); $contract->set_contract_date($contract_date); $contract->set_old_contract_id($old_contract_id); $composite->add_contract($contract); } } if (!$composite->contains_unit($location_code)) { //composite inneholder ikke unit -> legg den til $location = null; try { // We get the data from the property module $data = @execMethod('property.bolocation.read_single', array('location_code' => $location_code, 'extra' => array('view' => true))); if ($data != null) { $level = -1; $names = array(); $levelFound = false; for ($i = 1; $i < 6; $i++) { $loc_name = 'loc' . $i . '_name'; if (array_key_exists($loc_name, $data)) { $level = $i; $names[$level] = $data[$loc_name]; } } $gab_id = ''; $gabinfos = @execMethod('property.sogab.read', array('location_code' => $location_code, 'allrows' => true)); if ($gabinfos != null && is_array($gabinfos) && count($gabinfos) == 1) { $gabinfo = array_shift($gabinfos); $gab_id = $gabinfo['gab_id']; } $location = new rental_property_location($location_code, rental_uicommon::get_nicely_formatted_gab_id($gab_id), $level, $names); if (isset($data['street_name']) && $data['street_name']) { $location->set_address_1($data['street_name'] . ' ' . $data['street_number']); } //$location->set_address_1($data['address']); foreach ($data['attributes'] as $attributes) { switch ($attributes['column_name']) { case 'area_gross': $location->set_area_gros($attributes['value']); break; case 'area_net': $location->set_area_net($attributes['value']); break; } } } else { $location = new rental_property_location($location_code, null, 1, array()); } } catch (Exception $e) { $location = new rental_property_location($location_code, null, 1, array()); } $composite->add_unit(new rental_unit($this->unmarshal($this->db->f('unit_id', true), 'int'), $composite_id, $location)); } return $composite; }