fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [9951] Tilbakestilling av formatering


From: Torstein
Subject: [Fmsystem-commits] [9951] Tilbakestilling av formatering
Date: Fri, 31 Aug 2012 10:14:13 +0000

Revision: 9951
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9951
Author:   vator
Date:     2012-08-31 10:14:12 +0000 (Fri, 31 Aug 2012)
Log Message:
-----------
Tilbakestilling av formatering

Modified Paths:
--------------
    trunk/controller/inc/class.cat_hooks.inc.php
    trunk/controller/inc/class.menu.inc.php
    trunk/controller/inc/class.socase.inc.php
    trunk/controller/inc/class.socheck_item.inc.php
    trunk/controller/inc/class.socheck_list.inc.php
    trunk/controller/inc/class.socontrol.inc.php
    trunk/controller/inc/class.socontrol_group.inc.php
    trunk/controller/inc/class.socontrol_group_list.inc.php
    trunk/controller/inc/class.socontrol_item.inc.php
    trunk/controller/inc/class.socontrol_item_list.inc.php
    trunk/controller/inc/class.socontrol_item_option.inc.php
    trunk/controller/inc/class.sodocument.inc.php
    trunk/controller/inc/class.soprocedure.inc.php
    trunk/controller/inc/class.uicalendar.inc.php
    trunk/controller/inc/class.uicase.inc.php
    trunk/controller/inc/class.uicheck_list.inc.php
    trunk/controller/inc/class.uicheck_list_for_component.inc.php
    trunk/controller/inc/class.uicontrol.inc.php
    trunk/controller/inc/class.uicontrol_group.inc.php
    trunk/controller/inc/class.uicontrol_group_component.inc.php
    trunk/controller/inc/class.uicontrol_item.inc.php
    trunk/controller/inc/class.uicontrol_location.inc.php
    trunk/controller/inc/class.uidocument.inc.php
    trunk/controller/inc/class.uiprocedure.inc.php
    trunk/controller/inc/class.uitest.inc.php
    trunk/controller/inc/hook_home.inc.php
    trunk/controller/templates/base/add_component_to_control.xsl
    trunk/controller/templates/base/add_component_to_control_group.xsl
    trunk/controller/templates/base/app_data.xsl
    trunk/controller/templates/base/calendar/calendar_filters.xsl
    trunk/controller/templates/base/calendar/check_list_status_manager.xsl
    trunk/controller/templates/base/calendar/icon_color_map.xsl
    trunk/controller/templates/base/calendar/nav_calendar_month.xsl
    trunk/controller/templates/base/calendar/nav_calendar_year.xsl
    trunk/controller/templates/base/calendar/select_buildings_on_property.xsl
    trunk/controller/templates/base/calendar/select_my_locations.xsl
    trunk/controller/templates/base/calendar/view_calendar_month.xsl
    
trunk/controller/templates/base/calendar/view_calendar_month_for_locations.xsl
    trunk/controller/templates/base/calendar/view_calendar_year.xsl
    
trunk/controller/templates/base/calendar/view_calendar_year_for_locations.xsl
    trunk/controller/templates/base/case/create_case_message.xsl
    trunk/controller/templates/base/case/view_case_message.xsl
    trunk/controller/templates/base/check_list/add_case.xsl
    trunk/controller/templates/base/check_list/add_check_list.xsl
    trunk/controller/templates/base/check_list/cases_tab_menu.xsl
    trunk/controller/templates/base/check_list/check_list_tab_menu.xsl
    trunk/controller/templates/base/check_list/edit_check_list.xsl
    trunk/controller/templates/base/check_list/print_check_list.xsl
    trunk/controller/templates/base/check_list/view_cases_for_check_list.xsl
    trunk/controller/templates/base/check_list/view_check_list.xsl
    trunk/controller/templates/base/check_list/view_check_lists.xsl
    trunk/controller/templates/base/check_list/view_closed_cases.xsl
    trunk/controller/templates/base/check_list/view_control_details.xsl
    trunk/controller/templates/base/check_list/view_control_info.xsl
    trunk/controller/templates/base/check_list/view_control_items.xsl
    trunk/controller/templates/base/check_list/view_open_cases.xsl
    trunk/controller/templates/base/common.xsl
    trunk/controller/templates/base/component.xsl
    trunk/controller/templates/base/config.tpl
    trunk/controller/templates/base/control/control.xsl
    trunk/controller/templates/base/control/control_tabs.xsl
    trunk/controller/templates/base/control/controls_datatable.xsl
    trunk/controller/templates/base/control_component.xsl
    trunk/controller/templates/base/control_component_tabs.xsl
    trunk/controller/templates/base/control_group/control_group.xsl
    trunk/controller/templates/base/control_group/control_group_items.xsl
    trunk/controller/templates/base/control_group/control_group_tabs.xsl
    trunk/controller/templates/base/control_group/control_groups.xsl
    trunk/controller/templates/base/control_group/control_groups_datatable.xsl
    trunk/controller/templates/base/control_group_component_tabs.xsl
    trunk/controller/templates/base/control_item/choose_control_items.xsl
    trunk/controller/templates/base/control_item/control_item.xsl
    trunk/controller/templates/base/control_item/control_item_option.xsl
    trunk/controller/templates/base/control_item/control_items_datatable.xsl
    trunk/controller/templates/base/control_item/sort_check_list.xsl
    trunk/controller/templates/base/control_item/view_control_item_list.xsl
    trunk/controller/templates/base/control_location/control_location_tabs.xsl
    trunk/controller/templates/base/control_location/control_locations.xsl
    
trunk/controller/templates/base/control_location/register_control_to_component.xsl
    
trunk/controller/templates/base/control_location/register_control_to_location.xsl
    
trunk/controller/templates/base/control_location/view_locations_for_control.xsl
    trunk/controller/templates/base/css/base.css
    trunk/controller/templates/base/datatable.xsl
    trunk/controller/templates/base/procedure/print_procedure.xsl
    trunk/controller/templates/base/procedure/procedure_documents.xsl
    trunk/controller/templates/base/procedure/procedure_item.xsl
    trunk/controller/templates/base/procedure/procedure_tabs.xsl
    trunk/controller/templates/base/procedure/procedures_datatable.xsl
    trunk/controller/templates/base/procedure/view_procedures_for_control.xsl
    trunk/controller/templates/base/view_component_for_control.xsl
    trunk/controller/templates/base/view_component_for_control_group.xsl
    trunk/controller/templates/base/yui_booking_i18n.xsl

Modified: trunk/controller/inc/class.cat_hooks.inc.php
===================================================================
--- trunk/controller/inc/class.cat_hooks.inc.php        2012-08-31 10:09:39 UTC 
(rev 9950)
+++ trunk/controller/inc/class.cat_hooks.inc.php        2012-08-31 10:14:12 UTC 
(rev 9951)
@@ -1,112 +1,119 @@
 <?php
+       /**
+       * phpGroupWare - controller: a part of a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package controller
+       * @subpackage entity
+       * @version $Id$
+       */
 
-/**
- * phpGroupWare - controller: a part of a Facilities Management System.
- *
- * @author Sigurd Nes <address@hidden>
- * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
- * This file is part of phpGroupWare.
- *
- * phpGroupWare is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * phpGroupWare is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with phpGroupWare; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
- * @package controller
- * @subpackage entity
- * @version $Id$
- */
+       /**
+       * hook management for categories
+       * @package controller
+       */
+       class controller_cat_hooks
+       {
+               protected $soresponsible;
+               protected $_db;
 
-/**
- * hook management for categories
- * @package controller
- */
-class controller_cat_hooks {
+               function __construct()
+               {
+                       $this->_db                              =& 
$GLOBALS['phpgw']->db;
+                       $this->soresponsible    = 
CreateObject('property.soresponsible');
+                       $this->soresponsible->appname = 'controller';
+               }               
+               /**
+                * Handle a new category being added, create location to hold 
ACL-data
+                */
+               function cat_add($data)
+               {
+                       if ( isset($data['cat_owner']) && $data['cat_owner'] != 
-1 )
+                       {
+                               return false; //nothing needed to be done, we 
only care about global cats
+                       }
 
-  protected $soresponsible;
-  protected $_db;
+                       $location = '';
+                       if($data['location_id'])
+                       {
+                               $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
+                               $location = $location_info['location'];
+                       }
+                       
$GLOBALS['phpgw']->locations->add("{$location}.category.{$data['cat_id']}", 
$data['cat_name'], 'controller');
+                       
+/*
+                       $this->soresponsible->add_type(array
+                               (
+                                       'name'  => $data['cat_name'],
+                                       'descr' => $data['cat_name'],
+                                       'location'      => 
"{$location}.category.{$data['cat_id']}",
+                                       'cat_id'        => $data['cat_id'],
+                                       'active'        => true
+                               )
+                       );
+*/
+               }
 
-  function __construct() {
-    $this->_db = & $GLOBALS['phpgw']->db;
-    $this->soresponsible = CreateObject('property.soresponsible');
-    $this->soresponsible->appname = 'controller';
-  }
-
-  /**
-   * Handle a new category being added, create location to hold ACL-data
-   */
-  function cat_add($data) {
-    if (isset($data['cat_owner']) && $data['cat_owner'] != -1) {
-      return false; //nothing needed to be done, we only care about global cats
-    }
-
-    $location = '';
-    if ($data['location_id']) {
-      $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
-      $location = $location_info['location'];
-    }
-    
$GLOBALS['phpgw']->locations->add("{$location}.category.{$data['cat_id']}", 
$data['cat_name'], 'controller');
-
-    /*
-      $this->soresponsible->add_type(array
-      (
-      'name'   => $data['cat_name'],
-      'descr'  => $data['cat_name'],
-      'location'       => "{$location}.category.{$data['cat_id']}",
-      'cat_id' => $data['cat_id'],
-      'active' => true
-      )
-      );
-     */
-  }
-
-  /**
-   * Handle a category being deleted, remove the location 
-   */
-  function cat_delete($data) {
-    if (isset($data['cat_owner']) && $data['cat_owner'] != -1) {
-      return false; //nothing needed to be done, we only care about global cats
-    }
-    if ($data['location_id']) {
-      $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
-      $location = "{$location_info['location']}.category.{$data['cat_id']}";
-      $GLOBALS['phpgw']->locations->delete('controller', $location, false);
+               /**
+                * Handle a category being deleted, remove the location 
+                */
+               function cat_delete($data)
+               {
+                       if ( isset($data['cat_owner']) && $data['cat_owner'] != 
-1 )
+                       {
+                               return false; //nothing needed to be done, we 
only care about global cats
+                       }
+                       if($data['location_id'])
+                       {
+                               $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
+                               $location = 
"{$location_info['location']}.category.{$data['cat_id']}";
+                               
$GLOBALS['phpgw']->locations->delete('controller', $location, false);
 //                             $this->_db->query("DELETE FROM 
fm_responsibility WHERE cat_id = " . (int) $data['cat_id'], __LINE__, __FILE__);
-    }
-  }
+                       }
+               }
 
-  /**
-   * Handle a category being edited, update the location info
-   */
-  function cat_edit($data) {
-    if (isset($data['cat_owner']) && $data['cat_owner'] != -1) {
-      return false; //nothing needed to be done, we only care about global cats
-    }
+               /**
+                * Handle a category being edited, update the location info
+                */
+               function cat_edit($data)
+               {
+                       if ( isset($data['cat_owner']) && $data['cat_owner'] != 
-1 )
+                       {
+                               return false; //nothing needed to be done, we 
only care about global cats
+                       }
 
-    if ($data['location_id']) {
-      $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
-      $location = "{$location_info['location']}.category.{$data['cat_id']}";
-      $GLOBALS['phpgw']->locations->update_description($location, 
$data['cat_name'], 'controller');
+                       if($data['location_id'])
+                       {
+                               $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
+                               $location = 
"{$location_info['location']}.category.{$data['cat_id']}";
+                               
$GLOBALS['phpgw']->locations->update_description($location, $data['cat_name'], 
'controller');
 
-      /*
-        $value_set['name']             = 
$this->_db->db_addslashes($data['cat_name']);
-        $value_set['descr']            = $value_set['name'];
+/*
+                               $value_set['name']              = 
$this->_db->db_addslashes($data['cat_name']);
+                               $value_set['descr']             = 
$value_set['name'];
 
-        $value_set     = $this->_db->validate_update($value_set);
-        $this->_db->query("UPDATE fm_responsibility SET $value_set WHERE 
cat_id = " . (int) $data['cat_id'], __LINE__, __FILE__);
-       */
-    }
-  }
-
-}
+                               $value_set      = 
$this->_db->validate_update($value_set);
+                               $this->_db->query("UPDATE fm_responsibility SET 
$value_set WHERE cat_id = " . (int) $data['cat_id'], __LINE__, __FILE__);
+*/
+                       }
+               }
+       }

Modified: trunk/controller/inc/class.menu.inc.php
===================================================================
--- trunk/controller/inc/class.menu.inc.php     2012-08-31 10:09:39 UTC (rev 
9950)
+++ trunk/controller/inc/class.menu.inc.php     2012-08-31 10:14:12 UTC (rev 
9951)
@@ -1,171 +1,176 @@
 <?php
+       /**
+       * phpGroupWare - controller: a part of a Facilities Management System.
+       *
+       * @author Erik Holm-Larsen <address@hidden>
+       * @author Torstein Vadla <address@hidden>
+       * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
+       * @package property
+       * @subpackage controller
+       * @version $Id$
+       */
 
-/**
- * phpGroupWare - controller: a part of a Facilities Management System.
- *
- * @author Erik Holm-Larsen <address@hidden>
- * @author Torstein Vadla <address@hidden>
- * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
- * This file is part of phpGroupWare.
- *
- * phpGroupWare is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * phpGroupWare is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with phpGroupWare; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
- * @package property
- * @subpackage controller
- * @version $Id$
- */
+       class controller_menu
+       {
+               function get_menu()
+               {
+                       $incoming_app = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
'controller';
+                       $menus = array();
 
-class controller_menu {
+                       $menus['navbar'] = array
+                       (
+                               'controller' => array
+                               (
+                                       'text'  => lang('Controller'),
+                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uicontrol.control_list') ),
+                                       'image' => array('property', 
'location'),
+                                       'order' => 10,
+                                       'group' => 'office'
+                               )
+                       );
 
-  function get_menu() {
-    $incoming_app = $GLOBALS['phpgw_info']['flags']['currentapp'];
-    $GLOBALS['phpgw_info']['flags']['currentapp'] = 'controller';
-    $menus = array();
+                       
if($GLOBALS['phpgw']->acl->check('.usertype.superuser',PHPGW_ACL_ADD,'controller'))
+                       {
+                               $menus['navigation'] =  array
+                               (
+                                       'control' => array
+                                       (
+                                               'text'  => lang('Control'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uicontrol.control_list') ),
+                                               'image' => array('property', 
'location_1'),
+                                               'children' => array(
+                                                                               
        'location_for_check_list' => array
+                                                                               
        (
+                                                                               
                'text'  => lang('location_connections'),
+                                                                               
                'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 'controller.uicontrol_location.index') ),
+                                                                               
                'image' => array('property', 'location_1')
+                                                                               
        ),
+                                                                               
        'component_for_check_list' => array
+                                                                               
        (
+                                                                               
                'text'  => lang('component'),
+                                                                               
                'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 
'controller.uicontrol_location.register_control_to_component') ),
+                                                                               
                'image' => array('property', 'entity_1')
+                                                                               
        )
+                                                                               
)
+                                       ),
+                                       'control_item' => array
+                                       (
+                                               'text'  => lang('Control_item'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uicontrol_item.index') ),
+                                               'image' => array('property', 
'location_1')
+                                       ),
+                                       'control_group' => array
+                                       (
+                                               'text'  => 
lang('Control_group'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uicontrol_group.index') ),
+                                               'image' => array('property', 
'location_1'),
+                                               'children' => array(
+                                                                               
        'component_for_control_group' => array
+                                                                               
        (
+                                                                               
                'text'  => lang('component'),
+                                                                               
                'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 'controller.uicontrol_group_component.index') ),
+                                                                               
                'image' => array('property', 'entity_1')
+                                                                               
        )
+                                                                               
)
+                                       ),
+                                       'procedure' => array
+                                       (
+                                               'text'  => lang('Procedure'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uiprocedure.index') ),
+                                               'image' => array('property', 
'location_1'),
+                                       ),
+                                       'calendar_overview' => array
+                                       (
+                                               'text'  => 
lang('Calendar_overview'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=> 
'controller.uicalendar.view_calendar_for_year') ),
+                                               'image' => array('property', 
'location_1'),
+                                       )
+                               );
+                       }
+                       
+                       if ( $GLOBALS['phpgw']->acl->check('run', 
phpgwapi_acl::READ, 'admin')
+                               || $GLOBALS['phpgw']->acl->check('admin', 
phpgwapi_acl::ADD, 'controller'))
+                       {
+                               $menus['admin'] = array
+                               (
+                                       'index' => array
+                                       (
+                                               'text'  => 
lang('Configuration'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig.index', 'appname' => 'controller') )
+                                       ),
+                                       'acl'   => array
+                                       (
+                                               'text'  => lang('Configure 
Access Permissions'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl', 'acl_app' => 'controller') )
+                                       ),
+                                       'check_item_status'     => array
+                                       (
+                                               'text'  => lang('check item 
status'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'controller_check_item_status') )
+                                       ),
+                                       'control_cats'  => array
+                                       (
+                                               'text'  => lang('Control area'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uicategories.index', 'appname' => 'controller', 'location' => 
'.control', 'global_cats' => 'true', 'menu_selection' => 
'admin::controller::control_cats') )
+                                       ),
+                                       'role_at_location'      => array
+                                       (
+                                               'url'   =>      
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'property.uilocation.responsiblility_role', 'menu_selection' => 
'admin::controller::role_at_location') ),
+                                               'text'  =>      lang('role at 
location'),
+                                               'image' => array('property', 
'responsibility_role')
+                                       ),
+                                       'controller_document_types'     => array
+                                       (
+                                               'url'   =>      
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'controller.uidocument.document_types', 'menu_selection' => 
'admin::controller::controller_document_types') ),
+                                               'text'  =>      lang('Document 
types')
+                                       )
+                               );
+                       }
 
-    $menus['navbar'] = array
-        (
-        'controller' => array
-            (
-            'text' => lang('Controller'),
-            'url' => $GLOBALS['phpgw']->link('/index.php', array('menuaction' 
=> 'controller.uicontrol.control_list')),
-            'image' => array('property', 'location'),
-            'order' => 10,
-            'group' => 'office'
-        )
-    );
+                       if ( 
isset($GLOBALS['phpgw_info']['user']['apps']['preferences']) )
+                       {
+                               $menus['preferences'] = array
+                               (
+                                       // in case of userprefs - need a hook 
for 'settings'
 
-    if ($GLOBALS['phpgw']->acl->check('.usertype.superuser', PHPGW_ACL_ADD, 
'controller')) {
-      $menus['navigation'] = array(
-          'control' => array(
-              'text' => lang('Control'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicontrol.control_list')),
-              'image' => array('property', 'location_1'),
-              'children' => array(
-                  'location_for_check_list' => array
-                      (
-                      'text' => lang('location_connections'),
-                      'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicontrol_location.index')),
-                      'image' => array('property', 'location_1')
-                  ),
-                  'component_for_check_list' => array
-                      (
-                      'text' => lang('component'),
-                      'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 
'controller.uicontrol_location.register_control_to_component')),
-                      'image' => array('property', 'entity_1')
-                  )
-              )
-          ),
-          'control_item' => array
-              (
-              'text' => lang('Control_item'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicontrol_item.index')),
-              'image' => array('property', 'location_1')
-          ),
-          'control_group' => array
-              (
-              'text' => lang('Control_group'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicontrol_group.index')),
-              'image' => array('property', 'location_1'),
-              'children' => array(
-                  'component_for_control_group' => array
-                      (
-                      'text' => lang('component'),
-                      'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicontrol_group_component.index')),
-                      'image' => array('property', 'entity_1')
-                  )
-              )
-          ),
-          'procedure' => array
-              (
-              'text' => lang('Procedure'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uiprocedure.index')),
-              'image' => array('property', 'location_1'),
-          ),
-          'calendar_overview' => array
-              (
-              'text' => lang('Calendar_overview'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicalendar.view_calendar_for_year')),
-              'image' => array('property', 'location_1'),
-          )
-      );
-    }
+                                       array
+                                       (
+                                               'text'  => 
$GLOBALS['phpgw']->translation->translate('Preferences', array(), true),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/preferences/preferences.php', array('appname' => 
'controller', 'type'=> 'user') )
+                                       ),
 
-    if ($GLOBALS['phpgw']->acl->check('run', phpgwapi_acl::READ, 'admin')
-            || $GLOBALS['phpgw']->acl->check('admin', phpgwapi_acl::ADD, 
'controller')) {
-      $menus['admin'] = array
-          (
-          'index' => array
-              (
-              'text' => lang('Configuration'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'admin.uiconfig.index', 'appname' => 'controller'))
-          ),
-          'acl' => array
-              (
-              'text' => lang('Configure Access Permissions'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'preferences.uiadmin_acl.list_acl', 'acl_app' => 
'controller'))
-          ),
-          'check_item_status' => array
-              (
-              'text' => lang('check item status'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'property.uigeneric.index', 'type' => 
'controller_check_item_status'))
-          ),
-          'control_cats' => array
-              (
-              'text' => lang('Control area'),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'admin.uicategories.index', 'appname' => 'controller', 
'location' => '.control', 'global_cats' => 'true', 'menu_selection' => 
'admin::controller::control_cats'))
-          ),
-          'role_at_location' => array
-              (
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'property.uilocation.responsiblility_role', 
'menu_selection' => 'admin::controller::role_at_location')),
-              'text' => lang('role at location'),
-              'image' => array('property', 'responsibility_role')
-          ),
-          'controller_document_types' => array
-              (
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uidocument.document_types', 'menu_selection' 
=> 'admin::controller::controller_document_types')),
-              'text' => lang('Document types')
-          )
-      );
-    }
+                                       array
+                                       (
+                                               'text'  => 
$GLOBALS['phpgw']->translation->translate('Grant Access', array(), true),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'preferences.uiadmin_acl.aclprefs', 'acl_app'=> 'controller') )
+                                       )
+                               );
+                       }
 
