コード例 #1
0
 public function __construct()
 {
     phpgwapi_cache::session_set('frontend', 'tab', $GLOBALS['phpgw']->locations->get_id('frontend', '.drawings'));
     parent::__construct();
     $this->location_code = $this->header_state['selected_location'];
     //			$this->location_code = '1102-01';
 }
コード例 #2
0
 public function __construct()
 {
     parent::__construct();
     $read = $GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_READ, 'controller');
     //1
     $add = $GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_ADD, 'controller');
     //2
     $edit = $GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_EDIT, 'controller');
     //4
     $delete = $GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_DELETE, 'controller');
     //8
     $manage = $GLOBALS['phpgw']->acl->check('.control', 16, 'controller');
     //16
     $this->so = CreateObject('controller.socheck_list');
     $this->so_control = CreateObject('controller.socontrol');
     $this->so_control_group = CreateObject('controller.socontrol_group');
     $this->so_control_group_list = CreateObject('controller.socontrol_group_list');
     $this->so_control_item = CreateObject('controller.socontrol_item');
     $this->so_check_list = CreateObject('controller.socheck_list');
     $this->so_check_item = CreateObject('controller.socheck_item');
     $this->location_finder = new location_finder();
     self::set_active_menu('controller::location_check_list');
     if (phpgw::get_var('noframework', 'bool')) {
         $GLOBALS['phpgw_info']['flags']['noframework'] = true;
         phpgwapi_cache::session_set('controller', 'noframework', true);
     } else {
         if (phpgwapi_cache::session_get('controller', 'noframework')) {
             $GLOBALS['phpgw_info']['flags']['noframework'] = true;
         }
     }
 }
コード例 #3
0
 function __construct()
 {
     parent::__construct();
     $this->so = CreateObject('controller.socase');
     $this->so_control = CreateObject('controller.socontrol');
     $this->so_control_item = CreateObject('controller.socontrol_item');
     $this->so_check_item = CreateObject('controller.socheck_item');
     $this->so_procedure = CreateObject('controller.soprocedure');
     $this->so_control_group_list = CreateObject('controller.socontrol_group_list');
     $this->so_control_group = CreateObject('controller.socontrol_group');
     $this->so_control_item_list = CreateObject('controller.socontrol_item_list');
     $this->so_check_list = CreateObject('controller.socheck_list');
     $this->location_finder = new location_finder();
     $this->read = $GLOBALS['phpgw']->acl->check('.checklist', PHPGW_ACL_READ, 'controller');
     //1
     $this->add = $GLOBALS['phpgw']->acl->check('.checklist', PHPGW_ACL_ADD, 'controller');
     //2
     $this->edit = $GLOBALS['phpgw']->acl->check('.checklist', PHPGW_ACL_EDIT, 'controller');
     //4
     $this->delete = $GLOBALS['phpgw']->acl->check('.checklist', PHPGW_ACL_DELETE, 'controller');
     //8
     if (phpgw::get_var('noframework', 'bool')) {
         $GLOBALS['phpgw_info']['flags']['noframework'] = true;
         phpgwapi_cache::session_set('controller', 'noframework', true);
     } else {
         if (phpgwapi_cache::session_get('controller', 'noframework')) {
             $GLOBALS['phpgw_info']['flags']['noframework'] = true;
         }
     }
 }
コード例 #4
0
 public function __construct()
 {
     $extra_tabs = array();
     $extra_tabs[0] = array('label' => lang('messages'), 'link' => $GLOBALS['phpgw']->link('/', array('menuaction' => "frontend.uimessages.index", 'noframework' => $noframework)));
     phpgwapi_cache::session_set('frontend', 'extra_tabs', $extra_tabs);
     phpgwapi_cache::session_set('frontend', 'tab', 0);
     parent::__construct();
 }
コード例 #5
0
 /**
  * View a list of all resultunits
  */
 public function index()
 {
     $search_for = phpgw::get_var('search_for');
     if ($search_for) {
         phpgwapi_cache::session_set('rental', 'resultunit_query', $search_for);
     }
     $this->render('resultunit_list.php');
 }
コード例 #6
0
 public function __construct()
 {
     $this->contract_state_identifier = "contract_state";
     $this->contracts_per_location_identifier = "contracts_per_location";
     //	$this->form_url = "index.php?menuaction=frontend.uicontract_internal.index";
     $this->form_url = $GLOBALS['phpgw']->link('/', array('menuaction' => 'frontend.uicontract_internal.index'));
     phpgwapi_cache::session_set('frontend', 'tab', $GLOBALS['phpgw']->locations->get_id('frontend', '.rental.contract'));
     parent::__construct();
 }
コード例 #7
0
 public function __construct()
 {
     $GLOBALS['phpgw']->translation->add_app('property');
     $this->location_id = phpgw::get_var('location_id', 'int', 'REQUEST', 0);
     $location_info = $GLOBALS['phpgw']->locations->get_name($this->location_id);
     $this->acl_location = $location_info['location'];
     $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
     $this->acl =& $GLOBALS['phpgw']->acl;
     $this->acl_read = $this->acl->check($this->acl_location, PHPGW_ACL_READ, 'frontend');
     phpgwapi_cache::session_set('frontend', 'tab', $this->location_id);
     parent::__construct();
     $this->location_code = $this->header_state['selected_location'];
     /*
     			$this->bo->location_code = $this->location_code;
     			
     			$_org_units = array();
     			if(is_array($this->header_state['org_unit']))
     			{
     				foreach ($this->header_state['org_unit'] as $org_unit)
     				{
     					$_org_unit_id = (int)$org_unit['ORG_UNIT_ID'];
     					$_subs = execMethod('property.sogeneric.read_tree',array('node_id' => $_org_unit_id, 'type' => 'org_unit'));
     					$_org_units[$_org_unit_id] = true;
     					foreach($_subs as $entry)
     					{
     						$_org_units[$entry['id']] = true;
     						if(isset($entry['children']) && $entry['children'])
     						{
     							$this->_get_children($entry['children'], $_org_units);			
     						}
     					}
     				}
     			}
     			$org_units = array_keys($_org_units);
     			$this->bo->org_units = $org_units;
     */
 }
コード例 #8
0
 public function get_local_menu_ajax()
 {
     $node = phpgw::get_var('node');
     $selection = explode('|', $node);
     $app = $selection[0];
     if (!isset($GLOBALS['phpgw_info']['user']['apps'][$app])) {
         return array();
     }
     $menu = array();
     $_section = 'navigation';
     if ($app == 'admin') {
         if (!isset($selection[1])) {
             $navbar = $this->get('navbar');
             $navigation = $this->get('admin');
             foreach ($GLOBALS['phpgw_info']['user']['apps'] as $_app => $app_info) {
                 if (!in_array($_app, array('logout', 'about', 'preferences')) && isset($navbar[$_app])) {
                     if (isset($navigation[$_app])) {
                         $menu[] = array('key' => $_app, 'is_leaf' => count($navigation[$_app]) > 1 ? false : true, 'text' => $GLOBALS['phpgw']->translation->translate($_app, array(), true), 'url' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uiconfig.index', 'appname' => $_app)));
                     }
                 }
             }
             return $menu;
         } else {
             $_section = 'admin';
             $app = $selection[1];
             array_shift($selection);
         }
     }
     if (!($menu_gross = phpgwapi_cache::session_get('phpgwapi', "menu_{$app}"))) {
         $menu_gross = execMethod("{$app}.menu.get_menu");
         phpgwapi_cache::session_set('phpgwapi', "menu_{$app}", $menu_gross);
     }
     $menu_gross = $menu_gross[$_section];
     $count_selection = count($selection);
     if ($count_selection > 1) {
         for ($i = 1; $i < count($selection); $i++) {
             if (isset($menu_gross[$selection[$i]])) {
                 $menu_gross = $menu_gross[$selection[$i]];
             } else {
                 if (isset($menu_gross['children'][$selection[$i]])) {
                     $menu_gross = $menu_gross['children'][$selection[$i]];
                 } else {
                     $menu_gross = array();
                 }
             }
         }
         $children = isset($menu_gross['children']) ? $menu_gross['children'] : array();
     } else {
         $children = $menu_gross;
     }
     $i = 0;
     foreach ($children as $key => $vals) {
         $vals['url'] = str_replace('&amp;', '&', $vals['url']);
         $menu[$i] = $vals;
         $menu[$i]['key'] = $key;
         $menu[$i]['is_leaf'] = true;
         if (isset($menu[$i]['children'])) {
             $menu[$i]['is_leaf'] = false;
             unset($menu[$i]['children']);
         }
         $i++;
     }
     return $menu;
 }
コード例 #9
0
ファイル: navbar.inc.php プロジェクト: HaakonME/porticoestate
function parse_navbar($force = False)
{
    $navbar = array();
    $navbar = execMethod('phpgwapi.menu.get', 'navbar');
    $user = $GLOBALS['phpgw']->accounts->get($GLOBALS['phpgw_info']['user']['id']);
    $var = array('print_url' => strpos($_SERVER['REQUEST_URI'], '?') ? "{$_SERVER['REQUEST_URI']}&phpgw_return_as=noframes" : "{$_SERVER['REQUEST_URI']}?phpgw_return_as=noframes", 'print_text' => lang('print'), 'home_url' => $GLOBALS['phpgw']->link('/home.php'), 'home_text' => lang('home'), 'home_icon' => 'icon icon-home', 'about_url' => $GLOBALS['phpgw']->link('/about.php', array('app' => $GLOBALS['phpgw_info']['flags']['currentapp'])), 'about_text' => lang('about'), 'logout_url' => $GLOBALS['phpgw']->link('/logout.php'), 'logout_text' => lang('logout'), 'user_fullname' => $user->__toString());
    if ($GLOBALS['phpgw']->acl->check('run', PHPGW_ACL_READ, 'preferences')) {
        $var['preferences_url'] = $GLOBALS['phpgw']->link('/preferences/index.php');
        $var['preferences_text'] = lang('preferences');
    }
    if (isset($GLOBALS['phpgw_info']['user']['apps']['manual'])) {
        $var['help_url'] = "javascript:openwindow('" . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'manual.uimanual.help', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'], 'section' => isset($GLOBALS['phpgw_info']['apps']['manual']['section']) ? $GLOBALS['phpgw_info']['apps']['manual']['section'] : '', 'referer' => phpgw::get_var('menuaction'))) . "','700','600')";
        $var['help_text'] = lang('help');
        $var['help_icon'] = 'icon icon-help';
    }
    if (isset($GLOBALS['phpgw_info']['server']['support_address']) && $GLOBALS['phpgw_info']['server']['support_address']) {
        $var['support_url'] = "javascript:openwindow('" . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'manual.uisupport.send', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'])) . "','700','600')";
        $var['support_text'] = lang('support');
        $var['support_icon'] = 'icon icon-help';
    }
    if (isset($GLOBALS['phpgw_info']['user']['apps']['admin'])) {
        $var['debug_url'] = "javascript:openwindow('" . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uidebug_json.index', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'])) . "','','')";
        $var['debug_text'] = lang('debug');
        $var['debug_icon'] = 'icon icon-debug';
    }
    $GLOBALS['phpgw']->template->set_root(PHPGW_TEMPLATE_DIR);
    $GLOBALS['phpgw']->template->set_file('navbar', 'navbar.tpl');
    $flags =& $GLOBALS['phpgw_info']['flags'];
    $var['current_app_title'] = isset($flags['app_header']) ? $flags['app_header'] : lang($GLOBALS['phpgw_info']['flags']['currentapp']);
    $flags['menu_selection'] = isset($flags['menu_selection']) ? $flags['menu_selection'] : '';
    // breadcrumbs
    $current_url = array('id' => $flags['menu_selection'], 'url' => phpgw::get_var('REQUEST_URI', 'string', 'SERVER'), 'name' => $var['current_app_title']);
    $breadcrumbs = phpgwapi_cache::session_get('phpgwapi', 'breadcrumbs');
    $breadcrumbs = $breadcrumbs ? $breadcrumbs : array();
    // first one
    if ($breadcrumbs[0]['id'] != $flags['menu_selection']) {
        array_unshift($breadcrumbs, $current_url);
    }
    if (count($breadcrumbs) >= 5) {
        array_pop($breadcrumbs);
    }
    phpgwapi_cache::session_set('phpgwapi', 'breadcrumbs', $breadcrumbs);
    $breadcrumbs = array_reverse($breadcrumbs);
    $navigation = array();
    if (!isset($GLOBALS['phpgw_info']['user']['preferences']['property']['nonavbar']) || $GLOBALS['phpgw_info']['user']['preferences']['property']['nonavbar'] != 'yes') {
        prepare_navbar($navbar);
    } else {
        foreach ($navbar as &$app_tmp) {
            $app_tmp['text'] = ' ...';
        }
    }
    if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent'] == 'ajax_menu') {
        $exclude = array('logout', 'about', 'preferences');
        $i = 1;
        foreach ($navbar as $app => $app_data) {
            if (in_array($app, $exclude)) {
                continue;
            }
            $applications[] = array('value' => array('id' => $i, 'app' => $app, 'label' => $app_data['text'], 'href' => str_replace('&amp;', '&', $app_data['url'])), 'children' => array());
            $mapping[$i] = array('id' => $i, 'name' => $app, 'expanded' => false, 'highlight' => $app == $currentapp ? true : false, 'is_leaf' => false);
            $i++;
        }
        $applications = json_encode($applications);
        $mapping = json_encode($mapping);
        $_menu_selection = str_replace('::', '|', $GLOBALS['phpgw_info']['flags']['menu_selection']);
        $var['treemenu'] = <<<HTML
\t\t\t\t<div id="MenutreeDiv1"></div>
\t\t\t\t<script type="text/javascript">
\t\t \t\t\tvar apps = {$applications};
\t\t\t\t\tvar mapping = {$mapping};
\t\t\t\t\tvar proxy_data = ['first_element_is_dummy'];
\t\t\t\t\tvar menu_selection = '{$_menu_selection}';
\t\t\t\t</script>
HTML;
    } else {
        //			prepare_navbar($navbar);
        $navigation = execMethod('phpgwapi.menu.get', 'navigation');
        $treemenu = '';
        foreach ($navbar as $app => $app_data) {
            if (!in_array($app, array('logout', 'about', 'preferences'))) {
                $submenu = isset($navigation[$app]) ? render_submenu($app, $navigation[$app]) : '';
                $treemenu .= render_item($app_data, "navbar::{$app}", $submenu);
            }
        }
        $var['treemenu'] = <<<HTML
\t\t\t<ul id="navbar">
{$treemenu}
\t\t\t</ul>

HTML;
    }
    if (isset($GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['sidecontent'] == 'jsmenu') {
        $var['treemenu'] .= <<<JS
\t\t\t\t<script type="text/javascript">
\t\t\t\t\$(function() {
\t\t\t\t\$("#navbar").menu();
\t\t\t});
\t\t\t</script>
JS;
    }
    $GLOBALS['phpgw']->template->set_var($var);
    $GLOBALS['phpgw']->template->pfp('out', 'navbar');
    if (phpgw::get_var('phpgw_return_as') != 'json' && ($global_message = phpgwapi_cache::system_get('phpgwapi', 'phpgw_global_message'))) {
        echo "<div class='msg_good'>";
        echo nl2br($global_message);
        echo '</div>';
    }
    if (phpgw::get_var('phpgw_return_as') != 'json' && $breadcrumbs && isset($GLOBALS['phpgw_info']['user']['preferences']['common']['show_breadcrumbs']) && $GLOBALS['phpgw_info']['user']['preferences']['common']['show_breadcrumbs']) {
        $history_url = array();
        foreach ($breadcrumbs as $breadcrumb) {
            $history_url[] = "<a href='{$breadcrumb['url']}'>{$breadcrumb['name']}</a>";
        }
        $breadcrumbs = '<div class="breadcrumbs"><h4>' . implode(' >> ', $history_url) . '</h4></div>';
        echo $breadcrumbs;
    }
    if (phpgw::get_var('phpgw_return_as') != 'json' && ($receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))) {
        phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
        $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($receipt);
        $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
        foreach ($msgbox_data as &$message) {
            echo "<div class='{$message['msgbox_class']}'>";
            echo $message['msgbox_text'];
            echo '</div>';
        }
    }
    $GLOBALS['phpgw']->hooks->process('after_navbar');
    register_shutdown_function('parse_footer_end');
}
コード例 #10
0
 public function query()
 {
     $params = array('start' => phpgw::get_var('startIndex', 'int', 'REQUEST', 0), 'results' => phpgw::get_var('results', 'int', 'REQUEST', null), 'query' => phpgw::get_var('query'), 'sort' => phpgw::get_var('sort'), 'dir' => phpgw::get_var('dir'), 'filters' => $filters);
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort');
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     // Form variables
     $search_for = phpgw::get_var('query');
     $search_type = phpgw::get_var('search_option');
     // Create an empty result set
     $result_objects = array();
     $result_count = 0;
     //Retrieve a project identifier and load corresponding project
     $project_id = phpgw::get_var('project_id');
     $exp_param = phpgw::get_var('export');
     $export = false;
     if (isset($exp_param)) {
         $export = true;
         $num_of_objects = null;
     }
     //Retrieve the type of query and perform type specific logic
     $query_type = phpgw::get_var('type');
     //var_dump($query_type);
     switch ($query_type) {
         case 'project_type':
             phpgwapi_cache::session_set('logistic', 'project_type_query', $search_for);
             $search_type = 'project_type';
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->get_count($search_for, $search_type, $filters);
             break;
         default:
             // ... all composites, filters (active and vacant)
             phpgwapi_cache::session_set('logistic', 'project_query', $search_for);
             $filters = array('project_type' => phpgw::get_var('project_type'));
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->get_count($search_for, $search_type, $filters);
             break;
     }
     //var_dump($result_objects);
     //Create an empty row set
     $rows = array();
     foreach ($result_objects as $result) {
         if (isset($result)) {
             $project = $result->serialize();
             $href = self::link(array('menuaction' => 'logistic.uiactivity.edit', 'project_id' => $project['id']));
             $project['add_activity_link'] = "<a class=\"btn-sm delete\" href=\"{$href}\">Legg til aktivitet</a>";
             $rows[] = $project;
         }
     }
     // ... add result data
     $result_data = array('results' => $rows);
     $result_data['total_records'] = $object_count;
     $result_data['start'] = $params['start'];
     $result_data['sort'] = $params['sort'];
     $result_data['dir'] = $params['dir'];
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     if (!$export) {
         //Add action column to each row in result table
         if ($search_type && $search_type == 'project_type') {
             array_walk($result_data['results'], array($this, '_add_links'), "logistic.uiproject.view_project_type");
         } else {
             array_walk($result_data['results'], array($this, '_add_links'), "logistic.uiproject.view");
         }
     }
     return $this->yui_results($result_data);
 }
