/**
  * @param mixed $data
  * If $data is an array - then the process is run as cron - and will look for $data['function'] to
  * determine which custom class to load
  */
 function index($data = '')
 {
     if (!isset($GLOBALS['phpgw_info']['user']['apps']['admin'])) {
         return;
     }
     if (is_array($data)) {
         $function = $data['function'];
     } else {
         $data = unserialize(urldecode(phpgw::get_var('data')));
         $data = phpgw::clean_value($data);
         if (!isset($data['function'])) {
             $function = phpgw::get_var('function');
         } else {
             $function = $data['function'];
         }
     }
     // prevent path traversal
     if (preg_match('/\\.\\./', $function)) {
         return;
     }
     $file = PHPGW_SERVER_ROOT . "/property/inc/cron/{$GLOBALS['phpgw_info']['user']['domain']}/{$function}.php";
     if (is_file($file)) {
         require_once $file;
         $custom = new $function();
         $custom->pre_run($data);
     } else {
         echo "no such file: path_to_phpgw_server_root/property/inc/cron/{$GLOBALS['phpgw_info']['user']['domain']}/{$function}.php";
     }
 }
/**
 * Cherry pick selected values into a new array
 * 
 * @param array $array    input array
 * @param array $keys     array of keys to pick
 *
 * @return array containg values from $array for the keys in $keys.
 */