-    if (isset($GLOBALS['phpgw_info']['user']['apps']['preferences'])) {
-      $menus['preferences'] = array
-          (
-          // in case of userprefs - need a hook for 'settings'
+                       //Nothing...
+                       //$menus['folders'] = 
phpgwapi_menu::get_categories('bergen');
 
-          array
-              (
-              'text' => 
$GLOBALS['phpgw']->translation->translate('Preferences', array(), true),
-              'url' => $GLOBALS['phpgw']->link('/preferences/preferences.php', 
array('appname' => 'controller', 'type' => 'user'))
-          ),
-          array
-              (
-              'text' => $GLOBALS['phpgw']->translation->translate('Grant 
Access', array(), true),
-              'url' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'preferences.uiadmin_acl.aclprefs', 'acl_app' => 
'controller'))
-          )
-      );
-    }
+                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
$incoming_app;
 
-    //Nothing...
-    //$menus['folders'] = phpgwapi_menu::get_categories('bergen');
-
-    $GLOBALS['phpgw_info']['flags']['currentapp'] = $incoming_app;
-
-    return $menus;
-  }
-
-}
+                       return $menus;
+               }
+       }

Modified: trunk/controller/inc/class.socase.inc.php
===================================================================
--- trunk/controller/inc/class.socase.inc.php   2012-08-31 10:09:39 UTC (rev 
9950)
+++ trunk/controller/inc/class.socase.inc.php   2012-08-31 10:14:12 UTC (rev 
9951)
@@ -1,219 +1,236 @@
 <?php
+       /**
+       * phpGroupWare - controller: a part of a Facilities Management System.
+       *
+       * @author Erink Holm-Larsen <address@hidden>
+       * @author Torstein Vadla <address@hidden>
+       * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
+       * @package property
+       * @subpackage controller
+       * @version $Id: class.socheck_item.inc.php 8535 2012-01-09 10:14:45Z 
vator $
+       */
 
-/**
- * phpGroupWare - controller: a part of a Facilities Management System.
- *
- * @author Erink Holm-Larsen <address@hidden>
- * @author Torstein Vadla <address@hidden>
- * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
- * This file is part of phpGroupWare.
- *
- * phpGroupWare is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * phpGroupWare is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with phpGroupWare; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
- * @package property
- * @subpackage controller
- * @version $Id: class.socheck_item.inc.php 8535 2012-01-09 10:14:45Z vator $
- */
-phpgw::import_class('controller.socommon');
+       phpgw::import_class('controller.socommon');
 
-include_class('controller', 'check_item_case', 'inc/model/');
+       include_class('controller', 'check_item_case', 'inc/model/');
 
-class controller_socase extends controller_socommon {
+       class controller_socase extends controller_socommon
+       {
+               protected static $so;
 
-  protected static $so;
+               /**
+                * Get a static reference to the storage object associated with 
this model object
+                *
+                * @return controller_socase the storage object
+                */
+               public static function get_instance()
+               {
+                       if (self::$so == null)
+                       {
+                               self::$so = CreateObject('controller.socase');
+                       }
+                       return self::$so;
+               }
 
-  /**
-   * Get a static reference to the storage object associated with this model 
object
-   *
-   * @return controller_socase the storage object
-   */
-  public static function get_instance() {
-    if (self::$so == null) {
-      self::$so = CreateObject('controller.socase');
-    }
-    return self::$so;
-  }
+               function get_query(string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean 
$return_count){}
 
-  function get_query(string $sort_field, boolean $ascending, string 
$search_for, string $search_type, array $filters, boolean $return_count) {}
+               function populate(int $object_id, &$object){}
 
-  function populate(int $object_id, &$object) {}
+               /**
+                * Get single case object from database  
+                * 
+                * @param       $case id id of case to be returned
+                * @return case object
+               */
+               public function get_single($case_id)
+               {
+                       $case_id = (int) $case_id;
+                       
+                       $sql = "SELECT * FROM controller_check_item_case "; 
+                       $sql .= "WHERE id = {$case_id}";
+                       
 
-  /**
-   * Get single case object from database  
-   * 
-   * @param    $case id id of case to be returned
-   * @return case object
-   */
-  public function get_single($case_id) {
-    $case_id = (int) $case_id;
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
 
-    $sql = "SELECT * FROM controller_check_item_case ";
-    $sql .= "WHERE id = {$case_id}";
+                       if($this->db->next_record())
+                       {
+                               $case = new 
controller_check_item_case($this->unmarshal($this->db->f('id'), 'int'));
+                               
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
+                               
$case->set_status($this->unmarshal($this->db->f('status'), 'int'));
+                               
$case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
+                               
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
+                               
$case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
+                               
$case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));   
+                               
$case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
+                               
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
+                               
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
+                               
$case->set_measurement($this->unmarshal($this->db->f('measurement'), 'string'));
+                                       
+                               return $case;
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+               
+               /**
+                * Get cases for message  
+                * 
+                * @param       $location_id location id
+                * @param       $location_item_id location item id
+                * @param $return_type return data as objects or as arrays
+                * @return array of case object represented as objects or arrays
+               */
+               public function get_cases_by_message($location_id, 
$location_item_id, $return_type = "return_object")
+               {
+                       $location_id            = (int) $location_id;
+                       $location_item_id       = (int) $location_item_id;
 
+                       $sql = "SELECT * FROM controller_check_item_case "; 
+                       $sql .= "WHERE location_id = {$location_id} AND 
location_item_id = {$location_item_id}";
 
-    $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+                       $this->db->query($sql);
 
-    if ($this->db->next_record()) {
-      $case = new 
controller_check_item_case($this->unmarshal($this->db->f('id'), 'int'));
-      $case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
-      $case->set_status($this->unmarshal($this->db->f('status'), 'int'));
-      $case->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-      
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
-      $case->set_descr($this->unmarshal($this->db->f('descr', true), 
'string'));
-      $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
-      $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 
'int'));
-      $case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
-      $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 
'int'));
-      $case->set_measurement($this->unmarshal($this->db->f('measurement'), 
'string'));
+                       while ($this->db->next_record())
+                       {
+                               $case = new 
controller_check_item_case($this->unmarshal($this->db->f('id'), 'int'));
+                               
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
+                               
$case->set_status($this->unmarshal($this->db->f('status'), 'int'));
+                               
$case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
+                               
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
+                               
$case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
+                               
$case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));   
+                               
$case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
+                               
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
+                               
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
+                               
$case->set_measurement($this->unmarshal($this->db->f('measurement'), 'string'));
+                               
+                               if($return_type == "return_object")
+                               {
+                                       $cases_array[] = $case;
+                               }
+                               else
+                               {
+                                       $cases_array[] = $case->toArray();
+                               }
+                       }
 