コード例 #11
0
 public function query()
 {
     $params = array('start' => phpgw::get_var('startIndex', 'int', 'REQUEST', 0), 'results' => phpgw::get_var('results', 'int', 'REQUEST', null), 'query' => phpgw::get_var('query'), 'sort' => phpgw::get_var('sort'), 'dir' => phpgw::get_var('dir'), 'filters' => $filters);
     $activity_id = phpgw::get_var('activity_id');
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort');
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     // Form variables
     $search_for = phpgw::get_var('query');
     $search_type = phpgw::get_var('search_option');
     // Create an empty result set
     $result_objects = array();
     $result_count = 0;
     //Retrieve a contract identifier and load corresponding contract
     $project_id = phpgw::get_var('project_id');
     $exp_param = phpgw::get_var('export');
     $export = false;
     if (isset($exp_param)) {
         $export = true;
         $num_of_objects = null;
     }
     //Retrieve the type of query and perform type specific logic
     $query_type = phpgw::get_var('type');
     switch ($query_type) {
         default:
             // ... all composites, filters (active and vacant)
             phpgwapi_cache::session_set('logistic', 'requirement_query', $search_for);
             $filters = array('activity' => $activity_id);
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->get_count($search_for, $search_type, $filters);
             break;
     }
     //Create an empty row set
     $rows = array();
     foreach ($result_objects as $result) {
         if (isset($result)) {
             $rows[] = $result->serialize();
         }
     }
     //Sigurd
     $custom = createObject('phpgwapi.custom_fields');
     //_debug_array($rows);
     $line_id = 0;
     // optional preselect
     foreach ($rows as &$entry) {
         //-----------Sigurd
         $_filters = array('requirement_id' => $entry['id']);
         $requirement_values_array = $this->so_requirement_value->get(0, false, $sort_field, $sort_ascending, $search_for, $search_type, $_filters);
         $location_id = $entry['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();
             }
         }
         $entry['criterias'] = implode(',', $criterias);
         //-------------
         $_checked = '';
         if ($entry['id'] == $line_id) {
             $_checked = 'checked="checked"';
         }
         $num_required = $entry['no_of_items'];
         $num_allocated = $this->so_resource_allocation->count_allocated($entry['id']);
         $entry['allocated'] = $num_allocated;
         $entry['select'] = "<input class=\"select_line\" type =\"radio\" {$_checked} name=\"values[select_line]\" value=\"{$entry['id']}\">";
         if ($num_allocated == $num_required) {
             $entry['status'] = "OK";
             $entry['alloc_link'] = "<span class='btn-sm cancel'>Tildel ressurser</span>";
         } else {
             $num_remaining = $num_required - $num_allocated;
             $entry['status'] = "MANGLER (" . $num_remaining . ")";
             $href = self::link(array('menuaction' => 'logistic.uirequirement_resource_allocation.edit', 'requirement_id' => $entry['id']));
             $entry['alloc_link'] = "<a class=\"btn-sm alloc\" href=\"{$href}\">Tildel ressurser</a>";
         }
         //$href = self::link(array('menuaction' => 'logistic.uirequirement.edit', 'id' => $entry['id']));
         $href = "javascript:load_requirement_edit_id({$entry['id']});";
         $entry['edit_requirement_link'] = "<a class=\"btn-sm alloc\" href=\"{$href}\">Endre behov</a>";
         $href = "javascript:load_requirement_delete_id({$entry['id']});";
         $entry['delete_requirement_link'] = "<a class=\"btn-sm alloc\" href=\"{$href}\">Slett behov</a>";
     }
     // ... add result data
     $result_data = array('results' => $rows);
     $result_data['total_records'] = $object_count;
     $result_data['start'] = $params['start'];
     $result_data['sort'] = $params['sort'];
     $result_data['dir'] = $params['dir'];
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     if (!$export) {
         //Add action column to each row in result table
         array_walk($result_data['results'], array($this, '_add_links'), "logistic.uirequirement.view");
     }
     return $this->yui_results($result_data);
 }
コード例 #12
0
 function read($data)
 {
     $start = isset($data['start']) && $data['start'] ? $data['start'] : 0;
     $filter = isset($data['filter']) && $data['filter'] ? $data['filter'] : 0;
     $query = isset($data['query']) ? $data['query'] : '';
     $sort = isset($data['sort']) && $data['sort'] ? $data['sort'] : 'ASC';
     $order = isset($data['order']) ? $data['order'] : '';
     $cat_id = isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id'] : '';
     $type_id = isset($data['type_id']) ? $data['type_id'] : '';
     $lookup_tenant = isset($data['lookup_tenant']) ? $data['lookup_tenant'] : '';
     $district_id = isset($data['district_id']) ? $data['district_id'] : '';
     $allrows = isset($data['allrows']) ? $data['allrows'] : '';
     $lookup = isset($data['lookup']) ? $data['lookup'] : '';
     $status = isset($data['status']) ? $data['status'] : '';
     $part_of_town_id = isset($data['part_of_town_id']) ? $data['part_of_town_id'] : '';
     $dry_run = isset($data['dry_run']) ? $data['dry_run'] : '';
     $location_code = isset($data['location_code']) ? $data['location_code'] : '';
     $filter_role_on_contact = $data['filter_role_on_contact'] ? (int) $data['filter_role_on_contact'] : 0;
     $role_id = $data['role_id'] ? (int) $data['role_id'] : 0;
     $results = $data['results'] ? (int) $data['results'] : 0;
     $control_registered = isset($data['control_registered']) ? $data['control_registered'] : '';
     $control_id = isset($data['control_id']) && $data['control_id'] ? $data['control_id'] : 0;
     if (!$type_id) {
         return;
     }
     if ($order == 'undefined') {
         $order = '';
     }
     switch ($order) {
         case 'undefined':
             $order = '';
             break;
         case 'loc1':
             $order = 'fm_location1.loc1';
             break;
         default:
     }
     $sql = $this->socommon->fm_cache('sql_' . $type_id . '_lt' . $lookup_tenant . '_l' . $lookup . '_f' . !!$filter_role_on_contact);
     $location_id = $GLOBALS['phpgw']->locations->get_id('property', ".location.{$type_id}");
     //			$choice_table = 'phpgw_cust_choice';
     $attribute_table = 'phpgw_cust_attribute';
     //			$attribute_filter = " custom = 1 AND location_id = {$location_id}";
     $attribute_filter = " location_id = {$location_id}";
     //			$attribute_choice_filter = " location_id = {$location_id}";
     if (!$sql) {
         $location_types = $this->soadmin_location->select_location_type();
         $cols = "fm_location{$type_id}.*";
         $cols_return[] = 'location_code';
         $uicols['input_type'][] = 'hidden';
         $uicols['name'][] = 'location_code';
         $uicols['descr'][] = 'dummy';
         $uicols['statustext'][] = 'dummy';
         $uicols['exchange'][] = false;
         $uicols['align'][] = '';
         $uicols['datatype'][] = '';
         $uicols['formatter'][] = '';
         for ($i = 0; $i < $type_id; $i++) {
             $uicols['input_type'][] = 'text';
             $uicols['name'][] = "loc{$location_types[$i]['id']}";
             $uicols['descr'][] = $location_types[$i]['name'];
             $uicols['statustext'][] = $location_types[$i]['descr'];
             $uicols['exchange'][] = true;
             $uicols['align'][] = 'center';
             $uicols['datatype'][] = 'link';
             $uicols['formatter'][] = '';
             $cols .= ",fm_location{$type_id}.loc{$location_types[$i]['id']}";
             $cols_return[] = "loc{$location_types[$i]['id']}";
         }
         $uicols['datatype'][$type_id] = 'I';
         // correct the last one
         $list_info = $location_types[$type_id - 1]['list_info'];
         for ($i = 1; $i < $type_id + 1; $i++) {
             if (isset($list_info[$i]) && $list_info[$i]) {
                 $cols .= ",fm_location{$i}.loc{$i}_name";
                 $cols_return[] = "loc{$i}_name";
                 $uicols['input_type'][] = 'text';
                 $uicols['name'][] = "loc{$i}_name";
                 $uicols['descr'][] = $location_types[$i - 1]['name'] . ' ' . lang('name');
                 $uicols['statustext'][] = $location_types[$i - 1]['name'] . ' ' . lang('name');
                 $uicols['exchange'][] = true;
                 $uicols['align'][] = 'left';
                 $uicols['datatype'][] = 'V';
                 $uicols['formatter'][] = '';
             }
         }
         $joinmethod = '';
         $paranthesis = '';
         for ($j = $type_id - 1; $j > 0; $j--) {
             $joinmethod .= " {$this->join} fm_location{$j}";
             $paranthesis .= '(';
             $on = 'ON';
             for ($i = $j; $i > 0; $i--) {
                 $joinmethod .= " {$on} (fm_location" . ($j + 1) . ".loc{$i} = fm_location{$j}.loc{$i})";
                 $on = 'AND';
                 if ($i == 1) {
                     $joinmethod .= ")";
                 }
             }
         }
         //			$paranthesis .='(';
         //			$joinmethod .= " {$this->join} fm_part_of_town ON (fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id))";
         $config = $this->soadmin_location->read_config('');
         //_debug_array($config);
         if ($lookup_tenant) {
             $cols .= ',fm_tenant.id as tenant_id';
             $cols_return[] = 'tenant_id';
             $uicols['input_type'][] = 'hidden';
             $uicols['name'][] = 'tenant_id';
             $uicols['descr'][] = 'dummy';
             $uicols['statustext'][] = 'dummy';
             $uicols['exchange'][] = true;
             $uicols['align'][] = '';
             $uicols['datatype'][] = '';
             $uicols['formatter'][] = '';
             $cols .= ',fm_tenant.last_name';
             $cols_return[] = 'last_name';
             $uicols['input_type'][] = 'text';
             $uicols['name'][] = 'last_name';
             $uicols['datatype'][] = 'V';
             $uicols['descr'][] = lang('last name');
             $uicols['statustext'][] = lang('last name');
             $uicols['exchange'][] = true;
             $uicols['align'][] = 'left';
             $uicols['datatype'][] = 'V';
             $uicols['formatter'][] = '';
             $cols .= ',fm_tenant.first_name';
             $cols_return[] = 'first_name';
             $uicols['input_type'][] = 'text';
             $uicols['name'][] = 'first_name';
             $uicols['datatype'][] = 'V';
             $uicols['descr'][] = lang('first name');
             $uicols['statustext'][] = lang('first name');
             $uicols['exchange'][] = true;
             $uicols['align'][] = 'left';
             $uicols['datatype'][] = 'V';
             $uicols['formatter'][] = '';
             $cols .= ',fm_tenant.contact_phone';
             $cols_return[] = 'contact_phone';
             $uicols['input_type'][] = 'text';
             $uicols['name'][] = 'contact_phone';
             $uicols['datatype'][] = 'V';
             $uicols['descr'][] = lang('contact phone');
             $uicols['statustext'][] = lang('contact phone');
             $uicols['exchange'][] = true;
             $uicols['align'][] = 'left';
             $uicols['datatype'][] = 'V';
             $uicols['formatter'][] = '';
             $sub_query_tenant = 1;
             $this->socommon->fm_cache('sub_query_tenant_' . $type_id . '_' . $lookup_tenant . '_' . $lookup, $sub_query_tenant);
         }
         $config_count = count($config);
         for ($i = 0; $i < $config_count; $i++) {
             if ($config[$i]['location_type'] <= $type_id && $config[$i]['f_key'] == 1) {
                 if (!$lookup_tenant && $config[$i]['column_name'] == 'tenant_id') {
                 } else {
                     $joinmethod .= " {$this->left_join} {$config[$i]['reference_table']} ON ( fm_location{$config[$i]['location_type']}.{$config[$i]['column_name']} = {$config[$i]['reference_table']}.{$config[$i]['reference_id']}))";
                     $paranthesis .= '(';
                 }
             }
             if ($config[$i]['location_type'] <= $type_id && $config[$i]['query_value'] == 1) {
                 if ($config[$i]['column_name'] == 'street_id') {
                     $sub_query_street = 1;
                     $this->socommon->fm_cache('sub_query_street_' . $type_id . '_' . $lookup_tenant . '_' . $lookup, $sub_query_street);
                     //list address at sublevels beneath address-level
                     if ($location_types[$type_id - 1]['list_address']) {
                         $cols .= ',fm_streetaddress.descr as street_name';
                         $cols_return[] = 'street_name';
                         $uicols['input_type'][] = 'text';
                         $uicols['name'][] = 'street_name';
                         $uicols['descr'][] = lang('street name');
                         $uicols['statustext'][] = lang('street name');
                         $uicols['exchange'][] = true;
                         $uicols['align'][] = 'left';
                         $uicols['datatype'][] = 'V';
                         $uicols['formatter'][] = '';
                         $cols .= ',street_number';
                         $cols_return[] = 'street_number';
                         $uicols['input_type'][] = 'text';
                         $uicols['name'][] = 'street_number';
                         $uicols['descr'][] = lang('street number');
                         $uicols['statustext'][] = lang('street number');
                         $uicols['exchange'][] = true;
                         $uicols['align'][] = 'left';
                         $uicols['datatype'][] = 'V';
                         $uicols['formatter'][] = '';
                         $cols .= ',fm_location' . $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
                         $cols_return[] = $config[$i]['column_name'];
                         $uicols['input_type'][] = 'hidden';
                         $uicols['name'][] = $config[$i]['column_name'];
                         $uicols['descr'][] = lang($config[$i]['input_text']);
                         $uicols['statustext'][] = lang($config[$i]['input_text']);
                         $uicols['exchange'][] = true;
                         $uicols['align'][] = '';
                         $uicols['datatype'][] = '';
                         $uicols['formatter'][] = '';
                     }
                 } else {
                     $cols .= ',fm_location' . $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
                     $cols_return[] = $config[$i]['column_name'];
                     $uicols['input_type'][] = 'hidden';
                     $uicols['name'][] = $config[$i]['column_name'];
                     $uicols['descr'][] = $config[$i]['input_text'];
                     $uicols['statustext'][] = $config[$i]['input_text'];
                     $uicols['exchange'][] = true;
                     $uicols['align'][] = '';
                     $uicols['datatype'][] = '';
                     $uicols['formatter'][] = '';
                 }
             }
         }
         $this->db->query("SELECT * FROM {$attribute_table} WHERE (list=1 OR lookup_form=1) AND {$attribute_filter}");
         while ($this->db->next_record()) {
             $cols .= ",fm_location{$type_id}." . $this->db->f('column_name');
         }
         $cols .= ",fm_location{$type_id}_category.descr as category_text";
         $joinmethod .= " {$this->left_join} fm_location{$type_id}_category ON ( fm_location{$type_id}.category = fm_location{$type_id}_category.id))";
         $paranthesis .= '(';
         if ($filter_role_on_contact) {
             $joinmethod .= " {$this->join} fm_responsibility_contact ON ( fm_location{$type_id}.location_code = fm_responsibility_contact.location_code))";
             $paranthesis .= '(';
             $joinmethod .= " {$this->join} fm_responsibility_role ON ( fm_responsibility_contact.responsibility_role_id = fm_responsibility_role.id))";
             $paranthesis .= '(';
             $cols .= ',fm_responsibility_role.id as role_id';
             $cols_return[] = 'role_id';
             $uicols['input_type'][] = 'hidden';
             $uicols['name'][] = 'role_id';
             $uicols['descr'][] = 'dummy';
             $uicols['statustext'][] = 'dummy';
             $uicols['exchange'][] = false;
             $uicols['align'][] = '';
             $uicols['datatype'][] = '';
             $uicols['formatter'][] = '';
         }
         $from = " FROM {$paranthesis} fm_location{$type_id} ";
         $sql = "SELECT {$cols} {$from} {$joinmethod}";
         $this->socommon->fm_cache('sql_' . $type_id . '_lt' . $lookup_tenant . '_l' . $lookup . '_f' . !!$filter_role_on_contact, $sql);
         $this->socommon->fm_cache('uicols_' . $type_id . '_' . $lookup_tenant . '_' . $lookup . '_f' . !!$filter_role_on_contact, $uicols);
         $this->socommon->fm_cache('cols_return_' . $type_id . '_' . $lookup_tenant . '_' . $lookup . '_f' . !!$filter_role_on_contact, $cols_return);
     } else {
         $uicols = $this->socommon->fm_cache('uicols_' . $type_id . '_' . $lookup_tenant . '_' . $lookup . '_f' . !!$filter_role_on_contact);
         $cols_return = $this->socommon->fm_cache('cols_return_' . $type_id . '_' . $lookup_tenant . '_' . $lookup . '_f' . !!$filter_role_on_contact);
         $sub_query_tenant = $this->socommon->fm_cache('sub_query_tenant_' . $type_id . '_' . $lookup_tenant . '_' . $lookup);
         $sub_query_street = $this->socommon->fm_cache('sub_query_street_' . $type_id . '_' . $lookup_tenant . '_' . $lookup);
     }
     $filtermethod = '';
     $where = 'WHERE';
     if ($control_registered) {
         $sql .= "{$this->join} controller_control_location_list ON (fm_location{$type_id}.location_code = controller_control_location_list.location_code )";
         $filtermethod .= " {$where}  controller_control_location_list.control_id = {$control_id}";
         $where = 'AND';
     }
     //---------------------start custom user cols
     $user_columns = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['location_columns_' . $type_id . !!$lookup]) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['location_columns_' . $type_id . !!$lookup] : '';
     $user_column_filter = '';
     if (isset($user_columns) and is_array($user_columns) and $user_columns[0]) {
         $user_column_filter = " OR ({$attribute_filter} AND id IN (" . implode(',', $user_columns) . '))';
     }
     $this->db->query("SELECT DISTINCT * FROM {$attribute_table} WHERE (list=1 OR lookup_form=1) AND {$attribute_filter} {$user_column_filter} ORDER BY attrib_sort ASC");
     $i = count($uicols['name']);
     while ($this->db->next_record()) {
         $input_type = 'text';
         if ($this->db->f('lookup_form') == 1 && $this->db->f('list') != 1) {
             $input_type = 'hidden';
             $exchange = true;
         } else {
             if ($this->db->f('lookup_form') == 1) {
                 $exchange = true;
             } else {
                 $input_type = 'text';
                 $exchange = false;
             }
         }
         $uicols['input_type'][] = $input_type;
         $uicols['name'][] = $this->db->f('column_name');
         $uicols['descr'][] = $this->db->f('input_text');
         $uicols['statustext'][] = $this->db->f('statustext');
         $uicols['datatype'][$i] = $this->db->f('datatype');
         $uicols['formatter'][] = '';
         $uicols['exchange'][] = $exchange;
         $uicols['cols_return_extra'][$i] = array('name' => $this->db->f('column_name'), 'datatype' => $this->db->f('datatype'), 'attrib_id' => $this->db->f('id'));
         //TODO: move alignment to ui
         switch ($this->db->f('datatype')) {
             case 'V':
             case 'C':
             case 'N':
                 $uicols['align'][] = 'left';
                 break;
             case 'D':
             case 'I':
                 $uicols['align'][] = 'right';
                 break;
             default:
                 $uicols['align'][] = 'center';
         }
         if ($this->db->f('column_name') == 'category') {
             $i++;
             $cols .= ",fm_location{$type_id}_category.descr as category_text";
             $uicols['input_type'][] = 'text';
             $uicols['name'][] = 'category_text';
             $uicols['descr'][] = $this->db->f('input_text') . ' ' . lang('name');
             $uicols['statustext'][] = '';
             $uicols['datatype'][$i] = 'V';
             $uicols['formatter'][] = '';
             $uicols['exchange'][] = false;
             $uicols['align'][] = 'right';
             $uicols['cols_return_extra'][$i] = array();
         }
         $i++;
     }
     //---------------------end custom user cols
     $this->uicols = $uicols;
     if ($order && !$order == 'fm_location1.loc1') {
         $ordermethod = " ORDER BY {$order} {$sort}";
     } else {
         $ordermethod = " ORDER BY fm_location{$type_id}.loc1 {$sort}";
         if ($type_id > 1) {
             for ($i = 2; $i < $type_id + 1; $i++) {
                 $ordermethod .= ",fm_location{$type_id}.loc{$i} ASC";
             }
         }
     }
     $GLOBALS['phpgw']->config->read();
     if (isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location']) {
         $access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
         $filtermethod = " WHERE fm_location{$type_id}.loc1 in ('" . implode("','", $access_location) . "')";
         $where = 'AND';
     }
     if ($cat_id) {
         $cat_id = $this->db->db_addslashes($cat_id);
         $filtermethod .= " {$where} fm_location{$type_id}.category='{$cat_id}'";
         $where = 'AND';
     } else {
         $filtermethod .= " {$where}  (fm_location{$type_id}.category !='99' OR fm_location{$type_id}.category IS NULL)";
         $where = 'AND';
     }
     if ($filter > 0) {
         //cramirez.r@ccfirst.com 16/09/08 	validacion is added to avoid notice
         if (isset($GLOBALS['phpgw_info']['user']['preferences']['property']['property_filter']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['property_filter'] == 'owner') {
             $filtermethod .= " {$where} fm_owner.id='{$filter}' ";
         } else {
             $filtermethod .= " {$where} fm_owner.category='{$filter}' ";
         }
         $where = 'AND';
     }
     if ($status > 0) {
         $filtermethod .= " {$where} fm_location{$type_id}.status = {$status} ";
         $where = 'AND';
     } else {
         //				$filtermethod .= " $where fm_location" . ($type_id). ".status IS NULL ";
         //				$filtermethod .= " $where fm_location" . ($type_id). ".status !=2 ";
         //				$where= 'AND';
     }
     if ($district_id > 0) {
         $filtermethod .= " {$where} fm_part_of_town.district_id='{$district_id}' ";
         $where = 'AND';
     }
     if ($part_of_town_id > 0) {
         $filtermethod .= " {$where} fm_part_of_town.part_of_town_id='{$part_of_town_id}' ";
         $where = 'AND';
     }
     if ($location_code) {
         $filtermethod .= " {$where} fm_location{$type_id}.location_code {$this->like} '{$location_code}%'";
         $where = 'AND';
     }
     if ($filter_role_on_contact && $role_id) {
         $time = time() + 1;
         $filtermethod .= " {$where} active_from < {$time} AND (active_to > {$time} OR active_to = 0)" . " AND expired_on IS NULL AND fm_responsibility_role.id ={$role_id} AND contact_id = {$filter_role_on_contact}";
         $where = 'AND';
     } else {
         if ($filter_role_on_contact) {
             $time = time() + 1;
             $filtermethod .= " {$where} active_from < {$time} AND (active_to > {$time} OR active_to = 0)" . " AND expired_on IS NULL AND contact_id = {$filter_role_on_contact}";
             $where = 'AND';
         }
     }
     $_querymethod = array();
     $__querymethod = array();
     $_joinmethod_datatype = array();
     if ($query) {
         $query = $this->db->db_addslashes($query);
         $query = str_replace(",", '.', $query);
         if (stristr($query, '.')) {
             $query_part = explode(".", $query);
             $_querymethod[] = "(fm_location{$type_id}.loc1='{$query_part[0]}' AND fm_location{$type_id}.loc{$type_id}='{$query_part[1]}')";
         }
         $sub_query = '';
         if ($sub_query_tenant) {
             $sub_query = "OR fm_tenant.last_name {$this->like} '%{$query}%' OR fm_tenant.first_name {$this->like} '%{$query}%' OR fm_tenant.contact_phone {$this->like} '%{$query}%'";
         }
         if ($sub_query_street) {
             $sub_query .= "OR fm_streetaddress.descr {$this->like} '%{$query}%'";
         }
         $query_name = '';
         for ($i = 1; $i < $type_id + 1; $i++) {
             $query_name .= "OR loc{$i}_name {$this->like} '%{$query}%'";
         }
         if (!$criteria_id) {
             $_querymethod[] = " (fm_location{$type_id}.loc1 {$this->like} '%{$query}%' {$sub_query} OR fm_location{$type_id}.location_code {$this->like} '%{$query}%' {$query_name})";
         } else {
             $__querymethod = array("fm_location{$type_id}.loc1 = '-1'");
             // block query waiting for criteria
         }
         $this->db->query("SELECT * FROM {$attribute_table} WHERE {$attribute_filter} AND search='1'");
         while ($this->db->next_record()) {
             switch ($this->db->f('datatype')) {
                 case 'V':
                 case 'email':
                 case 'CH':
                     if (!$criteria_id) {
                         $_querymethod[] = "fm_location{$type_id}." . $this->db->f('column_name') . " {$this->like} '%{$query}%'";
                         $__querymethod = array();
                         // remove block
                     }
                     break;
                 case 'R':
                 case 'LB':
                     if (!$criteria_id) {
                         $_joinmethod_datatype[] = "{$this->join} phpgw_cust_choice ON (fm_location{$type_id}." . $this->db->f('column_name') . " = phpgw_cust_choice.id" . " AND phpgw_cust_choice.location_id =" . (int) $this->db->f('location_id') . " AND phpgw_cust_choice.attrib_id =" . (int) $this->db->f('id') . ')';
                         $_querymethod[] = "(phpgw_cust_choice.location_id =" . (int) $this->db->f('location_id') . " AND phpgw_cust_choice.attrib_id =" . (int) $this->db->f('id') . " AND phpgw_cust_choice.value {$this->like} '%{$query}%')";
                         $__querymethod = array();
                         // remove block
                     }
                     break;
                 case 'I':
                     if (ctype_digit($query) && !$criteria_id) {
                         $_querymethod[] = "fm_location{$type_id}." . $this->db->f('column_name') . " = " . (int) $query;
                         $__querymethod = array();
                         // remove block
                     }
                     break;
                 case 'VENDOR':
                     if ($criteria_id == 'vendor') {
                         $_joinmethod_datatype[] = "{$this->join} fm_vendor ON (fm_location{$type_id}." . $this->db->f('column_name') . " = fm_vendor.id AND fm_vendor.org_name {$this->like} '%{$query}%') ";
                         $__querymethod = array();
                         // remove block
                     }
                     break;
                 case 'AB':
                     if ($criteria_id == 'ab') {
                         $_joinmethod_datatype[] = "{$this->join} phpgw_contact_person ON (fm_location{$type_id}." . $this->db->f('column_name') . " = pphpgw_contact_person.person_id AND (phpgw_contact_person.first_name {$this->like} '%{$query}%' OR phpgw_contact_person.last_name {$this->like} '%{$query}%'))";
                         $__querymethod = array();
                         // remove block
                     }
                     break;
                 case 'ABO':
                     if ($criteria_id == 'abo') {
                         $_joinmethod_datatype[] = "{$this->join} phpgw_contact_org ON (fm_location{$type_id}." . $this->db->f('column_name') . " = phpgw_contact_org.org_id AND phpgw_contact_org.name {$this->like} '%{$query}%')";
                         $__querymethod = array();
                         // remove block
                     }
                     break;
                 default:
                     if (!$criteria_id) {
                         $_querymethod[] = "fm_location{$type_id}." . $this->db->f('column_name') . " = '{$query}'";
                         $__querymethod = array();
                         // remove block
                     }
             }
         }
         $where = 'AND';
     }
     foreach ($_joinmethod_datatype as $_joinmethod) {
         $sql .= $_joinmethod;
     }
     $querymethod = '';
     $_querymethod = array_merge($__querymethod, $_querymethod);
     if ($_querymethod) {
         $querymethod = " {$where} (" . implode(' OR ', $_querymethod) . ')';
         unset($_querymethod);
     }
     $sql .= "{$filtermethod} {$querymethod}";
     $values = array();
     //			$this->db->query('SELECT count(*) AS cnt ' . substr($sql,strripos($sql,' from')),__LINE__,__FILE__);
     //			$this->db->next_record();
     //			$this->total_records = $this->db->f('cnt');
     $cache_info = phpgwapi_cache::session_get('property', "location{$type_id}_listing_metadata");
     if (!isset($cache_info['sql_hash']) || $cache_info['sql_hash'] != md5($sql)) {
         $cache_info = array();
     }
     if (!$cache_info) {
         $this->db->query('SELECT count(*) AS cnt ' . substr($sql, strripos($sql, ' from')), __LINE__, __FILE__);
         $this->db->next_record();
         $cache_info = array('total_records' => $this->db->f('cnt'), 'sql_hash' => md5($sql));
         phpgwapi_cache::session_set('property', "location{$type_id}_listing_metadata", $cache_info);
     }
     $this->total_records = $cache_info['total_records'];
     //cramirez.r@ccfirst.com 23/07/08 avoid retrieve data in first time, only render definition for headers (var myColumnDefs)
     if ($dry_run) {
         return array();
     }
     if (!$allrows) {
         $this->db->limit_query($sql . $ordermethod, $start, __LINE__, __FILE__, $results);
     } else {
         $_fetch_single = false;
         /*
         				if($this->total_records > 200)
         				{
         					$_fetch_single = true;
         				}
         				else
         				{
         					$_fetch_single = false;
         				}
         */
         $this->db->query($sql . $ordermethod, __LINE__, __FILE__, false, $_fetch_single);
         unset($_fetch_single);
     }
     $j = 0;
     $location_count = $type_id - 1;
     $cols_return = $uicols['name'];
     $dataset = array();
     while ($this->db->next_record()) {
         foreach ($cols_return as $key => $field) {
             $dataset[$j][$field] = array('value' => $this->db->f($field), 'datatype' => $uicols['datatype'][$key], 'attrib_id' => isset($uicols['cols_return_extra'][$key]['attrib_id']) ? $uicols['cols_return_extra'][$key]['attrib_id'] : '');
         }
         $j++;
     }
     $this->db->set_fetch_single(false);
     $values = $this->custom->translate_value($dataset, $location_id, $location_count);
     return $values;
 }
