/**
  * 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('rental.bofellesdata');
     }
     return self::$bo;
 }
Пример #2
0
 /**
  * Synchronization job to update company name on contract parties which are connected to Fellesdata.
  *
  * Uses property org_enhet_id on party to link party with unit from Fellesdata.
  * To be run as a scheduled job
  */
 function syncronize_party_name()
 {
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     $use_fellesdata = $config->config_data['use_fellesdata'];
     if (!$use_fellesdata) {
         return;
     }
     $bofelles = rental_bofellesdata::get_instance();
     $parties = rental_soparty::get_instance()->get();
     $result_count = rental_soparty::get_instance()->get_count();
     $updated_parties;
     $updated_parties[] = "Total number of parties: {$result_count}";
     if ($this->isExecutiveOfficer() || $this->isAdministrator()) {
         $count = 0;
         $count_result_unit_number = 0;
         $count_identifier = 0;
         $count_responsibility = 0;
         foreach ($parties as $party) {
             $unit_found = false;
             $fellesdata = NULL;
             if (isset($party)) {
                 $sync_data = $party->get_sync_data();
                 $fellesdata = $bofelles->result_unit_exist($sync_data['result_unit_number'], 4);
                 if ($fellesdata) {
                     $updated_parties[] = "Unit id found {$fellesdata['UNIT_ID']} by result unit number check. The unit name is {$fellesdata['UNIT_NAME']}<br />";
                     $count_result_unit_number++;
                 }
                 if ($fellesdata && isset($fellesdata['UNIT_ID']) && is_numeric($fellesdata['UNIT_ID'])) {
                     // We found a match, so store the new connection
                     $party->set_org_enhet_id($fellesdata['UNIT_ID']);
                     $old_party_name = $party->get_company_name();
                     $party->set_company_name($fellesdata['UNIT_NAME']);
                     $updated_parties[] = "Updated company name on party {$party->get_id()} with unit ID {$party->get_org_enhet_id} from {$old_party_name} to {$party->get_company_name()}";
                     $count++;
                 } else {
                     // No match was found. Do nothing
                     //$party->set_org_enhet_id(NULL);
                 }
                 rental_soparty::get_instance()->store($party);
             }
         }
         $updated_parties[] = "Number of parties found through result unit number {$count_result_unit_number}";
         $updated_parties[] = "Number of parties that have been updated {$count}";
         $this->log_sync_messages($updated_parties);
     }
 }