-      return $case;
-    } else {
-      return null;
-    }
-  }
+                       return $cases_array;
+               }
+               
+               /**
+                * Inserts a new case in database  
+                * 
+                * @param       $case to inserted
+                * @return true or false
+               */
+               function add(&$case)
+               {
+                       $cols = array(
+                                       'check_item_id',
+                                       'status',
+                                       'location_id',
+                                       'location_item_id',
+                                       'descr',
+                                       'user_id',
+                                       'entry_date',
+                                       'modified_date',
+                                       'modified_by',
+                                       'measurement',
+                       );
 
-  /**
-   * Get cases for message  
-   * 
-   * @param    $location_id location id
-   * @param    $location_item_id location item id
-   * @param $return_type return data as objects or as arrays
-   * @return array of case object represented as objects or arrays
-   */
-  public function get_cases_by_message($location_id, $location_item_id, 
$return_type = "return_object") {
-    $location_id = (int) $location_id;
-    $location_item_id = (int) $location_item_id;
+                       $values = array(
+                               $this->marshal($case->get_check_item_id(), 
'int'),
+                               $case->get_status(),
+                               $this->marshal($case->get_location_id(), 'int'),
+                               $this->marshal($case->get_location_item_id(), 
'int'),
+                               $this->marshal($case->get_descr(), 'string'),
+                               $this->marshal($case->get_user_id(), 'int'),
+                               $this->marshal($case->get_entry_date(), 'int'),
+                               $this->marshal($case->get_modified_date(), 
'int'),
+                               $this->marshal($case->get_modified_by(), 'int'),
+                               $this->marshal($case->get_measurement(), 
'string')
+                       );
 
-    $sql = "SELECT * FROM controller_check_item_case ";
-    $sql .= "WHERE location_id = {$location_id} AND location_item_id = 
{$location_item_id}";
+                       $result = $this->db->query('INSERT INTO 
controller_check_item_case (' . join(',', $cols) . ') VALUES (' . join(',', 
$values) . ')', __LINE__,__FILE__);
 
-    $this->db->query($sql);
+                       return $result ? 
$this->db->get_last_insert_id('controller_check_item_case', 'id') : 0;
+               }
 
-    while ($this->db->next_record()) {
-      $case = new 
controller_check_item_case($this->unmarshal($this->db->f('id'), 'int'));
-      $case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
-      $case->set_status($this->unmarshal($this->db->f('status'), 'int'));
-      $case->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-      
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
-      $case->set_descr($this->unmarshal($this->db->f('descr', true), 
'string'));
-      $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
-      $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 
'int'));
-      $case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
-      $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 
'int'));
-      $case->set_measurement($this->unmarshal($this->db->f('measurement'), 
'string'));
+               /**
+                * Updates an existing case object in database  
+                * 
+                * @param       $case to updated
+                * @return true or false
+               */
+               function update($case)
+               {
+                       $id = (int) $case->get_id();
+                       
+                       $values = array(
+                               'check_item_id = ' . 
$this->marshal($case->get_check_item_id(), 'int'),
+                               'status = ' . $case->get_status(),
+                               'location_id = ' . 
$this->marshal($case->get_location_id(), 'int'),
+                               'location_item_id = ' . 
$this->marshal($case->get_location_item_id(), 'int'),
+                               'descr = ' . $this->marshal($case->get_descr(), 
'string'),
+                               'user_id = ' . 
$this->marshal($case->get_user_id(), 'int'),
+                               'entry_date = ' . 
$this->marshal($case->get_entry_date(), 'int'),
+                               'modified_date = ' . 
$this->marshal($case->get_modified_date(), 'int'),
+                               'modified_by = ' . 
$this->marshal($case->get_modified_by(), 'int'),
+                               'measurement = ' . 
$this->marshal($case->get_measurement(), 'string')
+                       );
 
-      if ($return_type == "return_object") {
-        $cases_array[] = $case;
-      } else {
-        $cases_array[] = $case->toArray();
-      }
-    }
+                       $result = $this->db->query('UPDATE 
controller_check_item_case SET ' . join(',', $values) . " WHERE id=$id", 
__LINE__,__FILE__);
 
-    return $cases_array;
-  }
-
-  /**
-   * Inserts a new case in database  
-   * 
-   * @param    $case to inserted
-   * @return true or false
-   */
-  function add(&$case) {
-    $cols = array(
-        'check_item_id',
-        'status',
-        'location_id',
-        'location_item_id',
-        'descr',
-        'user_id',
-        'entry_date',
-        'modified_date',
-        'modified_by',
-        'measurement',
-    );
-
-    $values = array(
-        $this->marshal($case->get_check_item_id(), 'int'),
-        $case->get_status(),
-        $this->marshal($case->get_location_id(), 'int'),
-        $this->marshal($case->get_location_item_id(), 'int'),
-        $this->marshal($case->get_descr(), 'string'),
-        $this->marshal($case->get_user_id(), 'int'),
-        $this->marshal($case->get_entry_date(), 'int'),
-        $this->marshal($case->get_modified_date(), 'int'),
-        $this->marshal($case->get_modified_by(), 'int'),
-        $this->marshal($case->get_measurement(), 'string')
-    );
-
-    $result = $this->db->query('INSERT INTO controller_check_item_case (' . 
join(',', $cols) . ') VALUES (' . join(',', $values) . ')', __LINE__, __FILE__);
-
-    return $result ? 
$this->db->get_last_insert_id('controller_check_item_case', 'id') : 0;
-  }
-
-  /**
-   * Updates an existing case object in database  
-   * 
-   * @param    $case to updated
-   * @return true or false
-   */
-  function update($case) {
-    $id = (int) $case->get_id();
-
-    $values = array(
-        'check_item_id = ' . $this->marshal($case->get_check_item_id(), 'int'),
-        'status = ' . $case->get_status(),
-        'location_id = ' . $this->marshal($case->get_location_id(), 'int'),
-        'location_item_id = ' . $this->marshal($case->get_location_item_id(), 
'int'),
-        'descr = ' . $this->marshal($case->get_descr(), 'string'),
-        'user_id = ' . $this->marshal($case->get_user_id(), 'int'),
-        'entry_date = ' . $this->marshal($case->get_entry_date(), 'int'),
-        'modified_date = ' . $this->marshal($case->get_modified_date(), 'int'),
-        'modified_by = ' . $this->marshal($case->get_modified_by(), 'int'),
-        'measurement = ' . $this->marshal($case->get_measurement(), 'string')
-    );
-
-    $result = $this->db->query('UPDATE controller_check_item_case SET ' . 
join(',', $values) . " WHERE id=$id", __LINE__, __FILE__);
-
-    if ($result) {
-      return $id;
-    } else {
-      return 0;
-    }
-  }
-
-  /**
-   * Delete case in database  
-   * 
-   * @param    $case_id case to be deleted
-   * @return true or false
-   */
-  function delete($case_id) {
-    $case_id = (int) $case_id;
-    $status = $this->db->query("DELETE FROM controller_check_item_case WHERE 
id = $case_id");
-
-    if ($status) {
-      return true;
-    } else {
-      return false;
-    }
-  }
-
-  function get_id_field_name() {
-    
-  }
-
-}
+                       if( $result )
+                       {
+                               return $id;
+                       }
+                       else
+                       {
+                               return 0;
+                       }
+               }
+               
+               /**
+                * Delete case in database  
+                * 
+                * @param       $case_id case to be deleted
+                * @return true or false
+               */
+               function delete($case_id)
+               {
+                       $case_id = (int) $case_id;
+                       $status = $this->db->query("DELETE FROM 
controller_check_item_case WHERE id = $case_id");
+                                       
+                       if( $status )
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               return false;
+                       }
+               }
+               
+               function get_id_field_name(){}
+       }

Modified: trunk/controller/inc/class.socheck_item.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_item.inc.php     2012-08-31 10:09:39 UTC 
(rev 9950)
+++ trunk/controller/inc/class.socheck_item.inc.php     2012-08-31 10:14:12 UTC 
(rev 9951)
@@ -1,546 +1,620 @@
 <?php
+       /**
+       * phpGroupWare - controller: a part of a Facilities Management System.
+       *
+       * @author Erink Holm-Larsen <address@hidden>
+       * @author Torstein Vadla <address@hidden>
+       * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
+       * @package property
+       * @subpackage controller
+       * @version $Id$
+       */
 
-/**
- * phpGroupWare - controller: a part of a Facilities Management System.
- *
- * @author Erink Holm-Larsen <address@hidden>
- * @author Torstein Vadla <address@hidden>
- * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
- * This file is part of phpGroupWare.
- *
- * phpGroupWare is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * phpGroupWare is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with phpGroupWare; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
- * @package property
- * @subpackage controller
- * @version $Id$
- */
-phpgw::import_class('controller.socommon');
+       phpgw::import_class('controller.socommon');
 
-include_class('controller', 'check_item', 'inc/model/');
-include_class('controller', 'check_item_case', 'inc/model/');
+       include_class('controller', 'check_item', 'inc/model/');
+       include_class('controller', 'check_item_case', 'inc/model/');
 