コード例 #13
0
 /**
  * Import Facilit data to Portico Estate's rental module
  * The function assumes CSV files have been uploaded to a location on the server reachable by the
  * web server user.  The CSV files must correspond to the table names from Facilit, as exported
  * from Access. Field should be enclosed in single quotes and separated by comma.  The CSV files
  * must contain the column headers on the first line.
  * 
  * @return unknown_type
  */
 public function import()
 {
     $steps = 7;
     /* Import logic:
      * 
      * 1. Do step logic if the session variable is not set
      * 2. Set step result on session
      * 3. Set label for import button
      * 4. Log messages for this step
      *  
      */
     $this->messages = array();
     $this->warnings = array();
     $this->errors = array();
     // Import contract parties if not done before and put them on the users session
     if (!phpgwapi_cache::session_get('rental', 'facilit_parties')) {
         phpgwapi_cache::session_set('rental', 'facilit_parties', $this->import_parties());
         $this->log_messages(1);
         return '1';
     }
     // Import composites if not done before and put them on the users session
     if (!phpgwapi_cache::session_get('rental', 'facilit_composites')) {
         phpgwapi_cache::session_set('rental', 'facilit_composites', $this->import_composites());
         $this->log_messages(2);
         return '2';
     }
     // Load composite to contract link table if not done before and put them on the users session
     if (!phpgwapi_cache::session_get('rental', 'facilit_rentalobject_to_contract')) {
         phpgwapi_cache::session_set('rental', 'facilit_rentalobject_to_contract', $this->import_rentalobject_to_contract());
         $this->log_messages(3);
         return '3';
     }
     // Import contracts if not done before and put them on the users session
     // Prerequisites: Composites, parties, contract to composite bindings, and default values for accounts/project number for
     if (!phpgwapi_cache::session_get('rental', 'facilit_contracts')) {
         $composites = phpgwapi_cache::session_get('rental', 'facilit_composites');
         $rentalobject_to_contract = phpgwapi_cache::session_get('rental', 'facilit_rentalobject_to_contract');
         $parties = phpgwapi_cache::session_get('rental', 'facilit_parties');
         $location_id = $this->location_id;
         $defalt_values['account_in'] = rental_socontract::get_instance()->get_default_account($location_id, true);
         //IN
         $defalt_values['account_out'] = rental_socontract::get_instance()->get_default_account($location_id, false);
         //OUT
         $defalt_values['project_number'] = rental_socontract::get_instance()->get_default_project_number($location_id);
         //PROJECTNUMBER
         phpgwapi_cache::session_set('rental', 'facilit_contracts', $this->import_contracts($composites, $rentalobject_to_contract, $parties, $defalt_values));
         $this->log_messages(4);
         return '4';
     }
     // Import price items if not done before and put them on the users session
     // Prerequisites: Contracts
     if (!phpgwapi_cache::session_get('rental', 'facilit_contract_price_items')) {
         $contracts = phpgwapi_cache::session_get('rental', 'facilit_contracts');
         phpgwapi_cache::session_set('rental', 'facilit_contract_price_items', $this->import_contract_price_items($contracts));
         $this->log_messages(5);
         return '5';
     }
     // Import events if not done before and put them on the users session
     // Prerequistes: Contracts
     if (!phpgwapi_cache::session_get('rental', 'facilit_events')) {
         $contracts = phpgwapi_cache::session_get('rental', 'facilit_contracts');
         $event_data = phpgwapi_cache::session_get('rental', 'facilit_events');
         $regulation_id_location_id = isset($event_data) ? $event_data : array();
         phpgwapi_cache::session_set('rental', 'facilit_events', $this->import_events($contracts, $regulation_id_location_id));
         $this->log_messages(6);
         return '6';
     }
     // Import adjustments
     // Prerequistes: Contracts
     if (!phpgwapi_cache::session_get('rental', 'facilit_adjustments')) {
         $contracts = phpgwapi_cache::session_get('rental', 'facilit_contracts');
         $event_data = phpgwapi_cache::session_get('rental', 'facilit_events');
         $regulation_id_location_id = isset($event_data) ? $event_data : array();
         $this->import_adjustments($contracts, $regulation_id_location_id);
         $this->log_messages(7);
         $this->clean_up();
     }
     // We're done with the import, so clear all session variables so we're ready for a new one
     // We do not clear parties (same for all responsibility areas)
     // We do not clear event data, the array is just added for each
     phpgwapi_cache::session_clear('rental', 'facilit_composites');
     phpgwapi_cache::session_clear('rental', 'facilit_rentalobject_to_contract');
     phpgwapi_cache::session_clear('rental', 'facilit_contracts');
     phpgwapi_cache::session_clear('rental', 'facilit_contract_price_items');
     phpgwapi_cache::session_clear('rental', 'facilit_events');
     phpgwapi_cache::session_clear('rental', 'facilit_adjustments');
     return '7';
 }
コード例 #14
0
 private function get_location_filter()
 {
     $entity_group_id = phpgw::get_var('entity_group_id', 'int');
     $location_id = phpgw::get_var('location_id', 'int');
     $location_filter = phpgwapi_cache::session_get('controller', "location_filter_{$entity_group_id}");
     if (!$location_filter) {
         $this->soadmin_entity = CreateObject('property.soadmin_entity');
         $entity_list = $this->soadmin_entity->read(array('allrows' => true));
         $location_filter = array();
         foreach ($entity_list as $entry) {
             $categories = $this->soadmin_entity->read_category(array('entity_id' => $entry['id'], 'order' => 'name', 'sort' => 'asc', 'enable_controller' => true, 'allrows' => true));
             foreach ($categories as $category) {
                 if ($category['enable_controller']) {
                     if ($entity_group_id && $category['entity_group_id'] != $entity_group_id) {
                         continue;
                     }
                     $sort_arr = explode(' ', $category['name']);
                     $location_filter[] = array('id' => $category['location_id'], 'name' => "{$entry['name']}::{$category['name']}", 'sort_key' => trim($sort_arr[0]));
                 }
             }
         }
         // Obtain a list of columns
         foreach ($location_filter as $key => $row) {
             $id[$key] = $row['sort_key'];
         }
         array_multisort($id, SORT_ASC, SORT_STRING, $location_filter);
         phpgwapi_cache::session_set('controller', "location_filter_{$entity_group_id}", $location_filter);
     }
     foreach ($location_filter as &$location) {
         $location['selected'] = $location['id'] == $location_id ? 1 : 0;
     }
     return $location_filter;
 }
