public function __construct() { $cal_id = phpgw::get_var('cal_id', 'int', 'POST'); if ($cal_id) { $this->cal_id = $cal_id; } $this->bo = CreateObject('calendar.bocalendar', 1); $this->so = CreateObject('calendar.socalendar', 1); $this->tz_offset = phpgwapi_datetime::user_timezone(); if ($this->debug) { echo "BO Owner : " . $this->bo->owner . "<br />\n"; } if ($this->bo->use_session) { $this->save_sessiondata(); } }
function edit_id($values = array()) { if (!isset($values['select']) || !is_array($values['select'])) { return $receipt['message'][] = array('msg' => lang('Nothing to do')); } $this->db->transaction_begin(); foreach ($values['select'] as $field) { $start_date = phpgwapi_datetime::date_to_timestamp($values['start_date'][$field]); if ($start_date && $start_date < time()) { $receipt['error'][] = array('msg' => lang('Cannot go back in time for "%1"', $field)); continue; } $sql = "SELECT value,descr, max(start_date) as start_date FROM fm_idgenerator WHERE name='{$field}' GROUP BY value, descr ORDER BY start_date ASC"; $this->db->query($sql, __LINE__, __FILE__); while ($this->db->next_record()) { $value = $this->db->f('value'); $descr = $this->db->f('descr'); $old_start_date = $this->db->f('start_date'); } if ($start_date > $old_start_date) { $sql = "INSERT INTO fm_idgenerator (name, descr, value, start_date ) VALUES ('{$field}','{$descr}', '{$values[$field]}','{$start_date}')"; $this->db->query($sql, __LINE__, __FILE__); } else { if ($start_date < $old_start_date) { $sql = "DELETE FROM fm_idgenerator WHERE name = name AND start_date > {$start_date}"; $this->db->query($sql, __LINE__, __FILE__); $sql = "INSERT INTO fm_idgenerator (name, descr, value, start_date ) VALUES ('{$field}','{$descr}', '{$values[$field]}','{$start_date}')"; $this->db->query($sql, __LINE__, __FILE__); } else { $sql = "UPDATE fm_idgenerator SET value = '{$values[$field]}' WHERE name='{$field}' AND start_date = {$start_date}"; $this->db->query($sql, __LINE__, __FILE__); } } } $this->db->transaction_commit(); $receipt['message'][] = array('msg' => lang('ID is updated')); return $receipt; }
function list_repeated_events($syear, $smonth, $sday, $eyear, $emonth, $eday, $owner_id = 0) { if (!isset($GLOBALS['phpgw_info']['server']['calendar_type']) || isset($GLOBALS['phpgw_info']['server']['calendar_type']) && $GLOBALS['phpgw_info']['server']['calendar_type'] != 'sql') { return array(); } $user_timezone = phpgwapi_datetime::user_timezone(); $starttime = mktime(0, 0, 0, $smonth, $sday, $syear) - $user_timezone; $endtime = mktime(23, 59, 59, $emonth, $eday, $eyear) - $user_timezone; // $starttime = mktime(0,0,0,$smonth,$sday,$syear); // $endtime = mktime(23,59,59,$emonth,$eday,$eyear); $sql = "AND (phpgw_cal.cal_type='M') " . 'AND (phpgw_cal_user.cal_login IN ('; if ($owner_id) { if (is_array($owner_id)) { $ids = $owner_id; } else { $ids[] = $owner_id; } } else { $ids = !$this->is_group ? array($this->owner) : $this->g_owner; } $sql .= is_array($ids) && count($ids) ? implode(',', $ids) : 0; // $member_groups = $GLOBALS['phpgw']->accounts->membership($this->user); // @reset($member_groups); // while(list($key,$group_info) = each($member_groups)) // { // $member[] = $group_info['account_id']; // } // @reset($member); // $sql .= ','.implode(',',$member).') '; // $sql .= 'AND (phpgw_cal.datetime <= '.$starttime.') '; // $sql .= 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) ' $sql .= ') AND ((phpgw_cal_repeats.recur_enddate >= ' . $starttime . ') OR (phpgw_cal_repeats.recur_enddate=0))) ' . (strpos($this->filter, 'private') ? 'AND phpgw_cal.is_public=0 ' : '') . ($this->cat_id ? "AND phpgw_cal.category like '%" . $this->cat_id . "%' " : '') . 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; if ($this->debug) { echo '<!-- SO list_repeated_events : SQL : ' . $sql . ' -->' . "\n"; } return $this->get_event_ids(True, $sql); }
function import() { if (!$this->acl_add) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uilocation.stop', 'perm' => 2, 'acl_location' => $this->acl_location)); } $GLOBALS['phpgw_info']['flags']['menu_selection'] .= '::import'; $receipt = $GLOBALS['phpgw']->session->appsession('session_data', 'import_receipt'); $GLOBALS['phpgw']->session->appsession('session_data', 'import_receipt', ''); $art = phpgw::get_var('art', 'int'); $type = phpgw::get_var('type'); $dim_b = phpgw::get_var('dim_b', 'int'); $invoice_num = phpgw::get_var('invoice_num'); $kid_nr = phpgw::get_var('kid_nr'); $vendor_id = phpgw::get_var('vendor_id', 'int'); $vendor_name = phpgw::get_var('vendor_name'); $janitor = phpgw::get_var('janitor'); $supervisor = phpgw::get_var('supervisor'); $budget_responsible = phpgw::get_var('budget_responsible'); $invoice_date = urldecode(phpgw::get_var('invoice_date')); $num_days = phpgw::get_var('num_days', 'int'); $payment_date = urldecode(phpgw::get_var('payment_date')); $cancel = phpgw::get_var('cancel', 'bool'); $convert = phpgw::get_var('convert', 'bool'); $conv_type = phpgw::get_var('conv_type'); $sday = phpgw::get_var('sday', 'int'); $smonth = phpgw::get_var('smonth', 'int'); $syear = phpgw::get_var('syear', 'int'); $eday = phpgw::get_var('eday', 'int'); $emonth = phpgw::get_var('emonth', 'int'); $eyear = phpgw::get_var('eyear', 'int'); $download = phpgw::get_var('download', 'bool'); $auto_tax = phpgw::get_var('auto_tax', 'bool'); $tsvfile = $_FILES['tsvfile']['tmp_name']; if (!$tsvfile) { $tsvfile = phpgw::get_var('tsvfile'); } if ($cancel && $tsvfile) { unlink($tsvfile); } if ($convert) { unset($receipt); if ($conv_type == '') { $receipt['error'][] = array('msg' => lang('Please - select a import format !')); } if (!$tsvfile) { $receipt['error'][] = array('msg' => lang('Please - select a file to import from !')); } if (!$art) { $receipt['error'][] = array('msg' => lang('Please - select type invoice!')); } if (!$vendor_id) { $receipt['error'][] = array('msg' => lang('Please - select Vendor!')); } if (!$type) { $receipt['error'][] = array('msg' => lang('Please - select type order!')); } if (!$budget_responsible) { $receipt['error'][] = array('msg' => lang('Please - select budget responsible!')); } if (!$this->invoice->check_vendor($vendor_id)) { $receipt['error'][] = array('msg' => lang('That Vendor ID is not valid !') . ' : ' . $vendor_id); } if (!$payment_date && !$num_days) { $receipt['error'][] = array('msg' => lang('Please - select either payment date or number of days from invoice date !')); } if (!file_exists($tsvfile)) { $receipt['error'][] = array('msg' => lang('The file is empty or removed!')); } if (!is_array($receipt['error'])) { if ($invoice_date) { $sdateparts = phpgwapi_datetime::date_array($invoice_date); $sday = $sdateparts['day']; $smonth = $sdateparts['month']; $syear = $sdateparts['year']; unset($sdateparts); $edateparts = phpgwapi_datetime::date_array($payment_date); $eday = $edateparts['day']; $emonth = $edateparts['month']; $eyear = $edateparts['year']; unset($edateparts); } $old = $tsvfile; $tsvfile = $GLOBALS['phpgw_info']['server']['temp_dir'] . '/invoice_import_' . basename($tsvfile); rename($old, $tsvfile); $invoice_common = array('bilagsnr' => $this->invoice->next_bilagsnr(), 'art' => $art, 'type' => $type, 'dim_b' => $dim_b, 'invoice_num' => $invoice_num, 'kid_nr' => $kid_nr, 'vendor_id' => $vendor_id, 'vendor_name' => $vendor_name, 'janitor' => $janitor, 'supervisor' => $supervisor, 'budget_responsible' => $budget_responsible, 'num_days' => $num_days, 'sday' => $sday, 'smonth' => $smonth, 'syear' => $syear, 'eday' => $eday, 'emonth' => $emonth, 'eyear' => $eyear, 'tsvfile' => $tsvfile, 'conv_type' => $conv_type, 'invoice_date' => $invoice_date, 'payment_date' => $payment_date, 'auto_tax' => $auto_tax); $buffer = $this->bo->import($invoice_common, $download); if (!$download) { $receipt = $buffer; $GLOBALS['phpgw']->session->appsession('session_data', 'import_receipt', $receipt); unlink($tsvfile); unset($invoice_common); unset($art); unset($type); unset($dim_b); unset($invoice_num); unset($kid_nr); unset($vendor_id); unset($vendor_name); unset($janitor); unset($supervisor); unset($budget_responsible); unset($invoice_date); unset($num_days); unset($payment_date); unset($conv_type); unset($auto_tax); // $GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiXport.import')); } else { $GLOBALS['phpgw_info']['flags']['noframework'] = true; $this->debug_import($buffer, $invoice_common); return; } } } set_time_limit(0); $link_data = array('menuaction' => 'property.uiXport.import', 'sub' => $sub); $msgbox_data = $this->bocommon->msgbox_data($receipt); $GLOBALS['phpgw']->jqcal->add_listener('invoice_date'); $GLOBALS['phpgw']->jqcal->add_listener('payment_date'); $data = array('menu' => $this->bocommon->get_menu(), 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'form_action' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'cancel_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiinvoice.index', 'sub' => $sub)), 'lang_cancel' => lang('Cancel'), 'lang_cancel_statustext' => lang('cancel the import'), 'action_url' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property' . '.uiXport.import')), 'tsvfilename' => '', 'lang_debug' => lang('Debug output in browser'), 'lang_debug_statustext' => lang('Check this to have the output to screen before import (recommended)'), 'value_debug' => $download, 'lang_import' => lang('Import'), 'lang_import_statustext' => lang('click this button to start the import'), 'lang_invoice_date' => lang('invoice date'), 'lang_payment_date' => lang('Payment date'), 'lang_no_of_days' => lang('Days'), 'lang_invoice_number' => lang('Invoice Number'), 'lang_invoice_num_statustext' => lang('Enter Invoice Number'), 'lang_select' => lang('Select per button !'), 'lang_kidnr' => lang('KID nr'), 'lang_kid_nr_statustext' => lang('Enter Kid nr'), 'lang_vendor' => lang('Vendor'), 'addressbook_link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uilookup.vendor')), 'lang_invoice_date_statustext' => lang('Enter the invoice date'), 'lang_num_days_statustext' => lang('Enter the payment date or the payment delay'), 'lang_payment_date_statustext' => lang('Enter the payment date or the payment delay'), 'lang_file_statustext' => lang('Select the file to import from'), 'lang_vendor_statustext' => lang('Select the vendor by clicking the button'), 'lang_vendor_name_statustext' => lang('Select the vendor by clicking the button'), 'lang_select_vendor_statustext' => lang('Select the vendor by clicking this button'), 'value_invoice_date' => $invoice_date, 'value_payment_date' => $payment_date, 'value_belop' => $belop, 'value_vendor_id' => $vendor_id, 'value_vendor_name' => $vendor_name, 'value_kid_nr' => $kid_nr, 'value_dim_b' => $dim_b, 'value_invoice_num' => $invoice_num, 'value_merknad' => $merknad, 'value_num_days' => $num_days, 'lang_file' => lang('File'), 'lang_conv' => lang('Conversion'), 'conv_list' => $this->bo->select_import_conv($conv_type), 'select_conv' => 'conv_type', 'lang_select_conversion' => lang('Select the type of conversion:'), 'lang_conv_statustext' => lang('You have to select the Conversion for this import'), 'lang_auto_tax' => lang('Auto TAX'), 'lang_auto_tax_statustext' => lang('Set tax during import'), 'lang_art' => lang('Art'), 'art_list' => $this->invoice->get_lisfm_ecoart($art), 'select_art' => 'art', 'lang_select_art' => lang('Select Invoice Type'), 'lang_art_statustext' => lang('You have to select type of invoice'), 'lang_type' => lang('Type invoice II'), 'type_list' => $this->invoice->get_type_list($type), 'select_type' => 'type', 'lang_no_type' => lang('No type'), 'lang_type_statustext' => lang('Select the type invoice. To do not use type - select NO TYPE'), 'lang_dimb' => lang('Dim B'), 'dimb_list' => $this->invoice->select_dimb_list($dim_b), 'select_dimb' => 'dim_b', 'lang_no_dimb' => lang('No Dim B'), 'lang_dimb_statustext' => lang('Select the Dim B for this invoice. To do not use Dim B - select NO DIM B'), 'lang_janitor' => lang('Janitor'), 'janitor_list' => $this->bocommon->get_user_list_right(32, $janitor, '.invoice'), 'select_janitor' => 'janitor', 'lang_no_janitor' => lang('No janitor'), 'lang_janitor_statustext' => lang('Select the janitor responsible for this invoice. To do not use janitor - select NO JANITOR'), 'lang_supervisor' => lang('Supervisor'), 'supervisor_list' => $this->bocommon->get_user_list_right(64, $supervisor, '.invoice'), 'select_supervisor' => 'supervisor', 'lang_no_supervisor' => lang('No supervisor'), 'lang_supervisor_statustext' => lang('Select the supervisor responsible for this invoice. To do not use supervisor - select NO SUPERVISOR'), 'lang_budget_responsible' => lang('B - responsible'), 'budget_responsible_list' => $this->bocommon->get_user_list_right(128, $budget_responsible, '.invoice'), 'select_budget_responsible' => 'budget_responsible', 'lang_select_budget_responsible' => lang('Select B-Responsible'), 'lang_budget_responsible_statustext' => lang('You have to select a budget responsible for this invoice in order to make the import')); $GLOBALS['phpgw']->xslttpl->add_file(array('invoice')); $appname = lang('Invoice'); $function_msg = lang('Import from CSV'); $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg; $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('import' => $data)); // $GLOBALS['phpgw']->xslttpl->pp(); }
/** * Find recurring events for a period defined by the event * * @return array schedule */ public function event_schedule_data() { $id = phpgw::get_var('id', 'int'); $event = $this->so->read_single($id); $criteria = array('start_date' => $event['start_date'], 'end_date' => $event['end_date'], 'location_id' => $event['location_id'], 'location_item_id' => $event['location_item_id']); $this->find_scedules($criteria); $schedules = $this->cached_events; $total_records = 0; $lang_exception = lang('exception'); $values = array(); $i = 1; foreach ($schedules as $_date => $set) { $__date = substr($_date, 0, 4) . '-' . substr($_date, 4, 2) . '-' . substr($_date, 6, 2); $date = phpgwapi_datetime::convertDate($__date, 'Y-m-d', $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']); foreach ($set as $entry) { $values[] = array('time' => $i, 'date' => array('exception' => $entry['exception'], 'lang_exception' => $lang_exception, 'type' => 'event', 'name' => $date, 'link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'booking.uievent.show', 'location_id' => $entry['location_id'], 'location_item_id' => $entry['location_item_id'])))); $i++; } } $data = array('ResultSet' => array("totalResultsAvailable" => $total_records, "Result" => $values)); return $data; }
function update_investment($values) { $date_array = phpgwapi_datetime::date_array($values['date']); $date = mktime(2, 0, 0, $date_array['month'], $date_array['day'], $date_array['year']); $date = date($GLOBALS['phpgw']->db->date_format(), $date); $new_index = str_replace(",", ".", $values['new_index']); $update = array(); foreach ($values['update'] as $entry) { $local_error = false; $n = $entry; if ($values['value'][$n]) { if (abs($values['value'][$n]) - abs($values['initial_value'][$n] * $new_index) < 0) { $new_value = 0; $new_index = $values['value'][$n] / $values['initial_value'][$n]; } else { $new_value = $values['value'][$n] - $values['initial_value'][$n] * $new_index; } $update[] = array('entity_id' => $values['entity_id'][$n], 'invest_id' => $values['investment_id'][$n], 'new_index' => $new_index, 'new_value' => $new_value, 'initial_value' => $values['initial_value'][$n], 'date' => $date); } } return $this->so->update_investment($update); }
/** * Prepare an attribute value so it can be saved in the database * * @param array $values_attribute an attribute structure * * @return array the structure with the value prepared * * @internal the name of this method is misleading */ public function convert_attribute_save($values_attribute = null) { if (!is_array($values_attribute)) { return ''; } foreach ($values_attribute as &$attrib) { if (!$attrib['value']) { continue; } switch ($attrib['datatype']) { case 'CH': $attrib['value'] = ',' . implode(',', $attrib['value']) . ','; break; case 'R': $attrib['value'] = $attrib['value'][0]; break; case 'N': $attrib['value'] = str_replace(',', '.', $attrib['value']); break; case 'D': $ts = phpgwapi_datetime::date_to_timestamp($attrib['value']) - phpgwapi_datetime::user_timezone(); $attrib['value'] = date($this->_dateformat, $ts); break; case 'DT': if ($attrib['value']['date']) { $date_array = phpgwapi_datetime::date_array($attrib['value']['date']); $ts = mktime((int) $attrib['value']['hour'], (int) $attrib['value']['min'], 0, $date_array['month'], $date_array['day'], $date_array['year']) - phpgwapi_datetime::user_timezone(); $attrib['value'] = date($this->_datetimeformat, $ts); } else { $attrib['value'] = ''; } break; } } return $values_attribute; }
/** * Save responsibility contact * * @param array $values values to be stored/edited and referencing ID if editing * * @return array $receip with result on the action(failed/success) */ public function save_contact($values) { phpgw::import_class('phpgwapi.datetime'); if (isset($values['active_from'])) { $values['active_from'] = phpgwapi_datetime::date_to_timestamp($values['active_from']); } if (isset($values['active_to'])) { $values['active_to'] = phpgwapi_datetime::date_to_timestamp($values['active_to']); } if (isset($values['id']) && $values['id']) { $receipt = $this->so->edit_contact($values); } else { $receipt = $this->so->add_contact($values); } return $receipt; }
function read($data) { $start = isset($data['start']) && $data['start'] ? $data['start'] : 0; $filter = $data['filter'] ? (int) $data['filter'] : 0; $query = isset($data['query']) ? $data['query'] : ''; $sort = isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC'; $order = isset($data['order']) ? $data['order'] : ''; $cat_id = isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id'] : 0; $status_id = isset($data['status_id']) && $data['status_id'] ? $data['status_id'] : 'open'; $start_date = isset($data['start_date']) && $data['start_date'] ? (int) $data['start_date'] : 0; $end_date = isset($data['end_date']) && $data['end_date'] ? (int) $data['end_date'] : 0; $allrows = isset($data['allrows']) ? $data['allrows'] : ''; $obligation = isset($data['obligation']) ? $data['obligation'] : ''; $wo_hour_cat_id = isset($data['wo_hour_cat_id']) ? $data['wo_hour_cat_id'] : ''; $b_group = isset($data['b_group']) ? $data['b_group'] : ''; $ecodimb = isset($data['ecodimb']) ? $data['ecodimb'] : ''; $paid = isset($data['paid']) ? $data['paid'] : ''; $b_account = isset($data['b_account']) ? $data['b_account'] : ''; $district_id = isset($data['district_id']) ? $data['district_id'] : ''; $dry_run = isset($data['dry_run']) ? $data['dry_run'] : ''; $criteria = isset($data['criteria']) && $data['criteria'] ? $data['criteria'] : array(); $filter_year = isset($data['filter_year']) ? $data['filter_year'] : ''; $tender_deadline = isset($data['tender_deadline']) && $data['tender_deadline'] ? (int) $data['tender_deadline'] : 0; $inspection_on_completion = isset($data['inspection_on_completion']) && $data['inspection_on_completion'] ? (int) $data['inspection_on_completion'] : 0; $GLOBALS['phpgw']->config->read(); $sql = $this->bocommon->fm_cache('sql_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group); //echo $sql; if (!$sql) { $cols = "fm_project.id as project_id"; $cols_return[] = 'project_id'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'project_id'; $uicols['descr'][] = lang('Project'); $uicols['statustext'][] = lang('Project ID'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = 'linktToProject'; $uicols['classname'][] = ''; $uicols['sortable'][] = true; $cols .= ",fm_workorder.id as workorder_id"; $cols_return[] = 'workorder_id'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'workorder_id'; $uicols['descr'][] = lang('Workorder'); $uicols['statustext'][] = lang('Workorder ID'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = 'linktToOrder'; $uicols['classname'][] = ''; $uicols['sortable'][] = true; $cols .= ",fm_workorder.title as title"; $cols_return[] = 'title'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'title'; $uicols['descr'][] = lang('Title'); $uicols['statustext'][] = lang('Workorder title'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; $uicols['sortable'][] = ''; $cols .= ",fm_workorder_status.descr as status"; $cols_return[] = 'status'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'status'; $uicols['descr'][] = lang('Status'); $uicols['statustext'][] = lang('Workorder status'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; $uicols['sortable'][] = ''; $cols .= ",fm_workorder.entry_date as entry_date"; $cols_return[] = 'entry_date'; $cols .= ",fm_workorder.start_date as start_date"; $cols_return[] = 'start_date'; $cols .= ",fm_workorder.end_date as end_date"; $cols_return[] = 'end_date'; $cols .= ",fm_workorder.tender_deadline as tender_deadline"; $cols_return[] = 'tender_deadline'; $cols .= ",fm_workorder.tender_received as tender_received"; $cols_return[] = 'tender_received'; $cols .= ",fm_workorder.inspection_on_completion as inspection_on_completion"; $cols_return[] = 'inspection_on_completion'; $cols .= ",fm_project.ecodimb"; $cols_return[] = 'ecodimb'; $cols .= ",fm_workorder.contract_sum"; $cols_return[] = 'contract_sum'; $cols .= ",fm_workorder.approved"; $cols_return[] = 'approved'; $cols .= ",fm_workorder.account_id as b_account_id"; $cols_return[] = 'b_account_id'; /* $uicols['input_type'][] = 'text'; $uicols['name'][] = 'entry_date'; $uicols['descr'][] = lang('Entry date'); $uicols['statustext'][] = lang('Workorder entry date'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; */ $cols .= ",phpgw_accounts.account_lid as user_lid"; $cols_return[] = 'user_lid'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'user_lid'; $uicols['descr'][] = lang('User'); $uicols['statustext'][] = lang('Workorder User'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; $uicols['sortable'][] = ''; $cols .= ',fm_workorder.vendor_id'; $cols_return[] = 'vendor_id'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'vendor_id'; $uicols['descr'][] = lang('Vendor ID'); $uicols['statustext'][] = lang('Vendor ID'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; $uicols['sortable'][] = ''; $cols .= ",loc1_name"; // $cols_return[] = 'loc1_name'; /* $uicols['input_type'][] = 'hidden'; $uicols['name'][] = 'loc1_name'; $uicols['descr'][] = ''; $uicols['statustext'][] = ''; $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; $uicols['sortable'][] = ''; */ $cols .= ",fm_project.user_id as project_owner"; $joinmethod .= "{$this->join} fm_workorder ON (fm_project.id = fm_workorder.project_id) {$this->join} phpgw_accounts ON (fm_workorder.user_id = phpgw_accounts.account_id))"; $paranthesis .= '('; $joinmethod .= " {$this->join} fm_workorder_status ON (fm_workorder.status = fm_workorder_status.id))"; $paranthesis .= '('; $cols .= ',fm_workorder_status.closed'; $cols .= ',fm_vendor.org_name'; $cols_return[] = 'org_name'; $uicols['input_type'][] = 'hidden'; $uicols['name'][] = 'org_name'; $uicols['descr'][] = lang('Vendor name'); $uicols['statustext'][] = lang('Vendor name'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = ''; $uicols['classname'][] = ''; $uicols['sortable'][] = ''; $cols .= ',fm_workorder.budget'; $cols_return[] = 'budget'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'budget'; $uicols['descr'][] = lang('budget'); $uicols['statustext'][] = lang('budget'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = 'myFormatCount2'; $uicols['classname'][] = 'rightClasss'; $uicols['sortable'][] = false; // $cols .= ',fm_workorder.combined_cost'; // $cols_return[] = 'combined_cost'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'obligation'; $uicols['descr'][] = lang('sum orders'); $uicols['statustext'][] = lang('Cost - either budget or calculation'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = 'myFormatCount2'; $uicols['classname'][] = 'rightClasss'; $uicols['sortable'][] = false; $cols .= ',fm_workorder.actual_cost'; $cols_return[] = 'actual_cost'; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'actual_cost'; $uicols['descr'][] = lang('Actual cost'); $uicols['statustext'][] = lang('Actual cost - paid so far'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = 'myFormatCount2'; $uicols['classname'][] = 'rightClasss'; $uicols['sortable'][] = true; $uicols['input_type'][] = 'text'; $uicols['name'][] = 'diff'; $uicols['descr'][] = lang('difference'); $uicols['statustext'][] = lang('difference'); $uicols['exchange'][] = false; $uicols['align'][] = ''; $uicols['datatype'][] = ''; $uicols['formatter'][] = 'myFormatCount2'; $uicols['classname'][] = 'rightClasss'; $uicols['sortable'][] = ''; $joinmethod .= " {$this->left_join} fm_vendor ON (fm_workorder.vendor_id = fm_vendor.id))"; $paranthesis .= '('; $joinmethod .= " {$this->left_join} fm_workorder_budget ON (fm_workorder.id = fm_workorder_budget.order_id))"; $paranthesis .= '('; //----- wo_hour_status if ($wo_hour_cat_id) { $joinmethod .= " {$this->join} fm_wo_hours ON (fm_workorder.id = fm_wo_hours.workorder_id))"; $paranthesis .= '('; $joinmethod .= " {$this->join} fm_wo_hours_category ON (fm_wo_hours.category = fm_wo_hours_category.id))"; $paranthesis .= '('; } $joinmethod .= " {$this->join} fm_b_account ON (fm_workorder.account_id =fm_b_account.id))"; $paranthesis .= '('; //----- b_group $cols_return[] = 'location_code'; $cols_return[] = 'billable_hours'; $cols_return[] = 'continuous'; $cols .= ',fm_workorder.billable_hours'; $cols .= ',fm_workorder.continuous'; $no_address = false; if (isset($GLOBALS['phpgw']->config->config_data['location_at_workorder']) && $GLOBALS['phpgw']->config->config_data['location_at_workorder']) { $no_address = true; $cols .= ',fm_workorder.location_code'; $cols .= ',fm_workorder.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; $joinmethod .= "{$this->join} fm_locations ON (fm_workorder.location_code = fm_locations.location_code))"; $paranthesis .= '('; $location_table = 'fm_locations'; } else { $cols .= ",fm_project.location_code"; $location_table = 'fm_project'; } $entity_table = 'fm_project'; $sql = $this->bocommon->generate_sql(array('entity_table' => $entity_table, 'location_table' => $location_table, 'cols' => $cols, 'cols_return' => $cols_return, 'uicols' => $uicols, 'joinmethod' => $joinmethod, 'paranthesis' => $paranthesis, 'force_location' => true, 'no_address' => $no_address, 'location_level' => 0)); $this->bocommon->fm_cache('sql_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group, $sql); $this->uicols = $this->bocommon->uicols; $cols_return = $this->bocommon->cols_return; $type_id = $this->bocommon->type_id; // $this->cols_extra = $this->bocommon->cols_extra; $this->bocommon->fm_cache('uicols_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group, $this->uicols); $this->bocommon->fm_cache('cols_return_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group, $cols_return); $this->bocommon->fm_cache('type_id_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group, $type_id); // $this->bocommon->fm_cache('cols_extra_workorder'.!!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group,$this->cols_extra); } else { $this->uicols = $this->bocommon->fm_cache('uicols_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group); $cols_return = $this->bocommon->fm_cache('cols_return_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group); $type_id = $this->bocommon->fm_cache('type_id_workorder' . !!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group); // $this->cols_extra = $this->bocommon->fm_cache('cols_extra_workorder'.!!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group); } $location_table = 'fm_project'; if (isset($GLOBALS['phpgw']->config->config_data['location_at_workorder']) && $GLOBALS['phpgw']->config->config_data['location_at_workorder']) { $location_table = 'fm_workorder'; } $order_field = ''; if ($order) { $ordermethod = " ORDER BY {$order} {$sort}"; switch ($order) { case 'workorder_id': $ordermethod = " ORDER BY fm_workorder.id {$sort}"; break; case 'actual_cost': $order_field = ',fm_workorder.actual_cost'; break; case 'address': if (isset($GLOBALS['phpgw']->config->config_data['location_at_workorder']) && $GLOBALS['phpgw']->config->config_data['location_at_workorder']) { $order_field = ", fm_workorder.address"; } else { $order_field = ", fm_project.address"; } break; case 'entry_date': $order_field = ", fm_workorder.entry_date"; $ordermethod = " ORDER BY fm_workorder.entry_date {$sort}, fm_workorder.id"; break; case 'start_date': $order_field = ", fm_workorder.start_date"; $ordermethod = " ORDER BY fm_workorder.start_date {$sort}, fm_workorder.id"; break; case 'end_date': $order_field = ", fm_workorder.end_date"; $ordermethod = " ORDER BY fm_workorder.end_date {$sort}, fm_workorder.id"; break; case 'tender_deadline': $order_field = ", fm_workorder.tender_deadline"; $ordermethod = " ORDER BY fm_workorder.tender_deadline {$sort}, fm_workorder.id"; break; case 'tender_received': $order_field = ", fm_workorder.tender_received"; $ordermethod = " ORDER BY fm_workorder.tender_received {$sort}, fm_workorder.id"; break; case 'inspection_on_completion': $order_field = ", fm_workorder.inspection_on_completion"; $ordermethod = " ORDER BY fm_workorder.inspection_on_completion {$sort}, fm_workorder.id"; break; case 'ecodimb': $order_field = ", fm_project.ecodimb"; $ordermethod = " ORDER BY fm_workorder.ecodimb {$sort}, fm_workorder.id"; break; case 'budget': $order_field = ", fm_workorder.budget"; $ordermethod = " ORDER BY fm_workorder.budget {$sort}, fm_workorder.id"; break; case 'approved': $order_field = ", fm_workorder.approved"; $ordermethod = " ORDER BY fm_workorder.approved {$sort}, fm_workorder.id"; break; case 'b_account_id': $order_field = ", fm_workorder.account_id"; $ordermethod = " ORDER BY fm_workorder.account_id {$sort}, fm_workorder.id"; break; default: $order_field = ", {$order}"; } } else { // $ordermethod = ' ORDER BY fm_workorder.project_id DESC,fm_workorder.id DESC'; $ordermethod = ' ORDER BY fm_workorder.id DESC'; } //_debug_array($order_field);die; $where = 'WHERE'; $filtermethod = ''; if (isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location']) { $access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ); $filtermethod = " WHERE fm_project.loc1 in ('" . implode("','", $access_location) . "')"; $where = 'AND'; } if ($cat_id > 0) { $cats = CreateObject('phpgwapi.categories', -1, 'property', '.project'); $cats->supress_info = true; $cat_list_project = $cats->return_sorted_array(0, false, '', '', '', false, $cat_id, false); $cat_filter = array($cat_id); foreach ($cat_list_project as $_category) { $cat_filter[] = $_category['id']; } $filtermethod .= " {$where} fm_workorder.category IN (" . implode(',', $cat_filter) . ')'; $where = 'AND'; } if ($status_id && $status_id != 'all') { if ($status_id == 'open') { $filtermethod .= " {$where} fm_workorder_status.closed IS NULL"; /* $_status_filter = array(); $this->db->query("SELECT * FROM fm_workorder_status WHERE closed IS NULL"); $this->db->query("SELECT * FROM fm_workorder_status WHERE delivered IS NULL AND closed IS NULL"); while($this->db->next_record()) { $_status_filter[] = $this->db->f('id'); } $filtermethod .= " $where fm_workorder.status IN ('" . implode("','", $_status_filter) . "')"; */ } else { $filtermethod .= " {$where} fm_workorder.status='{$status_id}' "; } $where = 'AND'; } $group_method = ''; if ($wo_hour_cat_id) { $filtermethod .= " {$where} fm_wo_hours_category.id={$wo_hour_cat_id} "; $where = 'AND'; $group_method = " group by fm_project.id,{$location_table}.location_code,fm_workorder.id,workorder_id,title,fm_workorder.status,fm_workorder.entry_date,user_lid,fm_workorder.vendor_id,project_owner,{$location_table}.address,fm_vendor.org_name,fm_workorder.combined_cost,fm_workorder.actual_cost,fm_workorder.act_vendor_cost"; } if ($b_group) { $filtermethod .= " {$where} fm_b_account.category='{$b_group}' "; $where = 'AND'; } if ($paid) { /* 0 => cancelled, 1 => obligation , 2 => paid */ $filtermethod .= " {$where} fm_workorder.paid = {$paid} AND vendor_id > 0"; $where = 'AND'; } if ($ecodimb) { $filtermethod .= " {$where} fm_project.ecodimb =" . (int) $ecodimb; $where = 'AND'; } if ($b_account) { $filtermethod .= " {$where} fm_workorder.account_id = '{$b_account}'"; $where = 'AND'; } if ($district_id) { $filtermethod .= " {$where} district_id = {$district_id}"; $where = 'AND'; } if (is_array($this->grants)) { $grants = $this->grants; while (list($user) = each($grants)) { $public_user_list[] = $user; } reset($public_user_list); $filtermethod .= " {$where} (fm_project.access='public' AND fm_project.user_id IN(" . implode(',', $public_user_list) . ")"; $where = 'AND'; } if ($filter) { $filtermethod .= " {$where} fm_workorder.user_id={$filter}"; $where = 'AND'; } if ($start_date) { $end_date = $end_date + 3600 * 16 + phpgwapi_datetime::user_timezone(); $start_date = $start_date - 3600 * 8 + phpgwapi_datetime::user_timezone(); $filtermethod .= " {$where} (fm_workorder.start_date >= {$start_date} AND fm_workorder.start_date <= {$end_date}"; if ($obligation) { $filtermethod .= " OR fm_workorder_status.closed IS NULL)"; } else { $filtermethod .= ')'; } $where = 'AND'; } if ($tender_deadline) { $tender_deadline = $tender_deadline - 3600 * 8 + phpgwapi_datetime::user_timezone(); $filtermethod .= " {$where} (fm_workorder.tender_deadline IS NOT NULL AND fm_workorder.tender_deadline > 0" . " AND fm_workorder.tender_deadline <= {$tender_deadline} AND" . " (fm_workorder.tender_received = 0 OR fm_workorder.tender_received IS NULL))"; $where = 'AND'; } if ($inspection_on_completion) { $inspection_on_completion = $inspection_on_completion - 3600 * 8 + phpgwapi_datetime::user_timezone(); $filtermethod .= " {$where} (fm_workorder.tender_deadline IS NOT NULL AND fm_workorder.tender_deadline > 0" . " AND fm_workorder.end_date IS NOT NULL AND fm_workorder.end_date > 0" . " AND fm_workorder.end_date <= {$inspection_on_completion} AND" . " (fm_workorder.inspection_on_completion = 0 OR fm_workorder.inspection_on_completion IS NULL))"; $where = 'AND'; } if ($filter_year && $filter_year != 'all') { $filter_year = (int) $filter_year; $filtermethod .= " {$where} (fm_workorder_budget.year={$filter_year} OR fm_workorder_status.closed IS NULL)"; $where = 'AND'; } $querymethod = ''; if ($query) { $query = $this->db->db_addslashes($query); $query = str_replace(",", '.', $query); if (stristr($query, '.')) { $query = explode(".", $query); $querymethod = " {$where} ({$location_table}.location_code {$this->like} '{$query[0]}%' AND {$location_table}.location_code {$this->like} '%{$query[1]}')"; } else { $matchtypes = array('exact' => '=', 'like' => $this->like); if (count($criteria) > 1) { $_querymethod = array(); foreach ($criteria as $field_info) { if ($field_info['type'] == int) { $_query = (int) $query; } else { if ($field_info['type'] == 'bigint' && !ctype_digit($query)) { $_query = 0; } else { $_query = $query; } } $_querymethod[] = "{$field_info['field']} {$matchtypes[$field_info['matchtype']]} {$field_info['front']}{$_query}{$field_info['back']}"; } $querymethod = $where . ' (' . implode(' OR ', $_querymethod) . ')'; unset($_querymethod); //_debug_array($querymethod); } else { if ($criteria[0]['type'] == 'int') { $_query = (int) $query; } else { if ($criteria[0]['type'] == 'bigint' && !ctype_digit($query)) { $_query = 0; } else { $_query = $query; } } $querymethod = "{$where} {$criteria[0]['field']} {$matchtypes[$criteria[0]['matchtype']]} {$criteria[0]['front']}{$_query}{$criteria[0]['back']}"; } } $where = 'AND'; } $querymethod .= ')'; $sql_full = "{$sql} {$filtermethod} {$querymethod}"; $sql_base = substr($sql_full, strripos($sql_full, 'FROM')); if ($GLOBALS['phpgw_info']['server']['db_type'] == 'postgres') { $sql_minimized = "SELECT DISTINCT fm_workorder.id {$sql_base}"; $sql_count = "SELECT count(id) as cnt FROM ({$sql_minimized}) as t"; $this->db->query($sql_count, __LINE__, __FILE__); $this->db->next_record(); $this->total_records = $this->db->f('cnt'); } else { $sql_count = 'SELECT DISTINCT fm_workorder.id ' . substr($sql_full, strripos($sql_full, 'FROM')); $this->db->query($sql_count, __LINE__, __FILE__); $this->total_records = $this->db->num_rows(); } $workorder_list = array(); if ($dry_run) { return $workorder_list; } $sql_end = str_replace('SELECT DISTINCT fm_workorder.id', "SELECT DISTINCT fm_workorder.id {$order_field}", $sql_minimized) . $ordermethod; // _debug_array($sql_end); if (!$allrows) { $this->db->limit_query($sql_end, $start, __LINE__, __FILE__); } else { $_fetch_single = false; //FIXME: something wrong here... /* if($this->total_records > 200) { $_fetch_single = true; } else { $_fetch_single = false; } */ $this->db->query($sql_end, __LINE__, __FILE__, false, $_fetch_single); unset($_fetch_single); } $count_cols_return = count($cols_return); $_order_list = array(); while ($this->db->next_record()) { $workorder_list[] = array('workorder_id' => $this->db->f('id')); $_order_list[] = $this->db->f('id'); } $this->db->set_fetch_single(false); $_actual_cost_arr = array(); $this->db->query('SELECT id, percent FROM fm_ecomva', __LINE__, __FILE__); $_taxcode = array(0 => 0); while ($this->db->next_record()) { $_taxcode[$this->db->f('id')] = $this->db->f('percent'); } foreach ($workorder_list as &$workorder) { $this->db->query("{$sql} WHERE fm_workorder.id = '{$workorder['workorder_id']}'"); $this->db->next_record(); for ($i = 0; $i < $count_cols_return; $i++) { $workorder[$cols_return[$i]] = $this->db->f($cols_return[$i]); } $workorder['actual_cost'] = 0; $workorder['obligation'] = 0; $workorder['combined_cost'] = 0; $workorder['budget'] = 0; //--------- $workorder['grants'] = (int) $this->grants[$this->db->f('project_owner')]; $location_code = $this->db->f('location_code'); $location = explode('-', $location_code); $count_location = count($location); for ($m = 0; $m < $count_location; $m++) { $workorder['loc' . ($m + 1)] = $location[$m]; $workorder['query_location']['loc' . ($m + 1)] = implode("-", array_slice($location, 0, $m + 1)); } } reset($workorder_list); foreach ($workorder_list as &$workorder) { $order_budget = $this->get_budget($workorder['workorder_id']); foreach ($order_budget as $entry) { if ($entry['active'] == 2) { continue; } if ($filter_year && $filter_year != 'all') { if ($entry['year'] == $filter_year) { $workorder['actual_cost'] += $entry['actual_cost']; $workorder['combined_cost'] += $entry['sum_orders']; $workorder['budget'] += $entry['budget']; $workorder['obligation'] += $entry['sum_oblications']; } } else { $workorder['actual_cost'] += $entry['actual_cost']; if ($entry['active']) { $workorder['combined_cost'] += $entry['sum_orders']; $workorder['budget'] += $entry['budget']; $workorder['obligation'] += $entry['sum_oblications']; } } } $_diff_start = abs($workorder['budget']) > 0 ? $workorder['budget'] : $workorder['combined_cost']; $workorder['diff'] = $_diff_start - $workorder['obligation'] - $workorder['actual_cost']; } return $workorder_list; }
* Based on Webcalendar by Craig Knudsen <*****@*****.**> * * http://www.radix.net/~cknudsen * * Written by Mark Peters <*****@*****.**> * * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ if (!isset($GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents']) || !$GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents']) { return; } $GLOBALS['phpgw']->translation->add_app('calendar'); phpgw::import_class('phpgwapi.datetime'); $GLOBALS['date'] = date('Ymd', phpgwapi_datetime::user_localtime()); $GLOBALS['g_year'] = substr($GLOBALS['date'], 0, 4); $GLOBALS['g_month'] = substr($GLOBALS['date'], 4, 2); $GLOBALS['g_day'] = substr($GLOBALS['date'], 6, 2); $GLOBALS['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; $GLOBALS['css'] = "\n<style type=\"text/css\">\n<!--\n" . "@import url('calendar/templates/base/css/base.css')\n-->\n</style>\n"; $page_ = explode('.', $GLOBALS['phpgw_info']['user']['preferences']['calendar']['defaultcalendar']); $_page = substr($page_[0], 0, 7); // makes planner from planner_{user|category} if ($_page == 'index' || $_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner') { $_page = 'month'; $GLOBALS['phpgw']->preferences->read(); $GLOBALS['phpgw']->preferences->add('calendar', 'defaultcalendar', 'month'); $GLOBALS['phpgw']->preferences->save_repository(); } if (!@file_exists(PHPGW_INCLUDE_ROOT . '/calendar/inc/hook_home_' . $_page . '.inc.php')) {
/**************************************************************************\ * phpGroupWare - Calendar * * http://www.phpgroupware.org * * Based on Webcalendar by Craig Knudsen <*****@*****.**> * * http://www.radix.net/~cknudsen * * Written by Mark Peters <*****@*****.**> * * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ global $calendar_id; $d1 = strtolower(substr($GLOBALS['phpgw_info']['server']['app_inc'], 0, 3)); if ($d1 == 'htt' || $d1 == 'ftp') { echo 'Failed attempt to break in via an old Security Hole!<br />' . "\n"; $phpgw->common->phpgw_exit(); } unset($d1); if ($calendar_id) { $GLOBALS['phpgw']->translation->add_app('calendar'); $cal = CreateObject('calendar.uicalendar'); //echo "Event ID: $calendar_id<br />\n"; phpgw::import_class('phpgwapi.datetime'); if ($event = $cal->bo->read_entry($calendar_id)) { echo $cal->timematrix(array('date' => phpgwapi_datetime::localdates(mktime(0, 0, 0, $event['start']['month'], $event['start']['mday'], $event['start']['year']) - $phpgw->calendar->tz_offset), 'starttime' => $cal->bo->splittime('000000', False), 'endtime' => 0, 'participants' => $event['participants'])) . '</td></tr><tr><td>' . $cal->view_event($event) . '</td></tr><tr><td align="center">' . $cal->get_response($calendar_id); } unset($cal); unset($event); }
public function populate() { $this->set_title(phpgw::get_var('title', 'string')); $this->set_description(phpgw::get_var('description', 'html')); if (phpgw::get_var('start_date', 'string') != '') { $start_date_ts = phpgwapi_datetime::date_to_timestamp(phpgw::get_var('start_date', 'string')); $this->set_start_date($start_date_ts); } else { $this->set_start_date(0); } if (phpgw::get_var('end_date', 'string') != '') { $end_date_ts = phpgwapi_datetime::date_to_timestamp(phpgw::get_var('end_date', 'string')); $this->set_end_date($end_date_ts); } else { $this->set_end_date(0); } $this->set_repeat_type(phpgw::get_var('repeat_type', 'string')); $this->set_repeat_interval(phpgw::get_var('repeat_interval', 'string')); $this->set_procedure_id(phpgw::get_var('procedure_id', 'int')); $this->set_control_area_id(phpgw::get_var('control_area_id', 'int')); $this->set_responsibility_id(phpgw::get_var('responsibility_id', 'int')); }
public function read($dry_run = '') { $start_date = phpgwapi_datetime::date_to_timestamp($this->start_date); $end_date = phpgwapi_datetime::date_to_timestamp($this->end_date); $valid_locations = $this->get_gallery_location(); $values = $this->so->read(array('start' => $this->start, 'query' => $this->query, 'sort' => $this->sort, 'order' => $this->order, 'allrows' => $this->allrows, 'location_id' => $this->location_id, 'user_id' => $this->user_id, 'mime_type' => $this->mime_type, 'start_date' => $start_date, 'end_date' => $end_date, 'cat_id' => $this->cat_id, 'valid_locations' => $valid_locations, 'dry_run' => $dry_run)); $img_types = array('image/jpeg', 'image/png', 'image/gif'); static $locations = array(); static $urls = array(); $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; $i = 0; foreach ($values as &$entry) { if (!$entry['mime_type']) { $entry['mime_type'] = $this->mime_magic->filename2mime($entry['name']); } $entry['img_id'] = ''; if (in_array($entry['mime_type'], $img_types)) { $entry['img_id'] = "img-{$i}"; $i++; } $entry['date'] = $GLOBALS['phpgw']->common->show_date(strtotime($entry['created']), $dateformat); $directory = explode('/', $entry['directory']); $location = $this->get_location($directory); $entry['location'] = $location['location']; $entry['location_item_id'] = $location['location_item_id']; $entry['url'] = $this->interlink->get_relation_link($entry['location'], $entry['location_item_id']); $entry['location_name'] = $this->interlink->get_location_name($entry['location']); $entry['document_url'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uigallery.view_file', 'file' => urlencode("{$entry['directory']}/{$entry['name']}"))); $entry['user'] = $GLOBALS['phpgw']->accounts->get($entry['createdby_id'])->__toString(); } //_debug_array($values); $this->total_records = $this->so->total_records; return $values; }
function add_manual_invoice($values, $skip_update_voucher_id = false) { $orders_affected = array(); $_dateformat = $this->db->date_format(); if (!$this->supertransaction) { $this->db->transaction_begin(); } $num = $this->add($values, $skip_update_voucher_id); $this->voucher_id = $values[0]['bilagsnr']; $voucher = $this->get_voucher($values[0]['bilagsnr']); foreach ($voucher as &$line) { $line['overftid'] = date($_dateformat, phpgwapi_datetime::date_to_timestamp($values[0]['paid_date'])); $line['ordrebelop'] = $line['godkjentbelop']; $line['filnavn'] = 'dummy'; $line['oppsynsigndato'] = date($_dateformat); $line['saksigndato'] = date($_dateformat); $line['budsjettsigndato'] = date($_dateformat); $line['utbetalingsigndato'] = date($_dateformat); $line['utbetalingid'] = $GLOBALS['phpgw']->accounts->get($this->account_id)->lid; $line['manual_record'] = 1; $this->add_OverfBilag($line); } $this->delete_voucher_from_fm_ecobilag($values[0]['bilagsnr']); reset($voucher); if ($this->debug) { return true; } foreach ($voucher as &$line) { if ($line['order_id']) { $amount = $line['godkjentbelop'] * 100; //Oppdater beløp på bestilling if ($line['dimd'] % 2 == 0) { $actual_cost_field = 'act_mtrl_cost'; } else { $actual_cost_field = 'act_vendor_cost'; } $operator = '+'; if (!$this->debug) { //notify_coordinator_on_consumption is performed here.. $this->correct_actual_cost($line['order_id'], $amount, $actual_cost_field, $operator); } } } $this->update_actual_cost_from_archive($orders_affected); if (!$this->supertransaction) { return $this->db->transaction_commit(); } else { return $num; } }
} $refer = explode('.', $GLOBALS['HTTP_GET_VARS']['menuaction']); $referrer = $refer[2]; $templates = array('head_tpl' => 'head.tpl', 'form_button_dropdown' => 'form_button_dropdown.tpl', 'form_button_script' => 'form_button_script.tpl'); $tpl->set_file($templates); $tpl->set_block('head_tpl', 'head', 'head'); $tpl->set_block('head_tpl', 'head_table', 'head_table'); $tpl->set_block('head_tpl', 'head_col', 'head_col'); $tpl->set_block('form_button_script', 'form_button'); if (floor(phpversion()) >= 4) { $tpl->set_var('cols', 8); } else { $tpl->set_var('cols', 7); } phpgw::import_class('phpgwapi.datetime'); $today = date('Ymd', phpgwapi_datetime::user_localtime()); $col_width = 12; add_col($tpl, ' <td width="2%"> </td>'); add_col($tpl, ' <td width="2%">' . add_image_ahref($this->page('day', array('date' => $today)), 'today', lang('Today')) . '</td>'); add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('week', array('date' => $today)), 'week', lang('This week')) . '</td>'); add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('month', array('date' => $today)), 'month', lang('This month')) . '</td>'); add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('year', array('date' => $today)), 'year', lang('This Year')) . '</td>'); if (floor(phpversion()) >= 4) { add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('planner', array('date' => $today)), 'planner', lang('Planner')) . '</td>'); $col_width += 2; } add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('matrixselect'), 'view', lang('Daily Matrix View')) . '</td>'); add_col($tpl, ' <td width="' . (100 - $col_width) . '%" align="left"' . (floor(phpversion()) < 4 ? ' colspan="2"' : '') . '> </td>'); $tpl->parse('row', 'head_table', True); $tpl->set_var('header_column', ''); $tpl->set_var('cols', $cols);
function date_to_timestamp($date) { if ($date) { $date_array = phpgwapi_datetime::date_array($date); $date = mktime(8, 0, 0, $date_array['month'], $date_array['day'], $date_array['year']); } return $date; }
/** * Show project that is overdue * * @return void */ public function home_project_overdue_end_date() { $accound_id = $GLOBALS['phpgw_info']['user']['account_id']; $save_app = $GLOBALS['phpgw_info']['flags']['currentapp']; $GLOBALS['phpgw_info']['flags']['currentapp'] = 'property'; $maxmatches = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] = 5; $prefs = $GLOBALS['phpgw_info']['user']['preferences']; if (isset($prefs['property']['mainscreen_show_project_overdue']) && $prefs['property']['mainscreen_show_project_overdue'] == 'yes') { $soproject = CreateObject('property.soproject'); $values = $soproject->read(array('filter' => $accound_id, 'overdue' => time())); $total_records = $soproject->total_records; $portalbox = CreateObject('phpgwapi.listbox', array('title' => lang('end date delay') . " ({$total_records})", 'primary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'], 'secondary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'], 'tertiary' => $GLOBALS['phpgw_info']['theme']['navbar_bg'], 'width' => '100%', 'outerborderwidth' => '0', 'header_background_image' => $GLOBALS['phpgw']->common->image('phpgwapi', 'bg_filler', '.png', False))); $app_id = $GLOBALS['phpgw']->applications->name2id('property'); if (!isset($GLOBALS['portal_order']) || !in_array($app_id, $GLOBALS['portal_order'])) { $GLOBALS['portal_order'][] = $app_id; } $var = $this->get_controls($app_id); foreach ($var as $key => $value) { // $portalbox->set_controls($key,$value); } foreach ($values as $entry) { $entry['delay'] = ceil(phpgwapi_datetime::get_working_days($entry['end_date'], time())); $portalbox->data[] = array('text' => "Forsinkelse: {$entry['delay']} dager :: prosjekt nr:{$entry['project_id']} :: {$entry['location_code']} :: {$entry['address']}", 'link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiproject.edit', 'id' => $entry['project_id'], 'tab' => 'budget'))); } echo "\n" . '<!-- BEGIN ticket info -->' . "\n<div class='property_tickets' style='padding-left: 10px;'>" . $portalbox->draw() . "</div>\n" . '<!-- END ticket info -->' . "\n"; unset($tts); unset($portalbox); unset($category_name); unset($default_status); } $GLOBALS['phpgw_info']['flags']['currentapp'] = $save_app; $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] = $maxmatches; }
function read_single($workorder_id) { if (!$workorder_id) { return array(); } $contacts = CreateObject('property.sogeneric'); $contacts->get_location_info('vendor', false); $workorder = $this->so->read_single($workorder_id); $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; //Delay; $workorder['tender_delay'] = phpgwapi_datetime::get_working_days($workorder['tender_deadline'], $workorder['tender_received']); $workorder['end_date_delay'] = phpgwapi_datetime::get_working_days($workorder['end_date'], $workorder['inspection_on_completion']); //formtatting $workorder['start_date'] = $GLOBALS['phpgw']->common->show_date($workorder['start_date'], $dateformat); $workorder['end_date'] = $GLOBALS['phpgw']->common->show_date($workorder['end_date'], $dateformat); $workorder['tender_deadline'] = $GLOBALS['phpgw']->common->show_date($workorder['tender_deadline'], $dateformat); $workorder['tender_received'] = $GLOBALS['phpgw']->common->show_date($workorder['tender_received'], $dateformat); $workorder['inspection_on_completion'] = $GLOBALS['phpgw']->common->show_date($workorder['inspection_on_completion'], $dateformat); if (isset($workorder['vendor_id']) && $workorder['vendor_id']) { $custom = createObject('property.custom_fields'); $vendor['attributes'] = $custom->find('property', '.vendor', 0, '', 'ASC', 'attrib_sort', true, true); $vendor = $contacts->read_single(array('id' => $workorder['vendor_id']), $vendor); foreach ($vendor['attributes'] as $attribute) { if ($attribute['name'] == 'org_name') { $workorder['vendor_name'] = $attribute['value']; } if ($attribute['name'] == 'email') { $workorder['vendor_email'] = $attribute['value']; } } } $workorder['b_account_name'] = $this->so->get_b_account_name($workorder['b_account_id']); $config = CreateObject('phpgwapi.config', 'property'); $config->read(); $tax = 1 + $config->config_data['fm_tax'] / 100; $workorder['calculation'] = $workorder['calculation'] * $tax; $vfs = CreateObject('phpgwapi.vfs'); $vfs->override_acl = 1; $workorder['files'] = $vfs->ls(array('string' => "/property/workorder/{$workorder_id}", 'relatives' => array(RELATIVE_NONE))); $vfs->override_acl = 0; $j = count($workorder['files']); for ($i = 0; $i < $j; $i++) { $workorder['files'][$i]['file_name'] = urlencode($workorder['files'][$i]['name']); } $workorder['origin'] = $this->interlink->get_relation('property', '.project.workorder', $workorder_id, 'origin'); $workorder['target'] = $this->interlink->get_relation('property', '.project.workorder', $workorder_id, 'target'); if ($workorder['location_code']) { $solocation = CreateObject('property.solocation', $this->bocommon); $workorder['location_data'] = $solocation->read_single($workorder['location_code']); } if ($workorder['tenant_id'] > 0) { $tenant_data = $this->bocommon->read_single_tenant($workorder['tenant_id']); $workorder['location_data']['tenant_id'] = $workorder['tenant_id']; $workorder['location_data']['contact_phone'] = $tenant_data['contact_phone']; $workorder['location_data']['last_name'] = $tenant_data['last_name']; $workorder['location_data']['first_name'] = $tenant_data['first_name']; } else { unset($workorder['location_data']['tenant_id']); unset($workorder['location_data']['contact_phone']); unset($workorder['location_data']['last_name']); unset($workorder['location_data']['first_name']); } if ($workorder['p_num']) { $soadmin_entity = CreateObject('property.soadmin_entity'); $category = $soadmin_entity->read_single_category($workorder['p_entity_id'], $workorder['p_cat_id']); $workorder['p'][$workorder['p_entity_id']]['p_num'] = $workorder['p_num']; $workorder['p'][$workorder['p_entity_id']]['p_entity_id'] = $workorder['p_entity_id']; $workorder['p'][$workorder['p_entity_id']]['p_cat_id'] = $workorder['p_cat_id']; $workorder['p'][$workorder['p_entity_id']]['p_cat_name'] = $category['name']; } $event_criteria = array('appname' => 'property', 'location' => '.project.workorder', 'location_item_id' => $workorder_id); $events = execMethod('property.soevent.read_at_location', $event_criteria); $workorder['event_id'] = $events ? $events[0]['id'] : ''; return $workorder; }
function save($values) { $document_date = phpgwapi_datetime::date_array($values['document_date']); $values['document_date'] = mktime(2, 0, 0, $document_date['month'], $document_date['day'], $document_date['year']); //_debug_array($values); if ($values['document_id']) { if ($values['document_id'] != 0) { $receipt = $this->so->edit($values); } } else { $receipt = $this->so->add($values); } return $receipt; }
function view_contact($contact_id = '', $contact_type = '', $referer = '') { $contact_id = empty($contact_id) ? phpgw::get_var('ab_id') : $contact_id; $contact_type = $contact_type ? $contact_type : $this->bo->search_contact_type_id($this->bo->get_type_contact($contact_id)); $referer = $referer == '' ? phpgw::get_var('referer') : $referer; $referer = urldecode($referer); if ($contact_type == $this->tab_main_persons) { $type = 'person'; $contacts = $this->bo->get_principal_persons_data($contact_id); $userformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; if ($userformat != $this->bo->bday_internformat) { $contacts['org_name'] = '<a href="' . $contacts['org_link'] . '">' . htmlentities($contacts['org_name'], ENT_QUOTES, 'UTF-8') . '</a>'; unset($contacts['org_link']); $cat_link_url = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'addressbook.uiaddressbook.index', 'section' => 'Persons', 'nonavbar' => $this->nonavbar)); $contacts['per_birthday'] = phpgwapi_datetime::convertDate($contacts['per_birthday'], $this->bo->bday_internformat, $userformat); } } else { if ($contact_type == $this->tab_main_organizations) { $cat_link_url = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'addressbook.uiaddressbook.index', 'section' => 'Organizations', 'nonavbar' => $this->nonavbar)); $type = 'org'; $contacts = $this->bo->get_principal_organizations_data($contact_id); } } if (isset($contacts['tab_extra']) && is_array($contacts['tab_extra'])) { foreach ($contacts['tab_extra'] as $key => $value) { $contacts[$key] = $value; } } $owner = $contacts['owner']; $cats = $contacts['tab_cats']['my_cats']; $access = $contacts['access']; unset($contacts['tab_cats']); unset($contacts['tab_extra']); if (!$this->bo->check_read($contact_id, $owner)) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'addressbook.uiaddressbook.index', 'section' => $contact_type, 'nonavbar' => $this->nonavbar)); } $tmp_cats = array(); foreach ($cats as $key => $cat_id) { if ($cat_id) { $catinfo = $this->cat->return_single(intval($cat_id)); $tmp_cats[] = '<a href="' . $cat_link_url . '&fcat_id=' . $cat_id . '">' . $catinfo[0]['name'] . '</a>'; } } $catname = implode(', ', $tmp_cats); unset($tmp_cats); unset($contacts['contact_id']); unset($contacts['cat_id']); unset($contacts['access']); unset($contacts['owner']); unset($contacts['email']); unset($contacts['wphone']); unset($contacts['load']); unset($contacts['my_cats']); $comms = $this->bo->get_comm_contact_data($contact_id); if (isset($comms[$contact_id]) && is_array($comms[$contact_id])) { $contacts = $contacts + $comms[$contact_id]; $comms_media[] = array_keys($comms[$contact_id]); } else { $comms_media[0] = array(); } $addr = $this->bo->get_addr_contact_data($contact_id, array('addr_pref_val' => 'Y')); if (isset($addr) && isset($addr[0]) && is_array($addr[0])) { unset($addr[0]['contact_id']); unset($addr[0]['key_addr_id']); unset($addr[0]['addr_type']); unset($addr[0]['addr_preferred']); unset($addr[0]['addr_description']); unset($addr[0]['addr_contact_id']); $contacts = array_merge($contacts, $addr[0]); } $others = $this->bo->get_others_contact_data($contact_id); if (is_array($others)) { foreach ($others as $key => $other_data) { $contacts[$other_data['other_name']] = $other_data['other_value']; } } $this->template->set_root(PHPGW_APP_TPL); $this->template->set_file(array('view_t' => 'view.tpl')); $this->template->set_block('view_t', 'view_header', 'view_header'); $this->template->set_block('view_t', 'view_row', 'view_row'); $this->template->set_block('view_t', 'view_footer', 'view_footer'); $this->template->set_block('view_t', 'view_buttons', 'view_buttons'); $GLOBALS['phpgw']->common->phpgw_header(true); $this->template->set_var('lang_viewpref', lang('Address book - view')); $tr_class = ''; $row_cnt = 0; foreach ($contacts as $field => $data) { if ($field != 'org_name') { $data = htmlentities($data, ENT_QUOTES, 'UTF-8'); } $ref = ''; if (!is_numeric($field) && $data != '') { if (in_array($field, $comms_media[0])) { $this->template->set_var('display_col', lang($field)); if (strpos($field, 'email')) { if (isset($GLOBALS['phpgw_info']['user']['apps']['email']) && $GLOBALS['phpgw_info']['user']['apps']['email']) { $ref = '<a href="' . $GLOBALS['phpgw']->link('/email/compose.php', array('to' => urlencode($data))) . '" target="_new">'; } else { $ref = '<a href="mailto:' . $data . '">'; } $data .= '</a>'; } if ($field == 'website') { if (!empty($data) && substr($data, 0, 7) != 'http://') { $data = 'http://' . $data; } $ref = '<a href="' . $data . '" target="_new">'; $data .= '</a>'; } } else { $this->template->set_var('display_col', $this->bo->display_name($field)); } $tr_class = $row_cnt % 2 ? 'row_off' : 'row_on'; $this->template->set_var('tr_class', $tr_class); ++$row_cnt; $this->template->set_var('ref_data', $ref . $data); $this->template->parse('cols', 'view_row', True); } } if ($contact_type == $this->tab_main_organizations) { $persons = $this->bo->get_person_orgs_data($contact_id); if ($persons && is_array($persons)) { $per_link = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'addressbook.uiaddressbook.view_person', 'nonavbar' => $this->nonavbar)); $ppl = array(); foreach ($persons as $per) { if ($per['per_first_name'] || $per['per_last_name']) { $ppl[] = '<a href="' . $per_link . '&ab_id=' . $per['my_person_id'] . '">' . $per['per_first_name'] . ' ' . $per['per_last_name'] . '</a>'; } } $tr_class = $row_cnt % 2 ? 'row_off' : 'row_on'; $this->template->set_var('tr_class', $tr_class); ++$row_cnt; $this->template->set_var('display_col', lang('contacts')); $this->template->set_var('ref_data', implode('<br />', $ppl)); $this->template->parse('cols', 'view_row', True); } } /* Following cleans up view_row, since we were only using it to fill {cols} */ $this->template->set_var('view_row', ''); /* These are in the footer */ if ($row_cnt % 2) { $this->template->set_var(array('access_class' => 'row_on', 'cat_class' => 'row_off', 'owner_class' => 'row_off')); } else { $this->template->set_var(array('access_class' => 'row_off', 'cat_class' => 'row_on', 'owner_class' => 'row_on')); } unset($row_cnt); $this->template->set_var('lang_owner', lang('Record owner')); if (isset($GLOBALS['phpgw_info']['server']['addressmaster']) && $owner == $GLOBALS['phpgw_info']['server']['addressmaster']) { $this->template->set_var('owner', 'addressmaster'); } else { $this->template->set_var('owner', $GLOBALS['phpgw']->common->grab_owner_name($owner)); } $this->template->set_var('lang_access', lang('Record access')); $this->template->set_var('access', $access); $this->template->set_var('lang_category', lang('Category')); $this->template->set_var('catname', $catname); if ($this->bo->check_edit($contact_id)) { $this->template->set_var('edit_button', $this->html_1button_form('edit', 'Edit', $GLOBALS['phpgw']->link('/index.php', array('menuaction' => "addressbook.uiaddressbook.edit_{$type}", 'ab_id' => $contact_id, 'nonavbar' => $this->nonavbar)))); } else { $this->template->set_var('edit_button', ''); } $this->template->set_var('copy_button', $this->html_1button_form('submit', 'copy', $GLOBALS['phpgw']->link('/index.php', array('menuaction' => "addressbook.uiaddressbook.copy_{$type}", 'ab_id' => $contact_id, 'nonavbar' => $this->nonavbar)))); if ($contacts['per_first_name'] && $contacts['per_last_name']) { $this->template->set_var('vcard_button', $this->html_1button_form('VCardForm', 'VCard', $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'addressbook.uivcard.out', 'ab_id' => $contact_id, 'nonavbar' => $this->nonavbar)))); } else { $this->template->set_var('vcard_button', lang('no vcard')); } $this->template->set_var('done_button', $this->html_1button_form('DoneForm', 'Done', isset($referer) && $referer ? $referer : $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'addressbook.uiaddressbook.index', 'action' => $contact_type, 'nonavbar' => $this->nonavbar)))); $this->template->pparse('out', 'view_t'); if ($contact_type == $this->tab_main_persons) { $GLOBALS['phpgw']->hooks->process(array('location' => 'addressbook_view', 'ab_id' => $contact_id)); } }
public function update_receipt($data) { $add_receipt = array(); $delete_receipt = array(); if ($data['events_orig']) { foreach ($data['events_orig'] as $schedule_time_id => $event_id) { if (!$data['events'][$schedule_time_id]) { $delete_receipt[$schedule_time_id] = $event_id; } } } if ($data['events']) { foreach ($data['events'] as $schedule_time_id => $event_id) { if (!$data['events_orig'][$schedule_time_id]) { $add_receipt[$schedule_time_id] = $event_id; } } } $this->_db->transaction_begin(); foreach ($delete_receipt as $schedule_time_id => $event_id) { $schedule = explode('_', $schedule_time_id); $schedule_time = $schedule[1]; $this->_db->query("DELETE FROM fm_event_receipt WHERE receipt_time = {$schedule_time} AND event_id = {$event_id}", __LINE__, __FILE__); $receipt['error'][] = array('msg' => "{$event_id}::{$schedule_time}"); } $entry_date = phpgwapi_datetime::user_localtime(); foreach ($add_receipt as $schedule_time_id => $event_id) { $schedule = explode('_', $schedule_time_id); $schedule_time = $schedule[1]; $vals = array($event_id, $schedule_time, $this->account, $entry_date); $vals = $this->_db->validate_insert($vals); $this->_db->query("INSERT INTO fm_event_receipt (event_id, receipt_time, user_id, entry_date) VALUES ({$vals})", __LINE__, __FILE__); $receipt['message'][] = array('msg' => "{$event_id}::{$schedule_time}"); } $this->_db->transaction_commit(); return $receipt; }
function update_control_serie() { if ($start_date = phpgw::get_var('control_start_date', 'string')) { phpgw::import_class('phpgwapi.datetime'); $start_date = phpgwapi_datetime::date_to_timestamp($start_date); } $so_control = CreateObject('controller.socontrol'); $values = array('ids' => phpgw::get_var('ids', 'int'), 'action' => phpgw::get_var('action', 'string'), 'assigned_to' => phpgw::get_var('control_responsible', 'int'), 'start_date' => $start_date, 'repeat_interval' => phpgw::get_var('repeat_interval', 'int'), 'controle_time' => phpgw::get_var('controle_time', 'float'), 'service_time' => phpgw::get_var('service_time', 'float')); $ret = $so_control->update_control_serie($values); if ($ret) { $result = array('status_kode' => 'ok', 'status' => 'Ok', 'msg' => lang('updated')); } else { $result = array('status_kode' => 'error', 'status' => lang('error'), 'msg' => 'Noe gikk galt'); } return $result; }
/** * Public function for saving a check list * * @param HTTP:: location code, control id, status etc.. (check list details) * @return data array */ function save_check_list() { $check_list_id = phpgw::get_var('check_list_id'); if (!$this->add && !$this->edit) { phpgwapi_cache::message_set('No access', 'error'); $this->redirect(array('menuaction' => 'controller.uicheck_list.edit_check_list', 'check_list_id' => $check_list_id)); } $control_id = phpgw::get_var('control_id', 'int'); $serie_id = phpgw::get_var('serie_id', 'int'); $status = (int) phpgw::get_var('status'); $type = phpgw::get_var('type'); $deadline_date = phpgw::get_var('deadline_date', 'string'); $planned_date = phpgw::get_var('planned_date', 'string'); $completed_date = phpgw::get_var('completed_date', 'string'); $comment = phpgw::get_var('comment', 'string'); $assigned_to = phpgw::get_var('assigned_to', 'int'); $billable_hours = phpgw::get_var('billable_hours', 'float'); $deadline_date_ts = date_converter::date_to_timestamp($deadline_date); $error = false; if ($planned_date != '') { $planned_date_ts = date_converter::date_to_timestamp($planned_date); } else { $planned_date_ts = $deadline_date_ts; } if ($completed_date != '') { $completed_date_ts = phpgwapi_datetime::date_to_timestamp($completed_date); $status = controller_check_list::STATUS_DONE; } else { $completed_date_ts = 0; } if ($check_list_id > 0) { $check_list = $this->so->get_single($check_list_id); if ($status == controller_check_list::STATUS_DONE) { if (!$this->_check_for_required($check_list)) { $this->redirect(array('menuaction' => 'controller.uicheck_list.edit_check_list', 'check_list_id' => $check_list_id)); } } } else { if ($status == controller_check_list::STATUS_DONE) { $status = controller_check_list::STATUS_NOT_DONE; $completed_date_ts = 0; $error_message = "Status kunne ikke settes til utført - prøv igjen"; $error = true; phpgwapi_cache::message_set($error_message, 'error'); } $check_list = new controller_check_list(); $check_list->set_control_id($control_id); $location_code = phpgw::get_var('location_code'); $check_list->set_location_code($location_code); $check_list->set_serie_id($serie_id); if ($type == "component") { $location_id = phpgw::get_var('location_id'); $component_id = phpgw::get_var('component_id'); $check_list->set_location_id($location_id); $check_list->set_component_id($component_id); } } $check_list->set_comment($comment); $check_list->set_deadline($deadline_date_ts); $check_list->set_planned_date($planned_date_ts); $check_list->set_completed_date($completed_date_ts); $orig_assigned_to = $check_list->get_assigned_to(); $check_list->set_assigned_to($assigned_to); $config = CreateObject('phpgwapi.config', 'controller'); $config->read(); $required_actual_hours = isset($config->config_data['required_actual_hours']) && $config->config_data['required_actual_hours'] ? $config->config_data['required_actual_hours'] : false; if ($status == controller_check_list::STATUS_DONE && $required_actual_hours && $check_list->get_billable_hours() == 0 && !$billable_hours) { phpgwapi_cache::message_set(lang("Please enter billable hours"), 'error'); $error = true; } else { $check_list->set_delta_billable_hours($billable_hours); } if ($status == controller_check_list::STATUS_DONE && $this->_check_for_required($check_list) && !$error) { $check_list->set_status($status); } else { if ($status == controller_check_list::STATUS_CANCELED && !$error) { $check_list->set_status($status); } } if (!$error && $check_list->validate()) { $check_list_id = $this->so->store($check_list); $serie = $this->so_control->get_serie($check_list->get_serie_id()); /** * Add an iCal-event if there is a serie - and the checklist is visited the first time - or assigned is changed */ if (phpgw::get_var('request_ical_event', 'bool') && $check_list_id && $serie) { $bocommon = CreateObject('property.bocommon'); $current_prefs_user = $bocommon->create_preferences('property', $GLOBALS['phpgw_info']['user']['account_id']); $from_address = "{$GLOBALS['phpgw_info']['user']['fullname']}<{$current_prefs_user['email']}>"; $from_name = $GLOBALS['phpgw_info']['user']['fullname']; $to_name = $GLOBALS['phpgw']->accounts->id2name($assigned_to); $prefs_target = $bocommon->create_preferences('property', $assigned_to); $to_address = $prefs_target['email']; if (!($start_date = $check_list->get_planned_date())) { $start_date = $check_list->get_deadline(); } $startTime = $start_date + 8 * 3600; $endTime = $startTime + (double) $serie['service_time'] * 3600 + (double) $serie['controle_time'] * 3600; if ($check_list->get_component_id() > 0) { $component_arr = execMethod('property.soentity.read_single_eav', array('location_id' => $check_list->get_location_id(), 'id' => $check_list->get_component_id())); $location_name = execMethod('property.bolocation.get_location_name', $component_arr['location_code']); $short_desc = $location_name . '::' . execMethod('property.soentity.get_short_description', array('location_id' => $check_list->get_location_id(), 'id' => $check_list->get_component_id())); $location = $location_name; } $repeat_type_array = array("0" => lang('day'), "1" => lang('week'), "2" => lang('month'), "3" => lang('year')); $subject = "{$repeat_type_array[$serie['repeat_type']]}/{$serie['repeat_interval']}"; $subject .= "::{$serie['title']}::{$short_desc}"; $link_backend = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'controller.uicheck_list.add_check_list', 'control_id' => $check_list->get_control_id(), 'location_id' => $check_list->get_location_id(), 'component_id' => $check_list->get_component_id(), 'serie_id' => $check_list->get_serie_id(), 'type' => 'component', 'assigned_to' => $check_list->get_assigned_to(), 'deadline_current' => true), false, true, true); $link_mobilefrontend = $GLOBALS['phpgw']->link('/mobilefrontend/index.php', array('menuaction' => 'controller.uicheck_list.add_check_list', 'control_id' => $check_list->get_control_id(), 'location_id' => $check_list->get_location_id(), 'component_id' => $check_list->get_component_id(), 'serie_id' => $check_list->get_serie_id(), 'type' => 'component', 'assigned_to' => $check_list->get_assigned_to(), 'deadline_current' => true), false, true, true); $html_description = "<a href ='{$link_mobilefrontend}'>Serie#" . $check_list->get_serie_id() . '::Mobilefrontend</a><br/><br/>'; $html_description .= "<a href ='{$link_backend}'>Serie#" . $check_list->get_serie_id() . '::Backend</a>'; $_serie_id = $check_list->get_serie_id(); $text_description = str_replace('&', '&', "Serie#{$_serie_id}::Mobilefrontend:\\n{$link_mobilefrontend}\\n\\nSerie#{$_serie_id}::Backend:\\n{$link_backend}"); if ($from_address && $to_address) { $this->sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $html_description, $text_description, $location); } else { phpgwapi_cache::message_set("Mangler epostadresse til avsender eller addresat - eller begge", 'error'); } } if ($check_list_id > 0) { $this->redirect(array('menuaction' => 'controller.uicheck_list.edit_check_list', 'check_list_id' => $check_list_id)); } else { $this->edit_check_list($check_list); } } else { if ($check_list->get_id() > 0) { $this->edit_check_list($check_list); } else { $this->redirect(array('menuaction' => 'controller.uicheck_list.add_check_list', 'control_id' => $control_id, 'location_id' => $location_id, 'component_id' => $component_id, 'serie_id' => $serie_id, 'deadline_ts' => $deadline_date_ts, 'type' => $type, 'assigned_to' => $assigned_to, 'status' => $status)); } } }
function add() { if (!$this->acl_add) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uilocation.stop', 'perm' => 2, 'acl_location' => $this->acl_location)); } $GLOBALS['phpgw_info']['flags']['menu_selection'] .= '::add'; $receipt = $GLOBALS['phpgw']->session->appsession('session_data', 'add_receipt'); if (!$receipt) { $receipt = array(); } if (isset($receipt['voucher_id']) && $receipt['voucher_id']) { $link_receipt = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiinvoice.receipt', 'voucher_id' => $receipt['voucher_id'])); } $GLOBALS['phpgw']->session->appsession('session_data', 'add_receipt', ''); $bolocation = CreateObject('property.bolocation'); $referer = parse_url(phpgw::get_var('HTTP_REFERER', 'string', 'SERVER')); parse_str($referer['query']); // produce $menuaction if (phpgw::get_var('cancel', 'bool') || $menuaction != 'property.uiinvoice.add') { $GLOBALS['phpgw']->session->appsession('session_data', 'add_values', ''); } if (!$GLOBALS['phpgw']->session->appsession('session_data', 'add_values') && phpgw::get_var('add_invoice', 'bool')) { $values['art'] = phpgw::get_var('art', 'int'); $values['type'] = phpgw::get_var('type'); $values['dim_b'] = phpgw::get_var('dim_b', 'int'); $values['invoice_num'] = phpgw::get_var('invoice_num'); $values['kid_nr'] = phpgw::get_var('kid_nr'); $values['vendor_id'] = phpgw::get_var('vendor_id', 'int'); $values['vendor_name'] = phpgw::get_var('vendor_name'); $values['janitor'] = phpgw::get_var('janitor'); $values['supervisor'] = phpgw::get_var('supervisor'); $values['budget_responsible'] = phpgw::get_var('budget_responsible'); $values['invoice_date'] = urldecode(phpgw::get_var('invoice_date')); $values['num_days'] = phpgw::get_var('num_days', 'int'); $values['payment_date'] = urldecode(phpgw::get_var('payment_date')); $values['sday'] = phpgw::get_var('sday', 'int'); $values['smonth'] = phpgw::get_var('smonth', 'int'); $values['syear'] = phpgw::get_var('syear', 'int'); $values['eday'] = phpgw::get_var('eday', 'int'); $values['emonth'] = phpgw::get_var('emonth', 'int'); $values['eyear'] = phpgw::get_var('eyear', 'int'); $values['auto_tax'] = phpgw::get_var('auto_tax', 'bool'); $values['merknad'] = phpgw::get_var('merknad'); $values['b_account_id'] = phpgw::get_var('b_account_id', 'int'); $values['b_account_name'] = phpgw::get_var('b_account_name'); $values['amount'] = phpgw::get_var('amount'); // float - has to accept string until client side validation is in place. if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['currency'])) { $values['amount'] = str_ireplace($GLOBALS['phpgw_info']['user']['preferences']['common']['currency'], '', $values['amount']); } $values['amount'] = str_replace(' ', '', $values['amount']); $values['amount'] = str_replace(',', '.', $values['amount']); $values['order_id'] = phpgw::get_var('order_id'); $insert_record = $GLOBALS['phpgw']->session->appsession('insert_record', 'property'); $values = $this->bocommon->collect_locationdata($values, $insert_record); $GLOBALS['phpgw']->session->appsession('session_data', 'add_values', $values); } else { $values = $GLOBALS['phpgw']->session->appsession('session_data', 'add_values'); $GLOBALS['phpgw']->session->appsession('session_data', 'add_values', ''); } $location_code = phpgw::get_var('location_code'); $debug = phpgw::get_var('debug', 'bool'); $add_invoice = phpgw::get_var('add_invoice', 'bool'); if ($location_code) { $values['location_data'] = $bolocation->read_single($location_code, array('tenant_id' => $tenant_id, 'p_num' => $p_num)); } if ($add_invoice && is_array($values)) { $order = false; if ($values['order_id'] && !ctype_digit($values['order_id'])) { $receipt['error'][] = array('msg' => lang('Please enter an integer for order!')); unset($values['order_id']); } else { if ($values['order_id']) { $order = true; } } if (!$values['amount']) { $receipt['error'][] = array('msg' => lang('Please - enter an amount!')); } if (!$values['art']) { $receipt['error'][] = array('msg' => lang('Please - select type invoice!')); } if (!$values['vendor_id'] && !$order) { $receipt['error'][] = array('msg' => lang('Please - select Vendor!')); } if (!$values['type']) { $receipt['error'][] = array('msg' => lang('Please - select type order!')); } if (!$values['budget_responsible'] && (!isset($order) || !$order)) { $receipt['error'][] = array('msg' => lang('Please - select budget responsible!')); } if (!$values['invoice_num']) { $receipt['error'][] = array('msg' => lang('Please - enter a invoice num!')); } if (!$order && $values['vendor_id']) { if (!$this->bo->check_vendor($values['vendor_id'])) { $receipt['error'][] = array('msg' => lang('That Vendor ID is not valid !') . ' : ' . $values['vendor_id']); } } if (!$values['payment_date'] && !$values['num_days']) { $receipt['error'][] = array('msg' => lang('Please - select either payment date or number of days from invoice date !')); } //_debug_array($values); if (!is_array($receipt['error'])) { if ($values['invoice_date']) { $sdateparts = phpgwapi_datetime::date_array($values['invoice_date']); $values['sday'] = $sdateparts['day']; $values['smonth'] = $sdateparts['month']; $values['syear'] = $sdateparts['year']; unset($sdateparts); $edateparts = phpgwapi_datetime::date_array($values['payment_date']); $values['eday'] = $edateparts['day']; $values['emonth'] = $edateparts['month']; $values['eyear'] = $edateparts['year']; unset($edateparts); } $values['regtid'] = date($GLOBALS['phpgw']->db->datetime_format()); $_receipt = array(); //local errors $receipt = $this->bo->add($values, $debug); if (!$receipt['message'] && $values['order_id'] && !$receipt[0]['spvend_code']) { $_receipt['error'][] = array('msg' => lang('vendor is not defined in order %1', $values['order_id'])); $debug = false; // try again.. if ($receipt[0]['location_code']) { // $values['location_data'] = $bolocation->read_single($receipt['location_code'],array('tenant_id'=>$tenant_id,'p_num'=>$p_num)); } } if ($debug) { $this->debug($receipt); return; } if (!$_receipt['error']) { unset($values); $GLOBALS['phpgw']->session->appsession('session_data', 'add_receipt', $receipt); $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiinvoice.add')); } } else { if ($values['location']) { $location_code = implode("-", $values['location']); $values['location_data'] = $bolocation->read_single($location_code, isset($values['extra']) ? $values['extra'] : ''); } $GLOBALS['phpgw']->session->appsession('session_data', 'add_values', ''); } } if (isset($receipt['voucher_id']) && $receipt['voucher_id']) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiinvoice.list_sub', 'user_lid' => $GLOBALS['phpgw_info']['user']['account_lid'], 'voucher_id' => $receipt['voucher_id'])); } $location_data = $bolocation->initiate_ui_location(array('values' => isset($values['location_data']) ? $values['location_data'] : '', 'type_id' => -1, 'no_link' => false, 'tenant' => false, 'lookup_type' => 'form', 'lookup_entity' => false, 'entity_data' => false)); $b_account_data = $this->bocommon->initiate_ui_budget_account_lookup(array('b_account_id' => isset($values['b_account_id']) ? $values['b_account_id'] : '', 'b_account_name' => isset($values['b_account_name']) ? $values['b_account_name'] : '')); $link_data = array('menuaction' => 'property.uiinvoice.add', 'debug' => true); if ($_receipt) { $receipt = array_merge($receipt, $_receipt); } $msgbox_data = $this->bocommon->msgbox_data($receipt); $GLOBALS['phpgw']->jqcal->add_listener('invoice_date'); $GLOBALS['phpgw']->jqcal->add_listener('payment_date'); $data = array('menu' => $this->bocommon->get_menu(), 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'form_action' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'cancel_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiinvoice.index')), 'lang_cancel' => lang('Cancel'), 'lang_cancel_statustext' => lang('cancel'), 'action_url' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property' . '.uiinvoice.add')), 'tsvfilename' => '', 'lang_add' => lang('add'), 'lang_add_statustext' => lang('click this button to add a invoice'), 'lang_invoice_date' => lang('invoice date'), 'lang_payment_date' => lang('Payment date'), 'lang_no_of_days' => lang('Days'), 'lang_invoice_number' => lang('Invoice Number'), 'lang_invoice_num_statustext' => lang('Enter Invoice Number'), 'lang_select' => lang('Select per button !'), 'lang_kidnr' => lang('KID nr'), 'lang_kid_nr_statustext' => lang('Enter Kid nr'), 'lang_vendor' => lang('Vendor'), 'addressbook_link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uilookup.vendor')), 'lang_invoice_date_statustext' => lang('Enter the invoice date'), 'lang_num_days_statustext' => lang('Enter the payment date or the payment delay'), 'lang_payment_date_statustext' => lang('Enter the payment date or the payment delay'), 'lang_vendor_statustext' => lang('Select the vendor by clicking the button'), 'lang_vendor_name_statustext' => lang('Select the vendor by clicking the button'), 'lang_select_vendor_statustext' => lang('Select the vendor by clicking this button'), 'value_invoice_date' => isset($values['invoice_date']) ? $values['invoice_date'] : '', 'value_payment_date' => isset($values['payment_date']) ? $values['payment_date'] : '', 'value_belop' => isset($values['belop']) ? $values['belop'] : '', 'value_vendor_id' => isset($values['vendor_id']) ? $values['vendor_id'] : '', 'value_vendor_name' => isset($values['vendor_name']) ? $values['vendor_name'] : '', 'value_kid_nr' => isset($values['kid_nr']) ? $values['kid_nr'] : '', 'value_dim_b' => isset($values['dim_b']) ? $values['dim_b'] : '', 'value_invoice_num' => isset($values['invoice_num']) ? $values['invoice_num'] : '', 'value_merknad' => isset($values['merknad']) ? $values['merknad'] : '', 'value_num_days' => isset($values['num_days']) ? $values['num_days'] : '', 'value_amount' => isset($values['amount']) ? $values['amount'] : '', 'value_order_id' => isset($values['order_id']) ? $values['order_id'] : '', 'lang_auto_tax' => lang('Auto TAX'), 'lang_auto_tax_statustext' => lang('Set tax'), 'lang_amount' => lang('Amount'), 'lang_amount_statustext' => lang('Amount of the invoice'), 'lang_order' => lang('Order ID'), 'lang_order_statustext' => lang('Order # that initiated the invoice'), 'lang_art' => lang('Art'), 'art_list' => $this->bo->get_lisfm_ecoart(isset($values['art']) ? $values['art'] : ''), 'select_art' => 'art', 'lang_select_art' => lang('Select Invoice Type'), 'lang_art_statustext' => lang('You have to select type of invoice'), 'lang_type' => lang('Type invoice II'), 'type_list' => $this->bo->get_type_list(isset($values['type']) ? $values['type'] : ''), 'select_type' => 'type', 'lang_no_type' => lang('No type'), 'lang_type_statustext' => lang('Select the type invoice. To do not use type - select NO TYPE'), 'lang_dimb' => lang('Dim B'), 'dimb_list' => $this->bo->select_dimb_list(isset($values['dim_b']) ? $values['dim_b'] : ''), 'select_dimb' => 'dim_b', 'lang_no_dimb' => lang('No Dim B'), 'lang_dimb_statustext' => lang('Select the Dim B for this invoice. To do not use Dim B - select NO DIM B'), 'lang_janitor' => lang('Janitor'), 'janitor_list' => $this->bocommon->get_user_list_right(32, isset($values['janitor']) ? $values['janitor'] : '', '.invoice'), 'select_janitor' => 'janitor', 'lang_no_janitor' => lang('No janitor'), 'lang_janitor_statustext' => lang('Select the janitor responsible for this invoice. To do not use janitor - select NO JANITOR'), 'lang_supervisor' => lang('Supervisor'), 'supervisor_list' => $this->bocommon->get_user_list_right(64, isset($values['supervisor']) ? $values['supervisor'] : '', '.invoice'), 'select_supervisor' => 'supervisor', 'lang_no_supervisor' => lang('No supervisor'), 'lang_supervisor_statustext' => lang('Select the supervisor responsible for this invoice. To do not use supervisor - select NO SUPERVISOR'), 'lang_budget_responsible' => lang('B - responsible'), 'budget_responsible_list' => $this->bocommon->get_user_list_right(128, isset($values['budget_responsible']) ? $values['budget_responsible'] : '', '.invoice'), 'select_budget_responsible' => 'budget_responsible', 'lang_select_budget_responsible' => lang('Select B-Responsible'), 'lang_budget_responsible_statustext' => lang('You have to select a budget responsible for this invoice in order to add the invoice'), 'lang_merknad' => lang('Descr'), 'lang_merknad_statustext' => lang('Descr'), 'location_data' => $location_data, 'b_account_data' => $b_account_data, 'link_receipt' => isset($link_receipt) ? $link_receipt : '', 'lang_receipt' => lang('receipt')); //_debug_array($data); $GLOBALS['phpgw']->xslttpl->add_file(array('invoice')); $appname = lang('Invoice'); $function_msg = lang('Add invoice'); $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg; $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('add' => $data)); // $GLOBALS['phpgw']->xslttpl->pp(); }
/** * Set pending action for items across the system. * * @param array $data array containing string 'appname' - the name of the module being looked up * string 'location' - the location within the module to look up * integer 'id' - id of the referenced item - could possibly be a bigint * integer 'responsible' - the user_id asked for approval * string 'responsible_type' - what type of responsible is asked for action (user,vendor or tenant) * string 'action' - what type of action is pending * string 'remark' - a general remark - if any * integer 'deadline' - unix timestamp if any deadline is given. * * @return integer $reminder number of request for this action */ public function set_pending_action($data = array()) { $appname = $data['appname']; $location = $data['location']; $item_id = $data['id']; //possible bigint $responsible = (int) $data['responsible']; $action = $this->db->db_addslashes($data['action']); $remark = $this->db->db_addslashes($data['remark']); $deadline = (int) $data['deadline']; if (!$item_id) { throw new Exception("No item_id given"); } $responsible_type = isset($data['responsible_type']) && $data['responsible_type'] ? $data['responsible_type'] : 'user'; if (!in_array($responsible_type, $this->valid_responsible_types)) { throw new Exception("'{$responsible_type}' is not a valid responsible_type"); } $sql = "SELECT id FROM fm_action_pending_category WHERE num = '{$action}'"; $this->db->query($sql, __LINE__, __FILE__); $this->db->next_record(); $action_category = $this->db->f('id'); if (!$action_category) { throw new Exception("'{$action}' is not a valid action_type"); } $location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location); if (!$location_id) { throw new Exception("phpgwapi_locations::get_id ({$appname}, {$location}) returned 0"); } $reminder = 1; if ($this->db->get_transaction()) { $this->global_transaction = true; } else { $this->db->transaction_begin(); } $condition = " WHERE location_id = {$location_id}" . " AND item_id = {$item_id}" . " AND responsible = {$responsible}" . " AND action_category = {$action_category}" . " AND action_performed IS NULL" . " AND expired_on IS NULL"; $sql = "SELECT id, reminder FROM fm_action_pending {$condition}"; $this->db->query($sql, __LINE__, __FILE__); $this->db->next_record(); if ($this->db->f('reminder')) { $reminder = $this->db->f('reminder') + 1; $id = $this->db->f('id'); $value_set = array('expired_on' => phpgwapi_datetime::user_localtime(), 'expired_by' => $this->account); if ($deadline > 0) { $value_set['deadline'] = $deadline; } if (isset($data['close']) && $data['close']) { $value_set['action_performed'] = phpgwapi_datetime::user_localtime(); } $value_set = $this->db->validate_update($value_set); $sql = "UPDATE fm_action_pending SET {$value_set} WHERE id = {$id}"; $ok = !!$this->db->query($sql, __LINE__, __FILE__); if (isset($data['close']) && $data['close']) { if (!$this->global_transaction) { $this->db->transaction_commit(); } return $ok; } } //if nothing found - and you want to close if (isset($data['close']) && $data['close']) { return 0; } $values = array($item_id, $location_id, $responsible, $responsible_type, $action_category, phpgwapi_datetime::user_localtime(), $reminder, $deadline, phpgwapi_datetime::user_localtime(), $this->account, $remark); $values = $this->db->validate_insert($values); $sql = "INSERT INTO fm_action_pending (" . "item_id, location_id, responsible, responsible_type," . "action_category, action_requested, reminder, action_deadline," . "created_on, created_by, remark) VALUES ( {$values} {$vals})"; $this->db->query($sql, __LINE__, __FILE__); if (!$this->global_transaction) { $this->db->transaction_commit(); } return $reminder; }
public function bulk_update_status($start_date, $end_date, $status_filter, $status_new, $execute, $type, $user_id = 0, $ids, $paid = false, $closed_orders = false, $ecodimb = 0, $transfer_budget_year = 0, $new_budget = array(), $b_account_id = 0) { if ($transfer_budget_year && $execute && $new_budget) { // echo "<H1> Overføre budsjett for valgte prosjekt/bestillinger til år {$transfer_budget_year} </H1>"; $soworkorder = CreateObject('property.soworkorder'); foreach ($ids as $_id) { if ((int) $new_budget[$_id]['latest_year'] >= (int) $transfer_budget_year) { continue; } switch ($type) { case 'project': try { $this->transfer_budget($_id, $new_budget[$_id], $transfer_budget_year); } catch (Exception $e) { if ($e) { phpgwapi_cache::message_set($e->getMessage(), 'error'); } } break; case 'workorder': try { $soworkorder->transfer_budget($_id, $new_budget[$_id], $transfer_budget_year); } catch (Exception $e) { if ($e) { phpgwapi_cache::message_set($e->getMessage(), 'error'); } } break; default: throw new Exception('property_soproject::bulk_update_status() - not a valid type'); } } // die(); } $start_date = $start_date ? phpgwapi_datetime::date_to_timestamp($start_date) : time(); $start_date -= 3600 * 24; $end_date = $end_date ? phpgwapi_datetime::date_to_timestamp($end_date) : time(); $filter = ''; if ($user_id) { $user_id = (int) $user_id; $filter .= "AND fm_{$type}.user_id = {$user_id}"; } if ($ecodimb) { $ecodimb = (int) $ecodimb; $filter .= "AND fm_{$type}.ecodimb = {$ecodimb}"; } if ($status_filter) { if ($status_filter == 'open') { $filter .= " AND fm_{$type}_status.closed IS NULL"; } else { $filter .= " AND fm_{$type}.status='{$status_filter}' "; } } switch ($type) { case 'project': $sql_budget = "SELECT DISTINCT year, month, active, sum(budget) as amount FROM fm_project_budget WHERE "; $sql_budget .= 'project_id = %d GROUP BY year, month, active ORDER BY year'; if ($closed_orders) { $filter .= " AND fm_open_workorder_view.project_id IS NULL"; } $table = 'fm_project'; $status_table = 'fm_project_status'; $title_field = 'fm_project.name as title'; $this->_update_status_project($execute, $status_new, $ids); $sql = "SELECT DISTINCT {$table}.id,{$status_table}.closed, {$status_table}.descr as status ,{$title_field},{$table}.start_date,{$table}.project_type_id, count(project_id) as num_open FROM {$table}" . " {$this->join} {$status_table} ON {$table}.status = {$status_table}.id " . " {$this->left_join} fm_open_workorder_view ON {$table}.id = fm_open_workorder_view.project_id " . " WHERE ({$table}.start_date > {$start_date} AND {$table}.start_date < {$end_date} OR {$table}.start_date IS NULL) {$filter}" . " GROUP BY {$table}.id, {$status_table}.closed, {$status_table}.descr ,{$table}.name, {$table}.start_date,project_type_id" . " ORDER BY {$table}.id DESC"; break; case 'workorder': $sql_budget = "SELECT DISTINCT year, month, active, sum(combined_cost) as amount FROM fm_workorder_budget WHERE "; $sql_budget .= 'order_id = %d GROUP BY year, month, active ORDER BY year'; if ($b_account_id) { $filter .= " AND fm_workorder.account_id = '{$b_account_id}'"; } $table = 'fm_workorder'; $status_table = 'fm_workorder_status'; $title_field = 'fm_workorder.title'; $actual_cost = ',actual_cost'; $join_method = "{$this->join} {$status_table} ON {$table}.status = {$status_table}.id"; $join_method .= " {$this->join} fm_project ON {$table}.project_id = fm_project.id"; if ($paid) { $join_method .= " {$this->join} fm_orders_actual_cost_view ON fm_workorder.id = fm_orders_actual_cost_view.order_id"; $actual_cost = ',fm_orders_actual_cost_view.actual_cost'; $group_method = ''; } else { $start_period = date('Y') - 1 . '00'; $end_period = date('Y') - 1 . 13; $join_method .= " {$this->left_join} fm_ecobilagoverf ON ( fm_workorder.id = fm_ecobilagoverf.pmwrkord_code AND fm_ecobilagoverf.periode > {$start_period} AND fm_ecobilagoverf.periode < {$end_period})"; $actual_cost = ',sum(fm_ecobilagoverf.godkjentbelop) AS actual_cost'; $group_method = "GROUP BY fm_workorder.id, fm_workorder.project_id, fm_workorder.account_id, fm_workorder_status.closed,fm_workorder_status.descr,fm_project.project_type_id,fm_workorder.title,fm_workorder.start_date,fm_workorder.continuous"; } $this->_update_status_workorder($execute, $status_new, $ids); $sql = "SELECT {$table}.id, {$table}.project_id,{$status_table}.closed, {$table}.account_id, {$status_table}.descr as status ,{$title_field},{$table}.start_date {$actual_cost}," . " project_type_id, continuous" . " FROM {$table} {$join_method}" . " WHERE ({$table}.start_date > {$start_date} AND {$table}.start_date < {$end_date} {$filter}) OR {$table}.start_date is NULL" . " {$group_method} ORDER BY {$table}.id DESC"; break; default: return array(); } $project_types = array(1 => lang('operation'), 2 => lang('investment'), 3 => lang('buffer'), 4 => lang('maintenance')); $this->db->query($sql, __LINE__, __FILE__); $values = array(); $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; while ($this->db->next_record()) { $values[] = array('id' => $this->db->f('id'), 'project_id' => $this->db->f('project_id'), 'closed' => $this->db->f('closed'), 'title' => $this->db->f('title', true), 'status' => $this->db->f('status', true), 'actual_cost' => (double) $this->db->f('actual_cost'), 'start_date' => $GLOBALS['phpgw']->common->show_date($this->db->f('start_date'), $dateformat), 'num_open' => (int) $this->db->f('num_open'), 'project_type_id' => $this->db->f('project_type_id'), 'continuous' => $this->db->f('continuous') ? X : '', 'project_type' => $project_types[$this->db->f('project_type_id')], 'b_account_id' => $this->db->f('account_id')); } foreach ($values as &$entry) { $sql = sprintf($sql_budget, $entry['id']); $this->db->query($sql, __LINE__, __FILE__); $budget = array(); $_budget = array(); $_year = 0; $_active_amount = array(); while ($this->db->next_record()) { $_year = $this->db->f('year'); $_amount = $this->db->f('amount'); $_active = $this->db->f('active') ? X : 0; if ($_active) { $_active_amount[$_year] += $_amount; } $_budget[$_year] += $_amount; } foreach ($_budget as $__year => $__budget) { $budget[] = $__year . ' [' . number_format((int) $_active_amount[$__year], 0, ',', '.') . '/' . number_format((int) $__budget, 0, ',', '.') . ']'; } $entry['budget'] = implode(' ;', $budget); $entry['latest_year'] = $_year; $entry['active_amount'] = array_sum($_active_amount); } return $values; }
function save($project, $action = '', $values_attribute = array()) { //_debug_array($project); while (is_array($project['location']) && (list(, $value) = each($project['location']))) { if ($value) { $location[] = $value; } } $project['location_code'] = implode("-", $location); $project['start_date'] = phpgwapi_datetime::date_to_timestamp($project['start_date']); $project['end_date'] = phpgwapi_datetime::date_to_timestamp($project['end_date']); if (is_array($values_attribute)) { $values_attribute = $this->custom->convert_attribute_save($values_attribute); } // Custom rules - pre commit $criteria = array('appname' => 'property', 'location' => '.project', 'allrows' => true); $custom_functions = $GLOBALS['phpgw']->custom_functions->find($criteria); foreach ($custom_functions as $entry) { // prevent path traversal if (preg_match('/\\.\\./', $entry['file_name'])) { continue; } $file = PHPGW_SERVER_ROOT . "/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}"; if ($entry['active'] && is_file($file) && !$entry['client_side'] && $entry['pre_commit']) { require_once $file; } } unset($entry); reset($custom_functions); if ($action == 'edit') { try { $receipt = $this->so->edit($project, $values_attribute); } catch (Exception $e) { if ($e) { phpgwapi_cache::message_set($e->getMessage(), 'error'); $receipt['id'] = $project['id']; } } if (isset($project['send_order']) && $project['send_order']) { $uiwo_hour = CreateObject('property.uiwo_hour'); foreach ($project['send_order'] as $_order_id) { try { $uiwo_hour->send_order($_order_id); } catch (Exception $e) { if ($e) { phpgwapi_cache::message_set($e->getMessage(), 'error'); } } } } } else { $receipt = $this->so->add($project, $values_attribute); } foreach ($custom_functions as $entry) { // prevent path traversal if (preg_match('/\\.\\./', $entry['file_name'])) { continue; } $file = PHPGW_SERVER_ROOT . "/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}"; if ($entry['active'] && is_file($file) && !$entry['client_side'] && !$entry['pre_commit']) { require_once $file; } } return $receipt; }
/** * Show current date * * @param integer $t Time, defaults to user preferences * @param string $format Date format, defaults to user preferences * @return string Formated date */ public function show_date($t = '', $format = '') { if (!$t || substr(php_uname(), 0, 7) == "Windows" && intval($t) <= 0) { return ''; // return nothing if not valid input // $t = phpgwapi_datetime::gmtnow(); } // + (date('I') == 1?3600:0) $t += phpgwapi_datetime::user_timezone(); if (!$format) { $format = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] . ' - '; if ($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12') { $format .= 'h:i a'; } else { $format .= 'H:i'; } } return date($format, $t); }
public function populate() { $this->set_id(phpgw::get_var('id')); $this->set_activity_id(phpgw::get_var('activity_id')); $this->set_no_of_items(phpgw::get_var('no_of_items')); $this->set_location_id(phpgw::get_var('location_id')); $this->set_create_user(phpgw::get_var('create_user')); if ($this->get_id() == '' | $this->get_id() == 0) { $user_id = $GLOBALS['phpgw_info']['user']['id']; $this->set_create_user($user_id); } if (phpgw::get_var('start_date', 'string') != '') { $start_date_ts = phpgwapi_datetime::date_to_timestamp(phpgw::get_var('start_date', 'string')); $this->set_start_date($start_date_ts); } if (phpgw::get_var('end_date', 'string') != '') { $end_date_ts = phpgwapi_datetime::date_to_timestamp(phpgw::get_var('end_date', 'string')); $this->set_end_date($end_date_ts); } }
private function update_ticket($id, $project, $values_attribute) { $_finnish_date = (int) $project['end_date']; if (!$_finnish_date) { return; } $finnish_date = $_finnish_date; $note = 'FerdigDato er automatisk til prosjekt sluttDato'; if ($project['b_account_id'] == 48) { //search for 2 working day delay for ($i = 2; $i < 10; $i++) { $finnish_date = $_finnish_date + 86400 * $i; $working_days = phpgwapi_datetime::get_working_days($_finnish_date, $finnish_date); if ($working_days == 2) { $note = 'FerdigDato er automatisk oppdatert til 2 virkedager etter prosjekt sluttDato'; break; } } } $this->db->query("SELECT status, finnish_date, finnish_date2 FROM fm_tts_tickets WHERE id='{$id}'", __LINE__, __FILE__); $this->db->next_record(); $status = $this->db->f('status'); /** * Kun oppdatere åpne meldinger */ if ($status == 'X') { return; } $oldfinnish_date = (int) $this->db->f('finnish_date'); $oldfinnish_date2 = (int) $this->db->f('finnish_date2'); $update = false; if ($oldfinnish_date && $finnish_date && $oldfinnish_date2 != $finnish_date) { $this->db->query("UPDATE fm_tts_tickets SET finnish_date2='{$finnish_date}' WHERE id='{$id}'", __LINE__, __FILE__); $old_value = $oldfinnish_date2; $update = true; } else { if (!$oldfinnish_date && $finnish_date && $oldfinnish_date != $finnish_date) { $this->db->query("UPDATE fm_tts_tickets SET finnish_date='{$finnish_date}' , finnish_date2='{$finnish_date}' WHERE id='{$id}'", __LINE__, __FILE__); $old_value = $oldfinnish_date; $update = true; } } if ($update) { $fields_updated = array('finnish_date'); $this->historylog->add('F', $id, $finnish_date, $old_value); $this->historylog->add('C', $id, $note); $this->botts->mail_ticket($id, $fields_updated, $receipt = array(), $project['location_code'], false, true); phpgwapi_cache::message_set(lang('finnish date changed'), 'message'); } }