-class controller_socheck_item extends controller_socommon {
+       class controller_socheck_item extends controller_socommon
+       {
+               protected static $so;
 
-  protected static $so;
+               /**
+                * Get a static reference to the storage object associated with 
this model object
+                *
+                * @return controller_socontrol_group the storage object
+                */
+               public static function get_instance()
+               {
+                       if (self::$so == null)
+                       {
+                               self::$so = 
CreateObject('controller.socheck_item');
+                       }
+                       return self::$so;
+               }
 
-  /**
-   * Get a static reference to the storage object associated with this model 
object
-   *
-   * @return controller_socontrol_group the storage object
-   */
-  public static function get_instance() {
-    if (self::$so == null) {
-      self::$so = CreateObject('controller.socheck_item');
-    }
-    return self::$so;
-  }
+               /**
+                * Add a new check item object to database
+                * 
+                * @param       $check_item check item oject to be added
+                * @return id of the inserted check item, 0 otherwise 
+               */
+               function add(&$check_item)
+               {
+                       $cols = array(
+                                       'control_item_id',
+                                       'check_list_id'
+                       );
 
-  /**
-   * Add a new check item object to database
-   * 
-   * @param    $check_item check item oject to be added
-   * @return id of the inserted check item, 0 otherwise 
-   */
-  function add(&$check_item) {
-    $cols = array(
-        'control_item_id',
-        'check_list_id'
-    );
+                       $values = array(
+                               
$this->marshal($check_item->get_control_item_id(), 'int'),
+                               
$this->marshal($check_item->get_check_list_id(), 'int')
+                       );
 
-    $values = array(
-        $this->marshal($check_item->get_control_item_id(), 'int'),
-        $this->marshal($check_item->get_check_list_id(), 'int')
-    );
+                       $result = $this->db->query('INSERT INTO 
controller_check_item (' . join(',', $cols) . ') VALUES (' . join(',', $values) 
. ')', __LINE__,__FILE__);
 
-    $result = $this->db->query('INSERT INTO controller_check_item (' . 
join(',', $cols) . ') VALUES (' . join(',', $values) . ')', __LINE__, __FILE__);
+                       return $result ? 
$this->db->get_last_insert_id('controller_check_item', 'id') : 0;
+               }
 
-    return $result ? $this->db->get_last_insert_id('controller_check_item', 
'id') : 0;
-  }
+               /**
+                * Update existing check item object in database  
+                * 
+                * @param       $check_item check item oject to be updated
+                * @return  id of the inserted check item, 0 otherwise 
+               */
+               function update($check_item)
+               {
+                       $id = $check_item->get_id();
 
-  /**
-   * Update existing check item object in database  
-   * 
-   * @param    $check_item check item oject to be updated
-   * @return  id of the inserted check item, 0 otherwise 
-   */
-  function update($check_item) {
-    $id = $check_item->get_id();
+                       $values = array(
+                               'control_item_id = ' . 
$this->marshal($check_item->get_control_item_id(), 'int'),
+                               'check_list_id = ' . 
$this->marshal($check_item->get_check_list_id(), 'int')
+                       );
 
-    $values = array(
-        'control_item_id = ' . 
$this->marshal($check_item->get_control_item_id(), 'int'),
-        'check_list_id = ' . $this->marshal($check_item->get_check_list_id(), 
'int')
-    );
+                       $result = $this->db->query('UPDATE 
controller_check_item SET ' . join(',', $values) . " WHERE id=$id", 
__LINE__,__FILE__);
 
-    $result = $this->db->query('UPDATE controller_check_item SET ' . join(',', 
$values) . " WHERE id=$id", __LINE__, __FILE__);
+                       if( $result )
+                       {
+                               return $id;
+                       }
+                       else
+                       {
+                               return 0;
+                       }
+               }
 
-    if ($result) {
-      return $id;
-    } else {
-      return 0;
-    }
-  }
+               /**
+                * Get single check item object from database including related 
control item  
+                * 
+                * @param       $check_item_id id to check item to be fetched 
from database
+                * @return  check item object 
+               */
+               public function get_single($check_item_id)
+               {
+                       $check_item_id = (int) $check_item_id;
 
-  /**
-   * Get single check item object from database including related control item 
 
-   * 
-   * @param    $check_item_id id to check item to be fetched from database
-   * @return  check item object 
-   */
-  public function get_single($check_item_id) {
-    $check_item_id = (int) $check_item_id;
+                       $sql = "SELECT ci.*, ci.id as c_id, coi.id as coi_id, 
coi.* ";
+                       $sql .= "FROM controller_check_item ci, 
controller_control_item coi "; 
+                       $sql .= "WHERE ci.id = {$check_item_id} ";
+                       $sql .= "AND ci.control_item_id=coi.id";
 
-    $sql = "SELECT ci.*, ci.id as c_id, coi.id as coi_id, coi.* ";
-    $sql .= "FROM controller_check_item ci, controller_control_item coi ";
-    $sql .= "WHERE ci.id = {$check_item_id} ";
-    $sql .= "AND ci.control_item_id=coi.id";
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
 
-    $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+                       if($this->db->next_record())
+                       {
+                               $check_item = new 
controller_check_item($this->unmarshal($this->db->f('c_id'), 'int'));
+                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                               
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
 
-    if ($this->db->next_record()) {
-      $check_item = new 
controller_check_item($this->unmarshal($this->db->f('c_id'), 'int'));
-      
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
-      
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
+                               $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
+                               $control_item->set_title($this->db->f('title', 
true), 'string');
+                               
$control_item->set_required($this->db->f('required', true), 'string');
+                               
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+                               
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+                               
$control_item->set_control_group_id($this->db->f('control_group_id'), 'int');
 
-      $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
-      $control_item->set_title($this->db->f('title', true), 'string');
-      $control_item->set_required($this->db->f('required', true), 'string');
-      $control_item->set_what_to_do($this->db->f('what_to_do', true), 
'string');
-      $control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
-      $control_item->set_control_group_id($this->db->f('control_group_id'), 
'int');
+                               
$check_item->set_control_item($control_item->toArray());
 
-      $check_item->set_control_item($control_item->toArray());
+                               return $check_item;
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+               
+               /**
+                * Get single check item object from database including related 
cases and control item 
+                * 
+                * @param       $check_item_id id to check item to be fetched 
from database
+                * @return  check item object 
+               */
+               public function get_single_with_cases($check_item_id, 
$return_type = "return_object")
+               {
+                       $check_item_id = (int) $check_item_id;
 
-      return $check_item;
-    } else {
-      return null;
-    }
-  }
+                       $sql  = "SELECT ci.id as ci_id, control_item_id, 
check_list_id, ";
+                       $sql .= "cic.id as cic_id, cic.status as cic_status, 
cic.*, ";
+                       $sql .= "coi.id as coi_id, coi.* ";
+                       $sql .= "FROM controller_check_item ci "; 
+                       $sql .= "LEFT JOIN controller_control_item as coi ON 
ci.control_item_id = coi.id ";
+                       $sql .= "LEFT JOIN controller_check_item_case as cic ON 
ci.id = cic.check_item_id ";
+                       $sql .= "WHERE ci.id = {$check_item_id} ";
+                                                                               
        
+                       $this->db->query($sql);
+                       
+                       $counter = 0;
+                       $check_item = null;
+                       while ($this->db->next_record())
+                       {
+                               if( $counter == 0 )
+                               {
+                                       $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
+                                       
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
+                                       
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                                       
+                                       $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
+                                       
$control_item->set_title($this->db->f('title', true), 'string');
+                                       
$control_item->set_required($this->db->f('required', true), 'string');
+                                       
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+                                       
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+                                       
$control_item->set_control_group_id($this->db->f('control_group_id'), 'int');
+                                       
$control_item->set_type($this->db->f('type', true), 'string');
+                               
+                                       if($return_type == "return_array")
+                                       {
+                                               
$check_item->set_control_item($control_item->toArray());
+                                       }
+                                       else
+                                       {
+                                               
$check_item->set_control_item($control_item);
+                                       }
+                                               
+                                       $cases_array = array();
+                               }
+                               
+                               if($this->db->f('cic_id'))
+                               {
+                                       $case = new 
controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
+                                       
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
+                                       
$case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
+                                       
$case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
+                                       
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
+                                       
$case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
+                                       
$case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));   
+                                       
$case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
+                                       
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
+                                       
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
+                               
+                               
+                                       if($return_type == "return_array")
+                                       {
+                                               $cases_array[] = 
$case->toArray();
+                                       }
+                                       else
+                                       {
+                                               $cases_array[] = $case;
+                                       }
+                               }
+                               
+                               $check_item_id =  $check_item->get_id();
+                               $counter++;
+                       }
+                       
+                       if($check_item != null)
+                       {
+                               $check_item->set_cases_array($cases_array);
+                               
+                               if($return_type == "return_array")
+                               {
+                                       return $check_item->toArray();
+                               }
+                               else
+                               {
+                                       return $check_item;
+                               }
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+               
+               /**
+                * Get single check item object from database including related 
control item
+                * 
+                * @param       $check_list_id check list id
+                * @param       $check_item_id control item id
+                * @return check item object 
+               */
+               public function 
get_check_item_by_check_list_and_control_item($check_list_id, $control_item_id)
+               {
+                       $check_list_id = (int) $check_list_id;
+                       $control_item_id = (int) $control_item_id;
 
-  /**
-   * Get single check item object from database including related cases and 
control item 
-   * 
-   * @param    $check_item_id id to check item to be fetched from database
-   * @return  check item object 
-   */
-  public function get_single_with_cases($check_item_id, $return_type = 
"return_object") {
-    $check_item_id = (int) $check_item_id;
+                       $sql  = "SELECT ci.*, ci.id as c_id, coi.id as coi_id, 
coi.* ";
+                       $sql .= "FROM controller_check_item ci, 
controller_control_item coi "; 
+                       $sql .= "WHERE ci.check_list_id = {$check_list_id} ";
+                       $sql .= "AND ci.control_item_id = coi.id ";
+                       $sql .= "AND ci.control_item_id = {$control_item_id}";
+                       
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
 
-    $sql = "SELECT ci.id as ci_id, control_item_id, check_list_id, ";
-    $sql .= "cic.id as cic_id, cic.status as cic_status, cic.*, ";
-    $sql .= "coi.id as coi_id, coi.* ";
-    $sql .= "FROM controller_check_item ci ";
-    $sql .= "LEFT JOIN controller_control_item as coi ON ci.control_item_id = 
coi.id ";
-    $sql .= "LEFT JOIN controller_check_item_case as cic ON ci.id = 
cic.check_item_id ";
-    $sql .= "WHERE ci.id = {$check_item_id} ";
+                       if($this->db->next_record())
+                       {
+                               $check_item = new 
controller_check_item($this->unmarshal($this->db->f('c_id'), 'int'));
+                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                               
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
 
-    $this->db->query($sql);
+                               $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
+                               $control_item->set_title($this->db->f('title', 
true), 'string');
+                               
$control_item->set_required($this->db->f('required', true), 'string');
+                               
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+                               
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+                               
$control_item->set_control_group_id($this->db->f('control_group_id'), 'int');
 
-    $counter = 0;
-    $check_item = null;
-    while ($this->db->next_record()) {
-      if ($counter == 0) {
-        $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
-        
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
-        
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                               
$check_item->set_control_item($control_item->toArray());
 
-        $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
-        $control_item->set_title($this->db->f('title', true), 'string');
-        $control_item->set_required($this->db->f('required', true), 'string');
-        $control_item->set_what_to_do($this->db->f('what_to_do', true), 
'string');
-        $control_item->set_how_to_do($this->db->f('how_to_do', true), 
'string');
-        $control_item->set_control_group_id($this->db->f('control_group_id'), 
'int');
-        $control_item->set_type($this->db->f('type', true), 'string');
+                               return $check_item;
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+               
+       /* Later ikke til at denne er i bruk: Torstein 10.07.12
+               public function get_check_items($check_list_id, $status, $type, 
$return_type = "return_object"){
+                       $sql  = "SELECT ci.id as ci_id, control_item_id, 
check_list_id, "; 
+                       $sql .= "coi.id as coi_id, coi.title, coi.required, 
coi.what_to_do, coi.how_to_do, coi.control_group_id, coi.type "; 
+                       $sql .= "FROM controller_check_item ci "; 
+                       $sql .= "LEFT JOIN controller_control_item as coi ON 
ci.control_item_id = coi.id ";
+                       $sql .= "WHERE ci.check_list_id = $check_list_id ";
+                       
+                       if($status == 'open')
+                               $sql .= "AND ci.status = 0 ";
+                       else if($status == 'handled')
+                               $sql .= "AND ci.status = 1 ";
+                               
+                       if($type != null)
+                               $sql .= "AND coi.type = '$type'";
+                               
+                       $this->db->query($sql);
+                       
+                       while ($this->db->next_record()) {
+                               $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
+                               
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
 true), 'int'));
+                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
+                               
+                               $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id', true), 'int'));
+                               $control_item->set_title($this->db->f('title', 
true), 'string');
+                               
$control_item->set_required($this->db->f('required', true), 'string');
+                               
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+                               
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+                               
$control_item->set_control_group_id($this->db->f('control_group_id', true), 
'string');
+                               $control_item->set_type($this->db->f('type', 
true), 'string');
+                               
+                               if($return_type == "return_array"){
+                                       
$check_item->set_control_item($control_item->toArray());
+                                       $check_items_array[] = 
$check_item->toArray();
+                               }
+                               else{
+                                       
$check_item->set_control_item($control_item);
+                                       $check_items_array[] = $check_item;
+                               }
+                       }
+                       
+                       return $check_items_array;
+               }
+               */
+               
+               /**
+                * Get check item objects from database including control item 
and related cases 
+                * 
+                * @param       $check_list_id check list id
+                * @param       $type control item registration type 
COMMENT/TEXTFIELD/CHECKLIST/RADIOBUTTONS 
+                * @param       $status status for cases OPEN/CLOSED/PENDING
+                * @param       $messageStatus is there a message registered 
for the case
+                * @param       $returnType data returned as objects or arrays
+                * @return check item objects
+               */
+               public function get_check_items_with_cases($check_list_id, 
$type = "control_item_type_1", $status = "open", $messageStatus = null, 
$return_type = "return_object")
+               {
+                       $check_list_id = (int) $check_list_id;
+                       $sql  = "SELECT ci.id as ci_id, control_item_id, 
check_list_id, ";
+                       $sql .= "cic.id as cic_id, cic.status as cic_status, 
cic.*, ";
+                       $sql .= "coi.id as coi_id, coi.* ";
+                       $sql .= "FROM controller_check_item ci "; 
+                       $sql .= "LEFT JOIN controller_control_item as coi ON 
ci.control_item_id = coi.id ";
+                       $sql .= "LEFT JOIN controller_check_item_case as cic ON 
ci.id = cic.check_item_id ";
+                       $sql .= "WHERE ci.check_list_id = {$check_list_id} ";
+                       
+                       if($status == 'open')
+                       {
+                               $sql .= "AND cic.status = 0 ";
+                       }
+                       else if($status == 'closed')
+                       {
+                               $sql .= "AND cic.status = 1 ";
+                       }
+                       else if($status == 'waiting')
+                       {
+                               $sql .= "AND cic.status = 2 ";
+                       }
+                       else if($status == 'open_or_waiting')
+                       {
+                               $sql .= "AND (cic.status = 0 OR cic.status = 2) 
";
+                       }
+                       
+                       if($type != null)
+                       {
+                               $sql .= "AND coi.type = '$type' ";
+                       }
+                                                                               
+                       if($messageStatus != null & $messageStatus == 
'no_message_registered')
+                       {
+                               $sql .= "AND cic.location_item_id IS NULL ";
+                       }
+                       else if($messageStatus != null &  $messageStatus == 
'message_registered')
+                       {
+                               $sql .= "AND cic.location_item_id > 0 ";
+                       }
+                       
+                       $sql .= "ORDER BY ci.id";
+                                                                               
        
+                       $this->db->query($sql);
+                       
+                       $check_item_id = 0;
+                       $check_item = null;
+                       while ($this->db->next_record())
+                       {
+                               if( $this->db->f('ci_id') != $check_item_id )
+                               {       
+                                       if($check_item_id)
+                                       {
+                                               
$check_item->set_cases_array($cases_array);
+                                               
+                                               if($return_type == 
"return_array")
+                                               {
+                                                       $check_items_array[] = 
$check_item->toArray();
+                                               }
+                                               else
+                                               {
+                                                       $check_items_array[] = 
$check_item;
+                                               }
+                                       }
+                               
+                                       $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
+                                       
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
+                                       
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                                       
+                                       $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
+                                       
$control_item->set_title($this->db->f('title', true), 'string');
+                                       
$control_item->set_required($this->db->f('required', true), 'string');
+                                       
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+                                       
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+                                       
$control_item->set_control_group_id($this->db->f('control_group_id'), 'int');
+                                       
$control_item->set_type($this->db->f('type', true), 'string');
+                               
+                                       if($return_type == "return_array")
+                                       {
+                                               
$check_item->set_control_item($control_item->toArray());
+                                       }
+                                       else
+                                       {
+                                               
$check_item->set_control_item($control_item);
+                                       }
+                                                       
+                                       $cases_array = array();
+                               }
+                               
+                               if( $this->db->f('cic_id') )
+                               {
+                                       $case = new 
controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
+                                       
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
+                                       
$case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
+                                       
$case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
+                                       
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
+                                       
$case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
+                                       
$case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));   
+                                       
$case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
+                                       
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
+                                       
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
+                                       
$case->set_measurement($this->unmarshal($this->db->f('measurement', true), 
'string'));
+                                                               
+                                       if($return_type == "return_array")
+                                       {
+                                               $cases_array[] = 
$case->toArray();
+                                       }
+                                       else
+                                       {
+                                               $cases_array[] = $case;
+                                       }
+                               }
+                               
+                               $check_item_id = $check_item->get_id();
+                       }
+                       
+                       if($check_item != null)
+                       {
+                               $check_item->set_cases_array($cases_array);
+                               
+                               if($return_type == "return_array")
+                               {
+                                       $check_items_array[] = 
$check_item->toArray();
+                               }
+                               else
+                               {
+                                       $check_items_array[] = $check_item;
+                               }
+                               return $check_items_array;
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+               
+               /**
+                * Get check item objects from database including related 
control item and cases
+                * 
+                * @param       $message_ticket_id get check items and cases 
for this message
+                * @param       $returnType data returned as objects or arrays
+                * @return check item objects 
+               */
+               public function 
get_check_items_with_cases_by_message($message_ticket_id, $return_type = 
"return_object")
+               {
+                       $message_ticket_id = (int) $message_ticket_id;
 
-        if ($return_type == "return_array") {
-          $check_item->set_control_item($control_item->toArray());
-        } else {
-          $check_item->set_control_item($control_item);
-        }
+                       $sql  = "SELECT ci.id as ci_id, control_item_id, "; 
+                       $sql .= "check_list_id, cic.id as cic_id, cic.status as 
cic_status, cic.*, ";
+                       $sql .= "coi.id as coi_id, coi.* ";
+                       $sql .= "FROM controller_check_item ci "; 
+                       $sql .= "LEFT JOIN controller_control_item as coi ON 
ci.control_item_id = coi.id ";
+                       $sql .= "LEFT JOIN controller_check_item_case as cic ON 
ci.id = cic.check_item_id ";
+                       $sql .= "WHERE cic.location_item_id = 
{$message_ticket_id}";
+                                                                               
        
+                       $this->db->query($sql);
+                       
+                       $check_item_id = 0;
+                       $check_item = null;
+                       while ($this->db->next_record())
+                       {
+                               if( $this->db->f('ci_id') != $check_item_id )
+                               {
+                                       if($check_item_id)
+                                       {
+                                               
$check_item->set_cases_array($cases_array);
+                                               
+                                               if($return_type == 
"return_array")
+                                               {
+                                                       $check_items_array[] = 
$check_item->toArray();
+                                               }
+                                               else
+                                               {
+                                                       $check_items_array[] = 
$check_item;
+                                               }
+                                       }
+                               
+                                       $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
+                                       
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
+                                       
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                                       
+                                       $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
+                                       
$control_item->set_title($this->db->f('title', true), 'string');
+                                       
$control_item->set_required($this->db->f('required', true), 'string');
+                                       
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+                                       
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+                                       
$control_item->set_control_group_id($this->db->f('control_group_id'), 'int');
+                                       
$control_item->set_type($this->db->f('type', true), 'string');
+                               
+                                       if($return_type == "return_array")
+                                       {
+                                               
$check_item->set_control_item($control_item->toArray());
+                                       }
+                                       else
+                                       {
+                                               
$check_item->set_control_item($control_item);
+                                       }
+                                                                       
+                                       $cases_array = array();
+                               }
+                               
+                               if($this->db->f('cic_id'))
+                               {
+                                       $case = new 
controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
+                                       
$case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
+                                       
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
+                                       
$case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
+                                       
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
+                                       
$case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
+                                       
$case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));   
+                                       
$case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
+                                       
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
+                                       
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
+                               
+                               
+                                       if($return_type == "return_array")
+                                       {
+                                               $cases_array[] = 
$case->toArray();
+                                       }
+                                       else
+                                       {
+                                               $cases_array[] = $case;
+                                       }
+                               }
+                               
+                               $check_item_id =  $check_item->get_id();
+                       }
+                       
+                       if($check_item != null)
+                       {
+                               $check_item->set_cases_array($cases_array);
+                               
+                               if($return_type == "return_array")
+                               {
+                                       $check_items_array[] = 
$check_item->toArray();
+                               }
+                               else
+                               {
+                                       $check_items_array[] = $check_item;
+                               }
+                               
+                               return $check_items_array;
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+                /* Later ikke til at vi bruker denne: Torstein 10.07.12
+               public function get_check_items_by_message($location_id, 
$location_item_id, $return_type = "return_array" )
+               {
+                       $location_id            = (int)$location_id;
+                       $location_item_id       = (int)$location_item_id;
+                       $sql  = "SELECT ci.* "; 
+                       $sql .= "FROM controller_check_item ci "; 
+                       $sql .= "LEFT JOIN controller_check_item_case as cic ON 
ci.id = cic.check_item_id ";
+                       $sql .= "WHERE cic.location_id = {$location_id} AND 
cic.location_item_id = {$location_item_id} ";
+                                                               
+                       $this->db->query($sql);
+                       
+                       while ($this->db->next_record()) {
+                               $check_item = new 
controller_check_item($this->unmarshal($this->db->f('id', true), 'int'));
+                               
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
 true), 'int'));
+                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
+                               
+                               if($return_type == "return_array")
+                                       $check_items_array[] = 
$check_item->toArray();
+                               else
+                                       $check_items_array[] = $check_item;
+                       }
+                       
+                       return $check_items_array;
+               }
+               */
+               
+               function get_query(string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean 
$return_count){}
 
-        $cases_array = array();
-      }
+               function populate(int $object_id, &$object){}
 
-      if ($this->db->f('cic_id')) {
-        $case = new 
controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
-        
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
-        $case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
-        $case->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-        
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
-        $case->set_descr($this->unmarshal($this->db->f('descr', true), 
'string'));
-        $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
-        $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 
'int'));
-        
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
-        $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 
'int'));
-
-
-        if ($return_type == "return_array") {
-          $cases_array[] = $case->toArray();
-        } else {
-          $cases_array[] = $case;
-        }
-      }
-
-      $check_item_id = $check_item->get_id();
-      $counter++;
-    }
-
-    if ($check_item != null) {
-      $check_item->set_cases_array($cases_array);
-
-      if ($return_type == "return_array") {
-        return $check_item->toArray();
-      } else {
-        return $check_item;
-      }
-    } else {
-      return null;
-    }
-  }
-
-  /**
-   * Get single check item object from database including related control item
-   * 
-   * @param    $check_list_id check list id
-   * @param    $check_item_id control item id
-   * @return check item object 
-   */
-  public function 
get_check_item_by_check_list_and_control_item($check_list_id, $control_item_id) 
{
-    $check_list_id = (int) $check_list_id;
-    $control_item_id = (int) $control_item_id;
-
-    $sql = "SELECT ci.*, ci.id as c_id, coi.id as coi_id, coi.* ";
-    $sql .= "FROM controller_check_item ci, controller_control_item coi ";
-    $sql .= "WHERE ci.check_list_id = {$check_list_id} ";
-    $sql .= "AND ci.control_item_id = coi.id ";
-    $sql .= "AND ci.control_item_id = {$control_item_id}";
-
-    $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
-
-    if ($this->db->next_record()) {
-      $check_item = new 
controller_check_item($this->unmarshal($this->db->f('c_id'), 'int'));
-      
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
-      
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
-
-      $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
-      $control_item->set_title($this->db->f('title', true), 'string');
-      $control_item->set_required($this->db->f('required', true), 'string');
-      $control_item->set_what_to_do($this->db->f('what_to_do', true), 
'string');
-      $control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
-      $control_item->set_control_group_id($this->db->f('control_group_id'), 
'int');
-
-      $check_item->set_control_item($control_item->toArray());
-
-      return $check_item;
-    } else {
-      return null;
-    }
-  }
-
-  /* Later ikke til at denne er i bruk: Torstein 10.07.12
-    public function get_check_items($check_list_id, $status, $type, 
$return_type = "return_object"){
-    $sql  = "SELECT ci.id as ci_id, control_item_id, check_list_id, ";
-    $sql .= "coi.id as coi_id, coi.title, coi.required, coi.what_to_do, 
coi.how_to_do, coi.control_group_id, coi.type ";
-    $sql .= "FROM controller_check_item ci ";
-    $sql .= "LEFT JOIN controller_control_item as coi ON ci.control_item_id = 
coi.id ";
-    $sql .= "WHERE ci.check_list_id = $check_list_id ";
-
-    if($status == 'open')
-    $sql .= "AND ci.status = 0 ";
-    else if($status == 'handled')
-    $sql .= "AND ci.status = 1 ";
-
-    if($type != null)
-    $sql .= "AND coi.type = '$type'";
-
-    $this->db->query($sql);
-
-    while ($this->db->next_record()) {
-    $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
-    
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
 true), 'int'));
-    
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
-
-    $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id', true), 'int'));
-    $control_item->set_title($this->db->f('title', true), 'string');
-    $control_item->set_required($this->db->f('required', true), 'string');
-    $control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
-    $control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
-    $control_item->set_control_group_id($this->db->f('control_group_id', 
true), 'string');
-    $control_item->set_type($this->db->f('type', true), 'string');
-
-    if($return_type == "return_array"){
-    $check_item->set_control_item($control_item->toArray());
-    $check_items_array[] = $check_item->toArray();
-    }
-    else{
-    $check_item->set_control_item($control_item);
-    $check_items_array[] = $check_item;
-    }
-    }
-
-    return $check_items_array;
-    }
-   */
-
-  /**
-   * Get check item objects from database including control item and related 
cases 
-   * 
-   * @param    $check_list_id check list id
-   * @param    $type control item registration type 
COMMENT/TEXTFIELD/CHECKLIST/RADIOBUTTONS 
-   * @param    $status status for cases OPEN/CLOSED/PENDING
-   * @param    $messageStatus is there a message registered for the case
-   * @param    $returnType data returned as objects or arrays
-   * @return check item objects
-   */
-  public function get_check_items_with_cases($check_list_id, $type = 
"control_item_type_1", $status = "open", $messageStatus = null, $return_type = 
"return_object") {
-    $check_list_id = (int) $check_list_id;
-    $sql = "SELECT ci.id as ci_id, control_item_id, check_list_id, ";
-    $sql .= "cic.id as cic_id, cic.status as cic_status, cic.*, ";
-    $sql .= "coi.id as coi_id, coi.* ";
-    $sql .= "FROM controller_check_item ci ";
-    $sql .= "LEFT JOIN controller_control_item as coi ON ci.control_item_id = 
coi.id ";
-    $sql .= "LEFT JOIN controller_check_item_case as cic ON ci.id = 
cic.check_item_id ";
-    $sql .= "WHERE ci.check_list_id = {$check_list_id} ";
-
-    if ($status == 'open') {
-      $sql .= "AND cic.status = 0 ";
-    } else if ($status == 'closed') {
-      $sql .= "AND cic.status = 1 ";
-    } else if ($status == 'waiting') {
-      $sql .= "AND cic.status = 2 ";
-    } else if ($status == 'open_or_waiting') {
-      $sql .= "AND (cic.status = 0 OR cic.status = 2) ";
-    }
-
-    if ($type != null) {
-      $sql .= "AND coi.type = '$type' ";
-    }
-
-    if ($messageStatus != null & $messageStatus == 'no_message_registered') {
-      $sql .= "AND cic.location_item_id IS NULL ";
-    } else if ($messageStatus != null & $messageStatus == 
'message_registered') {
-      $sql .= "AND cic.location_item_id > 0 ";
-    }
-
-    $sql .= "ORDER BY ci.id";
-
-    $this->db->query($sql);
-
-    $check_item_id = 0;
-    $check_item = null;
-    while ($this->db->next_record()) {
-      if ($this->db->f('ci_id') != $check_item_id) {
-        if ($check_item_id) {
-          $check_item->set_cases_array($cases_array);
-
-          if ($return_type == "return_array") {
-            $check_items_array[] = $check_item->toArray();
-          } else {
-            $check_items_array[] = $check_item;
-          }
-        }
-
-        $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
-        
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
-        
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
-
-        $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
-        $control_item->set_title($this->db->f('title', true), 'string');
-        $control_item->set_required($this->db->f('required', true), 'string');
-        $control_item->set_what_to_do($this->db->f('what_to_do', true), 
'string');
-        $control_item->set_how_to_do($this->db->f('how_to_do', true), 
'string');
-        $control_item->set_control_group_id($this->db->f('control_group_id'), 
'int');
-        $control_item->set_type($this->db->f('type', true), 'string');
-
-        if ($return_type == "return_array") {
-          $check_item->set_control_item($control_item->toArray());
-        } else {
-          $check_item->set_control_item($control_item);
-        }
-
-        $cases_array = array();
-      }
-
-      if ($this->db->f('cic_id')) {
-        $case = new 
controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
-        
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
-        $case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
-        $case->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-        
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
-        $case->set_descr($this->unmarshal($this->db->f('descr', true), 
'string'));
-        $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
-        $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 
'int'));
-        
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
-        $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 
'int'));
-        $case->set_measurement($this->unmarshal($this->db->f('measurement', 
true), 'string'));
-
-        if ($return_type == "return_array") {
-          $cases_array[] = $case->toArray();
-        } else {
-          $cases_array[] = $case;
-        }
-      }
-
-      $check_item_id = $check_item->get_id();
-    }
-
-    if ($check_item != null) {
-      $check_item->set_cases_array($cases_array);
-
-      if ($return_type == "return_array") {
-        $check_items_array[] = $check_item->toArray();
-      } else {
-        $check_items_array[] = $check_item;
-      }
-      return $check_items_array;
-    } else {
-      return null;
-    }
-  }
-
-  /**
-   * Get check item objects from database including related control item and 
cases
-   * 
-   * @param    $message_ticket_id get check items and cases for this message
-   * @param    $returnType data returned as objects or arrays
-   * @return check item objects 
-   */
-  public function get_check_items_with_cases_by_message($message_ticket_id, 
$return_type = "return_object") {
-    $message_ticket_id = (int) $message_ticket_id;
-
-    $sql = "SELECT ci.id as ci_id, control_item_id, ";
-    $sql .= "check_list_id, cic.id as cic_id, cic.status as cic_status, cic.*, 
";
-    $sql .= "coi.id as coi_id, coi.* ";
-    $sql .= "FROM controller_check_item ci ";
-    $sql .= "LEFT JOIN controller_control_item as coi ON ci.control_item_id = 
coi.id ";
-    $sql .= "LEFT JOIN controller_check_item_case as cic ON ci.id = 
cic.check_item_id ";
-    $sql .= "WHERE cic.location_item_id = {$message_ticket_id}";
-
-    $this->db->query($sql);
-
-    $check_item_id = 0;
-    $check_item = null;
-    while ($this->db->next_record()) {
-      if ($this->db->f('ci_id') != $check_item_id) {
-        if ($check_item_id) {
-          $check_item->set_cases_array($cases_array);
-
-          if ($return_type == "return_array") {
-            $check_items_array[] = $check_item->toArray();
-          } else {
-            $check_items_array[] = $check_item;
-          }
-        }
-
-        $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
-        
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
-        
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
-
-        $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
-        $control_item->set_title($this->db->f('title', true), 'string');
-        $control_item->set_required($this->db->f('required', true), 'string');
-        $control_item->set_what_to_do($this->db->f('what_to_do', true), 
'string');
-        $control_item->set_how_to_do($this->db->f('how_to_do', true), 
'string');
-        $control_item->set_control_group_id($this->db->f('control_group_id'), 
'int');
-        $control_item->set_type($this->db->f('type', true), 'string');
-
-        if ($return_type == "return_array") {
-          $check_item->set_control_item($control_item->toArray());
-        } else {
-          $check_item->set_control_item($control_item);
-        }
-
-        $cases_array = array();
-      }
-
-      if ($this->db->f('cic_id')) {
-        $case = new 
controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
-        $case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
-        
$case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 
'int'));
-        $case->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-        
$case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 
'int'));
-        $case->set_descr($this->unmarshal($this->db->f('descr', true), 
'string'));
-        $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
-        $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 
'int'));
-        
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 
'int'));
-        $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 
'int'));
-
-
-        if ($return_type == "return_array") {
-          $cases_array[] = $case->toArray();
-        } else {
-          $cases_array[] = $case;
-        }
-      }
-
-      $check_item_id = $check_item->get_id();
-    }
-
-    if ($check_item != null) {
-      $check_item->set_cases_array($cases_array);
-
-      if ($return_type == "return_array") {
-        $check_items_array[] = $check_item->toArray();
-      } else {
-        $check_items_array[] = $check_item;
-      }
-
-      return $check_items_array;
-    } else {
-      return null;
-    }
-  }
-
-  /* Later ikke til at vi bruker denne: Torstein 10.07.12
-    public function get_check_items_by_message($location_id, 
$location_item_id, $return_type = "return_array" )
-    {
-    $location_id               = (int)$location_id;
-    $location_item_id  = (int)$location_item_id;
-    $sql  = "SELECT ci.* ";
-    $sql .= "FROM controller_check_item ci ";
-    $sql .= "LEFT JOIN controller_check_item_case as cic ON ci.id = 
cic.check_item_id ";
-    $sql .= "WHERE cic.location_id = {$location_id} AND cic.location_item_id = 
{$location_item_id} ";
-
-    $this->db->query($sql);
-
-    while ($this->db->next_record()) {
-    $check_item = new 
controller_check_item($this->unmarshal($this->db->f('id', true), 'int'));
-    
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
 true), 'int'));
-    
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
-
-    if($return_type == "return_array")
-    $check_items_array[] = $check_item->toArray();
-    else
-    $check_items_array[] = $check_item;
-    }
-
-    return $check_items_array;
-    }
-   */
-
-  function get_query(string $sort_field, boolean $ascending, string 
$search_for, string $search_type, array $filters, boolean $return_count) {
-    
-  }
-
-  function populate(int $object_id, &$object) {
-    
-  }
-
-  function get_id_field_name() {
-    
-  }
-
-}
+               function get_id_field_name(){}
+       }