コード例 #15
0
 function read($data)
 {
     $start = isset($data['start']) && $data['start'] ? $data['start'] : 0;
     $results = isset($data['results']) && $data['results'] ? $data['results'] : 0;
     $filter = isset($data['filter']) && $data['filter'] ? $data['filter'] : 'all';
     $query = isset($data['query']) ? $data['query'] : '';
     $sort = isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
     $order = isset($data['order']) ? $data['order'] : '';
     $cat_id = isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id'] : 0;
     $district_id = isset($data['district_id']) && $data['district_id'] ? $data['district_id'] : 0;
     $part_of_town_id = isset($data['part_of_town_id']) && $data['part_of_town_id'] ? $data['part_of_town_id'] : 0;
     $lookup = isset($data['lookup']) ? $data['lookup'] : '';
     $allrows = isset($data['allrows']) ? $data['allrows'] : '';
     $entity_id = isset($data['entity_id']) ? $data['entity_id'] : '';
     $cat_id = isset($data['cat_id']) ? $data['cat_id'] : '';
     $status = isset($data['status']) ? $data['status'] : '';
     $start_date = isset($data['start_date']) ? $data['start_date'] : '';
     $end_date = isset($data['end_date']) ? $data['end_date'] : '';
     $dry_run = isset($data['dry_run']) ? $data['dry_run'] : '';
     $this->type = isset($data['type']) && $data['type'] ? $data['type'] : $this->type;
     $location_code = isset($data['location_code']) ? $data['location_code'] : '';
     $criteria_id = isset($data['criteria_id']) ? $data['criteria_id'] : '';
     $attrib_filter = $data['attrib_filter'] ? $data['attrib_filter'] : array();
     $p_num = isset($data['p_num']) ? $data['p_num'] : '';
     $custom_condition = isset($data['custom_condition']) ? $data['custom_condition'] : '';
     $org_units = isset($data['org_units']) && is_array($data['org_units']) ? $data['org_units'] : array();
     $location_id = isset($data['location_id']) && $data['location_id'] ? (int) $data['location_id'] : 0;
     $entity_group_id = isset($data['entity_group_id']) && $data['entity_group_id'] ? (int) $data['entity_group_id'] : 0;
     $filter_entity_group = isset($data['filter_entity_group']) && $data['filter_entity_group'] ? (int) $data['filter_entity_group'] : 0;
     $filter_item = isset($data['filter_item']) && $data['filter_item'] ? $data['filter_item'] : array();
     if ($location_id) {
         $loc_arr = $GLOBALS['phpgw']->locations->get_name($location_id);
         $type_arr = explode('.', $loc_arr['location']);
         if (count($type_arr) != 4) {
             return array();
         }
         $this->type = $type_arr[1];
         $entity_id = $type_arr[2];
         $cat_id = $type_arr[3];
     }
     if (!$entity_id || !$cat_id) {
         return array();
     }
     if (!$location_id) {
         $location_id = $GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");
     }
     $admin_entity = CreateObject('property.soadmin_entity');
     $admin_entity->type = $this->type;
     $category = $admin_entity->read_single_category($entity_id, $cat_id);
     $this->get_cols($category, $entity_id, $cat_id, $lookup, $location_id);
     if ($category['is_eav']) {
         return $this->read_eav($data);
     }
     $entity_table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
     $choice_table = 'phpgw_cust_choice';
     $attribute_table = 'phpgw_cust_attribute';
     $attribute_filter = " location_id = {$location_id}";
     $sql = $this->sql;
     if (!$cat_id > 0) {
         return;
     }
     $grants = $GLOBALS['phpgw']->session->appsession("grants_entity_{$entity_id}_{$cat_id}", $this->type_app[$this->type]);
     if (!$grants) {
         $this->acl =& $GLOBALS['phpgw']->acl;
         $this->acl->set_account_id($this->account);
         $grants = $this->acl->get_grants($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");
         $GLOBALS['phpgw']->session->appsession("grants_entity_{$entity_id}_{$cat_id}", $this->type_app[$this->type], $grants);
     }
     //_debug_array($cols_return_extra);
     if ($order) {
         switch ($order) {
             case 'user_id':
                 //				$ordermethod = " ORDER BY phpgw_accounts.account_lastname {$sort}";  // Don't work with LDAP.
                 break;
             case 'loc1_name':
                 $ordermethod = " ORDER BY fm_location1.loc1_name {$sort}";
                 // Don't work with LDAP.
                 break;
             default:
                 $metadata = $this->db->metadata($entity_table);
                 if (isset($metadata[$order])) {
                     $ordermethod = " ORDER BY {$entity_table}.{$order} {$sort}";
                 }
         }
     } else {
         $ordermethod = " order by {$entity_table}.id DESC";
     }
     $where = 'WHERE';
     $filtermethod = '';
     $_config = CreateObject('phpgwapi.config', $this->type_app[$this->type]);
     $_config->read();
     if (isset($_config->config_data['acl_at_location']) && $_config->config_data['acl_at_location'] && $category['location_level'] > 0) {
         $access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
         $filtermethod = " WHERE {$entity_table}.loc1 in ('" . implode("','", $access_location) . "')";
         $where = 'AND';
     }
     $bypass_acl_at_entity = false;
     if (isset($_config->config_data['bypass_acl_at_entity']) && is_array($_config->config_data['bypass_acl_at_entity']) && in_array($entity_id, $_config->config_data['bypass_acl_at_entity'])) {
         $bypass_acl_at_entity = true;
     }
     unset($_config);
     if ($org_units) {
         $filtermethod .= " {$where} ( {$entity_table}.org_unit_id IN(" . implode(',', $org_units) . "))";
         $where = 'AND';
     }
     if ($filter == 'all') {
         if (is_array($grants) && !$bypass_acl_at_entity) {
             foreach ($grants as $user => $right) {
                 $public_user_list[] = $user;
             }
             reset($public_user_list);
             $filtermethod .= " {$where} ( {$entity_table}.user_id IN(" . implode(',', $public_user_list) . "))";
             $where = 'AND';
         }
     } else {
         $filtermethod = " {$where} {$entity_table}.user_id={$filter} ";
         $where = 'AND';
     }
     if ($status) {
         $filtermethod .= " {$where} {$entity_table}.status='{$status}' ";
         $where = 'AND';
     }
     if ($district_id > 0 && $category['location_level'] && !$part_of_town_id) {
         $filtermethod .= " {$where}  fm_part_of_town.district_id='{$district_id}' ";
         $where = 'AND';
     } else {
         if ($part_of_town_id > 0 && $category['location_level']) {
             $filtermethod .= " {$where}  fm_part_of_town.part_of_town_id='{$part_of_town_id}' ";
             $where = 'AND';
         }
     }
     if ($start_date) {
         $filtermethod .= " {$where} {$entity_table}.entry_date >= {$start_date} AND {$entity_table}.entry_date <= {$end_date} ";
         $where = 'AND';
     }
     if ($location_code) {
         $filtermethod .= " {$where} {$entity_table}.location_code {$this->like} '{$location_code}%'";
         $where = 'AND';
         $query = '';
     }
     if ($attrib_filter) {
         $filtermethod .= " {$where} " . implode(' AND ', $attrib_filter);
         $where = 'AND';
     }
     if ($custom_condition) {
         $filtermethod .= " {$where} {$custom_condition}";
         $where = 'AND';
     }
     if ($p_num) {
         $filtermethod .= " {$where} {$entity_table}.p_num='{$p_num}'";
         $where = 'AND';
     }
     if ($entity_group_id) {
         $filtermethod .= " {$where} {$entity_table}.entity_group_id = {$entity_group_id}";
         $where = 'AND';
     }
     if ($filter_entity_group) {
         $filtermethod .= " {$where} {$entity_table}.entity_group_id IS NULL";
         $where = 'AND';
     }
     if (is_array($filter_item) && count($filter_item)) {
         $filtermethod .= " {$where} {$entity_table}.id IN (" . implode(',', $filter_item) . ')';
         $where = 'AND';
     }
     $_querymethod = array();
     $__querymethod = array();
     $_joinmethod_datatype = array();
     $_joinmethod_datatype_custom = array();
     if ($query) {
         $query = $this->db->db_addslashes($query);
         $query = str_replace(",", '.', $query);
         if (stristr($query, '.')) {
             $query = explode(".", $query);
             $_querymethod[] = "({$entity_table}.location_code {$this->like} '" . $query[0] . "%' AND {$entity_table}.location_code {$this->like} '%" . $query[1] . "')";
         } else {
             if (!$criteria_id) {
                 $_querymethod[] .= "( {$entity_table}.location_code {$this->like} '%{$query}%' OR {$entity_table}.num {$this->like} '%{$query}%' OR address {$this->like} '%{$query}%')";
                 //						$where= 'OR';
             } else {
                 $__querymethod = array("{$entity_table}.id = -1");
                 // block query waiting for criteria
             }
             //_debug_array($__querymethod);
             $this->db->query("SELECT * FROM {$attribute_table} WHERE {$attribute_filter} AND search='1'");
             while ($this->db->next_record()) {
                 switch ($this->db->f('datatype')) {
                     case 'V':
                     case 'email':
                     case 'T':
                         if (!$criteria_id) {
                             $_querymethod[] = "{$entity_table}." . $this->db->f('column_name') . " {$this->like} '%{$query}%'";
                             $__querymethod = array();
                             // remove block
                         }
                         break;
                     case 'CH':
                         if (!$criteria_id) {
                             // from filter
                             $_querymethod[] = "{$entity_table}." . $this->db->f('column_name') . " {$this->like} '%,{$query},%'";
                             $__querymethod = array();
                             // remove block
                             // from text-search
                             $_filter_choise = "WHERE (phpgw_cust_choice.location_id =" . (int) $this->db->f('location_id') . " AND phpgw_cust_choice.attrib_id =" . (int) $this->db->f('id') . " AND phpgw_cust_choice.value {$this->like} '%{$query}%')";
                             $this->db2->query("SELECT phpgw_cust_choice.id FROM phpgw_cust_choice {$_filter_choise}", __LINE__, __FILE__);
                             while ($this->db2->next_record()) {
                                 $_querymethod[] = "{$entity_table}." . $this->db->f('column_name') . " {$this->like} '%," . $this->db2->f('id') . ",%'";
                             }
                         }
                         break;
                     case 'R':
                     case 'LB':
                         if (!$criteria_id) {
                             $_filter_choise = "WHERE (phpgw_cust_choice.location_id =" . (int) $this->db->f('location_id') . " AND phpgw_cust_choice.attrib_id =" . (int) $this->db->f('id') . " AND phpgw_cust_choice.value {$this->like} '%{$query}%')";
                             $this->db2->query("SELECT phpgw_cust_choice.id FROM phpgw_cust_choice {$_filter_choise}", __LINE__, __FILE__);
                             $__filter_choise = array();
                             while ($this->db2->next_record()) {
                                 $__filter_choise[] = $this->db2->f('id');
                             }
                             if ($__filter_choise) {
                                 $_querymethod[] = "{$entity_table}." . $this->db->f('column_name') . ' IN (' . implode(',', $__filter_choise) . ')';
                             }
                             $__querymethod = array();
                             // remove block
                         }
                         break;
                     case 'I':
                         if (ctype_digit($query) && !$criteria_id) {
                             $_querymethod[] = "{$entity_table}." . $this->db->f('column_name') . " = " . (int) $query;
                             $__querymethod = array();
                             // remove block
                         }
                         break;
                     case 'VENDOR':
                         if ($criteria_id == 'vendor') {
                             $_joinmethod_datatype[] = "{$this->join} fm_vendor ON ({$entity_table}." . $this->db->f('column_name') . " = fm_vendor.id AND fm_vendor.org_name {$this->like} '%{$query}%') ";
                             $__querymethod = array();
                             // remove block
                         }
                         break;
                     case 'AB':
                         if ($criteria_id == 'ab') {
                             $_joinmethod_datatype[] = "{$this->join} phpgw_contact_person ON ({$entity_table}." . $this->db->f('column_name') . " = pphpgw_contact_person.person_id AND (phpgw_contact_person.first_name {$this->like} '%{$query}%' OR phpgw_contact_person.last_name {$this->like} '%{$query}%'))";
                             $__querymethod = array();
                             // remove block
                         }
                         break;
                     case 'ABO':
                         if ($criteria_id == 'abo') {
                             $_joinmethod_datatype[] = "{$this->join} phpgw_contact_org ON ({$entity_table}." . $this->db->f('column_name') . " = phpgw_contact_org.org_id AND phpgw_contact_org.name {$this->like} '%{$query}%')";
                             $__querymethod = array();
                             // remove block
                         }
                         break;
                     default:
                         if (!$criteria_id) {
                             $_querymethod[] = "{$entity_table}." . $this->db->f('column_name') . " = '{$query}'";
                             $__querymethod = array();
                             // remove block
                         }
                 }
             }
         }
     }
     $_joinmethod_datatype = array_merge($_joinmethod_datatype, $_joinmethod_datatype_custom);
     foreach ($_joinmethod_datatype as $_joinmethod) {
         $sql .= $_joinmethod;
     }
     $querymethod = '';
     $_querymethod = array_merge($__querymethod, $_querymethod);
     if ($_querymethod) {
         $querymethod = " {$where} (" . implode(' OR ', $_querymethod) . ')';
         unset($_querymethod);
     }
     $sql .= " {$filtermethod} {$querymethod}";
     $cache_info = phpgwapi_cache::session_get($this->type_app[$this->type], "{$entity_table}_listing_metadata");
     if (!isset($cache_info['sql_hash']) || $cache_info['sql_hash'] != md5($sql)) {
         $cache_info = array();
     }
     if (!$cache_info) {
         $sql_cnt = "SELECT DISTINCT {$entity_table}.id " . substr($sql, strripos($sql, 'FROM'));
         $sql2 = "SELECT count(*) as cnt FROM ({$sql_cnt}) as t";
         $this->db->query($sql2, __LINE__, __FILE__);
         $this->db->next_record();
         unset($sql2);
         unset($sql_cnt);
         $cache_info = array('total_records' => $this->db->f('cnt'), 'sql_hash' => md5($sql));
         phpgwapi_cache::session_set($this->type_app[$this->type], "{$entity_table}_listing_metadata", $cache_info);
     }
     $this->total_records = $cache_info['total_records'];
     if ($dry_run) {
         return array();
     }
     if (!$allrows) {
         $this->db->limit_query($sql . $ordermethod, $start, __LINE__, __FILE__, $results);
     } else {
         $this->db->query($sql . $ordermethod, __LINE__, __FILE__);
     }
     $j = 0;
     $uicols = $this->uicols;
     $cols_return = $uicols['name'];
     //			$cols_return = $this->cols_return;
     $dataset = array();
     while ($this->db->next_record()) {
         foreach ($cols_return as $key => $field) {
             $dataset[$j][$field] = array('value' => $this->db->f($field), 'datatype' => $uicols['datatype'][$key], 'attrib_id' => $uicols['cols_return_extra'][$key]['attrib_id'], 'get_list_function' => $uicols['get_list_function'][$key], 'get_list_function_input' => $uicols['get_list_function_input'][$key], 'get_single_function' => $uicols['get_single_function'][$key], 'get_single_function_input' => $uicols['get_single_function_input'][$key]);
         }
         $dataset[$j]['location_id'] = array('value' => $location_id, 'datatype' => false, 'attrib_id' => false);
         $dataset[$j]['entity_id'] = array('value' => $entity_id, 'datatype' => false, 'attrib_id' => false);
         $dataset[$j]['cat_id'] = array('value' => $cat_id, 'datatype' => false, 'attrib_id' => false);
         $dataset[$j]['_type'] = array('value' => $this->type, 'datatype' => false, 'attrib_id' => false);
         if ($lookup) {
             $dataset[$j]["entity_cat_name_{$entity_id}"] = array('value' => $category['name'], 'datatype' => false, 'attrib_id' => false);
             $dataset[$j]["entity_id_{$entity_id}"] = array('value' => $entity_id, 'datatype' => false, 'attrib_id' => false);
             $dataset[$j]["cat_id_{$entity_id}"] = array('value' => $cat_id, 'datatype' => false, 'attrib_id' => false);
         }
         $j++;
     }
     $values = $this->custom->translate_value($dataset, $location_id);
     return $values;
 }
コード例 #16
0
 private function get_contracts_per_location()
 {
     $org_unit = $this->header_state['selected_org_unit'];
     if ($org_unit == 'all' || $org_unit == 'none') {
         phpgwapi_cache::message_set('Velg organisasjon', 'error');
         return array();
     }
     $values = phpgwapi_cache::session_get('frontend', $this->contracts_per_location_identifier);
     if (isset($values[$org_unit])) {
         return $values[$org_unit];
     }
     $parties = rental_soparty::get_instance()->get(null, null, null, null, null, null, array('org_unit_id' => $org_unit));
     $types = rental_socontract::get_instance()->get_fields_of_responsibility();
     $location_id_internal = array_search('contract_type_internleie', $types);
     $location_id_in = array_search('contract_type_innleie', $types);
     $location_id_ex = array_search('contract_type_eksternleie', $types);
     $contracts_per_location = array();
     $contracts_in_per_location = array();
     $contracts_ex_per_location = array();
     //For all parties connected to the internal organization unit
     foreach ($parties as $party) {
         //... get the contracts
         $contracts = rental_socontract::get_instance()->get(null, null, null, null, null, null, array('party_id' => $party->get_id()));
         //... and for each contract connected to this contract part
         foreach ($contracts as $id => $contract) {
             //... get the composites
             $composites = rental_socomposite::get_instance()->get(null, null, null, null, null, null, array('contract_id' => $contracts[$id]->get_id()));
             //...and for each composite in the contract in which this contract part is connected
             foreach ($composites as $composite) {
                 //... get the units
                 $units = $composite->get_units();
                 //... and for each unit retrieve the property locations we are after
                 foreach ($units as $unit) {
                     $property_location = $unit->get_location();
                     $property_locations[$property_location->get_location_code()] = $property_location;
                     // Contract holders: contracts_per_location (internal) and contracts_in_per_location (in)
                     // Internal contract should have impact on total price
                     if ($contract->get_location_id() == $location_id_internal) {
                         $total_price = rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
                         $contract->set_total_price($total_price);
                         if (!is_array($contracts_per_location[$org_unit][$property_location->get_location_code()])) {
                             $contracts_per_location[$org_unit][$property_location->get_location_code()] = array();
                         }
                         array_push($contracts_per_location[$org_unit][$property_location->get_location_code()], $contract);
                     } else {
                         if ($contract->get_location_id() == $location_id_in) {
                             $total_price = rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
                             $contract->set_total_price($total_price);
                             if (!is_array($contracts_in_per_location[$org_unit][$property_location->get_location_code()])) {
                                 $contracts_in_per_location[$org_unit][$property_location->get_location_code()] = array();
                             }
                             array_push($contracts_in_per_location[$org_unit][$property_location->get_location_code()], $contract);
                         } else {
                             if ($contract->get_location_id() == $location_id_ex) {
                                 $total_price = rental_socontract_price_item::get_instance()->get_total_price($contract->get_id());
                                 $contract->set_total_price($total_price);
                                 if (!is_array($contracts_ex_per_location[$org_unit][$property_location->get_location_code()])) {
                                     $contracts_ex_per_location[$org_unit][$property_location->get_location_code()] = array();
                                 }
                                 array_push($contracts_ex_per_location[$org_unit][$property_location->get_location_code()], $contract);
                             }
                         }
                     }
                 }
             }
         }
     }
     phpgwapi_cache::session_set('frontend', 'contracts_per_location', $contracts_per_location);
     phpgwapi_cache::session_set('frontend', 'contracts_in_per_location', $contracts_in_per_location);
     phpgwapi_cache::session_set('frontend', 'contracts_ex_per_location', $contracts_ex_per_location);
     return ${$this}->contracts_per_location_identifier[$org_unit];
 }
コード例 #17
0
 /**
  * Import deviations found in the survey to the database from a spreadsheet
  *
  * @param int  $id  entity id
  *
  * @return void
  */
 private function _handle_import($id)
 {
     $id = (int) $id;
     if (!$id) {
         throw new Exception('uicondition_survey::_handle_import() - missing id');
     }
     $step = phpgw::get_var('step', 'int', 'REQUEST');
     $sheet_id = phpgw::get_var('sheet_id', 'int', 'REQUEST');
     $sheet_id = $sheet_id ? $sheet_id : phpgw::get_var('selected_sheet_id', 'int', 'REQUEST');
     if (!$step) {
         if ($cached_file = phpgwapi_cache::session_get('property', 'condition_survey_import_file')) {
             phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
             unlink($cached_file);
             unset($cached_file);
         }
     }
     if ($start_line = phpgw::get_var('start_line', 'int', 'REQUEST')) {
         phpgwapi_cache::system_set('property', 'import_sheet_start_line', $start_line);
     } else {
         $start_line = phpgwapi_cache::system_get('property', 'import_sheet_start_line');
         $start_line = $start_line ? $start_line : 1;
     }
     if ($columns = phpgw::get_var('columns')) {
         phpgwapi_cache::system_set('property', 'import_sheet_columns', $columns);
     } else {
         $columns = phpgwapi_cache::system_get('property', 'import_sheet_columns');
         $columns = $columns && is_array($columns) ? $columns : array();
     }
     if ($step > 1) {
         $cached_file = phpgwapi_cache::session_get('property', 'condition_survey_import_file');
     }
     if ($step == 1 || isset($_FILES['import_file']['tmp_name'])) {
         $file = $_FILES['import_file']['tmp_name'];
         $cached_file = "{$file}_temporary_import_file";
         // save a copy to survive multiple steps
         file_put_contents($cached_file, file_get_contents($file));
         phpgwapi_cache::session_set('property', 'condition_survey_import_file', $cached_file);
         $step = 1;
         // Add the file to documents
         $bofiles = CreateObject('property.bofiles');
         $to_file = "{$bofiles->fakebase}/condition_survey/{$id}/" . str_replace(' ', '_', $_FILES['import_file']['name']);
         $bofiles->vfs->rm(array('string' => $to_file, 'relatives' => array(RELATIVE_NONE)));
         $bofiles->create_document_dir("condition_survey/{$id}");
         $bofiles->vfs->override_acl = 1;
         $bofiles->vfs->cp(array('from' => $_FILES['import_file']['tmp_name'], 'to' => $to_file, 'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL)));
         $bofiles->vfs->override_acl = 0;
         unset($bofiles);
     }
     $tabs = array();
     switch ($step) {
         case 0:
             $active_tab = 'step_1';
             $lang_submit = lang('continue');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => '#step_1');
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => null);
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => null);
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => null);
             break;
         case 1:
             $active_tab = 'step_2';
             $lang_submit = lang('continue');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 0, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => '#step_2');
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => null);
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => null);
             break;
         case 2:
             $active_tab = 'step_3';
             $lang_submit = lang('continue');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 0, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 1, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => '#step_3');
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => null);
             break;
         case 3:
             $active_tab = 'step_4';
             $lang_submit = lang('import');
             $tabs['step_1'] = array('label' => lang('choose file'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 0, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_2'] = array('label' => lang('choose sheet'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 1, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_3'] = array('label' => lang('choose start line'), 'link' => self::link(array('menuaction' => 'property.uicondition_survey.import', 'id' => $id, 'step' => 2, 'sheet_id' => $sheet_id, 'start_line' => $start_line)));
             $tabs['step_4'] = array('label' => lang('choose columns'), 'link' => '#step_4');
             break;
             /*
             				case 4://temporary
             					phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
             					unlink($cached_file);
             					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction' => 'property.uicondition_survey.import', 'id' =>$id, 'step' => 0));
             					break;
             */
     }
     //-----------
     if (!$step) {
         phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
         unlink($cached_file);
     } else {
         if ($cached_file) {
             phpgw::import_class('phpgwapi.phpexcel');
             try {
                 $objPHPExcel = PHPExcel_IOFactory::load($cached_file);
                 $AllSheets = $objPHPExcel->getSheetNames();
                 $sheets = array();
                 if ($AllSheets) {
                     foreach ($AllSheets as $key => $sheet) {
                         $sheets[] = array('id' => $key, 'name' => $sheet, 'selected' => $sheet_id == $key);
                     }
                 }
                 $objPHPExcel->setActiveSheetIndex((int) $sheet_id);
             } catch (Exception $e) {
                 if ($e) {
                     phpgwapi_cache::message_set($e->getMessage(), 'error');
                     phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
                     unlink($cached_file);
                 }
             }
         }
     }
     $survey = $this->bo->read_single(array('id' => $id, 'view' => $mode == 'view'));
     $rows = $objPHPExcel->getActiveSheet()->getHighestDataRow();
     $highestColumm = $objPHPExcel->getActiveSheet()->getHighestDataColumn();
     $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumm);
     $i = 0;
     $html_table = '<table border="1">';
     if ($rows > 1 && $step == 2) {
         $cols = array();
         for ($j = 0; $j < $highestColumnIndex; $j++) {
             $cols[] = $this->getexcelcolumnname($j);
         }
         $html_table .= "<tr><th align = 'center'>" . lang('start') . "</th><th align='center'>" . implode("</th><th align='center'>", $cols) . '</th></tr>';
         foreach ($objPHPExcel->getActiveSheet()->getRowIterator() as $row) {
             if ($i > 20) {
                 break;
             }
             $i++;
             $row_key = $i;
             $_checked = '';
             if ($start_line == $row_key) {
                 $_checked = 'checked="checked"';
             }
             $_radio = "[{$row_key}]<input id=\"start_line\" type =\"radio\" {$_checked} name=\"start_line\" value=\"{$row_key}\">";
             $cellIterator = $row->getCellIterator();
             $cellIterator->setIterateOnlyExistingCells(false);
             $row_values = array();
             foreach ($cellIterator as $cell) {
                 if (!is_null($cell)) {
                     $row_values[] = $cell->getCalculatedValue();
                 }
             }
             $html_table .= "<tr><td><pre>{$_radio}</pre></td><td>" . implode('</td><td>', $row_values) . '</td></tr>';
         }
         echo '</table>';
     } else {
         if ($rows > 1 && $step == 3) {
             $_options = array('_skip_import_' => 'Utelates fra import/implisitt', 'import_type' => 'import type', 'building_part' => 'bygningsdels kode', 'descr' => 'Tilstandbeskrivelse', 'title' => 'Tiltak/overskrift', 'condition_degree' => 'Tilstandsgrad', 'condition_type' => 'Konsekvenstype', 'consequence' => 'Konsekvensgrad', 'probability' => 'Sannsynlighet', 'due_year' => 'År (innen)', 'amount_investment' => 'Beløp investering', 'amount_operation' => 'Beløp drift', 'amount_potential_grants' => 'Potensial for offentlig støtte');
             $custom = createObject('phpgwapi.custom_fields');
             $attributes = $custom->find('property', '.project.request', 0, '', '', '', true, true);
             foreach ($attributes as $attribute) {
                 $_options["custom_attribute_{$attribute['id']}"] = $attribute['input_text'];
             }
             phpgw::import_class('phpgwapi.sbox');
             for ($j = 0; $j < $highestColumnIndex; $j++) {
                 $_column = $this->getexcelcolumnname($j);
                 $_value = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, $start_line)->getCalculatedValue();
                 $selected = isset($columns[$_column]) && $columns[$_column] ? $columns[$_column] : '';
                 $_listbox = phpgwapi_sbox::getArrayItem("columns[{$_column}]", $selected, $_options, true);
                 $html_table .= "<tr><td>[{$_column}] {$_value}</td><td>{$_listbox}</td><tr>";
             }
         } else {
             if ($rows > 1 && $step == 4) {
                 $rows = $objPHPExcel->getActiveSheet()->getHighestDataRow();
                 $rows = $rows ? $rows + 1 : 0;
                 $import_data = array();
                 for ($i = $start_line; $i < $rows; $i++) {
                     $_result = array();
                     foreach ($columns as $_row_key => $_value_key) {
                         if ($_value_key != '_skip_import_') {
                             $_result[$_value_key] = $objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue();
                         }
                     }
                     $import_data[] = $_result;
                 }
                 if ($import_data) {
                     try {
                         $this->bo->import($survey, $import_data);
                     } catch (Exception $e) {
                         if ($e) {
                             phpgwapi_cache::message_set($e->getMessage(), 'error');
                         }
                     }
                 }
                 //				$msg = "'{$cached_file}' contained " . count($import_data) . " lines";
                 //				phpgwapi_cache::message_set($msg, 'message');
             }
         }
     }
     $html_table .= '</table>';
     if (isset($survey['location_code']) && $survey['location_code']) {
         $survey['location_data'] = execMethod('property.solocation.read_single', $survey['location_code']);
     }
     $bolocation = CreateObject('property.bolocation');
     $location_data = $bolocation->initiate_ui_location(array('values' => $survey['location_data'], 'type_id' => 2, 'lookup_type' => 'view2', 'tenant' => false, 'lookup_entity' => array(), 'entity_data' => isset($survey['p']) ? $survey['p'] : ''));
     $data = array('lang_submit' => $lang_submit, 'survey' => $survey, 'location_data2' => $location_data, 'step' => $step + 1, 'sheet_id' => $sheet_id, 'start_line' => $start_line, 'html_table' => $html_table, 'sheets' => array('options' => $sheets), 'tabs' => $GLOBALS['phpgw']->common->create_tabs($tabs, $active_tab));
     $GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . '::' . lang('condition survey import');
     self::render_template_xsl(array('condition_survey_import'), $data);
 }
