/**
  * Set a message on bottom of home-screen
  *
  * @return void
  */
 function home_screen_message()
 {
     if (!$GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin')) {
         $GLOBALS['phpgw']->redirect_link('/admin/index.php');
     }
     if (phpgw::get_var('msg_title', 'string')) {
         $msg_title = phpgw::get_var('msg_title', 'string');
     } else {
         $msg_title = lang("important message");
     }
     if (phpgw::get_var('message', 'string')) {
         phpgwapi_cache::system_set('phpgwapi', 'phpgw_home_screen_message_title', $msg_title);
         phpgwapi_cache::system_set('phpgwapi', 'phpgw_home_screen_message', phpgw::get_var('message', 'html'));
     }
     if (phpgw::get_var('delete_message', 'bool')) {
         phpgwapi_cache::system_clear('phpgwapi', 'phpgw_home_screen_message_title');
         phpgwapi_cache::system_clear('phpgwapi', 'phpgw_home_screen_message');
     }
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('administration');
     $data = array('value_title' => phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message_title'), 'value_message' => phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message'), 'form_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uiaccounts.home_screen_message')), 'lang_cancel' => lang('cancel'), 'lang_submit' => lang('submit'));
     $GLOBALS['phpgw']->xslttpl->add_file('home_screen_message');
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('home_screen_message' => $data));
 }
 function get_column_list()
 {
     $columns = array();
     // defined i property_bocommon::generate_sql()
     $location_relation_data = phpgwapi_cache::system_get('property', 'location_relation_data');
     $this->location_relation_data = $location_relation_data && is_array($location_relation_data) ? $location_relation_data : array();
     if ($this->location_relation_data && is_array($this->location_relation_data)) {
         foreach ($this->location_relation_data as $entry) {
             $columns[$entry['name']] = array('id' => $entry['name'], 'input_type' => 'text', 'name' => $entry['name'], 'descr' => $entry['descr'], 'statustext' => $entry['descr'], 'align' => '', 'datatype' => $entry['datatype'], 'sortable' => false, 'exchange' => false, 'formatter' => '', 'classname' => '');
         }
     }
     /*
     			$columns['user_id'] = array
     			(
     				'id'			=> 'user_id',
     				'input_type'	=> 'text',
     				'name'			=> 'user_id',
     				'descr'			=> lang('User'),
     				'statustext'	=> lang('User'),
     				'align' 		=> '',
     				'datatype'		=> 'user',
     				'sortable'		=> false,
     				'exchange'		=> false,
     				'formatter'		=> '',
     				'classname'		=> ''
     			);
     */
     return $columns;
 }
 /**
  * Fetch an account
  *
  * @param integer $id        the account id to fetch
  * @param boolean $use_cache read the record from the cache, should (just about) always be true
  *
  * @return object the account as a phpgw_account derived object
  */
 public function get($id, $use_cache = true)
 {
     $id = (int) $id;
     $account = null;
     static $cache = array();
     if (isset($cache[$id])) {
         return $cache[$id];
     }
     if ($use_cache) {
         $account = phpgwapi_cache::system_get('phpgwapi', "account_{$id}");
         if (is_object($account)) {
             return $account;
         }
     }
     $this->db->query("SELECT * FROM phpgw_accounts WHERE account_id = {$id}", __LINE__, __FILE__);
     if ($this->db->next_record()) {
         $record = array('id' => $this->db->f('account_id'), 'lid' => $this->db->f('account_lid'), 'passwd_hash' => $this->db->f('account_pwd', true), 'firstname' => $this->db->f('account_firstname', true), 'lastname' => $this->db->f('account_lastname', true), 'last_login' => $this->db->f('account_lastlogin'), 'last_login_from' => $this->db->f('account_lastloginfrom'), 'last_passwd_change' => $this->db->f('account_lastpwd_change'), 'enabled' => $this->db->f('account_status') == 'A', 'expires' => $this->db->f('account_expires'), 'person_id' => $this->db->f('person_id'), 'quota' => $this->db->f('account_quota'), 'type' => $this->db->f('account_type'));
         if ($this->db->f('account_type') == 'g') {
             $account = new phpgwapi_group();
         } else {
             $account = new phpgwapi_user();
         }
         $account->init($record);
         phpgwapi_cache::system_set('phpgwapi', "account_{$id}", $account);
     }
     $cache[$id] = $account;
     return $account;
 }
 /**
  * Import deviations found in the survey to the database from a spreadsheet
  *
  * @param int  $id  entity id
  *
  * @return void
  */
 private function _handle_import($id)
 {
     $id = (int) $id;
     if (!$id) {
         throw new Exception('uicondition_survey::_handle_import() - missing id');
     }
     $step = phpgw::get_var('step', 'int', 'REQUEST');
     $sheet_id = phpgw::get_var('sheet_id', 'int', 'REQUEST');
     $sheet_id = $sheet_id ? $sheet_id : phpgw::get_var('selected_sheet_id', 'int', 'REQUEST');
     if (!$step) {
         if ($cached_file = phpgwapi_cache::session_get('property', 'condition_survey_import_file')) {
             phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
             unlink($cached_file);
             unset($cached_file);
         }
     }
     if ($start_line = phpgw::get_var('start_line', 'int', 'REQUEST')) {
         phpgwapi_cache::system_set('property', 'import_sheet_start_line', $start_line);
     } else {
         $start_line = phpgwapi_cache::system_get('property', 'import_sheet_start_line');
         $start_line = $start_line ? $start_line : 1;
     }
     if ($columns = phpgw::get_var('columns')) {
         phpgwapi_cache::system_set('property', 'import_sheet_columns', $columns);
     } else {
         $columns = phpgwapi_cache::system_get('property', 'import_sheet_columns');
         $columns = $columns && is_array($columns) ? $columns : array();
     }
     if ($step > 1) {
         $cached_file = phpgwapi_cache::session_get('property', 'condition_survey_import_file');
     }
     if ($step == 1 || isset($_FILES['import_file']['tmp_name'])) {
         $file = $_FILES['import_file']['tmp_name'];
         $cached_file = "{$file}_temporary_import_file";
         // save a copy to survive multiple steps
         file_put_contents($cached_file, file_get_contents($file));
         phpgwapi_cache::session_set('property', 'condition_survey_import_file', $cached_file);
         $step = 1;
         // Add the file to documents
         $bofiles = CreateObject('property.bofiles');
         $to_file = "{$bofiles->fakebase}/condition_survey/{$id}/" . str_replace(' ', '_', $_FILES['import_file']['name']);
         $bofiles->vfs->rm(array('string' => $to_file, 'relatives' => array(RELATIVE_NONE)));
         $bofiles->create_document_dir("condition_survey/{$id}");
         $bofiles->vfs->override_acl = 1;
         $bofiles->vfs->cp(array('from' => $_FILES['import_file']['tmp_name'], 'to' => $to_file, 'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL)));
         $bofiles->vfs->override_acl = 0;
         unset($bofiles);
     }
     $tabs = array();
     switch ($step) {
         case 0:
             $active_tab = 'step_1';
             $lang_submit = lang('continue');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => '#step_1');
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => null);
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => null);
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => null);
             break;
         case 1:
             $active_tab = 'step_2';
             $lang_submit = lang('continue');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 0, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => '#step_2');
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => null);
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => null);
             break;
         case 2:
             $active_tab = 'step_3';
             $lang_submit = lang('continue');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 0, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 1, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => '#step_3');
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => null);
             break;
         case 3:
             $active_tab = 'step_4';
             $lang_submit = lang('import');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 0, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 1, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 2, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => '#step_4');
             break;
             /*
             				case 4://temporary
             					phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
             					unlink($cached_file);
             					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction' => 'property.uicondition_survey.import', 'id' =>$id, 'step' => 0));
             					break;
             */
     }
     //-----------
     if (!$step) {
         phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
         unlink($cached_file);
     } else {
         if ($cached_file) {
             phpgw::import_class('phpgwapi.phpexcel');
             try {
                 $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
                 $AllSheets = $objPHPExcel->getSheetNames();
                 $sheets = array();
                 if ($AllSheets) {
                     foreach ($AllSheets as $key => $sheet) {
                         $sheets[] = array('id' => $key, 'name' => $sheet, 'selected' => $sheet_id == $key);
                     }
                 }
                 $objPHPExcel->setActiveSheetIndex((int) $sheet_id);
             } catch (Exception $e) {
                 if ($e) {
                     phpgwapi_cache::message_set($e->getMessage(), 'error');
                     phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
                     unlink($cached_file);
                 }
             }
         }
     }
     $survey = $this->bo->read_single(array('id' => $id, 'view' => $mode == 'view'));
     $rows = $objPHPExcel->getActiveSheet()->getHighestDataRow();
     $highestColumm = $objPHPExcel->getActiveSheet()->getHighestDataColumn();
     $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumm);
     $i = 0;
     $html_table = '<table border="1">';
     if ($rows > 1 && $step == 2) {
         $cols = array();
         for ($j = 0; $j < $highestColumnIndex; $j++) {
             $cols[] = $this->getexcelcolumnname($j);
         }
         $html_table .= "<tr><th align = 'center'>" . lang('start') . "</th><th align='center'>" . implode("</th><th align='center'>", $cols) . '</th></tr>';
         foreach ($objPHPExcel->getActiveSheet()->getRowIterator() as $row) {
             if ($i > 20) {
                 break;
             }
             $i++;
             $row_key = $i;
             $_checked = '';
             if ($start_line == $row_key) {
                 $_checked = 'checked="checked"';
             }
             $_radio = "[{$row_key}]<input id=\"start_line\" type =\"radio\" {$_checked} name=\"start_line\" value=\"{$row_key}\">";
             $cellIterator = $row->getCellIterator();
             $cellIterator->setIterateOnlyExistingCells(false);
             $row_values = array();
             foreach ($cellIterator as $cell) {
                 if (!is_null($cell)) {
                     $row_values[] = $cell->getCalculatedValue();
                 }
             }
             $html_table .= "<tr><td><pre>{$_radio}</pre></td><td>" . implode('</td><td>', $row_values) . '</td></tr>';
         }
         echo '</table>';
     } else {
         if ($rows > 1 && $step == 3) {
             $_options = array('_skip_import_' => 'Utelates fra import/implisitt', 'import_type' => 'import type', 'building_part' => 'bygningsdels kode', 'descr' => 'Tilstandbeskrivelse', 'title' => 'Tiltak/overskrift', 'condition_degree' => 'Tilstandsgrad', 'condition_type' => 'Konsekvenstype', 'consequence' => 'Konsekvensgrad', 'probability' => 'Sannsynlighet', 'due_year' => 'År (innen)', 'amount_investment' => 'Beløp investering', 'amount_operation' => 'Beløp drift', 'amount_potential_grants' => 'Potensial for offentlig støtte');
             $custom = createObject('phpgwapi.custom_fields');
             $attributes = $custom->find('property', '.project.request', 0, '', '', '', true, true);
             foreach ($attributes as $attribute) {
                 $_options["custom_attribute_{$attribute['id']}"] = $attribute['input_text'];
             }
             phpgw::import_class('phpgwapi.sbox');
             for ($j = 0; $j < $highestColumnIndex; $j++) {
                 $_column = $this->getexcelcolumnname($j);
                 $_value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, $start_line)->getCalculatedValue();
                 $selected = isset($columns[$_column]) && $columns[$_column] ? $columns[$_column] : '';
                 $_listbox = phpgwapi_sbox::getArrayItem("columns[{$_column}]", $selected, $_options, true);
                 $html_table .= "<tr><td>[{$_column}] {$_value}</td><td>{$_listbox}</td><tr>";
             }
         } else {
             if ($rows > 1 && $step == 4) {
                 $rows = $objPHPExcel->getActiveSheet()->getHighestDataRow();
                 $rows = $rows ? $rows + 1 : 0;
                 $import_data = array();
                 for ($i = $start_line; $i < $rows; $i++) {
                     $_result = array();
                     foreach ($columns as $_row_key => $_value_key) {
                         if ($_value_key != '_skip_import_') {
                             $_result[$_value_key] = $objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue();
                         }
                     }
                     $import_data[] = $_result;
                 }
                 if ($import_data) {
                     try {
                         $this->bo->import($survey, $import_data);
                     } catch (Exception $e) {
                         if ($e) {
                             phpgwapi_cache::message_set($e->getMessage(), 'error');
                         }
                     }
                 }
                 //				$msg = "'{$cached_file}' contained " . count($import_data) . " lines";
                 //				phpgwapi_cache::message_set($msg, 'message');
             }
         }
     }
     $html_table .= '</table>';
     if (isset($survey['location_code']) && $survey['location_code']) {
         $survey['location_data'] = execMethod('property.solocation.read_single', $survey['location_code']);
     }
     $bolocation = CreateObject('property.bolocation');
     $location_data = $bolocation->initiate_ui_location(array('values' => $survey['location_data'], 'type_id' => 2, 'lookup_type' => 'view2', 'tenant' => false, 'lookup_entity' => array(), 'entity_data' => isset($survey['p']) ? $survey['p'] : ''));
     $data = array('lang_submit' => $lang_submit, 'survey' => $survey, 'location_data2' => $location_data, 'step' => $step + 1, 'sheet_id' => $sheet_id, 'start_line' => $start_line, 'html_table' => $html_table, 'sheets' => array('options' => $sheets), 'tabs' => $GLOBALS['phpgw']->common->create_tabs($tabs, $active_tab));
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . '::' . lang('condition survey import');
     self::render_template_xsl(array('condition_survey_import'), $data);
 }