Modified: trunk/controller/inc/class.socheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_list.inc.php     2012-08-31 10:09:39 UTC 
(rev 9950)
+++ trunk/controller/inc/class.socheck_list.inc.php     2012-08-31 10:14:12 UTC 
(rev 9951)
@@ -1,831 +1,919 @@
-<?php
+<?php  
+       /**
+       * phpGroupWare - controller: a part of a Facilities Management System.
+       *
+       * @author Erik Holm-Larsen <address@hidden>
+       * @author Torstein Vadla <address@hidden>
+       * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
+       * @package property
+       * @subpackage controller
+       * @version $Id$
+       */
 
-/**
- * phpGroupWare - controller: a part of a Facilities Management System.
- *
- * @author Erik Holm-Larsen <address@hidden>
- * @author Torstein Vadla <address@hidden>
- * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
- * This file is part of phpGroupWare.
- *
- * phpGroupWare is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * phpGroupWare is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with phpGroupWare; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
- * @package property
- * @subpackage controller
- * @version $Id$
- */
 phpgw::import_class('controller.socommon');
 
 include_class('controller', 'check_list', 'inc/model/');
 include_class('controller', 'control_item', 'inc/model/');
 include_class('controller', 'check_item', 'inc/model/');
 
-class controller_socheck_list extends controller_socommon {
+class controller_socheck_list extends controller_socommon
+{
+       protected static $so;
 
-  protected static $so;
+       /**
+        * Get a static reference to the storage object associated with this 
model object
+        *
+        * @return controller_socheck_list the storage object
+        */
+       public static function get_instance()
+       {
+               if (self::$so == null)
+               {
+                       self::$so = CreateObject('controller.socheck_list');
+               }
+               return self::$so;
+       }
+       
+       /**
+        * Get a check list and related check_items and returns it as an object
+        *
+        * @param $check_list_id
+        * @return check list object
+        */
+       public function get_single($check_list_id)
+       {
+               $check_list_id = (int) $check_list_id;
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.control_id, cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, location_code, component_id, 
num_open_cases, num_pending_cases, location_id, ci.id as ci_id, control_item_id 
"; 
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "LEFT JOIN controller_check_item as ci ON cl.id = 
ci.check_list_id ";
+               $sql .= "WHERE cl.id = {$check_list_id}";
+               
+               $this->db->query($sql);
+               $this->db->next_record();
+                       
+               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+               
$check_list->set_control_id($this->unmarshal($this->db->f('control_id'), 
'int'));
+               
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
+               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
+               
$check_list->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
+               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));       
+               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int')); 
+                       
+               if($check_list != null)
+               {
+                       return $check_list;
+               }
+               else
+               {
+                       return null;
+               }
+       }
+       
+       /**
+        * Get check lists from database with related check items and control 
items
+        *
+        * @param $check_list_id check list id
+        * @param $status status OPEN/CLOSED
+        * @param $type control items registration type (Radiobuttons, 
Checklist, textfield, just commentfield)
+        * @return returns a check list object
+        */
+       public function get_single_with_check_items($check_list_id, $status, 
$type)
+       {
+               $check_list_id = (int) $check_list_id;
+               $sql  = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.control_id, cl.comment as cl_comment, deadline, planned_date, 
completed_date, num_open_cases, location_code, num_pending_cases, ";
+               $sql .= "ci.id as ci_id, control_item_id, check_list_id, "; 
+               $sql .= "coi.title as coi_title, coi.required as coi_required, 
";
+               $sql .= "coi.what_to_do as coi_what_to_do, coi.how_to_do as 
coi_how_to_do, coi.control_group_id as coi_control_group_id, coi.type "; 
+               $sql .= "FROM controller_check_list cl "; 
+               $sql .= "LEFT JOIN controller_check_item as ci ON cl.id = 
ci.check_list_id ";
+               $sql .= "LEFT JOIN controller_control_item as coi ON 
ci.control_item_id = coi.id ";
+               $sql .= "WHERE cl.id = {$check_list_id} ";
+               
+               if($status == 'open')
+               {
+                       $sql .= "AND ci.status = 0 ";
+               }
+               else if($status == 'handled')
+               {
+                       $sql .= "AND ci.status = 1 ";
+               }
+                       
+               if($type != null)
+               {
+                       $sql .= "AND coi.type = '$type'";
+               }                                       
 
-  /**
-   * Get a static reference to the storage object associated with this model 
object
-   *
-   * @return controller_socheck_list the storage object
-   */
-  public static function get_instance() {
-    if (self::$so == null) {
-      self::$so = CreateObject('controller.socheck_list');
-    }
-    return self::$so;
-  }
+               $this->db->query($sql);
+               
+               $counter = 0;
+               $check_list = null;
+               while ($this->db->next_record())
+               {
+                       if($counter == 0)
+                       {
+                               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'bool'));
+                               
$check_list->set_control_id($this->unmarshal($this->db->f('control_id'), 
'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));       
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       }
+                                               
+                       if($this->db->f('ci_id'))
+                       {
+                               $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
+                               
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
+                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                               
+                               $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
+                               
$control_item->set_title($this->db->f('coi_title', true), 'string');
+                               
$control_item->set_required($this->db->f('coi_required', true), 'string');
+                               
$control_item->set_what_to_do($this->db->f('coi_what_to_do', true), 'string');
+                               
$control_item->set_how_to_do($this->db->f('coi_how_to_do', true), 'string');
+                               
$control_item->set_control_group_id($this->db->f('coi_control_group_id', true), 
'string');
+                               $control_item->set_type($this->db->f('type', 
true), 'string');
+                               
+                               
$check_item->set_control_item($control_item->toArray());
+                               $check_items_array[] = $check_item->toArray();
+                       }
+                       
+                       $counter++;
+               }
+               
+               if($check_list != null)
+               {
+                       $check_list->set_check_item_array($check_items_array);
+                       return $check_list->toArray();
+               }
+               else
+               {
+                       return null;
+               }
+       }
+       
+       /**
+        * Get check list objects for a control
+        *
+        * @param $control_id
+        * @return array with check list objects
+        */
+       function get_check_lists_for_control($control_id)
+       {
+               $control_id = (int) $control_id;
 
-  /**
-   * Get a check list and related check_items and returns it as an object
-   *
-   * @param $check_list_id
-   * @return check list object
-   */
-  public function get_single($check_list_id) {
-    $check_list_id = (int) $check_list_id;
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.control_id, 
cl.comment as cl_comment, deadline, planned_date, ";
-    $sql .= "completed_date, location_code, component_id, num_open_cases, 
num_pending_cases, location_id, ci.id as ci_id, control_item_id ";
-    $sql .= "FROM controller_check_list cl ";
-    $sql .= "LEFT JOIN controller_check_item as ci ON cl.id = ci.check_list_id 
";
-    $sql .= "WHERE cl.id = {$check_list_id}";
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, component_id, location_code, 
num_open_cases, num_pending_cases ";
+               $sql .= "ci.id as ci_id, control_item_id, check_list_id ";
+               $sql .= "FROM controller_check_list cl, controller_check_item 
ci ";
+               $sql .= "WHERE cl.control_id = {$control_id} ";
+               $sql .= "AND cl.id = ci.check_list_id "; 
+               $sql .= "ORDER BY cl.id;";
 
-    $this->db->query($sql);
-    $this->db->next_record();
+               $this->db->query($sql);
+               
+               $check_list_id = 0;
+               $check_list = null;
+               while ($this->db->next_record())
+               {
+                       if( $this->db->f('cl_id') != $check_list_id )
+                       {
+                               if( $check_list_id )
+                               {
+                                       
$check_list->set_check_item_array($check_items_array);
+                                       $check_list_array[] = 
$check_list->toArray();
+                               }
+                               
+                               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                               
+                               $check_items_array = array();
+                       }
+                       
+                       $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
+                       
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
+                       
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+                       $check_items_array[] = $check_item->toArray();
+                       
+                       $check_list_id =  $check_list->get_id();
+               }
+               
+               if($check_list != null)
+               {
+                       $check_list->set_check_item_array($check_items_array);
+                       $check_list_array[] = $check_list->toArray();
+               
+                       return $check_list_array;
+               }
+               else
+               {
+                       return null;
+               }
+       }
+       
+       function get_check_list_for_control_by_date($control_id, $deadline_ts, 
$status = null, $location_code, $location_id, $component_id, $type)
+       {
+         $sql  = "SELECT * "; 
+               $sql .= "FROM controller_check_list ";
+               $sql .= "WHERE control_id = {$control_id} ";
+               $sql .= "AND deadline = {$deadline_ts}";                
 
-    $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-    $check_list->set_control_id($this->unmarshal($this->db->f('control_id'), 
'int'));
-    $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-    $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-    $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-    
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-    
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-    
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-    
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
-    $check_list->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-    
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-    
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+               if($type == "location")
+               {
+                       $sql .= "AND location_code = '{$location_code}' ";      
+               }
+               else if($type == "component")
+               {
+                       $sql .= "AND location_id = '{$location_id}' AND 
component_id = '{$component_id}' ";
+               }
+               
+               if($status != null)
+               {
+                       $sql .= "AND status = {$status} ";
+               }
 
-    if ($check_list != null) {
-      return $check_list;
-    } else {
-      return null;
-    }
-  }
+               $this->db->query($sql);
+               
+               $check_list = null;
+               if( $this->db->next_record() )
+               {
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('id'), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('status'), 'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('comment'), 'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));       
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+               }
+                               
+               return $check_list;
+       }
+       
+       /**
+        * Get check list objects for a control on a location with set planned 
date
+        *
+        * @param $control_id control id
+        * @param $location_code location code representing physical locations
+        * @param $location_id location id representing logical system locations
+        * @param $component_id component id: entity within logical location
+        * @return array with check list objects
+        */
+       function get_planned_check_lists_for_control($control_id, 
$location_code,$location_id, $component_id)
+       {
+               $control_id = (int) $control_id;
+               
+               $component_filter = ' AND component_id IS NULL ';
+               if($component_id)
+               {
+                       $location_id = (int)$location_id;
+                       $component_id = (int)$component_id;
+                       $component_filter = " AND component_id = 
{$component_id} AND location_id = {$location_id} ";
+               }
 
-  /**
-   * Get check lists from database with related check items and control items
-   *
-   * @param $check_list_id check list id
-   * @param $status status OPEN/CLOSED
-   * @param $type control items registration type (Radiobuttons, Checklist, 
textfield, just commentfield)
-   * @return returns a check list object
-   */
-  public function get_single_with_check_items($check_list_id, $status, $type) {
-    $check_list_id = (int) $check_list_id;
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.control_id, 
cl.comment as cl_comment, deadline, planned_date, completed_date, 
num_open_cases, location_code, num_pending_cases, ";
-    $sql .= "ci.id as ci_id, control_item_id, check_list_id, ";
-    $sql .= "coi.title as coi_title, coi.required as coi_required, ";
-    $sql .= "coi.what_to_do as coi_what_to_do, coi.how_to_do as coi_how_to_do, 
coi.control_group_id as coi_control_group_id, coi.type ";
-    $sql .= "FROM controller_check_list cl ";
-    $sql .= "LEFT JOIN controller_check_item as ci ON cl.id = ci.check_list_id 
";
-    $sql .= "LEFT JOIN controller_control_item as coi ON ci.control_item_id = 
coi.id ";
-    $sql .= "WHERE cl.id = {$check_list_id} ";
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, component_id, location_code, 
num_open_cases, num_pending_cases ";
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "WHERE cl.control_id = {$control_id} ";
+               $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND NOT cl.planned_date IS NULL ";
+               $sql .= "AND cl.completed_date IS NULL ";
+               $sql .= $component_filter;
+               $sql .= "ORDER BY cl.id;";
 
-    if ($status == 'open') {
-      $sql .= "AND ci.status = 0 ";
-    } else if ($status == 'handled') {
-      $sql .= "AND ci.status = 1 ";
-    }
+               $this->db->query($sql);
+               
+               $check_list_id = 0;
+               $check_list = null;
+               while ($this->db->next_record())
+               {
+                       if( $this->db->f('cl_id') != $check_list_id )
+                       {
+                               if($check_list_id)
+                               {
+                                       $check_list_array[] = $check_list;
+                               }
+                               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment'), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));       
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       }
+                       $check_list_id =  $check_list->get_id();
+               }
+               
+               if($check_list != null)
+               {
+                       $check_list_array[] = $check_list;
+                       return $check_list_array;
+               }
+               else
+               {
+                       return null;
+               }
+       }
+                
+       /**
+        * Get check list objects for a control on a location after specitied 
date
+        *
+        * @param $control_id control id
+        * @param $location_code location code
+        * @return array with check list objects
+        */
+       function get_open_check_lists_for_control($control_id, $location_code, 
$from_date)
+       {
+               $control_id = (int) $control_id;
 
-    if ($type != null) {
-      $sql .= "AND coi.type = '$type'";
-    }
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, component_id, location_code, 
num_open_cases, num_pending_cases ";
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "WHERE cl.control_id = {$control_id} ";
+               $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND (cl.planned_date IS NULL OR cl.planned_date < 
$from_date) ";
+               $sql .= "AND cl.deadline < $from_date ";
+               $sql .= "AND cl.completed_date IS NULL ";
+               $sql .= "ORDER BY cl.id;";
+               
+               $this->db->query($sql);
+               
+               $check_list_id = 0;
+               $check_list = null;
+               while ($this->db->next_record())
+               {
+               
+                       if( $this->db->f('cl_id') != $check_list_id )
+                       {
+                               if($check_list_id)
+                               {
+                                       $check_list_array[] = $check_list;
+                               }
+                               
+                               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));       
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       }
+                       $check_list_id =  $check_list->get_id();
+               }
+               
+               if($check_list != null)
+               {
+                       $check_list_array[] = $check_list;
+                       return $check_list_array;
+               }
+               else
+               {
+                       return null;
+               }
+       }
+       
+       /**
+        * Get array with control id and number of open cases within time period
+        *
+        * @param $cl_criteria check list criteria object
+        * @param $from_date start time period
+        * @param $to_date end time period
+        * @return array with check list objects
+        */
+       function get_num_open_cases_for_control( $cl_criteria, $from_date_ts, 
$to_date_ts )
+       {
+               
+               $sql =  "SELECT c.id as c_id, sum(cl.num_open_cases) as count ";
+               $sql .= "FROM controller_check_list cl, controller_control c ";
+               
+               if($cl_criteria->get_component_id() > 0 && 
$cl_criteria->get_location_id() > 0)
+               {
+                   $sql .= "WHERE cl.component_id = 
{$cl_criteria->get_component_id()} ";
+                   $sql .= "AND cl.location_id = 
{$cl_criteria->get_location_id()} ";
+               }
+               else
+               {
+                   $sql .= "WHERE cl.location_code = 
'{$cl_criteria->get_location_code()}' ";
+               }
+               
+               $sql .= "AND c.id = {$cl_criteria->get_control_id()} ";
+               $sql .= "AND cl.control_id = c.id ";
+               $sql .= "AND cl.deadline >= $from_date_ts AND $to_date_ts > 
cl.deadline ";
+               $sql .= "GROUP BY c.id";
+               
+               $this->db->query($sql);
+               
+               if ($this->db->next_record() & $this->db->f('count') > 0)
+               {
+                       $control_array = array
+                       (
+                               "id"    => 
$this->unmarshal($this->db->f('c_id'), 'int'),
+                               "count" => $this->db->f('count')
+                       );
+               }
+               
+               return $control_array;
+       }
+       
+       /**
+        * Get array with check lists for a location within time period and for 
a specified repeat type
+        *
+        * @param $location_code location code
+        * @param $from_date_ts start time period
+        * @param $to_date_ts end time period
+        * @param $repeat_type_expr repeat type expression
+        * @return array with check list objects
+        */
+       function get_check_lists_for_location( $location_code, $from_date_ts, 
$to_date_ts, $repeat_type_expr = null )
+       {
+               $sql =  "SELECT c.id as c_id, ";
+               $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id as cl_component_id, cl.location_code 
as cl_location_code, num_open_cases, num_pending_cases "; 
+               $sql .= "FROM controller_control c ";
+               $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = 
c.id ";
+               $sql .= "WHERE cl.location_code = '{$location_code}' ";
+               
+               if( $repeat_type != null )
+               {
+                       $sql .= "AND c.repeat_type $repeat_type_expr ";
+               }
+               
+               $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
+               $sql .= "ORDER BY c.id;";
+               
+               $this->db->query($sql);
+               
+               $control_id = 0;
+               $control = null;
+               $controls_array = array();
+               while ($this->db->next_record())
+               {
+                       if( $this->db->f('c_id') != $control_id )
+                       {       
+                               if($control_id)
+                               {
+                                       
$control->set_check_lists_array($check_lists_array);
+                                       $controls_array[] = $control;
+                               }
+                       
+                               $control = new 
controller_control($this->unmarshal($this->db->f('c_id'), 'int'));
+                                                                               
                
+                               $check_lists_array = array();
+                       }
 
-    $this->db->query($sql);
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 
'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       
+                       $check_lists_array[] = $check_list;
 
-    $counter = 0;
-    $check_list = null;
-    while ($this->db->next_record()) {
-      if ($counter == 0) {
-        $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-        $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'bool'));
-        
$check_list->set_control_id($this->unmarshal($this->db->f('control_id'), 
'int'));
-        $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-        $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-        
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-        
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-        
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-        
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-        
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-      }
+                       $control_id =  $control->get_id();
+               }
+               
+               if($control != null)
+               {
+                       $control->set_check_lists_array($check_lists_array);
+                       $controls_array[] = $control;
+               }       
+               
+               return $controls_array;
+       }
+       
+       /**
+        * Get array with check lists for a component within time period and 
for a specified repeat type
+        *
+        * @param $location_code location code
+        * @param $from_date_ts start time period
+        * @param $to_date_ts end time period
+        * @param $repeat_type_expr repeat type expression
+        * @return array with check list objects
+        */
+       function get_check_lists_for_component( $location_id, $component_id, 
$from_date_ts, $to_date_ts, $repeat_type_expr = null )
+       {
+               $location_id = (int) $location_id;
+               $component_id = (int) $component_id;
 
-      if ($this->db->f('ci_id')) {
-        $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
-        
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
-        
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
+               $sql =  "SELECT c.id as c_id, ";
+               $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id, cl.location_id, cl.location_code as 
cl_location_code, num_open_cases, num_pending_cases "; 
+               $sql .= "FROM controller_control c ";
+               $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = 
c.id ";
+               $sql .= "WHERE cl.location_id = {$location_id} ";
+               $sql .= "AND cl.component_id = {$component_id} ";
+               
+               if( $repeat_type != null )
+               {
+                       $sql .= "AND c.repeat_type $repeat_type_expr ";
+               }
+               
+               $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
+               $sql .= "ORDER BY c.id;";
+               
+               $this->db->query($sql);
+               
+               $control_id = 0;
+               $control = null;
+               $controls_array = array();
+               while ($this->db->next_record())
+               {
+                       if( $this->db->f('c_id') != $control_id )
+                       {
+                               if($control_id != 0)
+                               {
+                                       
$control->set_check_lists_array($check_lists_array);
+                                       $controls_array[] = $control;
+                               }
 
-        $control_item = new 
controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
-        $control_item->set_title($this->db->f('coi_title', true), 'string');
-        $control_item->set_required($this->db->f('coi_required', true), 
'string');
-        $control_item->set_what_to_do($this->db->f('coi_what_to_do', true), 
'string');
-        $control_item->set_how_to_do($this->db->f('coi_how_to_do', true), 
'string');
-        
$control_item->set_control_group_id($this->db->f('coi_control_group_id', true), 
'string');
-        $control_item->set_type($this->db->f('type', true), 'string');
+                               $control = new 
controller_control($this->unmarshal($this->db->f('c_id'), 'int'));
+                                                                               
                
+                               $check_lists_array = array();
+                       }
 
-        $check_item->set_control_item($control_item->toArray());
-        $check_items_array[] = $check_item->toArray();
-      }
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
+                       
$check_list->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       
+                       $check_lists_array[] = $check_list;
 
-      $counter++;
-    }
+                       $control_id =  $control->get_id();
+               }
+               
+               if($control != null)
+               {
+                       $control->set_check_lists_array($check_lists_array);
+                       $controls_array[] = $control;
+               }       
+               
+               return $controls_array;
+       }
+       
+       /**
+        * Get array with check lists for a control on a location within time 
period and for a specified repeat type
+        *
+        * @param $control_id control id
+        * @param $location_code location code
+        * @param $from_date_ts start time period
+        * @param $to_date_ts end time period
+        * @param $repeat_type_expr repeat type expression
+        * @return array with check list objects
+       */
+       function get_check_lists_for_control_and_location( $control_id, 
$location_code, $from_date_ts, $to_date_ts, $repeat_type = null )
+       {
+               $control_id = (int) $control_id;
 
-    if ($check_list != null) {
-      $check_list->set_check_item_array($check_items_array);
-      return $check_list->toArray();
-    } else {
-      return null;
-    }
-  }
+               $sql =  "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id as cl_component_id, cl.location_code 
as cl_location_code, num_open_cases, num_pending_cases "; 
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "LEFT JOIN controller_control c on cl.control_id = c.id 
";
+               $sql .= "WHERE cl.control_id = {$control_id} ";
+               $sql .= "AND cl.location_code = '{$location_code}' ";
+               
+               if( $repeat_type != null )
+               {
+                       $sql .= "AND c.repeat_type = $repeat_type ";
+               }
+               
+               $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
+               
+               $this->db->query($sql);
+               
+               while ($this->db->next_record())
+               {
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 
'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       
+                       $check_lists_array[] = $check_list;
+               }
+               
+               return array( "location_code" => $location_code, 
"check_lists_array" => $check_lists_array);
+       }
+       
+       /**
+        * Get array with check lists for a control on a component within time 
period and for a specified repeat type
+        *
+        * @param $control_id control id
+        * @param $location_code location code
+        * @param $from_date_ts start time period
+        * @param $to_date_ts end time period
+        * @param $repeat_type_expr repeat type expression
+        * @return array with check list objects
+       */
+       function get_check_lists_for_control_and_component( $control_id, 
$location_id, $component_id, $from_date_ts, $to_date_ts, $repeat_type = null )
+       {
+               $control_id = (int) $control_id;
+               $location_id = (int) $location_id;
+               $component_id = (int) $component_id;
 
-  /**
-   * Get check list objects for a control
-   *
-   * @param $control_id
-   * @return array with check list objects
-   */
-  function get_check_lists_for_control($control_id) {
-    $control_id = (int) $control_id;
+               $sql =  "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id as cl_component_id, cl.location_id as 
cl_location_id, cl.location_code as cl_location_code, num_open_cases, 
num_pending_cases "; 
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "LEFT JOIN controller_control c on cl.control_id = c.id 
";
+               $sql .= "WHERE cl.control_id = {$control_id} ";
+               $sql .= "AND cl.component_id = {$component_id} ";
+               $sql .= "AND cl.location_id = {$location_id} ";
+               
+               if( $repeat_type != null )
+               {
+                       $sql .= "AND c.repeat_type = $repeat_type ";
+               }
+               
+               $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
+               
+               $this->db->query($sql);
+               
+               while ($this->db->next_record())
+               {
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));       
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 
'int'));
+                       
$check_list->set_location_id($this->unmarshal($this->db->f('cl_location_id'), 
'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+                       
+                       $check_lists_array[] = $check_list;
+               }
+               
+               return array( "location_code" => $location_code, 
"check_lists_array" => $check_lists_array);
+       }
+       
+/* Denne ser det ikke ut til at vi bruker: Torstein 9/7-12 
+       function get_check_list_for_date($control_id, $current_date){
+               $sql =  "SELECT c.id as c_id, title, description, start_date, 
end_date, control_area_id, c.location_code as c_location_code, repeat_type, 
repeat_interval, ";
+               $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id as cl_component_id, cl.location_code 
as cl_location_code, num_open_cases, num_pending_cases "; 
+               $sql .= "FROM controller_control c ";
+               $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = 
c.id ";
+               $sql .= "WHERE c.id = {$control_id} "; 
+               $sql .= "AND NOT planned_date IS NULL ";
 
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, ";
-    $sql .= "completed_date, component_id, location_code, num_open_cases, 
num_pending_cases ";
-    $sql .= "ci.id as ci_id, control_item_id, check_list_id ";
-    $sql .= "FROM controller_check_list cl, controller_check_item ci ";
-    $sql .= "WHERE cl.control_id = {$control_id} ";
-    $sql .= "AND cl.id = ci.check_list_id ";
-    $sql .= "ORDER BY cl.id;";
+               $this->db->query($sql);
+               
+               $check_lists_array = array();
+               while ($this->db->next_record()) {
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+                       $check_list->set_control_id($control_id);
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int')); 
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id', 
true), 'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
+                       
+                       $check_lists_array[] = $check_list;
+               }
 
-    $this->db->query($sql);
+               return $check_lists_array;
+       }
+       */
+       
+       function get_query(string $sort_field, boolean $ascending, string 
$search_for, string $search_type, array $filters, boolean $return_count)
+       {
+               $current_time = time();
+               $buffer_in_days = 3600*24*7*5;
+               $buffer_time = $current_time - $buffer_in_days;
 
-    $check_list_id = 0;
-    $check_list = null;
-    while ($this->db->next_record()) {
-      if ($this->db->f('cl_id') != $check_list_id) {
-        if ($check_list_id) {
-          $check_list->set_check_item_array($check_items_array);
-          $check_list_array[] = $check_list->toArray();
-        }
+               $clauses = array('1=1');
+               $clauses[] = "{$current_time} >= p.start_date AND p.start_date 
> {$buffer_time}"; 
+               
+               $filter_clauses = array();
+               
+               // Search for based on search type
+               if($search_for)
+               {
+                       $search_for = $this->marshal($search_for,'field');
+                       $like_pattern = "'%".$search_for."%'";
+                       $like_clauses = array();
+                       switch($search_type)
+                       {
+                               default:
+                                       $like_clauses[] = "p.title $this->like 
$like_pattern";
+                                       break;
+                       }
+                       
+                       if(count($like_clauses))
+                       {
+                               $clauses[] = '(' . join(' OR ', $like_clauses) 
. ')';
+                       }
+               }
+               
+               if(isset($filters[$this->get_id_field_name()]))
+               {
+                       $filter_clauses[] = "p.id = 
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
+               }
+               
+               if(count($filter_clauses))
+               {
+                       $clauses[] = join(' AND ', $filter_clauses);
+               }
+               
+               $condition =  join(' AND ', $clauses);
 
-        $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-        $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-        $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-        $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-        
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-        
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-        
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
-        
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-        
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-        
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
+               $tables = "controller_control p";
+               
+               if($return_count)
+               {
+                       $cols = 'COUNT(DISTINCT(p.id)) AS count';
+               }
+               else
+               {
+                       $cols = 'p.* ';
+               }
+               
+               $dir = $ascending ? 'ASC' : 'DESC';
+               if($sort_field == 'id')
+               {
+                       $sort_field = 'p.id';
+               }
+               $order = $sort_field ? "ORDER BY {$this->marshal($sort_field, 
'field')} $dir ": '';
+               
+               return "SELECT {$cols} FROM {$tables} {$joins} WHERE 
{$condition} {$order}";
+       }
 