コード例 #18
0
 protected function session_set($key, $data)
 {
     return phpgwapi_cache::session_set($this->get_ui_session_key(), $key, $data);
 }
コード例 #19
0
 public function __construct()
 {
     // This module uses XSLT templates
     $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
     $this->config = CreateObject('phpgwapi.config', 'frontend');
     $this->config->read();
     $use_fellesdata = $this->config->config_data['use_fellesdata'];
     $logo_path = $this->config->config_data['logo_path'];
     // Get the mode: in frame or full screen
     $mode = phpgwapi_cache::session_get('frontend', 'noframework');
     $noframework = isset($mode) ? $mode : true;
     /* Get the tabs and check to see whether the user has specified a tab or has a selected tab on session */
     $tabs = $this->get_tabs();
     $location_id = phpgw::get_var('location_id', 'int', 'REQUEST');
     $tab = isset($location_id) ? $location_id : phpgwapi_cache::session_get('frontend', 'tab');
     $selected = isset($tab) && $tab ? $tab : array_shift(array_keys($tabs));
     $this->tabs = $GLOBALS['phpgw']->common->create_tabs($tabs, $selected);
     $this->menu = $this->create_menu($tabs, $selected);
     phpgwapi_cache::session_set('frontend', 'tab', $selected);
     // Get header state
     $this->header_state = phpgwapi_cache::session_get('frontend', 'header_state');
     $this->header_state['use_fellesdata'] = $use_fellesdata;
     $this->header_state['logo_path'] = $logo_path;
     $this->header_state['form_action'] = $tabs[$selected]['link'];
     // Get navigation parameters
     $param_selected_location = phpgw::get_var('location');
     // New location selected from locations list
     $param_selected_org_unit = phpgw::get_var('org_unit_id');
     // New organisational unit selected from organisational units list
     $param_only_org_unit = phpgw::get_var('org_enhet_id');
     // Frontend access from rental module regarding specific organisational unit
     //Refresh organisation list
     $refresh = phpgw::get_var('refresh', 'bool');
     $property_locations_update = false;
     /* If the user has selected an organisational unit or all units */
     if (isset($param_selected_org_unit) && $param_selected_org_unit && $param_selected_org_unit != 'none') {
         //Specify which unit(s)
         if ($param_selected_org_unit == 'all') {
             $org_unit_ids = $this->header_state['org_unit'];
         } else {
             if ($this->org_unit_in_selection($param_selected_org_unit, $this->header_state['org_unit'])) {
                 //Creating a temporary array holding the single organisational unit in query
                 $org_unit_ids = array(array("ORG_UNIT_ID" => $param_selected_org_unit));
             } else {
                 //If the organisational unit selected is not in list; do default 'all'
                 $org_unit_ids = $this->header_state['org_unit'];
                 $param_selected_org_unit = 'none';
             }
         }
         $this->header_state['selected_org_unit'] = $param_selected_org_unit;
         //Update locations according to organisational unit specification
         $property_locations = frontend_borental::get_property_locations($org_unit_ids, $this->header_state['org_unit']);
         $property_locations_update = true;
     } else {
         if ($param_selected_org_unit == 'none') {
             $this->header_state['selected_org_unit'] = $param_selected_org_unit;
             $property_locations = array();
             $this->header_state['locations'] = $property_locations;
             $this->header_state['number_of_locations'] = count($property_locations);
         } else {
             if (isset($param_only_org_unit) && $param_only_org_unit && $param_selected_org_unit != 'none') {
                 //TODO: check permissions
                 if ($use_fellesdata) {
                     $name_and_result_number = frontend_bofellesdata::get_instance()->get_organisational_unit_info($param_only_org_unit);
                     //Specify unit
                     $org_unit_ids = array(array("ORG_UNIT_ID" => $param_only_org_unit, "ORG_NAME" => $name_and_result_number['UNIT_NAME'], "UNIT_ID" => $name_and_result_number['UNIT_NUMBER']));
                     //Update header state
                     $this->header_state['org_unit'] = $org_unit_ids;
                     $this->header_state['number_of_org_units'] = '1';
                     //$this->header_state['selected_org_unit'] = $name_and_result_number['UNIT_NUMBER'];
                     $this->header_state['selected_org_unit'] = $param_only_org_unit;
                     //Update locations
                     $property_locations = frontend_borental::get_property_locations($org_unit_ids, $this->header_state['org_unit']);
                     $property_locations_update = true;
                     $noframework = false;
                     // In regular frames
                     phpgwapi_cache::session_set('frontend', 'noframework', $noframework);
                     // Store mode on session
                     $GLOBALS['phpgw_info']['flags']['menu_selection'] = "frontend::{$selected}";
                     $this->insert_links_on_header_state();
                 }
             } else {
                 if (!isset($this->header_state) || isset($refresh) || !isset($this->header_state['locations'])) {
                     if ($use_fellesdata) {
                         //Specify organisational units
                         $org_units = frontend_bofellesdata::get_instance()->get_result_units($GLOBALS['phpgw_info']['user']['account_lid']);
                         //Merge with delegation units
                         $delegation_org_ids = frontend_bofrontend::get_delegations($GLOBALS['phpgw_info']['user']['account_id']);
                         if (count($delegation_org_ids) > 0) {
                             $delegation_units = frontend_bofellesdata::get_instance()->populate_result_units($delegation_org_ids);
                             $org_units = array_merge($org_units, $delegation_units);
                         }
                         //Update org units on header state
                         $this->header_state['org_unit'] = $org_units;
                         $this->header_state['number_of_org_units'] = count($org_units);
                         $this->header_state['selected_org_unit'] = 'none';
                         //Update locations
                         //FIXME Sigurd 15. okt 2013: deselect 'all' on initial view
                         //$property_locations = frontend_borental::get_property_locations($org_units, $this->header_state['org_unit']);
                     } else {
                         if ($param_selected_org_unit != 'none') {
                             //If no organisational database is in use: get rented properties based on username
                             $usernames[] = $GLOBALS['phpgw_info']['user']['account_lid'];
                             $property_locations = frontend_borental::get_property_locations($usernames, $this->header_state['org_unit']);
                         }
                     }
                     $property_locations_update = true;
                     $this->insert_links_on_header_state();
                 }
             }
         }
     }
     if ($property_locations_update) {
         if (count($property_locations) > 0) {
             $this->header_state['selected_location'] = $property_locations[0]['location_code'];
             $param_selected_location = $property_locations[0]['location_code'];
         } else {
             $this->header_state['selected_location'] = '';
             $param_selected_location = '';
         }
         $this->header_state['locations'] = $property_locations;
         $this->header_state['number_of_locations'] = count($property_locations);
         //FIXME
         $this->calculate_totals($property_locations);
     }
     /* If the user has selected a location or as a side-effect from selecting organisational unit */
     if ($param_selected_location) {
         $locs = $this->header_state['locations'];
         $exist = false;
         foreach ($locs as $loc) {
             if ($loc['location_code'] == $param_selected_location) {
                 $exist = true;
             }
         }
         if ($exist) {
             $this->header_state['selected_location'] = $param_selected_location;
             $parties = frontend_borental::get_all_parties(array(), $this->header_state['selected_org_unit']);
             $totals = frontend_borental::get_total_cost_and_area($parties, $param_selected_location);
             $this->header_state['selected_total_price'] = number_format($totals['sum_total_price'], 2, ",", " ") . " " . lang('currency');
             $this->header_state['selected_total_area'] = number_format($totals['sum_total_area'], 2, ",", " ") . " " . lang('square_meters');
             phpgwapi_cache::session_set('frontend', 'header_state', $this->header_state);
         } else {
             //Set totals to 0
             $this->header_state['selected_location'] = $param_selected_location;
             $this->header_state['selected_total_price'] = lang('no_selection');
             $this->header_state['selected_total_area'] = lang('no_selection');
             phpgwapi_cache::session_set('frontend', 'header_state', $this->header_state);
         }
         phpgwapi_cache::session_clear('frontend', 'contract_state');
         phpgwapi_cache::session_clear('frontend', 'contract_state_in');
         phpgwapi_cache::session_clear('frontend', 'contract_state_ex');
     }
     /* Store the header state on the session*/
     $bomessenger = CreateObject('messenger.bomessenger');
     $total_messages = $bomessenger->total_messages(" AND message_status = 'N'");
     if ($total_messages > 0) {
         $this->header_state['new_messages'] = "({$total_messages})";
     } else {
         $this->header_state['new_messages'] = lang('no_new_messages');
     }
     phpgwapi_cache::session_set('frontend', 'header_state', $this->header_state);
     $GLOBALS['phpgw']->css->add_external_file('frontend/templates/base/base.css');
     $GLOBALS['phpgw_info']['flags']['noframework'] = true;
     $GLOBALS['phpgw']->js->validate_file('jquery', 'menu', 'frontend');
 }