Пример #3
0
if ($editable) {
    ?>
			<select name="org_enhet_id" id="org_enhet_id">
				<option value=""><?php 
    echo lang('no_party_location');
    ?>
</option>
		<?php 
    $result_units = rental_bofellesdata::get_instance()->get_result_units();
    $party_org_enhet_id = $party->get_org_enhet_id();
    foreach ($result_units as $result_unit) {
        if ($result_unit['ORG_UNIT_ID'] == $party_org_enhet_id) {
            echo "<option value='{$result_unit['ORG_UNIT_ID']}' selected=selected >{$result_unit['UNIT_ID']} - {$result_unit['ORG_UNIT_NAME']}</option>";
        } else {
            echo "<option value='{$result_unit['ORG_UNIT_ID']}'>{$result_unit['UNIT_ID']} - {$result_unit['ORG_UNIT_NAME']}</option>";
        }
    }
    ?>
		</select>
	<?php 
} else {
    $party_org_enhet_id = $party->get_org_enhet_id();
    if (isset($party_org_enhet_id) && is_numeric($party_org_enhet_id)) {
        $result_unit = rental_bofellesdata::get_instance()->get_result_unit($party_org_enhet_id);
        echo $result_unit['ORG_NAME'];
    } else {
        echo lang('no_party_location');
    }
}
?>
</dd>
 public function edit()
 {
     $GLOBALS['phpgw_info']['flags']['app_header'] .= '::' . lang('edit');
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     $use_fellesdata = $config->config_data['use_fellesdata'];
     $unit_id = (int) phpgw::get_var('id');
     $unit_level = (int) phpgw::get_var('level');
     if (isset($unit_id) && $unit_id > 0 && $use_fellesdata) {
         $msglog['error']['msg'] = phpgw::get_var('error');
         $msglog['message']['msg'] = phpgw::get_var('message');
         if (isset($_POST['search'])) {
             $username = phpgw::get_var('username');
             if (!isset($username)) {
                 $msglog['error']['msg'] = lang('lacking_username');
             } else {
                 $account_id = frontend_bofrontend::delegate_exist($username);
                 if ($account_id) {
                     $search_result = frontend_bofrontend::get_account_info($account_id);
                     $msglog['message']['msg'] = lang('user_found_in_PE');
                 } else {
                     $fellesdata_user = frontend_bofellesdata::get_instance()->get_user($username);
                     if ($fellesdata_user) {
                         $search_result = $fellesdata_user;
                         $msglog['message']['msg'] = lang('user_found_in_Fellesdata');
                     } else {
                         $msglog['error']['msg'] = lang('no_hits');
                     }
                 }
             }
         } else {
             if (isset($_POST['add'])) {
                 $account_id = phpgw::get_var('account_id');
                 //var_dump($account_id);
                 $bofelles = rental_bofellesdata::get_instance();
                 $unit = $bofelles->get_result_unit($unit_id, $unit_level);
                 //var_dump($unit);
                 if ($account_id) {
                     $res = $this->add_delegate($account_id, $unit['ORG_UNIT_ID'], $unit['ORG_NAME']);
                     //var_dump($res);
                     if (!$res) {
                         $msglog['error']['msg'] = lang('delegation_error');
                     } else {
                         $msglog['message']['msg'] = lang('delegation_successful');
                     }
                 } else {
                     $msglog['error']['msg'] = lang('unknown_user');
                 }
             }
         }
         $bofelles = rental_bofellesdata::get_instance();
         $unit = $bofelles->get_result_unit_with_leader($unit_id, $unit_level);
         $delegates_per_org_unit = frontend_bofrontend::get_delegates($unit_id);
         $unit['UNIT_NO_OF_DELEGATES'] = count($delegates_per_org_unit);
         $form_action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'rental.uiresultunit.edit', 'id' => $unit_id, 'level' => $unit_level));
         $this->render('resultunit.php', array('unit' => $unit, 'form_action' => $form_action, 'search_result' => isset($search_result) ? $search_result : array(), 'msglog' => $msglog, 'cancel_link' => self::link(array('menuaction' => 'rental.uiresultunit.index', 'populate_form' => 'yes'))));
     }
 }
Пример #5
0
 /**
  * Public method. Called when a user wants to sync data with Fellesdata. 
  * Returns a json string with the following fields: email, org_name, unit_leader_fullname and department
  */
 public function get_synchronize_party_info()
 {
     if ($this->isExecutiveOfficer() || $this->isAdministrator()) {
         $org_unit_id = phpgw::get_var("org_enhet_id");
         if (isset($org_unit_id) && $org_unit_id > 0) {
             $config = CreateObject('phpgwapi.config', 'rental');
             $config->read();
             $use_fellesdata = $config->config_data['use_fellesdata'];
             if (!$use_fellesdata) {
                 return;
             }
             $bofelles = rental_bofellesdata::get_instance();
             $org_unit_with_leader = $bofelles->get_result_unit_with_leader($org_unit_id);
             $org_department = $bofelles->get_department_for_org_unit($org_unit_id);
             $org_name = $org_unit_with_leader['ORG_UNIT_NAME'];
             $org_email = $org_unit_with_leader['ORG_EMAIL'];
             $unit_leader_fullname = $org_unit_with_leader['LEADER_FULLNAME'];
             $dep_org_name = $org_department['DEP_ORG_NAME'];
             $jsonArr = array("email" => trim($org_email), "org_name" => trim($org_name), "unit_leader_fullname" => trim($unit_leader_fullname), "department" => trim($dep_org_name));
             return json_decode(json_encode($jsonArr));
         }
     }
 }