-        $check_items_array = array();
-      }
+       function populate(int $control_id, &$control)
+       {
+               if($control == null)
+               {
+                       $start_date = date("d.m.Y",  
$this->db->f('start_date'));
+                       $end_date = date("d.m.Y",  $this->db->f('end_date'));
+                       $control = new controller_control((int) $control_id);
 
-      $check_item = new 
controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
-      
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'),
 'int'));
-      
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 
'int'));
-      $check_items_array[] = $check_item->toArray();
+                       
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+                       
$control->set_description($this->unmarshal($this->db->f('description', true), 
'string'));
+                       $control->set_start_date($start_date);
+                       $control->set_end_date($end_date);
+                       
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id'), 
'int'));
+                       
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name', 
true), 'string'));
+                       
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id'), 
'int'));
+                       
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id'),
 'int'));
+                       
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id'),
 'int'));
+                       
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id'), 
'int'));
+                       
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
+                       
$control->set_equipment_type_id($this->unmarshal($this->db->f('equipment_type_id'),
 'int'));
+                       
$control->set_equipment_id($this->unmarshal($this->db->f('equipment_id'), 
'int'));
+                       
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                       
$control->set_location_id($this->unmarshal($this->db->f('location_id'), 
'string'));
+                       
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type'), 'int'));
+                       
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval'), 
'int'));
+               }
+               
+               return $control;
+       }
+       
+       function add(&$check_list)
+       {
+               $cols = array(
+                               'control_id',
+                               'comment',
+                               'deadline',
+                               'planned_date',
+                               'completed_date',
+                               'component_id',
+                               'location_code',
+                               'num_open_cases',
+                               'num_pending_cases',
+                               'location_id',
+                               'status'
+               );
+                               
+               $values = array(
+                       $this->marshal($check_list->get_control_id(), 'int'),
+                       $this->marshal($check_list->get_comment(), 'string'),
+                       $this->marshal($check_list->get_deadline(), 'int'),
+                       $this->marshal($check_list->get_planned_date(), 'int'),
+                       $this->marshal($check_list->get_completed_date(), 
'int'),
+                       $this->marshal($check_list->get_component_id(), 'int'),
+                       $this->marshal($check_list->get_location_code(), 
'string'),
+                       $this->marshal($check_list->get_num_open_cases(), 
'int'),
+                       $this->marshal($check_list->get_num_pending_cases(), 
'int'),
+                       $this->marshal($check_list->get_location_id(), 'int'),
+                       $check_list->get_status()
+               );
+               
+               $result = $this->db->query('INSERT INTO controller_check_list 
(' . join(',', $cols) . ') VALUES (' . join(',', $values) . ')', 
__LINE__,__FILE__);
+                       
+               return isset($result) ? 
$this->db->get_last_insert_id('controller_check_list', 'id') : 0;
+       }
+       
+       function update($check_list)
+       {
+               $id = intval($check_list->get_id());
 
-      $check_list_id = $check_list->get_id();
-    }
+               $values = array(
+                       'control_id = ' . 
$this->marshal($check_list->get_control_id(), 'int'),
+                       'status = ' . $check_list->get_status(),
+                       'comment = ' . 
$this->marshal($check_list->get_comment(), 'string'),
+                       'deadline = ' . 
$this->marshal($check_list->get_deadline(), 'int'),
+                       'planned_date = ' . 
$this->marshal($check_list->get_planned_date(), 'int'),
+                       'completed_date = ' . 
$this->marshal($check_list->get_completed_date(), 'int'),
+                       'location_code = ' . 
$this->marshal($check_list->get_location_code(), 'string'),
+                       'component_id = ' . 
$this->marshal($check_list->get_component_id(), 'int'),
+                       'location_id = ' . 
$this->marshal($check_list->get_location_id(), 'int'),
+                       'num_open_cases = ' . 
$this->marshal($check_list->get_num_open_cases(), 'int'),
+                       'num_pending_cases = ' . 
$this->marshal($check_list->get_num_pending_cases(), 'int')
+               );
 