コード例 #20
0
 protected function get_user_orgnr_from_auth_header()
 {
     $config = CreateObject('phpgwapi.config', 'bookingfrontend');
     $config->read();
     if ($config->config_data['authentication_method'] === 'MinId.php') {
         $ipdp = sha1($_SERVER['HTTP_UID']);
         $bregorgs = $this->get_breg_orgs($ipdp);
         $myorgnr = array();
         if ($bregorgs == array()) {
             $external_user = (object) 'ciao';
             $external_user->login = '******';
         } else {
             foreach ($bregorgs as $org) {
                 $myorgnr[] = $org['orgnr'];
             }
             if (count($myorgnr) > 1) {
                 $external_user = (object) 'ciao';
                 $external_user->login = $myorgnr[0];
                 $orgs = array();
                 foreach ($myorgnr as $org) {
                     $orgs[] = array('orgnumber' => $org, 'orgname' => $this->get_orgname_from_db($org));
                 }
                 phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, $orgs);
             } elseif (count($myorgnr) > 0) {
                 phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, NULL);
                 $external_user = (object) 'ciao';
                 $external_user->login = $myorgnr[0];
             }
         }
     } else {
         $header_key = isset($config->config_data['header_key']) && $config->config_data['header_key'] ? $config->config_data['header_key'] : 'Osso-User-Dn';
         $header_regular_expression = isset($config->config_data['header_regular_expression']) && $config->config_data['header_regular_expression'] ? $config->config_data['header_regular_expression'] : '/^cn=(.*),cn=users.*$/';
         $headers = getallheaders();
         if (isset($config->config_data['debug']) && $config->config_data['debug']) {
             $this->debug = true;
             echo 'headers:<br>';
             _debug_array($headers);
         }
         if (isset($headers[$header_key]) && $headers[$header_key]) {
             $matches = array();
             preg_match_all($header_regular_expression, $headers[$header_key], $matches);
             $userid = $matches[1][0];
             if ($this->debug) {
                 echo 'matches:<br>';
                 _debug_array($matches);
             }
         }
         $options = array();
         $options['soap_version'] = SOAP_1_1;
         $options['location'] = isset($config->config_data['soap_location']) && $config->config_data['soap_location'] ? $config->config_data['soap_location'] : '';
         // 'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1';
         $options['uri'] = isset($config->config_data['soap_uri']) && $config->config_data['soap_uri'] ? $config->config_data['soap_uri'] : '';
         // 'http://soat1a.srv.bergenkom.no';
         $options['trace'] = 1;
         if (isset($config->config_data['soap_proxy_host']) && $config->config_data['soap_proxy_host']) {
             $options['proxy_host'] = $config->config_data['soap_proxy_host'];
         }
         if (isset($config->config_data['soap_proxy_port']) && $config->config_data['soap_proxy_port']) {
             $options['proxy_port'] = $config->config_data['soap_proxy_port'];
         }
         $options['encoding'] = isset($config->config_data['soap_encoding']) && $config->config_data['soap_encoding'] ? $config->config_data['soap_encoding'] : 'UTF-8';
         $options['login'] = isset($config->config_data['soap_login']) && $config->config_data['soap_login'] ? $config->config_data['soap_login'] : '';
         $options['password'] = isset($config->config_data['soap_password']) && $config->config_data['soap_password'] ? $config->config_data['soap_password'] : '';
         $wsdl = isset($config->config_data['soap_wsdl']) && $config->config_data['soap_wsdl'] ? $config->config_data['soap_wsdl'] : '';
         // 'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1?wsdl';
         $authentication_method = isset($config->config_data['authentication_method']) && $config->config_data['authentication_method'] ? $config->config_data['authentication_method'] : '';
         require_once PHPGW_SERVER_ROOT . "/bookingfrontend/inc/custom/default/{$authentication_method}";
         $external_user = new booking_external_user($wsdl, $options, $userid, $this->debug);
         // test values
         //$external_user = (object) 'ciao'; $external_user->login = 994239929;
     }
     if ($this->debug) {
         echo 'External user:<br>';
         _debug_array($external_user);
     }
     try {
         return createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($external_user->login);
     } catch (sfValidatorError $e) {
         if ($this->debug) {
             echo $e->getMessage();
             die;
         }
         return null;
     }
 }
コード例 #21
0
 public function __construct()
 {
     phpgwapi_cache::session_set('frontend', 'tab', $GLOBALS['phpgw']->locations->get_id('frontend', '.delegates'), $GLOBALS['phpgw_info']['user']['account_id']);
     parent::__construct();
 }
コード例 #22
0
 /**
  * setup the user data cache
  *
  * @param boolean $write_cache should the cached data be stored?
  *
  * @return void
  */
 protected function _setup_cache($write_cache = true)
 {
     $this->_data = $GLOBALS['phpgw']->accounts->read()->toArray();
     $this->_data['fullname'] = $GLOBALS['phpgw']->accounts->read()->__toString();
     //			$this->_data['acl']         = $GLOBALS['phpgw']->acl->read(); // This one is never used
     $this->_data['preferences'] = $GLOBALS['phpgw']->preferences->read();
     $this->_data['apps'] = $GLOBALS['phpgw']->applications->read();
     $this->_data['domain'] = $this->_account_domain;
     $this->_data['sessionid'] = $this->_sessionid;
     $this->_data['session_ip'] = $this->_get_user_ip();
     $this->_data['session_lid'] = $this->_account_lid . '#' . $this->_account_domain;
     $this->_data['account_id'] = $this->_account_id;
     $this->_data['account_lid'] = $this->_account_lid;
     $this->_data['userid'] = $this->_account_lid;
     $this->_data['passwd'] = $this->_passwd;
     if ($write_cache) {
         phpgwapi_cache::session_set('phpgwapi', 'phpgw_info', $this->_data);
     }
 }
コード例 #23
0
 public function __construct()
 {
     $GLOBALS['phpgw']->translation->add_app('property');
     $this->location_id = phpgw::get_var('location_id', 'int', 'REQUEST', 0);
     $location_info = $GLOBALS['phpgw']->locations->get_name($this->location_id);
     $this->acl_location = $location_info['location'];
     $location_arr = explode('.', $this->acl_location);
     $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
     $this->bo = CreateObject('property.boentity');
     $this->bocommon =& $this->bo->bocommon;
     $this->soadmin_entity =& $this->bo->soadmin_entity;
     $this->entity_id = isset($location_arr[2]) && $location_arr[2] ? $location_arr[2] : $this->bo->entity_id;
     $this->cat_id = isset($location_arr[3]) && $location_arr[3] ? $location_arr[3] : $this->bo->cat_id;
     $this->type = $this->bo->type;
     $this->type_app = $this->bo->type_app;
     if (isset($location_arr[3])) {
         $this->bo->entity_id = $this->entity_id;
         $this->bo->cat_id = $this->cat_id;
         $this->acl_location = ".{$this->type}.{$this->entity_id}";
         if ($this->cat_id) {
             $this->acl_location .= ".{$this->cat_id}";
         }
     }
     $this->acl =& $GLOBALS['phpgw']->acl;
     $this->acl_read = $this->acl->check($this->acl_location, PHPGW_ACL_READ, 'property');
     $this->acl_add = $this->acl->check($this->acl_location, PHPGW_ACL_ADD, 'property');
     $this->acl_edit = $this->acl->check($this->acl_location, PHPGW_ACL_EDIT, 'property');
     $this->acl_delete = $this->acl->check($this->acl_location, PHPGW_ACL_DELETE, 'property');
     $this->start = $this->bo->start;
     $this->query = $this->bo->query;
     $this->sort = $this->bo->sort;
     $this->order = $this->bo->order;
     $this->filter = $this->bo->filter;
     $this->part_of_town_id = $this->bo->part_of_town_id;
     $this->district_id = $this->bo->district_id;
     $this->status = $this->bo->status;
     //			$this->location_code		= $this->bo->location_code;
     $this->p_num = $this->bo->p_num;
     $GLOBALS['phpgw']->session->appsession('entity_id', 'property', $this->entity_id);
     $this->start_date = $this->bo->start_date;
     $this->end_date = $this->bo->end_date;
     $this->allrows = $this->bo->allrows;
     $this->category_dir = "{$this->type}_{$this->entity_id}_{$this->cat_id}";
     $this->bo->category_dir = $this->category_dir;
     phpgwapi_cache::session_set('frontend', 'tab', $this->location_id);
     parent::__construct();
     $this->location_code = $this->header_state['selected_location'];
     $this->bo->location_code = $this->location_code;
     $_org_units = array();
     if (is_array($this->header_state['org_unit'])) {
         foreach ($this->header_state['org_unit'] as $org_unit) {
             $_org_unit_id = (int) $org_unit['ORG_UNIT_ID'];
             $_subs = execMethod('property.sogeneric.read_tree', array('node_id' => $_org_unit_id, 'type' => 'org_unit'));
             $_org_units[$_org_unit_id] = true;
             foreach ($_subs as $entry) {
                 $_org_units[$entry['id']] = true;
                 if (isset($entry['children']) && $entry['children']) {
                     $this->_get_children($entry['children'], $_org_units);
                 }
             }
         }
     }
     $org_units = array_keys($_org_units);
     $this->bo->org_units = $org_units;
 }
コード例 #24
0
 function save_sessiondata($data)
 {
     if ($this->use_session) {
         phpgwapi_cache::session_set('property.request', 'session_data', $data);
     }
 }
コード例 #25
0
    /**
     * Public method. 
     * 
     * @return unknown_type
     */
    public function index()
    {
        // Set the submit button label to its initial state
        $this->import_button_label = "Start import";
        $this->download_template_button_label = 'Download template';
        $check_method = 0;
        $get_identificator = false;
        if ($this->conv_type = phpgw::get_var('conv_type')) {
            $check_method++;
            $get_identificator = true;
        }
        if ($this->location_id = phpgw::get_var('location_id', 'int')) {
            $check_method++;
            $get_identificator = true;
        }
        if ($table = phpgw::get_var('table')) {
            $check_method++;
            $get_identificator = true;
        }
        if ($check_method > 1) {
            phpgwapi_cache::session_set('property', 'import_message', 'choose only one target!');
            $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiimport.index'));
        }
        phpgwapi_cache::session_set('property', 'import_settings', $_POST);
        $download_template = phpgw::get_var('download_template');
        if ($download_template) {
            $this->get_template($this->location_id);
        }
        // If the parameter 'importsubmit' exist (submit button in import form), set path
        if (phpgw::get_var("importsubmit")) {
            if ($GLOBALS['phpgw']->session->is_repost() && !phpgw::get_var('debug', 'bool')) {
                phpgwapi_cache::session_set('property', 'import_message', 'Hmm... looks like a repost!');
                $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiimport.index'));
            }
            $start_time = time();
            // Start time of import
            $start = date("G:i:s", $start_time);
            echo "<h3>Import started at: {$start}</h3>";
            echo "<ul>";
            if ($this->conv_type) {
                if (preg_match('/\\.\\./', $this->conv_type)) {
                    throw new Exception("Not a valid file: {$this->conv_type}");
                }
                $file = PHPGW_SERVER_ROOT . "/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$this->conv_type}";
                if (is_file($file)) {
                    require_once $file;
                }
            } else {
                require_once PHPGW_SERVER_ROOT . "/property/inc/import/import_update_generic.php";
            }
            $this->debug = phpgw::get_var('debug', 'bool');
            $this->import_conversion = new import_conversion($this->location_id, $this->debug);
            // Get the path for user input or use a default path
            $files = array();
            if (isset($_FILES['file']['tmp_name']) && $_FILES['file']['tmp_name']) {
                $files[] = array('name' => $_FILES['file']['tmp_name'], 'type' => $_FILES['file']['type']);
            } else {
                $path = phpgw::get_var('path', 'string');
                $files = $this->get_files($path);
            }
            if (!$files) {
                phpgwapi_cache::session_set('property', 'import_message', 'Ingen filer er valgt');
                $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'property.uiimport.index'));
            }
            foreach ($files as $file) {
                $valid_type = false;
                switch ($file['type']) {
                    case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
                    case 'application/vnd.oasis.opendocument.spreadsheet':
                    case 'application/vnd.ms-excel':
                        $this->csvdata = $this->getexceldata($file['name'], $get_identificator);
                        $valid_type = true;
                        break;
                    case 'text/csv':
                    case 'text/comma-separated-values':
                        $this->csvdata = $this->getcsvdata($file['name'], $get_identificator);
                        $valid_type = true;
                        break;
                    default:
                        throw new Exception("Not a valid filetype: {$file['type']}");
                }
                if ($valid_type) {
                    $result = $this->import();
                    $this->messages = array_merge($this->messages, $this->import_conversion->messages);
                    $this->warnings = array_merge($this->warnings, $this->import_conversion->warnings);
                    $this->errors = array_merge($this->errors, $this->import_conversion->errors);
                    $this->csvdata = array();
                    echo '<li class="info">Import: finished step ' . $result . '</li>';
                }
            }
            echo "</ul>";
            $end_time = time();
            $difference = ($end_time - $start_time) / 60;
            $end = date("G:i:s", $end_time);
            echo "<h3>Import ended at: {$end}. Import lasted {$difference} minutes.";
            if ($this->errors) {
                echo "<ul>";
                foreach ($this->errors as $error) {
                    echo '<li class="error">Error: ' . $error . '</li>';
                }
                echo "</ul>";
            }
            if ($this->warnings) {
                echo "<ul>";
                foreach ($this->warnings as $warning) {
                    echo '<li class="warning">Warning: ' . $warning . '</li>';
                }
                echo "</ul>";
            }
            if ($this->messages) {
                echo "<ul>";
                foreach ($this->messages as $message) {
                    echo '<li class="info">Message: ' . $message . '</li>';
                }
                echo "</ul>";
            }
            echo '<a href="' . $GLOBALS['phpgw']->link('/home.php') . '">Home</a>';
            echo '</br><a href="' . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiimport.index')) . '">Import</a>';
        } else {
            $import_settings = phpgwapi_cache::session_get('property', 'import_settings');
            $import_message = phpgwapi_cache::session_get('property', 'import_message');
            phpgwapi_cache::session_clear('property', 'import_message');
            $conv_list = $this->get_import_conv($import_settings['conv_type']);
            $conv_option = '<option value="">' . lang('none selected') . '</option>' . "\n";
            foreach ($conv_list as $conv) {
                $selected = '';
                if ($conv['selected']) {
                    $selected = 'selected =  "selected"';
                }
                $conv_option .= <<<HTML
\t\t\t\t\t<option value='{$conv['id']}'{$selected}>{$conv['name']}</option>
HTML;
            }
            $tables = $this->valid_tables;
            ksort($tables);
            $table_option = '<option value="">' . lang('none selected') . '</option>' . "\n";
            foreach ($tables as $table => $table_info) {
                $selected = $import_settings['table'] == $table ? 'selected =  "selected"' : '';
                $table_option .= <<<HTML
\t\t\t\t\t<option value='{$table}'{$selected}>{$table_info['name']}::{$table_info['permission']}</option>
HTML;
            }
            $entity = CreateObject('property.soadmin_entity');
            $entity_list = $entity->read(array('allrows' => true));
            $category_option = '<option value="">' . lang('none selected') . '</option>' . "\n";
            foreach ($entity_list as $entry) {
                $category_list = $entity->read_category_tree2($entry['id']);
                foreach ($category_list as $category) {
                    $selected = $import_settings['location_id'] == $category['location_id'] ? 'selected =  "selected"' : '';
                    $category_option .= <<<HTML
\t\t\t\t\t\t<option value="{$category['location_id']}"{$selected}>{$category['name']}</option>
HTML;
                }
            }
            $home = $GLOBALS['phpgw']->link('/home.php');
            $action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiimport.index'));
            $debug_checked = isset($import_settings['debug']) && $import_settings['debug'] ? 'checked =  "checked"' : '';
            $html = <<<HTML
\t\t\t\t<h1><img src="rental/templates/base/images/32x32/actions/document-save.png" /> Importer ( MsExcel / CSV )</h1>
\t\t\t\t<div id="messageHolder">{$import_message}</div>
\t\t\t\t<form action="{$action}" method="post" enctype="multipart/form-data">
\t\t\t\t\t<fieldset>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<label for="file">Choose file:</label>
\t\t\t\t\t\t\t<input type="file" name="file" id="file" title = 'Single file'/>
\t\t\t\t\t\t</p>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<label for="path">Local path:</label>
\t\t\t\t\t\t\t<input type="text" name="path" id="path" value = '{$import_settings['path']}' title = 'Alle filer i katalogen'/>
\t\t\t\t\t\t</p>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<label for="conv_type">Choose conversion:</label>
\t\t\t\t\t\t\t<select name="conv_type" id="conv_type">
\t\t\t\t\t\t\t{$conv_option}
\t\t\t\t\t\t</select>
\t\t\t\t\t\t</p>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<label for="table">Choose Table:</label>
\t\t\t\t\t\t\t<select name="table" id="table">
\t\t\t\t\t\t\t{$table_option}
\t\t\t\t\t\t</select>
\t\t\t\t\t\t</p>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<label for="category">Choose category:</label>
\t\t\t\t\t\t\t<select name="location_id" id="category">
\t\t\t\t\t\t\t{$category_option}
\t\t\t\t\t\t</select>
\t\t\t\t\t\t</p>

\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<label for="debug">Debug:</label>
\t\t\t\t\t\t\t<input type="checkbox" name="debug" id="debug" {$debug_checked} value ='1' />
\t\t\t\t\t\t</p>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<input type="submit" name="download_template" value="{$this->download_template_button_label}"  />
\t\t\t\t\t\t</p>
\t\t\t\t\t\t<p>
\t\t\t\t\t\t\t<input type="submit" name="importsubmit" value="{$this->import_button_label}"  />
\t\t\t\t\t\t</p>
\t\t \t\t\t</fieldset>
\t\t\t\t</form>
\t\t\t\t<br><a href='{$home}'>Home</a>
HTML;
            echo $html;
        }
    }
