/** * Get a static reference to the storage object associated with this model object * * @return the storage object */ public static function get_instance() { if (self::$bo == null) { self::$bo = CreateObject('frontend.bofellesdata'); } return self::$bo; }
/** * Create useraccount on login for SSO/ntlm * * @return void */ public function auto_addaccount() { $account_lid = $GLOBALS['hook_values']['account_lid']; if (!$GLOBALS['phpgw']->accounts->exists($account_lid)) { $config = CreateObject('phpgwapi.config', 'frontend'); $config->read(); $autocreate_user = isset($config->config_data['autocreate_user']) && $config->config_data['autocreate_user'] ? $config->config_data['autocreate_user'] : 0; if ($autocreate_user) { $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($account_lid); if ($fellesdata_user) { // Read default assign-to-group from config $default_group_id = isset($config->config_data['frontend_default_group']) && $config->config_data['frontend_default_group'] ? $config->config_data['frontend_default_group'] : 0; $group_lid = $GLOBALS['phpgw']->accounts->name2id($default_group_id); $group_lid = $group_lid ? $group_lid : 'frontend_delegates'; $password = '******' . mt_rand(100, mt_getrandmax()) . '&'; $account_id = frontend_bofrontend::create_delegate_account($account_lid, $fellesdata_user['firstname'], $fellesdata_user['lastname'], $password, $group_lid); if ($account_id) { $GLOBALS['phpgw']->redirect_link('/login.php', array()); } } } } }
public function index() { $config = CreateObject('phpgwapi.config', 'rental'); $config->read(); $use_fellesdata = $config->config_data['use_fellesdata']; if (isset($_POST['search'])) { $username = phpgw::get_var('username'); if (!isset($username)) { $msglog['error'][] = array('msg' => lang('lacking_username')); } else { if ($username == $GLOBALS['phpgw_info']['user']['account_lid']) { $msglog['error'][] = array('msg' => lang('searching_for_self')); } else { $account_id = frontend_bofrontend::delegate_exist($username); if ($account_id) { $search = frontend_bofrontend::get_account_info($account_id); $msglog['message'][] = array('msg' => lang('user_found_in_PE')); } else { if ($use_fellesdata) { $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($username); if ($fellesdata_user) { $search = $fellesdata_user; $msglog['message'][] = array('msg' => lang('user_found_in_Fellesdata')); } } else { $msglog['error'][] = array('msg' => lang('no_hits')); } } } } } else { if (isset($_POST['add'])) { $account_id = phpgw::get_var('account_id'); $success = false; if ($use_fellesdata) { $org_units = frontend_bofellesdata::get_instance()->get_result_units($GLOBALS['phpgw_info']['user']['account_lid']); //Parameter to delegate access to only a single organisational unit $org_unit_id = $this->header_state['selected_org_unit']; $success = true; foreach ($org_units as $org_unit) { if ($org_unit_id == 'all' || $org_unit['ORG_UNIT_ID'] == $org_unit_id) { //$curr_success = true; $res = $this->add_delegate($account_id, $org_unit['ORG_UNIT_ID'], $org_unit['ORG_NAME']); if ($res) { //$mail_contents[] = $res; $org_unit_names[] = $org_unit['ORG_NAME']; } else { $msglog['error'][] = array('msg' => lang('error_delegating_unit', $org_unit['ORG_NAME'])); } $success = $success && $res; } } } if ($success) { //Retrieve the usernames $user_account = $GLOBALS['phpgw']->accounts->get($account_id); $owner_account = $GLOBALS['phpgw']->accounts->get($GLOBALS['phpgw_info']['user']['account_id']); $user_name = $user_account->__get('lid'); $owner_name = $owner_account->__get('lid'); $org_name_string = implode(',', $org_unit_names); //If the usernames are set retrieve account data from Fellesdata if (isset($user_name) && $user_name != '' && $owner_name && $owner_name != '') { $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($user_name); $fellesdata_owner = frontend_bofellesdata::get_instance()->get_user($owner_name); if ($fellesdata_user && $fellesdata_owner) { //Send email notification to delegate $email = $fellesdata_user['email']; if (isset($email) && $email != '') { $title = lang('email_add_delegate_title'); $message = lang('email_add_delegate_message', $fellesdata_user['firstname'], $fellesdata_user['lastname'], $fellesdata_owner['firstname'], $fellesdata_owner['lastname'], $org_name_string); frontend_bofrontend::send_system_message($email, $title, $message); } } } $msglog['message'][] = array('msg' => lang('delegation_successful')); /* //send e-mail to user $user_account = $GLOBALS['phpgw']->accounts->get($account_id); $user_name = $user_account->__get('lid'); $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($user_name); if($fellesdata_user) { $email = $fellesdata_user['email']; if(isset($email) && $email != '') { $title = lang('email_add_delegate_title'); $mail_content = implode(',',$mail_contents); frontend_bofrontend::send_system_message($email,$title,$mail_content); } }*/ } else { $msglog['error'][] = array('msg' => lang('delegation_error')); } } else { if (isset($_POST['remove'])) { $account_id = phpgw::get_var('account_id'); $result = frontend_bofrontend::remove_delegate($account_id, null, null); if ($result) { $msglog['message'][] = array('msg' => lang('remove_delegate_successful')); } else { $msglog['error'][] = array('msg' => lang('remove_delegate_error')); } } else { if (isset($_POST['remove_specific'])) { $account_id = phpgw::get_var('account_id'); //Parameter to delegate access to only a single organisational unit $org_unit_id = $this->header_state['selected_org_unit']; $result = frontend_bofrontend::remove_delegate($account_id, null, $org_unit_id); if ($result) { $msglog['message'][] = array('msg' => lang('remove_delegate_successful')); } else { $msglog['error'][] = array('msg' => lang('remove_delegate_error')); } } } } } $form_action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'frontend.uidelegates.index')); $delegates_per_org_unit = frontend_bofrontend::get_delegates($this->header_state['selected_org_unit']); $delegates_per_user = frontend_bofrontend::get_delegates(null, true); $number_of_delegates = count($delegates_per_org_unit); $number_of_user_delegates = count($delegates_per_user); $config = CreateObject('phpgwapi.config', 'frontend'); $config->read(); $delegateLimit = $config->config_data['delegate_limit']; if (!is_numeric($delegateLimit)) { $delegateLimit = 3; } $error_message = lang('max_x_delegates', $delegateLimit); $data = array('header' => $this->header_state, 'tabs' => $this->tabs, 'delegate_data' => array('form_action' => $form_action, 'delegate' => $delegates_per_org_unit, 'user_delegate' => $delegates_per_user, 'number_of_delegates' => isset($number_of_delegates) ? $number_of_delegates : 0, 'number_of_user_delegates' => isset($number_of_user_delegates) ? $number_of_user_delegates : 0, 'search' => isset($search) ? $search : array(), 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($GLOBALS['phpgw']->common->msgbox_data($msglog)), 'delegate_limit' => $delegateLimit, 'error_message' => $error_message)); $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('app_data' => $data)); $GLOBALS['phpgw']->xslttpl->add_file(array('frontend', 'delegate')); }
public function add_delegate(int $account_id, $org_unit_id, $org_name) { $config = CreateObject('phpgwapi.config', 'rental'); $config->read(); $use_fellesdata = $config->config_data['use_fellesdata']; if (!isset($account_id) || $account_id == '' && $use_fellesdata) { //User is only registered in Fellesdata $username = phpgw::get_var('username'); $firstname = phpgw::get_var('firstname'); $lastname = phpgw::get_var('lastname'); $password = '******'; $account_id = frontend_bofrontend::create_delegate_account($username, $firstname, $lastname, $password); if (isset($account_id) && !is_numeric($account_id)) { return false; } } $success = frontend_bofrontend::add_delegate($account_id, null, $org_unit_id, $org_name); if ($success) { //Retrieve the usernames $user_account = $GLOBALS['phpgw']->accounts->get($account_id); $owner_account = $GLOBALS['phpgw']->accounts->get($GLOBALS['phpgw_info']['user']['account_id']); $user_name = $user_account->__get('lid'); $owner_name = $owner_account->__get('lid'); $org_name_string = $org_name; //If the usernames are set retrieve account data from Fellesdata if (isset($user_name) && $user_name != '' && $owner_name && $owner_name != '' && $use_fellesdata) { $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($user_name); $fellesdata_owner = frontend_bofellesdata::get_instance()->get_user($owner_name); if ($fellesdata_user && $fellesdata_owner) { //Send email notification to delegate $email = $fellesdata_user['email']; if (isset($email) && $email != '') { $title = lang('email_add_delegate_title'); $message = lang('email_add_delegate_message', $fellesdata_user['firstname'], $fellesdata_user['lastname'], $fellesdata_owner['firstname'], $fellesdata_owner['lastname'], $org_name_string); frontend_bofrontend::send_system_message($email, $title, $message); return true; } } } } return false; }
public function __construct() { // This module uses XSLT templates $GLOBALS['phpgw_info']['flags']['xslt_app'] = true; $this->config = CreateObject('phpgwapi.config', 'frontend'); $this->config->read(); $use_fellesdata = $this->config->config_data['use_fellesdata']; $logo_path = $this->config->config_data['logo_path']; // Get the mode: in frame or full screen $mode = phpgwapi_cache::session_get('frontend', 'noframework'); $noframework = isset($mode) ? $mode : true; /* Get the tabs and check to see whether the user has specified a tab or has a selected tab on session */ $tabs = $this->get_tabs(); $location_id = phpgw::get_var('location_id', 'int', 'REQUEST'); $tab = isset($location_id) ? $location_id : phpgwapi_cache::session_get('frontend', 'tab'); $selected = isset($tab) && $tab ? $tab : array_shift(array_keys($tabs)); $this->tabs = $GLOBALS['phpgw']->common->create_tabs($tabs, $selected); $this->menu = $this->create_menu($tabs, $selected); phpgwapi_cache::session_set('frontend', 'tab', $selected); // Get header state $this->header_state = phpgwapi_cache::session_get('frontend', 'header_state'); $this->header_state['use_fellesdata'] = $use_fellesdata; $this->header_state['logo_path'] = $logo_path; $this->header_state['form_action'] = $tabs[$selected]['link']; // Get navigation parameters $param_selected_location = phpgw::get_var('location'); // New location selected from locations list $param_selected_org_unit = phpgw::get_var('org_unit_id'); // New organisational unit selected from organisational units list $param_only_org_unit = phpgw::get_var('org_enhet_id'); // Frontend access from rental module regarding specific organisational unit //Refresh organisation list $refresh = phpgw::get_var('refresh', 'bool'); $property_locations_update = false; /* If the user has selected an organisational unit or all units */ if (isset($param_selected_org_unit) && $param_selected_org_unit && $param_selected_org_unit != 'none') { //Specify which unit(s) if ($param_selected_org_unit == 'all') { $org_unit_ids = $this->header_state['org_unit']; } else { if ($this->org_unit_in_selection($param_selected_org_unit, $this->header_state['org_unit'])) { //Creating a temporary array holding the single organisational unit in query $org_unit_ids = array(array("ORG_UNIT_ID" => $param_selected_org_unit)); } else { //If the organisational unit selected is not in list; do default 'all' $org_unit_ids = $this->header_state['org_unit']; $param_selected_org_unit = 'none'; } } $this->header_state['selected_org_unit'] = $param_selected_org_unit; //Update locations according to organisational unit specification $property_locations = frontend_borental::get_property_locations($org_unit_ids, $this->header_state['org_unit']); $property_locations_update = true; } else { if ($param_selected_org_unit == 'none') { $this->header_state['selected_org_unit'] = $param_selected_org_unit; $property_locations = array(); $this->header_state['locations'] = $property_locations; $this->header_state['number_of_locations'] = count($property_locations); } else { if (isset($param_only_org_unit) && $param_only_org_unit && $param_selected_org_unit != 'none') { //TODO: check permissions if ($use_fellesdata) { $name_and_result_number = frontend_bofellesdata::get_instance()->get_organisational_unit_info($param_only_org_unit); //Specify unit $org_unit_ids = array(array("ORG_UNIT_ID" => $param_only_org_unit, "ORG_NAME" => $name_and_result_number['UNIT_NAME'], "UNIT_ID" => $name_and_result_number['UNIT_NUMBER'])); //Update header state $this->header_state['org_unit'] = $org_unit_ids; $this->header_state['number_of_org_units'] = '1'; //$this->header_state['selected_org_unit'] = $name_and_result_number['UNIT_NUMBER']; $this->header_state['selected_org_unit'] = $param_only_org_unit; //Update locations $property_locations = frontend_borental::get_property_locations($org_unit_ids, $this->header_state['org_unit']); $property_locations_update = true; $noframework = false; // In regular frames phpgwapi_cache::session_set('frontend', 'noframework', $noframework); // Store mode on session $GLOBALS['phpgw_info']['flags']['menu_selection'] = "frontend::{$selected}"; $this->insert_links_on_header_state(); } } else { if (!isset($this->header_state) || isset($refresh) || !isset($this->header_state['locations'])) { if ($use_fellesdata) { //Specify organisational units $org_units = frontend_bofellesdata::get_instance()->get_result_units($GLOBALS['phpgw_info']['user']['account_lid']); //Merge with delegation units $delegation_org_ids = frontend_bofrontend::get_delegations($GLOBALS['phpgw_info']['user']['account_id']); if (count($delegation_org_ids) > 0) { $delegation_units = frontend_bofellesdata::get_instance()->populate_result_units($delegation_org_ids); $org_units = array_merge($org_units, $delegation_units); } //Update org units on header state $this->header_state['org_unit'] = $org_units; $this->header_state['number_of_org_units'] = count($org_units); $this->header_state['selected_org_unit'] = 'none'; //Update locations //FIXME Sigurd 15. okt 2013: deselect 'all' on initial view //$property_locations = frontend_borental::get_property_locations($org_units, $this->header_state['org_unit']); } else { if ($param_selected_org_unit != 'none') { //If no organisational database is in use: get rented properties based on username $usernames[] = $GLOBALS['phpgw_info']['user']['account_lid']; $property_locations = frontend_borental::get_property_locations($usernames, $this->header_state['org_unit']); } } $property_locations_update = true; $this->insert_links_on_header_state(); } } } } if ($property_locations_update) { if (count($property_locations) > 0) { $this->header_state['selected_location'] = $property_locations[0]['location_code']; $param_selected_location = $property_locations[0]['location_code']; } else { $this->header_state['selected_location'] = ''; $param_selected_location = ''; } $this->header_state['locations'] = $property_locations; $this->header_state['number_of_locations'] = count($property_locations); //FIXME $this->calculate_totals($property_locations); } /* If the user has selected a location or as a side-effect from selecting organisational unit */ if ($param_selected_location) { $locs = $this->header_state['locations']; $exist = false; foreach ($locs as $loc) { if ($loc['location_code'] == $param_selected_location) { $exist = true; } } if ($exist) { $this->header_state['selected_location'] = $param_selected_location; $parties = frontend_borental::get_all_parties(array(), $this->header_state['selected_org_unit']); $totals = frontend_borental::get_total_cost_and_area($parties, $param_selected_location); $this->header_state['selected_total_price'] = number_format($totals['sum_total_price'], 2, ",", " ") . " " . lang('currency'); $this->header_state['selected_total_area'] = number_format($totals['sum_total_area'], 2, ",", " ") . " " . lang('square_meters'); phpgwapi_cache::session_set('frontend', 'header_state', $this->header_state); } else { //Set totals to 0 $this->header_state['selected_location'] = $param_selected_location; $this->header_state['selected_total_price'] = lang('no_selection'); $this->header_state['selected_total_area'] = lang('no_selection'); phpgwapi_cache::session_set('frontend', 'header_state', $this->header_state); } phpgwapi_cache::session_clear('frontend', 'contract_state'); phpgwapi_cache::session_clear('frontend', 'contract_state_in'); phpgwapi_cache::session_clear('frontend', 'contract_state_ex'); } /* Store the header state on the session*/ $bomessenger = CreateObject('messenger.bomessenger'); $total_messages = $bomessenger->total_messages(" AND message_status = 'N'"); if ($total_messages > 0) { $this->header_state['new_messages'] = "({$total_messages})"; } else { $this->header_state['new_messages'] = lang('no_new_messages'); } phpgwapi_cache::session_set('frontend', 'header_state', $this->header_state); $GLOBALS['phpgw']->css->add_external_file('frontend/templates/base/base.css'); $GLOBALS['phpgw_info']['flags']['noframework'] = true; $GLOBALS['phpgw']->js->validate_file('jquery', 'menu', 'frontend'); }
/** * Remove a delegate * @param $account_id the delegate * @param $owner_id the person who has delegated * @param $org_unit_id the organisational unit in question */ public static function remove_delegate(int $account_id, int $owner_id, int $org_unit_id) { if (!isset($owner_id)) { $owner_id = $GLOBALS['phpgw_info']['user']['account_id']; } // The location $location_id = $GLOBALS['phpgw']->locations->get_id('frontend', '.'); // If a specific organisational unit if (isset($org_unit_id)) { $sql = "DELETE FROM phpgw_account_delegates WHERE account_id = {$account_id} AND data = '{$org_unit_id}' AND location_id = {$location_id}"; } else { // The owner id is the current user if not set $sql = "DELETE FROM phpgw_account_delegates WHERE account_id = {$account_id} AND owner_id = {$owner_id} AND location_id = {$location_id}"; } $db = clone $GLOBALS['phpgw']->db; $db->Halt_On_Error = 'no'; $result = $db->query($sql, __LINE__, __FILE__); if ($result && $db->affected_rows() > 0) { $user_account = $GLOBALS['phpgw']->accounts->get($account_id); $owner_account = $GLOBALS['phpgw']->accounts->get($owner_id); $user_name = $user_account->__get('lid'); $owner_name = $owner_account->__get('lid'); if (isset($user_name) && $user_name != '' && $owner_name && $owner_name != '') { $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($user_name); $fellesdata_owner = frontend_bofellesdata::get_instance()->get_user($owner_name); if ($fellesdata_user && $fellesdata_owner) { $email = $fellesdata_user['email']; if (isset($email) && $email != '') { $title = lang('email_remove_delegate_title'); $message = lang('email_remove_delegate_message', $fellesdata_user['firstname'], $fellesdata_user['lastname'], $fellesdata_owner['firstname'], $fellesdata_owner['lastname']); frontend_bofrontend::send_system_message($email, $title, $message); } } } return true; } return false; }
/** * Show single contract details */ public function index() { $contractdata = array(); // This is the main container for all contract data sent to XSLT template stuff $msglog = array(); // Array of errors and other notifications displayed to us $filter = phpgw::get_var('contract_filter'); // The user wants to change the contract status filter if (isset($filter)) { $this->contract_filter = $filter; phpgwapi_cache::session_set('frontend', 'contract_filter', $filter); // ... if the user changes filter that may cause the if ($filter == 'active' || $filter == 'not_active') { $change_contract = true; } } else { $filter = phpgwapi_cache::session_get('frontend', 'contract_filter'); $this->contract_filter = isset($filter) && $filter ? $filter : 'active'; } if (isset($_POST['send'])) { $contract_id = phpgw::get_var('contract_id'); $contract_message = phpgw::get_var('contract_message'); $config = CreateObject('phpgwapi.config', 'rental'); $config->read(); $use_fellesdata = $config->config_data['use_fellesdata']; if ($use_fellesdata) { $user_data = frontend_bofellesdata::get_instance()->get_user($GLOBALS['phpgw_info']['user']['account_lid']); if ($user_data['email']) { if (isset($contract_message) && $contract_message != '') { $from_address = $user_data['email']; $result = frontend_borental::send_contract_message($contract_id, $contract_message, $from_address); if ($result) { $msglog['message'] = lang('message_sent'); } else { $msglog['error'] = lang('message_not_sent'); } } else { $msglog['error'] = lang('message_empty'); } } else { $msglog['error'] = lang('user_not_in_fellesdata'); } } else { $msglog['error'] = lang('fellesdata_not_in_use'); } } // If the user wants to view another contract connected to this location // Request parameter: the user wants to view details about anther contract // The current state of the contract view of this user's session $this->contract_state = phpgwapi_cache::session_get('frontend', $this->contract_state_identifier); $new_contract = phpgw::get_var('contract_id'); $contracts_per_location = $this->get_contracts_per_location(); $contracts_for_selection = array(); $number_of_valid_contracts = 0; foreach ($contracts_per_location[$this->header_state['selected_location']] as $contract) { if ($this->contract_filter == 'active' && $contract->is_active() || $this->contract_filter == 'not_active' && !$contract->is_active() || $this->contract_filter == 'all') { $number_of_valid_contracts += 1; //Only select necessary fields $contracts_for_selection[] = array('id' => $contract->get_id(), 'old_contract_id' => $contract->get_old_contract_id(), 'contract_status' => $contract->get_contract_status()); if ($change_contract || $new_contract == $contract->get_id() || !isset($this->contract_state['contract'])) { $this->contract_state['selected'] = $contract->get_id(); $this->contract_state['contract'] = $contract; //$this->contract = rental_socontract::get_instance()->get_single($new_contract); phpgwapi_cache::session_set('frontend', $this->contract_state_identifier, $this->contract_state); $change_contract = false; //Get more details on contract parties $parties = rental_soparty::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $this->contract_state['contract']->get_id())); $party_array = array(); foreach ($parties as $party) { $party_array[] = $party->serialize(); } $composites = rental_socomposite::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $this->contract_state['contract']->get_id())); $composite_array = array(); foreach ($composites as $composite) { $composite_array[] = $composite->serialize(); } $this->contract_state['contract']->set_total_price(number_format($this->contract_state['contract']->get_total_price(), 2, ",", " ") . " " . lang('currency')); $this->contract_state['contract']->set_rented_area(number_format($this->contract_state['contract']->get_rented_area(), 2, ",", " ") . " " . lang('square_meters')); } } } if (!isset($party_array) && isset($this->contract_state['contract'])) { $parties = rental_soparty::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $this->contract_state['contract']->get_id())); $party_array = array(); foreach ($parties as $party) { $party_array[] = $party->serialize(); } } if (!isset($composite_array) && isset($this->contract_state['contract'])) { $composites = rental_socomposite::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $this->contract_state['contract']->get_id())); $composite_array = array(); foreach ($composites as $composite) { $composite_array[] = $composite->serialize(); } } if ($number_of_valid_contracts == 0) { $this->contract_state['selected'] = ''; $this->contract_state['contract'] = null; } $data = array('msgbox_data' => $GLOBALS['phpgw']->common->msgbox($GLOBALS['phpgw']->common->msgbox_data($msglog)), 'header' => $this->header_state, 'tabs' => $this->tabs, 'contract_data' => array('select' => $contracts_for_selection, 'selected_contract' => $this->contract_state['selected'], 'contract' => isset($this->contract_state['contract']) ? $this->contract_state['contract']->serialize() : array(), 'party' => $party_array, 'composite' => $composite_array, 'contract_filter' => $this->contract_filter, 'form_url' => $this->form_url)); $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('app_data' => $data)); $GLOBALS['phpgw']->xslttpl->add_file(array('frontend', 'contract')); }