function extract_values($array, $keys)
{
    $result = array();
    foreach ($keys as $key) {
        if (in_array($key, array_keys($array))) {
            $result[$key] = phpgw::clean_value($array[$key]);
        }
    }
    return $result;
}
 public function index()
 {
     $config = CreateObject('phpgwapi.config', 'booking');
     $config->read();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         foreach ($_POST as $dim => $value) {
             if (strlen(trim($value)) > 0) {
                 $config->value($dim, phpgw::clean_value($value));
             } else {
                 unset($config->config_data[$dim]);
             }
         }
         $config->save_repository();
     }
     $this->use_yui_editor();
     self::render_template('metasettings', array('config_data' => $config->config_data));
 }
 function responsiblility_role()
 {
     $type_id = phpgw::get_var('type_id', 'int');
     $dry_run = false;
     if (!$type_id) {
         $type_id = 1;
     }
     if ($_menu_selection = phpgw::get_var('menu_selection')) {
         $GLOBALS['phpgw_info']['flags']['menu_selection'] = $_menu_selection;
     } else {
         $GLOBALS['phpgw_info']['flags']['menu_selection'] .= '::responsibility_role';
     }
     if (!$this->acl_read) {
         $this->bocommon->no_access();
         return;
     }
     $values = phpgw::get_var('values');
     $values_assign = $_POST['values_assign'];
     $role_id = phpgw::get_var('role_id', 'int');
     $receipt = array();
     //	$_role = CreateObject('property.sogeneric');
     //	$_role->get_location_info('responsibility_role','');
     $this->save_sessiondata();
     $user_id = phpgw::get_var('user_id', 'int', 'request', $this->account);
     if ($values_assign && $this->acl_edit) {
         $values_assign = phpgw::clean_value(json_decode(stripslashes($values_assign), true));
         //json_decode has issues with magic_quotes_gpc
         $user_id = abs($user_id);
         $account = $GLOBALS['phpgw']->accounts->get($user_id);
         $contact_id = $account->person_id;
         if (!$role_id) {
             $receipt['error'][] = array('msg' => lang('missing role'));
         } else {
             //		$role = $_role->read_single($data=array('id' => $role_id));
             $values['contact_id'] = $contact_id;
             //		$values['responsibility_id']	= $role['responsibility_id'];
             $values['responsibility_role_id'] = $role_id;
             $values['assign'] = $values_assign['assign'];
             $values['assign_orig'] = $values_assign['assign_orig'];
             $boresponsible = CreateObject('property.boresponsible');
             $receipt = $boresponsible->update_role_assignment($values);
         }
     }
     $second_display = phpgw::get_var('second_display', 'bool');
     $default_district = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['default_district']) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['default_district'] : '';
     if ($default_district && !$second_display && !$this->district_id) {
         $this->bo->district_id = $default_district;
         $this->district_id = $default_district;
     }
     $datatable = array();
     $values_combo_box = array();
     if (phpgw::get_var('phpgw_return_as') != 'json') {
         $datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uilocation.responsiblility_role', 'type_id' => $type_id, 'query' => $this->query, 'district_id' => $this->district_id, 'part_of_town_id' => $this->part_of_town_id, 'lookup' => $lookup, 'lookup_tenant' => $lookup_tenant, 'lookup_name' => $lookup_name, 'cat_id' => $this->cat_id, 'status' => $this->status, 'location_code' => $this->location_code, 'menu_selection' => $_menu_selection, 'download_type' => 'responsiblility_role'));
         $datatable['config']['allow_allrows'] = true;
         $datatable['config']['base_java_url'] = "menuaction:'property.uilocation.responsiblility_role'," . "type_id:'{$type_id}'," . "query:'{$this->query}'," . "district_id: '{$this->district_id}'," . "part_of_town_id:'{$this->part_of_town_id}'," . "lookup:'{$lookup}'," . "second_display:1," . "lookup_tenant:'{$lookup_tenant}'," . "lookup_name:'{$lookup_name}'," . "cat_id:'{$this->cat_id}'," . "status:'{$this->status}'," . "location_code:'{$this->location_code}'," . "block_query:'{$block_query}'," . "menu_selection:'{$_menu_selection}'," . "download_type:'responsiblility_role'";
         $values_combo_box[0] = execMethod('property.soadmin_location.read', array());
         //$values_combo_box[0]  = array(array('id'=>'1','name'=> 'Eiendom'));
         $values_combo_box[1] = $this->bocommon->select_category_list(array('format' => 'filter', 'selected' => $this->cat_id, 'type' => 'location', 'type_id' => $type_id, 'order' => 'descr'));
         $default_value = array('id' => '', 'name' => lang('no category'));
         array_unshift($values_combo_box[1], $default_value);
         $values_combo_box[2] = $this->bocommon->select_district_list('filter', $this->district_id);
         $default_value = array('id' => '', 'name' => lang('no district'));
         array_unshift($values_combo_box[2], $default_value);
         $values_combo_box[3] = $this->bocommon->select_part_of_town('filter', $this->part_of_town_id, $this->district_id);
         $default_value = array('id' => '', 'name' => lang('no part of town'));
         array_unshift($values_combo_box[3], $default_value);
         /*
         				$_role_criteria = array
         				(
         					'allrows'	=> true,
         					'order'		=> 'name'
         				);
         
         
         				$roles = $_role->read($_role_criteria);
         				foreach ($roles as $role)
         				{
         					if(ctype_digit(ltrim($role['location'],'.location')))
         					{
         						 $values_combo_box[5][] = array
         						 (
         							'id'		=> $role['id'],
         							'name'		=> $role['name'],
         							'type_id'	=> ltrim($role['location'],'.location')
         						 );
         					}
         				}
         
         				$default_value = array ('id'=>'','name'=>lang('no role'));
         				array_unshift ($values_combo_box[5],$default_value);
         */
         $_role_criteria = array('type' => 'responsibility_role', 'filter' => array('location_level' => $type_id), 'filter_method' => 'like', 'order' => 'name');
         $values_combo_box[4] = execMethod('property.sogeneric.get_list', $_role_criteria);
         foreach ($values_combo_box[4] as &$_role) {
             $_role['name'] .= ':: ' . execMethod('property.soresponsible.get_responsibility_name_from_role', $_role['id']);
         }
         $default_value = array('id' => '', 'name' => lang('no role'));
         array_unshift($values_combo_box[4], $default_value);
         //				$values_combo_box[5]  = $this->bocommon->get_user_list_right2('filter',PHPGW_ACL_READ,$this->user_id,".location.{$type_id}");
         $_users = $GLOBALS['phpgw']->accounts->get_list('accounts', -1, 'ASC', 'account_lastname', '', -1);
         $values_combo_box[5] = array();
         foreach ($_users as $_user) {
             $values_combo_box[5][] = array('id' => $_user->id, 'name' => $_user->__toString());
         }
         unset($_users);
         unset($_user);
         array_unshift($values_combo_box[5], array('id' => -1 * $GLOBALS['phpgw_info']['user']['account_id'], 'name' => lang('mine roles')));
         $default_value = array('id' => '', 'name' => lang('no user'));
         array_unshift($values_combo_box[5], $default_value);
         $datatable['actions']['form'] = array(array('action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uilocation.responsiblility_role', 'entity_id' => $this->entity_id, 'cat_id' => $this->cat_id, 'district_id' => $this->district_id, 'query' => $this->query, 'filter' => $this->filter, 'sort' => $this->sort, 'order' => $this->order, 'menu_selection' => $_menu_selection, 'download_type' => 'responsiblility_role')), 'fields' => array('field' => array(array('id' => 'btn_type_id', 'name' => 'type_id', 'value' => lang('location type'), 'type' => 'button', 'style' => 'filter', 'tab_index' => 1), array('id' => 'btn_cat_id', 'name' => 'cat_id', 'value' => lang('Category'), 'type' => 'button', 'style' => 'filter', 'tab_index' => 2), array('id' => 'btn_district_id', 'name' => 'district_id', 'value' => lang('District'), 'type' => 'button', 'style' => 'filter', 'tab_index' => 3), array('id' => 'btn_part_of_town_id', 'name' => 'part_of_town_id', 'value' => lang('Part of Town'), 'type' => 'button', 'style' => 'filter', 'tab_index' => 4), array('id' => 'btn_role_id', 'name' => 'role_id', 'value' => lang('role'), 'type' => 'button', 'style' => 'filter', 'tab_index' => 5), array('id' => 'sel_user_id', 'name' => 'user_id', 'value' => lang('User'), 'type' => 'select', 'style' => 'filter', 'values' => $values_combo_box[5], 'onchange' => 'onChangeSelect();', 'tab_index' => 6), array('id' => 'btn_save', 'value' => lang('save'), 'tab_index' => 7, 'type' => 'button'), array('id' => 'btn_search', 'name' => 'search', 'value' => lang('search'), 'type' => 'button', 'tab_index' => 8), array('id' => 'btn_export', 'type' => 'button', 'value' => lang('download'), 'tab_index' => 9), array('name' => 'query', 'id' => 'txt_query', 'value' => '', 'type' => 'text', 'size' => 28, 'onkeypress' => 'return pulsar(event)', 'tab_index' => 7), array('type' => 'hidden', 'id' => 'event', 'value' => '')), 'hidden_value' => array(array('id' => 'values_combo_box_0', 'value' => $this->bocommon->select2String($values_combo_box[0])), array('id' => 'values_combo_box_1', 'value' => $this->bocommon->select2String($values_combo_box[1])), array('id' => 'values_combo_box_2', 'value' => $this->bocommon->select2String($values_combo_box[2])), array('id' => 'values_combo_box_3', 'value' => $this->bocommon->select2String($values_combo_box[3])), array('id' => 'values_combo_box_4', 'value' => $this->bocommon->select2String($values_combo_box[4]))))));
         $dry_run = true;
     }
     $location_list = array();
     $location_list = $this->bo->get_responsible(array('user_id' => $user_id, 'role_id' => $role_id, 'type_id' => $type_id, 'lookup_tenant' => $lookup_tenant, 'lookup' => $lookup, 'allrows' => $this->allrows, 'dry_run' => $dry_run));
     $uicols = $this->bo->uicols;
     $uicols['name'][] = 'responsible_contact';
     $uicols['descr'][] = lang('responsible');
     $uicols['sortable'][] = false;
     $uicols['sort_field'][] = '';
     $uicols['format'][] = '';
     $uicols['formatter'][] = '';
     $uicols['input_type'][] = '';
     $uicols['name'][] = 'responsible_contact_id';
     $uicols['descr'][] = 'dummy';
     $uicols['sortable'][] = false;
     $uicols['sort_field'][] = '';
     $uicols['format'][] = '';
     $uicols['formatter'][] = '';
     $uicols['input_type'][] = 'hidden';
     $uicols['name'][] = 'responsible_item';
     $uicols['descr'][] = 'dummy';
     $uicols['sortable'][] = false;
     $uicols['sort_field'][] = '';
     $uicols['format'][] = '';
     $uicols['formatter'][] = '';
     $uicols['input_type'][] = 'hidden';
     $uicols['name'][] = 'select';
     $uicols['descr'][] = lang('select');
     $uicols['sortable'][] = false;
     $uicols['sort_field'][] = '';
     $uicols['format'][] = '';
     $uicols['formatter'][] = $this->acl_edit ? 'myFormatterCheck' : '';
     $uicols['input_type'][] = '';
     $content = array();
     $j = 0;
     if (isset($location_list) && is_array($location_list)) {
         foreach ($location_list as $location) {
             for ($i = 0; $i < count($uicols['name']); $i++) {
                 if ($uicols['input_type'][$i] != 'hidden') {
                     if (isset($location['query_location'][$uicols['name'][$i]])) {
                         $datatable['rows']['row'][$j]['column'][$i]['name'] = $uicols['name'][$i];
                         $datatable['rows']['row'][$j]['column'][$i]['statustext'] = lang('search');
                         $datatable['rows']['row'][$j]['column'][$i]['value'] = $location[$uicols['name'][$i]];
                         $datatable['rows']['row'][$j]['column'][$i]['format'] = 'link';
                         $datatable['rows']['row'][$j]['column'][$i]['java_link'] = true;
                         $datatable['rows']['row'][$j]['column'][$i]['link'] = $location['query_location'][$uicols['name'][$i]];
                     } else {
                         $datatable['rows']['row'][$j]['column'][$i]['value'] = $location[$uicols['name'][$i]];
                         //$datatable['rows']['row'][$j]['column'][$i]['value'] 			= $i;
                         $datatable['rows']['row'][$j]['column'][$i]['name'] = $uicols['name'][$i];
                         $datatable['rows']['row'][$j]['column'][$i]['lookup'] = $lookup;
                         $datatable['rows']['row'][$j]['column'][$i]['align'] = isset($uicols['align'][$i]) ? $uicols['align'][$i] : 'center';
                         if (isset($uicols['datatype']) && isset($uicols['datatype'][$i]) && $uicols['datatype'][$i] == 'link' && $location[$uicols['name'][$i]]) {
                             $datatable['rows']['row'][$j]['column'][$i]['format'] = 'link';
                             $datatable['rows']['row'][$j]['column'][$i]['value'] = lang('link');
                             $datatable['rows']['row'][$j]['column'][$i]['link'] = $location[$uicols['name'][$i]];
                             $datatable['rows']['row'][$j]['column'][$i]['target'] = '_blank';
                         }
                     }
                 } else {
                     $datatable['rows']['row'][$j]['column'][$i]['name'] = $uicols['name'][$i];
                     $datatable['rows']['row'][$j]['column'][$i]['value'] = $location[$uicols['name'][$i]];
                 }
                 $datatable['rows']['row'][$j]['hidden'][$i]['value'] = $location[$uicols['name'][$i]];
                 $datatable['rows']['row'][$j]['hidden'][$i]['name'] = $uicols['name'][$i];
             }
             $j++;
         }
     }
     // NO pop-up
     $datatable['rowactions']['action'] = array();
     //$uicols_count indicates the number of columns to display in actuall option-menu. this variable was set in $this->bo->read()
     $uicols_count = count($uicols['descr']);
     for ($i = 0; $i < $uicols_count; $i++) {
         //all colums should be have formatter
         $datatable['headers']['header'][$i]['formatter'] = !isset($uicols['formatter'][$i]) || !$uicols['formatter'][$i] ? '""' : $uicols['formatter'][$i];
         if ($uicols['input_type'][$i] != 'hidden') {
             $datatable['headers']['header'][$i]['name'] = $uicols['name'][$i];
             $datatable['headers']['header'][$i]['text'] = $uicols['descr'][$i];
             $datatable['headers']['header'][$i]['visible'] = true;
             $datatable['headers']['header'][$i]['format'] = $this->bocommon->translate_datatype_format($uicols['datatype'][$i]);
             $datatable['headers']['header'][$i]['sortable'] = false;
             //$datatable['headers']['header'][$i]['formatter']		= (isset($uicols['formatter'][$i])? $uicols['formatter'][$i]:"");
             if ($uicols['name'][$i] == 'loc1') {
                 $datatable['headers']['header'][$i]['sortable'] = true;
                 $datatable['headers']['header'][$i]['sort_field'] = 'loc1';
             } else {
                 if ($uicols['name'][$i] == 'street_name') {
                     $datatable['headers']['header'][$i]['sortable'] = true;
                     $datatable['headers']['header'][$i]['sort_field'] = 'street_name';
                 } else {
                     if (isset($uicols['cols_return_extra'][$i]) && ($uicols['cols_return_extra'][$i] != 'T' || $uicols['cols_return_extra'][$i] != 'CH')) {
                         $datatable['headers']['header'][$i]['sortable'] = true;
                         $datatable['headers']['header'][$i]['sort_field'] = $uicols['name'][$i];
                     }
                 }
             }
         } else {
             $datatable['headers']['header'][$i]['name'] = $uicols['name'][$i];
             $datatable['headers']['header'][$i]['text'] = $uicols['descr'][$i];
             $datatable['headers']['header'][$i]['visible'] = false;
             $datatable['headers']['header'][$i]['sortable'] = false;
             $datatable['headers']['header'][$i]['format'] = 'hidden';
         }
     }
     // path for property.js
     $property_js = "/property/js/yahoo/property.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, '/'));
     }
     $datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url'] . $property_js;
     // Pagination and sort values
     $datatable['pagination']['records_start'] = (int) $this->bo->start;
     $datatable['pagination']['records_limit'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     if ($dry_run) {
         $datatable['pagination']['records_returned'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $datatable['pagination']['records_returned'] = count($location_list);
     }
     $datatable['pagination']['records_total'] = $this->bo->total_records;
     if (phpgw::get_var("start") == "" && phpgw::get_var("order", 'string') == "") {
         $datatable['sorting']['order'] = 'loc1';
         // name key Column in myColumnDef
         $datatable['sorting']['sort'] = 'asc';
         // ASC / DESC
     } else {
         $datatable['sorting']['order'] = phpgw::get_var('order', 'string');
         // name of column of Database
         $datatable['sorting']['sort'] = phpgw::get_var('sort', 'string');
         // ASC / DESC
     }
     $appname = lang('location');
     $function_msg = lang('role');
     //-- BEGIN----------------------------- JSON CODE ------------------------------
     //values for Pagination
     $json = array('recordsReturned' => $datatable['pagination']['records_returned'], 'totalRecords' => (int) $datatable['pagination']['records_total'], 'startIndex' => $datatable['pagination']['records_start'], 'sort' => $datatable['sorting']['order'], 'dir' => $datatable['sorting']['sort'], 'records' => array(), 'headers' => $uicols);
     // values for datatable
     if (isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])) {
         foreach ($datatable['rows']['row'] as $row) {
             $json_row = array();
             foreach ($row['column'] as $column) {
                 if (isset($column['format']) && $column['format'] == "link" && isset($column['java_link']) && $column['java_link'] == true) {
                     $json_row[$column['name']] = "<a href='#' id='" . $column['link'] . "' onclick='javascript:filter_data(this.id);'>" . $column['value'] . "</a>";
                 } else {
                     if (isset($column['format']) && $column['format'] == "link") {
                         $json_row[$column['name']] = "<a href='" . $column['link'] . "' target='_blank'>" . $column['value'] . "</a>";
                     } else {
                         $json_row[$column['name']] = $column['value'];
                     }
                 }
             }
             $json['records'][] = $json_row;
         }
     }
     // values for control select
     //cr@ccfirst.com 10/09/08 values passed for update select in YUI
     $opt_cb_depend = $this->bocommon->select_part_of_town('filter', $this->part_of_town_id, $this->district_id);
     $default_value = array('id' => '', 'name' => '!no part of town');
     array_unshift($opt_cb_depend, $default_value);
     $json['hidden']['dependent'][] = array('id' => $this->part_of_town_id, 'value' => $this->bocommon->select2String($opt_cb_depend));
     // right in datatable
     if (isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action'])) {
         $json['rights'] = $datatable['rowactions']['action'];
     }
     if (isset($receipt) && is_array($receipt) && count($receipt)) {
         $json['message'][] = $receipt;
     }
     if (phpgw::get_var('phpgw_return_as') == 'json') {
         return $json;
     }
     $datatable['json_data'] = json_encode($json);
     //-------------------- JSON CODE ----------------------
     // Prepare template variables and process XSLT
     $template_vars = array();
     $template_vars['datatable'] = $datatable;
     $GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
     phpgwapi_yui::load_widget('dragdrop');
     phpgwapi_yui::load_widget('datatable');
     phpgwapi_yui::load_widget('menu');
     phpgwapi_yui::load_widget('connection');
     //// cramirez: necesary for include a partucular js
     phpgwapi_yui::load_widget('loader');
     //cramirez: necesary for use opener . Avoid error JS
     phpgwapi_yui::load_widget('tabview');
     phpgwapi_yui::load_widget('paginator');
     //FIXME this one is only needed when $lookup==true - so there is probably an error
     phpgwapi_yui::load_widget('animation');
     if (!isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css)) {
         $GLOBALS['phpgw']->css = createObject('phpgwapi.css');
     }
     // Prepare CSS Style
     $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/container/assets/skins/sam/container.css');
     $GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
     //Title of Page
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . '::' . $appname . '::' . $function_msg;
     // Prepare YUI Library
     $GLOBALS['phpgw']->js->validate_file('yahoo', 'location.responsiblility_role', 'property');
 }
 private function _populate($data = array())
 {
     $insert_record = phpgwapi_cache::session_get('property', 'insert_record');
     $values = phpgw::get_var('values');
     $_fields = array(array('name' => 'title', 'type' => 'string', 'required' => true), array('name' => 'descr', 'type' => 'string', 'required' => true), array('name' => 'cat_id', 'type' => 'integer', 'required' => true), array('name' => 'report_date', 'type' => 'string', 'required' => true), array('name' => 'status_id', 'type' => 'integer', 'required' => true), array('name' => 'vendor_id', 'type' => 'integer', 'required' => false), array('name' => 'vendor_name', 'type' => 'string', 'required' => false), array('name' => 'coordinator_id', 'type' => 'integer', 'required' => false), array('name' => 'coordinator_name', 'type' => 'string', 'required' => false), array('name' => 'multiplier', 'type' => 'float', 'required' => false));
     foreach ($_fields as $_field) {
         if ($data[$_field['name']] = $_POST['values'][$_field['name']]) {
             $data[$_field['name']] = phpgw::clean_value($data[$_field['name']], $_field['type']);
         }
         if ($_field['required'] && !$data[$_field['name']]) {
             $this->receipt['error'][] = array('msg' => lang('Please enter value for attribute %1', $_field['name']));
         }
     }
     //_debug_array($data);die();
     $values = $this->bocommon->collect_locationdata($data, $insert_record);
     if (!isset($values['location_code']) || !$values['location_code']) {
         $this->receipt['error'][] = array('msg' => lang('Please select a location !'));
     }
     /*
      * Extra data from custom fields
      */
     $values['attributes'] = phpgw::get_var('values_attribute');
     if (is_array($values['attributes'])) {
         foreach ($values['attributes'] as $attribute) {
             if ($attribute['nullable'] != 1 && (!$attribute['value'] && !$values['extra'][$attribute['name']])) {
                 $this->receipt['error'][] = array('msg' => lang('Please enter value for attribute %1', $attribute['input_text']));
             }
         }
     }
     if (!isset($values['cat_id']) || !$values['cat_id']) {
         $this->receipt['error'][] = array('msg' => lang('Please select a category !'));
     }
     if (!isset($values['title']) || !$values['title']) {
         $this->receipt['error'][] = array('msg' => lang('Please give a title !'));
     }
     if (!isset($values['report_date']) || !$values['report_date']) {
         $this->receipt['error'][] = array('msg' => lang('Please select a date!'));
     }
     return $values;
 }
 function export_cron($data = array())
 {
     if (!$data) {
         $data = unserialize(urldecode(phpgw::get_var('data')));
         $data = phpgw::clean_value($data);
     }
     _debug_array($data);
     $receipt = $this->export($data);
     _debug_array($receipt);
 }
     if (phpgw::get_var('phpgw_return_as', 'string') == 'json') {
         header('Content-Type: application/json');
         echo json_encode(array('sessionExpired' => true));
         $GLOBALS['phpgw_info']['flags']['nofooter'] = true;
         $GLOBALS['phpgw']->common->phpgw_exit();
     } else {
         $GLOBALS['phpgw']->redirect_link('/login.php', $cd_array);
     }
 }
 if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] != $GLOBALS['phpgw_info']['server']['default_lang']) {
     $GLOBALS['phpgw']->translation->set_userlang($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'], true);
 }
 $redirect = unserialize(phpgw::get_var('redirect', 'raw', 'COOKIE'));
 if (is_array($redirect) && count($redirect)) {
     foreach ($redirect as $key => $value) {
         $redirect_data[$key] = phpgw::clean_value($value);
     }
     $sessid = phpgw::get_var('sessionid', 'string', 'GET');
     if ($sessid) {
         $redirect_data['sessionid'] = $sessid;
         $redirect_data['kp3'] = phpgw::get_var('kp3', 'string', 'GET');
     }
     $GLOBALS['phpgw']->session->phpgw_setcookie('redirect', false, 0);
     $GLOBALS['phpgw']->redirect_link('/index.php', $redirect_data);
     unset($redirect);
     unset($redirect_data);
     unset($sessid);
 }
 /* A few hacker resistant constants that will be used throught the program */
 define('PHPGW_TEMPLATE_DIR', ExecMethod('phpgwapi.phpgw.common.get_tpl_dir', 'phpgwapi'));
 define('PHPGW_IMAGES_DIR', ExecMethod('phpgwapi.phpgw.common.get_image_path', 'phpgwapi'));
Beispiel #8
0
        unset($_COOKIE['last_usertype']);
    }
}
$last_loginid = phpgw::get_var('last_loginid', 'string', 'COOKIE');
if ($GLOBALS['phpgw_info']['server']['show_domain_selectbox'] && $last_loginid !== '') {
    reset($GLOBALS['phpgw_domain']);
    list($default_domain) = each($GLOBALS['phpgw_domain']);
    if ($_COOKIE['last_domain'] != $default_domain && !empty($_COOKIE['last_domain'])) {
        $last_loginid .= '@' . phpgw::get_var('last_domain', 'string', 'COOKIE');
    }
}
//FIXME switch to an array
$extra_vars = array();
foreach ($_GET as $name => $value) {
    if (preg_match('/phpgw_/', $name)) {
        $extra_vars[$name] = urlencode(phpgw::clean_value($value));
    }
}
$cd = 0;
if (isset($_GET['cd'])) {
    $cd = (int) $_GET['cd'];
}
$tmpl->set_var('login_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/property/login.php?' . http_build_query($extra_vars));
$tmpl->set_var('registration_url', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/registration/');
$tmpl->set_var('version', $GLOBALS['phpgw_info']['server']['versions']['phpgwapi']);
$tmpl->set_var('cd', check_logoutcode($cd));
$tmpl->set_var('last_loginid', $last_loginid);
$tmpl->set_var('lang_username', lang('username'));
$tmpl->set_var('lang_password', lang('password'));
$tmpl->set_var('lang_login', lang('login'));
$tmpl->set_var('lang_testjs', lang('Your browser does not support javascript and/or css, please use a modern standards compliant browser.  If you have disabled either of these features please enable them for this site.'));
    function prepare_for_db($table, $values_attribute, $id = 0)
    {
        $id = (int) $id;
        $data = array();
        if (isset($values_attribute) && is_array($values_attribute)) {
            foreach ($values_attribute as $entry) {
                if ($entry['disabled']) {
                    continue;
                }
                switch ($entry['datatype']) {
                    case 'C':
                    case 'T':
                    case 'V':
                    case 'link':
                    case 'email':
                    case 'link':
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? $this->_db2->db_addslashes(phpgw::clean_value($entry['value'], 'string')) : '';
                        $entry['value'] = $this->_db2->db_addslashes($entry['value']);
                        // in case of history entries
                        break;
                    case 'LB':
                    case 'R':
                    case 'AB':
                    case 'ABO':
                    case 'AB':
                    case 'ABO':
                    case 'VENDOR':
                    case 'event':
                    case 'I':
                    case 'custom3':
                    case 'user':
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? phpgw::clean_value($entry['value'], 'int') : '';
                        break;
                    case 'bolean':
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? phpgw::clean_value($entry['value'], 'bool') : '';
                        break;
                    case 'N':
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? phpgw::clean_value($entry['value'], 'float') : '';
                        break;
                    case 'CH':
                        $_value = ',' . implode(',', phpgw::clean_value($entry['value'])) . ',';
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? $_value : '';
                        break;
                    case 'D':
                    case 'DT':
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? $entry['value'] : '';
                        break;
                    case 'pwd':
                        if ($entry['value'] && $entry['value2']) {
                            if ($entry['value'] || $entry['value2']) {
                                if ($entry['value'] == $entry['value2']) {
                                    $data['value_set'][$entry['name']] = md5($entry['value']);
                                } else {
                                    throw new Exception(lang('Passwords do not match!'));
                                }
                            }
                        } else {
                            $data['value_set'][$entry['name']] = isset($entry['value']) ? $entry['value'] : '';
                        }
                        break;
                    default:
                        $data['value_set'][$entry['name']] = isset($entry['value']) && $entry['value'] ? $this->_db2->db_addslashes(phpgw::clean_value($entry['value'], 'string')) : '';
                }
                if ($entry['history'] == 1) {
                    if ($id) {
                        $this->_db2->query("SELECT {$entry['name']} FROM {$table} WHERE id = {$id}", __LINE__, __FILE__);
                        $this->_db2->next_record();
                        $old_value = $this->_db2->f($entry['name']);
                        if ($entry['value'] != $old_value) {
                            $data['history_set'][$entry['attrib_id']] = array('
									value' => $entry['value'], 'date' => phpgwapi_datetime::date_to_timestamp($entry['date']));
                        }
                    } else {
                        $data['history_set'][$entry['attrib_id']] = $entry['value'];
                    }
                }
            }
        }
        return $data;
    }
 function prizing()
 {
     if (!$this->acl_manage) {
         $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uilocation.stop', 'perm' => 16, 'acl_location' => $this->acl_location));
     }
     $GLOBALS['phpgw']->xslttpl->add_file(array('pricebook', 'nextmatchs', 'search_field'));
     $cat_id = phpgw::get_var('cat_id', 'int', 'GET');
     $activity_id = phpgw::get_var('activity_id', 'int');
     $vendor_id = phpgw::get_var('vendor_id', 'int', 'GET');
     $agreement_id = phpgw::get_var('agreement_id', 'int', 'GET');
     $values = phpgw::get_var('values');
     $referer = $GLOBALS['phpgw']->session->appsession('referer', 'property');
     if (!$referer) {
         $referer = phpgw::get_var('HTTP_REFERER', 'string', 'SERVER', phpgw::clean_value($GLOBALS['HTTP_REFERER']));
         $referer .= '&cat_id=' . $cat_id;
         $GLOBALS['phpgw']->session->appsession('referer', 'property', $referer);
     }
     if ($values['submit_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 new index for calculating next value(s)!'));
         }
         if (!$receipt['error']) {
             $receipt = $this->bo->update_pricebook($values);
         }
     }
     if ($values['submit_add']) {
         if (!$values['date']) {
             $receipt['error'][] = array('msg' => lang('Please select a date !'));
         }
         if (!$values['m_cost'] && !$values['w_cost']) {
             $receipt['error'][] = array('msg' => lang('Please enter a value for either material cost, labour cost or both !'));
         }
         if (!$receipt['error']) {
             $receipt = $this->bo->add_activity_first_prize($values);
         }
     }
     $pricebook_list = $this->bo->read_activity_prize($activity_id, $agreement_id);
     $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
     if (isset($pricebook_list) and is_array($pricebook_list)) {
         foreach ($pricebook_list as $pricebook) {
             if ($pricebook['current_index']) {
                 $link_delete = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uipricebook.delete', 'method' => 'prize', 'activity_id' => $activity_id, 'agreement_id' => $agreement_id, 'index_count' => $pricebook['index_count']));
                 $value_m_cost = $pricebook['m_cost'];
                 $value_w_cost = $pricebook['w_cost'];
                 $value_total_cost = $pricebook['total_cost'];
             }
             $content[] = array('m_cost' => $pricebook['m_cost'], 'w_cost' => $pricebook['w_cost'], 'total_cost' => $pricebook['total_cost'], 'this_index' => $pricebook['this_index'], 'date' => $GLOBALS['phpgw']->common->show_date($pricebook['date'], $dateformat), 'current_index' => $pricebook['current_index'], 'index_count' => $pricebook['index_count'], 'link_delete' => $link_delete, 'lang_delete_statustext' => lang('Delete this entry'), 'text_delete' => lang('delete'));
         }
     }
     //_debug_array($content);
     $table_header[] = array('lang_index_count' => lang('Index Count'), 'lang_total_cost' => lang('Total Cost'), 'lang_prizing' => lang('Prizing'), 'lang_last_index' => lang('Last index'), 'lang_m_cost' => lang('Material cost'), 'lang_w_cost' => lang('Labour cost'), 'lang_date' => lang('Date'), 'lang_delete' => lang('Delete'));
     $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'));
     $table_first_entry[] = array('lang_m_cost' => lang('Material cost'), 'lang_m_cost_statustext' => lang('Enter a value for the material cost'), 'lang_w_cost' => lang('Labour cost'), 'lang_w_cost_statustext' => lang('Enter a value for the labour cost'), 'lang_date' => lang('Date'), 'lang_date_statustext' => lang('Select the date for the first value'), 'lang_add' => lang('Add'), 'lang_add_statustext' => lang('Add first value for this prizing'));
     $link_data = array('menuaction' => 'property.uipricebook.prizing', 'activity_id' => $activity_id, 'agreement_id' => $agreement_id);
     if (!$this->allrows) {
         $record_limit = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $record_limit = $this->bo->total_records;
     }
     $num_records = count($pricebook_list);
     $vendor_data = $this->contacts->read_single(array('id' => $vendor_id), array('attributes' => array(array('column_name' => 'org_name'))));
     if (is_array($vendor_data)) {
         foreach ($vendor_data['attributes'] as $attribute) {
             if ($attribute['name'] == 'org_name') {
                 $value_vendor_name = $attribute['value'];
                 break;
             }
         }
     }
     $activity = $this->bo->read_single_activity($activity_id);
     $msgbox_data = $this->bocommon->msgbox_data($receipt);
     $data = array('msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'done_action' => $referer, 'lang_done' => lang('done'), 'lang_done_statustext' => lang('Back to the list'), 'allrows' => $this->allrows, 'allow_allrows' => true, 'start_record' => $this->start, 'record_limit' => $record_limit, 'num_records' => $num_records, 'all_records' => $this->bo->total_records, 'link_url' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'img_path' => $GLOBALS['phpgw']->common->get_image_path('phpgwapi', 'default'), 'lang_vendor' => lang('Vendor'), 'lang_activity' => lang('Activity'), 'value_vendor_name' => $value_vendor_name, 'value_activity_id' => $activity_id, 'value_activity_code' => $activity['num'], 'value_vendor_id' => $vendor_id, 'value_m_cost' => $value_m_cost, 'value_w_cost' => $value_w_cost, 'value_total_cost' => $value_total_cost, 'table_header_prizing' => $table_header, 'values_prizing' => $content, 'table_update' => $table_update, 'table_first_entry' => $table_first_entry, 'update_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uipricebook.prizing', 'activity_id' => $activity_id, 'vendor_id' => $vendor_id)));
     $appname = lang('pricebook');
     $function_msg = lang('edit pricing');
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('prizing' => $data));
     //	$GLOBALS['phpgw']->xslttpl->pp();
     $this->save_sessiondata();
 }
 public function import($survey, $import_data = array())
 {
     if (!isset($survey['id']) || !$survey['id']) {
         throw new Exception('property_socondition_survey::import - missing id');
     }
     $location_data = execMethod('property.solocation.read_single', $survey['location_code']);
     $_locations = explode('-', $survey['location_code']);
     $i = 1;
     foreach ($_locations as $_location) {
         $location["loc{$i}"] = $_location;
         $i++;
     }
     $sorequest = CreateObject('property.sorequest');
     $this->_db->transaction_begin();
     $config = CreateObject('phpgwapi.config', 'property');
     $config->read();
     if (!$survey['location_code']) {
         throw new Exception('property_socondition_survey::import - condition survey location_code not configured');
     }
     //FIXME
     if (!isset($config->config_data['condition_survey_import_cat']) || !is_array($config->config_data['condition_survey_import_cat'])) {
         throw new Exception('property_socondition_survey::import - condition survey import categories not configured');
     }
     if (!isset($config->config_data['condition_survey_initial_status']) || !$config->config_data['condition_survey_initial_status']) {
         throw new Exception('property_socondition_survey::import - condition survey initial status not configured');
     }
     if (!isset($config->config_data['condition_survey_hidden_status']) || !$config->config_data['condition_survey_hidden_status']) {
         throw new Exception('property_socondition_survey::import - condition survey hidden status not configured');
     }
     /**
      * Park old request on the location and below as obsolete
      */
     if (isset($config->config_data['condition_survey_obsolete_status']) && $config->config_data['condition_survey_obsolete_status']) {
         $this->_db->query("UPDATE fm_request SET status = '{$config->config_data['condition_survey_obsolete_status']}'" . " WHERE location_code {$this->_db->like} '{$survey['location_code']}%'", __LINE__, __FILE__);
     } else {
         //				throw new Exception('property_socondition_survey::import - condition survey obsolete status not configured');
     }
     $cats = CreateObject('phpgwapi.categories', -1, 'property', '.project');
     $cats->supress_info = true;
     $categories = $cats->return_sorted_array(0, false, '', '', '', $globals = true, '', $use_acl = false);
     /*
     		$import_types = array
     		(
     			1 => 'Hidden',
     			2 => 'Normal import',
     			3 => 'Users/Customers responsibility',
     		);
     */
     $import_type_responsibility = array();
     $import_type_responsibility[1] = 1;
     //hidden => responsible_unit 1
     $import_type_responsibility[2] = 1;
     //'Normal import' => responsible_unit 1
     $import_type_responsibility[3] = 2;
     //'Customers' => responsible_unit 2
     $import_type_responsibility[4] = 3;
     //'Customers' => responsible_unit 3
     $import_type_responsibility[5] = 4;
     //'Customers' => responsible_unit 3
     $import_type_responsibility[6] = 5;
     //'Customers' => responsible_unit 3
     $import_type_responsibility[7] = 6;
     //'Customers' => responsible_unit 3
     $import_type_responsibility[8] = 7;
     //'Customers' => responsible_unit 3
     /*
     		$cats_candidates = array
     		(
     			1 => 'Investment',
     			2 => 'Operation',
     			3 => 'Combined::Investment/Operation',
     		);
     */
     $_update_buildingpart = array();
     $filter_buildingpart = isset($config->config_data['filter_buildingpart']) ? $config->config_data['filter_buildingpart'] : array();
     if ($filter_key = array_search('.project.request', $filter_buildingpart)) {
         $_update_buildingpart = array("filter_{$filter_key}" => 1);
     }
     foreach ($import_data as &$entry) {
         $entry['amount_investment'] = (int) str_replace(array(' ', ','), array('', '.'), $entry['amount_investment']);
         $entry['amount_operation'] = (int) str_replace(array(' ', ','), array('', '.'), $entry['amount_operation']);
         $entry['amount_potential_grants'] = (int) str_replace(array(' ', ','), array('', '.'), $entry['amount_potential_grants']);
         $entry['import_type'] = (int) $entry['import_type'];
         $entry['condition_degree'] = (int) $entry['condition_degree'];
         $entry['amount'] = $entry['amount_investment'] + $entry['amount_operation'] + $entry['amount_potential_grants'];
     }
     unset($entry);
     $custom = createObject('phpgwapi.custom_fields');
     $attributes = $custom->find('property', '.project.request', 0, '', '', '', true, true);
     $origin_id = $GLOBALS['phpgw']->locations->get_id('property', '.project.condition_survey');
     foreach ($import_data as $entry) {
         //if( $entry['condition_degree'] > 0 && $entry['building_part'] && $entry['import_type'] > 0)
         if ($entry['amount'] && $entry['building_part'] && $entry['import_type'] > 0) {
             $request = array();
             if ($entry['amount_investment'] && !$entry['amount_operation']) {
                 if (isset($config->config_data['condition_survey_import_cat'][1])) {
                     $request['cat_id'] = (int) $config->config_data['condition_survey_import_cat'][1];
                 }
             }
             if (!$entry['amount_investment'] && $entry['amount_operation']) {
                 if (isset($config->config_data['condition_survey_import_cat'][2])) {
                     $request['cat_id'] = (int) $config->config_data['condition_survey_import_cat'][2];
                 }
             } else {
                 if (isset($config->config_data['condition_survey_import_cat'][3])) {
                     $request['cat_id'] = (int) $config->config_data['condition_survey_import_cat'][3];
                 }
             }
             if (!isset($request['cat_id']) || !$request['cat_id']) {
                 $request['cat_id'] = (int) $categories[0]['id'];
             }
             $this->_check_building_part($entry['building_part'], $_update_buildingpart);
             $request['condition_survey_id'] = $survey['id'];
             $request['multiplier'] = $survey['multiplier'];
             $request['street_name'] = $location_data['street_name'];
             $request['street_number'] = $location_data['street_number'];
             $request['location'] = $location;
             $request['location_code'] = $survey['location_code'];
             $request['origin_id'] = $origin_id;
             $request['origin_item_id'] = (int) $survey['id'];
             $request['title'] = substr($entry['title'], 0, 255);
             $request['descr'] = phpgw::clean_value($entry['descr'], 'string');
             $request['building_part'] = phpgw::clean_value($entry['building_part'], 'string');
             $request['coordinator'] = $survey['coordinator_id'];
             if ($entry['import_type'] == 1) {
                 $request['status'] = $config->config_data['condition_survey_hidden_status'];
             } else {
                 $request['status'] = $config->config_data['condition_survey_initial_status'];
             }
             $request['amount_investment'] = $entry['amount_investment'];
             $request['amount_operation'] = $entry['amount_operation'];
             $request['amount_potential_grants'] = $entry['amount_potential_grants'];
             $request['planning_value'] = $entry['amount'];
             $request['planning_date'] = mktime(13, 0, 0, 7, 1, $entry['due_year'] ? (int) $entry['due_year'] : date('Y'));
             $request['recommended_year'] = $entry['due_year'] ? (int) $entry['due_year'] : date('Y');
             $request['responsible_unit'] = (int) $import_type_responsibility[$entry['import_type']];
             $request['condition'] = array(array('degree' => $entry['condition_degree'], 'condition_type' => $entry['condition_type'], 'consequence' => $entry['consequence'], 'probability' => $entry['probability']));
             $values_attribute = array();
             foreach ($entry as $_field => $_value) {
                 if (preg_match('/^custom_attribute_/', $_field) && $_value) {
                     $attribute_id = (int) ltrim($_field, 'custom_attribute_');
                     $values_attribute[] = array('name' => $attributes[$attribute_id]['column_name'], 'value' => $_value, 'datatype' => $attributes[$attribute_id]['datatype']);
                 }
             }
             $sorequest->add($request, $values_attribute);
         }
     }
     $this->_db->transaction_commit();
 }
 function edit()
 {
     if (!$this->acl_add) {
         $this->bocommon->no_access();
         return;
     }
     $id = phpgw::get_var($this->location_info['id']['name']);
     $values = phpgw::get_var('values');
     $values_attribute = phpgw::get_var('values_attribute');
     $GLOBALS['phpgw_info']['apps']['manual']['section'] = 'general.edit.' . $this->type;
     $GLOBALS['phpgw']->xslttpl->add_file(array('generic', 'attributes_form'));
     $receipt = array();
     if (is_array($values)) {
         $insert_record_attributes = $GLOBALS['phpgw']->session->appsession("insert_record_values{$this->acl_location}", $this->location_info['acl_app']);
         if (is_array($insert_record_attributes)) {
             foreach ($insert_record_attributes as $attribute) {
                 foreach ($values_attribute as &$attr) {
                     if ($attr['name'] == $attribute) {
                         $attr['value'] = phpgw::get_var($attribute, 'string', 'POST');
                     }
                 }
             }
         }
         //				$values = $this->bocommon->collect_locationdata($values,$insert_record_values);
         if (isset($values['save']) && $values['save'] || isset($values['apply']) && $values['apply']) {
             if ($GLOBALS['phpgw']->session->is_repost()) {
                 $receipt['error'][] = array('msg' => lang('Hmm... looks like a repost!'));
             }
             if (!$id && !$values[$this->location_info['id']['name']] && $this->location_info['id']['type'] != 'auto') {
                 $receipt['error'][] = array('msg' => lang('missing value for %1', lang('id')));
             }
             foreach ($this->location_info['fields'] as $field_info) {
                 if (isset($field_info['nullable']) && $field_info['nullable'] != true) {
                     if (!$values[$field_info['name']]) {
                         $receipt['error'][] = array('msg' => lang('missing value for %1', $field_info['descr']));
                     }
                 }
                 if ($field_info['type'] == 'int') {
                     if ($values[$field_info['name']] && !ctype_digit($values[$field_info['name']])) {
                         $receipt['error'][] = array('msg' => "{$field_info['descr']}: " . lang('Please enter an integer !'));
                     }
                 } else {
                     if ($field_info['type'] == 'numeric') {
                         $values[$field_info['name']] = str_replace(',', '.', $values[$field_info['name']]);
                         if ($values[$field_info['name']] && !is_numeric($values[$field_info['name']])) {
                             $receipt['error'][] = array('msg' => "{$field_info['descr']}: " . lang('Please enter a numeric value !'));
                         }
                     }
                 }
             }
             if ($values['id'] && $this->location_info['id']['type'] == 'int' && !ctype_digit($values['id'])) {
                 $receipt['error'][] = array('msg' => lang('Please enter an integer !'));
                 unset($values['id']);
             }
             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 (isset($attribute['value']) && $attribute['value'] && $attribute['datatype'] == 'I' && !ctype_digit($attribute['value'])) {
                         $receipt['error'][] = array('msg' => lang('Please enter integer for attribute %1', $attribute['input_text']));
                     }
                 }
             }
             if ($id) {
                 $values['id'] = $id;
                 $action = 'edit';
             } else {
                 $id = $values['id'];
             }
             if (!$receipt['error']) {
                 $receipt = $this->bo->save($values, $action, $values_attribute);
                 if (isset($values['save']) && $values['save']) {
                     $GLOBALS['phpgw']->session->appsession('session_data', "general_receipt_{$this->type}_{$this->type_id}", $receipt);
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uigeneric.index', 'appname' => $this->appname, 'type' => $this->type, 'type_id' => $this->type_id));
                 }
                 $id = $receipt['id'];
             }
         } else {
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uigeneric.index', 'appname' => $this->appname, 'type' => $this->type, 'type_id' => $this->type_id));
         }
     }
     if ($id) {
         $values = $this->bo->read_single(array('id' => $id));
         $function_msg = $this->location_info['edit_msg'];
         $action = 'edit';
     } else {
         $values = $this->bo->read_single();
         $function_msg = $this->location_info['add_msg'];
         $action = 'add';
     }
     /* Preserve attribute values from post */
     if (isset($receipt['error'])) {
         foreach ($this->location_info['fields'] as $field) {
             $values[$field['name']] = phpgw::clean_value($_POST['values'][$field['name']]);
         }
         if (isset($values_attribute) && is_array($values_attribute)) {
             $values = $this->custom->preserve_attribute_values($values, $values_attribute);
         }
     }
     $link_data = array('menuaction' => 'property.uigeneric.edit', 'id' => $id, 'appname' => $this->appname, 'type' => $this->type, 'type_id' => $this->type_id);
     $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.uigeneric.attrib_history', 'appname' => $this->appname, 'attrib_id' => $attribute['id'], 'actor_id' => $actor_id, 'role' => $this->role, 'acl_location' => $this->acl_location, 'edit' => true);
                 $attribute['link_history'] = $GLOBALS['phpgw']->link('/index.php', $link_history_data);
             }
         }
         phpgwapi_yui::tabview_setup('general_edit_tabview');
         $attributes_groups = $this->custom->get_attribute_groups($this->location_info['acl_app'], $this->acl_location, $values['attributes']);
         //_debug_array($attributes_groups);die();
         if (isset($attributes_groups[0]['id']) && $attributes_groups[0]['id'] > 0 || count($attributes_groups) > 1) {
             //					$tabs['general']	= array('label' => lang('general'), 'link' => '#general');
         }
         $attributes = array();
         foreach ($attributes_groups as $group) {
             if (isset($group['attributes']) && isset($tabs['general'])) {
                 //						$tabs[str_replace(' ', '_', $group['name'])] = array('label' => $group['name'], 'link' => '#' . str_replace(' ', '_', $group['name']));
                 //						$group['link'] = str_replace(' ', '_', $group['name']);
             }
             $attributes[] = $group;
         }
         unset($attributes_groups);
         unset($values['attributes']);
     }
     foreach ($this->location_info['fields'] as &$field) {
         $field['value'] = isset($values[$field['name']]) ? $values[$field['name']] : '';
         if (isset($field['values_def'])) {
             if ($field['values_def']['valueset'] && is_array($field['values_def']['valueset'])) {
                 $field['valueset'] = $field['values_def']['valueset'];
                 foreach ($field['valueset'] as &$_entry) {
                     $_entry['selected'] = $_entry['id'] == $field['value'] ? 1 : 0;
                 }
             } else {
                 if (isset($field['values_def']['method'])) {
                     foreach ($field['values_def']['method_input'] as $_argument => $_argument_value) {
                         if (preg_match('/^##/', $_argument_value)) {
                             $_argument_value_name = trim($_argument_value, '#');
                             $_argument_value = $values[$_argument_value_name];
                         }
                         if (preg_match('/^\\$this->/', $_argument_value)) {
                             $_argument_value_name = ltrim($_argument_value, '$this->');
                             $_argument_value = $this->{$_argument_value_name};
                         }
                         $method_input[$_argument] = $_argument_value;
                     }
                     $field['valueset'] = execMethod($field['values_def']['method'], $method_input);
                 }
             }
             if (isset($values['id']) && $values['id'] && isset($field['role']) && $field['role'] == 'parent') {
                 // can not select it self as parent.
                 $exclude = array($values['id']);
                 $children = $this->bo->get_children2($values['id'], 0, true);
                 foreach ($children as $child) {
                     $exclude[] = $child['id'];
                 }
                 $k = count($field['valueset']);
                 for ($i = 0; $i < $k; $i++) {
                     if (in_array($field['valueset'][$i]['id'], $exclude)) {
                         unset($field['valueset'][$i]);
                     }
                 }
             }
         }
     }
     $msgbox_data = $this->bocommon->msgbox_data($receipt);
     $data = array('msgbox_data' => $GLOBALS['phpgw']->common->msgbox($msgbox_data), 'form_action' => $GLOBALS['phpgw']->link('/index.php', $link_data), 'done_action' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uigeneric.index', 'type' => $this->type, 'type_id' => $this->type_id)), 'lang_descr' => lang('Descr'), 'lang_save' => lang('save'), 'lang_cancel' => lang('cancel'), 'lang_apply' => lang('apply'), 'value_id' => isset($values['id']) ? $values['id'] : '', 'value_descr' => $values['descr'], 'attributes_group' => $attributes, 'lookup_functions' => isset($values['lookup_functions']) ? $values['lookup_functions'] : '', 'textareacols' => isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] : 60, 'textarearows' => isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] : 10, 'tabs' => phpgwapi_yui::tabview_generate($tabs, 'general'), 'id_name' => $this->location_info['id']['name'], 'id_type' => $this->location_info['id']['type'], 'fields' => $this->location_info['fields']);
     $appname = $this->location_info['name'];
     $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw']->translation->translate($this->location_info['acl_app'], array(), false, $this->location_info['acl_app']) . "::{$appname}::{$function_msg}";
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('edit' => $data));
 }