コード例 #26
0
 public function query()
 {
     $params = array('start' => phpgw::get_var('startIndex', 'int', 'REQUEST', 0), 'results' => phpgw::get_var('results', 'int', 'REQUEST', null), 'query' => phpgw::get_var('query'), 'sort' => phpgw::get_var('sort'), 'dir' => phpgw::get_var('dir'), 'filters' => $filters);
     $ctrl_area = phpgw::get_var('control_areas');
     if (isset($ctrl_area) && $ctrl_area > 0) {
         $filters['control_areas'] = $ctrl_area;
     }
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort');
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     // Form variables
     $search_for = phpgw::get_var('query');
     $search_type = phpgw::get_var('search_option');
     // Create an empty result set
     $result_objects = array();
     $result_count = 0;
     //Retrieve a contract identifier and load corresponding contract
     $procedure_id = phpgw::get_var('procedure_id');
     $exp_param = phpgw::get_var('export');
     $export = false;
     if (isset($exp_param) && $exp_param) {
         $export = true;
         $num_of_objects = null;
     }
     //Retrieve the type of query and perform type specific logic
     $query_type = phpgw::get_var('type');
     switch ($query_type) {
         default:
             // ... all composites, filters (active and vacant)
             phpgwapi_cache::session_set('controller', 'procedure_query', $search_for);
             //$filters = array();
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->get_count($search_for, $search_type, $filters);
             break;
     }
     //Create an empty row set
     $rows = array();
     foreach ($result_objects as $result) {
         if (isset($result)) {
             $rows[] = $result->serialize();
         }
     }
     // ... add result data
     $result_data = array('results' => $rows);
     $result_data['total_records'] = $object_count;
     $result_data['start'] = $params['start'];
     $result_data['sort'] = $params['sort'];
     $result_data['dir'] = $params['dir'];
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     if (!$export) {
         //Add action column to each row in result table
         array_walk($result_data['results'], array($this, '_add_links'), "controller.uiprocedure.view");
     }
     //_debug_array($result_data);
     return $this->yui_results($result_data);
 }
コード例 #27
0
 public function add_ticket()
 {
     $values = phpgw::get_var('values');
     $p_entity_id = phpgw::get_var('p_entity_id', 'int');
     $p_cat_id = phpgw::get_var('p_cat_id', 'int');
     $p_num = phpgw::get_var('p_num');
     $origin = phpgw::get_var('origin');
     if ($p_entity_id && $p_cat_id && $p_num) {
         $item = execMethod('property.boentity.read_single', array('id' => $p_num, 'entity_id' => $p_entity_id, 'cat_id' => $p_cat_id, 'view' => true));
     }
     $bo = CreateObject('property.botts', true);
     $boloc = CreateObject('property.bolocation', true);
     $location_details = $boloc->read_single($this->location_code, array('noattrib' => true));
     $missingfields = false;
     $msglog = array();
     // Read default assign-to-group from config
     $config = CreateObject('phpgwapi.config', 'frontend');
     $config->read();
     $default_cat = $config->config_data['tts_default_cat'] ? $config->config_data['tts_default_cat'] : 0;
     if (!$default_cat) {
         throw new Exception('Default category is not set in config');
         $GLOBALS['phpgw']->common->phpgw_exit();
     }
     $cat_id = isset($values['cat_id']) && $values['cat_id'] ? $values['cat_id'] : $default_cat;
     if (isset($values['save'])) {
         foreach ($values as $key => $value) {
             if (empty($value) && $key !== 'file') {
                 $missingfields = true;
             }
         }
         if (!$missingfields && !phpgw::get_var('added')) {
             $location = array();
             $_location_arr = explode('-', $this->location_code);
             $i = 1;
             foreach ($_location_arr as $_loc) {
                 $location["loc{$i}"] = $_loc;
                 $i++;
             }
             $assignedto = execMethod('property.boresponsible.get_responsible', array('location' => $location, 'cat_id' => $cat_id));
             if (!$assignedto) {
                 $default_group = (int) $config->config_data['tts_default_group'];
             } else {
                 $default_group = 0;
             }
             $ticket = array('origin_id' => $GLOBALS['phpgw']->locations->get_id('property', $origin), 'origin_item_id' => $p_num, 'cat_id' => $cat_id, 'group_id' => $default_group ? $default_group : null, 'assignedto' => $assignedto, 'priority' => 3, 'status' => 'O', 'subject' => $values['title'], 'details' => $values['locationdesc'] . ":\n\n" . $values['description'], 'apply' => lang('Apply'), 'contact_id' => 0, 'location' => $location, 'location_code' => $this->location_code, 'street_name' => $location_details['street_name'], 'street_number' => $location_details['street_number'], 'location_name' => $location_details['loc1_name']);
             $result = $bo->add($ticket);
             if ($result['message'][0]['msg'] != null && $result['id'] > 0) {
                 $msglog['message'][] = array('msg' => lang('Ticket added'));
                 $noform = true;
                 // Files
                 $values['file_name'] = @str_replace(' ', '_', $_FILES['file']['name']);
                 if ($values['file_name'] && $result['id']) {
                     $bofiles = CreateObject('property.bofiles');
                     $to_file = $bofiles->fakebase . '/fmticket/' . $result['id'] . '/' . $values['file_name'];
                     if ($bofiles->vfs->file_exists(array('string' => $to_file, 'relatives' => array(RELATIVE_NONE)))) {
                         $msglog['error'][] = array('msg' => lang('This file already exists !'));
                     } else {
                         $bofiles->create_document_dir("fmticket/{$result['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)))) {
                             $msglog['error'][] = array('msg' => lang('Failed to upload file!'));
                         }
                         $bofiles->vfs->override_acl = 0;
                     }
                 }
                 $redirect = true;
                 phpgwapi_cache::session_set('frontend', 'msgbox', $msglog);
                 // /Files
             }
         } else {
             $msglog['error'][] = array('msg' => lang('Missing field(s)'));
         }
     }
     $tts_frontend_cat_selected = $config->config_data['tts_frontend_cat'] ? $config->config_data['tts_frontend_cat'] : array();
     $cats = CreateObject('phpgwapi.categories', -1, 'property', '.ticket');
     $cats->supress_info = true;
     $categories = $cats->return_sorted_array(0, false, '', '', '', true, '', false);
     $category_list = array();
     foreach ($categories as $category) {
         if (in_array($category['id'], $tts_frontend_cat_selected)) {
             $category_list[] = array('id' => $category['id'], 'name' => $category['name'], 'selected' => $category['id'] == $default_cat ? 1 : 0);
         }
     }
     $form_action_data = array('menuaction' => 'frontend.uihelpdesk.add_ticket', 'noframework' => '1', 'origin' => $origin, 'p_entity_id' => $p_entity_id, 'p_cat_id' => $p_cat_id, 'p_num' => $p_num);
     $data = array('redirect' => isset($redirect) ? $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'frontend.uihelpdesk.index')) : null, 'msgbox_data' => $GLOBALS['phpgw']->common->msgbox($GLOBALS['phpgw']->common->msgbox_data($msglog)), 'form_action' => $GLOBALS['phpgw']->link('/index.php', $form_action_data), 'title' => $values['title'], 'locationdesc' => $values['locationdesc'], 'description' => $values['description'], 'noform' => $noform, 'category_list' => $category_list, 'custom_attributes' => array('attributes' => $item['attributes']));
     $GLOBALS['phpgw']->xslttpl->add_file(array('frontend', 'helpdesk', 'attributes_view'));
     $GLOBALS['phpgw']->xslttpl->set_var('phpgw', array('add_ticket' => $data));
 }
コード例 #28
0
 /**
  * Get a list of users that have grants rights to their records at a location within an app
  *
  * @param string $app      Application name
  *				if emptry string, value of $GLOBALS['phpgw_info']['flags']['currentapp'] is used
  * @param string $location location within application
  *
  * @return array Array with account ids and corresponding rights
  */
 public function get_grants($app = '', $location = '')
 {
     $grant_rights = phpgwapi_cache::session_get('phpgwapi', "get_grants_{$app}_{$location}");
     if (!is_null($grant_rights)) {
         return $grant_rights;
         // nothing more to do
     }
     $grant_rights = $this->get_grants_type($app, $location, 0);
     $grant_mask = $this->get_grants_type($app, $location, 1);
     if (is_array($grant_mask)) {
         foreach ($grant_mask as $user_id => $mask) {
             if ($grant_rights[$user_id]) {
                 $grant_rights[$user_id] &= ~$mask;
                 if ($grant_rights[$user_id] <= 0) {
                     unset($grant_rights[$user_id]);
                 }
             }
         }
     }
     phpgwapi_cache::session_set('phpgwapi', "get_grants_{$app}_{$location}", $grant_rights);
     return $grant_rights;
 }
コード例 #29
0
 public function query()
 {
     $params = array('start' => phpgw::get_var('startIndex', 'int', 'REQUEST', 0), 'results' => phpgw::get_var('results', 'int', 'REQUEST', null), 'query' => phpgw::get_var('query'), 'sort' => phpgw::get_var('sort'), 'dir' => phpgw::get_var('dir'), 'filters' => $filters);
     if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) {
         $user_rows_per_page = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     } else {
         $user_rows_per_page = 10;
     }
     // YUI variables for paging and sorting
     $start_index = phpgw::get_var('startIndex', 'int');
     $num_of_objects = phpgw::get_var('results', 'int', 'GET', $user_rows_per_page);
     $sort_field = phpgw::get_var('sort');
     $sort_ascending = phpgw::get_var('dir') == 'desc' ? false : true;
     // Form variables
     $search_for = phpgw::get_var('query');
     $search_type = phpgw::get_var('search_option');
     // Create an empty result set
     $result_objects = array();
     $result_count = 0;
     //Retrieve a contract identifier and load corresponding contract
     $exp_param = phpgw::get_var('export');
     $export = false;
     if (isset($exp_param)) {
         $export = true;
         $num_of_objects = null;
     }
     //Retrieve the type of query and perform type specific logic
     $query_type = phpgw::get_var('type');
     switch ($query_type) {
         case 'children':
             $activity_id = phpgw::get_var('activity_id');
             $filters = array('id' => $activity_id);
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->get_count();
             array_shift($result_objects);
             if ($result_objects) {
                 $object_count--;
             }
             break;
         case 'activity_id':
             $activity_id = phpgw::get_var('activity_id');
             $filters = array('id' => $activity_id);
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->get_count($search_for, $search_type, $filters);
             break;
         default:
             // ... all activities, filters (active and vacant)
             phpgwapi_cache::session_set('logistic', 'activity_query', $search_for);
             $filters = array('project' => phpgw::get_var('project'), 'user' => phpgw::get_var('user'), 'activity' => phpgw::get_var('filter', 'int'));
             $result_objects = $this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, $filters);
             $object_count = $this->so->total_records;
             break;
     }
     //Create an empty row set
     $rows = array();
     foreach ($result_objects as $activity) {
         if (isset($activity)) {
             $filters = array('activity' => $activity->get_id());
             $requirements_for_activity = $this->so_requirement->get(0, null, null, null, null, null, $filters);
             if (count($requirements_for_activity) > 0) {
                 $total_num_alloc = 0;
                 $total_num_required = 0;
                 foreach ($requirements_for_activity as $requirement) {
                     $filters = array('requirement_id' => $requirement->get_id());
                     $num_allocated = $this->so_resource_allocation->get_count(null, null, $filters);
                     $num_required = $requirement->get_no_of_items();
                     $total_num_alloc += $num_allocated;
                     $total_num_required += $num_required;
                 }
                 if ($total_num_alloc == $total_num_required) {
                     $status = "Behov dekket";
                 } else {
                     $status = "Udekket behov (" . ($total_num_required - $total_num_alloc) . ")";
                 }
             } else {
                 $status = "Ingen registerte behov";
             }
             $activity_arr = $activity->serialize();
             $activity_arr['status'] = $status;
             $href = self::link(array('menuaction' => 'logistic.uiactivity.view', 'id' => $activity_arr['id']));
             $activity_arr['id_link'] = "<a href=\"{$href}\">" . $activity_arr['id'] . "</a>";
             $activity_arr['name'] = "<a href=\"{$href}\">" . $activity_arr['name'] . "</a>";
             $rows[] = $activity_arr;
         }
     }
     // ... add result data
     $result_data = array('results' => $rows);
     $result_data['total_records'] = $object_count;
     $result_data['start'] = $params['start'];
     $result_data['sort'] = $params['sort'];
     $result_data['dir'] = $params['dir'];
     $editable = phpgw::get_var('editable') == 'true' ? true : false;
     if (!$export) {
         //Add action column to each row in result table
         /*
         				array_walk(
         								$result_data['results'],
         								array($this, '_add_links'),
         								"logistic.uiactivity.view"
         				);
         */
     }
     return $this->yui_results($result_data);
 }