Esempio n. 5
0
    }
    $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->save_repository();
}
if (isset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']) && is_array($GLOBALS['phpgw_info']['user']['preferences']['portal_order'])) {
    $app_check = array();
    ksort($GLOBALS['phpgw_info']['user']['preferences']['portal_order']);
    foreach ($GLOBALS['phpgw_info']['user']['preferences']['portal_order'] as $app) {
        if (!isset($app_check[$app]) || !$app_check[$app]) {
            $app_check[$app] = true;
            $sorted_apps[] = $GLOBALS['phpgw']->applications->id2name($app);
        }
    }
} else {
    $sorted_apps = array('email', 'calendar', 'news_admin', 'addressbook');
}
$GLOBALS['phpgw']->hooks->process('home', $sorted_apps);
if (isset($GLOBALS['portal_order']) && is_array($GLOBALS['portal_order'])) {
    $GLOBALS['phpgw']->preferences->delete('portal_order');
    foreach ($GLOBALS['portal_order'] as $app_order => $app_id) {
        $GLOBALS['phpgw']->preferences->add('portal_order', $app_order, $app_id);
    }
    $GLOBALS['phpgw']->preferences->save_repository();
}
if (phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message')) {
    echo "<div class='msg_important'><h2>";
    echo nl2br(phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message_title'));
    echo "</h2>";
    echo nl2br(phpgwapi_cache::system_get('phpgwapi', 'phpgw_home_screen_message'));
    echo '</div>';
}
$GLOBALS['phpgw']->common->phpgw_footer();
Esempio n. 6
0
function parse_navbar($force = False)
{
    $navbar = array();
    $navbar = execMethod('phpgwapi.menu.get', 'navbar');
    $user = $GLOBALS['phpgw']->accounts->get($GLOBALS['phpgw_info']['user']['id']);
    $var = array('print_url' => strpos($_SERVER['REQUEST_URI'], '?') ? "{$_SERVER['REQUEST_URI']}&phpgw_return_as=noframes" : "{$_SERVER['REQUEST_URI']}?phpgw_return_as=noframes", 'print_text' => lang('print'), 'home_url' => $GLOBALS['phpgw']->link('/home.php'), 'home_text' => lang('home'), 'home_icon' => 'icon icon-home', 'about_url' => $GLOBALS['phpgw']->link('/about.php', array('app' => $GLOBALS['phpgw_info']['flags']['currentapp'])), 'about_text' => lang('about'), 'logout_url' => $GLOBALS['phpgw']->link('/logout.php'), 'logout_text' => lang('logout'), 'user_fullname' => $user->__toString());
    if ($GLOBALS['phpgw']->acl->check('run', PHPGW_ACL_READ, 'preferences')) {
        $var['preferences_url'] = $GLOBALS['phpgw']->link('/preferences/index.php');
        $var['preferences_text'] = lang('preferences');
    }
    if (isset($GLOBALS['phpgw_info']['user']['apps']['manual'])) {
        $var['help_url'] = "javascript:openwindow('" . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'manual.uimanual.help', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'], 'section' => isset($GLOBALS['phpgw_info']['apps']['manual']['section']) ? $GLOBALS['phpgw_info']['apps']['manual']['section'] : '', 'referer' => phpgw::get_var('menuaction'))) . "','700','600')";
        $var['help_text'] = lang('help');
        $var['help_icon'] = 'icon icon-help';
    }
    if (isset($GLOBALS['phpgw_info']['server']['support_address']) && $GLOBALS['phpgw_info']['server']['support_address']) {
        $var['support_url'] = "javascript:openwindow('" . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'manual.uisupport.send', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'])) . "','700','600')";
        $var['support_text'] = lang('support');
        $var['support_icon'] = 'icon icon-help';
    }
    if (isset($GLOBALS['phpgw_info']['user']['apps']['admin'])) {
        $var['debug_url'] = "javascript:openwindow('" . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uidebug_json.index', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'])) . "','','')";
        $var['debug_text'] = lang('debug');
        $var['debug_icon'] = 'icon icon-debug';
    }
    $GLOBALS['phpgw']->template->set_root(PHPGW_TEMPLATE_DIR);
    $GLOBALS['phpgw']->template->set_file('navbar', 'navbar.tpl');
    $flags =& $GLOBALS['phpgw_info']['flags'];
    $var['current_app_title'] = isset($flags['app_header']) ? $flags['app_header'] : lang($GLOBALS['phpgw_info']['flags']['currentapp']);
    $flags['menu_selection'] = isset($flags['menu_selection']) ? $flags['menu_selection'] : '';
    // breadcrumbs
    $current_url = array('id' => $flags['menu_selection'], 'url' => phpgw::get_var('REQUEST_URI', 'string', 'SERVER'), 'name' => $var['current_app_title']);
    $breadcrumbs = phpgwapi_cache::session_get('phpgwapi', 'breadcrumbs');
    $breadcrumbs = $breadcrumbs ? $breadcrumbs : array();
    // first one
    if ($breadcrumbs[0]['id'] != $flags['menu_selection']) {
        array_unshift($breadcrumbs, $current_url);
    }
    if (count($breadcrumbs) >= 5) {
        array_pop($breadcrumbs);
    }
    phpgwapi_cache::session_set('phpgwapi', 'breadcrumbs', $breadcrumbs);
    $breadcrumbs = array_reverse($breadcrumbs);
    $navigation = array();
    if (!isset($GLOBALS['phpgw_info']['user']['preferences']['property']['nonavbar']) || $GLOBALS['phpgw_info']['user']['preferences']['property']['nonavbar'] != 'yes') {
        prepare_navbar($navbar);
    } else {
        foreach ($navbar as &$app_tmp) {
            $app_tmp['text'] = ' ...';
        }
    }
    if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent'] == 'ajax_menu') {
        $exclude = array('logout', 'about', 'preferences');
        $i = 1;
        foreach ($navbar as $app => $app_data) {
            if (in_array($app, $exclude)) {
                continue;
            }
            $applications[] = array('value' => array('id' => $i, 'app' => $app, 'label' => $app_data['text'], 'href' => str_replace('&amp;', '&', $app_data['url'])), 'children' => array());
            $mapping[$i] = array('id' => $i, 'name' => $app, 'expanded' => false, 'highlight' => $app == $currentapp ? true : false, 'is_leaf' => false);
            $i++;
        }
        $applications = json_encode($applications);
        $mapping = json_encode($mapping);
        $_menu_selection = str_replace('::', '|', $GLOBALS['phpgw_info']['flags']['menu_selection']);
        $var['treemenu'] = <<<HTML
