コード例 #1
0
 /**
  * Cache an account object in the system cache
  *
  * @param object $account phpgw_account object to cache
  *
  * @return void
  */
 protected function _cache_account($account)
 {
     phpgwapi_cache::system_set('phpgwapi', "account_{$account->id}", $account);
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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));
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 /**
  * 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);
 }
コード例 #7
0
 function generate_sql($data)
 {
     //_debug_array($data);
     $cols = isset($data['cols']) ? $data['cols'] : '';
     $entity_table = isset($data['entity_table']) ? $data['entity_table'] : '';
     $location_table = isset($data['location_table']) ? $data['location_table'] : '';
     $cols_return = isset($data['cols_return']) && $data['cols_return'] ? $data['cols_return'] : array();
     $uicols = isset($data['uicols']) && $data['uicols'] ? $data['uicols'] : array();
     $joinmethod = isset($data['joinmethod']) ? $data['joinmethod'] : '';
     $paranthesis = isset($data['paranthesis']) ? $data['paranthesis'] : '';
     $lookup = isset($data['lookup']) ? $data['lookup'] : '';
     $location_level = isset($data['location_level']) && $data['location_level'] ? (int) $data['location_level'] : 0;
     $no_address = isset($data['no_address']) ? $data['no_address'] : '';
     $uicol_address = isset($data['uicol_address']) ? $data['uicol_address'] : '';
     $force_location = isset($data['force_location']) ? $data['force_location'] : '';
     $cols_extra = array();
     $cols_return_lookup = array();
     $GLOBALS['phpgw']->config->read();
     $list_location_level = isset($GLOBALS['phpgw']->config->config_data['list_location_level']) && $GLOBALS['phpgw']->config->config_data['list_location_level'] ? $GLOBALS['phpgw']->config->config_data['list_location_level'] : array();
     if (!$list_location_level) {
         for ($i = 0; $i < $location_level; $i++) {
             $list_location_level[] = $i + 1;
         }
     }
     $soadmin_location = CreateObject('property.soadmin_location');
     $location_types = $soadmin_location->select_location_type();
     $config = $soadmin_location->read_config('');
     if ($location_level || $force_location) {
         $_location_table = $location_table ? $location_table : $entity_table;
         if ($location_level) {
             $type_id = $location_level;
         } else {
             $type_id = count($location_types);
         }
         $cols .= ",fm_location1.loc1_name";
         $joinmethod .= " {$this->join}  fm_location1 ON ({$_location_table}.loc1 = fm_location1.loc1))";
         $paranthesis .= '(';
         $joinmethod .= " {$this->join}  fm_part_of_town ON (fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id))";
         $paranthesis .= '(';
         $joinmethod .= " {$this->join}  fm_owner ON (fm_location1.owner_id = fm_owner.id))";
         $paranthesis .= '(';
     } else {
         $type_id = 0;
         //count($location_types);
         $no_address = true;
     }
     $this->type_id = $type_id;
     $_level = 1;
     for ($i = 0; $i < $type_id; $i++) {
         if ($_level > 1) {
             $joinmethod .= " {$this->left_join} fm_location{$_level}";
             $paranthesis .= '(';
             $on = 'ON';
             for ($k = $_level - 1; $k > 0; $k--) {
                 $joinmethod .= " {$on} (fm_location{$_level}.loc{$k} = fm_location" . ($_level - 1) . ".loc{$k} AND  fm_location{$_level}.loc{$_level} = {$entity_table}.loc{$_level})";
                 $on = 'AND';
                 if ($k == 1) {
                     $joinmethod .= ")";
                 }
             }
         }
         $_level++;
     }
     unset($_level);
     foreach ($list_location_level as $_key => $_level) {
         if ($_level) {
             $i = $_level - 1;
             $uicols['input_type'][] = 'text';
             $uicols['name'][] = 'loc' . $location_types[$i]['id'];
             $uicols['descr'][] = $location_types[$i]['name'];
             $uicols['statustext'][] = $location_types[$i]['descr'];
             $uicols['exchange'][] = false;
             $uicols['align'][] = '';
             $uicols['datatype'][] = '';
             $uicols['formatter'][] = '';
             $uicols['classname'][] = '';
             $uicols['sortable'][] = $_level === 1;
         }
     }
     //_debug_array($uicols);die();
     //_debug_array($joinmethod);die();
     unset($soadmin_location);
     for ($i = 0; $i < $this->type_id; $i++) {
         $cols_return[] = 'loc' . $location_types[$i]['id'];
     }
     $location_relation_data = array();
     $custom = createObject('property.custom_fields');
     for ($i = 1; $i < $type_id + 1; $i++) {
         $cols .= ",loc{$i}_name";
         $cols_return[] = "loc{$i}_name";
         $cols_extra[] = "loc{$i}_name";
         $cols_return_lookup[] = "loc{$i}_name";
         $uicols['input_type'][] = in_array($i, $list_location_level) ? 'text' : 'hidden';
         $uicols['name'][] = "loc{$i}_name";
         $uicols['descr'][] = $location_types[$i - 1]['name'];
         $uicols['statustext'][] = $location_types[$i - 1]['descr'];
         $uicols['exchange'][] = $lookup;
         $uicols['align'][] = '';
         $uicols['datatype'][] = '';
         $uicols['formatter'][] = '';
         $uicols['classname'][] = '';
         $uicols['sortable'][] = $i == 1;
         $fm_location_cols_temp = $custom->find('property', '.location.' . $i, 0, '', '', '', true);
         foreach ($fm_location_cols_temp as $entry) {
             if ($entry['lookup_form']) {
                 $location_relation_data[] = array('level' => $i, 'name' => $entry['name'], 'descr' => $entry['input_text'], 'status_text' => $entry['status_text'], 'datatype' => $entry['datatype']);
             }
         }
     }
     phpgwapi_cache::system_set('property', 'location_relation_data', $location_relation_data);
     if (!$no_address) {
         $cols .= ",{$entity_table}.address";
         $cols_return[] = 'address';
         $uicols['input_type'][] = 'text';
         $uicols['name'][] = 'address';
         $uicols['descr'][] = lang('address');
         $uicols['statustext'][] = lang('address');
         $uicols['exchange'][] = false;
         $uicols['align'][] = '';
         $uicols['datatype'][] = '';
         $uicols['formatter'][] = '';
         $uicols['classname'][] = '';
         $uicols['sortable'][] = true;
     }
     $config_count = count($config);
     for ($i = 0; $i < $config_count; $i++) {
         if ($config[$i]['location_type'] <= $type_id && $config[$i]['query_value'] == 1) {
             if ($config[$i]['column_name'] == 'street_id') {
                 $cols_return[] = 'street_name';
                 $uicols['input_type'][] = 'hidden';
                 $uicols['name'][] = 'street_name';
                 $uicols['descr'][] = lang('street name');
                 $uicols['statustext'][] = lang('street name');
                 $uicols['exchange'][] = false;
                 $uicols['align'][] = '';
                 $uicols['datatype'][] = '';
                 $uicols['formatter'][] = '';
                 $uicols['classname'][] = '';
                 $uicols['sortable'][] = true;
                 $cols_return[] = 'street_number';
                 $uicols['input_type'][] = 'hidden';
                 $uicols['name'][] = 'street_number';
                 $uicols['descr'][] = lang('street number');
                 $uicols['statustext'][] = lang('street number');
                 $uicols['exchange'][] = false;
                 $uicols['align'][] = '';
                 $uicols['datatype'][] = '';
                 $uicols['formatter'][] = '';
                 $uicols['classname'][] = '';
                 $uicols['sortable'][] = '';
                 $cols_return[] = $config[$i]['column_name'];
                 $uicols['input_type'][] = 'hidden';
                 $uicols['name'][] = $config[$i]['column_name'];
                 $uicols['descr'][] = lang($config[$i]['input_text']);
                 $uicols['statustext'][] = lang($config[$i]['input_text']);
                 $uicols['exchange'][] = false;
                 $uicols['align'][] = '';
                 $uicols['datatype'][] = '';
                 $uicols['formatter'][] = '';
                 $uicols['classname'][] = '';
                 $uicols['sortable'][] = '';
                 if ($lookup) {
                     $cols_extra[] = 'street_name';
                     $cols_extra[] = 'street_number';
                     $cols_extra[] = $config[$i]['column_name'];
                 }
             } else {
                 $cols_return[] = $config[$i]['column_name'];
                 $uicols['input_type'][] = 'text';
                 $uicols['name'][] = $config[$i]['column_name'];
                 $uicols['descr'][] = $config[$i]['input_text'];
                 $uicols['statustext'][] = $config[$i]['input_text'];
                 $uicols['exchange'][] = false;
                 $uicols['align'][] = '';
                 $uicols['datatype'][] = '';
                 $uicols['formatter'][] = '';
                 $uicols['classname'][] = '';
                 $uicols['sortable'][] = '';
                 if ($lookup) {
                     $cols_extra[] = $config[$i]['column_name'];
                 }
             }
         }
     }
     $this->uicols = $uicols;
     $this->cols_return = $cols_return;
     $this->cols_extra = $cols_extra;
     $this->cols_return_lookup = $cols_return_lookup;
     $from = " FROM {$paranthesis} {$entity_table} ";
     $sql = "SELECT DISTINCT {$cols} {$from} {$joinmethod}";
     return $sql;
 }
コード例 #8
0
 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;
 }