コード例 #30
0
 function read($data)
 {
     $start = isset($data['start']) && $data['start'] ? (int) $data['start'] : 0;
     $status_id = isset($data['status_id']) && $data['status_id'] ? $data['status_id'] : 'O';
     //O='Open'
     $user_id = isset($data['user_id']) && $data['user_id'] ? (int) $data['user_id'] : 0;
     $reported_by = isset($data['reported_by']) && $data['reported_by'] ? (int) $data['reported_by'] : 0;
     $query = isset($data['query']) ? $data['query'] : '';
     $sort = isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
     $order = isset($data['order']) ? $data['order'] : '';
     $cat_id = isset($data['cat_id']) && $data['cat_id'] ? (int) $data['cat_id'] : 0;
     $district_id = isset($data['district_id']) && $data['district_id'] ? (int) $data['district_id'] : 0;
     $part_of_town_id = isset($data['part_of_town_id']) && $data['part_of_town_id'] ? (int) $data['part_of_town_id'] : 0;
     $allrows = isset($data['allrows']) ? $data['allrows'] : '';
     $start_date = isset($data['start_date']) && $data['start_date'] ? (int) $data['start_date'] : 0;
     $end_date = isset($data['end_date']) && $data['end_date'] ? (int) $data['end_date'] : 0;
     $external = isset($data['external']) ? $data['external'] : '';
     $dry_run = isset($data['dry_run']) ? $data['dry_run'] : '';
     $new = isset($data['new']) ? $data['new'] : '';
     $location_code = isset($data['location_code']) ? $data['location_code'] : '';
     $p_num = isset($data['p_num']) ? $data['p_num'] : '';
     $vendor_id = isset($data['vendor_id']) && $data['vendor_id'] ? (int) $data['vendor_id'] : 0;
     $ecodimb = isset($data['ecodimb']) && $data['ecodimb'] ? (int) $data['ecodimb'] : 0;
     $b_account = isset($data['b_account']) && $data['b_account'] ? $data['b_account'] : '';
     $building_part = isset($data['building_part']) && $data['building_part'] ? $data['building_part'] : '';
     $branch_id = isset($data['branch_id']) && $data['branch_id'] ? (int) $data['branch_id'] : 0;
     $order_dim1 = isset($data['order_dim1']) && $data['order_dim1'] ? (int) $data['order_dim1'] : 0;
     $custom_filtermethod = isset($data['custom_filtermethod']) && $data['custom_filtermethod'] ? (array) $data['custom_filtermethod'] : array();
     $result_order_field = '';
     if ($order) {
         if ($order == 'assignedto') {
             $result_order_field = ',account_lastname';
             $order_join = "LEFT OUTER JOIN phpgw_accounts ON fm_tts_tickets.assignedto=phpgw_accounts.account_id";
             $order = 'account_lastname';
         } else {
             if ($order == 'user') {
                 $result_order_field = ',account_lastname';
                 $order_join = "LEFT OUTER JOIN phpgw_accounts ON fm_tts_tickets.user_id=phpgw_accounts.account_id";
                 $order = 'account_lastname';
             } else {
                 $order_join = '';
             }
         }
         $ordermethod = " ORDER BY {$order} {$sort}";
     } else {
         $ordermethod = ' ORDER BY fm_tts_tickets.id DESC';
     }
     $filtermethod = '';
     $where = 'WHERE';
     $GLOBALS['phpgw']->config->read();
     if (!isset($GLOBALS['phpgw']->config->config_data['bypass_acl_at_tickets']) || !$GLOBALS['phpgw']->config->config_data['bypass_acl_at_tickets']) {
         $this->grants = $GLOBALS['phpgw']->session->appsession('grants_ticket', 'property');
         if (!$this->grants) {
             $GLOBALS['phpgw']->acl->set_account_id($this->account);
             $this->grants = $GLOBALS['phpgw']->acl->get_grants('property', '.ticket');
             $GLOBALS['phpgw']->session->appsession('grants_ticket', 'property', $this->grants);
         }
         $public_user_list = array();
         if (isset($GLOBALS['phpgw']->config->config_data['acl_at_tts_category']) && $GLOBALS['phpgw']->config->config_data['acl_at_tts_category']) {
             $categories = $GLOBALS['phpgw']->locations->get_subs('property', '.ticket.category');
             $category_grants = array();
             foreach ($categories as $location) {
                 $category_grants = array_merge($category_grants, $GLOBALS['phpgw']->acl->get_grants('property', $location));
             }
             foreach ($category_grants as $user => $right) {
                 $public_user_list[] = $user;
             }
         }
         if (isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location']) {
             $access_location = execMethod('property.socommon.get_location_list', PHPGW_ACL_READ);
             if ($access_location) {
                 $filtermethod .= " {$where} fm_tts_tickets.loc1 in ('" . implode("','", $access_location) . "')";
                 $where = 'AND';
             }
         }
         if (is_array($this->grants)) {
             $grants =& $this->grants;
             foreach ($grants as $user => $right) {
                 $public_user_list[] = $user;
             }
         }
         if ($public_user_list) {
             $public_user_list = array_unique($public_user_list);
             reset($public_user_list);
             $filtermethod .= " {$where} ( fm_tts_tickets.user_id IN(" . implode(',', $public_user_list) . "))";
             $where = 'AND';
         }
     }
     if ($tenant_id = $GLOBALS['phpgw']->session->appsession('tenant_id', 'property')) {
         $filtermethod .= $where . ' fm_tts_tickets.tenant_id=' . $tenant_id;
         $where = 'AND';
     }
     if ($status_id == 'X') {
         $closed = '';
         $this->db->query('SELECT * from fm_tts_status', __LINE__, __FILE__);
         while ($this->db->next_record()) {
             if ($this->db->f('closed')) {
                 $closed .= " OR fm_tts_tickets.status = 'C" . $this->db->f('id') . "'";
             }
         }
         $filtermethod .= " {$where} ( (fm_tts_tickets.status='X'{$closed})";
         $where = 'AND';
         //				$filtermethod .= " $where ( fm_tts_tickets.status='X'";
         //				$where = 'AND';
     } else {
         if ($status_id == 'O2') {
             $filtermethod .= " {$where} ( fm_tts_tickets.status='O'";
             $where = 'AND';
         } else {
             if ($status_id == 'O') {
                 $open = '';
                 $this->db->query('SELECT * from fm_tts_status', __LINE__, __FILE__);
                 while ($this->db->next_record()) {
                     if (!$this->db->f('closed')) {
                         $open .= " OR fm_tts_tickets.status = 'C" . $this->db->f('id') . "'";
                     }
                 }
                 $filtermethod .= " {$where} ( (fm_tts_tickets.status='O'{$open})";
                 $where = 'AND';
             } else {
                 if ($status_id == 'all') {
                     $filtermethod .= "{$where} (1=1";
                     //nothing
                     $where = 'AND';
                 } else {
                     if (is_array($status_id) && count($status_id)) {
                         $or = '';
                         $filtermethod .= "{$where} ((";
                         foreach ($status_id as $value) {
                             if ($value) {
                                 $filtermethod .= "{$or} fm_tts_tickets.status = '{$value}'";
                                 $or = ' OR';
                             }
                         }
                         $filtermethod .= ')';
                         $where = 'AND';
                     } else {
                         $filtermethod .= " {$where} (fm_tts_tickets.status='{$status_id}'";
                         $where = 'AND';
                     }
                 }
             }
         }
     }
     if ($new) {
         $filtermethod .= " OR fm_tts_views.id IS NULL )";
     } else {
         $filtermethod .= ')';
     }
     if ($cat_id > 0) {
         $filtermethod .= " {$where} cat_id=" . (int) $cat_id;
         $where = 'AND';
     }
     if ($vendor_id > 0) {
         $filtermethod .= " {$where} vendor_id=" . (int) $vendor_id;
         $where = 'AND';
     }
     if ($ecodimb > 0) {
         $filtermethod .= " {$where} ecodimb=" . (int) $ecodimb;
         $where = 'AND';
     }
     if ($b_account > 0) {
         $filtermethod .= " {$where} b_account_id='{$b_account}'";
         $where = 'AND';
     }
     if ($building_part) {
         $filtermethod .= " {$where} building_part='{$building_part}'";
         $where = 'AND';
     }
     if ($branch_id > 0) {
         $filtermethod .= " {$where} branch_id=" . (int) $branch_id;
         $where = 'AND';
     }
     if ($order_dim1 > 0) {
         $filtermethod .= " {$where} order_dim1=" . (int) $order_dim1;
         $where = 'AND';
     }
     if ($user_id > 0) {
         $filtermethod .= " {$where} (assignedto={$user_id}";
         $where = 'AND';
         if (!($membership = $GLOBALS['phpgw']->accounts->membership($user_id))) {
             $membership = array(-1 => 0);
         }
         $filtermethod .= ' OR (assignedto IS NULL AND group_id IN (' . implode(',', array_keys($membership)) . ')))';
     }
     if ($user_id < 0) {
         $filtermethod .= " {$where} fm_tts_tickets.user_id=" . (int) abs($user_id);
         $where = 'AND';
     }
     if ($reported_by > 0) {
         $filtermethod .= " {$where} fm_tts_tickets.user_id=" . (int) $reported_by;
         $where = 'AND';
     }
     if ($district_id > 0) {
         $filtermethod .= " {$where}  district_id=" . (int) $district_id;
         $where = 'AND';
     }
     if ($part_of_town_id > 0) {
         $filtermethod .= " {$where} fm_part_of_town.part_of_town_id= " . (int) $part_of_town_id;
         $where = 'AND';
     }
     $actual_cost_field = 'fm_tts_tickets.actual_cost';
     $actual_cost_group_field = ',fm_tts_tickets.actual_cost';
     $budget_field = 'fm_tts_tickets.budget';
     $budget_group_field = ',fm_tts_tickets.budget';
     $date_join = '';
     $date_budget_join = '';
     if ($start_date) {
         $order_add = $GLOBALS['phpgw']->acl->check('.ticket.order', PHPGW_ACL_ADD, 'property');
         $order_edit = $GLOBALS['phpgw']->acl->check('.ticket.order', PHPGW_ACL_EDIT, 'property');
         $_end_date = $end_date + 3600 * 16 + phpgwapi_datetime::user_timezone();
         $_start_date = $start_date - 3600 * 8 + phpgwapi_datetime::user_timezone();
         $filtermethod .= " {$where} (fm_tts_tickets.modified_date >= {$_start_date} AND fm_tts_tickets.modified_date <= {$_end_date} ";
         if ($order_add || $order_edit) {
             $end_period = date('Ym', $end_date);
             $start_period = date('Ym', $start_date);
             $filtermethod .= " OR (fm_tts_payments.period >= {$start_period} AND fm_tts_payments.period <= {$end_period})";
             $date_join = "LEFT JOIN fm_tts_payments ON ( fm_tts_tickets.id=fm_tts_payments.ticket_id AND fm_tts_payments.period >= {$start_period} AND fm_tts_payments.period <= {$end_period} )";
             $actual_cost_field = 'SUM(fm_tts_payments.amount) AS actual_cost';
             $actual_cost_group_field = '';
             $start_budget_period = date('Y', $end_date) . '00';
             $end_budget_period = date('Y', $start_date) . '13';
             $filtermethod .= " OR (fm_tts_budget.period >= {$start_budget_period} AND fm_tts_budget.period <= {$end_budget_period}))";
             $date_budget_join = "LEFT JOIN fm_tts_budget ON ( fm_tts_tickets.id=fm_tts_budget.ticket_id AND fm_tts_budget.period >= {$start_budget_period} AND fm_tts_budget.period <= {$end_budget_period} )";
             $budget_field = 'SUM(fm_tts_budget.amount) AS budget';
             $budget_group_field = '';
         } else {
             $filtermethod .= ')';
         }
         $where = 'AND';
     }
     if ($location_code) {
         $filtermethod .= " {$where} fm_tts_tickets.location_code {$this->like} '{$location_code}%'";
         $where = 'AND';
     }
     foreach ($custom_filtermethod as $custom_filter_key => $custom_filter_value) {
         $filtermethod .= " {$where} fm_tts_tickets.{$custom_filter_key} = '{$custom_filter_value}'";
         $where = 'AND';
     }
     $location_id = $GLOBALS['phpgw']->locations->get_id('property', '.ticket');
     $querymethod = '';
     if ($query) {
         $query = $this->db->db_addslashes($query);
         $querymethod = " {$where} ((subject {$this->like} '%{$query}%'" . " OR address {$this->like} '%{$query}%' " . " OR fm_location1.loc1_name {$this->like} '%{$query}%'" . " OR fm_tts_tickets.location_code {$this->like} '%{$query}%'";
         if (ctype_digit($query)) {
             $querymethod .= " OR fm_tts_tickets.order_id =" . (int) $query . " OR fm_tts_tickets.id =" . (int) $query . ')';
         } else {
             $querymethod .= ')';
         }
         $query = str_replace(",", '.', $query);
         if (stristr($query, '.')) {
             if (!$p_num) {
                 $query = explode(".", $query);
                 $querymethod .= " OR (fm_tts_tickets.loc1='{$query[0]}' AND fm_tts_tickets.loc4='{$query[1]}')";
             } else {
                 $query = explode(".", $query);
                 $querymethod = " {$where} (fm_tts_tickets.p_entity_id='" . (int) $query[1] . "' AND fm_tts_tickets.p_cat_id='" . (int) $query[2] . "' AND fm_tts_tickets.p_num='{$query[3]}')";
             }
         }
         $custom_filter = $this->custom->get_custom_filter($location_id, 'fm_tts_tickets', $criteria_id = '', $query);
         if ($custom_filter['querymethod']) {
             $_where = $where == 'AND' ? 'OR' : 'WHERE';
             $querymethod .= " {$_where} (" . implode(' OR ', $custom_filter['querymethod']) . ')';
         } else {
             if (isset($custom_filter['joinmethod_datatype']) && $custom_filter['joinmethod_datatype']) {
                 $querymethod = '';
             }
         }
         if ($querymethod) {
             $querymethod .= ')';
         }
     }
     $return_fields = "fm_tts_tickets.id,fm_tts_tickets.assignedto,fm_tts_tickets.status,fm_tts_tickets.user_id," . "fm_tts_tickets.subject,fm_tts_tickets.address,fm_tts_tickets.location_code,fm_tts_tickets.priority,fm_tts_tickets.cat_id,fm_tts_tickets.group_id," . "fm_tts_tickets.entry_date,fm_tts_tickets.modified_date,fm_tts_tickets.finnish_date,fm_tts_tickets.finnish_date2,fm_tts_tickets.order_id,fm_tts_tickets.vendor_id," . "fm_tts_tickets.billable_hours,fm_district.descr as district,fm_tts_views.id as view,fm_location1.loc1_name,fm_tts_tickets.ecodimb,fm_tts_tickets.order_dim1 {$result_order_field}";
     $custom_cols = $this->custom->find('property', '.ticket', 0, '', 'ASC', 'attrib_sort', true, true);
     foreach ($custom_cols as $custom_col) {
         $return_fields .= ",fm_tts_tickets.{$custom_col['column_name']}";
     }
     $sql = "SELECT DISTINCT {$return_fields},{$budget_field},{$actual_cost_field} FROM fm_tts_tickets" . " {$this->left_join} fm_location1 ON fm_tts_tickets.loc1=fm_location1.loc1" . " {$this->left_join} fm_part_of_town ON fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id" . " {$this->left_join} fm_district ON fm_district.id = fm_part_of_town.district_id" . " {$order_join}{$date_join}{$date_budget_join}" . " LEFT OUTER JOIN fm_tts_views ON (fm_tts_tickets.id = fm_tts_views.id AND fm_tts_views.account_id='{$this->account}')";
     if (isset($custom_filter['joinmethod_datatype']) && $custom_filter['joinmethod_datatype']) {
         foreach ($custom_filter['joinmethod_datatype'] as $_joinmethod) {
             $sql .= $_joinmethod;
         }
     }
     $group_fields = str_ireplace(array('fm_district.descr as district', 'fm_tts_views.id as view'), array('fm_district.descr', 'fm_tts_views.id'), $return_fields);
     $sql .= " {$filtermethod} {$querymethod} GROUP BY {$group_fields}{$budget_group_field}{$actual_cost_group_field}";
     $sql_cnt = "SELECT DISTINCT {$budget_field},{$actual_cost_field}, fm_tts_tickets.id FROM fm_tts_tickets" . " {$this->left_join} fm_location1 ON fm_tts_tickets.loc1=fm_location1.loc1" . " {$this->left_join} fm_part_of_town ON fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id" . " {$this->left_join} fm_district ON fm_district.id = fm_part_of_town.district_id" . " {$order_join}{$date_join}{$date_budget_join}" . " LEFT OUTER JOIN fm_tts_views ON (fm_tts_tickets.id = fm_tts_views.id AND fm_tts_views.account_id='{$this->account}')";
     if (isset($custom_filter['joinmethod_datatype']) && $custom_filter['joinmethod_datatype']) {
         foreach ($custom_filter['joinmethod_datatype'] as $_joinmethod) {
             $sql_cnt .= $_joinmethod;
         }
     }
     $sql_cnt .= " {$filtermethod} {$querymethod}";
     //_debug_array($sql);
     $cache_info = phpgwapi_cache::session_get('property', 'tts_listing_metadata');
     if (!isset($cache_info['sql_hash']) || $cache_info['sql_hash'] != md5($sql_cnt)) {
         $cache_info = array();
     }
     if (!$cache_info) {
         $sql2 = "SELECT count(*) as cnt, sum(budget) as sum_budget, sum(actual_cost) as sum_actual_cost FROM ({$sql_cnt} GROUP BY fm_tts_tickets.id, fm_tts_tickets.budget {$actual_cost_group_field}) as t";
         $this->db->query($sql2, __LINE__, __FILE__);
         $this->db->next_record();
         unset($sql2);
         $cache_info = array('total_records' => $this->db->f('cnt'), 'sum_budget' => $this->db->f('sum_budget'), 'sum_actual_cost' => $this->db->f('sum_actual_cost'), 'sql_hash' => md5($sql_cnt));
         $custom_status = $this->get_custom_status();
         $closed_status = array('X');
         foreach ($custom_status as $custom) {
             if ($custom['closed']) {
                 $closed_status[] = "C{$custom['id']}";
             }
         }
         $filter_closed = " AND fm_tts_tickets.status NOT IN ('" . implode("','", $closed_status) . "')";
         $sql2 = "SELECT (SUM(budget) - SUM(actual_cost)) as sum_difference FROM ({$sql_cnt} {$filter_closed} GROUP BY fm_tts_tickets.id, fm_tts_tickets.budget {$actual_cost_group_field}) as t";
         $this->db->query($sql2, __LINE__, __FILE__);
         $this->db->next_record();
         unset($sql2);
         $cache_info['sum_difference'] = (double) $this->db->f('sum_difference');
         phpgwapi_cache::session_set('property', 'tts_listing_metadata', $cache_info);
     }
     $this->total_records = (int) $cache_info['total_records'];
     $this->sum_budget = (int) $cache_info['sum_budget'];
     $this->sum_actual_cost = (int) $cache_info['sum_actual_cost'];
     $this->sum_difference = (double) $cache_info['sum_difference'];
     $tickets = array();
     if (!$dry_run) {
         if (!$allrows) {
             $this->db->limit_query($sql . $ordermethod, $start, __LINE__, __FILE__);
         } else {
             $_fetch_single = false;
             /*
             					if($this->total_records > 200)
             					{
             						$_fetch_single = true;
             					}
             					else
             					{
             						$_fetch_single = false;
             					}
             */
             $this->db->query($sql . $ordermethod, __LINE__, __FILE__, false, $_fetch_single);
             unset($_fetch_single);
         }
         $i = 0;
         while ($this->db->next_record()) {
             $tickets[] = array('id' => (int) $this->db->f('id'), 'subject' => $this->db->f('subject', true), 'loc1_name' => $this->db->f('loc1_name', true), 'location_code' => $this->db->f('location_code'), 'district' => $this->db->f('district', true), 'user_id' => $this->db->f('user_id'), 'address' => $this->db->f('address', true), 'assignedto' => $this->db->f('assignedto'), 'status' => $this->db->f('status'), 'priority' => $this->db->f('priority'), 'cat_id' => $this->db->f('cat_id'), 'group_id' => $this->db->f('group_id'), 'entry_date' => $this->db->f('entry_date'), 'modified_date' => $this->db->f('modified_date'), 'finnish_date' => $this->db->f('finnish_date'), 'finnish_date2' => $this->db->f('finnish_date2'), 'order_id' => $this->db->f('order_id'), 'vendor_id' => $this->db->f('vendor_id'), 'actual_cost' => $this->db->f('actual_cost'), 'estimate' => $this->db->f('budget'), 'new_ticket' => $this->db->f('view') ? false : true, 'billable_hours' => $this->db->f('billable_hours'), 'ecodimb' => $this->db->f('ecodimb'), 'order_dim1' => $this->db->f('order_dim1'));
             foreach ($custom_cols as $custom_col) {
                 if ($custom_value = $this->db->f($custom_col['column_name'], true)) {
                     $custom_value = $this->custom->get_translated_value(array('value' => $custom_value, 'attrib_id' => $custom_col['id'], 'datatype' => $custom_col['datatype']), $location_id);
                 }
                 $tickets[$i][$custom_col['column_name']] = $custom_value;
             }
             $i++;
         }
     }
     $this->db->set_fetch_single(false);
     return $tickets;
 }