\t\t\t\t<div id="MenutreeDiv1"></div>
\t\t\t\t<script type="text/javascript">
\t\t \t\t\tvar apps = {$applications};
\t\t\t\t\tvar mapping = {$mapping};
\t\t\t\t\tvar proxy_data = ['first_element_is_dummy'];
\t\t\t\t\tvar menu_selection = '{$_menu_selection}';
\t\t\t\t</script>
HTML;
    } else {
        //			prepare_navbar($navbar);
        $navigation = execMethod('phpgwapi.menu.get', 'navigation');
        $treemenu = '';
        foreach ($navbar as $app => $app_data) {
            if (!in_array($app, array('logout', 'about', 'preferences'))) {
                $submenu = isset($navigation[$app]) ? render_submenu($app, $navigation[$app]) : '';
                $treemenu .= render_item($app_data, "navbar::{$app}", $submenu);
            }
        }
        $var['treemenu'] = <<<HTML
\t\t\t<ul id="navbar">
{$treemenu}
\t\t\t</ul>

HTML;
    }
    if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent'] == 'jsmenu') {
        $var['treemenu'] .= <<<JS
\t\t\t\t<script type="text/javascript">
\t\t\t\t\$(function() {
\t\t\t\t\$("#navbar").menu();
\t\t\t});
\t\t\t</script>
JS;
    }
    $GLOBALS['phpgw']->template->set_var($var);
    $GLOBALS['phpgw']->template->pfp('out', 'navbar');
    if (phpgw::get_var('phpgw_return_as') != 'json' && ($global_message = phpgwapi_cache::system_get('phpgwapi', 'phpgw_global_message'))) {
        echo "<div class='msg_good'>";
        echo nl2br($global_message);
        echo '</div>';
    }
    if (phpgw::get_var('phpgw_return_as') != 'json' && $breadcrumbs && isset($GLOBALS['phpgw_info']['user']['preferences']['common']['show_breadcrumbs']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['show_breadcrumbs']) {
        $history_url = array();
        foreach ($breadcrumbs as $breadcrumb) {
            $history_url[] = "<a href='{$breadcrumb['url']}'>{$breadcrumb['name']}</a>";
        }
        $breadcrumbs = '<div class="breadcrumbs"><h4>' . implode(' >> ', $history_url) . '</h4></div>';
        echo $breadcrumbs;
    }
    if (phpgw::get_var('phpgw_return_as') != 'json' && ($receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))) {
        phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
        $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($receipt);
        $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
        foreach ($msgbox_data as &$message) {
            echo "<div class='{$message['msgbox_class']}'>";
            echo $message['msgbox_text'];
            echo '</div>';
        }
    }
    $GLOBALS['phpgw']->hooks->process('after_navbar');
    register_shutdown_function('parse_footer_end');
}
 /**
  * Get periodized budget for an order
  * @param integer $order_id
  * @param bool $calculate_fictive_periods
  * @return array Array with budget information.
  */
 function get_budget($order_id, $calculate_fictive_periods = true)
 {
     // Som før: Periodisering der det er definert
     // Som før: Enkelt posteringer for gjeldende periode der periodisering ikke er definert
     // Ny: Fiktiv periodisering over 12 mnd med startperiode for inneværende mnd for løpende som ikke er periodisert
     if (!$order_id) {
         return array();
     }
     $continuous = false;
     $cached_info = phpgwapi_cache::system_get('property', "budget_order_{$order_id}");
     if ($cached_info) {
         return $cached_info;
     }
     $closed_period = array();
     $active_period = array();
     $sum_year_budget = array();
     $sum_year_combined_cost = array();
     $sql = "SELECT continuous, fm_workorder.start_date , fm_workorder_budget.budget, fm_workorder_budget.combined_cost," . " project_type_id, year, month, active, closed, fictive_periodization" . " FROM fm_workorder" . " {$this->join} fm_project ON fm_workorder.project_id = fm_project.id" . " {$this->join} fm_workorder_status ON fm_workorder.status = fm_workorder_status.id" . " {$this->join} fm_workorder_budget ON fm_workorder.id = fm_workorder_budget.order_id" . " WHERE order_id = '{$order_id}'" . " ORDER BY year, month";
     $this->db->query($sql, __LINE__, __FILE__);
     $_check_periodization = array();
     $_order_budget = array();
     while ($this->db->next_record()) {
         $fictive_periodization = !!$this->db->f('fictive_periodization');
         $project_type_id = (int) $this->db->f('project_type_id');
         $year = (int) $this->db->f('year');
         $month = (int) $this->db->f('month');
         $continuous = !!$this->db->f('continuous');
         $period = sprintf("%s%02d", $year, $month);
         $budget = (int) $this->db->f('budget');
         $combined_cost = (int) $this->db->f('combined_cost');
         $closed_order = (int) $this->db->f('closed');
         $_order_budget[$period] = array('order_id' => $order_id, 'start_period' => date('Ym', $this->db->f('start_date')), 'budget' => $budget ? $budget : $combined_cost, 'combined_cost' => $combined_cost, 'year' => $year, 'month' => $month, 'actual_cost' => 0, 'closed_order' => $closed_order, 'active_period' => (int) $this->db->f('active'));
         $active_period[$period] = (int) $this->db->f('active');
         /**
          * If the order is periodized - do not calculate fictitious periods
          * */
         $_check_periodization[$year] += 1;
         if ($calculate_fictive_periods) {
             $calculate_fictive_periods = $_check_periodization[$year] > 1 ? false : true;
         }
         if ($continuous) {
             $sum_year_budget[$year] += $budget ? $budget : $combined_cost;
             $sum_year_combined_cost[$year] += $combined_cost;
         }
     }
     $sql = "SELECT periode, amount AS actual_cost, periodization, periodization_start" . " FROM fm_workorder {$this->join} fm_orders_paid_or_pending_view ON fm_workorder.id = fm_orders_paid_or_pending_view.order_id" . " WHERE order_id = '{$order_id}' ORDER BY periode ASC";
     $this->db->query($sql, __LINE__, __FILE__);
     $orders_paid_or_pending = array();
     $orders_paid_or_pending_temp = array();
     //	_debug_array($sql);die();
     while ($this->db->next_record()) {
         $_periode = $this->db->f('periode');
         $periode = $_periode ? $_periode : 'dummy';
         //strange...
         if ($periode == 'dummy') {
             $orders_paid_or_pending_temp[date('Ym')]['actual_cost'] += $this->db->f('actual_cost');
             $orders_paid_or_pending_temp[date('Ym')]['periode'] = date('Ym');
             $orders_paid_or_pending_temp[date('Ym')]['periodization'] = $this->db->f('periodization');
             $orders_paid_or_pending_temp[date('Ym')]['periodization_start'] = $this->db->f('periodization_start');
         } else {
             $orders_paid_or_pending_temp[$periode] = array('periode' => $periode, 'periodization' => (int) $this->db->f('periodization'), 'periodization_start' => $this->db->f('periodization_start'));
             $orders_paid_or_pending_temp[$periode]['actual_cost'] += $this->db->f('actual_cost');
         }
     }
     //	_debug_array($orders_paid_or_pending_temp);die();
     foreach ($orders_paid_or_pending_temp as $entry) {
         if ($entry['periodization']) {
             $periodization_start = $entry['periodization_start'] ? $entry['periodization_start'] : $entry['periodization'];
             $periodization_start_year = (int) substr($periodization_start, 0, 4);
             $periodization_start_month = (int) substr($periodization_start, -2);
             $sql = "SELECT month, value, dividend, divisor" . " FROM fm_eco_periodization_outline  WHERE periodization_id = {$entry['periodization']} ORDER BY month ASC";
             $this->db->query($sql, __LINE__, __FILE__);
             $periodization_outline = array();
             while ($this->db->next_record()) {
                 $periodization_outline[] = array('month' => $this->db->f('month'), 'value' => $this->db->f('value'), 'dividend' => $this->db->f('dividend'), 'divisor' => $this->db->f('divisor'));
             }
             if (!$periodization_outline) {
                 $periodization_outline[] = array('month' => 1, 'value' => 100);
             }
             foreach ($periodization_outline as $outline) {
                 if ($outline['dividend'] && $outline['divisor']) {
                     $partial_actual_cost = $entry['actual_cost'] * $outline['dividend'] / $outline['divisor'];
                 } else {
                     $partial_actual_cost = $entry['actual_cost'] * $outline['value'] / 100;
                 }
                 $_period_month = (int) $periodization_start_month + (int) $outline['month'] - 1;
                 $_future_year_count = floor(($_period_month - 1) / 12);
                 $_periodization_start_year = $periodization_start_year + $_future_year_count;
                 $_month = $_period_month - $_future_year_count * 12;
                 $orders_paid_or_pending[] = array('periode' => sprintf("%s%02d", $_periodization_start_year, $_month), 'actual_cost' => $partial_actual_cost, 'periodization' => $entry['periodization']);
             }
         } else {
             $orders_paid_or_pending[] = $entry;
         }
     }
     //	_debug_array($orders_paid_or_pending);die();
     /**
      * Fiktiv periodisering over 12 mnd med startperiode for inneværende mnd for løpende som ikke er periodisert
      * Hopper over historiske år.
      * Start-periode blir måned for første betaling dersom den er før inneværende måned
      * ellers: Start-periode blir måned for start-dato for bestilling dersom den ligger frem i tid
      * ellers: Dersom start-dato for bestilling er passert - blir start-periode inneværende måned.
      * */
     $calculate_fictive_periods = $fictive_periodization ? $calculate_fictive_periods : false;
     $fictive_period = array();
     $exclude_from_fictive_period = array();
     $exclude_year_from_fictive_period = array();
     $order_budget = array();
     if ($continuous && $calculate_fictive_periods) {
         //First payment;
         $sql = "SELECT periode FROM fm_orders_paid_or_pending_view" . " WHERE order_id = '{$order_id}'  AND periode > " . date('Y') . '00' . " ORDER BY periode ASC";
         $this->db->query($sql, __LINE__, __FILE__);
         $this->db->next_record();
         $current_paid_period = (int) $this->db->f('periode');
         /*
         				  //FIXME total payment - if needed;
         				  $sql = "SELECT sum(amount) AS actual_cost FROM  fm_orders_paid_or_pending_view"
         				  . " WHERE order_id = '{$order_id}'  AND (periode IS NULL OR periode > " . date('Y') . '00)';
         
         				  $this->db->query($sql,__LINE__,__FILE__);
         				  $this->db->next_record();
         				  $_actual_cost_current_year = $this->db->f('actual_cost');
         */
         foreach ($_order_budget as $_period => $_budget) {
             if ($_period == "{$_budget['year']}00" && $_budget['year'] == date('Y')) {
                 $order_budget[$_period] = $_budget;
                 $active_period[$_period] = $active_period[$_period] ? 2 : 0;
                 if ($current_paid_period && $current_paid_period < (int) date('Ym')) {
                     $_current_month = (int) substr($current_paid_period, -2);
                 } else {
                     if ((int) $_budget['start_period'] > (int) date('Ym')) {
                         $_current_month = (int) substr($_budget['start_period'], -2);
                     } else {
                         $_current_month = date('n');
                         // Numeric representation of a month, without leading zeros 1 through 12
                     }
                 }
                 foreach ($orders_paid_or_pending as $_paid_or_pending) {
                     if ((int) $_paid_or_pending['periode'] > (int) $_period && (int) $_paid_or_pending['periode'] < (int) sprintf("%s%02d", $_budget['year'], $_current_month)) {
                         $_current_month = (int) substr($_paid_or_pending['periode'], -2);
                         break;
                     }
                 }
                 unset($_paid_or_pending);
                 $_sum_year_combined_cost = $sum_year_combined_cost[$_budget['year']];
                 $distribution_key = 1 / (13 - $_current_month);
                 for ($i = $_current_month; $i < 13; $i++) {
                     $period = sprintf("%s%02d", $_budget['year'], $i);
                     $fictive_period[$period] = true;
                     $active_period[$period] = $active_period[$_period] ? 1 : 0;
                     $order_budget[$period] = $_budget;
                     $order_budget[$period]['budget'] = $sum_year_budget[$_budget['year']] * $distribution_key;
                     $order_budget[$period]['combined_cost'] = $_sum_year_combined_cost * $distribution_key;
                     $order_budget[$period]['active_period'] = $_budget['active_period'];
                     $order_budget[$period]['month'] = $i;
                     $closed_period[$period] = 0;
                     //(int)$period < date('Ym');
                 }
                 $_start_month_remainig = $_current_month < 12 ? $_current_month : 0;
                 $_start_year_remainig = $_budget['year'];
                 $_start_period_remainig = array();
                 $distribution_key_remaining = 1 / (13 - $_start_month_remainig);
                 if ($_start_month_remainig) {
                     for ($i = $_start_month_remainig; $i < 13; $i++) {
                         $period = sprintf("%s%02d", $_budget['year'], $i);
                         $_start_period_remainig[] = $period;
                     }
                 }
             } else {
                 //FIXME
                 $exclude_from_fictive_period[$_period] = true;
                 $exclude_year_from_fictive_period[$_budget['year']] = true;
                 $order_budget[$_period] = $_budget;
             }
             unset($_budget);
         }
     } else {
         $order_budget = $_order_budget;
         foreach ($order_budget as $period => $_budget) {
             $this->db->query("SELECT closed FROM fm_workorder" . " {$this->join} fm_project ON fm_workorder.project_id = fm_project.id" . " {$this->join} fm_project_budget ON fm_project.id = fm_project_budget.project_id" . " WHERE fm_workorder.id = '{$_budget['order_id']}'" . " AND fm_project_budget.year = {$_budget['year']}" . " AND fm_project_budget.month = {$_budget['month']}", __LINE__, __FILE__);
             $this->db->next_record();
             $closed_period[$period] = (int) $this->db->f('closed');
         }
     }
     //_debug_array($order_budget);die();
     //_debug_array($_start_period_remainig);die();
     //_debug_array($orders_paid_or_pending);die();
     foreach ($orders_paid_or_pending as $_orders_paid_or_pending) {
         $periode = $_orders_paid_or_pending['periode'];
         $_dummy_period = $periode ? $periode : date('Y') . '00';
         if (!$periode) {
             $periode = date('Ym');
         }
         $year = substr($periode, 0, 4);
         $_found = false;
         if ($_start_month_remainig && $year == $_start_year_remainig) {
             if (in_array($periode, $_start_period_remainig)) {
                 $_temp_obligation = $order_budget[$periode]['combined_cost'] - $_orders_paid_or_pending['actual_cost'];
                 //FIXME
                 if ((int) $order_budget[$periode]['combined_cost'] * (int) $_orders_paid_or_pending['actual_cost'] > 0) {
                     $_sum_year_remaining_cost += $_temp_obligation;
                     $order_budget[$periode]['combined_cost'] -= $_temp_obligation;
                 }
             }
         }
         if (isset($_orders_paid_or_pending['periodization']) && $_orders_paid_or_pending['periodization'] && !isset($exclude_year_from_fictive_period[$year])) {
             $order_budget[$periode]['actual_cost'] += $_orders_paid_or_pending['actual_cost'];
             $order_budget[$periode]['actual_period'] = $periode;
             $order_budget[$periode]['year'] = $year;
             $order_budget[$periode]['month'] = substr($periode, -2);
             $order_budget[$periode]['closed_order'] = $closed_order;
             $_found = true;
         } else {
             if (isset($order_budget[$periode])) {
                 $order_budget[$periode]['actual_cost'] += $_orders_paid_or_pending['actual_cost'];
                 $order_budget[$periode]['actual_period'] = $periode;
                 $_found = true;
             } else {
                 for ($i = 0; $i < 13; $i++) {
                     $_period = $year . sprintf("%02s", $i);
                     if (isset($order_budget[$_period])) {
                         $order_budget[$_period]['actual_cost'] += $_orders_paid_or_pending['actual_cost'];
                         $order_budget[$_period]['actual_period'] = $periode;
                         $_found = true;
                         break;
                     }
                 }
             }
         }
         if (!$_found) {
             $order_budget[$_dummy_period]['year'] = substr($_dummy_period, 0, 4);
             $order_budget[$_dummy_period]['month'] = substr($_dummy_period, -2);
             $order_budget[$_dummy_period]['actual_cost'] += $_orders_paid_or_pending['actual_cost'];
             $order_budget[$_dummy_period]['actual_period'] = $periode;
         }
     }
     //_debug_array($order_budget);die();
     $sort_period = array();
     $values = array();
     $_current_period = date('Ym');
     $_delay_period_sum = 0;
     $_delay_period = false;
     /**
      * Move the distribution of ficivous calkulated cost to preserve the total obligation
      */
     $distribution_key_remaining_period = array();
     $distribution_key_delayed_period = array();
     foreach ($order_budget as $period => &$_budget) {
         if (isset($_start_period_remainig) && in_array($period, $_start_period_remainig)) {
             if ($period < date('Ym') && !abs($_budget['actual_cost']) > 0) {
                 $_sum_year_remaining_cost += $_budget['combined_cost'];
                 $_budget['combined_cost'] = 0;
                 $distribution_key_remaining_period[$period] = 0;
                 $distribution_key_delayed_period[$period] += $distribution_key_remaining;
             } else {
                 if (abs($_budget['actual_cost']) > 0) {
                     $distribution_key_remaining_period[$period] = 0;
                     $distribution_key_delayed_period[$period] += $distribution_key_remaining;
                 } else {
                     $distribution_key_remaining_period[$period] = $distribution_key_remaining;
                 }
             }
         }
     }
     $distribution_key_delayed_sum = array_sum($distribution_key_delayed_period);
     $num_distribution_key_correction = count($distribution_key_remaining_period) - count($distribution_key_delayed_period);
     unset($period);
     unset($_budget);
     foreach ($distribution_key_remaining_period as $period => &$value) {
         if ($value) {
             $value += $distribution_key_delayed_sum / $num_distribution_key_correction;
         }
     }
     unset($period);
     unset($value);
     foreach ($order_budget as $period => $_budget) {
         if (isset($_start_period_remainig) && in_array($period, $_start_period_remainig)) {
             $_budget['combined_cost'] += $_sum_year_remaining_cost * $distribution_key_remaining_period[$period];
         }
         $_sum_orders = 0;
         $_sum_oblications = 0;
         $_actual_cost = 0;
         $_actual_cost += $_budget['actual_cost'];
         $_sum_orders += $_budget['combined_cost'];
         if (!$_budget['closed_order']) {
             if ($active_period[$period] == 1) {
                 $_sum_oblications += $_budget['combined_cost'];
                 if ((int) $_budget['budget'] * (int) $_budget['actual_cost'] > 0) {
                     $_sum_oblications -= $_budget['actual_cost'];
                 }
                 if ($_budget['budget'] >= 0) {
                     if ($_sum_oblications < 0) {
                         $_sum_oblications = 0;
                     }
                 } else {
                     if ($_sum_oblications > 0) {
                         $_sum_oblications = 0;
                     }
                 }
             }
         }
         //override if periode is closed
         if (!isset($active_period[$period]) || !$active_period[$period] == 1) {
             $_sum_oblications = 0;
         }
         //override if periode is closed
         if (isset($closed_period[$period]) && $closed_period[$period]) {
             $_sum_oblications = 0;
         }
         if (isset($active_period[$period]) && $active_period[$period] == 1 && $_delay_period_sum && !$_delay_period) {
             $_sum_oblications += $_delay_period_sum;
             $_delay_period_sum = 0;
         }
         $_delay_period = false;
         $values[] = array('year' => $_budget['year'], 'month' => $_budget['month'] > 0 ? sprintf("%02s", $_budget['month']) : '00', 'period' => $period, 'budget' => $_budget['budget'], 'combined_cost' => $_budget['combined_cost'], 'sum_orders' => $_sum_orders, 'sum_oblications' => $_sum_oblications, 'actual_cost' => $_actual_cost, 'closed_order' => $_budget['closed_order'], 'actual_period' => $_budget['actual_period']);
         $sort_period[] = $period;
     }
     if ($values) {
         array_multisort($sort_period, SORT_ASC, $values);
     }
     //_debug_array($values);die();
     $deviation_acc = 0;
     $budget_acc = 0;
     $_year = 0;
     foreach ($values as &$entry) {
         /**
          * operation: start over each year
          */
         if ($project_type_id == 1 && $_year != $entry['year']) {
             $_year = $entry['year'];
             $deviation_acc = 0;
             $budget_acc = 0;
         }
         if (abs($entry['actual_cost']) > 0) {
             $_diff_start = abs($entry['budget']) > 0 ? $entry['budget'] : $entry['sum_orders'];
             $entry['diff'] = $_diff_start - $entry['sum_oblications'] - $entry['actual_cost'];
             $_deviation = $entry['budget'] - $entry['actual_cost'];
             $deviation = $_deviation;
             $deviation_acc += $deviation;
         } else {
             $entry['diff'] = 0;
             $deviation = 0;
         }
         $entry['deviation_period'] = $deviation;
         $budget_acc += $entry['budget'];
         $entry['deviation_acc'] = abs($deviation) > 0 ? $deviation_acc : 0;
         $entry['deviation_percent_period'] = $deviation / $entry['budget'] * 100;
         $entry['deviation_percent_acc'] = $entry['deviation_acc'] / $budget_acc * 100;
         $entry['closed'] = isset($closed_period[$entry['period']]) && $closed_period[$entry['period']];
         $entry['active'] = isset($active_period[$entry['period']]) && $active_period[$entry['period']] ? $active_period[$entry['period']] : 0;
         $entry['fictive'] = isset($fictive_period[$entry['period']]) && $fictive_period[$entry['period']];
     }
     phpgwapi_cache::system_set('property', "budget_order_{$order_id}", $values);
     return $values;
 }
 /**
  * get list of normal / non-anonymous sessions
  *
  * The data form the session-files get cached in the app_session phpgwapi/php4_session_cache
  *
  * @param integer $start       the record to start at
  * @param string  $order       the "field" to sort by
  * @param string  $sort        the direction to sort the data
  * @param boolean $all_no_sort get all records unsorted?
  *
  * @return array the list of session records
  */
 public function list_sessions($start, $order, $sort, $all_no_sort = false)
 {
     // We cache the data for 5mins system wide as this is an expensive operation
     $last_updated = 0;
     //phpgwapi_cache::system_get('phpgwapi', 'session_list_saved');
     if (is_null($last_updated) || $last_updated < 60 * 5) {
         $data = array();
         switch ($GLOBALS['phpgw_info']['server']['sessions_type']) {
             case 'db':
                 $data = phpgwapi_session_handler_db::get_list();
                 break;
             case 'php':
             default:
                 $data = self::_get_list();
         }
         phpgwapi_cache::system_set('phpgwapi', 'session_list', $data);
         phpgwapi_cache::system_set('phpgwapi', 'session_list_saved', time());
     } else {
         $data = phpgwapi_cache::system_get('phpgwapi', 'session_list');
     }
     if ($all_no_sort) {
         return $data;
     }
     $GLOBALS['phpgw']->session->sort_by = $sort;
     $GLOBALS['phpgw']->session->sort_order = $order;
     uasort($data, array('self', 'session_sort'));
     $maxmatches = 25;
     if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) && (int) $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) {
         $maxmatches = (int) $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     }
     return array_slice($data, $start, $maxmatches);
 }
 public function get($id, $use_cache = true)
 {
     $id = (int) $id;
     $account = null;
     if (!$id) {
         return null;
     }
     if ($use_cache) {
         $account = phpgwapi_cache::system_get('phpgwapi', "account_{$id}");
         if (is_object($account)) {
             return $account;
         }
     }
     $acct_type = $this->get_type($id);
     /* search the dn for the given uid */
     if ($acct_type == phpgwapi_account::TYPE_GROUP && $this->group_context) {
         $sri = ldap_search($this->ds, $this->group_context, "gidnumber={$id}");
     } else {
         if ($acct_type == phpgwapi_account::TYPE_USER && $this->user_context) {
             $sri = ldap_search($this->ds, $this->user_context, "uidnumber={$id}");
         } else {
             throw new Exception('Invalid account requested');
         }
     }
     $entries = ldap_get_entries($this->ds, $sri);
     // first in best dressed - we can't tell which one is the correct one
     $entry = $entries[0];
     unset($entries);
     $record = array();
     /* Now dump it into the array; take first entry found */
     if (isset($entry['phpgwcontactid'])) {
         $record['person_id'] = $entry['phpgwcontactid'][0];
     }
     $record['dn'] = $entry['dn'];
     $record['fullname'] = $entry['cn'][0];
     if ($acct_type == 'g') {
         $record['id'] = $entry['gidnumber'][0];
         $record['lid'] = $entry['cn'][0];
         $record['firstname'] = $entry['cn'][0];
         $record['lastname'] = lang('group');
         $record['type'] = 'g';
         $account = new phpgwapi_group();
     } else {
         $record['id'] = $entry['uidnumber'][0];
         $record['lid'] = $entry['uid'][0];
         $record['firstname'] = isset($entry['givenname']) && isset($entry['givenname'][0]) ? $entry['givenname'][0] : '';
         $record['lastname'] = isset($entry['sn']) && isset($entry['sn'][0]) ? $entry['sn'][0] : '';
         $record['expires'] = $record['account_expires'] = $entry['phpgwaccountexpires'][0];
         //		$record['homedirectory']    = isset($entry['homedirectory']) ? $entry['homedirectory'][0] : self::FALLBACK_HOMEDIRECTORY;
         //		$record['loginshell']       = isset($entry['loginshell']) ? $entry['loginshell'][0] : self::FALLBACK_LOGINSHELL;
         $record['enabled'] = isset($entry['phpgwaccountstatus']) && $entry['phpgwaccountstatus'][0] == 'A' ? true : false;
         $record['type'] = 'u';
         if (!isset($entry['phpgwquota']) || $entry['phpgwquota'] === '') {
             $record['quota'] = $this->quota;
             // set to 0 by default
         } else {
             $record['quota'] = $entry['phpgwquota'][0];
         }
         $account = new phpgwapi_user();
     }
     $account->init($record);
     phpgwapi_cache::system_set('phpgwapi', "account_{$id}", $account);
     return $account;
 }