function __construct()
 {
     phpgwapi_jquery::load_widget('datepicker');
     $theme = 'ui-lightness';
     $GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/jquery/css/{$theme}/jquery-ui-1.8.19.custom.css");
     $this->img_cal = $GLOBALS['phpgw']->common->image('phpgwapi', 'cal');
     $this->dateformat = str_ireplace(array('d', 'm', 'y'), array('dd', 'mm', 'yy'), $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
     $this->lang_select_date = lang('select date');
 }
 function edit($mode = 'edit')
 {
     if ($GLOBALS['phpgw_info']['flags']['nonavbar'] = phpgw::get_var('nonavbar', 'bool')) {
         $GLOBALS['phpgw_info']['flags']['noheader_xsl'] = true;
         $GLOBALS['phpgw_info']['flags']['nofooter'] = true;
     }
     $_lean = phpgw::get_var('lean', 'bool');
     $id = phpgw::get_var('id');
     // in case of bigint
     $selected_tab = phpgw::get_var('tab', 'string', 'REQUEST', 'general');
     if ($mode == 'edit' && (!$this->acl_add && !$this->acl_edit)) {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiworkorder.view', 'id' => $id));
     }
     if ($mode == 'view') {
         if (!$this->acl_read) {
             $this->bocommon->no_access();
             return;
         }
         if (!$id) {
             phpgwapi_cache::message_set('ID is required for the function uiworkorder::view()', 'error');
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiworkorder.index'));
         }
     } else {
         if (!$this->acl_add && !$this->acl_edit) {
             $this->bocommon->no_access();
             return;
         }
     }
     $boproject = CreateObject('property.boproject');
     $bolocation = CreateObject('property.bolocation');
     $config = CreateObject('phpgwapi.config', 'property');
     $location_id = $GLOBALS['phpgw']->locations->get_id('property', $this->acl_location);
     $config->read();
     if ($mode == 'edit') {
         $project_id = phpgw::get_var('project_id', 'int');
         $values = phpgw::get_var('values');
         $values['ecodimb'] = phpgw::get_var('ecodimb');
         $values['vendor_id'] = phpgw::get_var('vendor_id', 'int');
         $values['vendor_name'] = phpgw::get_var('vendor_name', 'string');
         $values['b_account_id'] = phpgw::get_var('b_account_id', 'int');
         $values['b_account_name'] = phpgw::get_var('b_account_name', 'string');
         $values['event_id'] = phpgw::get_var('event_id', 'int');
         $origin = phpgw::get_var('origin');
         $origin_id = phpgw::get_var('origin_id', 'int');
         if ($origin == '.ticket' && $origin_id && !$values['descr']) {
             $boticket = CreateObject('property.botts');
             $ticket = $boticket->read_single($origin_id);
             $values['descr'] = $ticket['details'];
             $values['title'] = $ticket['subject'] ? $ticket['subject'] : $ticket['category_name'];
             $ticket_notes = $boticket->read_additional_notes($origin_id);
             $i = count($ticket_notes) - 1;
             if (isset($ticket_notes[$i]['value_note']) && $ticket_notes[$i]['value_note']) {
                 $values['descr'] .= ": " . $ticket_notes[$i]['value_note'];
             }
             $values['location_data'] = $ticket['location_data'];
         } else {
             if (preg_match("/(^.entity.|^.catch.)/i", $origin) && $origin_id) {
                 $_origin = explode('.', $origin);
                 $_boentity = CreateObject('property.boentity', false, $_origin[1], $_origin[2], $_origin[3]);
                 $_entity = $_boentity->read_single(array('entity_id' => $_origin[2], 'cat_id' => $_origin[3], 'id' => $origin_id, 'view' => true));
                 $values['location_data'] = $_entity['location_data'];
                 unset($_origin);
                 unset($_boentity);
                 unset($_entity);
             } else {
                 if ($origin == '.project.request' && $origin_id) {
                     $_borequest = CreateObject('property.borequest', false);
                     $_request = $_borequest->read_single($origin_id, array(), true);
                     $values['descr'] = $_request['descr'];
                     $values['title'] = $_request['title'];
                     $values['location_data'] = $_request['location_data'];
                     unset($_origin);
                     unset($_borequest);
                     unset($_request);
                 }
             }
         }
         if (isset($values['origin']) && $values['origin']) {
             $origin = $values['origin'];
             $origin_id = $values['origin_id'];
         }
         $interlink =& $this->bo->interlink;
         if (isset($origin) && $origin) {
             unset($values['origin']);
             unset($values['origin_id']);
             $values['origin'][0]['location'] = $origin;
             $values['origin'][0]['descr'] = $interlink->get_location_name($origin);
             $values['origin'][0]['data'][] = array('id' => $origin_id, 'link' => $interlink->get_relation_link(array('location' => $origin), $origin_id));
         }
     }
     if ($project_id && !isset($values['project_id'])) {
         $values['project_id'] = $project_id;
     }
     $project = isset($values['project_id']) ? $boproject->read_single_mini($values['project_id']) : '';
     if (isset($values['save'])) {
         if ($GLOBALS['phpgw']->session->is_repost()) {
             $receipt['error'][] = array('msg' => lang('Hmm... looks like a repost!'));
         }
         if (isset($config->config_data['invoice_acl']) && $config->config_data['invoice_acl'] == 'dimb') {
             if (!$this->acl_manage) {
                 $approve_role = execMethod('property.boinvoice.check_role', $project['ecodimb'] ? $project['ecodimb'] : $values['ecodimb']);
                 if (!$approve_role['is_janitor'] && !$approve_role['is_supervisor'] && !$approve_role['is_budget_responsible']) {
                     $receipt['error'][] = array('msg' => lang('you are not approved for this dimb: %1', $project['ecodimb'] ? $project['ecodimb'] : $values['ecodimb']));
                     $error_id = true;
                 }
                 if (isset($values['approved']) && $values['approved'] && (!isset($values['approved_orig']) || !$values['approved_orig'])) {
                     if (!$approve_role['is_supervisor'] && !$approve_role['is_budget_responsible']) {
                         $receipt['error'][] = array('msg' => lang('you do not have permission to approve this order'));
                         $values['approved'] = false;
                         $error_id = true;
                     }
                 }
             }
         }
         $insert_record = $GLOBALS['phpgw']->session->appsession('insert_record', 'property');
         /*
         				if(isset($insert_record_entity) && is_array($insert_record_entity))
         				{
         					for ($j=0;$j<count($insert_record_entity);$j++)
         					{
         						$insert_record['extra'][$insert_record_entity[$j]]	= $insert_record_entity[$j];
         					}
         				}
         */
         if (is_array($insert_record)) {
             $values = $this->bocommon->collect_locationdata($values, $insert_record);
         }
         if (isset($values['new_project_id']) && $values['new_project_id'] && !$boproject->read_single_mini($values['new_project_id'])) {
             $receipt['error'][] = array('msg' => lang('the project %1 does not exist', $values['new_project_id']));
         }
         if (isset($values['new_project_id']) && $values['new_project_id'] && $values['new_project_id'] == $values['project_id']) {
             unset($values['new_project_id']);
         }
         if (!$values['title']) {
             $receipt['error'][] = array('msg' => lang('Please enter a workorder title !'));
         }
         if (!$values['project_id']) {
             $receipt['error'][] = array('msg' => lang('Please select a valid project !'));
         }
         if (!$values['status']) {
             $receipt['error'][] = array('msg' => lang('Please select a status !'));
         }
         if (isset($config->config_data['workorder_require_vendor']) && $config->config_data['workorder_require_vendor'] == 1 && !$values['vendor_id']) {
             $receipt['error'][] = array('msg' => lang('no vendor'));
         }
         if (!$values['b_account_id']) {
             $receipt['error'][] = array('msg' => lang('Please select a budget account !'));
         } else {
             $_b_account = execMethod('property.bogeneric.read_single', array('id' => $values['b_account_id'], 'location_info' => array('type' => 'budget_account')));
             if (!$_b_account || !$_b_account['active']) {
                 $values['b_account_id'] = '';
                 $values['b_account_name'] = '';
                 $receipt['error'][] = array('msg' => lang('Please select a valid budget account !'));
             }
         }
         if (isset($values['budget']) && $values['budget'] && !ctype_digit(ltrim($values['budget'], '-'))) {
             $receipt['error'][] = array('msg' => lang('budget') . ': ' . lang('Please enter an integer !'));
         }
         if (!$id && (!$values['contract_sum'] && !$values['budget'])) {
             $receipt['error'][] = array('msg' => lang('please enter either a budget or contrakt sum'));
         }
         if (isset($values['addition_rs']) && $values['addition_rs'] && !ctype_digit(ltrim($values['addition_rs'], '-'))) {
             $receipt['error'][] = array('msg' => lang('Rig addition') . ': ' . lang('Please enter an integer !'));
         }
         if (isset($values['cat_id']) && $values['cat_id']) {
             $_category = $this->cats->return_single($values['cat_id']);
             if (!$_category[0]['active']) {
                 $receipt['error'][] = array('msg' => lang('invalid category'));
             }
         }
         if (isset($values['addition_percentage']) && $values['addition_percentage'] && !ctype_digit($values['addition_percentage'])) {
             $receipt['error'][] = array('msg' => lang('Percentage addition') . ': ' . lang('Please enter an integer !'));
         }
         if ($values['approval'] && $values['mail_address'] && $config->config_data['workorder_approval']) {
             if (isset($config->config_data['workorder_approval_status']) && $config->config_data['workorder_approval_status']) {
                 $values['status'] = $config->config_data['workorder_approval_status'];
             }
         }
         if ($id) {
             $values['id'] = $id;
             $action = 'edit';
         }
         if (!$receipt['error']) {
             if ($values['copy_workorder']) {
                 $action = 'add';
             }
             $receipt = $this->bo->save($values, $action);
             if (!$receipt['error']) {
                 $id = $receipt['id'];
             }
             $historylog = CreateObject('property.historylog', 'workorder');
             $function_msg = lang('Edit Workorder');
             //----------files
             $bofiles = CreateObject('property.bofiles');
             if (isset($values['file_action']) && is_array($values['file_action'])) {
                 $bofiles->delete_file("/workorder/{$id}/", $values);
             }
             $values['file_name'] = @str_replace(' ', '_', $_FILES['file']['name']);
             if ($values['file_name']) {
                 $to_file = $bofiles->fakebase . '/workorder/' . $id . '/' . $values['file_name'];
                 if ($bofiles->vfs->file_exists(array('string' => $to_file, 'relatives' => array(RELATIVE_NONE)))) {
                     $receipt['error'][] = array('msg' => lang('This file already exists !'));
                 } else {
                     $bofiles->create_document_dir("workorder/{$id}");
                     $bofiles->vfs->override_acl = 1;
                     if (!$bofiles->vfs->cp(array('from' => $_FILES['file']['tmp_name'], 'to' => $to_file, 'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL)))) {
                         $receipt['error'][] = array('msg' => lang('Failed to upload file !'));
                     }
                     $bofiles->vfs->override_acl = 0;
                 }
             }
             //-----------
             if ($values['approval'] && $values['mail_address'] && $config->config_data['workorder_approval']) {
                 $coordinator_name = $GLOBALS['phpgw_info']['user']['fullname'];
                 $coordinator_email = $GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
                 $subject = lang(Approval) . ": " . $id;
                 $message = '<a href ="' . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiworkorder.edit', 'id' => $id), false, true) . '">' . lang('Workorder %1 needs approval', $id) . '</a>';
                 if (isset($GLOBALS['phpgw_info']['server']['smtp_server']) && $GLOBALS['phpgw_info']['server']['smtp_server']) {
                     if (!is_object($GLOBALS['phpgw']->send)) {
                         $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
                     }
                     $action_params = array('appname' => 'property', 'location' => '.project.workorder', 'id' => $id, 'responsible' => '', 'responsible_type' => 'user', 'action' => 'approval', 'remark' => '', 'deadline' => '');
                     $bcc = '';
                     //$coordinator_email;
                     foreach ($values['mail_address'] as $_account_id => $_address) {
                         if (isset($values['approval'][$_account_id]) && $values['approval'][$_account_id]) {
                             $action_params['responsible'] = $_account_id;
                             $rcpt = $GLOBALS['phpgw']->send->msg('email', $_address, $subject, stripslashes($message), '', $cc, $bcc, $coordinator_email, $coordinator_name, 'html');
                             if ($rcpt) {
                                 $historylog->add('AP', $id, lang('%1 is notified', $_address));
                                 $receipt['message'][] = array('msg' => lang('%1 is notified', $_address));
                             }
                             execMethod('property.sopending_action.set_pending_action', $action_params);
                         }
                     }
                 } else {
                     $receipt['error'][] = array('msg' => lang('SMTP server is not set! (admin section)'));
                 }
             }
             $toarray = array();
             $toarray_sms = array();
             if (isset($receipt['notice_owner']) && is_array($receipt['notice_owner']) && $config->config_data['mailnotification']) {
                 if (!$this->account == $project['coordinator'] && $config->config_data['notify_project_owner']) {
                     $prefs_coordinator = $this->bocommon->create_preferences('property', $project['coordinator']);
                     if (isset($prefs_coordinator['email']) && $prefs_coordinator['email']) {
                         $toarray[] = $prefs_coordinator['email'];
                     }
                 }
             }
             $notify_list = execMethod('property.notify.read', array('location_id' => $location_id, 'location_item_id' => $id));
             $subject = lang('workorder %1 has been edited', $id);
             if (isset($GLOBALS['phpgw_info']['user']['apps']['sms'])) {
                 $sms_text = "{$subject}. \r\n{$GLOBALS['phpgw_info']['user']['fullname']} \r\n{$GLOBALS['phpgw_info']['user']['preferences']['property']['email']}";
                 $sms = CreateObject('sms.sms');
                 foreach ($notify_list as $entry) {
                     if ($entry['is_active'] && $entry['notification_method'] == 'sms' && $entry['sms']) {
                         $sms->websend2pv($this->account, $entry['sms'], $sms_text);
                         $toarray_sms[] = "{$entry['first_name']} {$entry['last_name']}({$entry['sms']})";
                         $receipt['message'][] = array('msg' => lang('%1 is notified', "{$entry['first_name']} {$entry['last_name']}"));
                     }
                 }
                 unset($entry);
                 if ($toarray_sms) {
                     $historylog->add('MS', $id, implode(',', $toarray_sms));
                 }
             }
             reset($notify_list);
             foreach ($notify_list as $entry) {
                 if ($entry['is_active'] && $entry['notification_method'] == 'email' && $entry['email']) {
                     $toarray[] = "{$entry['first_name']} {$entry['last_name']}<{$entry['email']}>";
                 }
             }
             unset($entry);
             if ($toarray) {
                 $to = implode(';', $toarray);
                 $from_name = $GLOBALS['phpgw_info']['user']['fullname'];
                 $from_email = $GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
                 $body = '<a href ="' . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiworkorder.edit', 'id' => $id), false, true) . '">' . lang('workorder %1 has been edited', $id) . '</a>' . "\n";
                 foreach ($receipt['notice_owner'] as $notice) {
                     $body .= $notice . "\n";
                 }
                 $body .= lang('Altered by') . ': ' . $from_name . "\n";
                 $body .= lang('remark') . ': ' . $values['remark'] . "\n";
                 $body = nl2br($body);
                 if (!is_object($GLOBALS['phpgw']->send)) {
                     $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
                 }
                 $returncode = $GLOBALS['phpgw']->send->msg('email', $to, $subject, $body, false, false, false, $from_email, $from_name, 'html');
                 if (!$returncode) {
                     $receipt['error'][] = array('msg' => "uiworkorder::edit: sending message to '{$to}' subject='{$subject}' failed !!!");
                     $receipt['error'][] = array('msg' => $GLOBALS['phpgw']->send->err['desc']);
                 } else {
                     $historylog->add('ON', $id, lang('%1 is notified', $to));
                     $receipt['message'][] = array('msg' => lang('%1 is notified', $to));
                 }
             }
         }
         if (phpgw::get_var('send_workorder', 'bool') && !$receipt['error']) {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiwo_hour.view', 'workorder_id' => $id, 'from' => 'index'));
         }
         if (phpgw::get_var('calculate_workorder', 'bool') && !$receipt['error']) {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiwo_hour.index', 'workorder_id' => $id));
         }
         if (phpgw::get_var('phpgw_return_as') == 'json') {
             if (!$receipt['error']) {
                 $result = array('status' => 'updated');
             } else {
                 $result = array('status' => 'error');
             }
             $result['receipt'] = $receipt;
             return $result;
         }
     }
     if (!isset($receipt['error'])) {
         if ($id) {
             $values = $this->bo->read_single($id);
             if (!isset($values['origin'])) {
                 $values['origin'] = '';
             }
         }
         if ($project_id && !isset($values['project_id'])) {
             $values['project_id'] = $project_id;
         }
         if (!$project && isset($values['project_id']) && $values['project_id']) {
             $project = $boproject->read_single_mini($values['project_id']);
         }
         $acl_required = $mode == 'edit' ? PHPGW_ACL_EDIT : PHPGW_ACL_READ;
         if (!$this->bocommon->check_perms($project['grants'], $acl_required)) {
             $receipt['error'][] = array('msg' => lang('You have no edit right for this project'));
             $GLOBALS['phpgw']->session->appsession('receipt', 'property', $receipt);
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiworkorder.view', 'id' => $id));
         }
         if ($project['key_fetch'] && !$values['key_fetch']) {
             $values['key_fetch'] = $project['key_fetch'];
         }
         if ($project['key_deliver'] && !$values['key_deliver']) {
             $values['key_deliver'] = $project['key_deliver'];
         }
         /*				if( $project['charge_tenant'] && !$id)
         				{
         					$values['charge_tenant']=$project['charge_tenant'];
         				}
          */
         if ($project['start_date'] && !$values['start_date']) {
             if ($project['project_type_id'] == 1) {
                 $values['start_date'] = $GLOBALS['phpgw']->common->show_date(time(), $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
             } else {
                 $values['start_date'] = $project['start_date'];
             }
         }
         $last_day_of_year = mktime(13, 0, 0, 12, 31, date("Y"));
         if ($project['end_date'] && !$values['end_date']) {
             if ($project['project_type_id'] == 1 && isset($config->config_data['delay_operation_workorder_end_date']) && $config->config_data['delay_operation_workorder_end_date'] == 1) {
                 $values['end_date'] = $GLOBALS['phpgw']->common->show_date($last_day_of_year, $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
             } else {
                 $values['end_date'] = $project['end_date'];
             }
         } else {
             if (!$project['end_date'] && !$values['end_date']) {
                 if ($project['project_type_id'] == 1 && isset($config->config_data['delay_operation_workorder_end_date']) && $config->config_data['delay_operation_workorder_end_date'] == 1) {
                     $values['end_date'] = $GLOBALS['phpgw']->common->show_date($last_day_of_year, $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                 } else {
                     $values['end_date'] = $GLOBALS['phpgw']->common->show_date(time(), $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
                 }
             }
         }
         if ($project['name'] && !isset($values['title'])) {
             $values['title'] = $project['name'];
         }
         if ($project['descr'] && !isset($values['descr'])) {
             $values['descr'] = $project['descr'];
         }
     }
     if ($id) {
         $record_history = $this->bo->read_record_history($id);
         //_debug_array($content_budget);die();
     } else {
         $record_history = array();
     }
     if ($id) {
         $function_msg = lang("{$mode} workorder");
     } else {
         $function_msg = lang('Add workorder');
     }
     if (isset($values['cat_id']) && $values['cat_id']) {
         $this->cat_id = $values['cat_id'];
     }
     if (isset($config->config_data['location_at_workorder']) && $config->config_data['location_at_workorder']) {
         $admin_location =& $bolocation->soadmin_location;
         $location_types = $admin_location->select_location_type();
         $max_level = count($location_types);
         $location_level = isset($project['location_data']['location_code']) && $project['inherit_location'] ? count(explode('-', $project['location_data']['location_code'])) : 0;
         $location_template_type = 'form';
         $_location_data = array();
         if (!$values['location_data'] && $origin_id) {
             $location_code = isset($values['location_code']) && $values['location_code'] ? $values['location_code'] : implode("-", $values['location']);
             $values['extra']['view'] = true;
             $values['location_data'] = $bolocation->read_single($location_code, $values['extra']);
         }
         if ($values['location_data']) {
             $_location_data = $values['location_data'];
         } else {
             if (isset($values['location']) && is_array($values['location'])) {
                 $location_code = implode("-", $values['location']);
                 $values['extra']['view'] = true;
                 $_location_data = $bolocation->read_single($location_code, $values['extra']);
             } else {
                 if (isset($project['location_data']) && $project['location_data'] && $project['inherit_location']) {
                     $_location_data = $project['location_data'];
                 }
             }
         }
         if ($mode == 'view') {
             $location_template_type = 'view';
         }
         $location_data = $bolocation->initiate_ui_location(array('values' => $_location_data, 'type_id' => $mode == 'edit' ? $max_level : count(explode('-', $_location_data['location_data']['location_code'])), 'no_link' => false, 'tenant' => true, 'block_parent' => $location_level, 'lookup_type' => $location_template_type, 'lookup_entity' => $this->bocommon->get_lookup_entity('project'), 'entity_data' => isset($values['p']) ? $values['p'] : '', 'filter_location' => $project['inherit_location'] ? $project['location_data']['location_code'] : false));
     } else {
         $location_template_type = 'view';
         $location_data = $bolocation->initiate_ui_location(array('values' => isset($project['location_data']) ? $project['location_data'] : '', 'type_id' => isset($project['location_data']['location_code']) ? count(explode('-', $project['location_data']['location_code'])) : '', 'no_link' => false, 'tenant' => isset($project['location_data']['tenant_id']) ? $project['location_data']['tenant_id'] : '', 'lookup_type' => 'view'));
     }
     if (isset($project['contact_phone'])) {
         for ($i = 0; $i < count($location_data['location']); $i++) {
             if ($location_data['location'][$i]['input_name'] == 'contact_phone') {
                 unset($location_data['location'][$i]['value']);
             }
         }
     }
     $vendor_data = $this->bocommon->initiate_ui_vendorlookup(array('vendor_id' => $values['vendor_id'], 'vendor_name' => $values['vendor_name'], 'type' => $mode));
     $b_group_data = $this->bocommon->initiate_ui_budget_account_lookup(array('b_account_id' => $project['b_account_id'], 'role' => 'group', 'type' => $mode));
     $b_account_data = $this->bocommon->initiate_ui_budget_account_lookup(array('b_account_id' => $values['b_account_id'], 'b_account_name' => $values['b_account_name'], 'disabled' => '', 'parent' => $project['b_account_id'], 'type' => $mode));
     $ecodimb_data = $this->bocommon->initiate_ecodimb_lookup(array('ecodimb' => $project['ecodimb'] ? $project['ecodimb'] : $values['ecodimb'], 'ecodimb_descr' => $values['ecodimb_descr'], 'disabled' => $project['ecodimb'] || $mode == 'view'));
     $event_criteria = array('location' => $this->acl_location, 'name' => 'event_id', 'event_name' => lang('schedule'), 'event_id' => $values['event_id'], 'item_id' => $id, 'type' => $mode);
     $event_data = $this->bocommon->initiate_event_lookup($event_criteria);
     if (isset($event_data['count']) && $event_data['count']) {
         $sum_estimated_cost = $event_data['count'] * $values['calculation'];
     } else {
         $sum_estimated_cost = $values['calculation'];
     }
     $sum_estimated_cost = number_format($sum_estimated_cost, 2, ',', '');
     $values['calculation'] = number_format($values['calculation'], 2, ',', '');
     $link_data = array('menuaction' => 'property.uiworkorder.edit', 'id' => $id);
     $supervisor_email = array();
     if ($need_approval = isset($config->config_data['workorder_approval']) ? $config->config_data['workorder_approval'] : '') {
         $invoice = CreateObject('property.soinvoice');
         if (isset($config->config_data['invoice_acl']) && $config->config_data['invoice_acl'] == 'dimb') {
             $sodimb_role_users = execMethod('property.sodimb_role_user.read', array('dimb_id' => $values['ecodimb'], 'role_id' => 2, 'query_start' => date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), 'get_netto_list' => true));
             if (isset($sodimb_role_users[$values['ecodimb']][2]) && is_array($sodimb_role_users[$values['ecodimb']][2])) {
                 foreach ($sodimb_role_users[$values['ecodimb']][2] as $supervisor_id => $entry) {
                     $prefs = $this->bocommon->create_preferences('property', $supervisor_id);
                     $supervisor_email[] = array('id' => $supervisor_id, 'address' => $prefs['email'], 'default' => $entry['default_user']);
                 }
             }
             //					$supervisor_id = $invoice->get_default_dimb_role_user(2, $values['ecodimb']);
             $supervisor2_id = $invoice->get_default_dimb_role_user(3, $values['ecodimb']);
             $prefs2 = $this->bocommon->create_preferences('property', $supervisor2_id);
             $supervisor_email[] = array('id' => $supervisor2_id, 'address' => $prefs2['email']);
             unset($prefs);
             unset($prefs2);
             unset($invoice);
         } else {
             $supervisor_id = 0;
             if (isset($GLOBALS['phpgw_info']['user']['preferences']['property']['approval_from']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['approval_from']) {
                 $supervisor_id = $GLOBALS['phpgw_info']['user']['preferences']['property']['approval_from'];
             }
             if ($supervisor_id) {
                 $prefs = $this->bocommon->create_preferences('property', $supervisor_id);
                 $supervisor_email[] = array('id' => $supervisor_id, 'address' => $prefs['email']);
                 if (isset($prefs['approval_from'])) {
                     $prefs2 = $this->bocommon->create_preferences('property', $prefs['approval_from']);
                     if (isset($prefs2['email'])) {
                         $supervisor_email[] = array('id' => $prefs['approval_from'], 'address' => $prefs2['email']);
                         $supervisor_email = array_reverse($supervisor_email);
                     }
                     unset($prefs2);
                 }
                 unset($prefs);
             }
         }
     }
     $workorder_status = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['workorder_status']) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['workorder_status'] : '';
     if (!$values['status']) {
         $values['status'] = $workorder_status;
     }
     $GLOBALS['phpgw']->jqcal->add_listener('values_start_date');
     $GLOBALS['phpgw']->jqcal->add_listener('values_end_date');
     $GLOBALS['phpgw']->jqcal->add_listener('values_tender_deadline');
     $GLOBALS['phpgw']->jqcal->add_listener('values_tender_received');
     $GLOBALS['phpgw']->jqcal->add_listener('values_inspection_on_completion');
     if (isset($receipt) && is_array($receipt)) {
         $msgbox_data = $this->bocommon->msgbox_data($receipt);
     } else {
         $msgbox_data = '';
     }
     $link_file_data = array('menuaction' => 'property.uiworkorder.view_file', 'id' => $id);
     $categories = $this->cats->formatted_xslt_list(array('selected' => $project['cat_id']));
     $datavalues[0] = array('name' => "0", 'values' => json_encode($record_history), 'total_records' => count($record_history), 'edit_action' => "''", 'is_paginator' => 0, 'footer' => 0);
     $myColumnDefs[0] = array('name' => "0", 'values' => json_encode(array(array('key' => 'value_date', 'label' => lang('Date'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_user', 'label' => lang('User'), 'Action' => true, 'resizeable' => true), array('key' => 'value_action', 'label' => lang('Action'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_old_value', 'label' => lang('old value'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_new_value', 'label' => lang('New Value'), 'sortable' => true, 'resizeable' => true))));
     $link_to_files = isset($config->config_data['files_url']) ? $config->config_data['files_url'] : '';
     $link_view_file = $GLOBALS['phpgw']->link('/index.php', $link_file_data);
     for ($z = 0; $z < count($values['files']); $z++) {
         if ($link_to_files) {
             $content_files[$z]['file_name'] = '<a href="' . $link_to_files . '/' . $values['files'][$z]['directory'] . '/' . $values['files'][$z]['file_name'] . '" target="_blank" title="' . lang('click to view file') . '">' . $values['files'][$z]['name'] . '</a>';
         } else {
             $content_files[$z]['file_name'] = '<a href="' . $link_view_file . '&amp;file_name=' . $values['files'][$z]['file_name'] . '" target="_blank" title="' . lang('click to view file') . '">' . $values['files'][$z]['name'] . '</a>';
         }
         $content_files[$z]['delete_file'] = '<input type="checkbox" name="values[file_action][]" value="' . $values['files'][$z]['name'] . '" title="' . lang('Check to delete file') . '">';
     }
     $datavalues[1] = array('name' => "1", 'values' => json_encode($content_files), 'total_records' => count($content_files), 'edit_action' => "''", 'is_paginator' => 0, 'footer' => 0);
     $myColumnDefs[1] = array('name' => "1", 'values' => json_encode(array(array('key' => 'file_name', 'label' => lang('Filename'), 'sortable' => false, 'resizeable' => true), array('key' => 'delete_file', 'label' => lang('Delete file'), 'sortable' => false, 'resizeable' => true))));
     $invoices = array();
     if ($id) {
         $active_invoices = execMethod('property.soinvoice.read_invoice_sub_sum', array('order_id' => $id));
         $historical_invoices = execMethod('property.soinvoice.read_invoice_sub_sum', array('order_id' => $id, 'paid' => true));
         $invoices = array_merge($active_invoices, $historical_invoices);
     }
     $content_invoice = array();
     foreach ($invoices as $entry) {
         $content_invoice[] = array('voucher_id' => $entry['transfer_time'] ? -1 * $entry['voucher_id'] : $entry['voucher_id'], 'voucher_out_id' => $entry['voucher_out_id'], 'status' => $entry['status'], 'period' => $entry['period'], 'periodization' => $entry['periodization'], 'periodization_start' => $entry['periodization_start'], 'invoice_id' => $entry['invoice_id'], 'budget_account' => $entry['budget_account'], 'dima' => $entry['dima'], 'dimb' => $entry['dimb'], 'dimd' => $entry['dimd'], 'type' => $entry['type'], 'amount' => $entry['amount'], 'approved_amount' => $entry['approved_amount'], 'vendor' => $entry['vendor'], 'project_group' => $entry['project_id'], 'currency' => $entry['currency'], 'budget_responsible' => $entry['budget_responsible'], 'budsjettsigndato' => $entry['budsjettsigndato'] ? $GLOBALS['phpgw']->common->show_date(strtotime($entry['budsjettsigndato']), $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) : '', 'transfer_time' => $entry['transfer_time'] ? $GLOBALS['phpgw']->common->show_date(strtotime($entry['transfer_time']), $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) : '');
     }
     //_debug_array($content_invoice);
     $datavalues[2] = array('name' => "2", 'values' => json_encode($content_invoice), 'total_records' => count($content_invoice), 'edit_action' => json_encode($GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiinvoice.index'))), 'is_paginator' => 1, 'footer' => 0);
     $_formatter_voucher_link = isset($config->config_data['invoicehandler']) && $config->config_data['invoicehandler'] == 2 ? 'YAHOO.widget.DataTable.formatLink_invoicehandler_2' : 'YAHOO.widget.DataTable.formatLink';
     if ($_lean) {
         $_formatter_voucher_link = '""';
     }
     $myColumnDefs[2] = array('name' => "2", 'values' => json_encode(array(array('key' => 'voucher_id', 'label' => lang('bilagsnr'), 'sortable' => false, 'resizeable' => true, 'formatter' => $_formatter_voucher_link), array('key' => 'voucher_out_id', 'hidden' => true), array('key' => 'invoice_id', 'label' => lang('invoice number'), 'sortable' => false, 'resizeable' => true), array('key' => 'vendor', 'label' => lang('vendor'), 'sortable' => false, 'resizeable' => true), array('key' => 'amount', 'label' => lang('amount'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterRight'), array('key' => 'approved_amount', 'label' => lang('approved amount'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterRight'), array('key' => 'period', 'label' => lang('period'), 'sortable' => false, 'resizeable' => true), array('key' => 'periodization', 'label' => lang('periodization'), 'sortable' => false, 'resizeable' => true), array('key' => 'periodization_start', 'label' => lang('periodization start'), 'sortable' => false, 'resizeable' => true), array('key' => 'currency', 'label' => lang('currency'), 'sortable' => false, 'resizeable' => true), array('key' => 'type', 'label' => lang('type'), 'sortable' => false, 'resizeable' => true), array('key' => 'budget_responsible', 'label' => lang('budget responsible'), 'sortable' => false, 'resizeable' => true), array('key' => 'budsjettsigndato', 'label' => lang('budsjettsigndato'), 'sortable' => false, 'resizeable' => true), array('key' => 'transfer_time', 'label' => lang('transfer time'), 'sortable' => false, 'resizeable' => true))));
     $notify_info = execMethod('property.notify.get_yui_table_def', array('location_id' => $location_id, 'location_item_id' => $id, 'count' => count($myColumnDefs)));
     $datavalues[] = $notify_info['datavalues'];
     $myColumnDefs[] = $notify_info['column_defs'];
     $myButtons = array();
     if ($mode == 'edit') {
         $myButtons[] = $notify_info['buttons'];
     }
     $myColumnDefs[] = array('name' => "4", 'values' => json_encode(array(array('key' => 'value_email', 'label' => lang('email'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_select', 'label' => lang('select'), 'sortable' => false, 'resizeable' => true))));
     $content_email = execMethod('property.bocommon.get_vendor_email', isset($values['vendor_id']) ? $values['vendor_id'] : 0);
     if (isset($values['mail_recipients']) && is_array($values['mail_recipients'])) {
         $_recipients_found = array();
         foreach ($content_email as &$vendor_email) {
             if (in_array($vendor_email['value_email'], $values['mail_recipients'])) {
                 $vendor_email['value_select'] = str_replace("type='checkbox'", "type='checkbox' checked='checked'", $vendor_email['value_select']);
                 $_recipients_found[] = $vendor_email['value_email'];
             }
         }
         $value_extra_mail_address = implode(',', array_diff($values['mail_recipients'], $_recipients_found));
     }
     $datavalues[] = array('name' => "4", 'values' => json_encode($content_email), 'total_records' => count($content_email), 'permission' => "''", 'is_paginator' => 0, 'edit_action' => "''", 'footer' => 0);
     //---------
     $content_budget = $this->bo->get_budget($id);
     $lang_delete = lang('Check to delete period');
     $lang_close = lang('Check to close period');
     $lang_active = lang('Check to activate period');
     $lang_fictive = lang('fictive');
     $rows_per_page = 10;
     $initial_page = 1;
     if ($content_budget && $project['periodization_id']) {
         $_year_count = array();
         foreach ($content_budget as $key => $row) {
             $_year_count[$row['year']] += 1;
             $rows_per_page = $_year_count[$row['year']];
         }
         $initial_page = floor(count($content_budget) / $rows_per_page);
     }
     foreach ($content_budget as &$b_entry) {
         $checked = $b_entry['active'] ? 'checked="checked"' : '';
         $b_entry['flag_active'] = $b_entry['active'] == 1;
         if ($b_entry['fictive']) {
             $b_entry['delete_period'] = $lang_fictive;
             $disabled = 'disabled="disabled"';
         } else {
             $b_entry['delete_period'] = "<input type='checkbox' name='values[delete_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_delete}'>";
         }
         if ($b_entry['active'] == 2) {
             $b_entry['month'] = 'Split';
             $b_entry['closed'] = 'Split';
         } else {
             $b_entry['closed'] = $b_entry['closed'] ? 'X' : '';
         }
         $b_entry['active'] = "<input type='checkbox' name='values[active_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_active}' {$checked} {$disabled}>";
         $b_entry['active_orig'] = "<input type='checkbox' name='values[active_orig_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' {$checked} {$disabled}>";
     }
     unset($b_entry);
     $datavalues[] = array('name' => "5", 'values' => json_encode($content_budget), 'total_records' => count($content_budget), 'edit_action' => "''", 'is_paginator' => 1, 'rows_per_page' => $rows_per_page, 'initial_page' => $initial_page, 'footer' => 0);
     $myColumnDefs[] = array('name' => "5", 'values' => json_encode(array(array('key' => 'year', 'label' => lang('year'), 'sortable' => false, 'resizeable' => true), array('key' => 'month', 'label' => lang('month'), 'sortable' => false, 'resizeable' => true), array('key' => 'budget', 'label' => lang('budget'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'sum_orders', 'label' => lang('order'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'sum_oblications', 'label' => lang('sum orders'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'actual_cost', 'label' => lang('actual cost'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'diff', 'label' => lang('difference'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'deviation_period', 'label' => lang('deviation'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'deviation_acc', 'label' => lang('deviation') . '::' . lang('accumulated'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'deviation_percent_period', 'label' => lang('deviation') . '::' . lang('percent'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount2'), array('key' => 'deviation_percent_acc', 'label' => lang('percent') . '::' . lang('accumulated'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount2'), array('key' => 'closed', 'label' => lang('closed'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'), array('key' => 'active', 'label' => lang('active'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'), array('key' => 'active_orig', 'hidden' => true), array('key' => 'flag_active', 'hidden' => true), array('key' => 'delete_period', 'label' => lang('Delete'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'))));
     //---------
     $link_claim = '';
     if (isset($values['charge_tenant']) ? $values['charge_tenant'] : '') {
         $claim = execMethod('property.sotenant_claim.read', array('project_id' => $project['project_id']));
         if ($claim) {
             $link_claim = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uitenant_claim.edit', 'claim_id' => $claim[0]['claim_id']));
         } else {
             $link_claim = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uitenant_claim.check', 'project_id' => $project['project_id']));
         }
     }
     $_cat_sub = $this->cats->return_sorted_array($start = 0, $limit = false, $query = '', $sort = '', $order = '', $globals = False, false);
     $selected_cat = $values['cat_id'] ? $values['cat_id'] : $project['cat_id'];
     $cat_sub = array();
     foreach ($_cat_sub as $entry) {
         if ($entry['active'] == 2 && $entry['id'] != $selected_cat) {
             continue;
         }
         $entry['name'] = str_repeat(' . ', (int) $entry['level']) . $entry['name'];
         $entry['title'] = $entry['description'];
         $cat_sub[] = $entry;
     }
     $suppresscoordination = isset($config->config_data['project_suppresscoordination']) && $config->config_data['project_suppresscoordination'] ? 1 : '';
     $user_list = $this->bocommon->get_user_list('select', isset($values['user_id']) && $values['user_id'] ? $values['user_id'] : $this->account, false, false, -1, false, false, '', -1);
     foreach ($user_list as &$user) {
         $user['id'] = $user['user_id'];
     }
     $value_coordinator = isset($project['coordinator']) ? $GLOBALS['phpgw']->accounts->get($project['coordinator'])->__toString() : $GLOBALS['phpgw']->accounts->get($this->account)->__toString();
     $year = date('Y') - 1;
     $limit = $year + 8;
     while ($year < $limit) {
         $year_list[] = array('id' => $year, 'name' => $year);
         $year++;
     }
     if (isset($receipt['error']) && $receipt['error']) {
         $year_list = $this->bocommon->select_list($_POST['values']['budget_year'], $year_list);
     }
     $sogeneric = CreateObject('property.sogeneric');
     $sogeneric->get_location_info('periodization', false);
     $periodization_data = $sogeneric->read_single(array('id' => (int) $project['periodization_id']), array());
     $property_js = "/property/js/yahoo/property2.js";
     if (!isset($GLOBALS['phpgw_info']['server']['no_jscombine']) || !$GLOBALS['phpgw_info']['server']['no_jscombine']) {
         $cachedir = urlencode($GLOBALS['phpgw_info']['server']['temp_dir']);
         $property_js = "/phpgwapi/inc/combine.php?cachedir={$cachedir}&type=javascript&files=" . str_replace('/', '--', ltrim($property_js, '/'));
     }
     $data = array('property_js' => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . $property_js), 'periodization_data' => $periodization_data, 'year_list' => array('options' => $year_list), 'mode' => $mode, 'value_coordinator' => $value_coordinator, 'event_data' => $event_data, 'link_claim' => $link_claim, 'lang_claim' => lang('claim'), 'suppressmeter' => isset($config->config_data['project_suppressmeter']) && $config->config_data['project_suppressmeter'] ? 1 : '', 'suppresscoordination' => $suppresscoordination, 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'myButtons' => $myButtons, 'tabs' => self::_generate_tabs(array(), array('documents' => $id ? false : true, 'history' => $id ? false : true), $selected_tab), 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'value_origin' => isset($values['origin']) ? $values['origin'] : '', 'value_origin_type' => isset($origin) ? $origin : '', 'value_origin_id' => isset($origin_id) ? $origin_id : '', 'lang_calculate' => lang('Calculate Workorder'), 'lang_calculate_statustext' => lang('Calculate workorder by adding items from vendors prizebook or adding general hours'), 'lang_send' => $this->bo->order_sent_adress ? lang('ReSend Workorder') : lang('Send Workorder'), 'lang_send_statustext' => lang('send this workorder to vendor'), 'project_link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiproject.edit')), 'b_group_data' => $b_group_data, 'b_account_data' => $b_account_data, 'value_start_date' => $values['start_date'], 'value_end_date' => $values['end_date'], 'value_tender_deadline' => $values['tender_deadline'], 'value_tender_received' => $values['tender_received'], 'value_tender_delay' => $values['tender_delay'], 'value_inspection_on_completion' => $values['inspection_on_completion'], 'value_end_date_delay' => $values['end_date_delay'], 'lang_copy_workorder' => lang('Copy workorder ?'), 'lang_copy_workorder_statustext' => lang('Choose Copy Workorder to copy this workorder to a new workorder'), 'lang_contact_phone' => lang('Contact phone'), 'contact_phone' => isset($project['contact_phone']) ? $project['contact_phone'] : '', 'lang_charge_tenant' => lang('Charge tenant'), 'lang_charge_tenant_statustext' => lang('Choose charge tenant if the tenant i to pay for this project'), 'charge_tenant' => isset($values['charge_tenant']) ? $values['charge_tenant'] : '', 'lang_power_meter' => lang('Power meter'), 'lang_power_meter_statustext' => lang('Enter the power meter'), 'value_power_meter' => isset($project['power_meter']) ? $project['power_meter'] : '', 'lang_addition_rs' => lang('Rig addition'), 'lang_addition_rs_statustext' => lang('Enter any round sum addition per order'), 'value_addition_rs' => isset($values['addition_rs']) ? $values['addition_rs'] : '', 'lang_addition_percentage' => lang('Percentage addition'), 'lang_addition_percentage_statustext' => lang('Enter any persentage addition per unit'), 'value_addition_percentage' => isset($values['addition_percentage']) ? $values['addition_percentage'] : '', 'lang_budget' => lang('Budget'), 'value_budget' => isset($receipt['error']) && $receipt['error'] ? $_POST['values']['budget'] : '', 'lang_budget_statustext' => lang('Enter the budget'), 'lang_incl_tax' => lang('incl tax'), 'lang_calculation' => lang('Calculation'), 'value_calculation' => isset($values['calculation']) ? $values['calculation'] : '', 'value_sum_estimated_cost' => $sum_estimated_cost, 'value_contract_sum' => isset($receipt['error']) && $receipt['error'] ? $_POST['values']['contract_sum'] : '', 'ecodimb_data' => $ecodimb_data, 'vendor_data' => $vendor_data, 'location_data' => $location_data, 'location_template_type' => $location_template_type, 'form_action' => $mode == 'edit' ? $GLOBALS['phpgw']->link('/index.php', $link_data) : $GLOBALS['phpgw']->link('/home.php'), 'done_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiworkorder.index')), 'lang_year' => lang('Year'), 'lang_save' => lang('save'), 'lang_done' => lang('done'), 'lang_title' => lang('Title'), 'value_title' => $values['title'], 'lang_project_name' => lang('Project name'), 'value_project_name' => isset($project['name']) ? $project['name'] : '', 'lang_project_id' => lang('Project ID'), 'value_project_id' => $values['project_id'], 'lang_workorder_id' => lang('Workorder ID'), 'value_workorder_id' => isset($id) ? $id : '', 'lang_title_statustext' => lang('Enter Workorder title'), 'lang_other_branch' => lang('Other branch'), 'lang_other_branch_statustext' => lang('Enter other branch if not found in the list'), 'value_other_branch' => isset($project['other_branch']) ? $project['other_branch'] : '', 'lang_descr_statustext' => lang('Enter a short description of the workorder'), 'lang_descr' => lang('Description'), 'value_descr' => $values['descr'], 'lang_remark_statustext' => lang('Enter a remark to add to the history of the order'), 'lang_remark' => lang('remark'), 'value_remark' => isset($values['remark']) ? $values['remark'] : '', 'lang_done_statustext' => lang('Back to the list'), 'lang_save_statustext' => lang('Save the workorder'), 'lang_cat_sub' => lang('category'), 'cat_sub_list' => $this->bocommon->select_list($selected_cat, $cat_sub), 'cat_sub_name' => 'values[cat_id]', 'lang_cat_sub_statustext' => lang('select sub category'), 'sum_workorder_budget' => isset($values['sum_workorder_budget']) ? $values['sum_workorder_budget'] : '', 'workorder_budget' => isset($values['workorder_budget']) ? $values['workorder_budget'] : '', 'lang_coordinator' => lang('Coordinator'), 'lang_sum' => lang('Sum'), 'select_user_name' => 'values[coordinator]', 'user_list' => array('options' => $user_list), 'status_list' => $this->bo->select_status_list('select', $values['status']), 'status_name' => 'values[status]', 'lang_no_status' => lang('Select status'), 'lang_status' => lang('Status'), 'lang_status_statustext' => lang('What is the current status of this workorder ?'), 'lang_confirm_status' => lang('Confirm status'), 'lang_confirm_statustext' => lang('Confirm status to the history'), 'branch_list' => $boproject->select_branch_p_list($project['project_id']), 'lang_branch' => lang('branch'), 'lang_branch_statustext' => lang('Select the branches for this project'), 'key_responsible_list' => $boproject->select_branch_list($project['key_responsible']), 'lang_key_responsible' => lang('key responsible'), 'key_fetch_list' => $this->bo->select_key_location_list(isset($values['key_fetch']) ? $values['key_fetch'] : ''), 'lang_no_key_fetch' => lang('Where to fetch the key'), 'lang_key_fetch' => lang('key fetch location'), 'lang_key_fetch_statustext' => lang('Select where to fetch the key'), 'key_deliver_list' => $this->bo->select_key_location_list(isset($values['key_deliver']) ? $values['key_deliver'] : ''), 'lang_no_key_deliver' => lang('Where to deliver the key'), 'lang_key_deliver' => lang('key deliver location'), 'lang_key_deliver_statustext' => lang('Select where to deliver the key'), 'value_approved' => isset($values['approved']) ? $values['approved'] : '', 'value_continuous' => isset($values['continuous']) ? $values['continuous'] : '', 'value_fictive_periodization' => isset($values['fictive_periodization']) ? $values['fictive_periodization'] : '', 'need_approval' => $need_approval, 'lang_ask_approval' => lang('Ask for approval'), 'lang_ask_approval_statustext' => lang('Check this to send a mail to your supervisor for approval'), 'value_approval_mail_address' => $supervisor_email, 'currency' => $GLOBALS['phpgw_info']['user']['preferences']['common']['currency'], 'link_view_file' => $GLOBALS['phpgw']->link('/index.php', $link_file_data), 'link_to_files' => isset($config->config_data['files_url']) ? $config->config_data['files_url'] : '', 'files' => isset($values['files']) ? $values['files'] : '', 'lang_files' => lang('files'), 'lang_filename' => lang('Filename'), 'lang_file_action' => lang('Delete file'), 'lang_view_file_statustext' => lang('click to view file'), 'lang_file_action_statustext' => lang('Check to delete file'), 'lang_upload_file' => lang('Upload file'), 'lang_file_statustext' => lang('Select file to upload'), 'value_billable_hours' => $values['billable_hours'], 'base_java_url' => "{menuaction:'property.bocommon.get_vendor_email',phpgw_return_as:'json'}", 'base_java_notify_url' => "{menuaction:'property.notify.update_data',location_id:{$location_id},location_item_id:'{$id}'}", 'edit_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiworkorder.edit', 'id' => $id)), 'lang_edit_statustext' => lang('Edit this entry '), 'lang_edit' => lang('Edit'), 'value_extra_mail_address' => $value_extra_mail_address, 'lean' => $_lean ? 1 : 0);
     $appname = lang('Workorder');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
     $GLOBALS['phpgw']->xslttpl->add_file(array('workorder', 'files', 'cat_sub_select'));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('edit' => $data));
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('menu');
     phpgwapi_yui::load_widget('connection');
     phpgwapi_yui::load_widget('loader');
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_yui::load_widget('animation');
     //			phpgwapi_yui::load_widget('container');
     //			phpgwapi_yui::load_widget('button');
     phpgwapi_jquery::load_widget('core');
     $GLOBALS['phpgw']->css->validate_file('datatable');
     $GLOBALS['phpgw']->css->validate_file('property');
     $GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
     $GLOBALS['phpgw']->js->validate_file('yahoo', 'workorder.edit', 'property');
     $GLOBALS['phpgw']->js->validate_file('portico', 'ajax_workorder_edit', 'property');
     $GLOBALS['phpgw']->js->validate_file('tinybox2', 'packed', 'phpgwapi');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
 }
 /**
  * Fetches controls and returns to datatable
  *
  * @param HTTP::phpgw_return_as	specifies how data should be returned
  * @return data array
  */
 public function index()
 {
     if (phpgw::get_var('phpgw_return_as') == 'json') {
         return $this->query();
     }
     phpgwapi_jquery::load_widget('core');
     $users = $GLOBALS['phpgw']->acl->get_user_list_right(PHPGW_ACL_EDIT, '.checklist');
     $user_list = array();
     foreach ($users as $user) {
         $user_list[] = array('id' => $user['account_id'], 'name' => "{$user['account_lastname']}, {$user['account_firstname']}", 'selected' => 0);
     }
     $_my_negative_self = -1 * $this->account;
     $default_value = array('id' => $_my_negative_self, 'name' => lang('my assigned controls'), 'selected' => $_my_negative_self == $this->account * -1);
     /*Unselect user if filter on component*/
     if (phpgw::get_var('component_id', 'int')) {
         $default_value['selected'] = 0;
     }
     unset($_my_negative_self);
     array_unshift($user_list, $default_value);
     array_unshift($user_list, array('id' => '', 'name' => lang('select')));
     // Sigurd: Start categories
     $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
     $cats->supress_info = true;
     $control_areas = $cats->formatted_xslt_list(array('format' => 'filter', 'selected' => $control_area_id, 'globals' => true, 'use_acl' => $this->_category_acl));
     array_unshift($control_areas['cat_list'], array('cat_id' => '', 'name' => lang('select value')));
     $control_areas_array = array();
     foreach ($control_areas['cat_list'] as $cat_list) {
         $control_areas_array[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name']);
     }
     // END categories
     // start district
     $property_bocommon = CreateObject('property.bocommon');
     $district_list = $property_bocommon->select_district_list('dummy', $this->district_id);
     array_unshift($district_list, array('id' => '', 'name' => lang('no district')));
     // end district
     $year_list = array();
     $year = date('Y');
     for ($_year = $year - 2; $_year < $year + 5; $_year++) {
         $year_list[] = array('id' => $_year, 'name' => $_year, 'selected' => $_year == $year ? 1 : 0);
     }
     $status_list = array(array('id' => '', 'name' => lang('select value')), array('id' => 'not_performed', 'name' => lang('status not done')), array('id' => 'done_with_open_deviation', 'name' => lang('done with open deviation')));
     $filter_component = '';
     if (phpgw::get_var('component_id', 'int')) {
         $filter_component = phpgw::get_var('location_id', 'int') . '_' . phpgw::get_var('component_id', 'int');
     }
     $data = array('datatable_name' => lang('status components'), 'form' => array('action' => self::link(array('menuaction' => 'controller.uicomponent.index')), 'method' => 'POST', 'toolbar' => array('item' => array(array('type' => 'filter', 'name' => 'report_type', 'text' => lang('report type'), 'list' => array(array('id' => 'components', 'name' => lang('components')), array('id' => 'summary', 'name' => lang('summary'))), 'onchange' => 'update_table();'), array('type' => 'filter', 'name' => 'entity_group_id', 'text' => lang('entity group'), 'list' => execMethod('property.bogeneric.get_list', array('type' => 'entity_group', 'selected' => phpgw::get_var('entity_group_id'), 'add_empty' => true)), 'onchange' => 'update_table();'), array('type' => 'hidden', 'name' => 'location_id', 'value' => phpgw::get_var('location_id', 'int')), array('type' => 'filter', 'name' => 'location_id', 'text' => lang('component'), 'list' => array(), 'onchange' => 'update_table();'), array('type' => 'filter', 'name' => 'org_unit_id', 'text' => lang('department'), 'list' => execMethod('property.bogeneric.get_list', array('type' => 'org_unit', 'selected' => phpgw::get_var('org_unit_id'), 'add_empty' => true)), 'onchange' => 'update_table();'), array('type' => 'filter', 'name' => 'user_id', 'text' => lang('User'), 'list' => $user_list, 'onchange' => 'update_table();'), array('type' => 'checkbox', 'name' => 'user_only', 'text' => 'Filtrer bruker', 'value' => 1, 'onclick' => 'update_table();'), array('type' => 'filter', 'name' => 'district_id', 'text' => lang('district'), 'list' => $district_list, 'onchange' => 'update_table();'), array('type' => 'filter', 'name' => 'year', 'text' => lang('year'), 'list' => $year_list, 'onchange' => 'update_table();'), array('type' => 'filter', 'name' => 'status', 'text' => lang('status'), 'list' => $status_list, 'onchange' => 'update_table();'), array('type' => 'checkbox', 'name' => 'all_items', 'text' => 'List uten kontroller', 'value' => 1, 'onclick' => 'update_table();'), array('type' => 'hidden', 'name' => 'filter_component', 'text' => '', 'value' => $filter_component), array('type' => 'hidden', 'name' => 'custom_frontend', 'text' => '', 'value' => isset($GLOBALS['phpgw_info']['flags']['custom_frontend']) && $GLOBALS['phpgw_info']['flags']['custom_frontend'] ? 1 : 0)))), 'datatable' => array('source' => self::link(array('menuaction' => 'controller.uicomponent.index', 'phpgw_return_as' => 'json')), 'field' => $this->get_fields($filter_component)));
     self::render_template_xsl(array('component', 'calendar/icon_color_map'), $data);
 }
 /**
  * Prepare data for view and edit - depending on mode
  *
  * @param array  $values  populated object in case of retry
  * @param string $mode    edit or view
  * @param int    $id      entity id - no id means 'new'
  *
  * @return void
  */
 public function edit($values = array(), $mode = 'edit')
 {
     $id = (int) phpgw::get_var('id');
     if (!$this->acl_add && !$this->acl_edit) {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uicondition_survey.view', 'id' => $id));
     }
     if ($mode == 'view') {
         if (!$this->acl_read) {
             $this->bocommon->no_access();
             return;
         }
     } else {
         if (!$this->acl_add && !$this->acl_edit) {
             $this->bocommon->no_access();
             return;
         }
     }
     phpgwapi_cache::session_clear('property.request', 'session_data');
     phpgwapi_yui::tabview_setup('survey_edit_tabview');
     $tabs = array();
     $tabs['generic'] = array('label' => lang('generic'), 'link' => '#generic');
     $active_tab = 'generic';
     $tabs['documents'] = array('label' => lang('documents'), 'link' => null);
     $tabs['request'] = array('label' => lang('request'), 'link' => null);
     $tabs['summation'] = array('label' => lang('summation'), 'link' => null);
     $tabs['import'] = array('label' => lang('import'), 'link' => null);
     if ($id) {
         if ($mode == 'edit') {
             $tabs['import']['link'] = '#import';
         }
         $tabs['documents']['link'] = '#documents';
         $tabs['request']['link'] = '#request';
         $tabs['summation']['link'] = '#summation';
         if (!$values) {
             $values = $this->bo->read_single(array('id' => $id, 'view' => $mode == 'view'));
         }
     }
     if (isset($values['location_code']) && $values['location_code']) {
         $values['location_data'] = execMethod('property.solocation.read_single', $values['location_code']);
     }
     $categories = $this->_get_categories($values['cat_id']);
     $bolocation = CreateObject('property.bolocation');
     $location_data = $bolocation->initiate_ui_location(array('values' => $values['location_data'], 'type_id' => 2, 'required_level' => 1, 'no_link' => $_no_link, 'lookup_type' => $mode == 'edit' ? 'form2' : 'view2', 'tenant' => false, 'lookup_entity' => array(), 'entity_data' => isset($values['p']) ? $values['p'] : ''));
     $msgbox_data = $this->bocommon->msgbox_data($this->receipt);
     $file_def = array(array('key' => 'file_name', 'label' => lang('Filename'), 'sortable' => false, 'resizeable' => true), array('key' => 'delete_file', 'label' => lang('Delete file'), 'sortable' => false, 'resizeable' => true));
     $datatable_def = array();
     $datatable_def[] = array('container' => 'datatable-container_0', 'requestUrl' => json_encode(self::link(array('menuaction' => 'property.uicondition_survey.get_files', 'id' => $id, 'phpgw_return_as' => 'json'))), 'ColumnDefs' => $file_def);
     $related_def = array(array('key' => 'url', 'label' => lang('id'), 'sortable' => true, 'resizeable' => true), array('key' => 'title', 'label' => lang('title'), 'sortable' => false, 'resizeable' => true, 'width' => '100'), array('key' => 'status', 'label' => lang('status'), 'sortable' => true, 'resizeable' => true), array('key' => 'condition_degree', 'label' => lang('condition degree'), 'sortable' => false, 'resizeable' => true), array('key' => 'score', 'label' => lang('score'), 'sortable' => true, 'resizeable' => true), array('key' => 'amount_investment', 'label' => lang('investment'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'amount_operation', 'label' => lang('operation'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'amount_potential_grants', 'label' => lang('potential grants'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'recommended_year', 'label' => lang('recommended year'), 'sortable' => true, 'resizeable' => true), array('key' => 'planned_year', 'label' => lang('planned year'), 'sortable' => true, 'resizeable' => true), array('key' => 'related', 'label' => lang('related'), 'sortable' => false, 'resizeable' => true));
     $datatable_def[] = array('container' => 'datatable-container_1', 'requestUrl' => json_encode(self::link(array('menuaction' => 'property.uicondition_survey.get_request', 'id' => $id, 'phpgw_return_as' => 'json'))), 'ColumnDefs' => $related_def);
     $summation_def = array(array('key' => 'building_part', 'label' => lang('building part'), 'sortable' => false, 'resizeable' => true), array('key' => 'category', 'label' => lang('category'), 'sortable' => true, 'resizeable' => true), array('key' => 'period_1', 'label' => lang('year') . ':: < 1', 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'period_2', 'label' => lang('year') . ':: 1 - 5', 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'period_3', 'label' => lang('year') . ':: 6 - 10', 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'period_4', 'label' => lang('year') . ':: 11 - 15', 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'period_5', 'label' => lang('year') . ':: 16 - 20', 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'period_6', 'label' => lang('year') . ':: 21 +', 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'), array('key' => 'sum', 'label' => lang('sum'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'YAHOO.portico.FormatterAmount0'));
     $datatable_def[] = array('container' => 'datatable-container_2', 'requestUrl' => json_encode(self::link(array('menuaction' => 'property.uicondition_survey.get_summation', 'id' => $id, 'phpgw_return_as' => 'json'))), 'ColumnDefs' => $summation_def);
     $this->config = CreateObject('phpgwapi.config', 'property');
     $this->config->read();
     $data = array('datatable_def' => $datatable_def, 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'survey' => $values, 'location_data2' => $location_data, 'lang_coordinator' => isset($this->config->config_data['lang_request_coordinator']) && $this->config->config_data['lang_request_coordinator'] ? $this->config->config_data['lang_request_coordinator'] : lang('coordinator'), 'categories' => array('options' => $categories), 'status_list' => array('options' => execMethod('property.bogeneric.get_list', array('type' => 'condition_survey_status', 'selected' => $values['status_id'], 'add_empty' => true))), 'editable' => $mode == 'edit', 'tabs' => phpgwapi_yui::tabview_generate($tabs, $active_tab), 'multiple_uploader' => $mode == 'edit' ? true : '');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . '::' . lang('condition survey');
     if ($mode == 'edit') {
         $GLOBALS['phpgw']->jqcal->add_listener('report_date');
         phpgwapi_jquery::load_widget('core');
         self::add_javascript('property', 'portico', 'condition_survey_edit.js');
         self::add_javascript('phpgwapi', 'yui3', 'yui/yui-min.js');
         self::add_javascript('phpgwapi', 'yui3-gallery', 'gallery-formvalidator/gallery-formvalidator-min.js');
         $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yui3-gallery/gallery-formvalidator/validatorCss.css');
     }
     self::add_javascript('property', 'portico', 'condition_survey.js');
     self::add_javascript('phpgwapi', 'tinybox2', 'packed.js');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
     //			$GLOBALS['phpgw_info']['server']['no_jscombine'] = true;
     self::render_template_xsl(array('condition_survey'), $data);
 }
Exemple #5
0
            // cut 'phpgw_'
            $extra_vars[$name] = $value;
        }
    }
    $GLOBALS['phpgw']->redirect_link($_GET['phpgw_forward'], $extra_vars);
    exit;
}
if (isset($GLOBALS['phpgw_info']['server']['force_default_app']) && $GLOBALS['phpgw_info']['server']['force_default_app'] != 'user_choice') {
    $GLOBALS['phpgw_info']['user']['preferences']['common']['default_app'] = $GLOBALS['phpgw_info']['server']['force_default_app'];
}
if (isset($_GET['cd']) && $_GET['cd'] == 'yes' && isset($GLOBALS['phpgw_info']['user']['preferences']['common']['default_app']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['default_app'] && $GLOBALS['phpgw_info']['user']['apps'][$GLOBALS['phpgw_info']['user']['preferences']['common']['default_app']]) {
    $GLOBALS['phpgw']->redirect_link('/' . $GLOBALS['phpgw_info']['user']['preferences']['common']['default_app'] . '/' . 'index.php');
    exit;
} else {
    phpgw::import_class('phpgwapi.jquery');
    phpgwapi_jquery::load_widget('core');
    $GLOBALS['phpgw']->common->phpgw_header();
    echo parse_navbar();
}
$GLOBALS['phpgw']->translation->add_app('mainscreen');
if (lang('mainscreen_message') != '!mainscreen_message') {
    echo '<div class="msg">' . lang('mainscreen_message') . '</div>';
}
if (isset($GLOBALS['phpgw_info']['user']['apps']['admin']) && $GLOBALS['phpgw_info']['user']['apps']['admin'] && (isset($GLOBALS['phpgw_info']['server']['checkfornewversion']) && $GLOBALS['phpgw_info']['server']['checkfornewversion'])) {
    $GLOBALS['phpgw']->network->set_addcrlf(False);
    $lines = $GLOBALS['phpgw']->network->gethttpsocketfile('http://www.phpgroupware.org/currentversion');
    for ($i = 0; $i < count($lines); ++$i) {
        if (preg_match('/currentversion/', $lines[$i])) {
            $line_found = explode(':', chop($lines[$i]));
        }
    }
 function index()
 {
     if (phpgw::get_var('save_component')) {
         //add component to control using component item ID
         $items_checked = array();
         $items = phpgw::get_var('values_assign');
         $item_arr = explode('|', $items);
         foreach ($item_arr as $item) {
             $items_checked[] = explode(';', $item);
         }
         //var_dump($items_checked);
         $control_group_id = phpgw::get_var('control_group_id');
         //var_dump($control_id);
         if ($control_group_id != null && is_numeric($control_group_id)) {
             //add chosen component to control
             foreach ($items_checked as $it) {
                 if (!$this->so_control_group->exist_component_control_group($control_group_id, $it[0])) {
                     $this->so_control_group->add_component_to_control_group($control_group_id, $it[0]);
                 }
             }
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group_component.index'));
     } else {
         if (phpgw::get_var('phpgw_return_as') == 'json') {
             return $this->get_component();
         }
         $bim_types = $this->so_control->get_bim_types();
         // Sigurd: START as categories
         $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
         $cats->supress_info = true;
         $control_areas = $cats->formatted_xslt_list(array('format' => 'filter', 'selected' => '', 'globals' => true, 'use_acl' => $this->_category_acl));
         array_unshift($control_areas['cat_list'], array('cat_id' => '', 'name' => lang('select value')));
         $control_areas_array = array();
         foreach ($control_areas['cat_list'] as $cat_list) {
             $control_areas_array[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name']);
         }
         // END as categories
         $data = array('view' => "add_component_to_control_group", 'control_group_filters' => array('control_area_array' => $control_areas_array, 'control_group_array' => $control_group_array), 'filter_form' => array('bim_types' => $bim_types), 'datatable' => array('source' => self::link(array('menuaction' => 'controller.uicontrol_group_component.index', 'phpgw_return_as' => 'json')), 'field' => array(array('key' => 'location_id', 'label' => lang('ID'), 'sortable' => true, 'formatter' => 'YAHOO.portico.formatLink'), array('key' => 'name', 'label' => lang('Name'), 'sortable' => false), array('key' => 'checked', 'label' => 'Velg', 'sortable' => false, 'formatter' => 'YAHOO.widget.DataTable.formatCheckbox', 'className' => 'mychecks'))));
         phpgwapi_yui::load_widget('paginator');
         phpgwapi_jquery::load_widget('core');
         self::add_javascript('controller', 'yahoo', 'control_tabs.js');
         self::add_javascript('controller', 'controller', 'ajax.js');
         self::render_template_xsl(array('control_group_component_tabs', 'common', 'add_component_to_control_group'), $data);
     }
 }
 function view_control_info()
 {
     $check_list_id = phpgw::get_var('check_list_id');
     $check_list = $this->so->get_single($check_list_id);
     $control = $this->so_control->get_single($check_list->get_control_id());
     $component_id = $check_list->get_component_id();
     if ($component_id > 0) {
         $location_id = $check_list->get_location_id();
         $component_id = $check_list->get_component_id();
         $component_arr = execMethod('property.soentity.read_single_eav', array('location_id' => $location_id, 'id' => $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' => $location_id, 'id' => $component_id));
         $component = new controller_component();
         $component->set_id($component_id);
         $component->set_location_id($location_id);
         $component->set_location_code($component_arr['location_code']);
         $component->set_xml_short_desc($short_desc);
         $component_array = $component->toArray();
         $type = 'component';
         $building_location_code = $this->location_finder->get_building_location_code($component_arr['location_code']);
     } else {
         $location_code = $check_list->get_location_code();
         $location_array = execMethod('property.bolocation.read_single', array('location_code' => $location_code));
         $type = 'location';
         $level = $this->location_finder->get_location_level($location_code);
     }
     $year = date("Y", $check_list->get_deadline());
     $month = date("n", $check_list->get_deadline());
     $level = $this->location_finder->get_location_level($location_code);
     $user_role = true;
     // Fetches buildings on property
     $buildings_on_property = $this->location_finder->get_buildings_on_property($user_role, $location_code, $level);
     $data = array('control' => $control, 'check_list' => $check_list, 'buildings_on_property' => $buildings_on_property, 'location_array' => $location_array, 'component_array' => $component_array, 'type' => $type, 'current_year' => $year, 'current_month_nr' => $month, 'building_location_code' => $building_location_code, 'location_level' => $level);
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'controller', 'check_list_update_status.js');
     self::render_template_xsl(array('check_list/fragments/check_list_menu', 'check_list/fragments/check_list_top_section', 'check_list/fragments/nav_control_plan', 'check_list/view_control_info', 'check_list/fragments/select_buildings_on_property'), $data);
 }
 public function view_calendar_month_for_locations()
 {
     static $_location_name = array();
     $control_id = phpgw::get_var('control_id', 'int');
     $control = $this->so_control->get_single($control_id);
     if (!($year = intval(phpgw::get_var('year')))) {
         $year = date('Y');
     }
     if (!($month = intval(phpgw::get_var('month')))) {
         $month = date('m');
     }
     $location_id = phpgw::get_var('location_id', 'int');
     $component_id = phpgw::get_var('component_id', 'int');
     $serie_id = phpgw::get_var('serie_id', 'int');
     $user_id = $GLOBALS['phpgw_info']['user']['account_id'];
     $bookmark_locations = array();
     $bookmarks = phpgwapi_cache::user_get('controller', "location_bookmark", $user_id);
     if (is_array($bookmarks)) {
         $bookmark_locations = array_keys($bookmarks);
     }
     if ($location_code = phpgw::get_var('location_code')) {
         $bookmark_locations[] = $location_code;
     }
     if (is_numeric($control_id) & $control_id > 0) {
         $locations_for_control_array = $this->so_control->get_locations_for_control($control_id);
         $components_for_control_array = $this->so_control->get_components_for_control($control_id, $location_id, $component_id, $serie_id);
         foreach ($locations_for_control_array as $location) {
             $locations_list[] = array('id' => $location['location_code'], 'name' => $location['loc_name'], 'selected' => $location_code == $location['location_code'] ? 1 : 0);
         }
         reset($locations_for_control_array);
         unset($location);
     }
     // Validates year. If year is not set, current year is chosen
     $year = $this->validate_year($year);
     // Validates month. If year is not set, current month in current year is chosen
     $month = $this->validate_month($month);
     // Gets timestamp value of first day in month
     $from_date_ts = month_calendar::get_start_date_month_ts($year, intval($month));
     // Gets timestamp value of first day in month
     $to_date_ts = month_calendar::get_next_start_date_month_ts($year, intval($month));
     $locations_with_calendar_array = array();
     foreach ($locations_for_control_array as $location) {
         $curr_location_code = $location['location_code'];
         if (!$bookmark_locations || !in_array($curr_location_code, $bookmark_locations)) {
             continue;
         }
         $repeat_type = $control->get_repeat_type();
         $check_lists_array = $this->so->get_check_lists_for_control_and_location($control_id, $curr_location_code, $from_date_ts, $to_date_ts, $control->get_repeat_type());
         $month_calendar = new month_calendar($control, $year, $month, null, $curr_location_code, "location");
         $calendar_array = $month_calendar->build_calendar($check_lists_array);
         $locations_with_calendar_array[] = array('location' => $location, 'calendar_array' => $calendar_array, 'selected' => $bookmarks && isset($bookmarks[$curr_location_code]));
     }
     foreach ($components_for_control_array as $component) {
         $short_desc_arr = execMethod('property.soentity.get_short_description', array('location_id' => $component->get_location_id(), 'id' => $component->get_id()));
         if (!isset($_location_name[$component->get_location_code()])) {
             $_location = execMethod('property.solocation.read_single', $component->get_location_code());
             $location_arr = explode('-', $component->get_location_code());
             $i = 1;
             $name_arr = array();
             foreach ($location_arr as $_dummy) {
                 $name_arr[] = $_location["loc{$i}_name"];
                 $i++;
             }
             $_location_name[$component->get_location_code()] = implode('::', $name_arr);
         }
         $short_desc_arr .= ' [' . $_location_name[$component->get_location_code()] . ']';
         $component->set_xml_short_desc($short_desc_arr);
         $repeat_type = $control->get_repeat_type();
         $component_with_check_lists = $this->so->get_check_lists_for_control_and_component($control_id, $component->get_location_id(), $component->get_id(), $from_date_ts, $to_date_ts, $repeat_type);
         $check_lists_array = $component_with_check_lists["check_lists_array"];
         /*
          * Start override control with data from serie
          */
         $control_relation = $component->get_control_relation();
         if (isset($control_relation['start_date']) && $control_relation['start_date']) {
             $control->set_start_date($control_relation['start_date']);
         }
         if (isset($control_relation['end_date']) && $control_relation['end_date']) {
             $control->set_end_date($control_relation['end_date']);
         }
         if (isset($control_relation['repeat_type']) && $control_relation['repeat_type']) {
             $control->set_repeat_type($control_relation['repeat_type']);
         }
         if (isset($control_relation['repeat_interval']) && $control_relation['repeat_interval']) {
             $control->set_repeat_interval($control_relation['repeat_interval']);
         }
         /*
          * End override control with data from serie
          */
         $month_calendar = new month_calendar($control, $year, $month, $component, null, "component");
         $calendar_array = $month_calendar->build_calendar($check_lists_array);
         $components_with_calendar_array[] = array("component" => $component->toArray(), "calendar_array" => $calendar_array);
     }
     // Gets array of locations assigned to current user
     $my_locations = $this->get_my_assigned_locations($location_code);
     $heading_array = month_calendar::get_heading_array($year, $month);
     $data = array('control' => $control->toArray(), 'my_locations' => $my_locations, 'property_array' => $property_array, 'location_array' => $location_array, 'heading_array' => $heading_array, 'locations_with_calendar_array' => $locations_with_calendar_array, 'components_with_calendar_array' => $components_with_calendar_array, 'current_year' => $year, 'current_month_nr' => $month, 'locations_list' => $locations_list, 'location_code' => $location_code, 'serie_id' => $serie_id);
     self::render_template_xsl(array('calendar/view_calendar_month_for_locations', 'calendar/check_list_status_manager', 'calendar/icon_color_map', 'calendar/select_my_locations', 'calendar/nav_calendar_month'), $data);
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'controller', 'ajax.js');
 }
 public function edit_inventory()
 {
     $location_id = phpgw::get_var('location_id', 'int');
     $id = phpgw::get_var('id', 'int');
     $inventory_id = phpgw::get_var('inventory_id', 'int');
     $system_location = $GLOBALS['phpgw']->locations->get_name($location_id);
     $this->acl_add = $this->acl->check($system_location['location'], PHPGW_ACL_ADD, $system_location['appname']);
     if (!$this->acl_add) {
         echo lang('No Access');
         $GLOBALS['phpgw']->common->phpgw_exit();
     }
     $unit_id = '';
     if ($inventory = $this->bo->get_inventory(array('id' => $id, 'location_id' => $location_id, 'inventory_id' => $inventory_id))) {
         $unit_id = $inventory[0]['unit_id'];
     }
     $location_code = execMethod('property.solocation.get_location_code', $inventory[0]['p_id']);
     $lock_unit = !!$unit_id;
     $receipt = array();
     $values = phpgw::get_var('values');
     $bolocation = CreateObject('property.bolocation');
     $values['location_data'] = $bolocation->read_single($location_code, array('view' => true));
     $values['unit_id'] = $values['unit_id'] ? $values['unit_id'] : $unit_id;
     if (isset($values['save']) && $values['save']) {
         $values['location_id'] = $location_id;
         $values['item_id'] = $id;
         $values['inventory_id'] = $inventory_id;
         if (!isset($receipt['error'])) {
             $this->bo->edit_inventory($values);
             $receipt['message'][] = array('msg' => 'Ok');
             $values = array();
         }
         if (phpgw::get_var('phpgw_return_as') == 'json') {
             if (!$receipt['error']) {
                 $result = array('status' => 'updated');
             } else {
                 $result = array('status' => 'error');
             }
             $result['receipt'] = $receipt;
             return $result;
         }
     }
     $msgbox_data = $this->bocommon->msgbox_data($receipt);
     $unit_list = execMethod('property.bogeneric.get_list', array('type' => 'unit', 'selected' => $unit_id));
     $location_data = execMethod('property.bolocation.initiate_ui_location', array('values' => $values['location_data'], 'type_id' => 5, 'no_link' => false, 'lookup_type' => 'view', 'tenant' => false, 'lookup_entity' => $lookup_entity, 'entity_data' => isset($values['p']) ? $values['p'] : ''));
     $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
     $data = array('msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'location_data' => $location_data, 'system_location' => $system_location, 'location_id' => $location_id, 'item_id' => $id, 'inventory_id' => $inventory_id, 'unit_list' => array('options' => $unit_list), 'lock_unit' => $lock_unit, 'value_inventory' => $values['inventory'] ? $values['inventory'] : $inventory[0]['inventory'], 'value_write_off' => $values['write_off'], 'bookable' => $values['bookable'] ? $values['bookable'] : $inventory[0]['bookable'], 'value_active_from' => $values['active_from'] ? $values['active_from'] : $GLOBALS['phpgw']->common->show_date($inventory[0]['active_from'], $dateformat), 'value_active_to' => $values['active_to'] ? $values['active_to'] : $GLOBALS['phpgw']->common->show_date($inventory[0]['active_to'], $dateformat), 'value_remark' => $values['remark'] ? $values['remark'] : $inventory[0]['remark']);
     $GLOBALS['phpgw']->jqcal->add_listener('active_from');
     $GLOBALS['phpgw']->jqcal->add_listener('active_to');
     $GLOBALS['phpgw']->xslttpl->add_file(array('entity', 'attributes_form', 'files'));
     $GLOBALS['phpgw_info']['flags']['noframework'] = true;
     phpgwapi_jquery::load_widget('core');
     $GLOBALS['phpgw']->js->validate_file('yahoo', 'entity.edit_inventory', 'property');
     $function_msg = lang('add inventory');
     $GLOBALS['phpgw_info']['flags']['app_header'] = $system_location['appname'] . '::' . $system_location['descr'] . '::' . $function_msg;
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('edit_inventory' => $data));
 }
 function view_closed_cases()
 {
     $check_list_id = phpgw::get_var('check_list_id');
     $case_location_code = phpgw::get_var('location_code');
     $check_list = $this->so_check_list->get_single($check_list_id);
     // Check list top section info
     $control = $this->so_control->get_single($check_list->get_control_id());
     $location_code = $check_list->get_location_code();
     $component_id = $check_list->get_component_id();
     if ($component_id > 0) {
         $location_id = $check_list->get_location_id();
         $component_id = $check_list->get_component_id();
         $component_arr = execMethod('property.soentity.read_single_eav', array('location_id' => $location_id, 'id' => $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' => $location_id, 'id' => $component_id));
         //				$short_desc = execMethod('property.soentity.get_short_description', array('location_id' => $location_id, 'id' => $component_id));
         $component = new controller_component();
         $component->set_id($component_id);
         $component->set_location_id($location_id);
         $component->set_location_code($component_arr['location_code']);
         $component->set_xml_short_desc($short_desc);
         $component_array = $component->toArray();
         $type = 'component';
         $building_location_code = $this->location_finder->get_building_location_code($component_arr['location_code']);
         $buildings_on_property = array();
     } else {
         $location_code = $check_list->get_location_code();
         $location_array = execMethod('property.bolocation.read_single', array('location_code' => $location_code));
         $type = 'location';
         // Fetches buildings on property
         $buildings_on_property = $this->location_finder->get_buildings_on_property($user_role, $location_code, $level);
     }
     // Check list top section info
     $level = $this->location_finder->get_location_level($location_code);
     $year = date("Y", $check_list->get_deadline());
     $month = date("n", $check_list->get_deadline());
     $user_role = true;
     $closed_check_items_and_cases = $this->so_check_item->get_check_items_with_cases($check_list_id, null, 'closed', null, $case_location_code);
     if ($buildings_on_property) {
         foreach ($buildings_on_property as &$building) {
             $building['selected'] = $building['id'] == $case_location_code ? 1 : 0;
         }
     }
     //---------
     foreach ($closed_check_items_and_cases as $key => $check_item) {
         //		$control_item_with_options = $this->so_control_item->get_single_with_options( $check_item->get_control_item_id() );
         foreach ($check_item->get_cases_array() as $case) {
             $component_location_id = $case->get_component_location_id();
             $component_id = $case->get_component_id();
             if ($component_id) {
                 $short_desc = execMethod('property.soentity.get_short_description', array('location_id' => $component_location_id, 'id' => $component_id));
                 $case->set_component_descr($short_desc);
             }
         }
         //		$check_item->get_control_item()->set_options_array( $control_item_with_options->get_options_array() );
         //		$closed_check_items_and_cases[$key] = $check_item;
     }
     //-------
     $data = array('control' => $control, 'check_list' => $check_list, 'buildings_on_property' => $buildings_on_property, 'location_array' => $location_array, 'component_array' => $component_array, 'type' => $type, 'location_level' => $level, 'current_year' => $year, 'current_month_nr' => $month, 'closed_check_items_and_cases' => $closed_check_items_and_cases, 'check_list' => $check_list, 'cases_view' => 'closed_cases', 'building_location_code' => $building_location_code);
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'controller', 'case.js');
     self::add_javascript('controller', 'controller', 'check_list_update_status.js');
     self::render_template_xsl(array('check_list/fragments/check_list_menu', 'case/cases_tab_menu', 'case/view_closed_cases', 'case/case_row', 'check_list/fragments/nav_control_plan', 'check_list/fragments/check_list_top_section', 'check_list/fragments/select_buildings_on_property'), $data);
 }
 function edit()
 {
     $id = phpgw::get_var('id');
     // in case of bigint
     if (!$this->acl_add && !$this->acl_edit) {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uis_agreement.view', 'id' => $id));
     }
     phpgwapi_jquery::load_widget('core');
     $values = phpgw::get_var('values');
     $delete_item = phpgw::get_var('delete_item');
     $item_id = phpgw::get_var('item_id');
     $active_tab = phpgw::get_var('tab', 'string', 'REQUEST', 'general');
     $config = CreateObject('phpgwapi.config', 'property');
     $boalarm = CreateObject('property.boalarm');
     $get_items = false;
     if ($delete_item && $id && $item_id) {
         $this->bo->delete_item($id, $item_id);
         $get_items = true;
     }
     $values_attribute = phpgw::get_var('values_attribute');
     $insert_record_s_agreement = $GLOBALS['phpgw']->session->appsession('insert_record_values.s_agreement', 'property');
     for ($j = 0; $j < count($insert_record_s_agreement); $j++) {
         $insert_record['extra'][$insert_record_s_agreement[$j]] = $insert_record_s_agreement[$j];
     }
     $GLOBALS['phpgw']->xslttpl->add_file(array('s_agreement', 'attributes_form', 'files'));
     if (is_array($values)) {
         $values['ecodimb'] = phpgw::get_var('ecodimb');
         while (is_array($insert_record['extra']) && (list($key, $column) = each($insert_record['extra']))) {
             if ($_POST[$key]) {
                 $values['extra'][$column] = phpgw::get_var($key, 'string', 'POST');
             }
         }
         if ($values['save'] || $values['apply']) {
             $values['vendor_id'] = phpgw::get_var('vendor_id', 'int', 'POST');
             $values['vendor_name'] = phpgw::get_var('vendor_name', 'string', 'POST');
             $values['b_account_id'] = phpgw::get_var('b_account_id', 'int', 'POST');
             $values['b_account_name'] = phpgw::get_var('b_account_name', 'string', 'POST');
             if (!$values['cat_id']) {
                 $receipt['error'][] = array('msg' => lang('Please select a category !'));
             }
             if (($values['ecodimb'] || $values['b_account_id']) && (!isset($values['budget']) || !$values['budget'])) {
                 $receipt['error'][] = array('msg' => lang('Missing budget value'));
             }
             if (!$values['last_name']) {
                 //						$receipt['error'][]=array('msg'=>lang('Please enter a name !'));
             }
             if (isset($values['budget']) && $values['budget'] && !ctype_digit($values['budget'])) {
                 $receipt['error'][] = array('msg' => lang('budget') . ': ' . lang('Please enter an integer !'));
             }
             if ($id) {
                 $values['s_agreement_id'] = $id;
                 $action = 'edit';
             } else {
                 $values['s_agreement_id'] = $this->bo->request_next_id();
             }
             if (isset($values['delete_b_year']) && is_array($values['delete_b_year'])) {
                 $this->bo->delete_year_from_budget($values['delete_b_year'], $id);
             }
             $bofiles = CreateObject('property.bofiles');
             if (isset($values['file_action']) && is_array($values['file_action'])) {
                 $bofiles->delete_file("/service_agreement/{$id}/", $values);
             }
             $values['file_name'] = str_replace(' ', '_', $_FILES['file']['name']);
             $to_file = "{$bofiles->fakebase}/service_agreement/{$values['s_agreement_id']}/{$values['file_name']}";
             if (!$values['document_name_orig'] && $bofiles->vfs->file_exists(array('string' => $to_file, 'relatives' => array(RELATIVE_NONE)))) {
                 $receipt['error'][] = array('msg' => lang('This file already exists !'));
             }
             if (!$receipt['error']) {
                 //						$values['s_agreement_id']	= $id;
                 $receipt = $this->bo->save($values, $values_attribute, $action);
                 $id = $receipt['s_agreement_id'];
                 $this->cat_id = $values['cat_id'] ? $values['cat_id'] : $this->cat_id;
                 if ($values['file_name']) {
                     $bofiles->create_document_dir("service_agreement/{$id}");
                     $bofiles->vfs->override_acl = 1;
                     if (!$bofiles->vfs->cp(array('from' => $_FILES['file']['tmp_name'], 'to' => $to_file, 'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL)))) {
                         $receipt['error'][] = array('msg' => lang('Failed to upload file !'));
                     }
                     $bofiles->vfs->override_acl = 0;
                 }
                 if ($values['save']) {
                     $GLOBALS['phpgw']->session->appsession('session_data', 's_agreement_receipt', $receipt);
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uis_agreement.index', 'role' => $this->role));
                 }
             }
         } else {
             if ($values['update']) {
                 if (!$values['date']) {
                     $receipt['error'][] = array('msg' => lang('Please select a date !'));
                 }
                 if (!$values['new_index']) {
                     $receipt['error'][] = array('msg' => lang('Please enter a index !'));
                 }
                 if (!$receipt['error']) {
                     $receipt = $this->bo->update($values);
                 }
                 $get_items = true;
             } else {
                 if ($values['delete_alarm'] && count($values['alarm'])) {
                     if (!$receipt['error']) {
                         $receipt = $boalarm->delete_alarm('s_agreement', $values['alarm']);
                     }
                 } else {
                     if (($values['enable_alarm'] || $values['disable_alarm']) && count($values['alarm'])) {
                         if (!$receipt['error']) {
                             $receipt = $boalarm->enable_alarm('s_agreement', $values['alarm'], $values['enable_alarm']);
                         }
                     } else {
                         if ($values['add_alarm']) {
                             $time = intval($values['time']['days']) * 24 * 3600 + intval($values['time']['hours']) * 3600 + intval($values['time']['mins']) * 60;
                             if ($time > 0) {
                                 $receipt = $boalarm->add_alarm('s_agreement', $this->bo->read_event(array('s_agreement_id' => $id)), $time, $values['user_id']);
                             }
                         } else {
                             if (!$values['save'] && !$values['apply'] && !$values['update']) {
                                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uis_agreement.index', 'role' => $this->role));
                             }
                         }
                     }
                 }
             }
         }
     }
     /* Preserve attribute values from post */
     if (isset($receipt['error']) && (isset($values_attribute) && is_array($values_attribute))) {
         $values = $this->bocommon->preserve_attribute_values($values, $values_attribute);
     }
     $GLOBALS['phpgw']->jqcal->add_listener('values_start_date');
     $GLOBALS['phpgw']->jqcal->add_listener('values_end_date');
     $GLOBALS['phpgw']->jqcal->add_listener('values_termination_date');
     $this->member_id = $values['member_of'] ? $values['member_of'] : $this->member_id;
     if ($id) {
         $values = $this->bo->read_single(array('s_agreement_id' => $id));
         $this->cat_id = $values['cat_id'] ? $values['cat_id'] : $this->cat_id;
         $this->member_id = $values['member_of'] ? $values['member_of'] : $this->member_id;
         $list = $this->bo->read_details($id);
         $uicols = $this->bo->uicols;
         $list = $this->list_content($list, $uicols);
         $content = $list['content'];
         $table_header = $list['table_header'];
         for ($i = 0; $i < count($list['content'][0]['row']); $i++) {
             $set_column[] = true;
         }
         if (isset($content) && is_array($content)) {
             $GLOBALS['phpgw']->jqcal->add_listener('values_date');
             $table_update[] = array('lang_new_index' => lang('New index'), 'lang_new_index_statustext' => lang('Enter a new index'), 'lang_date_statustext' => lang('Select the date for the update'), 'lang_update' => lang('Update'), 'lang_update_statustext' => lang('update selected investments'));
         }
     }
     $link_data = array('menuaction' => 'property.uis_agreement.edit', 'id' => $id, 'role' => $this->role);
     $vendor_data = $this->bocommon->initiate_ui_vendorlookup(array('vendor_id' => $values['vendor_id'], 'vendor_name' => $values['vendor_name']));
     $b_account_data = $this->bocommon->initiate_ui_budget_account_lookup(array('b_account_id' => $values['b_account_id'], 'b_account_name' => $values['b_account_name']));
     $ecodimb_data = $this->bocommon->initiate_ecodimb_lookup(array('ecodimb' => $values['ecodimb'], 'ecodimb_descr' => $values['ecodimb_descr']));
     $alarm_data = $this->bocommon->initiate_ui_alarm(array('acl_location' => $this->acl_location, 'alarm_type' => 's_agreement', 'type' => 'form', 'text' => 'Email notification', 'times' => $times, 'id' => $id, 'method' => $method, 'data' => $data, 'account_id' => $account_id));
     $msgbox_data = $this->bocommon->msgbox_data($receipt);
     if ($values['vendor_id']) {
         $member_of_list = $this->get_vendor_member_info($values['vendor_id']);
     } else {
         $member_of_list = array();
     }
     $table_add[] = array('lang_add' => lang('add detail'), 'lang_add_standardtext' => lang('add an item to the details'), 'add_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uis_agreement.edit_item', 's_agreement_id' => $id)));
     $link_file_data = array('menuaction' => 'property.uis_agreement.view_file', 'id' => $id);
     $config->read();
     $link_to_files = $config->config_data['files_url'];
     $j = count($values['files']);
     for ($i = 0; $i < $j; $i++) {
         $values['files'][$i]['file_name'] = urlencode($values['files'][$i]['name']);
     }
     $link_download = array('menuaction' => 'property.uis_agreement.download', 'id' => $id);
     $GLOBALS['phpgw']->js->validate_file('overlib', 'overlib', 'property');
     $GLOBALS['phpgw']->js->validate_file('core', 'check', 'property');
     $tabs = array();
     if (isset($values['attributes']) && is_array($values['attributes'])) {
         /*		foreach ($values['attributes'] as & $attribute)
         				{
         					if($attribute['history'] == true)
         					{
         						$link_history_data = array
         						(
         							'menuaction'	=> 'property.uis_agreement.attrib_history',
         							'attrib_id'	=> $attribute['id'],
         							'id'		=> $id,
         							'edit'		=> true
         						);
         
         						$attribute['link_history'] = $GLOBALS['phpgw']->link('/index.php',$link_history_data);
         					}
         				}
         		 */
         phpgwapi_yui::tabview_setup('edit_tabview');
         $tabs['general'] = array('label' => lang('general'), 'link' => '#general');
         $location = $this->acl_location;
         $attributes_groups = $this->bo->get_attribute_groups($location, $values['attributes']);
         $attributes = array();
         foreach ($attributes_groups as $group) {
             if (isset($group['attributes'])) {
                 $attributes[] = $group;
             }
         }
         unset($attributes_groups);
         unset($values['attributes']);
         $tabs['items'] = array('label' => lang('items'), 'link' => '#items');
     }
     //----------JSON CODE ----------------------------------------------
     //---GET ITEMS
     if (phpgw::get_var('phpgw_return_as') == 'json' && $get_items) {
         //$this->bo->delete_item($id,$item_id);
         $list = $this->bo->read_details($id);
         $list = $this->list_content($list, $uicols);
         $content = $list['content'];
         $content_values = array();
         for ($y = 0; $y < count($content); $y++) {
             for ($z = 0; $z < count($content[$y]['row']); $z++) {
                 if ($content[$y]['row'][$z + 1]['name'] != '') {
                     $content_values[$y][$content[$y]['row'][$z + 1]['name']] = $content[$y]['row'][$z + 1]['value'];
                 }
             }
         }
         /*$datavalues[0] = array
         		(
         				'name'					=> "0",
         				'values' 				=> json_encode($content_values),
         				'total_records'			=> count($content_values),
         				'edit_action'			=> "''",
         				'is_paginator'			=> 0,
         				'permission'			=> json_encode($permissions['rowactions']),
         				'footer'				=> 0
         		);*/
         if (count($content_values)) {
             return json_encode($content_values);
         } else {
             return "";
         }
     } else {
         if (phpgw::get_var('phpgw_return_as') == 'json' && !$get_items) {
             $alarm_data = $this->bocommon->initiate_ui_alarm(array('acl_location' => $this->acl_location, 'alarm_type' => 's_agreement', 'type' => 'form', 'text' => 'Email notification', 'times' => isset($times) ? $times : '', 'id' => $id, 'method' => isset($method) ? $method : '', 'data' => isset($data) ? $data : '', 'account_id' => isset($account_id) ? $account_id : ''));
             //$alarm_data['values'] = array();
             if (count($alarm_data['values'])) {
                 return json_encode($alarm_data['values']);
             } else {
                 return "";
             }
         }
     }
     //--------------------JSON code-----
     //_debug_array($id);die;
     $parameters = array('parameter' => array(array('name' => 's_agreement_id', 'source' => $id, 'ready' => 1), array('name' => 'id', 'source' => 'item_id'), array('name' => 'from', 'source' => $view_only ? 'view' : 'edit', 'ready' => 1)));
     $parameters2 = array('parameter' => array(array('name' => 's_agreement_id', 'source' => $id, 'ready' => 1), array('name' => 'id', 'source' => 'item_id')));
     $parameters3 = array('parameter' => array(array('name' => 'id', 'source' => $id, 'ready' => 1), array('name' => 'item_id', 'source' => 'item_id'), array('name' => 'delete_item', 'source' => 1, 'ready' => 1)));
     //_debug_array($parameters3);die;
     /*REQUIRES VALIDATION OF PERMISSIONS*/
     $permissions['rowactions'][] = array('text' => lang('View'), 'action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uis_agreement.view_item')), 'parameters' => $parameters);
     $permissions['rowactions'][] = array('text' => lang('Edit'), 'action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uis_agreement.edit_item')), 'parameters' => $parameters2);
     $permissions['rowactions'][] = array('text' => lang('Delete'), 'action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uis_agreement.edit')), 'confirm_msg' => lang('do you really want to delete this entry'), 'parameters' => $parameters3);
     $content_values = array();
     for ($y = 0; $y < count($content); $y++) {
         for ($z = 0; $z < count($content[$y]['row']); $z++) {
             if ($content[$y]['row'][$z + 1]['name'] != '') {
                 $content_values[$y][$content[$y]['row'][$z + 1]['name']] = $content[$y]['row'][$z + 1]['value'];
             }
         }
     }
     //------- alarm--------
     $datavalues[0] = array('name' => "0", 'values' => json_encode($alarm_data['values']), 'total_records' => count($alarm_data['values']), 'is_paginator' => 0, 'permission' => '""', 'footer' => 0);
     $myColumnDefs[0] = array('name' => "0", 'values' => json_encode(array(array('key' => 'time', 'label' => $alarm_data['header'][0]['lang_time'], 'sortable' => true, 'resizeable' => true, 'width' => 140), array('key' => 'text', 'label' => $alarm_data['header'][0]['lang_text'], 'sortable' => true, 'resizeable' => true, 'width' => 340), array('key' => 'user', 'label' => $alarm_data['header'][0]['lang_user'], 'sortable' => true, 'resizeable' => true, 'width' => 200), array('key' => 'enabled', 'label' => $alarm_data['header'][0]['lang_enabled'], 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterCenter', 'width' => 60), array('key' => 'alarm_id', 'label' => "dummy", 'sortable' => true, 'resizeable' => true, 'hidden' => true), array('key' => 'select', 'label' => $alarm_data['header'][0]['lang_select'], 'sortable' => false, 'resizeable' => false, 'formatter' => 'myFormatterCheck', 'width' => 60))));
     $myButtons[0] = array('name' => "0", 'values' => json_encode(array(array('id' => 'values[enable_alarm]', 'type' => 'buttons', 'value' => 'Enable', 'label' => $alarm_data[alter_alarm][0][lang_enable], 'funct' => 'onActionsClick', 'classname' => 'actionButton', 'value_hidden' => ""), array('id' => 'values[disable_alarm]', 'type' => 'buttons', 'value' => 'Disable', 'label' => $alarm_data[alter_alarm][0][lang_disable], 'funct' => 'onActionsClick', 'classname' => 'actionButton', 'value_hidden' => ""), array('id' => 'values[delete_alarm]', 'type' => 'buttons', 'value' => 'Delete', 'label' => $alarm_data[alter_alarm][0][lang_delete], 'funct' => 'onActionsClick', 'classname' => 'actionButton', 'value_hidden' => ""))));
     $myButtons[1] = array('name' => "1", 'values' => json_encode(array(array('id' => 'values[time][days]', 'type' => 'menu', 'value' => $this->bocommon->make_menu_date($alarm_data['add_alarm']['day_list'], "1_0", 'values[time][days]'), 'label' => "0", 'classname' => 'actionsFilter', 'value_hidden' => "0"), array('id' => 'values[time][hours]', 'type' => 'menu', 'value' => $this->bocommon->make_menu_date($alarm_data['add_alarm']['hour_list'], "1_1", 'values[time][hours]'), 'label' => "0", 'classname' => 'actionsFilter', 'value_hidden' => "0"), array('id' => 'values[time][mins]', 'type' => 'menu', 'value' => $this->bocommon->make_menu_date($alarm_data['add_alarm']['minute_list'], "1_2", 'values[time][mins]'), 'label' => "0", 'classname' => 'actionsFilter', 'value_hidden' => "0"), array('id' => 'values[user_id]', 'type' => 'menu', 'value' => $this->bocommon->make_menu_user($alarm_data['add_alarm']['user_list'], "1_3", 'values[user_id]'), 'label' => $this->bocommon->choose_select($alarm_data['add_alarm']['user_list'], "name"), 'classname' => 'actionsFilter', 'value_hidden' => $this->bocommon->choose_select($alarm_data['add_alarm']['user_list'], "id")), array('id' => 'values[add_alarm]', 'type' => 'buttons', 'value' => 'Add', 'label' => $alarm_data['add_alarm']['lang_add'], 'funct' => 'onAddClick', 'classname' => 'actionButton', 'value_hidden' => ""))));
     /*
     _debug_array(array( array('id' =>'values[time][days]', 'type'=>'menu',  'value'=>$this->bocommon->make_menu_date($alarm_data['add_alarm']['day_list'],"1_0",'values[time][days]' ), 'label'=>"0", 'classname'=> 'actionsFilter', 'value_hidden'=>"0"),
     													array('id' =>'values[time][hours]', 'type'=>'menu',  'value'=>$this->bocommon->make_menu_date($alarm_data['add_alarm']['hour_list'],"1_1",'values[time][hours]'), 'label'=>"0", 'classname'=> 'actionsFilter', 'value_hidden'=>"0"),
     													array('id' =>'values[time][mins]', 'type'=>'menu',  'value'=>$this->bocommon->make_menu_date($alarm_data['add_alarm']['minute_list'],"1_2",'values[time][mins]'), 'label'=>"0", 'classname'=> 'actionsFilter', 'value_hidden'=>"0"),
     													array('id' =>'values[user_id]',  'type'=>'menu',  'value'=>$this->bocommon->make_menu_user($alarm_data['add_alarm']['user_list'],"1_3",'values[user_id]'), 'label'=>$this->bocommon->choose_select($alarm_data['add_alarm']['user_list'],"name"),'classname'=> 'actionsFilter', 'value_hidden'=>$this->bocommon->choose_select($alarm_data['add_alarm']['user_list'],"id")),
     													array('id' =>'values[add_alarm]',  'type'=>'buttons', 'value'=>'Add',  'label'=>$alarm_data['add_alarm']['lang_add'],   'funct'=> 'onAddClick' , 'classname'=> 'actionButton', 'value_hidden'=>"")));
     die();
     */
     //---------items------------------------------------
     $datavalues[1] = array('name' => "1", 'values' => json_encode($content_values), 'total_records' => count($content_values), 'is_paginator' => 0, 'permission' => json_encode($permissions['rowactions']), 'footer' => 0);
     $td_count = 0;
     $ColumnDefs_data = array();
     if (isset($uicols['input_type']) && $uicols['input_type']) {
         foreach ($uicols['input_type'] as $key => $input_type) {
             if ($input_type != 'hidden') {
                 $ColumnDefs_data[] = array('key' => $uicols['name'][$key], 'label' => $uicols['descr'][$key], 'sortable' => true, 'resizeable' => true);
                 $td_count++;
             }
         }
     }
     $ColumnDefs_data[] = array('key' => 'update', 'label' => lang('Update'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'myFormatterCheckUpdate');
     //_debug_array($ColumnDefs_data);
     $myColumnDefs[1] = array('name' => "1", 'values' => json_encode($ColumnDefs_data));
     unset($ColumnDefs_data);
     $myButtons[2] = array('name' => "2", 'values' => json_encode(array(array('type' => 'text', 'label' => ' New index:', 'classname' => 'index-opt'), array('id' => 'values[new_index]', 'type' => 'inputText', 'size' => 12, 'classname' => 'index-opt'), array('id' => 'values[update]', 'type' => 'buttons', 'value' => 'Update', 'label' => 'Update', 'funct' => 'onUpdateClick', 'classname' => ''))));
     $link_view_file = $GLOBALS['phpgw']->link('/index.php', $link_file_data);
     for ($z = 0; $z < count($values['files']); $z++) {
         if ($link_to_files != '') {
             $content_files[$z]['file_name'] = '<a href="' . $link_to_files . '/' . $values['files'][$z]['directory'] . '/' . $values['files'][$z]['file_name'] . '" target="_blank" title="' . lang('click to view file') . '">' . $values['files'][$z]['name'] . '</a>';
         } else {
             $content_files[$z]['file_name'] = '<a href="' . $link_view_file . '&amp;file_name=' . $values['files'][$z]['file_name'] . '" target="_blank" title="' . lang('click to view file') . '">' . $values['files'][$z]['name'] . '</a>';
         }
         $content_files[$z]['delete_file'] = '<input type="checkbox" name="values[file_action][]" value="' . $values['files'][$z]['name'] . '" title="' . lang('Check to delete file') . '">';
     }
     $datavalues[2] = array('name' => "2", 'values' => json_encode($content_files), 'total_records' => count($content_files), 'permission' => "''", 'is_paginator' => 0, 'footer' => 0);
     $myColumnDefs[2] = array('name' => "2", 'values' => json_encode(array(array('key' => 'file_name', 'label' => lang('Filename'), 'sortable' => false, 'resizeable' => true), array('key' => 'delete_file', 'label' => lang('Delete file'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'))));
     if ($id) {
         $content_budget = $this->bo->get_budget($id);
         $lang_delete = lang('Check to delete year');
         foreach ($content_budget as &$b_entry) {
             $b_entry['delete_year'] = "<input type='checkbox' name='values[delete_b_year][]' value='{$b_entry['year']}' title='{$lang_delete}'>";
         }
     }
     $datavalues[3] = array('name' => "3", 'values' => json_encode($content_budget), 'total_records' => count($content_budget), 'permission' => "''", 'is_paginator' => 0, 'footer' => 1);
     $myColumnDefs[3] = array('name' => "3", 'values' => json_encode(array(array('key' => 'year', 'label' => lang('year'), 'sortable' => false, 'resizeable' => true), array('key' => 'category', 'label' => lang('category'), 'sortable' => false, 'resizeable' => true), array('key' => 'ecodimb', 'label' => lang('dimb'), 'sortable' => false, 'resizeable' => true), array('key' => 'budget_account', 'label' => lang('budget account'), 'sortable' => false, 'resizeable' => true), array('key' => 'budget', 'label' => lang('budget'), 'sortable' => false, 'resizeable' => true), array('key' => 'actual_cost', 'label' => lang('actual cost'), 'sortable' => false, 'resizeable' => true), array('key' => 'delete_year', 'label' => lang('Delete'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'))));
     //--------------------------------------------JSON CODE------------
     $this->cats->set_appname('property', '.project');
     $data = array('td_count' => $td_count, 'property_js' => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . "/property/js/yahoo/property2.js"), 'base_java_url' => json_encode(array('menuaction' => "property.uis_agreement.edit", 'id' => $id)), 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'myButtons' => $myButtons, 'link_import' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uis_agreement.import', 'tab' => 'items')), 'alarm_data' => $alarm_data, 'lang_alarm' => lang('Alarm'), 'lang_download' => 'download', 'link_download' => $GLOBALS['phpgw']->link('/index.php', $link_download), 'lang_download_help' => lang('Download table to your browser'), 'fileupload' => true, 'link_view_file' => $GLOBALS['phpgw']->link('/index.php', $link_file_data), 'link_to_files' => $link_to_files, 'files' => $values['files'], 'lang_files' => lang('files'), 'lang_filename' => lang('Filename'), 'lang_file_action' => lang('Delete file'), 'lang_view_file_statustext' => lang('click to view file'), 'lang_file_action_statustext' => lang('Check to delete file'), 'lang_upload_file' => lang('Upload file'), 'lang_file_statustext' => lang('Select file to upload'), 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'edit_url' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'lang_id' => lang('ID'), 'value_s_agreement_id' => $id, 'lang_category' => lang('category'), 'lang_save' => lang('save'), 'lang_cancel' => lang('cancel'), 'lang_apply' => lang('apply'), 'value_cat' => $values['cat'], 'lang_apply_statustext' => lang('Apply the values'), 'lang_cancel_statustext' => lang('Leave the service agreement untouched and return back to the list'), 'lang_save_statustext' => lang('Save the service agreement and return back to the list'), 'lang_no_cat' => lang('no category'), 'lang_cat_statustext' => lang('Select the category the s_agreement belongs to. To do not use a category select NO CATEGORY'), 'select_name' => 'values[cat_id]', 'cat_list' => $this->bocommon->select_category_list(array('format' => 'select', 'selected' => $this->cat_id, 'type' => 's_agreement', 'order' => 'descr')), 'member_of_list2' => $member_of_list, 'attributes_group' => $attributes, 'lookup_functions' => $values['lookup_functions'], 'dateformat' => $dateformat, 'lang_start_date_statustext' => lang('Select the estimated end date for the Project'), 'lang_start_date' => lang('start date'), 'value_start_date' => $values['start_date'], 'lang_end_date_statustext' => lang('Select the estimated end date for the Project'), 'lang_end_date' => lang('end date'), 'value_end_date' => $values['end_date'], 'lang_termination_date_statustext' => lang('Select the estimated termination date'), 'lang_termination_date' => lang('termination date'), 'value_termination_date' => $values['termination_date'], 'vendor_data' => $vendor_data, 'lang_budget' => lang('Budget'), 'lang_budget_statustext' => lang('Budget for selected year'), 'value_budget' => $values['budget'], 'currency' => $GLOBALS['phpgw_info']['user']['preferences']['common']['currency'], 'lang_year' => lang('year'), 'lang_year_statustext' => lang('Budget year'), 'year' => $this->bocommon->select_list($values['year'], $this->bo->get_year_list($id)), 'b_account_data' => $b_account_data, 'ecodimb_data' => $ecodimb_data, 'lang_category' => lang('category'), 'lang_no_cat' => lang('Select category'), 'cat_select' => $this->cats->formatted_xslt_list(array('select_name' => 'values[order_category]', 'selected' => $values['order_category'])), 'lang_name' => lang('name'), 'lang_name_statustext' => lang('name'), 'value_name' => $values['name'], 'lang_descr' => lang('descr'), 'lang_descr_statustext' => lang('descr'), 'value_descr' => $values['descr'], 'table_add' => $table_add, 'values' => $content, 'table_header' => $table_header, 'acl_manage' => $this->acl_manage, 'table_update' => $table_update, 'update_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uis_agreement.edit', 'id' => $id)), 'lang_select_all' => lang('Select All'), 'img_check' => $GLOBALS['phpgw']->common->get_image_path('property') . '/check.png', 'set_column' => $set_column, 'lang_import_detail' => lang('import detail'), 'lang_detail_import_statustext' => lang('import details to this agreement from spreadsheet'), 'lang_import' => lang('import'), 'textareacols' => isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] : 40, 'textarearows' => isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] : 6, 'tabs' => phpgwapi_yui::tabview_generate($tabs, $active_tab));
     //_debug_array($data);die;
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('menu');
     phpgwapi_yui::load_widget('connection');
     phpgwapi_yui::load_widget('loader');
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_yui::load_widget('animation');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('service agreement') . ': ' . ($id ? lang('edit') . ' ' . lang($this->role) : lang('add') . ' ' . lang($this->role));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('edit' => $data));
     $GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
     $GLOBALS['phpgw']->js->validate_file('yahoo', 'uis_agreement.edit', 'property');
 }
 function index()
 {
     $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
     $receipt = array();
     if (phpgw::get_var('phpgw_return_as') == 'json') {
         return $this->query();
     }
     $msgbox_data = array();
     if (phpgw::get_var('phpgw_return_as') != 'json' && ($receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))) {
         phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
         $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($receipt);
         $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
     }
     $myColumnDefs = array();
     $datavalues = array();
     $myButtons = array();
     $datavalues[] = array('name' => "0", 'values' => json_encode(array()), 'total_records' => 0, 'permission' => "''", 'is_paginator' => 1, 'edit_action' => "''", 'footer' => 0);
     $myColumnDefs[0] = array('name' => "0", 'values' => json_encode(array()));
     $GLOBALS['phpgw']->translation->add_app('property');
     $district_list = $this->bocommon->select_district_list('filter', $this->district_id);
     $part_of_town_list = execMethod('property.bogeneric.get_list', array('type' => 'part_of_town', 'selected' => $part_of_town_id));
     $location_type_list = execMethod('property.soadmin_location.select_location_type');
     array_unshift($district_list, array('id' => '', 'name' => lang('select')));
     array_unshift($part_of_town_list, array('id' => '', 'name' => lang('select')));
     array_unshift($location_type_list, array('id' => '', 'name' => lang('select')));
     $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
     $cats->supress_info = true;
     $control_area = $cats->formatted_xslt_list(array('format' => 'filter', 'globals' => true, 'use_acl' => $this->_category_acl));
     $control_area_list = array();
     foreach ($control_area['cat_list'] as $cat_list) {
         $control_area_list[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name']);
     }
     array_unshift($control_area_list, array('id' => '', 'name' => lang('select')));
     $data = array('td_count' => '""', 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'myButtons' => $myButtons, 'msgbox_data' => $msgbox_data, 'control_area_list' => array('options' => $control_area_list), 'filter_form' => array('control_area_list' => array('options' => $control_area_list), 'district_list' => array('options' => $district_list), 'part_of_town_list' => array('options' => $part_of_town_list), 'location_type_list' => array('options' => $location_type_list)), 'update_action' => self::link(array('menuaction' => 'controller.uicontrol_register_to_location.edit_location')));
     phpgwapi_jquery::load_widget('core');
     phpgwapi_jquery::load_widget('autocomplete');
     self::add_javascript('controller', 'controller', 'ajax_control_to_location.js');
     self::add_javascript('controller', 'yahoo', 'register_control.js');
     self::render_template_xsl(array('control_location/register_control_to_location'), $data);
 }
 function add_component_to_control()
 {
     if (phpgw::get_var('save_component')) {
         //add component to control using component item ID
         $items_checked = array();
         $items = phpgw::get_var('values_assign');
         $item_arr = explode('|', $items);
         foreach ($item_arr as $item) {
             $items_checked[] = explode(';', $item);
         }
         //var_dump($items_checked);
         $control_id = phpgw::get_var('control_id');
         //var_dump($control_id);
         if ($control_id != null && is_numeric($control_id)) {
             //add chosen component to control
             foreach ($items_checked as $it) {
                 $this->so_control->add_component_to_control($control_id, $it[0]);
             }
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicheck_list_for_component.index'));
     } else {
         if (phpgw::get_var('phpgw_return_as') == 'json') {
             return $this->get_component();
         }
         $bim_types = $this->so_control->get_bim_types();
         $control_areas_array = $this->so_control_area->get_control_areas_as_array();
         $tabs = array(array('label' => lang('View_component_for_control'), 'link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'controller.uicheck_list_for_component.index'))), array('label' => lang('Add_component_for_control')));
         $data = array('tabs' => $GLOBALS['phpgw']->common->create_tabs($tabs, 1), 'view' => "add_component_to_control", 'control_filters' => array('control_area_array' => $control_areas_array, 'control_array' => $control_array), 'filter_form' => array('bim_types' => $bim_types), 'datatable' => array('source' => self::link(array('menuaction' => 'controller.uicheck_list_for_component.add_component_to_control', 'phpgw_return_as' => 'json')), 'field' => array(array('key' => 'id', 'label' => lang('ID'), 'sortable' => true, 'formatter' => 'YAHOO.portico.formatLink'), array('key' => 'guid', 'label' => lang('GUID'), 'sortable' => false), array('key' => 'type', 'label' => lang('type'), 'sortable' => false), array('key' => 'checked', 'label' => 'Velg', 'sortable' => false, 'formatter' => 'YAHOO.widget.DataTable.formatCheckbox', 'className' => 'mychecks'), array('key' => 'actions', 'hidden' => true), array('key' => 'labels', 'hidden' => true), array('key' => 'ajax', 'hidden' => true))));
         phpgwapi_yui::load_widget('paginator');
         phpgwapi_jquery::load_widget('core');
         self::add_javascript('controller', 'yahoo', 'control_tabs.js');
         self::add_javascript('controller', 'controller', 'ajax.js');
         self::render_template_xsl(array('control_component_tabs', 'common', 'add_component_to_control'), $data);
     }
 }
 public function assign_job()
 {
     $assign_requirement_json = str_replace('&quot;', '"', phpgw::get_var('assign_requirement'));
     $assign_requirement = json_decode($assign_requirement_json);
     //_debug_array($assign_requirement);die();
     if (!$assign_requirement || !is_array($assign_requirement)) {
         echo 'Nothing to do';
         return;
     }
     $allocations = array();
     foreach ($assign_requirement as $assign_entry) {
         $assign_arr = explode('_', $assign_entry);
         $requirement_id = $assign_arr[0];
         $allocation_id = $assign_arr[1];
         $location_id = $assign_arr[2];
         $item_id = $assign_arr[3];
         $inventory_id = (int) $assign_arr[4];
         $allocations[] = $this->so_resource_allocation->get_single($allocation_id);
     }
     $requirement = $this->so->get_single($requirement_id);
     $custom = createObject('phpgwapi.custom_fields');
     //--
     $_filters = array('requirement_id' => $requirement_id);
     $requirement_values_array = $this->so_requirement_value->get(0, false, $sort_field, $sort_ascending, $search_for, $search_type, $_filters);
     $location_id = $requirement->get_location_id();
     $criterias = array();
     if (count($requirement_values_array) > 0) {
         foreach ($requirement_values_array as $requirement_value) {
             $loc_arr = $GLOBALS['phpgw']->locations->get_name($location_id);
             $cust_attribute_id = $requirement_value->get_cust_attribute_id();
             $attrib_data = $custom->get('property', $loc_arr['location'], $cust_attribute_id);
             $_criterie = $attrib_data['input_text'];
             if (isset($attrib_data['choice'])) {
                 foreach ($attrib_data['choice'] as $_choice) {
                     if ($_choice['id'] == $requirement_value->get_value()) {
                         $_criterie .= "::{$_choice['value']}";
                         break;
                     }
                 }
             } else {
                 if ($requirement_value->get_value()) {
                     $_criterie .= "::{$requirement_value->get_value()}";
                 }
             }
             $criterias[] = $_criterie;
             //					$operator	= $requirement_value->get_operator();
         }
     }
     $path = $this->so_activity->get_path($requirement->get_activity_id());
     $breadcrumb_array = array();
     foreach ($path as $menu_item) {
         $breadcrumb_array[] = $menu_item['name'];
     }
     $title = implode(' -> ', $breadcrumb_array);
     $message .= 'Hvor: ' . $title . "\n\n";
     $requirement_descr = $loc_arr['descr'] . '::' . implode(',', $criterias);
     $message .= 'Hva: ' . $requirement_descr . "\n\n";
     #FIXME timezone..
     //$GLOBALS['phpgw']->common->show_date($requirement->get_start_date())
     //$message .= 'Frist:' . $GLOBALS['phpgw']->common->show_date($requirement->get_start_date()) . "\n\n";
     $datetime_format = "{$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']} H:i";
     $when = date($datetime_format, $requirement->get_start_date());
     $message .= 'Frist: ' . $when . "\n\n";
     foreach ($allocations as $allocation) {
         $message .= 'Antall: ';
         $message .= $allocation->get_allocated_amount();
         $message .= ' Fra: ';
         if ($allocation->get_inventory_id()) {
             $inventory = execMethod('property.soentity.get_inventory', array('inventory_id' => $allocation->get_inventory_id()));
             $system_location = $GLOBALS['phpgw']->locations->get_name($inventory[0]['p_location_id']);
             $name = 'N∕A';
             if (preg_match('/.location./i', $system_location['location'])) {
                 $location_code = execMethod('property.solocation.get_location_code', $inventory[0]['p_id']);
                 $location = execMethod('property.solocation.read_single', $location_code);
                 $location_arr = explode('-', $location_code);
                 $i = 1;
                 $name_arr = array();
                 foreach ($location_arr as $_dummy) {
                     $name_arr[] = $location["loc{$i}_name"];
                     $i++;
                 }
                 $name = implode('::', $name_arr);
             } else {
                 if (preg_match('/.entity./i', $system_location['location'])) {
                     $name = execMethod('property.soentity.get_short_description', array('location_id' => $inventory[0]['p_location_id'], 'id' => $inventory[0]['p_id']));
                 }
             }
         }
         $message .= "{$name} ({$location_code})\n";
     }
     // --------
     $catsObj = CreateObject('phpgwapi.categories', -1, 'property', '.ticket');
     $catsObj->supress_info = true;
     $categories = $catsObj->formatted_xslt_list(array('select_name' => 'values[cat_id]', 'selected' => $this->cat_id, 'use_acl' => $this->_category_acl));
     $data = array('requirement_id' => $requirement_id, 'title' => $title, 'title_size' => strlen($title) > 20 ? strlen($title) : 20, 'categories' => $categories, 'assign_requirement_json' => $assign_requirement_json, 'requirement_descr' => $requirement_descr, 'message' => $message, 'priority_list' => array('options' => execMethod('property.botts.get_priority_list')));
     if (count($buildings_array) > 0) {
         $data['buildings_array'] = $buildings_array;
     } else {
         $data['building_array'] = $building_array;
     }
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('logistic', 'logistic', 'assign_job.js');
     self::render_template_xsl(array('allocation/assign_job'), $data);
     //------
 }
 public function edit()
 {
     $entity_so = CreateObject('property.soadmin_entity');
     $custom = createObject('phpgwapi.custom_fields');
     $location_id = phpgw::get_var('location_id');
     $project_type_id = phpgw::get_var('project_type_id');
     if ($location_id) {
         $req_types = $this->so->get(null, null, null, null, null, null, array('location_id' => $location_id, 'project_type_id' => $project_type_id));
         if (count($req_types) > 0) {
             $keys = array_keys($req_types);
             $req_type = $req_types[$keys[0]];
         }
     } else {
         $req_type = new logistic_resource_type_requirement();
     }
     if (isset($_POST['save'])) {
         $entity_id = phpgw::get_var('entity_id');
         $category_id = phpgw::get_var('category_id');
         $location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$category_id}");
         $req_type->set_location_id($location_id);
         $req_type->set_project_type_id(phpgw::get_var('project_type_id'));
         $cust_attr_ids = phpgw::get_var('attributes');
         $selected_attributes[] = array();
         $req_type_array = $this->so->get(null, null, null, null, null, null, array('location_id' => $location_id, 'project_type_id' => $project_type_id));
         $req_types_for_delete = array();
         if (count($req_type_array) > 0) {
             foreach ($req_type_array as $rt) {
                 if (!in_array($rt->get_cust_attribute_id(), $cust_attr_ids)) {
                     $req_types_for_delete[] = $rt;
                 }
                 $selected_attributes[] = $rt->get_cust_attribute_id();
             }
             foreach ($cust_attr_ids as $attr) {
                 if (!in_array($attr, $selected_attributes)) {
                     $req_type_new = new logistic_resource_type_requirement();
                     $req_type_new->set_location_id($location_id);
                     $req_type_new->set_project_type_id(phpgw::get_var('project_type_id'));
                     $req_type_new->set_cust_attribute_id($attr);
                     $req_type_new_id = $this->so->store($req_type_new);
                 }
             }
             foreach ($req_types_for_delete as $del_req_type) {
                 $this->so->delete($del_req_type);
             }
         } else {
             foreach ($cust_attr_ids as $attr) {
                 $req_type->set_cust_attribute_id($attr);
                 $req_type_id = $this->so->store($req_type);
             }
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'logistic.uiresource_type_requirement.view', 'location_id' => $location_id, 'project_type_id' => $req_type->get_project_type_id()));
     } else {
         if (isset($_POST['cancel'])) {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'logistic.uiresource_type_requirement.index'));
         } else {
             $entity_list = execMethod('property.soadmin_entity.read', array('allrows' => true));
             array_unshift($entity_list, array('id' => '', 'name' => lang('select value')));
             if ($location_id) {
                 $loc_arr = $GLOBALS['phpgw']->locations->get_name($location_id);
                 $entity_arr = explode('.', $loc_arr['location']);
                 $entity = $entity_so->read_single($entity_arr[2]);
                 $category = $entity_so->read_single_category($entity_arr[2], $entity_arr[3]);
                 foreach ($entity_list as &$e) {
                     if ($e['id'] == $entity['id']) {
                         $e['selected'] = 1;
                     }
                 }
                 $category_list = $entity_so->read_category(array('allrows' => true, 'entity_id' => $entity_arr[2]));
                 foreach ($category_list as &$c) {
                     if ($c['id'] == $category['id']) {
                         $c['selected'] = 1;
                     }
                 }
                 $attributes = $custom->find('property', ".entity.{$entity_arr[2]}.{$entity_arr[3]}", 0, '', '', '', true, true);
                 $selected_attributes = $this->so->get_selected_attributes($location_id, $project_type_id);
                 foreach ($attributes as &$a) {
                     if (in_array($a['id'], $selected_attributes)) {
                         $a['checked'] = 'checked';
                     }
                 }
             }
             $project_type_array = $this->so_project->get_project_types($req_type->get_project_type_id());
             $data = array('value_id' => !empty($req_type) ? $req_type->get_id() : 0, 'entities' => $entity_list, 'categories' => $category_list, 'attributes' => $attributes, 'project_types' => $project_type_array, 'editable' => true, 'req_type' => $req_type);
             $GLOBALS['phpgw_info']['flags']['app_header'] = lang('logistic') . '::' . lang('Project type');
             phpgwapi_jquery::load_widget('core');
             self::add_javascript('logistic', 'logistic', 'resource_type_requirement.js');
             self::render_template_xsl(array('project/resource_type_requirement_item'), $data);
         }
     }
 }
 /**
  * Prepare data for view and edit - depending on mode
  *
  * @param int    $cat_id  type of documents
  * @param string $mode    edit or view
  *
  * @return void
  */
 public function edit($cat_id = 0, $mode = 'edit')
 {
     if (!$cat_id) {
         $cat_id = phpgw::get_var('cat_id', 'int');
     }
     if (!$this->acl_add && !$this->acl_edit) {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'manual.uidocuments.view', 'cat_id' => $cat_id));
     }
     if ($mode == 'view') {
         $GLOBALS['phpgw_info']['flags']['menu_selection'] = "manual::view";
         if (!$this->acl_read) {
             $this->bocommon->no_access();
             return;
         }
     } else {
         if (!$this->acl_add && !$this->acl_edit) {
             $this->bocommon->no_access();
             return;
         }
     }
     $categories = $this->_get_categories($cat_id);
     $msgbox_data = $this->bocommon->msgbox_data($this->receipt);
     $file_def = array(array('key' => 'file_name', 'label' => lang('Filename'), 'sortable' => false, 'resizeable' => true));
     if ($mode == 'edit') {
         $file_def[1] = array('key' => 'delete_file', 'label' => lang('Delete file'), 'sortable' => false, 'resizeable' => true);
     }
     $datatable_def = array();
     $datatable_def[] = array('container' => 'datatable-container_0', 'requestUrl' => json_encode(self::link(array('menuaction' => 'manual.uidocuments.get_files', 'cat_id' => $cat_id, 'phpgw_return_as' => 'json'))), 'ColumnDefs' => $file_def);
     $data = array('datatable_def' => $datatable_def, 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'categories' => array('options' => $categories), 'editable' => $mode == 'edit', 'multiple_uploader' => $mode == 'edit' ? true : '');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('manual') . '::' . lang('documents');
     if ($mode == 'edit') {
         phpgwapi_jquery::load_widget('core');
         self::add_javascript('phpgwapi', 'yui3', 'yui/yui-min.js');
         self::add_javascript('phpgwapi', 'yui3-gallery', 'gallery-formvalidator/gallery-formvalidator-min.js');
         $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yui3-gallery/gallery-formvalidator/validatorCss.css');
         self::add_javascript('phpgwapi', 'tinybox2', 'packed.js');
         $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
         self::add_javascript('manual', 'portico', 'documents.add.js');
     }
     self::add_javascript('manual', 'portico', 'documents.view.js');
     //			$GLOBALS['phpgw_info']['server']['no_jscombine'] = true;
     self::render_template_xsl(array('documents_add'), $data);
 }
 public function edit($project = null)
 {
     $project_id = phpgw::get_var('id');
     if ($project_id && is_numeric($project_id)) {
         $project = $this->so->get_single($project_id);
     } else {
         if ($project == null) {
             $project = new logistic_project();
         }
     }
     $project_types = $this->so->get_project_types();
     foreach ($project_types as &$p_type) {
         if ($project->get_project_type_id() == $p_type['id']) {
             $p_type['selected'] = 1;
         }
     }
     $data = array('project' => $project, 'options' => $project_types, 'editable' => true);
     $this->use_yui_editor('description');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('logistic') . '::' . lang('Project type');
     $GLOBALS['phpgw']->jqcal->add_listener('start_date');
     $GLOBALS['phpgw']->jqcal->add_listener('end_date');
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('logistic', 'logistic', 'project.js');
     self::render_template_xsl(array('project/project_item'), $data);
 }
    /**
     * Create a menu "bar"
     *
     * @param array   $tabs      list of tabs as an array($id => $tab)
     * @param integer $selection array key of selected tab
     *
     * @return string HTML output string
     */
    public static function menu_generate($tabs, $selection)
    {
        phpgwapi_jquery::load_widget('menu');
        $output = <<<HTML

\t\t\t\t<ul id="menu">
\t\t\t\t<li><a href="#">moduler</a>
\t\t\t\t<ul>
HTML;
        foreach ($tabs as $id => $tab) {
            $selected = $id == $selection ? ' class="selected"' : '';
            $label = $tab['label'];
            $_function = '';
            if (isset($tab['function'])) {
                $_function = " onclick=\"javascript: {$tab['function']};\"";
            }
            if (!isset($tab['link']) && !isset($tab['function'])) {
                $selected = $selected ? $selected : ' class="ui-state-disabled"';
                $output .= <<<HTML

\t\t\t\t\t\t<li{$selected}><a><em>{$label}</em></a></li>
HTML;
            } else {
                $output .= <<<HTML

\t\t\t\t\t\t<li{$selected}><a href="{$tab['link']}"{$_function}><em>{$label}</em></a></li>
HTML;
            }
        }
        $output .= <<<HTML

\t\t\t\t</ul>
\t\t\t\t</li>
\t\t\t\t</ul>

HTML;
        return $output;
    }
 function index()
 {
     $receipt = array();
     $voucher_id = phpgw::get_var('voucher_id', 'int');
     $line_id = phpgw::get_var('line_id', 'int');
     if (phpgw::get_var('phpgw_return_as') == 'json') {
         return $this->query();
     }
     if (isset($this->config->config_data['invoice_acl']) && $this->config->config_data['invoice_acl'] == 'dimb') {
         $janitor_list = $this->bo->get_dimb_role_user(1, '', $janitor);
         $supervisor_list = $this->bo->get_dimb_role_user(2, '', $supervisor);
         $budget_responsible_list = $this->bo->get_dimb_role_user(3, '', $budget_responsible);
     } else {
         $janitor_list = $this->bocommon->get_user_list_right(32, $janitor, '.invoice');
         $supervisor_list = $this->bocommon->get_user_list_right(64, $supervisor, '.invoice');
         $budget_responsible_list = $this->bocommon->get_user_list_right(128, $budget_responsible, '.invoice');
     }
     $userlist_default = array();
     $userlist_default[] = array('id' => '*' . $GLOBALS['phpgw']->accounts->get($this->account_id)->lid, 'name' => lang('mine vouchers'));
     $userlist_default[] = array('id' => '', 'name' => lang('no user'));
     $voucher_list = array();
     if ($voucher_id) {
         $voucher_list = $this->bo->get_vouchers(array('query' => $voucher_id));
     }
     if (!$voucher_list) {
         $voucher_list = array('id' => '', 'name' => lang('select'));
     }
     foreach ($userlist_default as $default) {
         $janitor_list = array_merge(array($default), $janitor_list);
         $supervisor_list = array_merge(array($default), $supervisor_list);
         $budget_responsible_list = array_merge(array($default), $budget_responsible_list);
     }
     $msgbox_data = array();
     if (phpgw::get_var('phpgw_return_as') != 'json' && ($receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))) {
         phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
         $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($receipt);
         $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
     }
     $user = $GLOBALS['phpgw']->accounts->get($GLOBALS['phpgw_info']['user']['id']);
     $myColumnDefs = array();
     $datavalues = array();
     $myButtons = array();
     $datavalues[] = array('name' => "0", 'values' => $this->query(), 'total_records' => 0, 'permission' => "''", 'is_paginator' => 1, 'edit_action' => "''", 'footer' => 0);
     $datatable = array(array('key' => 'id', 'hidden' => true), array('key' => 'approve_line', 'label' => lang('select'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'status_line', 'label' => lang('status'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'amount', 'label' => lang('amount'), 'formatter' => 'FormatterRight', 'sortable' => true), array('key' => 'approved_amount', 'label' => lang('approved amount'), 'sortable' => true, 'formatter' => 'FormatterRight'), array('key' => 'split', 'label' => lang('split line'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'budget_account', 'label' => lang('budget account'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'dima', 'label' => lang('dim a'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'dimb', 'label' => lang('dim b'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'order_id', 'label' => lang('order'), 'sortable' => false, 'formatter' => 'FormatterRight'), array('key' => 'dime', 'label' => lang('dime'), 'sortable' => false, 'formatter' => 'FormatterRight'), array('key' => 'project_group', 'label' => lang('project group'), 'sortable' => false, 'formatter' => 'FormatterRight'), array('key' => 'line_text', 'label' => lang('invoice line text'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'approved_amount_hidden', 'hidden' => true));
     $myColumnDefs[0] = array('name' => "0", 'values' => json_encode($datatable));
     $criteria_list = array(array('id' => 'voucher_id', 'name' => lang('voucher id')), array('id' => 'invoice_id', 'name' => lang('invoice number')), array('id' => 'vendor_id', 'name' => lang('vendor')), array('id' => 'order_id', 'name' => lang('order id')), array('id' => 'b_account', 'name' => lang('budget account')), array('id' => 'dimb', 'name' => lang('dimb')));
     $data = array('td_count' => '""', 'base_java_url' => "{menuaction:'property.uiinvoice2.query'}", 'property_js' => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . "/property/js/yahoo/property2.js"), 'email_base_url' => json_encode($GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiinvoice2.index'), true, true)), 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'myButtons' => $myButtons, 'msgbox_data' => $msgbox_data, 'invoice_layout_config' => json_encode(execMethod('phpgwapi.template_portico.retrieve_local', 'invoice_layout_config')), 'preferences_url' => $GLOBALS['phpgw']->link('/preferences/index.php'), 'preferences_text' => lang('preferences'), 'home_url' => $GLOBALS['phpgw']->link('/home.php'), 'home_text' => lang('home'), 'home_icon' => 'icon icon-home', 'about_url' => $GLOBALS['phpgw']->link('/about.php', array('app' => $GLOBALS['phpgw_info']['flags']['currentapp'])), 'about_text' => lang('about'), 'logout_url' => $GLOBALS['phpgw']->link('/logout.php'), 'logout_text' => lang('logout'), 'user_fullname' => $user->__toString(), 'site_title' => "{$GLOBALS['phpgw_info']['server']['site_title']}", 'filter_form' => array('janitor_list' => array('options' => $janitor_list), 'supervisor_list' => array('options' => $supervisor_list), 'budget_responsible_list' => array('options' => $budget_responsible_list), 'criteria_list' => array('options' => $criteria_list)), 'filter_invoice' => array('voucher_list' => array('options' => $voucher_list)), 'voucher_info' => $this->get_single_line($line_id), 'update_action' => self::link(array('menuaction' => 'property.uiinvoice2.update_voucher')));
     //_debug_array($data);die();
     $GLOBALS['phpgw_info']['flags']['noframework'] = true;
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/layout/assets/skins/sam/layout.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
     phpgwapi_yui::load_widget('layout');
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('menu');
     phpgwapi_yui::load_widget('connection');
     phpgwapi_yui::load_widget('loader');
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_yui::load_widget('animation');
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('property', 'portico', 'ajax_invoice.js');
     self::add_javascript('property', 'yahoo', 'invoice2.index.js');
     self::add_javascript('phpgwapi', 'tinybox2', 'packed.js');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
     $GLOBALS['phpgw']->xslttpl->add_file(array('invoice2'));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('data' => $data));
 }
 /**
  * Initiate rich text editor for selected targets
  * @param array $targets
  */
 public function rich_text_editor($targets)
 {
     if (!is_array($targets)) {
         $targets = array($targets);
     }
     foreach ($targets as $target) {
         phpgwapi_jquery::init_ckeditor($target);
     }
 }
 function step2($errors = array(), $r_reg = '', $o_reg = '', $missing_fields = '')
 {
     phpgwapi_jquery::load_widget('core');
     $GLOBALS['phpgw']->js->validate_file('portico', 'ajax', 'registration');
     $show_password_prompt = True;
     $select_password = $this->bo->check_select_password();
     if (is_string($select_password)) {
         $this->simple_screen('error_general.tpl', $select_password);
     } elseif (!$select_password) {
         $show_password_prompt = False;
     }
     $this->header();
     $this->template->set_file(array('_personal_info' => 'personal_info.tpl'));
     $this->template->set_block('_personal_info', 'form');
     $tpl_vars = array('css' => $GLOBALS['phpgw']->common->get_css(), 'javascript' => $GLOBALS['phpgw']->common->get_javascript(), 'str_base_url' => $GLOBALS['phpgw']->link('/', array('logindomain' => $_REQUEST['logindomain']), true));
     $this->template->set_var($tpl_vars);
     if ($missing_fields) {
         while (list(, $field) = each($missing_fields)) {
             $missing[$field] = True;
             $this->template->set_var('missing_' . $field, '<font color="#CC0000">*</font>');
         }
     }
     if (is_array($r_reg)) {
         while (list($name, $value) = each($r_reg)) {
             $post_values[$name] = $value;
             $this->template->set_var('value_' . $name, $value);
         }
     }
     if (is_array($o_reg)) {
         while (list($name, $value) = each($o_reg)) {
             $post_values[$name] = $value;
             $this->template->set_var('value_' . $name, $value);
         }
     }
     //----
     if ($this->config['username_is'] == 'email') {
         $this->template->set_var('message', lang('username as email'));
         $username_fields = $this->get_username_fields();
         $username_fields['lang_username'] = '******' . lang('username') . '</b>';
         $username_fields['value_username'] = $GLOBALS['phpgw']->session->appsession('loginid', 'registration');
         $this->template->set_var($username_fields);
     } else {
         $this->template->set_block('form', 'username', 'empty');
     }
     //-------
     if ($errors) {
         $this->template->set_var('errors', $GLOBALS['phpgw']->common->error_list($errors));
     }
     $this->template->set_var('form_action', $GLOBALS['phpgw']->link('/registration/main.php', array('menuaction' => 'registration.boreg.step2', 'logindomain' => $_REQUEST['logindomain'])));
     $this->template->set_var('lang_password', lang('Password'));
     $this->template->set_var('lang_reenter_password', lang('Re-enter password'));
     $this->template->set_var('lang_submit', lang('Submit'));
     if (!$show_password_prompt) {
         $this->template->set_block('form', 'password', 'empty');
     }
     $this->template->set_block('form', 'other_fields_proto', 'other_fields_list');
     reset($this->fields);
     //_debug_array($this->fields);
     foreach ($this->fields as $num => $field_info) {
         $input_field = $this->get_input_field($field_info, $post_values);
         $var = array('missing_indicator' => $missing[$field_info['field_name']] ? '<font color="#CC0000">*</font>' : '', 'bold_start' => $field_info['field_required'] == 'Y' ? '<b>' : '', 'bold_end' => $field_info['field_required'] == 'Y' ? '</b>' : '', 'lang_displayed_text' => ltrim(lang($field_info['field_text']), '!'), 'input_field' => $input_field);
         $this->template->set_var($var);
         $this->template->parse('other_fields_list', 'other_fields_proto', True);
     }
     if ($this->config['display_tos']) {
         $this->template->set_var('tos_link', $GLOBALS['phpgw']->link('/registration/main.php', array('menuaction' => 'registration.uireg.tos', 'logindomain' => $_REQUEST['logindomain'])));
         $this->template->set_var('lang_tos_agree', lang('I have read the terms and conditions and agree by them.'));
         if ($r_reg['tos_agree']) {
             $this->template->set_var('value_tos_agree', 'checked');
         }
     } else {
         $this->template->set_block('form', 'tos', 'blank');
     }
     $this->template->pfp('out', 'form');
     $this->footer();
 }
 public function edit($control_item = null)
 {
     // NO REDIRECT
     if ($control_item == null) {
         $control_item_id = phpgw::get_var('id');
         // Edit control item
         if ($control_item_id > 0) {
             $control_item = $this->so->get_single_with_options($control_item_id);
         } else {
             $control_item = new controller_control_item();
         }
     }
     // Sigurd: START as categories
     $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
     $cats->supress_info = true;
     $control_areas = $cats->formatted_xslt_list(array('format' => 'filter', 'globals' => true, 'use_acl' => $this->_category_acl));
     $control_areas_array = $control_areas['cat_list'];
     $control_groups_array = $this->so_control_group->get_control_group_array();
     // Hack to fix display of &nbsp; char
     $what_to_do_fixed = str_replace("&nbsp;", " ", $control_item->get_what_to_do());
     $control_item->set_what_to_do($what_to_do_fixed);
     $how_to_do_fixed = str_replace("&nbsp;", " ", $control_item->get_how_to_do());
     $control_item->set_how_to_do($how_to_do_fixed);
     $data = array('editable' => true, 'control_item' => $control_item, 'control_areas' => $control_areas_array, 'control_groups' => $control_groups_array);
     $this->use_yui_editor(array('what_to_do', 'how_to_do'));
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'controller', 'ajax.js');
     self::render_template_xsl('control_item/control_item', $data);
 }
 function edit($mode = 'edit')
 {
     $id = (int) phpgw::get_var('id', 'int');
     if ($mode == 'edit' && (!$this->acl_add && !$this->acl_edit)) {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiproject.view', 'id' => $id));
     }
     if ($mode == 'view') {
         if (!$this->acl_read) {
             $this->bocommon->no_access();
             return;
         }
         if (!$id) {
             phpgwapi_cache::message_set('ID is required for the function uiproject::view()', 'error');
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiproject.index'));
         }
     } else {
         if (!$this->acl_add && !$this->acl_edit) {
             $this->bocommon->no_access();
             return;
         }
     }
     $GLOBALS['phpgw']->xslttpl->add_file(array('project', 'files', 'attributes_form'));
     $location_id = $GLOBALS['phpgw']->locations->get_id('property', $this->acl_location);
     $config = CreateObject('phpgwapi.config', 'property');
     $config->read();
     $bolocation = CreateObject('property.bolocation');
     if ($mode == 'edit') {
         $values = phpgw::get_var('values');
         $values_attribute = phpgw::get_var('values_attribute');
         $add_request = phpgw::get_var('add_request');
         $values['project_group'] = phpgw::get_var('project_group');
         $values['ecodimb'] = phpgw::get_var('ecodimb');
         $values['b_account_id'] = phpgw::get_var('b_account_id', 'int', 'POST');
         $values['b_account_name'] = phpgw::get_var('b_account_name', 'string', 'POST');
         $values['contact_id'] = phpgw::get_var('contact', 'int', 'POST');
         $auto_create = false;
         $datatable = array();
         $insert_record = $GLOBALS['phpgw']->session->appsession('insert_record', 'property');
         $insert_record_entity = $GLOBALS['phpgw']->session->appsession("insert_record_values{$this->acl_location}", 'property');
         if (isset($insert_record_entity) && is_array($insert_record_entity)) {
             for ($j = 0; $j < count($insert_record_entity); $j++) {
                 $insert_record['extra'][$insert_record_entity[$j]] = $insert_record_entity[$j];
             }
         }
         $bypass = phpgw::get_var('bypass', 'bool');
         //_debug_array($_REQUEST);
         if (phpgw::get_var('origin') == '.project.request' && phpgw::get_var('origin_id', 'int') && !$bypass) {
             $id = phpgw::get_var('project_id', 'int');
             $add_request = array('request_id' => array(phpgw::get_var('origin_id', 'int')));
         }
         if ($add_request) {
             $receipt = $this->bo->add_request($add_request, $id);
         }
         if ($_POST && !$bypass && isset($insert_record) && is_array($insert_record)) {
             $values = $this->bocommon->collect_locationdata($values, $insert_record);
         } else {
             $location_code = phpgw::get_var('location_code');
             $tenant_id = phpgw::get_var('tenant_id', 'int');
             $values['descr'] = phpgw::get_var('descr');
             $p_entity_id = phpgw::get_var('p_entity_id', 'int');
             $p_cat_id = phpgw::get_var('p_cat_id', 'int');
             $values['p'][$p_entity_id]['p_entity_id'] = $p_entity_id;
             $values['p'][$p_entity_id]['p_cat_id'] = $p_cat_id;
             $values['p'][$p_entity_id]['p_num'] = phpgw::get_var('p_num');
             $origin = phpgw::get_var('origin');
             $origin_id = phpgw::get_var('origin_id', 'int');
             if ($origin == '.ticket' && $origin_id && !$values['descr']) {
                 $boticket = CreateObject('property.botts');
                 $ticket = $boticket->read_single($origin_id);
                 $values['descr'] = $ticket['details'];
                 $values['name'] = $ticket['subject'] ? $ticket['subject'] : $ticket['category_name'];
                 $ticket_notes = $boticket->read_additional_notes($origin_id);
                 $i = count($ticket_notes) - 1;
                 if (isset($ticket_notes[$i]['value_note']) && $ticket_notes[$i]['value_note']) {
                     $values['descr'] .= ": " . $ticket_notes[$i]['value_note'];
                 }
                 $values['contact_id'] = $ticket['contact_id'];
                 $tts_status_create_project = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['tts_status_create_project']) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['tts_status_create_project'] : '';
                 if ($tts_status_create_project) {
                     $boticket->update_status(array('status' => $tts_status_create_project), $origin_id);
                 }
                 if (isset($GLOBALS['phpgw_info']['user']['preferences']['property']['auto_create_project_from_ticket']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['auto_create_project_from_ticket'] == 'yes') {
                     $auto_create = true;
                 }
             }
             if ($p_entity_id && $p_cat_id) {
                 if (!is_object($boadmin_entity)) {
                     $boadmin_entity = CreateObject('property.boadmin_entity');
                 }
                 $entity_category = $boadmin_entity->read_single_category($p_entity_id, $p_cat_id);
                 $values['p'][$p_entity_id]['p_cat_name'] = $entity_category['name'];
             }
             if ($location_code) {
                 $values['location_data'] = $bolocation->read_single($location_code, array('tenant_id' => $tenant_id, 'p_num' => $p_num, 'view' => true));
             }
         }
         if (isset($values['origin']) && $values['origin']) {
             $origin = $values['origin'];
             $origin_id = $values['origin_id'];
         }
         $interlink = CreateObject('property.interlink');
         if (isset($origin) && $origin) {
             unset($values['origin']);
             unset($values['origin_id']);
             $values['origin'][0]['location'] = $origin;
             $values['origin'][0]['descr'] = $interlink->get_location_name($origin);
             $values['origin'][0]['data'][] = array('id' => $origin_id, 'link' => $interlink->get_relation_link(array('location' => $origin), $origin_id));
         }
         if ($save = phpgw::get_var('save', 'bool')) {
             if ($GLOBALS['phpgw']->session->is_repost()) {
                 //						$receipt['error'][]=array('msg'=>lang('Hmm... looks like a repost!'));
             }
             if (isset($config->config_data['invoice_acl']) && $config->config_data['invoice_acl'] == 'dimb') {
                 if (!$this->acl_manage) {
                     if (!isset($values['ecodimb']) || !$values['ecodimb']) {
                         $receipt['error'][] = array('msg' => lang('Please select dimb!'));
                         $error_id = true;
                     }
                     $approve_role = execMethod('property.boinvoice.check_role', $values['ecodimb']);
                     if (!$approve_role['is_supervisor'] && !$approve_role['is_budget_responsible']) {
                         $receipt['error'][] = array('msg' => lang('you are not approved for this dimb: %1', $values['ecodimb']));
                         $error_id = true;
                     }
                 }
             }
             if (!isset($values['location'])) {
                 $receipt['error'][] = array('msg' => lang('Please select a location !'));
                 $error_id = true;
             }
             if (isset($values['b_account_id']) && $values['b_account_id']) {
                 $sogeneric = CreateObject('property.sogeneric');
                 $sogeneric->get_location_info('b_account_category', false);
                 $status_data = $sogeneric->read_single(array('id' => (int) $values['b_account_id']), array());
                 if (isset($status_data['project_group']) && $status_data['project_group']) {
                     if (!isset($values['project_group']) || !$values['project_group']) {
                         $receipt['error'][] = array('msg' => lang('Please select a project group!'));
                         $error_id = true;
                     }
                 }
             }
             if (isset($values['new_project_id']) && $values['new_project_id'] && !$this->bo->read_single_mini($values['new_project_id'])) {
                 $receipt['error'][] = array('msg' => lang('the project %1 does not exist', $values['new_project_id']));
             }
             if (isset($values['new_project_id']) && $values['new_project_id'] && $values['new_project_id'] == $id) {
                 unset($values['new_project_id']);
             }
             if (!isset($values['end_date']) || !$values['end_date']) {
                 $receipt['error'][] = array('msg' => lang('Please select an end date!'));
                 $error_id = true;
             }
             if (!isset($values['project_type_id']) || !$values['project_type_id']) {
                 $receipt['error'][] = array('msg' => lang('Please select a project type!'));
                 $error_id = true;
             }
             if (!$values['name']) {
                 $receipt['error'][] = array('msg' => lang('Please enter a project NAME !'));
                 $error_id = true;
             }
             if (!isset($config->config_data['project_optional_category']) || !$config->config_data['project_optional_category']) {
                 if (!$values['cat_id']) {
                     $receipt['error'][] = array('msg' => lang('Please select a category !'));
                     $error_id = true;
                 }
             }
             if (isset($values['cat_id']) && $values['cat_id']) {
                 $_category = $this->cats->return_single($values['cat_id']);
                 if (!$_category[0]['active']) {
                     $receipt['error'][] = array('msg' => lang('invalid category'));
                 }
             }
             if (!$values['coordinator']) {
                 $receipt['error'][] = array('msg' => lang('Please select a coordinator !'));
                 $error_id = true;
             }
             if (!$values['status']) {
                 $receipt['error'][] = array('msg' => lang('Please select a status !'));
                 $error_id = true;
             }
             if (isset($values['budget']) && $values['budget'] && !ctype_digit(ltrim($values['budget'], '-'))) {
                 $receipt['error'][] = array('msg' => lang('budget') . ': ' . lang('Please enter an integer !'));
                 $error_id = true;
             }
             if (isset($values['reserve']) && $values['reserve'] && !ctype_digit(ltrim($values['reserve'], '-'))) {
                 $receipt['error'][] = array('msg' => lang('reserve') . ': ' . lang('Please enter an integer !'));
                 $error_id = true;
             }
             if (isset($values_attribute) && is_array($values_attribute)) {
                 foreach ($values_attribute as $attribute) {
                     if ($attribute['nullable'] != 1 && (!$attribute['value'] && !$values['extra'][$attribute['name']])) {
                         $receipt['error'][] = array('msg' => lang('Please enter value for attribute %1', $attribute['input_text']));
                     }
                 }
             }
             if ($values['approval'] && $values['mail_address'] && $config->config_data['project_approval']) {
                 if (isset($config->config_data['project_approval_status']) && $config->config_data['project_approval_status']) {
                     $values['status'] = $config->config_data['project_approval_status'];
                 }
             }
             if ($id) {
                 $values['id'] = $id;
                 $action = 'edit';
             }
             if (!$receipt['error']) {
                 if ($values['copy_project']) {
                     $action = 'add';
                 }
                 $receipt = $this->bo->save($values, $action, $values_attribute);
                 if (!$receipt['error']) {
                     $id = $receipt['id'];
                 }
                 //----------files
                 $bofiles = CreateObject('property.bofiles');
                 if (isset($values['file_action']) && is_array($values['file_action'])) {
                     $bofiles->delete_file("/project/{$id}/", $values);
                 }
                 $file_name = @str_replace(' ', '_', $_FILES['file']['name']);
                 if ($file_name) {
                     $to_file = "{$bofiles->fakebase}/project/{$id}/{$file_name}";
                     if ($bofiles->vfs->file_exists(array('string' => $to_file, 'relatives' => array(RELATIVE_NONE)))) {
                         $receipt['error'][] = array('msg' => lang('This file already exists !'));
                     } else {
                         $bofiles->create_document_dir("project/{$id}");
                         $bofiles->vfs->override_acl = 1;
                         if (!$bofiles->vfs->cp(array('from' => $_FILES['file']['tmp_name'], 'to' => $to_file, 'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL)))) {
                             $receipt['error'][] = array('msg' => lang('Failed to upload file !'));
                         }
                         $bofiles->vfs->override_acl = 0;
                     }
                 }
                 //-----------
                 if (isset($GLOBALS['phpgw_info']['server']['smtp_server']) && $GLOBALS['phpgw_info']['server']['smtp_server']) {
                     $historylog = CreateObject('property.historylog', 'project');
                     if (!is_object($GLOBALS['phpgw']->send)) {
                         $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
                     }
                     $action_params['responsible'] = $_account_id;
                     $from_name = $GLOBALS['phpgw_info']['user']['fullname'];
                     $from_email = $GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
                     $subject = lang(Approval) . ": " . $id;
                     $message = '<a href ="' . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiproject.edit', 'id' => $id), false, true) . '">' . lang('project %1 needs approval', $id) . '</a>';
                     $bcc = '';
                     //$from_email;
                     $action_params = array('appname' => 'property', 'location' => '.project', 'id' => $id, 'responsible' => '', 'responsible_type' => 'user', 'action' => 'approval', 'remark' => '', 'deadline' => '');
                     if (isset($values['mail_address']) && is_array($values['mail_address'])) {
                         foreach ($values['mail_address'] as $_account_id => $_address) {
                             if (isset($values['approval'][$_account_id]) && $values['approval'][$_account_id]) {
                                 $rcpt = $GLOBALS['phpgw']->send->msg('email', $_address, $subject, stripslashes($message), '', $cc, $bcc, $from_email, $from_name, 'html');
                                 $action_params['responsible'] = $_account_id;
                                 execMethod('property.sopending_action.set_pending_action', $action_params);
                                 if (!$rcpt) {
                                     $receipt['error'][] = array('msg' => "uiproject::edit: sending message to '" . $_address . "', subject='{$subject}' failed !!!");
                                     $receipt['error'][] = array('msg' => $GLOBALS['phpgw']->send->err['desc']);
                                     $bypass_error = true;
                                 } else {
                                     $historylog->add('AP', $id, lang('%1 is notified', $_address));
                                     $receipt['message'][] = array('msg' => lang('%1 is notified', $_address));
                                 }
                             }
                         }
                     }
                     $toarray = array();
                     $toarray_sms = array();
                     if (isset($receipt['notice_owner']) && is_array($receipt['notice_owner'])) {
                         if ($this->account != $values['coordinator'] && isset($GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner']) {
                             $prefs_coordinator = $this->bocommon->create_preferences('property', $values['coordinator']);
                             if (isset($prefs_coordinator['email']) && $prefs_coordinator['email']) {
                                 $toarray[] = $prefs_coordinator['email'];
                             }
                         }
                     }
                     $notify_list = execMethod('property.notify.read', array('location_id' => $location_id, 'location_item_id' => $id));
                     $subject = lang('project %1 has been edited', $id);
                     if (isset($GLOBALS['phpgw_info']['user']['apps']['sms'])) {
                         $sms_text = "{$subject}. \r\n{$GLOBALS['phpgw_info']['user']['fullname']} \r\n{$GLOBALS['phpgw_info']['user']['preferences']['property']['email']}";
                         $sms = CreateObject('sms.sms');
                         foreach ($notify_list as $entry) {
                             if ($entry['is_active'] && $entry['notification_method'] == 'sms' && $entry['sms']) {
                                 $sms->websend2pv($this->account, $entry['sms'], $sms_text);
                                 $toarray_sms[] = "{$entry['first_name']} {$entry['last_name']}({$entry['sms']})";
                                 $receipt['message'][] = array('msg' => lang('%1 is notified', "{$entry['first_name']} {$entry['last_name']}"));
                             }
                         }
                         unset($entry);
                         if ($toarray_sms) {
                             $historylog->add('MS', $id, implode(',', $toarray_sms));
                         }
                     }
                     reset($notify_list);
                     foreach ($notify_list as $entry) {
                         if ($entry['is_active'] && $entry['notification_method'] == 'email' && $entry['email']) {
                             $toarray[] = "{$entry['first_name']} {$entry['last_name']}<{$entry['email']}>";
                         }
                     }
                     unset($entry);
                     if ($toarray) {
                         $to = implode(';', $toarray);
                         $from_name = $GLOBALS['phpgw_info']['user']['fullname'];
                         $from_email = $GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
                         $body = '<a href ="' . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiproject.edit', 'id' => $id), false, true) . '">' . lang('project %1 has been edited', $id) . '</a>' . "\n";
                         foreach ($receipt['notice_owner'] as $notice) {
                             $body .= $notice . "\n";
                         }
                         $body .= lang('Altered by') . ': ' . $from_name . "\n";
                         $body .= lang('remark') . ': ' . $values['remark'] . "\n";
                         $body = nl2br($body);
                         $returncode = $GLOBALS['phpgw']->send->msg('email', $to, $subject, $body, false, false, false, $from_email, $from_name, 'html');
                         if (!$returncode) {
                             $receipt['error'][] = array('msg' => "uiproject::edit: sending message to '{$to}' subject='{$subject}' failed !!!");
                             $receipt['error'][] = array('msg' => $GLOBALS['phpgw']->send->err['desc']);
                             $bypass_error = true;
                         } else {
                             $historylog->add('ON', $id, lang('%1 is notified', $to));
                             $receipt['message'][] = array('msg' => lang('%1 is notified', $to));
                         }
                     }
                 }
             }
             if ($receipt['error'] && !isset($bypass_error)) {
                 if (isset($values['location']) && is_array($values['location'])) {
                     $location_code = implode("-", $values['location']);
                     $values['extra']['view'] = true;
                     $values['location_data'] = $bolocation->read_single($location_code, $values['extra']);
                 }
                 if (isset($values['extra']['p_num'])) {
                     $values['p'][$values['extra']['p_entity_id']]['p_num'] = $values['extra']['p_num'];
                     $values['p'][$values['extra']['p_entity_id']]['p_entity_id'] = $values['extra']['p_entity_id'];
                     $values['p'][$values['extra']['p_entity_id']]['p_cat_id'] = $values['extra']['p_cat_id'];
                     $values['p'][$values['extra']['p_entity_id']]['p_cat_name'] = phpgw::get_var('entity_cat_name_' . $values['extra']['p_entity_id'], 'string', 'POST');
                 }
             }
         }
     }
     //$record_history = '';
     $record_history = array();
     if (isset($bypass_error) || (!isset($receipt['error']) || $add_request) && !$bypass && $id) {
         $_transfer_new_project = isset($values['new_project_id']) && $values['new_project_id'] ? true : false;
         $values = $this->bo->read_single($id);
         if (!isset($values['origin'])) {
             $values['origin'] = '';
         }
         if (!isset($values['workorder_budget']) && $save && !$_transfer_new_project && !$values['project_type_id'] == 3) {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiworkorder.edit', 'project_id' => $id));
         }
         if (!$this->bocommon->check_perms($values['grants'], PHPGW_ACL_EDIT)) {
             $receipt['error'][] = array('msg' => lang('You have no edit right for this project'));
             $GLOBALS['phpgw']->session->appsession('receipt', 'property', $receipt);
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiproject.view', 'id' => $id));
         } else {
             $record_history = $this->bo->read_record_history($id);
         }
     }
     /* Preserve attribute values from post */
     if (isset($receipt['error']) && (isset($values_attribute) && is_array($values_attribute))) {
         $values = $this->bocommon->preserve_attribute_values($values, $values_attribute);
     }
     if ($id) {
         $function_msg = lang("{$mode} project");
     } else {
         $function_msg = lang('Add Project');
         $values = $this->bo->read_single(0, $values);
     }
     $tabs = array();
     if (isset($values['attributes']) && is_array($values['attributes'])) {
         foreach ($values['attributes'] as &$attribute) {
             if ($attribute['history'] == true) {
                 $link_history_data = array('menuaction' => 'property.uiproject.attrib_history', 'attrib_id' => $attribute['id'], 'id' => $id, 'edit' => true);
                 $attribute['link_history'] = $GLOBALS['phpgw']->link('/index.php', $link_history_data);
             }
         }
     }
     if (isset($values['cat_id'])) {
         $this->cat_id = $values['cat_id'];
     }
     $lookup_type = $mode == 'edit' ? 'form' : 'view';
     //_debug_array($values);
     $location_data = $bolocation->initiate_ui_location(array('values' => isset($values['location_data']) ? $values['location_data'] : '', 'type_id' => -1, 'no_link' => false, 'tenant' => true, 'lookup_type' => $lookup_type, 'lookup_entity' => $this->bocommon->get_lookup_entity('project'), 'entity_data' => isset($values['p']) ? $values['p'] : ''));
     $b_account_data = array();
     $ecodimb_data = array();
     if (isset($config->config_data['budget_at_project']) && $config->config_data['budget_at_project']) {
         $b_account_data = $this->bocommon->initiate_ui_budget_account_lookup(array('b_account_id' => $values['b_account_id'], 'b_account_name' => $values['b_account_name'], 'role' => 'group', 'type' => $lookup_type));
         $ecodimb_data = $this->bocommon->initiate_ecodimb_lookup(array('ecodimb' => $values['ecodimb'], 'ecodimb_descr' => $values['ecodimb_descr'], 'disabled' => $mode == 'view'));
     }
     $contact_data = $this->bocommon->initiate_ui_contact_lookup(array('contact_id' => $values['contact_id'], 'contact_name' => $values['contact_name'], 'field' => 'contact', 'type' => $lookup_type));
     if (isset($values['contact_phone'])) {
         for ($i = 0; $i < count($location_data['location']); $i++) {
             if ($location_data['location'][$i]['input_name'] == 'contact_phone') {
                 $location_data['location'][$i]['value'] = $values['contact_phone'];
             }
         }
     }
     $link_data = array('menuaction' => 'property.uiproject.edit', 'id' => $id);
     $link_request_data = array('menuaction' => 'property.uirequest.index', 'query' => isset($values['location_data']['loc1']) ? $values['location_data']['loc1'] : '', 'project_id' => isset($id) ? $id : '');
     $supervisor_email = array();
     if ($need_approval = isset($config->config_data['project_approval']) ? $config->config_data['project_approval'] : '') {
         $invoice = CreateObject('property.soinvoice');
         if (isset($config->config_data['invoice_acl']) && $config->config_data['invoice_acl'] == 'dimb') {
             $supervisor_id = $invoice->get_default_dimb_role_user(2, $values['ecodimb']);
             $sodimb_role_users = execMethod('property.sodimb_role_user.read', array('dimb_id' => $values['ecodimb'], 'role_id' => 2, 'query_start' => date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), 'get_netto_list' => true));
             if (isset($sodimb_role_users[$values['ecodimb']][2]) && is_array($sodimb_role_users[$values['ecodimb']][2])) {
                 foreach ($sodimb_role_users[$values['ecodimb']][2] as $supervisor_id => $entry) {
                     $prefs = $this->bocommon->create_preferences('property', $supervisor_id);
                     $supervisor_email[] = array('id' => $supervisor_id, 'address' => $prefs['email'], 'default' => $entry['default_user']);
                 }
             }
             $supervisor2_id = $invoice->get_default_dimb_role_user(3, $values['ecodimb']);
             $prefs2 = $this->bocommon->create_preferences('property', $supervisor2_id);
             $supervisor_email[] = array('id' => $supervisor2_id, 'address' => $prefs2['email']);
             //					$supervisor_email = array_reverse($supervisor_email);
             unset($prefs);
             unset($prefs2);
             unset($invoice);
         } else {
             $supervisor_id = 0;
             if (isset($GLOBALS['phpgw_info']['user']['preferences']['property']['approval_from']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['approval_from']) {
                 $supervisor_id = $GLOBALS['phpgw_info']['user']['preferences']['property']['approval_from'];
             }
             if ($supervisor_id) {
                 $prefs = $this->bocommon->create_preferences('property', $supervisor_id);
                 $supervisor_email[] = array('id' => $supervisor_id, 'address' => $prefs['email']);
                 if (isset($prefs['approval_from'])) {
                     $prefs2 = $this->bocommon->create_preferences('property', $prefs['approval_from']);
                     if (isset($prefs2['email'])) {
                         $supervisor_email[] = array('id' => $prefs['approval_from'], 'address' => $prefs2['email']);
                         $supervisor_email = array_reverse($supervisor_email);
                     }
                     unset($prefs2);
                 }
                 unset($prefs);
             }
         }
     }
     $project_status = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['project_status']) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['project_status'] : '';
     $project_category = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['project_category']) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['project_category'] : '';
     if (!isset($values['status'])) {
         $values['status'] = $project_status;
     }
     if (!isset($values['cat_id'])) {
         $values['cat_id'] = $project_category;
     }
     if (!isset($values['coordinator'])) {
         $values['coordinator'] = $this->account;
     }
     if (!isset($values['start_date']) || !$values['start_date']) {
         $values['start_date'] = $GLOBALS['phpgw']->common->show_date(mktime(0, 0, 0, date("m"), date("d"), date("Y")), $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
     }
     if (isset($receipt) && is_array($receipt)) {
         $msgbox_data = $this->bocommon->msgbox_data($receipt);
     } else {
         $msgbox_data = '';
     }
     $values['sum'] = isset($values['budget']) ? $values['budget'] : 0;
     if (isset($values['reserve']) && $values['reserve'] != 0) {
         $reserve_remainder = $values['reserve'] - $values['deviation'];
         $remainder_percent = number_format($reserve_remainder / $values['reserve'] * 100, 2, ',', '');
         $values['sum'] = $values['sum'] + $values['reserve'];
     }
     $value_remainder = $values['sum'];
     $GLOBALS['phpgw']->jqcal->add_listener('values_start_date');
     $GLOBALS['phpgw']->jqcal->add_listener('values_end_date');
     $project_group_data = $this->bocommon->initiate_project_group_lookup(array('project_group' => $values['project_group'], 'project_group_descr' => $values['project_group_descr']));
     //---datatable settings---------------------------------------------------
     $sum_actual_cost = 0;
     $sum_oblications = 0;
     $rows_per_page = 10;
     $initial_page = 1;
     if ($id) {
         $content_budget = $this->bo->get_budget($id);
         $lang_delete = lang('Check to delete period');
         $lang_close = lang('Check to close period');
         $lang_active = lang('Check to activate period');
         $values['sum'] = 0;
         if ($content_budget && $values['periodization_id']) {
             $_year_count = array();
             foreach ($content_budget as $key => $row) {
                 $_year_count[$row['year']] += 1;
                 $rows_per_page = $_year_count[$row['year']];
             }
             $initial_page = floor(count($content_budget) / $rows_per_page);
         }
         /*
         				if($content_budget)
         				{
         					foreach ($content_budget as $key => $row)
         					{
         						$_year_arg[$key]  = $row['year'];
         						$_month_arg[$key] = $row['month'];
         					}
         
         					array_multisort($_year_arg, SORT_DESC, $_month_arg, SORT_ASC, $content_budget);
         
         					reset($content_budget);
         				}
         */
         foreach ($content_budget as &$b_entry) {
             if ($b_entry['active']) {
                 $sum_actual_cost += $b_entry['actual_cost'];
                 $sum_oblications += $b_entry['sum_oblications'];
                 $values['sum'] += $b_entry['budget'];
             }
             $checked = $b_entry['closed'] ? 'checked="checked"' : '';
             $checked2 = $b_entry['active'] ? 'checked="checked"' : '';
             $b_entry['flag_active'] = $b_entry['active'];
             $b_entry['delete_year'] = "<input type='checkbox' name='values[delete_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_delete}'>";
             $b_entry['closed'] = "<input type='checkbox' name='values[closed_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_close}' {$checked}>";
             $b_entry['closed_orig'] = "<input type='checkbox' name='values[closed_orig_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' {$checked}>";
             $b_entry['active'] = "<input type='checkbox' name='values[active_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' title='{$lang_active}' {$checked2}>";
             $b_entry['active_orig'] = "<input type='checkbox' name='values[active_orig_b_period][]' value='{$b_entry['year']}_{$b_entry['month']}' {$checked2}>";
         }
         unset($b_entry);
     }
     if (isset($values['reserve']) && $values['reserve'] != 0) {
         $reserve_remainder = $values['reserve'] - $values['deviation'];
         $remainder_percent = number_format($reserve_remainder / $values['reserve'] * 100, 2, ',', '');
         $values['sum'] = $values['sum'] + $values['reserve'];
     }
     $value_remainder = $values['sum'] - $sum_actual_cost - $sum_oblications;
     $values['sum'] = number_format($values['sum'], 0, ',', ' ');
     $value_remainder = number_format($value_remainder, 0, ',', ' ');
     if (isset($values['project_type_id']) && $values['project_type_id'] == 3) {
         $rows_per_page = 10;
         $initial_page = 1;
         $myColumnDefs[0] = array('name' => "0", 'values' => json_encode(array(array('key' => 'year', 'label' => lang('year'), 'sortable' => false, 'resizeable' => true), array('key' => 'entry_date', 'label' => lang('entry date'), 'sortable' => true, 'resizeable' => true), array('key' => 'amount_in', 'label' => lang('amount in'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'from_project', 'label' => lang('from project'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'project_link'), array('key' => 'amount_out', 'label' => lang('amount out'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'to_project', 'label' => lang('to project'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'project_link'), array('key' => 'remark', 'label' => lang('remark'), 'sortable' => true, 'resizeable' => true))));
         $content_budget = $this->bo->get_buffer_budget($id);
         foreach ($content_budget as &$b_entry) {
             $b_entry['entry_date'] = $GLOBALS['phpgw']->common->show_date($b_entry['entry_date'], $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
         }
         unset($b_entry);
     } else {
         $myColumnDefs[0] = array('name' => "0", 'values' => json_encode(array(array('key' => 'year', 'label' => lang('year'), 'sortable' => false, 'resizeable' => true), array('key' => 'month', 'label' => lang('month'), 'sortable' => false, 'resizeable' => true), array('key' => 'budget', 'label' => lang('budget'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'sum_oblications', 'label' => lang('sum orders'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'actual_cost', 'label' => lang('actual cost'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'diff', 'label' => lang('difference'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'deviation_period', 'label' => lang('deviation'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'deviation_acc', 'label' => lang('deviation') . '::' . lang('accumulated'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'deviation_percent_period', 'label' => lang('deviation') . '::' . lang('percent'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount2'), array('key' => 'deviation_percent_acc', 'label' => lang('percent') . '::' . lang('accumulated'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount2'), array('key' => 'closed', 'label' => lang('closed'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'), array('key' => 'closed_orig', 'hidden' => true), array('key' => 'active', 'label' => lang('active'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'), array('key' => 'active_orig', 'hidden' => true), array('key' => 'flag_active', 'hidden' => true), array('key' => 'delete_year', 'label' => lang('Delete'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'))));
     }
     $datavalues[0] = array('name' => "0", 'values' => json_encode($content_budget), 'total_records' => count($content_budget), 'edit_action' => "''", 'permission' => "''", 'is_paginator' => 1, 'rows_per_page' => $rows_per_page, 'initial_page' => $initial_page, 'footer' => 0);
     //_debug_array($values['workorder_budget']);die();
     $content_orders = $this->get_orders($id, date('Y'));
     //			_debug_array($content_orders);die();
     foreach ($content_orders as &$_order_entry) {
         $_order_entry['send_order'] = '';
         if (isset($_order_entry['mail_recipients'][0]) && $_order_entry['mail_recipients'][0]) {
             $_title = implode(';', $_order_entry['mail_recipients']);
             $_order_entry['send_order'] = "<input type='checkbox' name='values[send_order][]' value='{$_order_entry['workorder_id']}' title='{$_title}'>";
         }
     }
     //FIXME: deviation from this one
     $datavalues[1] = array('name' => "1", 'values' => json_encode($content_orders), 'total_records' => count($content_orders), 'edit_action' => json_encode($GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiworkorder.edit'))), 'is_paginator' => 1, 'rows_per_page' => 10, 'initial_page' => 1, 'footer' => 0);
     $myColumnDefs[1] = array('name' => "1", 'values' => json_encode(array(array('key' => 'workorder_id', 'label' => lang('Workorder'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'YAHOO.widget.DataTable.formatLink'), array('key' => 'title', 'label' => lang('title'), 'sortable' => true, 'resizeable' => true), array('key' => 'b_account_id', 'label' => lang('Budget account'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterRight'), array('key' => 'budget', 'label' => lang('budget'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'cost', 'label' => lang('cost'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'addition_percentage', 'label' => '%', 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterRight'), array('key' => 'obligation', 'label' => lang('sum orders'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'actual_cost', 'label' => lang('actual cost'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'diff', 'label' => lang('difference'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterAmount0'), array('key' => 'vendor_name', 'label' => lang('Vendor'), 'sortable' => true, 'resizeable' => true), array('key' => 'status', 'label' => lang('Status'), 'sortable' => true, 'resizeable' => true), array('key' => 'send_order', 'label' => lang('send workorder'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterCenter'))));
     $invoices = array();
     $content_invoice = array();
     if ($id) {
         $content_invoice = $this->get_vouchers($id, date('Y'));
     }
     $datavalues[2] = array('name' => "2", 'values' => json_encode($content_invoice), 'total_records' => count($content_invoice), 'edit_action' => json_encode($GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiinvoice.index'))), 'is_paginator' => 1, 'rows_per_page' => 10, 'initial_page' => 1, 'footer' => 0);
     $_formatter_voucher_link = isset($config->config_data['invoicehandler']) && $config->config_data['invoicehandler'] == 2 ? 'YAHOO.widget.DataTable.formatLink_invoicehandler_2' : 'YAHOO.widget.DataTable.formatLink_voucher';
     $myColumnDefs[2] = array('name' => "2", 'values' => json_encode(array(array('key' => 'workorder_id', 'label' => lang('Workorder'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'YAHOO.widget.DataTable.formatLink'), array('key' => 'voucher_id', 'label' => lang('bilagsnr'), 'sortable' => true, 'resizeable' => true, 'formatter' => $_formatter_voucher_link), array('key' => 'voucher_out_id', 'hidden' => true), array('key' => 'invoice_id', 'label' => lang('invoice number'), 'sortable' => false, 'resizeable' => true), array('key' => 'vendor', 'label' => lang('vendor'), 'sortable' => false, 'resizeable' => true), array('key' => 'amount', 'label' => lang('amount'), 'sortable' => true, 'resizeable' => true, 'formatter' => 'FormatterAmount2'), array('key' => 'approved_amount', 'label' => lang('approved amount'), 'sortable' => false, 'resizeable' => true, 'formatter' => 'FormatterAmount2'), array('key' => 'period', 'label' => lang('period'), 'sortable' => true, 'resizeable' => true), array('key' => 'periodization', 'label' => lang('periodization'), 'sortable' => false, 'resizeable' => true), array('key' => 'periodization_start', 'label' => lang('periodization start'), 'sortable' => false, 'resizeable' => true), array('key' => 'currency', 'label' => lang('currency'), 'sortable' => false, 'resizeable' => true), array('key' => 'type', 'label' => lang('type'), 'sortable' => true, 'resizeable' => true), array('key' => 'budget_responsible', 'label' => lang('budget responsible'), 'sortable' => true, 'resizeable' => true), array('key' => 'budsjettsigndato', 'label' => lang('budsjettsigndato'), 'sortable' => true, 'resizeable' => true), array('key' => 'transfer_time', 'label' => lang('transfer time'), 'sortable' => true, 'resizeable' => true))));
     $notify_info = execMethod('property.notify.get_yui_table_def', array('location_id' => $location_id, 'location_item_id' => $id, 'count' => count($myColumnDefs)));
     $datavalues[] = $notify_info['datavalues'];
     $myColumnDefs[3] = $notify_info['column_defs'];
     $myButtons = array();
     if ($mode == 'edit') {
         $myButtons[3] = $notify_info['buttons'];
     }
     $datavalues[4] = array('name' => "4", 'values' => json_encode($record_history), 'total_records' => count($record_history), 'edit_action' => "''", 'is_paginator' => 0, 'footer' => 0);
     $myColumnDefs[4] = array('name' => "4", 'values' => json_encode(array(array('key' => 'value_date', 'label' => lang('Date'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_user', 'label' => lang('User'), 'Action' => true, 'resizeable' => true), array('key' => 'value_action', 'label' => lang('action'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_old_value', 'label' => lang('old value'), 'sortable' => true, 'resizeable' => true), array('key' => 'value_new_value', 'label' => lang('new value'), 'sortable' => true, 'resizeable' => true))));
     //--------------files
     $link_file_data = array('menuaction' => 'property.uiproject.view_file', 'id' => $id);
     $link_to_files = isset($config->config_data['files_url']) ? $config->config_data['files_url'] : '';
     $link_view_file = $GLOBALS['phpgw']->link('/index.php', $link_file_data);
     $_files = $this->bo->get_files($id);
     $lang_view_file = lang('click to view file');
     $lang_delete_file = lang('Check to delete file');
     $z = 0;
     $content_files = array();
     foreach ($_files as $_file) {
         if ($link_to_files) {
             $content_files[$z]['file_name'] = "<a href='{$link_to_files}/{$_file['directory']}/{$_file['file_name']}' target=\"_blank\" title='{$lang_view_file}'>{$_file['name']}</a>";
         } else {
             $content_files[$z]['file_name'] = "<a href=\"{$link_view_file}&amp;file_name={$_file['file_name']}\" target=\"_blank\" title=\"{$lang_view_file}\">{$_file['name']}</a>";
         }
         $content_files[$z]['delete_file'] = "<input type=\"checkbox\" name=\"values[file_action][]\" value=\"{$_file['name']}\" title=\"{$lang_delete_file}\">";
         $z++;
     }
     $datavalues[5] = array('name' => "5", 'values' => json_encode($content_files), 'total_records' => count($content_files), 'edit_action' => "''", 'is_paginator' => 1, 'rows_per_page' => $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'], 'footer' => 0);
     $myColumnDefs[5] = array('name' => "5", 'values' => json_encode(array(array('key' => 'file_name', 'label' => lang('Filename'), 'sortable' => false, 'resizeable' => true), array('key' => 'delete_file', 'label' => lang('Delete file'), 'sortable' => false, 'resizeable' => true))));
     //--------------files
     $lang_delete_request_statustext = lang('Check to delete this request from this project');
     $_origin = array();
     if (isset($values['origin']) && $values['origin']) {
         foreach ($values['origin'] as $__origin) {
             foreach ($__origin['data'] as $_origin_data) {
                 $_select = '';
                 if ($__origin['location'] == '.project.request') {
                     $_select = "<input type=\"checkbox\" name=\"values[delete_request][]\" value=\"{$_origin_data['id']}\" title=\"{$lang_delete_request_statustext}\">";
                 }
                 $_origin[] = array('url' => "<a href='{$_origin_data['link']}'>{$_origin_data['id']} </a>", 'type' => $__origin['descr'], 'title' => $_origin_data['title'], 'status' => $_origin_data['statustext'], 'select' => $_select);
             }
         }
     }
     $datavalues[6] = array('name' => "6", 'values' => json_encode($_origin), 'total_records' => count($_origin), 'edit_action' => "''", 'is_paginator' => 1, 'rows_per_page' => 5, 'footer' => 0);
     $myColumnDefs[6] = array('name' => "6", 'values' => json_encode(array(array('key' => 'url', 'label' => lang('id'), 'sortable' => true, 'resizeable' => true), array('key' => 'type', 'label' => lang('type'), 'sortable' => true, 'resizeable' => true), array('key' => 'title', 'label' => lang('title'), 'sortable' => false, 'resizeable' => true), array('key' => 'status', 'label' => lang('status'), 'sortable' => false, 'resizeable' => true), array('key' => 'select', 'label' => lang('select'), 'sortable' => false, 'resizeable' => true))));
     //	_debug_array($myButtons);die();
     //----------------------------------------------datatable settings--------
     $suppresscoordination = isset($config->config_data['project_suppresscoordination']) && $config->config_data['project_suppresscoordination'] ? 1 : '';
     $year = date('Y') - 1;
     $limit = $year + 8;
     while ($year < $limit) {
         $year_list[] = array('id' => $year, 'name' => $year);
         $year++;
     }
     $periodization_list = $this->bo->get_periodizations_with_outline();
     $sub_entry_action_data = array();
     $sub_entry_action_data = array('menuaction' => 'property.uiworkorder.edit', 'project_id' => $id);
     if ($id && !$values['project_type_id'] == 3) {
         $sub_entry_action_data = array('menuaction' => 'property.uiworkorder.edit', 'project_id' => $id);
     } else {
         if ($id && $values['project_type_id'] == 3) {
             $sub_entry_action_data = array('menuaction' => 'property.uiproject.edit', 'bypass' => 1, 'parent_id' => $id, 'origin' => '.project', 'origin_id' => $id);
         }
     }
     $selected_tab = phpgw::get_var('tab', 'string', 'REQUEST', 'general');
     $project_type_id = isset($values['project_type_id']) && $values['project_type_id'] ? $values['project_type_id'] : $GLOBALS['phpgw_info']['user']['preferences']['property']['default_project_type'];
     $property_js = "/property/js/yahoo/property2.js";
     if (!isset($GLOBALS['phpgw_info']['server']['no_jscombine']) || !$GLOBALS['phpgw_info']['server']['no_jscombine']) {
         $cachedir = urlencode($GLOBALS['phpgw_info']['server']['temp_dir']);
         $property_js = "/phpgwapi/inc/combine.php?cachedir={$cachedir}&type=javascript&files=" . str_replace('/', '--', ltrim($property_js, '/'));
     }
     $data = array('property_js' => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . $property_js), 'project_types' => array('options' => $this->bo->get_project_types($project_type_id)), 'project_type_id' => $values['project_type_id'], 'inherit_location' => $id ? $values['inherit_location'] : 1, 'mode' => $mode, 'suppressmeter' => isset($config->config_data['project_suppressmeter']) && $config->config_data['project_suppressmeter'] ? 1 : '', 'suppresscoordination' => $suppresscoordination, 'custom_attributes' => array('attributes' => $values['attributes']), 'lookup_functions' => isset($values['lookup_functions']) ? $values['lookup_functions'] : '', 'b_account_data' => $b_account_data, 'ecodimb_data' => $ecodimb_data, 'contact_data' => $contact_data, 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'myButtons' => $myButtons, 'tabs' => self::_generate_tabs($tabs, array('documents' => $id ? false : true, 'history' => $id ? false : true), $selected_tab), 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'value_origin' => isset($values['origin']) ? $values['origin'] : '', 'value_origin_type' => isset($origin) ? $origin : '', 'value_origin_id' => isset($origin_id) ? $origin_id : '', 'year_list' => array('options' => $year_list), 'order_time_span' => array('options' => $this->bo->get_order_time_span($id)), 'periodization_list' => array('options' => $periodization_list), 'lang_select_request_statustext' => lang('Add request for this project'), 'lang_request_statustext' => lang('Link to the request for this project'), 'link_select_request' => $GLOBALS['phpgw']->link('/index.php', $link_request_data), 'add_sub_entry_action' => $GLOBALS['phpgw']->link('/index.php', $sub_entry_action_data), 'lang_add_sub_entry' => $values['project_type_id'] == 3 ? lang('add project') : lang('Add workorder'), 'lang_add_sub_entry_statustext' => $values['project_type_id'] == 3 ? lang('add a project to this buffer') : lang('Add a workorder to this project'), 'lang_no_workorders' => lang('No workorder budget'), 'workorder_link' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiworkorder.edit')), 'record_history' => $record_history, 'table_header_history' => $table_header_history, 'lang_history' => lang('History'), 'lang_no_history' => lang('No history'), 'lang_start_date_statustext' => lang('Select the estimated end date for the Project'), 'lang_start_date' => lang('Project start date'), 'value_start_date' => $values['start_date'], 'lang_end_date_statustext' => lang('Select the estimated end date for the Project'), 'lang_end_date' => lang('Project end date'), 'value_end_date' => isset($values['end_date']) ? $values['end_date'] : '', 'lang_copy_project' => lang('Copy project ?'), 'lang_copy_project_statustext' => lang('Choose Copy Project to copy this project to a new project'), 'lang_charge_tenant' => lang('Charge tenant'), 'lang_charge_tenant_statustext' => lang('Choose charge tenant if the tenant i to pay for this project'), 'charge_tenant' => isset($values['charge_tenant']) ? $values['charge_tenant'] : '', 'lang_power_meter' => lang('Power meter'), 'lang_power_meter_statustext' => lang('Enter the power meter'), 'value_power_meter' => isset($values['power_meter']) ? $values['power_meter'] : '', 'value_budget' => isset($values['budget']) ? $values['budget'] : '', 'lang_reserve' => lang('reserve'), 'value_reserve' => isset($values['reserve']) ? $values['reserve'] : '', 'lang_reserve_statustext' => lang('Enter the reserve'), 'value_sum' => isset($values['sum']) ? $values['sum'] : '', 'lang_reserve_remainder' => lang('reserve remainder'), 'value_reserve_remainder' => isset($reserve_remainder) ? $reserve_remainder : '', 'value_reserve_remainder_percent' => isset($remainder_percent) ? $remainder_percent : '', 'location_data' => $location_data, 'location_type' => 'form', 'form_action' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'done_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiproject.index')), 'lang_year' => lang('Year'), 'lang_category' => lang('category'), 'lang_save' => lang('save'), 'lang_done' => lang('done'), 'lang_name' => lang('Name'), 'lang_project_id' => lang('Project ID'), 'value_project_id' => isset($id) ? $id : '', 'project_group_data' => $project_group_data, 'value_name' => isset($values['name']) ? $values['name'] : '', 'lang_name_statustext' => lang('Enter Project Name'), 'lang_other_branch' => lang('Other branch'), 'lang_other_branch_statustext' => lang('Enter other branch if not found in the list'), 'value_other_branch' => isset($values['other_branch']) ? $values['other_branch'] : '', 'lang_descr_statustext' => lang('Enter a description of the project'), 'lang_descr' => lang('Description'), 'value_descr' => isset($values['descr']) ? $values['descr'] : '', 'lang_remark_statustext' => lang('Enter a remark to add to the history of the project'), 'lang_remark' => lang('remark'), 'value_remark' => isset($values['remark']) ? $values['remark'] : '', 'lang_done_statustext' => lang('Back to the list'), 'lang_save_statustext' => lang('Save the project'), 'lang_no_cat' => lang('Select category'), 'value_cat_id' => isset($values['cat_id']) ? $values['cat_id'] : '', 'cat_select' => $this->cats->formatted_xslt_list(array('select_name' => 'values[cat_id]', 'selected' => $values['cat_id'])), 'lang_workorder_id' => lang('Workorder ID'), 'lang_sum' => lang('Sum'), 'value_remainder' => $value_remainder, 'lang_remainder' => lang('remainder'), 'lang_coordinator' => lang('Coordinator'), 'lang_user_statustext' => lang('Select the coordinator the project belongs to. To do not use a category select NO USER'), 'select_user_name' => 'values[coordinator]', 'lang_no_user' => lang('Select coordinator'), 'user_list' => $this->bocommon->get_user_list_right2('select', 4, $values['coordinator'], $this->acl_location), 'status_list' => $this->bo->select_status_list('select', $values['status']), 'status_name' => 'values[status]', 'lang_no_status' => lang('Select status'), 'lang_status' => lang('Status'), 'lang_status_statustext' => lang('What is the current status of this project ?'), 'lang_confirm_status' => lang('Confirm status'), 'lang_confirm_statustext' => lang('Confirm status to the history'), 'branch_list' => $this->bo->select_branch_p_list(isset($id) ? $id : ''), 'lang_branch' => lang('branch'), 'lang_branch_statustext' => lang('Select the branches for this project'), 'key_responsible_list' => $this->bo->select_branch_list(isset($values['key_responsible']) ? $values['key_responsible'] : ''), 'lang_no_key_responsible' => lang('Select key responsible'), 'lang_key_responsible' => lang('key responsible'), 'lang_key_responsible_statustext' => lang('Select the key responsible for this project'), 'key_fetch_list' => $this->bo->select_key_location_list(isset($values['key_fetch']) ? $values['key_fetch'] : ''), 'lang_no_key_fetch' => lang('Where to fetch the key'), 'lang_key_fetch' => lang('key fetch location'), 'lang_key_fetch_statustext' => lang('Select where to fetch the key'), 'key_deliver_list' => $this->bo->select_key_location_list(isset($values['key_deliver']) ? $values['key_deliver'] : ''), 'lang_no_key_deliver' => lang('Where to deliver the key'), 'lang_key_deliver' => lang('key deliver location'), 'lang_key_deliver_statustext' => lang('Select where to deliver the key'), 'need_approval' => $need_approval, 'lang_ask_approval' => lang('Ask for approval'), 'lang_ask_approval_statustext' => lang('Check this to send a mail to your supervisor for approval'), 'value_approval_mail_address' => $supervisor_email, 'currency' => $GLOBALS['phpgw_info']['user']['preferences']['common']['currency'], 'base_java_notify_url' => "{menuaction:'property.notify.update_data',location_id:{$location_id},location_item_id:{$id}}", 'edit_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiproject.edit', 'id' => $id)), 'lang_edit_statustext' => lang('Edit this entry '), 'lang_edit' => lang('Edit'));
     //_debug_array($data);die;
     if ($auto_create) {
         $location = explode('-', $values['location_data']['location_code']);
         $level = count($location);
         for ($i = 1; $i < $level + 1; $i++) {
             $values['location']["loc{$i}"] = $location[$i - 1];
         }
         $values['street_name'] = $values['location_data']['street_name'];
         $values['street_number'] = $values['location_data']['street_number'];
         $values['location_name'] = $values['location_data']["loc{$level}_name"];
         $values['extra'] = $values['p'][0];
         unset($values['location_data']);
         unset($values['p']);
         $receipt = $this->bo->save($values, 'add', array());
         if (!$receipt['error']) {
             $id = $receipt['id'];
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiworkorder.edit', 'project_id' => $id));
         }
     }
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('menu');
     phpgwapi_yui::load_widget('connection');
     phpgwapi_yui::load_widget('loader');
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_yui::load_widget('animation');
     //			$template_vars = array();
     //			$template_vars['datatable'] = $datatable;
     $GLOBALS['phpgw']->css->validate_file('datatable');
     $GLOBALS['phpgw']->css->validate_file('property');
     $GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
     $appname = lang('project');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('edit' => $data));
     $GLOBALS['phpgw']->js->validate_file('yahoo', 'project.edit', 'property');
     phpgwapi_jquery::load_widget('core');
     $GLOBALS['phpgw']->js->validate_file('portico', 'ajax_project_edit', 'property');
 }
 public function edit()
 {
     $tabs = array('control_group' => array('label' => lang('Control_group'), 'link' => '#control_group'), 'control_items' => array('label' => lang('Control_items'), 'link' => '#control_items'));
     $tab_to_display = 'control_group';
     $control_group_id = phpgw::get_var('id', 'int');
     $new_control_group = false;
     if ($control_group_id) {
         $control_group = $this->so->get_single($control_group_id);
     } else {
         $control_group = new controller_control_group();
         $new_control_group = true;
     }
     if (isset($_POST['save_control_group'])) {
         if (!$this->add && !$this->edit) {
             phpgwapi_cache::message_set('No access', 'error');
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.index'));
         }
         $entity_id = phpgw::get_var('entity_id', 'int');
         $category_id = phpgw::get_var('category_id', 'int');
         $component_location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$category_id}");
         if (isset($control_group)) {
             $control_group->set_group_name(phpgw::get_var('group_name'));
             $control_group->set_procedure_id(phpgw::get_var('procedure'));
             $control_group->set_control_area_id(phpgw::get_var('control_area'));
             $control_group->set_building_part_id(phpgw::get_var('building_part'));
             $control_group->set_component_location_id($component_location_id);
             $attributes = phpgw::get_var('attributes');
             $attributes_operator = phpgw::get_var('attributes_operator');
             $criteria = array();
             if (is_array($attributes)) {
                 foreach ($attributes as $_key => $_value) {
                     if ($_value) {
                         $criteria[$_key]['value'] = $_value;
                         $criteria[$_key]['operator'] = $attributes_operator[$_key];
                     }
                 }
             }
             $control_group->set_component_criteria($criteria);
             if (isset($control_group_id) && $control_group_id > 0) {
                 $ctrl_group_id = $control_group_id;
                 if ($this->so->store($control_group)) {
                     $message = lang('messages_saved_form');
                 } else {
                     $error = lang('messages_form_error');
                 }
             } else {
                 $ctrl_group_id = $this->so->add($control_group);
                 if ($ctrl_group_id) {
                     $message = lang('messages_saved_form');
                 } else {
                     $error = lang('messages_form_error');
                 }
             }
             if ($new_control_group) {
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.edit', 'id' => $ctrl_group_id));
             } else {
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.view', 'id' => $ctrl_group_id));
             }
         }
     } else {
         if (isset($_POST['cancel_control_group'])) {
             if (isset($control_group_id) && $control_group_id > 0) {
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.view', 'id' => $control_group_id));
             } else {
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.index'));
             }
         } else {
             if (isset($_POST['remove_control_group_items'])) {
                 if (!$this->add && !$this->edit) {
                     phpgwapi_cache::message_set('No access', 'error');
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.index'));
                 }
                 $control_item_ids = array();
                 // Fetching selected control items
                 $control_tag_ids = phpgw::get_var('item_remove_ids');
                 foreach ($control_tag_ids as $control_item_id) {
                     $curr_control_item = $this->so_control_item->get_single($control_item_id);
                     $curr_control_item->set_control_group_id(null);
                     $this->so_control_item->store($curr_control_item);
                 }
                 // Sigurd: START as categories
                 $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
                 $cats->supress_info = true;
                 $control_areas = $cats->formatted_xslt_list(array('format' => 'filter', 'globals' => true, 'use_acl' => $this->_category_acl));
                 array_unshift($control_areas['cat_list'], array('cat_id' => '', 'name' => lang('select value')));
                 $control_area_array = array();
                 foreach ($control_areas['cat_list'] as $cat_list) {
                     $control_area_array[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name'], 'selected' => $control_group->get_control_area_id() == $cat_list['cat_id'] ? 1 : 0);
                 }
                 // END as categories
                 $procedure_array = $this->so_procedure->get_procedures(0, 0, 'title', 'ASC', null, null, array('control_areas' => $control_group->get_control_area_id()));
                 if ($this->flash_msgs) {
                     $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($this->flash_msgs);
                     $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
                 }
                 foreach ($procedure_array as $procedure) {
                     if ($control_group->get_procedure_id() && $procedure->get_id() == $control_group->get_procedure_id()) {
                         $procedure_options[] = array('id' => $procedure->get_id(), 'name' => $procedure->get_title(), 'selected' => 'yes');
                     } else {
                         $procedure_options[] = array('id' => $procedure->get_id(), 'name' => $procedure->get_title());
                     }
                 }
                 array_unshift($procedure_options, array('id' => '', 'name' => lang('select value')));
                 $building_part_options = $this->so->get_building_part_select_array($control_group->get_building_part_id());
                 $control_group_array = $control_group->toArray();
                 $control_items_array = $this->so_control_item->get(null, null, 'controller_control_item.control_area_id', true, null, null, array('available' => 'yes'));
                 $control_items = array();
                 foreach ($control_items_array as $control_item) {
                     $control_items[] = $control_item->serialize();
                 }
                 $selected_control_items_array = controller_socontrol_item_list::get_instance()->get_control_items($control_group->get_id());
                 $selected_control_items = array();
                 foreach ($selected_control_items_array as $ctrl_item) {
                     $selected_control_items[] = $ctrl_item->serialize();
                 }
                 phpgwapi_yui::tabview_setup('control_group_tabview');
                 $data = array('tabs' => phpgwapi_yui::tabview_generate($tabs, 'control_items'), 'value_id' => !empty($control_group) ? $control_group->get_id() : 0, 'editable' => true, 'procedure' => array('options' => $procedure_options), 'control_area' => array('options' => $control_area_array), 'control_group' => $control_group_array, 'control_items' => $control_items, 'selected_control_items' => $selected_control_items, 'building_part' => array('building_part_options' => $building_part_options));
                 $GLOBALS['phpgw_info']['flags']['app_header'] = lang('controller') . '::' . lang('Control_group');
                 phpgwapi_jquery::load_widget('core');
                 self::add_javascript('controller', 'yahoo', 'control_tabs.js');
                 self::add_javascript('controller', 'controller', 'ajax.js');
                 self::render_template_xsl(array('control_group/control_group_tabs', 'control_group/control_group', 'control_group/control_group_items'), $data);
             } else {
                 if (isset($_POST['save_control_group_items'])) {
                     if (!$this->add && !$this->edit) {
                         phpgwapi_cache::message_set('No access', 'error');
                         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.index'));
                     }
                     $tab_to_display = 'control_group_items';
                     //update control items with control group id
                     //$control_group_id = phpgw::get_var('control_group_id');
                     $control_item_ids = array();
                     // Fetching selected control items
                     $control_tag_ids = phpgw::get_var('control_tag_ids');
                     foreach ($control_tag_ids as $control_item_id) {
                         $curr_control_item = $this->so_control_item->get_single($control_item_id);
                         $curr_control_item->set_control_group_id($control_group_id);
                         $this->so_control_item->store($curr_control_item);
                     }
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uicontrol_group.view', 'id' => $control_group_id));
                 } else {
                     // Sigurd: START as categories
                     $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
                     $cats->supress_info = true;
                     $control_areas = $cats->formatted_xslt_list(array('format' => 'filter', 'globals' => true, 'use_acl' => $this->_category_acl));
                     array_unshift($control_areas['cat_list'], array('cat_id' => '', 'name' => lang('select value')));
                     $control_area_array = array();
                     foreach ($control_areas['cat_list'] as $cat_list) {
                         $control_area_array[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name'], 'selected' => $control_group->get_control_area_id() == $cat_list['cat_id'] ? 1 : 0);
                     }
                     // END as categories
                     $procedure_array = $this->so_procedure->get_procedures(0, 0, 'title', 'ASC', null, null, array('control_areas' => $control_group->get_control_area_id()));
                     if ($this->flash_msgs) {
                         $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($this->flash_msgs);
                         $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
                     }
                     foreach ($procedure_array as $procedure) {
                         $procedure_options[] = array('id' => $procedure->get_id(), 'name' => $procedure->get_title(), 'selected' => $procedure->get_id() == $control_group->get_procedure_id() ? 1 : 0);
                     }
                     array_unshift($procedure_options, array('id' => '', 'name' => lang('select value')));
                     $building_part_options = $this->so->get_building_part_select_array($control_group->get_building_part_id());
                     $control_group_array = $control_group->toArray();
                     $control_items_array = $this->so_control_item->get(null, null, 'controller_control_item.control_area_id', true, null, null, array('available' => 'yes'));
                     $control_items = array();
                     foreach ($control_items_array as $control_item) {
                         $control_items[] = $control_item->serialize();
                     }
                     $selected_control_items_array = controller_socontrol_item_list::get_instance()->get_control_items($control_group->get_id());
                     $selected_control_items = array();
                     foreach ($selected_control_items_array as $ctrl_item) {
                         $selected_control_items[] = $ctrl_item->serialize();
                     }
                     phpgwapi_yui::tabview_setup('control_group_tabview');
                     //--- sigurd 10.juni 13
                     $entity_so = CreateObject('property.soadmin_entity');
                     $custom = createObject('phpgwapi.custom_fields');
                     $entity_list = $entity_so->read(array('allrows' => true));
                     $attributes = array();
                     array_unshift($entity_list, array('id' => '', 'name' => lang('select value')));
                     $component_location_id = $control_group->get_component_location_id();
                     if ($component_location_id) {
                         $loc_arr = $GLOBALS['phpgw']->locations->get_name($component_location_id);
                         $entity_arr = explode('.', $loc_arr['location']);
                         $entity = $entity_so->read_single($entity_arr[2]);
                         $category = $entity_so->read_single_category($entity_arr[2], $entity_arr[3]);
                         foreach ($entity_list as &$e) {
                             if ($e['id'] == $entity['id']) {
                                 $e['selected'] = 1;
                             }
                         }
                         $category_list = $entity_so->read_category(array('allrows' => true, 'entity_id' => $entity_arr[2]));
                         array_unshift($category_list, array('id' => '', 'name' => lang('select value')));
                         foreach ($category_list as &$c) {
                             if ($c['id'] == $category['id']) {
                                 $c['selected'] = 1;
                             }
                         }
                         $attributes = $custom->find('property', ".entity.{$entity_arr[2]}.{$entity_arr[3]}", 0, '', '', '', true, true);
                         $operator1 = array(array('id' => 'eq', 'name' => '='));
                         $operator2 = array(array('id' => 'eq', 'name' => '='), array('id' => 'lt', 'name' => '<'), array('id' => 'gt', 'name' => '>'));
                         $component_criteria = $control_group->get_component_criteria();
                         foreach ($attributes as $key => &$a) {
                             switch ($a['datatype']) {
                                 case 'LB':
                                 case 'R':
                                 case 'CH':
                                     $a['operator'] = array('options' => $operator1);
                                     break;
                                 default:
                                     $a['operator'] = array('options' => $operator2);
                             }
                             if (isset($component_criteria[$key]['value']) && $component_criteria[$key]['value']) {
                                 $a['value'] = $component_criteria[$key]['value'];
                                 if (isset($a['choice']) && $a['choice']) {
                                     foreach ($a['choice'] as &$choise) {
                                         $choise['selected'] = $choise['id'] == $component_criteria[$key]['value'] ? 1 : 0;
                                     }
                                 }
                             }
                             if (isset($component_criteria[$key]['operator']) && $component_criteria[$key]['operator']) {
                                 if (isset($a['operator']) && $a['operator']) {
                                     foreach ($a['operator']['options'] as &$_operator) {
                                         $_operator['selected'] = $_operator['id'] == $component_criteria[$key]['operator'] ? 1 : 0;
                                     }
                                 }
                             }
                         }
                     }
                     //---
                     $data = array('entities' => array('options' => $entity_list), 'categories' => array('options' => $category_list), 'attributes' => $attributes, 'tabs' => phpgwapi_yui::tabview_generate($tabs, $tab_to_display), 'value_id' => !empty($control_group) ? $control_group->get_id() : 0, 'editable' => true, 'procedure' => array('options' => $procedure_options), 'control_area' => array('options' => $control_area_array), 'control_group' => $control_group_array, 'control_items' => $control_items, 'selected_control_items' => $selected_control_items, 'building_part' => array('building_part_options' => $building_part_options));
                     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('controller') . '::' . lang('Control_group');
                     /*
                     				$GLOBALS['phpgw']->richtext->replace_element('what_to_do');
                     				$GLOBALS['phpgw']->richtext->replace_element('how_to_do');
                     				$GLOBALS['phpgw']->richtext->generate_script();
                     */
                     //			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'controller.item', 'controller' );
                     phpgwapi_jquery::load_widget('core');
                     self::add_javascript('controller', 'yahoo', 'control_tabs.js');
                     self::add_javascript('controller', 'controller', 'ajax.js');
                     self::add_javascript('controller', 'controller', 'control_group_to_component.js');
                     self::render_template_xsl(array('control_group/control_group_tabs', 'control_group/control_group', 'control_group/control_group_items'), $data);
                 }
             }
         }
     }
 }
Exemple #25
0
phpgwapi_yui::load_widget('resize');
$javascripts = array("/phpgwapi/js/json/json.js");
if (!isset($GLOBALS['phpgw_info']['flags']['noframework'])) {
    phpgwapi_yui::load_widget('layout');
    $javascripts[] = "/phpgwapi/templates/portico/js/base.js";
}
if (!$GLOBALS['phpgw_info']['flags']['noframework'] && !$GLOBALS['phpgw_info']['flags']['nonavbar']) {
    $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/examples/treeview/assets/css/folders/tree.css');
    phpgwapi_yui::load_widget('treeview');
    phpgwapi_yui::load_widget('datasource');
    if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent'] == 'ajax_menu') {
        $javascripts[] = "/phpgwapi/templates/portico/js/menu.js";
    } else {
        if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent'] == 'jsmenu') {
            phpgw::import_class('phpgwapi.jquery');
            phpgwapi_jquery::load_widget('menu');
        }
    }
}
phpgwapi_yui::load_widget('button');
$stylesheets = array();
if (!isset($GLOBALS['phpgw_info']['flags']['no_reset_fonts'])) {
    $stylesheets[] = '/phpgwapi/js/yahoo/reset-fonts-grids/reset-fonts-grids.css';
}
$stylesheets[] = "/phpgwapi/js/yahoo/tabview/assets/skins/sam/tabview.css";
$stylesheets[] = "/phpgwapi/js/yahoo/resize/assets/skins/sam/resize.css";
$stylesheets[] = "/phpgwapi/js/yahoo/layout/assets/skins/sam/layout.css";
$stylesheets[] = "/phpgwapi/js/yahoo/menu/assets/skins/sam/menu.css";
$stylesheets[] = "/phpgwapi/js/yahoo/button/assets/skins/sam/button.css";
$stylesheets[] = "/phpgwapi/templates/portico/css/base.css";
if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['theme'])) {
 function index()
 {
     $receipt = array();
     if (phpgw::get_var('phpgw_return_as') == 'json') {
         return $this->query();
     }
     $msgbox_data = array();
     if (phpgw::get_var('phpgw_return_as') != 'json' && ($receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))) {
         phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
         $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($receipt);
         $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
     }
     $myColumnDefs = array();
     $datavalues = array();
     $myButtons = array();
     $datavalues[] = array('name' => "0", 'values' => $this->query(), 'total_records' => 0, 'permission' => "''", 'is_paginator' => 0, 'edit_action' => "''", 'footer' => 0);
     $datatable = array(array('key' => 'id', 'hidden' => true), array('key' => 'user', 'label' => lang('user'), 'sortable' => false), array('key' => 'ecodimb', 'label' => lang('dim b'), 'sortable' => false, 'formatter' => 'FormatterRight'), array('key' => 'role', 'label' => lang('role'), 'formatter' => 'FormatterRight', 'sortable' => true), array('key' => 'default_user', 'label' => lang('default'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'active_from', 'label' => lang('date from'), 'sortable' => true, 'formatter' => 'FormatterRight'), array('key' => 'active_to', 'label' => lang('date to'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'add', 'label' => lang('add'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'delete', 'label' => lang('delete'), 'sortable' => false, 'formatter' => 'FormatterCenter'), array('key' => 'alter_date', 'label' => lang('alter date'), 'sortable' => false, 'formatter' => 'FormatterCenter'));
     $myColumnDefs[0] = array('name' => "0", 'values' => json_encode($datatable));
     $user_list = $this->bocommon->get_user_list_right2('select', PHPGW_ACL_READ, $this->filter, '.invoice', array(), $this->account_id);
     $role_list = execMethod('property.bogeneric.get_list', array('type' => 'dimb_role', 'selected' => $role));
     $dimb_list = execMethod('property.bogeneric.get_list', array('type' => 'dimb', 'selected' => $dimb));
     array_unshift($user_list, array('id' => '', 'name' => lang('select')));
     array_unshift($role_list, array('id' => '', 'name' => lang('select')));
     array_unshift($dimb_list, array('id' => '', 'name' => lang('select')));
     $data = array('td_count' => '""', 'property_js' => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . "/property/js/yahoo/property2.js"), 'datatable' => $datavalues, 'myColumnDefs' => $myColumnDefs, 'myButtons' => $myButtons, 'msgbox_data' => $msgbox_data, 'filter_form' => array('user_list' => array('options' => $user_list), 'role_list' => array('options' => $role_list), 'dimb_list' => array('options' => $dimb_list)), 'update_action' => self::link(array('menuaction' => 'property.uidimb_role_user.edit')));
     $GLOBALS['phpgw']->jqcal->add_listener('query_start');
     $GLOBALS['phpgw']->jqcal->add_listener('query_end');
     $GLOBALS['phpgw']->jqcal->add_listener('active_from');
     $GLOBALS['phpgw']->jqcal->add_listener('active_to');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('connection');
     phpgwapi_yui::load_widget('loader');
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_yui::load_widget('animation');
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('property', 'portico', 'ajax_dimb_role_user.js');
     self::add_javascript('property', 'yahoo', 'dimb_role_user.index.js');
     $GLOBALS['phpgw']->xslttpl->add_file(array('dimb_role_user'));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('data' => $data));
 }
 /**
  * Public function for viewing chosen control items
  * 
  * @param HTTP::id the control_id
  * @return data array 
  */
 public function view_check_list()
 {
     $control_id = phpgw::get_var('control_id');
     $control = $this->so->get_single($control_id);
     // Fetches saved control groups from DB for this control
     $saved_control_groups = $this->so_control_group_list->get_control_groups_by_control($control_id);
     $saved_groups_with_items_array = array();
     // Populating array with saved control items for each group
     foreach ($saved_control_groups as $control_group) {
         // Fetches saved control items for group
         $saved_control_items = $this->so_control_item_list->get_control_items_by_control_and_group($control_id, $control_group->get_id());
         if (count($saved_control_items) > 0) {
             $saved_groups_with_items_array[] = array("control_group" => $control_group->toArray(), "control_items" => $saved_control_items);
         }
     }
     $tabs = $this->make_tab_menu($control_id);
     $data = array('tabs' => $GLOBALS['phpgw']->common->create_tabs($tabs, 3), 'view' => "sort_check_list", 'control' => $control, 'saved_groups_with_items_array' => $saved_groups_with_items_array);
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'yahoo', 'control_tabs.js');
     self::add_javascript('controller', 'controller', 'custom_ui.js');
     self::add_javascript('controller', 'controller', 'custom_drag_drop.js');
     self::add_javascript('controller', 'controller', 'ajax.js');
     self::render_template_xsl(array('control/control_tabs', 'control_item/sort_check_list'), $data);
 }
 /**
  * 
  */
 private function _insert_custom_js()
 {
     $criteria = array('appname' => 'property', 'location' => $this->acl_location, 'allrows' => true);
     if (!($custom_functions = $GLOBALS['phpgw']->custom_functions->find($criteria))) {
         return false;
     }
     $js_found = false;
     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'] && $entry['client_side'] && is_file($file)) {
             $GLOBALS['phpgw']->js->add_external_file("/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}");
             $js_found = true;
         }
     }
     if ($js_found) {
         phpgw::import_class('phpgwapi.jquery');
         phpgwapi_jquery::load_widget('core');
     }
 }
 public function view_resource_allocation()
 {
     $activity_id = phpgw::get_var('activity_id');
     $activity = $this->so->get_single($activity_id);
     $data = array('form' => array('toolbar' => array('item' => array(array('type' => 'text', 'text' => lang('search'), 'name' => 'query'), array('type' => 'submit', 'name' => 'search', 'value' => lang('Search'))))), 'datatable' => array('source' => self::link(array('menuaction' => 'logistic.uirequirement.index', 'activity_id' => $activity_id, 'phpgw_return_as' => 'json')), 'field' => array(array('key' => 'id', 'label' => lang('Id'), 'sortable' => true), array('key' => 'start_date', 'label' => lang('Start date'), 'sortable' => false), array('key' => 'end_date', 'label' => lang('End date'), 'sortable' => false), array('key' => 'no_of_items', 'label' => lang('Num required'), 'sortable' => false), array('key' => 'allocated', 'label' => lang('Num allocated'), 'sortable' => false), array('key' => 'location_label', 'label' => lang('Resource type'), 'sortable' => false), array('key' => 'criterias', 'label' => lang('Criterias'), 'sortable' => false), array('key' => 'link', 'hidden' => true), array('key' => 'id', 'className' => 'requirement_id', 'hidden' => true), array('key' => 'status', 'label' => lang('Status requirement'), 'sortable' => false))));
     if ($this->acl_add) {
         $data['datatable']['field'][] = array('key' => 'alloc_link', 'label' => lang('Allocate resources'), 'sortable' => false);
     }
     if ($this->acl_add) {
         $data['datatable']['field'][] = array('key' => 'edit_requirement_link', 'label' => lang('Edit requirement'), 'sortable' => false);
     }
     if ($this->acl_delete) {
         $data['datatable']['field'][] = array('key' => 'delete_requirement_link', 'label' => lang('Delete requirement'), 'sortable' => false);
     }
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('paginator');
     phpgwapi_jquery::load_widget('core');
     $tabs = $this->make_tab_menu($activity_id);
     $data['tabs'] = $GLOBALS['phpgw']->common->create_tabs($tabs, 1);
     $data['view'] = 'requirement_overview';
     $data['activity'] = $activity;
     $data['breadcrumb'] = $this->_get_breadcrumb($activity_id, 'logistic.uiactivity.view_resource_allocation', 'activity_id');
     $data['acl_add'] = $this->acl_add;
     self::add_javascript('logistic', 'logistic', 'resource_allocation.js');
     self::add_javascript('logistic', 'logistic', 'requirement_overview.js');
     self::add_javascript('logistic', 'logistic', 'requirement.js');
     self::add_javascript('phpgwapi', 'tinybox2', 'packed.js');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
     self::render_template_xsl(array('activity/view_activity_item', 'requirement/requirement_overview', 'activity/activity_tabs'), $data);
 }
 /**
  * Edit a contract
  */
 public function edit()
 {
     $GLOBALS['phpgw_info']['flags']['app_header'] .= '::' . lang('edit');
     $contract_id = (int) phpgw::get_var('id');
     $location_id = (int) phpgw::get_var('location_id');
     $update_price_items = false;
     phpgw::import_class('phpgwapi.jquery');
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('rental', 'rental', 'contract.edit.js');
     $message = null;
     $error = null;
     $add_default_price_items = false;
     if (isset($_POST['save_contract'])) {
         if (isset($contract_id) && $contract_id > 0) {
             $contract = rental_socontract::get_instance()->get_single($contract_id);
             // Gets responsibility area from db (ex: eksternleie, internleie)
             $responsibility_area = rental_socontract::get_instance()->get_responsibility_title($contract->get_location_id());
             // Redirect with error message if responsibility area is eksternleie and contract type not set
             if (!is_numeric(phpgw::get_var('contract_type')) && strcmp($responsibility_area, "contract_type_eksternleie") == 0) {
                 $error = lang('billing_removed_external_contract');
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => $message, 'error' => $error));
             }
             if (!$contract->has_permission(PHPGW_ACL_EDIT)) {
                 unset($contract);
                 $this->render('permission_denied.php', array('error' => lang('permission_denied_edit_contract')));
             }
         } else {
             // Gets responsibility area from db (ex: eksternleie, internleie)
             $responsibility_area = rental_socontract::get_instance()->get_responsibility_title($location_id);
             // Redirect with error message if responsibility area is eksternleie and contract type not set
             if (!is_numeric(phpgw::get_var('contract_type')) && strcmp($responsibility_area, "contract_type_eksternleie") == 0) {
                 $error = lang('billing_removed_external_contract');
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'location_id' => $location_id, 'message' => $message, 'error' => $error));
             }
             if (isset($location_id) && ($this->isExecutiveOfficer() || $this->isAdministrator())) {
                 $contract = new rental_contract();
                 $fields = rental_socontract::get_instance()->get_fields_of_responsibility();
                 $contract->set_location_id($location_id);
                 $contract->set_contract_type_title($fields[$location_id]);
                 $add_default_price_items = true;
             }
         }
         $date_start = phpgwapi_datetime::date_to_timestamp(phpgw::get_var('date_start'));
         $date_end = phpgwapi_datetime::date_to_timestamp(phpgw::get_var('date_end'));
         if (isset($contract)) {
             $contract->set_contract_date(new rental_contract_date($date_start, $date_end));
             $contract->set_security_type(phpgw::get_var('security_type'));
             $contract->set_security_amount(phpgw::get_var('security_amount'));
             $contract->set_executive_officer_id(phpgw::get_var('executive_officer'));
             $contract->set_comment(phpgw::get_var('comment'));
             if (isset($location_id) && $location_id > 0) {
                 $contract->set_location_id($location_id);
                 // only present when new contract
             }
             $contract->set_term_id(phpgw::get_var('billing_term'));
             $contract->set_billing_start_date(phpgwapi_datetime::date_to_timestamp(phpgw::get_var('billing_start_date')));
             $contract->set_billing_end_date(phpgwapi_datetime::date_to_timestamp(phpgw::get_var('billing_end_date')));
             $contract->set_service_id(phpgw::get_var('service_id'));
             $contract->set_responsibility_id(phpgw::get_var('responsibility_id'));
             $contract->set_reference(phpgw::get_var('reference'));
             $contract->set_invoice_header(phpgw::get_var('invoice_header'));
             $contract->set_account_in(phpgw::get_var('account_in'));
             /*
             					if($contract->get_contract_type_id() != phpgw::get_var('contract_type'))
             					{
             						// New contract type id set, retrieve correct account out
             						$type_id = phpgw::get_var('contract_type');
             						if(isset($type_id) && $type_is != ''){
             							$account = rental_socontract::get_instance()->get_contract_type_account($type_id);
             							$contract->set_account_out($account);
             						}
             						else
             						{
             							$contract->set_account_out(phpgw::get_var('account_out'));
             						}
             					}
             					else
             					{*/
             $contract->set_account_out(phpgw::get_var('account_out'));
             //}
             $contract->set_project_id(phpgw::get_var('project_id'));
             $contract->set_due_date(phpgwapi_datetime::date_to_timestamp(phpgw::get_var('due_date')));
             $contract->set_contract_type_id(phpgw::get_var('contract_type'));
             $old_rented_area = $contract->get_rented_area();
             $new_rented_area = phpgw::get_var('rented_area');
             $new_rented_area = str_replace(',', '.', $new_rented_area);
             $validated_numeric = false;
             if (!isset($new_rented_area) || $new_rented_area == '') {
                 $new_rented_area = 0;
             }
             if ($old_rented_area != $new_rented_area) {
                 $update_price_items = true;
             }
             $contract->set_rented_area($new_rented_area);
             $contract->set_adjustment_interval(phpgw::get_var('adjustment_interval'));
             $contract->set_adjustment_share(phpgw::get_var('adjustment_share'));
             $contract->set_adjustable(phpgw::get_var('adjustable') == 'on' ? true : false);
             $contract->set_publish_comment(phpgw::get_var('publish_comment') == 'on' ? true : false);
             $validated_numeric = $contract->validate_numeric();
             if ($validated_numeric) {
                 $so_contract = rental_socontract::get_instance();
                 $db_contract = $so_contract->get_db();
                 $db_contract->transaction_begin();
                 if ($so_contract->store($contract)) {
                     if ($update_price_items) {
                         $success = $so_contract->update_price_items($contract->get_id(), $new_rented_area);
                         if ($success) {
                             $db_contract->transaction_commit();
                             $message = lang('messages_saved_form');
                             $contract_id = $contract->get_id();
                         } else {
                             $db_contract->transaction_abort();
                             $error = lang('messages_form_error');
                         }
                     } else {
                         if ($add_default_price_items) {
                             $so_price_item = rental_soprice_item::get_instance();
                             //get default price items for location_id
                             $default_price_items = $so_contract->get_default_price_items($contract->get_location_id());
                             //add price_items to contract
                             foreach ($default_price_items as $price_item_id) {
                                 $so_price_item->add_price_item($contract->get_id(), $price_item_id);
                             }
                             $db_contract->transaction_commit();
                             $message = lang('messages_saved_form');
                             $contract_id = $contract->get_id();
                         } else {
                             $db_contract->transaction_commit();
                             $message = lang('messages_saved_form');
                             $contract_id = $contract->get_id();
                         }
                     }
                 } else {
                     $db_contract->transaction_abort();
                     $error = lang('messages_form_error');
                 }
             } else {
                 $error = $contract->get_validation_errors();
                 return $this->viewedit(true, $contract_id, $contract, $location_id, $notification, $message, $error);
             }
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => $message, 'error' => $error));
     } else {
         if (isset($_POST['add_notification'])) {
             $contract = rental_socontract::get_instance()->get_single($contract_id);
             if ($contract->has_permission(PHPGW_ACL_EDIT)) {
                 $account_id = phpgw::get_var('notification_target');
                 $location_id = phpgw::get_var('notification_location');
                 $date = phpgw::get_var('date_notification');
                 if ($date) {
                     $date = phpgwapi_datetime::date_to_timestamp($date);
                 }
                 $notification = new rental_notification(-1, $account_id, $location_id, $contract_id, $date, phpgw::get_var('notification_message'), phpgw::get_var('notification_recurrence'));
                 if (rental_sonotification::get_instance()->store($notification)) {
                     $message = lang('messages_saved_form');
                     $notification = null;
                     // We don't want to display the date/message when it was sucessfully stored.
                 } else {
                     $error = lang('messages_form_error');
                 }
             } else {
                 $error = lang('permission_denied_edit_contract');
             }
         }
     }
     return $this->viewedit(true, $contract_id, null, $location_id, $notification, $message, $error);
 }