-    if ($check_list != null) {
-      $check_list->set_check_item_array($check_items_array);
-      $check_list_array[] = $check_list->toArray();
+               $result = $this->db->query('UPDATE controller_check_list SET ' 
. join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
 
-      return $check_list_array;
-    } else {
-      return null;
-    }
-  }
-
-  function get_check_list_for_control_by_date($control_id, $deadline_ts, 
$status = null, $location_code, $location_id, $component_id, $type) {
-    $sql = "SELECT * ";
-    $sql .= "FROM controller_check_list ";
-    $sql .= "WHERE control_id = {$control_id} ";
-    $sql .= "AND deadline = {$deadline_ts}";
-
-    if ($type == "location") {
-      $sql .= "AND location_code = '{$location_code}' ";
-    } else if ($type == "component") {
-      $sql .= "AND location_id = '{$location_id}' AND component_id = 
'{$component_id}' ";
-    }
-
-    if ($status != null) {
-      $sql .= "AND status = {$status} ";
-    }
-
-    $this->db->query($sql);
-
-    $check_list = null;
-    if ($this->db->next_record()) {
-      $check_list = new 
controller_check_list($this->unmarshal($this->db->f('id'), 'int'));
-      $check_list->set_status($this->unmarshal($this->db->f('status'), 'int'));
-      $check_list->set_comment($this->unmarshal($this->db->f('comment'), 
'string'));
-      $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-      
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-      
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-      
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
-      
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-      
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-      
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-    }
-
-    return $check_list;
-  }
-
-  /**
-   * Get check list objects for a control on a location with set planned date
-   *
-   * @param $control_id control id
-   * @param $location_code location code representing physical locations
-   * @param $location_id location id representing logical system locations
-   * @param $component_id component id: entity within logical location
-   * @return array with check list objects
-   */
-  function get_planned_check_lists_for_control($control_id, $location_code, 
$location_id, $component_id) {
-    $control_id = (int) $control_id;
-
-    $component_filter = ' AND component_id IS NULL ';
-    if ($component_id) {
-      $location_id = (int) $location_id;
-      $component_id = (int) $component_id;
-      $component_filter = " AND component_id = {$component_id} AND location_id 
= {$location_id} ";
-    }
-
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, ";
-    $sql .= "completed_date, component_id, location_code, num_open_cases, 
num_pending_cases ";
-    $sql .= "FROM controller_check_list cl ";
-    $sql .= "WHERE cl.control_id = {$control_id} ";
-    $sql .= "AND cl.location_code = '{$location_code}' ";
-    $sql .= "AND NOT cl.planned_date IS NULL ";
-    $sql .= "AND cl.completed_date IS NULL ";
-    $sql .= $component_filter;
-    $sql .= "ORDER BY cl.id;";
-
-    $this->db->query($sql);
-
-    $check_list_id = 0;
-    $check_list = null;
-    while ($this->db->next_record()) {
-      if ($this->db->f('cl_id') != $check_list_id) {
-        if ($check_list_id) {
-          $check_list_array[] = $check_list;
-        }
-        $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-        $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-        $check_list->set_comment($this->unmarshal($this->db->f('cl_comment'), 
'string'));
-        $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-        
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-        
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-        
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
-        
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-        
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-        
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-      }
-      $check_list_id = $check_list->get_id();
-    }
-
-    if ($check_list != null) {
-      $check_list_array[] = $check_list;
-      return $check_list_array;
-    } else {
-      return null;
-    }
-  }
-
-  /**
-   * Get check list objects for a control on a location after specitied date
-   *
-   * @param $control_id control id
-   * @param $location_code location code
-   * @return array with check list objects
-   */
-  function get_open_check_lists_for_control($control_id, $location_code, 
$from_date) {
-    $control_id = (int) $control_id;
-
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, ";
-    $sql .= "completed_date, component_id, location_code, num_open_cases, 
num_pending_cases ";
-    $sql .= "FROM controller_check_list cl ";
-    $sql .= "WHERE cl.control_id = {$control_id} ";
-    $sql .= "AND cl.location_code = '{$location_code}' ";
-    $sql .= "AND (cl.planned_date IS NULL OR cl.planned_date < $from_date) ";
-    $sql .= "AND cl.deadline < $from_date ";
-    $sql .= "AND cl.completed_date IS NULL ";
-    $sql .= "ORDER BY cl.id;";
-
-    $this->db->query($sql);
-
-    $check_list_id = 0;
-    $check_list = null;
-    while ($this->db->next_record()) {
-
-      if ($this->db->f('cl_id') != $check_list_id) {
-        if ($check_list_id) {
-          $check_list_array[] = $check_list;
-        }
-
-        $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-        $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-        $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-        $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-        
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-        
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-        
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
-        
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-        
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-        
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-      }
-      $check_list_id = $check_list->get_id();
-    }
-
-    if ($check_list != null) {
-      $check_list_array[] = $check_list;
-      return $check_list_array;
-    } else {
-      return null;
-    }
-  }
-
-  /**
-   * Get array with control id and number of open cases within time period
-   *
-   * @param $cl_criteria check list criteria object
-   * @param $from_date start time period
-   * @param $to_date end time period
-   * @return array with check list objects
-   */
-  function get_num_open_cases_for_control($cl_criteria, $from_date_ts, 
$to_date_ts) {
-
-    $sql = "SELECT c.id as c_id, sum(cl.num_open_cases) as count ";
-    $sql .= "FROM controller_check_list cl, controller_control c ";
-
-    if ($cl_criteria->get_component_id() > 0 && 
$cl_criteria->get_location_id() > 0) {
-      $sql .= "WHERE cl.component_id = {$cl_criteria->get_component_id()} ";
-      $sql .= "AND cl.location_id = {$cl_criteria->get_location_id()} ";
-    } else {
-      $sql .= "WHERE cl.location_code = '{$cl_criteria->get_location_code()}' 
";
-    }
-
-    $sql .= "AND c.id = {$cl_criteria->get_control_id()} ";
-    $sql .= "AND cl.control_id = c.id ";
-    $sql .= "AND cl.deadline >= $from_date_ts AND $to_date_ts > cl.deadline ";
-    $sql .= "GROUP BY c.id";
-
-    $this->db->query($sql);
-
-    if ($this->db->next_record() & $this->db->f('count') > 0) {
-      $control_array = array
-          (
-          "id" => $this->unmarshal($this->db->f('c_id'), 'int'),
-          "count" => $this->db->f('count')
-      );
-    }
-
-    return $control_array;
-  }
-
-  /**
-   * Get array with check lists for a location within time period and for a 
specified repeat type
-   *
-   * @param $location_code location code
-   * @param $from_date_ts start time period
-   * @param $to_date_ts end time period
-   * @param $repeat_type_expr repeat type expression
-   * @return array with check list objects
-   */
-  function get_check_lists_for_location($location_code, $from_date_ts, 
$to_date_ts, $repeat_type_expr = null) {
-    $sql = "SELECT c.id as c_id, ";
-    $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as cl_comment, 
deadline, planned_date, completed_date, ";
-    $sql .= "cl.component_id as cl_component_id, cl.location_code as 
cl_location_code, num_open_cases, num_pending_cases ";
-    $sql .= "FROM controller_control c ";
-    $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = c.id ";
-    $sql .= "WHERE cl.location_code = '{$location_code}' ";
-
-    if ($repeat_type != null) {
-      $sql .= "AND c.repeat_type $repeat_type_expr ";
-    }
-
-    $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
-    $sql .= "ORDER BY c.id;";
-
-    $this->db->query($sql);
-
-    $control_id = 0;
-    $control = null;
-    $controls_array = array();
-    while ($this->db->next_record()) {
-      if ($this->db->f('c_id') != $control_id) {
-        if ($control_id) {
-          $control->set_check_lists_array($check_lists_array);
-          $controls_array[] = $control;
-        }
-
-        $control = new 
controller_control($this->unmarshal($this->db->f('c_id'), 'int'));
-
-        $check_lists_array = array();
-      }
-
-      $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-      $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-      $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-      $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-      
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-      
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-      
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 
'int'));
-      
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
-      
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-      
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-
-      $check_lists_array[] = $check_list;
-
-      $control_id = $control->get_id();
-    }
-
-    if ($control != null) {
-      $control->set_check_lists_array($check_lists_array);
-      $controls_array[] = $control;
-    }
-
-    return $controls_array;
-  }
-
-  /**
-   * Get array with check lists for a component within time period and for a 
specified repeat type
-   *
-   * @param $location_code location code
-   * @param $from_date_ts start time period
-   * @param $to_date_ts end time period
-   * @param $repeat_type_expr repeat type expression
-   * @return array with check list objects
-   */
-  function get_check_lists_for_component($location_id, $component_id, 
$from_date_ts, $to_date_ts, $repeat_type_expr = null) {
-    $location_id = (int) $location_id;
-    $component_id = (int) $component_id;
-
-    $sql = "SELECT c.id as c_id, ";
-    $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as cl_comment, 
deadline, planned_date, completed_date, ";
-    $sql .= "cl.component_id, cl.location_id, cl.location_code as 
cl_location_code, num_open_cases, num_pending_cases ";
-    $sql .= "FROM controller_control c ";
-    $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = c.id ";
-    $sql .= "WHERE cl.location_id = {$location_id} ";
-    $sql .= "AND cl.component_id = {$component_id} ";
-
-    if ($repeat_type != null) {
-      $sql .= "AND c.repeat_type $repeat_type_expr ";
-    }
-
-    $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
-    $sql .= "ORDER BY c.id;";
-
-    $this->db->query($sql);
-
-    $control_id = 0;
-    $control = null;
-    $controls_array = array();
-    while ($this->db->next_record()) {
-      if ($this->db->f('c_id') != $control_id) {
-        if ($control_id != 0) {
-          $control->set_check_lists_array($check_lists_array);
-          $controls_array[] = $control;
-        }
-
-        $control = new 
controller_control($this->unmarshal($this->db->f('c_id'), 'int'));
-
-        $check_lists_array = array();
-      }
-
-      $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-      $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-      $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-      $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-      
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-      
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-      
$check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 
'int'));
-      
$check_list->set_location_id($this->unmarshal($this->db->f('location_id'), 
'int'));
-      
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
-      
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-      
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-
-      $check_lists_array[] = $check_list;
-
-      $control_id = $control->get_id();
-    }
-
-    if ($control != null) {
-      $control->set_check_lists_array($check_lists_array);
-      $controls_array[] = $control;
-    }
-
-    return $controls_array;
-  }
-
-  /**
-   * Get array with check lists for a control on a location within time period 
and for a specified repeat type
-   *
-   * @param $control_id control id
-   * @param $location_code location code
-   * @param $from_date_ts start time period
-   * @param $to_date_ts end time period
-   * @param $repeat_type_expr repeat type expression
-   * @return array with check list objects
-   */
-  function get_check_lists_for_control_and_location($control_id, 
$location_code, $from_date_ts, $to_date_ts, $repeat_type = null) {
-    $control_id = (int) $control_id;
-
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";
-    $sql .= "cl.component_id as cl_component_id, cl.location_code as 
cl_location_code, num_open_cases, num_pending_cases ";
-    $sql .= "FROM controller_check_list cl ";
-    $sql .= "LEFT JOIN controller_control c on cl.control_id = c.id ";
-    $sql .= "WHERE cl.control_id = {$control_id} ";
-    $sql .= "AND cl.location_code = '{$location_code}' ";
-
-    if ($repeat_type != null) {
-      $sql .= "AND c.repeat_type = $repeat_type ";
-    }
-
-    $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
-
-    $this->db->query($sql);
-
-    while ($this->db->next_record()) {
-      $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-      $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-      $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-      $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-      
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-      
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-      
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 
'int'));
-      
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
-      
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-      
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-
-      $check_lists_array[] = $check_list;
-    }
-
-    return array("location_code" => $location_code, "check_lists_array" => 
$check_lists_array);
-  }
-
-  /**
-   * Get array with check lists for a control on a component within time 
period and for a specified repeat type
-   *
-   * @param $control_id control id
-   * @param $location_code location code
-   * @param $from_date_ts start time period
-   * @param $to_date_ts end time period
-   * @param $repeat_type_expr repeat type expression
-   * @return array with check list objects
-   */
-  function get_check_lists_for_control_and_component($control_id, 
$location_id, $component_id, $from_date_ts, $to_date_ts, $repeat_type = null) {
-    $control_id = (int) $control_id;
-    $location_id = (int) $location_id;
-    $component_id = (int) $component_id;
-
-    $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";
-    $sql .= "cl.component_id as cl_component_id, cl.location_id as 
cl_location_id, cl.location_code as cl_location_code, num_open_cases, 
num_pending_cases ";
-    $sql .= "FROM controller_check_list cl ";
-    $sql .= "LEFT JOIN controller_control c on cl.control_id = c.id ";
-    $sql .= "WHERE cl.control_id = {$control_id} ";
-    $sql .= "AND cl.component_id = {$component_id} ";
-    $sql .= "AND cl.location_id = {$location_id} ";
-
-    if ($repeat_type != null) {
-      $sql .= "AND c.repeat_type = $repeat_type ";
-    }
-
-    $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
-
-    $this->db->query($sql);
-
-    while ($this->db->next_record()) {
-      $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int'));
-      $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 
'int'));
-      $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-      $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 
'int'));
-      
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 
'int'));
-      
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'),
 'int'));