Beispiel #13
0
$forward = phpgw::get_var('phpgw_forward', 'int');
if ($forward) {
    $extra_vars['phpgw_forward'] = $forward;
    foreach ($_GET as $name => $value) {
        if (preg_match('/phpgw_/', $name)) {
            $extra_vars[$name] = phpgw::clean_value($value);
        }
    }
}
$redirect = phpgw::get_var('redirect_menuaction', 'string');
if ($redirect) {
    $matches = array();
    $extra_vars['menuaction'] = $redirect;
    foreach ($_GET as $name => $value) {
        if (preg_match('/^redirect_([\\w\\_\\-]+)/', $name, $matches) && $matches[1] != 'menuaction') {
            $extra_vars[$matches[1]] = phpgw::clean_value($value);
        }
    }
}
if (!isset($extra_vars['menuaction'])) {
    $extra_vars['menuaction'] = 'bookingfrontend.uisearch.index';
}
if (!$external_logout) {
    $GLOBALS['phpgw']->redirect_link('/bookingfrontend/', $extra_vars);
} else {
    $result_redirect = '';
    if (substr($external_logout, -1) == '=') {
        $result_redirect = $GLOBALS['phpgw']->link('/bookingfrontend/', $extra_vars, true);
    }
    $external_logout_url = "{$external_logout}{$bookingfrontend_host}{$result_redirect}";
    Header("Location: {$external_logout_url}");
/**
 * Cherry pick selected values into a new array
 * 
 * @param array $array    input array
 * @param array $keys     array of keys to pick
 *
 * @return array containg values from $array for the keys in $keys.
 */
function extract_values($array, $keys, $options = array())
{
    static $default_options = array('prefix' => '', 'suffix' => '', 'preserve_prefix' => false, 'preserve_suffix' => false);
    $options = array_merge($default_options, $options);
    $result = array();
    $isIndexed = array_values($keys) === $keys;
    if ($isIndexed) {
        foreach ($keys as $write_key) {
            $array_key = $options['prefix'] . $write_key . $options['suffix'];
            if (isset($array[$array_key])) {
                $result[($options['preserve_prefix'] ? $options['prefix'] : '') . $write_key . ($options['preserve_suffix'] ? $options['suffix'] : '')] = phpgw::clean_value($array[$array_key]);
            }
        }
    } else {
        foreach ($keys as $write_key => $type) {
            switch ($type) {
                case 'string':
                default:
                    $_type = 'string';
                    break;
                case 'bool':
                case 'boolean':
                    $_type = 'bool';
                    break;
                case 'int':
                case 'integer':
                case 'number':
                    $_type = 'int';
                    break;
                case 'float':
                case 'double':
                    $_type = 'float';
                    break;
                    /* Specific string types */
                /* Specific string types */
                case 'color':
                    $_type = 'color';
                    break;
                case 'email':
                    $_type = 'email';
                    break;
                case 'filename':
                    $_type = 'filename';
                    break;
                case 'ip':
                    $_type = 'ip';
                    break;
                case 'location':
                    $_type = 'location';
                    break;
                case 'url':
                    $_type = 'url';
                    break;
                    /* only use this if you really know what you are doing */
                /* only use this if you really know what you are doing */
                case 'raw':
                    $_type = 'raw';
                    break;
                case 'html':
                    $_type = 'html';
                    break;
            }
            $array_key = $options['prefix'] . $write_key . $options['suffix'];
            if (isset($array[$array_key])) {
                $result[($options['preserve_prefix'] ? $options['prefix'] : '') . $write_key . ($options['preserve_suffix'] ? $options['suffix'] : '')] = phpgw::clean_value($array[$array_key], $_type);
            }
        }
    }
    return $result;
}