-      
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 
'int'));
-      
$check_list->set_location_id($this->unmarshal($this->db->f('cl_location_id'), 
'int'));
-      
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
-      
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'),
 'int'));
-      
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'),
 'int'));
-
-      $check_lists_array[] = $check_list;
-    }
-
-    return array("location_code" => $location_code, "check_lists_array" => 
$check_lists_array);
-  }
-
-  /* Denne ser det ikke ut til at vi bruker: Torstein 9/7-12 
-    function get_check_list_for_date($control_id, $current_date){
-    $sql =     "SELECT c.id as c_id, title, description, start_date, end_date, 
control_area_id, c.location_code as c_location_code, repeat_type, 
repeat_interval, ";
-    $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as cl_comment, 
deadline, planned_date, completed_date, ";
-    $sql .= "cl.component_id as cl_component_id, cl.location_code as 
cl_location_code, num_open_cases, num_pending_cases ";
-    $sql .= "FROM controller_control c ";
-    $sql .= "LEFT JOIN controller_check_list cl on cl.control_id = c.id ";
-    $sql .= "WHERE c.id = {$control_id} ";
-    $sql .= "AND NOT planned_date IS NULL ";
-
-    $this->db->query($sql);
-
-    $check_lists_array = array();
-    while ($this->db->next_record()) {
-    $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
-    $check_list->set_control_id($control_id);
-    $check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'int'));
-    $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', 
true), 'string'));
-    $check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
-    
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
-    
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int'));
-    
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id', 
true), 'int'));
-    
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
-    
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int'));
-    
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
-
-    $check_lists_array[] = $check_list;
-    }
-
-    return $check_lists_array;
-    }
-   */
-
-  function get_query(string $sort_field, boolean $ascending, string 
$search_for, string $search_type, array $filters, boolean $return_count) {
-    $current_time = time();
-    $buffer_in_days = 3600 * 24 * 7 * 5;
-    $buffer_time = $current_time - $buffer_in_days;
-
-    $clauses = array('1=1');
-    $clauses[] = "{$current_time} >= p.start_date AND p.start_date > 
{$buffer_time}";
-
-    $filter_clauses = array();
-
-    // Search for based on search type
-    if ($search_for) {
-      $search_for = $this->marshal($search_for, 'field');
-      $like_pattern = "'%" . $search_for . "%'";
-      $like_clauses = array();
-      switch ($search_type) {
-        default:
-          $like_clauses[] = "p.title $this->like $like_pattern";
-          break;
-      }
-
-      if (count($like_clauses)) {
-        $clauses[] = '(' . join(' OR ', $like_clauses) . ')';
-      }
-    }
-
-    if (isset($filters[$this->get_id_field_name()])) {
-      $filter_clauses[] = "p.id = 
{$this->marshal($filters[$this->get_id_field_name()], 'int')}";
-    }
-
-    if (count($filter_clauses)) {
-      $clauses[] = join(' AND ', $filter_clauses);
-    }
-
-    $condition = join(' AND ', $clauses);
-
-    $tables = "controller_control p";
-
-    if ($return_count) {
-      $cols = 'COUNT(DISTINCT(p.id)) AS count';
-    } else {
-      $cols = 'p.* ';
-    }
-
-    $dir = $ascending ? 'ASC' : 'DESC';
-    if ($sort_field == 'id') {
-      $sort_field = 'p.id';
-    }
-    $order = $sort_field ? "ORDER BY {$this->marshal($sort_field, 'field')} 
$dir " : '';
-
-    return "SELECT {$cols} FROM {$tables} {$joins} WHERE {$condition} 
{$order}";
-  }
-
-  function populate(int $control_id, &$control) {
-    if ($control == null) {
-      $start_date = date("d.m.Y", $this->db->f('start_date'));
-      $end_date = date("d.m.Y", $this->db->f('end_date'));
-      $control = new controller_control((int) $control_id);
-
-      $control->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-      $control->set_description($this->unmarshal($this->db->f('description', 
true), 'string'));
-      $control->set_start_date($start_date);
-      $control->set_end_date($end_date);
-      
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id'), 
'int'));
-      
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name', 
true), 'string'));
-      
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id'), 
'int'));
-      
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id'),
 'int'));
-      
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id'),
 'int'));
-      
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id'), 
'int'));
-      
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
-      
$control->set_equipment_type_id($this->unmarshal($this->db->f('equipment_type_id'),
 'int'));
-      
$control->set_equipment_id($this->unmarshal($this->db->f('equipment_id'), 
'int'));
-      
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
-      $control->set_location_id($this->unmarshal($this->db->f('location_id'), 
'string'));
-      $control->set_repeat_type($this->unmarshal($this->db->f('repeat_type'), 
'int'));
-      
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval'), 
'int'));
-    }
-
-    return $control;
-  }
-
-  function add(&$check_list) {
-    $cols = array(
-        'control_id',
-        'comment',
-        'deadline',
-        'planned_date',
-        'completed_date',
-        'component_id',
-        'location_code',
-        'num_open_cases',
-        'num_pending_cases',
-        'location_id',
-        'status'
-    );
-
-    $values = array(
-        $this->marshal($check_list->get_control_id(), 'int'),
-        $this->marshal($check_list->get_comment(), 'string'),

@@ Diff output truncated at 153600 characters. @@



reply via email to

[Prev in Thread] Current Thread [Next in Thread]