fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [8308]


From: Torstein
Subject: [Fmsystem-commits] [8308]
Date: Thu, 15 Dec 2011 09:02:10 +0000

Revision: 8308
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8308
Author:   vator
Date:     2011-12-15 09:02:09 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------


Modified Paths:
--------------
    trunk/controller/inc/class.socheck_list.inc.php
    trunk/controller/inc/class.uicheck_list_for_location.inc.php
    trunk/controller/inc/class.uicontrol.inc.php
    trunk/controller/js/controller/custom_ui.js
    trunk/controller/js/yahoo/common.js
    trunk/controller/js/yahoo/datatable.js
    trunk/controller/setup/phpgw_no.lang

Added Paths:
-----------
    trunk/controller/images/status_icon_red_cross.png
    trunk/controller/js/controller/jquery-ui.custom.min.js

Removed Paths:
-------------
    trunk/controller/js/yahoo/example_edit.js
    trunk/controller/js/yahoo/example_normal_tabs.js
    trunk/controller/js/yahoo/example_separate_tabs.js

Added: trunk/controller/images/status_icon_red_cross.png
===================================================================
(Binary files differ)


Property changes on: trunk/controller/images/status_icon_red_cross.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/controller/inc/class.socheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_list.inc.php     2011-12-15 08:59:28 UTC 
(rev 8307)
+++ trunk/controller/inc/class.socheck_list.inc.php     2011-12-15 09:02:09 UTC 
(rev 8308)
@@ -1,507 +1,490 @@
-<?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$
-       */
-
-       phpgw::import_class('controller.socommon');
-
-       include_class('controller', 'check_list', 'inc/model/');
-
-       class controller_socheck_list extends controller_socommon
-       {
-               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_list');
-                       }
-                       return self::$so;
-               }
-       
-               public function get_single($check_list_id)
-               {
-                       $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, ci.id as ci_id, ci.status as ci_status, 
control_item_id, ci.comment as ci_comment, check_list_id FROM 
controller_check_list cl, controller_check_item ci WHERE cl.id = $check_list_id 
AND cl.id = ci.check_list_id;";
-                       $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', true), 'int'));
-                                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
-                                       
$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_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_status($this->unmarshal($this->db->f('ci_status', true), 
'bool'));
-                               
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true), 
'string'));
-                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
-                       
-                               $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;
-                       }
-               }
-               
-               public function get_single_with_control_items($check_list_id)
-               {
-                       $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, ";
-                       $sql .= "ci.id as ci_id, ci.status as ci_status, 
control_item_id, ci.comment as ci_comment, check_list_id, "; 
-                       $sql .= "coi.title as coi_id, coi.title as coi_title, 
coi.required as coi_required, 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 "; 
-                       $sql .= "FROM controller_check_list cl, 
controller_check_item ci, controller_control_item as coi "; 
-                       $sql .= "WHERE cl.id = $check_list_id ";
-                       $sql .= "AND cl.id = ci.check_list_id ";
-                       $sql .= "AND ci.control_item_id=coi.id;";
-               
-                       $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', true), 'int'));
-                                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
-                                       
$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_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_status($this->unmarshal($this->db->f('ci_status', true), 
'bool'));
-                               
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true), 
'string'));
-                               
$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('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');
-                       
-                               
$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;
-                       }
-               }
-       
-               public function get_check_list()
-               {
-                       $current_time = time();
-       
-                       $buffer_in_days = 3600*24*7*5;
-               
-                       $buffer_time = $current_time - $buffer_in_days;
-               
-                       $sql = "SELECT p.* FROM controller_control p WHERE 
$current_time >= p.start_date AND p.start_date > $buffer_time";
-                       $this->db->query($sql);
-                       
-                       while ($this->db->next_record())
-                       {
-                               $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($this->unmarshal($this->db->f('id', true), 'int'));
-
-                               
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-                               
$control->set_description($this->unmarshal($this->db->f('description', true), 
'boolean'));
-                               $control->set_start_date($start_date);
-                               $control->set_end_date($end_date);
-                               
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'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', 
true), 'int'));
-                               
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
-                               
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
-                               
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
-                               
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
-                               
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
 true), 'int'));
-                               
$control->set_component_id($this->unmarshal($this->db->f('component_id', true), 
'int'));
-                               
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'int'));
-                               
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
-                               
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
-                               
-                               $results[] = $control->toArray(); 
-                       }
-                               
-                       return $results;
-               }
-       
-               function get_check_lists_for_control($control_id)
-               {
-                       $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, ";
-                       $sql .= "ci.id as ci_id, ci.status as ci_status, 
control_item_id, ci.comment as ci_comment, 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_list_id = 0;
-                       $check_list = null;
-                       while ($this->db->next_record())
-                       {
-                               if( $this->db->f('cl_id', true) != 
$check_list_id )
-                               {
-                                       if($check_list_id != 0)
-                                       {
-                                               
$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', true), 'int'));
-                                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
-                                       
$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_items_array = array();
-                               }
-                       
-                               $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_status($this->unmarshal($this->db->f('ci_status', true), 
'bool'));
-                               
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true), 
'string'));
-                               
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), '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_agg_check_lists_for_location( $location_code, 
$from_date, $to_date )
-               {
-                       $sql =  "SELECT c.id as c_id, title, cl.id as cl_id, 
c.repeat_type, c.repeat_interval, deadline, count(ci.id) ";
-                       $sql .= "FROM controller_check_list cl, 
controller_control c, controller_check_item ci ";
-                       $sql .= "WHERE cl.location_code = $location_code ";
-                       $sql .= "AND c.repeat_type < 2 ";
-                       $sql .= "AND cl.control_id = c.id ";
-                       $sql .= "AND cl.id = ci.check_list_id ";
-                       $sql .= "AND deadline BETWEEN $from_date AND $to_date ";
-                       $sql .= "GROUP BY c.id, title, cl.id, cl.deadline, 
c.repeat_type, c.repeat_interval ";
-                       $sql .= "ORDER BY c.id";
-
-                       $this->db->query($sql);
-               
-                       $control_id = 0;
-                       $controls_array = array();
-                       $check_list_array = array();
-                       while ($this->db->next_record())
-                       {
-                               if( $this->db->f('c_id', true) != $control_id )
-                               {
-                                       if($control_id != 0)
-                                       {
-                                               $controls_array[] = array( 
"control" => $control_array, "check_list" => $check_list_array);
-                                               $check_list_array = array();
-                                       }
-                               
-                                       $control_array = array(
-                                                                               
        "id"                      => $this->unmarshal($this->db->f('c_id', 
true), 'int'),
-                                                                               
        "title"                   => $this->unmarshal($this->db->f('title', 
true), 'string'),
-                                                                               
        "repeat_type"     => $this->unmarshal($this->db->f('repeat_type', 
true), 'int'),
-                                                                               
        "repeat_interval" => $this->unmarshal($this->db->f('repeat_interval', 
true), 'int')
-                                                                               
);
-                               }
-
-                               $check_list_array[] = array(
-                                                                               
        "cl_id"         => $this->db->f('cl_id', true),
-                                                                               
        "deadline"      => $this->db->f('deadline', true),
-                                                                               
        "count"         => $this->db->f('count', true)
-                                                                               
);
-                       
-                               $control_id = $this->db->f('c_id', true);
-                       }       
-               
-                       if( !empty( $control_array ) )
-                       {
-                               $controls_array[] = array( "control" => 
$control_array, "check_list" => $check_list_array);
-                       
-                               return $controls_array;
-                       }
-                       else
-                       {
-                               return null;
-                       }
-               }
-
-               function get_check_lists_for_location( $location_code, 
$from_date, $to_date, $repeat_type )
-               {
-                       $sql =  "SELECT c.id as c_id, cl.id as cl_id, cl.status 
as cl_status, cl.comment as cl_comment, ";
-                       $sql .= "deadline, planned_date, completed_date, 
cl.location_code as cl_loc, c.* "; 
-                       $sql .= "FROM controller_check_list cl, 
controller_control c ";
-                       $sql .= "WHERE cl.location_code = $location_code ";
-                       $sql .= "AND c.repeat_type = $repeat_type ";
-                       $sql .= "AND cl.control_id = c.id ";
-                       $sql .= "AND deadline BETWEEN $from_date AND $to_date";
-                       $sql .= "ORDER BY c.id;";
-               
-                       $this->db->query($sql);
-               
-                       $control_id = 0;
-                       $control = null;
-                       while ($this->db->next_record())
-                       {
-                               if( $this->db->f('c_id', true) != $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', true), 'int'));
-                                       
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-                                       
$control->set_description($this->unmarshal($this->db->f('description', true), 
'boolean'));
-                                       
$control->set_start_date($this->unmarshal($this->db->f('start_date', true), 
'int'));
-                                       
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
-                                       
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'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', 
true), 'int'));
-                                       
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
-                                       
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
-                                       
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
-                                       
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
-                                       
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
 true), 'int'));
-                                       
$control->set_component_id($this->unmarshal($this->db->f('component_id', true), 
'int'));
-                                       
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'int'));
-                                       
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
-                                       
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
-                                                               
-                                       $check_lists_array = array();
-                               }
-
-                               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
-                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'string'));
-                               
$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_location_code($this->unmarshal($this->db->f('cl_loc', true), 
'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;
-                       }
-                       else
-                       {
-                               return null;
-                       }
-               }
-       
-               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) . ')';
-                               }
-                       }
-                       //var_dump($filters);
-                       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";
-                       //$joins = " {$this->left_join} rental_document_types 
ON (rental_document.type_id = rental_document_types.id)";
-                       //$joins = " {$this->left_join} controller_control_area 
ON (controller_control.control_area_id = controller_control_area.id)";
-                       //$joins .= " {$this->left_join} controller_procedure 
ON (controller_control.procedure_id = controller_procedure.id)";
-               
-                       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), 
'boolean'));
-                               $control->set_start_date($start_date);
-                               $control->set_end_date($end_date);
-                               
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'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', 
true), 'int'));
-                               
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
-                               
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
-                               
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
-                               
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
-       //                      
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
 true), 'int'));
-                               
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
 true), 'int'));
-                               
$control->set_component_id($this->unmarshal($this->db->f('component_id', true), 
'int'));
-                               
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'int'));
-                               
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
-                               
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
-                       }
-               
-                       return $control;
-               }
-       
-               function add(&$check_list)
-               {
-                       $cols = array(
-                                       'control_id',
-                                       'status',
-                                       'comment',
-                                       'deadline'
-                       );
-               
-                       $values = array(
-                               $this->marshal($check_list->get_control_id(), 
'int'),
-                               $this->marshal($check_list->get_status(), 
'bool'),
-                               $this->marshal($check_list->get_comment(), 
'string'),
-                               $this->marshal($check_list->get_deadline(), 
'int')
-                       );
-               
-                       $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($object){}
-       
-               function get_id_field_name($extended_info = false)
-               {
-                       if(!$extended_info)
-                       {
-                               $ret = 'id';
-                       }
-                       else
-                       {
-                               $ret = array
-                               (
-                                       'table'                 => 'control', 
// alias
-                                       'field'                 => 'id',
-                                       'translated'    => 'id'
-                               );
-                       }
-               
-                       return $ret;
-               }
-       }
+<?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$
+       */
+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
+{
+       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_list');
+               }
+               return self::$so;
+       }
+       
+       public function get_single($check_list_id){
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, ci.id as ci_id, ci.status as ci_status, 
control_item_id, ci.comment as ci_comment, check_list_id FROM 
controller_check_list cl, controller_check_item ci WHERE cl.id = $check_list_id 
AND cl.id = ci.check_list_id;";
+               $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', true), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
+                               
$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_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_status($this->unmarshal($this->db->f('ci_status', true), 
'bool'));
+                       
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true), 
'string'));
+                       
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), 'int'));
+                       
+                       $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;
+               }
+       }
+               
+       public function get_single_with_check_items($check_list_id){
+               $sql  = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, ";
+               $sql .= "ci.id as ci_id, ci.status as ci_status, 
control_item_id, ci.comment as ci_comment, check_list_id, "; 
+               $sql .= "coi.title as coi_id, coi.title as coi_title, 
coi.required as coi_required, 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 "; 
+               $sql .= "FROM controller_check_list cl, controller_check_item 
ci, controller_control_item as coi "; 
+               $sql .= "WHERE cl.id = $check_list_id ";
+               $sql .= "AND cl.id = ci.check_list_id ";
+               $sql .= "AND ci.control_item_id=coi.id;";
+               
+               $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', true), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
+                               
$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_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_status($this->unmarshal($this->db->f('ci_status', true), 
'bool'));
+                       
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true), 
'string'));
+                       
$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('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');
+                       
+                       $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;
+               }
+       }
+       
+       public function get_check_list(){
+
+               $current_time = time();
+       
+               $buffer_in_days = 3600*24*7*5;
+               
+               $buffer_time = $current_time - $buffer_in_days;
+               
+               $sql = "SELECT p.* FROM controller_control p WHERE 
$current_time >= p.start_date AND p.start_date > $buffer_time";
+               $this->db->query($sql);
+                       
+               while ($this->db->next_record()) {
+                       $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($this->unmarshal($this->db->f('id', true), 'int'));
+
+                       
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+                       
$control->set_description($this->unmarshal($this->db->f('description', true), 
'boolean'));
+                       $control->set_start_date($start_date);
+                       $control->set_end_date($end_date);
+                       
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'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', 
true), 'int'));
+                       
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
+                       
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
+                       
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), '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',
 true), 'int'));
+                       
$control->set_equipment_id($this->unmarshal($this->db->f('equipment_id', true), 
'int'));
+                       
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'int'));
+                       
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
+                       
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
+                               
+                       $results[] = $control->toArray(); 
+               }
+                               
+               return $results;
+       }
+       
+       function get_check_lists_for_control($control_id){
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, ";
+               $sql .= "ci.id as ci_id, ci.status as ci_status, 
control_item_id, ci.comment as ci_comment, 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_list_id = 0;
+               $check_list = null;
+               while ($this->db->next_record()) {
+               
+                       if( $this->db->f('cl_id', true) != $check_list_id ){
+                               
+                               if($check_list_id != 0){
+                                       
$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', true), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'bool'));
+                               
$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_items_array = array();
+                       }
+                       
+                       $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_status($this->unmarshal($this->db->f('ci_status', true), 
'bool'));
+                       
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true), 
'string'));
+                       
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id', 
true), '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_agg_check_lists_for_location( $location_code, $from_date, 
$to_date ){
+               
+               $sql =  "SELECT c.id as c_id, title, cl.id as cl_id, 
c.repeat_type, c.repeat_interval, deadline, count(ci.id) ";
+               $sql .= "FROM controller_check_list cl, controller_control c, 
controller_check_item ci ";
+               $sql .= "WHERE cl.location_code = $location_code ";
+               $sql .= "AND c.repeat_type < 2 ";
+               $sql .= "AND cl.control_id = c.id ";
+               $sql .= "AND cl.id = ci.check_list_id ";
+               $sql .= "AND deadline BETWEEN $from_date AND $to_date ";
+               $sql .= "GROUP BY c.id, title, cl.id, cl.deadline, 
c.repeat_type, c.repeat_interval ";
+               $sql .= "ORDER BY c.id";
+
+               $this->db->query($sql);
+               
+               $control_id = 0;
+               $controls_array = array();
+               $check_list_array = array();
+               while ($this->db->next_record()) {
+                       
+                       if( $this->db->f('c_id', true) != $control_id ){
+                               if($control_id != 0){
+                                       $controls_array[] = array( "control" => 
$control_array, "check_list" => $check_list_array);
+                                       $check_list_array = array();
+                               }
+                               
+                               $control_array = array(
+                                                                               
"id"                      => $this->unmarshal($this->db->f('c_id', true), 
'int'),
+                                                                               
"title"                   => $this->unmarshal($this->db->f('title', true), 
'string'),
+                                                                               
"repeat_type"     => $this->unmarshal($this->db->f('repeat_type', true), 'int'),
+                                                                               
"repeat_interval" => $this->unmarshal($this->db->f('repeat_interval', true), 
'int')
+                                                                       );
+                       }
+
+                       $check_list_array[] = array(
+                                                                               
"cl_id"         => $this->db->f('cl_id', true),
+                                                                               
"deadline"      => $this->db->f('deadline', true),
+                                                                               
"count"         => $this->db->f('count', true)
+                                                                       );
+                       
+                       $control_id = $this->db->f('c_id', true);
+               }               
+               
+               if( !empty( $control_array ) ){
+                       $controls_array[] = array( "control" => $control_array, 
"check_list" => $check_list_array);
+                       
+                       return $controls_array;
+               }else {
+                       return null;
+               }       
+       }
+       
+       function get_check_lists_for_location( $location_code, $from_date, 
$to_date, $repeat_type ){
+               $sql =  "SELECT c.id as c_id, cl.id as cl_id, cl.status as 
cl_status, cl.comment as cl_comment, ";
+               $sql .= "deadline, planned_date, completed_date, 
cl.location_code as cl_loc, c.* "; 
+               $sql .= "FROM controller_check_list cl, controller_control c ";
+               $sql .= "WHERE cl.location_code = $location_code ";
+               $sql .= "AND c.repeat_type = $repeat_type ";
+               $sql .= "AND cl.control_id = c.id ";
+               $sql .= "AND deadline BETWEEN $from_date AND $to_date";
+               $sql .= "ORDER BY c.id;";
+               
+               $this->db->query($sql);
+               
+               $control_id = 0;
+               $control = null;
+               while ($this->db->next_record()) {
+                       
+                       if( $this->db->f('c_id', true) != $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', true), 'int'));
+                               
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+                               
$control->set_description($this->unmarshal($this->db->f('description', true), 
'boolean'));
+                               
$control->set_start_date($this->unmarshal($this->db->f('start_date', true), 
'int'));
+                               
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
+                               
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'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', 
true), 'int'));
+                               
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
+                               
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
+                               
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
+                               
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
+                               
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
 true), 'int'));
+                               
$control->set_component_id($this->unmarshal($this->db->f('component_id', true), 
'int'));
+                               
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'int'));
+                               
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
+                               
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
+                                                               
+                               $check_lists_array = array();
+                       }
+
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'string'));
+                       
$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_location_code($this->unmarshal($this->db->f('cl_loc', true), 
'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;
+               }else {
+                       return null;
+               }       
+       }
+       
+       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) 
. ')';
+                       }
+               }
+               //var_dump($filters);
+               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";
+               //$joins = " {$this->left_join} rental_document_types ON 
(rental_document.type_id = rental_document_types.id)";
+               //$joins = " {$this->left_join} controller_control_area ON 
(controller_control.control_area_id = controller_control_area.id)";
+               //$joins .= " {$this->left_join} controller_procedure ON 
(controller_control.procedure_id = controller_procedure.id)";
+               
+               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), 
'boolean'));
+                       $control->set_start_date($start_date);
+                       $control->set_end_date($end_date);
+                       
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'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', 
true), 'int'));
+                       
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
+                       
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
+                       
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
+                       
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
+//                     
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
 true), 'int'));
+                       
$control->set_equipment_type_id($this->unmarshal($this->db->f('equipment_type_id',
 true), 'int'));
+                       
$control->set_equipment_id($this->unmarshal($this->db->f('equipment_id', true), 
'int'));
+                       
$control->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'int'));
+                       
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
+                       
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
+               }
+               
+               return $control;
+       }
+       
+       function add(&$check_list)
+       {
+               $cols = array(
+                               'control_id',
+                               'status',
+                               'comment',
+                               'deadline',
+                               'planned_date',
+                               'completed_date',
+                               'location_code',
+                               'equipment_id'
+               );
+               
+               $values = array(
+                       $this->marshal($check_list->get_control_id(), 'int'),
+                       $this->marshal($check_list->get_status(), 'bool'),
+                       $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_location_code(), 'int'),
+                       $this->marshal($check_list->get_equipment_id(), 'int')
+               );
+               
+               $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($object){}
+       
+       function get_id_field_name($extended_info = false)
+       {
+               if(!$extended_info)
+               {
+                       $ret = 'id';
+               }
+               else
+               {
+                       $ret = array
+                       (
+                               'table'                 => 'control', // alias
+                               'field'                 => 'id',
+                               'translated'    => 'id'
+                       );
+               }
+               
+               return $ret;
+       }       
+}
\ No newline at end of file

Modified: trunk/controller/inc/class.uicheck_list_for_location.inc.php
===================================================================
--- trunk/controller/inc/class.uicheck_list_for_location.inc.php        
2011-12-15 08:59:28 UTC (rev 8307)
+++ trunk/controller/inc/class.uicheck_list_for_location.inc.php        
2011-12-15 09:02:09 UTC (rev 8308)
@@ -1,329 +1,444 @@
-<?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$
-       */
-
-       phpgw::import_class('phpgwapi.yui');
-       phpgw::import_class('controller.uicommon');
-       phpgw::import_class('controller.socontrol_area');
-
-       class controller_uicheck_list_for_location extends controller_uicommon
-       {
-               var $cat_id;
-               var $start;
-               var $query;
-               var $sort;
-               var $order;
-               var $filter;
-               var $currentapp;
-               var $type_id;
-               var $location_code;
-
-               private $so_control_area;
-               private $so_control;
-
-               var $public_functions = array(
-                                                                               
'index' => true,
-                                                                               
'add_location_to_control' => true
-                                                                       );
-
-               function __construct()
-               {
-                       parent::__construct();
-
-                       $this->bo                                       = 
CreateObject('property.bolocation',true);
-                       $this->bocommon                         = & 
$this->bo->bocommon;
-                       $this->so_control_area          = 
CreateObject('controller.socontrol_area');
-                       $this->so_control                       = 
CreateObject('controller.socontrol');
-
-                       $this->type_id                          = 
$this->bo->type_id;
-
-                       $this->start                            = 
$this->bo->start;
-                       $this->query                            = 
$this->bo->query;
-                       $this->sort                                     = 
$this->bo->sort;
-                       $this->order                            = 
$this->bo->order;
-                       $this->filter                           = 
$this->bo->filter;
-                       $this->cat_id                           = 
$this->bo->cat_id;
-                       $this->part_of_town_id          = 
$this->bo->part_of_town_id;
-                       $this->district_id                      = 
$this->bo->district_id;
-                       $this->status                           = 
$this->bo->status;
-                       $this->allrows                          = 
$this->bo->allrows;
-                       $this->lookup                           = 
$this->bo->lookup;
-                       $this->location_code            = 
$this->bo->location_code;
-
-                       
self::set_active_menu('controller::control::location_for_check_list');
-               }
-
-               function index()
-               {
-                       if(phpgw::get_var('phpgw_return_as') == 'json') {
-                               return $this->query();
-                       }
-                       $building_types  = 
execMethod('property.soadmin_location.read',array());
-
-                       $type_id = 1;
-
-                       $category_types = 
$this->bocommon->select_category_list(array(
-                                                                               
                                                                
'format'=>'filter',
-                                                                               
                                                                'selected' => 
$this->cat_id,
-                                                                               
                                                                'type' 
=>'location',
-                                                                               
                                                                'type_id' 
=>$type_id,
-                                                                               
                                                                'order'=>'descr'
-                                                                               
                                                        ));
-
-                       $district_list  = 
$this->bocommon->select_district_list('filter',$this->district_id);
-                       $default_value = array ('id'=>'','name'=>lang('no 
district'));
-                       array_unshift($district_list,$default_value);
-
-                       $part_of_town_list =  
$this->bocommon->select_part_of_town('filter',$this->part_of_town_id,$this->district_id);
-                       $default_value = array ('id'=>'','name'=>lang('no part 
of town'));
-                       array_unshift($part_of_town_list,$default_value);
-
-                       $_role_criteria = array
-                                       (
-                                               'type'          => 
'responsibility_role',
-                                               'filter'        => 
array('location' => ".location.{$type_id}"),
-                                               'order'         => 'name'
-                                       );
-
-                       $responsibility_roles_list =   
execMethod('property.sogeneric.get_list',$_role_criteria);
-                       $default_value = array ('id'=>'','name'=>lang('no 
role'));
-                       array_unshift ($responsibility_roles,$default_value);
-
-                       $control_areas_array = 
$this->so_control_area->get_control_areas_as_array();
-                       $controls_array = 
$this->so_control->get_controls_by_control_area($control_areas_array[0]['id']);
-                       $control_id = $control_areas_array[0]['id'];
-
-                       if($control_id == null)
-                               $control_id = 0;
-
-                       $tabs = array( array(
-                                               'label' => 
lang('View_locations_for_control')
-                                       ), array(
-                                               'label' => 
lang('Add_locations_for_control'),
-                                               'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list_for_location.add_location_to_control'))
-                                       ));
-
-                       $data = array(
-                               'tabs'                                  => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 0),
-                               'view'                                  => 
"view_locations_for_control",
-                               'control_area_array'    => $control_areas_array,
-                               'control_array'                 => 
$control_array,
-                               'locations_table' => array(
-                                       'source' => 
self::link(array('menuaction' => 
'controller.uicontrol.get_locations_for_control', 'control_id' => $control_id 
,'phpgw_return_as' => 'json')),
-                                       'field' => array(
-                                               array(
-                                                       'key' => 'id',
-                                                       'label' => 
lang('ControlId'),
-                                                       'sortable'      => true,
-                                               ),
-                                               array(
-                                                       'key'   =>      'title',
-                                                       'label' =>      
lang('Property name'),
-                                                       'sortable'      =>      
false
-                                               ),
-                                               array(
-                                                       'key' => 
'location_code',
-                                                       'label' => 
lang('Address'),
-                                                       'sortable'      => false
-                                               ),
-                                               array(
-                                                       'key' => 'loc1_name',
-                                                       'label' => 
lang('Address'),
-                                                       'sortable'      => false
-                                               )
-                                       )
-                               )
-                       );
-
-
-                       phpgwapi_yui::load_widget('paginator');
-
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-                       self::add_javascript('controller', 'controller', 
'jquery.js');
-                       self::add_javascript('controller', 'controller', 
'ajax.js');
-
-                       
self::render_template_xsl(array('control_location_tabs', 'common', 
'view_locations_for_control'), $data);
-               }
-
-               function add_location_to_control()
-               {
-                       if(phpgw::get_var('phpgw_return_as') == 'json') {
-                               return $this->query();
-                       }
-                       $building_types  = 
execMethod('property.soadmin_location.read',array());
-
-                       $type_id = 1;
-
-                       $category_types = 
$this->bocommon->select_category_list(array(
-                                                                               
                                                                
'format'=>'filter',
-                                                                               
                                                                'selected' => 
$this->cat_id,
-                                                                               
                                                                'type' 
=>'location',
-                                                                               
                                                                'type_id' 
=>$type_id,
-                                                                               
                                                                'order'=>'descr'
-                                                                               
                                                        ));
-
-                       $district_list  = 
$this->bocommon->select_district_list('filter',$this->district_id);
-                       $default_value = array ('id'=>'','name'=>lang('no 
district'));
-                       array_unshift($district_list,$default_value);
-
-                       $part_of_town_list =  
$this->bocommon->select_part_of_town('filter',$this->part_of_town_id,$this->district_id);
-                       $default_value = array ('id'=>'','name'=>lang('no part 
of town'));
-                       array_unshift($part_of_town_list,$default_value);
-
-                       $_role_criteria = array
-                                       (
-                                               'type'          => 
'responsibility_role',
-                                               'filter'        => 
array('location' => ".location.{$type_id}"),
-                                               'order'         => 'name'
-                                       );
-
-                       $responsibility_roles_list =   
execMethod('property.sogeneric.get_list',$_role_criteria);
-                       $default_value = array ('id'=>'','name'=>lang('no 
role'));
-                       array_unshift ($responsibility_roles,$default_value);
-
-                       $control_areas_array = 
$this->so_control_area->get_control_areas_as_array();
-
-                       $tabs = array( array(
-                                               'label' => 
lang('View_locations_for_control'),
-                                               'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list_for_location.index'))
-
-                                       ), array(
-                                               'label' => 
lang('Add_locations_for_control')
-                                       ));
-
-                       $data = array(
-                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 1),
-                               'view'                                          
=> "add_location_to_control",
-                               'control_filters'                       => 
array(
-                                       'control_area_array'            => 
$control_areas_array,
-                                       'control_array'                         
=> $control_array
-                               ),
-                               'filter_form'                           => 
array(
-                                       'building_types'                        
=> $building_types,
-                                       'category_types'                        
=> $category_types,
-                                       'district_list'                         
=> $district_list,
-                                       'part_of_town_list'             => 
$part_of_town_list
-                               ),
-                               'datatable' => array(
-                                       'source' => 
self::link(array('menuaction' => 'controller.uicheck_list_for_location.index', 
'phpgw_return_as' => 'json')),
-                                       'field' => array(
-                                               array(
-                                                       'key' => 
'location_code',
-                                                       'label' => 
lang('Property'),
-                                                       'sortable'      => true,
-                                                       'formatter' => 
'YAHOO.portico.formatLink'
-                                               ),
-                                               array(
-                                                       'key'   =>      
'loc1_name',
-                                                       'label' =>      
lang('Property name'),
-                                                       'sortable'      =>      
false
-                                               ),
-                                               array(
-                                                       'key' => 'adresse1',
-                                                       'label' => 
lang('Address'),
-                                                       'sortable'      => false
-                                               ),
-                                               array(
-                                                       'key' => 'postnummer',
-                                                       'label' => lang('Zip 
code'),
-                                                       'sortable'      => false
-                                               ),
-                                               array(
-                                                       'key' => 'actions',
-                                                       'hidden' => true
-                                               ),
-                                               array(
-                                                       'key' => 'labels',
-                                                       'hidden' => true
-                                               ),
-                                               array(
-                                                       'key' => 'ajax',
-                                                       'hidden' => true
-                                               )
-                                       )
-                               )
-                       );
-
-
-                       phpgwapi_yui::load_widget('paginator');
-
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-                       self::add_javascript('controller', 'controller', 
'jquery.js');
-                       self::add_javascript('controller', 'controller', 
'ajax.js');
-
-                       
self::render_template_xsl(array('control_location_tabs', 'common', 
'add_location_to_control'), $data);
-               }
-
-               public function query()
-               {
-                       $type_id = phpgw::get_var('type_id', 'int');
-                       $return_results = phpgw::get_var('results', 'int', 
'REQUEST', 0);
-
-                       $type_id = $type_id ? $type_id : 1;
-
-                       $location_list = array();
-
-                       $this->bo->sort = "ASC";
-                       $this->bo->start = phpgw::get_var('startIndex');
-
-                       $location_list = $this->bo->read(array('user_id' => 
$user_id, 'role_id' =>$role_id, 
'type_id'=>$type_id,'lookup_tenant'=>$lookup_tenant,
-                                                                               
                   'lookup'=>$lookup,'allrows'=>$this->allrows,'dry_run' 
=>$dry_run,'results' => $return_results));
-
-                       foreach($location_list as $location)
-                       {
-                               $results['results'][]= $location;
-                       }
-
-                       $results['total_records'] = $this->bo->total_records;
-                       $results['start'] = $this->start;
-                       $results['sort'] = 'location_code';
-                       $results['dir'] = "ASC";
-
-                       array_walk($results['results'], array($this, 
'add_actions'), array($type));
-
-                       return $this->yui_results($results);
-               }
-
-               public function add_actions(&$value, $key, $params)
-               {
-                       unset($value['query_location']);
-
-                       $value['ajax'] = array();
-                       $value['actions'] = array();
-                       $value['labels'] = array();
-
-                       $value['ajax'][] = false;
-                       $value['actions'][] = 
html_entity_decode(self::link(array('menuaction' => 'property.uilocation.view', 
'location_code' => $value['location_code'])));
-                       $value['labels'][] = lang('show');
-
-                       $value['ajax'][] = true;
-                       $value['actions'][] = 
html_entity_decode(self::link(array('menuaction' => 
'controller.uicontrol.add_location_to_control', 'location_code' => 
$value['location_code'])));
-                       $value['labels'][] = lang('add_location');
-               }
-       }
+<?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$
+       */
+       
+       phpgw::import_class('phpgwapi.yui');
+       phpgw::import_class('controller.uicommon');
+       phpgw::import_class('controller.socontrol_area');
+       
+       include_class('controller', 'check_list', 'inc/model/');
+       include_class('controller', 'date_generator', 'inc/components/');
+               
+       class controller_uicheck_list_for_location extends controller_uicommon
+       {
+               var $cat_id;
+               var $start;
+               var $query;
+               var $sort;
+               var $order;
+               var $filter;
+               var $currentapp;
+               var $type_id;
+               var $location_code;
+               
+               private $so_control_area;
+               private $so_control;
+               private $so_check_list;
+       
+               var $public_functions = array(
+                                                                               
'index' => true,
+                                                                               
'view_locations_for_control' => true,
+                                                                               
'add_location_to_control' => true,
+                                                                               
'add_check_list_for_location' => true,
+                                                                               
'save_check_list_for_location' => true,
+                                                                               
'edit_check_list_for_location' => true
+                                                                       );
+
+               function __construct()
+               {
+                       parent::__construct();
+                       
+                       $this->bo                                       = 
CreateObject('property.bolocation',true);
+                       $this->bocommon                         = & 
$this->bo->bocommon;
+                       $this->so_control_area          = 
CreateObject('controller.socontrol_area');
+                       $this->so_control                       = 
CreateObject('controller.socontrol');
+                       $this->so_check_list            = 
CreateObject('controller.socheck_list');
+                       
+                       $this->type_id                          = 
$this->bo->type_id;
+                       
+                       $this->start                            = 
$this->bo->start;
+                       $this->query                            = 
$this->bo->query;
+                       $this->sort                                     = 
$this->bo->sort;
+                       $this->order                            = 
$this->bo->order;
+                       $this->filter                           = 
$this->bo->filter;
+                       $this->cat_id                           = 
$this->bo->cat_id;
+                       $this->part_of_town_id          = 
$this->bo->part_of_town_id;
+                       $this->district_id                      = 
$this->bo->district_id;
+                       $this->status                           = 
$this->bo->status;
+                       $this->allrows                          = 
$this->bo->allrows;
+                       $this->lookup                           = 
$this->bo->lookup;
+                       $this->location_code            = 
$this->bo->location_code;
+                       
+                       
self::set_active_menu('controller::control::location_for_check_list');
+               }       
+       
+               function index()
+               {
+                       if(phpgw::get_var('phpgw_return_as') == 'json') {
+                               return $this->query();
+                       }
+                       $building_types  = 
execMethod('property.soadmin_location.read',array());
+                       
+                       $type_id = 1;
+                       
+                       $category_types = 
$this->bocommon->select_category_list(array(
+                                                                               
                                                                
'format'=>'filter',
+                                                                               
                                                                'selected' => 
$this->cat_id,
+                                                                               
                                                                'type' 
=>'location',
+                                                                               
                                                                'type_id' 
=>$type_id,
+                                                                               
                                                                'order'=>'descr'
+                                                                               
                                                        ));
+                       
+                       $district_list  = 
$this->bocommon->select_district_list('filter',$this->district_id);
+                       $default_value = array ('id'=>'','name'=>lang('no 
district'));
+                       array_unshift($district_list,$default_value);
+                       
+                       $part_of_town_list =  
$this->bocommon->select_part_of_town('filter',$this->part_of_town_id,$this->district_id);
+                       $default_value = array ('id'=>'','name'=>lang('no part 
of town'));
+                       array_unshift($part_of_town_list,$default_value);
+                       
+                       $_role_criteria = array
+                                       (
+                                               'type'          => 
'responsibility_role',
+                                               'filter'        => 
array('location' => ".location.{$type_id}"),
+                                               'order'         => 'name'
+                                       );
+
+                       $responsibility_roles_list =   
execMethod('property.sogeneric.get_list',$_role_criteria);
+                       $default_value = array ('id'=>'','name'=>lang('no 
role'));
+                       array_unshift ($responsibility_roles,$default_value);
+                       
+                       $control_areas_array = 
$this->so_control_area->get_control_areas_as_array();
+                       $controls_array = 
$this->so_control->get_controls_by_control_area($control_areas_array[0]['id']);
+                       $control_id = $control_areas_array[0]['id'];
+                       
+                       if($control_id == null)
+                               $control_id = 0;
+                       
+                       $tabs = array( array(
+                                               'label' => 
lang('View_locations_for_control')
+                                       ), array(
+                                               'label' => 
lang('Add_locations_for_control'),
+                                               'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list_for_location.add_location_to_control'))
+                                       ));
+                       
+                       $data = array(
+                               'tabs'                                  => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 0),
+                               'view'                                  => 
"view_locations_for_control",
+                               'control_area_array'    => $control_areas_array,
+                               'control_array'                 => 
$control_array,
+                               'locations_table' => array(
+                                       'source' => 
self::link(array('menuaction' => 
'controller.uicontrol.get_locations_for_control', 'control_id' => $control_id 
,'phpgw_return_as' => 'json')),
+                                       'field' => array(
+                                               array(
+                                                       'key' => 'id',
+                                                       'label' => 
lang('ControlId'),
+                                                       'sortable'      => true,
+                                               ),
+                                               array(
+                                                       'key'   =>      'title',
+                                                       'label' =>      
lang('Property name'),
+                                                       'sortable'      =>      
false
+                                               ),
+                                               array(
+                                                       'key' => 
'location_code',
+                                                       'label' => 
lang('location_code'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 'loc1_name',
+                                                       'label' => 
lang('Location_name'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 'actions',
+                                                       'hidden' => true
+                                               ),
+                                               array(
+                                                       'key' => 'labels',
+                                                       'hidden' => true
+                                               ),
+                                               array(
+                                                       'key' => 'ajax',
+                                                       'hidden' => true
+                                               ),array(
+                                                       'key' => 'parameters',
+                                                       'hidden' => true
+                                               )                               
                
+                                       )
+                               )
+                       );
+                       
+                       phpgwapi_yui::load_widget('paginator');
+                       
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'ajax.js');
+
+                       
self::render_template_xsl(array('control_location_tabs', 'common', 
'view_locations_for_control'), $data);               
+               }
+               
+               function add_location_to_control()
+               {
+                       if(phpgw::get_var('phpgw_return_as') == 'json') {
+                               return $this->query();
+                       }
+                       $building_types  = 
execMethod('property.soadmin_location.read',array());
+                       
+                       $type_id = 1;
+                       
+                       $category_types = 
$this->bocommon->select_category_list(array(
+                                                                               
                                                                
'format'=>'filter',
+                                                                               
                                                                'selected' => 
$this->cat_id,
+                                                                               
                                                                'type' 
=>'location',
+                                                                               
                                                                'type_id' 
=>$type_id,
+                                                                               
                                                                'order'=>'descr'
+                                                                               
                                                        ));
+                       
+                       $district_list  = 
$this->bocommon->select_district_list('filter',$this->district_id);
+                       $default_value = array ('id'=>'','name'=>lang('no 
district'));
+                       array_unshift($district_list,$default_value);
+                       
+                       $part_of_town_list =  
$this->bocommon->select_part_of_town('filter',$this->part_of_town_id,$this->district_id);
+                       $default_value = array ('id'=>'','name'=>lang('no part 
of town'));
+                       array_unshift($part_of_town_list,$default_value);
+                       
+                       $_role_criteria = array
+                                       (
+                                               'type'          => 
'responsibility_role',
+                                               'filter'        => 
array('location' => ".location.{$type_id}"),
+                                               'order'         => 'name'
+                                       );
+
+                       $responsibility_roles_list = 
execMethod('property.sogeneric.get_list',$_role_criteria);
+                       $default_value = array ('id'=>'','name'=>lang('no 
role'));
+                       array_unshift ($responsibility_roles,$default_value);
+                       
+                       $control_areas_array = 
$this->so_control_area->get_control_areas_as_array();
+                       
+                       $tabs = array( array(
+                                               'label' => 
lang('View_locations_for_control'),
+                                               'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list_for_location.index'))
+                       
+                                       ), array(
+                                               'label' => 
lang('Add_locations_for_control')
+                                       ));
+                                       
+                       $data = array(
+                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 1),
+                               'view'                                          
=> "add_location_to_control",
+                               'control_filters'                       => 
array(
+                                       'control_area_array'            => 
$control_areas_array,
+                                       'control_array'                         
=> $control_array
+                               ),
+                               'filter_form'                           => 
array(
+                                       'building_types'                        
=> $building_types,
+                                       'category_types'                        
=> $category_types,
+                                       'district_list'                         
=> $district_list,
+                                       'part_of_town_list'             => 
$part_of_town_list
+                               ),
+                               'datatable' => array(
+                                       'source' => 
self::link(array('menuaction' => 'controller.uicheck_list_for_location.index', 
'phpgw_return_as' => 'json')),
+                                       'field' => array(
+                                               array(
+                                                       'key' => 
'location_code',
+                                                       'label' => 
lang('Property'),
+                                                       'sortable'      => true,
+                                                       'formatter' => 
'YAHOO.portico.formatLink'
+                                               ),
+                                               array(
+                                                       'key'   =>      
'loc1_name',
+                                                       'label' =>      
lang('Property name'),
+                                                       'sortable'      =>      
false
+                                               ),
+                                               array(
+                                                       'key' => 'adresse1',
+                                                       'label' => 
lang('Address'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 'postnummer',
+                                                       'label' => lang('Zip 
code'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 'actions',
+                                                       'hidden' => true
+                                               ),
+                                               array(
+                                                       'key' => 'labels',
+                                                       'hidden' => true
+                                               ),
+                                               array(
+                                                       'key' => 'ajax',
+                                                       'hidden' => true
+                                               ),array(
+                                                       'key' => 'parameters',
+                                                       'hidden' => true
+                                               )                               
                
+                                       )
+                               )
+                       );
+                       
+                       phpgwapi_yui::load_widget('paginator');
+                       
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'ajax.js');
+
+                       
self::render_template_xsl(array('control_location_tabs', 'common', 
'add_location_to_control'), $data);          
+               }
+               
+               function add_check_list_for_location(){
+                       $location_code = phpgw::get_var('location_code');
+                       $control_id = phpgw::get_var('control_id');
+                       $date = phpgw::get_var('date');
+                       
+                       $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
+                       $control = $this->so_control->get_single($control_id);
+                       
+                       if($date == null || $date == ''){
+                               $todays_date = mktime(0,0,0, date("m"), 
date("d"), date("Y"));
+                               $period_start_date = $todays_date;
+                               
+                               if( $control->get_repeat_type() == 1 )
+                               {
+                                       $period_end_date = mktime(0,0,0, 
date("m")+1, date("d"), date("Y"));
+                               }else if( $control->get_repeat_type() == 2 )
+                               {
+                                       $period_end_date = mktime(0,0,0, 
date("m"), date("d"), date("Y") + 1);
+                               }else if( $control->get_repeat_type() == 3 )
+                               {
+                                       $period_end_date = mktime(0,0,0, 
date("m"), date("d"), date("Y") + $control->get_repeat_interval());             
               
+                               }
+                               
+                               $date_generator = new 
date_generator($control->get_start_date(), $control->get_end_date(), 
$period_start_date, $period_end_date, $control->get_repeat_type(), 
$control->get_repeat_interval());
+                                                       
+                               $calendar_array = $date_generator->get_dates();
+                       }
+                       else
+                       {
+                               $calendar_array[] = $date;
+                       }                       
+                                               
+                       $data = array
+                       (
+                               'location_array'        => $location_array,
+                               'control_array'         => $control->toArray(),
+                               'calendar_array'        => $calendar_array,
+                               'planned_date'          => 
$GLOBALS['phpgw']->yuical->add_listener('planned_date',date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],
 '')),
+                               'completed_date'        => 
$GLOBALS['phpgw']->yuical->add_listener('completed_date',date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],
 ''))
+                       );
+                       
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'custom_ui.js');
+                       
+                       
self::render_template_xsl(array('add_check_list_for_location'), $data);
+               }
+               
+               function edit_check_list_for_location(){
+                       $check_list_id = phpgw::get_var('check_list_id');
+                       
+                       $check_list = 
$this->so_check_list->get_single_with_check_items($check_list_id);
+                       
+                       $date_format = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+       
+                       $data = array
+                       (
+                               'check_list'            => $check_list,
+                               'date_format'           => $date_format
+                       );
+       
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'jquery-ui.custom.min.js');
+                       self::add_javascript('controller', 'controller', 
'custom_ui.js');
+                       
+                       
$GLOBALS['phpgw']->css->add_external_file('controller/templates/base/css/jquery-ui.custom.css');
+                       
+                       self::render_template_xsl('edit_check_list', $data);
+               }
+               
+               function save_check_list_for_location(){
+                       $location_code = phpgw::get_var('location_code');
+                       $control_id = phpgw::get_var('control_id');
+                       $status = phpgw::get_var('status');
+                       $planned_date = strtotime( 
phpgw::get_var('planned_date', 'string') );
+                       $completed_date = strtotime( 
phpgw::get_var('completed_date', 'string') );
+                       $deadline_date = strtotime( 
phpgw::get_var('deadline_date', 'string') );
+                               
+                       $check_list = new controller_check_list();
+                       $check_list->set_location_code($location_code);
+                       $check_list->set_control_id($control_id);
+                       $check_list->set_status($status);
+                       $check_list->set_deadline( $deadline_date );
+                       $check_list->set_planned_date($planned_date);
+                       $check_list->set_completed_date($completed_date);
+                       $check_list->set_equipment_id($equipment_id);
+
+                       $this->so_check_list->add($check_list); 
+                       
+                       $this->redirect(array('menuaction' => 
'controller.uilocation_check_list.view_calendar', 'year'=>2011, 'month'=>10));
+               }
+               
+               public function query(){
+                       $type_id = phpgw::get_var('type_id');
+                       $return_results = phpgw::get_var('results', 'int', 
'REQUEST', 0);
+                       
+                       $type_id = $type_id ? $type_id : 1;
+                       
+                       $location_list = array();
+
+                       $this->bo->sort = "ASC";
+                       $this->bo->start = phpgw::get_var('startIndex');
+                       
+                       $location_list = $this->bo->read(array('user_id' => 
$user_id, 'role_id' =>$role_id, 
'type_id'=>$type_id,'lookup_tenant'=>$lookup_tenant,
+                                                                               
                   'lookup'=>$lookup,'allrows'=>$this->allrows,'dry_run' 
=>$dry_run));
+
+                       $rows_total = $this->bo->read(array('type_id' => 
$type_id, 'allrows' => true));
+                       
+                       foreach($location_list as $location)
+                       {
+                               $results['results'][]= $location;       
+                       }
+                       
+                       $results['total_records'] = count($rows_total);
+                       $results['start'] = $this->start;
+                       $results['sort'] = 'location_code';
+                       $results['dir'] = "ASC";
+                                               
+                       array_walk($results['results'], array($this, 
'add_actions'), array($type));
+                                                       
+                       return $this->yui_results($results);
+               }
+                       
+               public function add_actions(&$value, $key, $params)
+               {
+                       unset($value['query_location']);
+                       
+                       $value['ajax'] = array();
+                       $value['actions'] = array();
+                       $value['labels'] = array();
+                       $value['parameters'] = array();
+                       
+                       $value['ajax'][] = true;
+                       $value['actions'][] = 
html_entity_decode(self::link(array('menuaction' => 
'controller.uicontrol.add_location_to_control', 'location_code' => 
$value['location_code'])));
+                       $value['labels'][] = lang('add_location');
+                       $value['parameters'][] = "control_id";
+               }
+       }

Modified: trunk/controller/inc/class.uicontrol.inc.php
===================================================================
--- trunk/controller/inc/class.uicontrol.inc.php        2011-12-15 08:59:28 UTC 
(rev 8307)
+++ trunk/controller/inc/class.uicontrol.inc.php        2011-12-15 09:02:09 UTC 
(rev 8308)
@@ -1,812 +1,743 @@
-<?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$
-       */      
-
-       phpgw::import_class('controller.uicommon');
-       phpgw::import_class('property.boevent');
-       phpgw::import_class('controller.socontrol');
-       phpgw::import_class('controller.socontrol_group');
-       phpgw::import_class('controller.socontrol_area');
-       phpgw::import_class('controller.socontrol_item');
-       phpgw::import_class('controller.socontrol_item_list');
-       phpgw::import_class('controller.soprocedure');
-
-       include_class('controller', 'control', 'inc/model/');
-       include_class('controller', 'control_area', 'inc/model/');
-       include_class('controller', 'control_item_list', 'inc/model/');
-       include_class('controller', 'control_group_list', 'inc/model/');
-       include_class('controller', 'check_item', 'inc/model/');
-
-       class controller_uicontrol extends controller_uicommon
-       {
-               private $bo;
-               private $so;
-               private $so_procedure;
-               private $so_control_group;
-               private $so_control_area; 
-               private $so_control_item;
-               private $so_control_item_list;
-               private $so_control_group_list;
-               private $so_check_list_list;
-               private $so_check_item;
-               private $_category_acl;
-
-               public $public_functions = array
-               (
-                       'index' =>      true,
-                       'control_list'  =>      true,
-                       'view'  =>      true,
-                       'view_control_details'                          =>      
true,
-                       'save_control_details'                          =>      
true,
-                       'view_control_groups'                           =>      
true,
-                       'save_control_groups'                           =>      
true,
-                       'view_control_items'                            =>      
true,
-                       'save_control_items'                            =>      
true,
-                       'view_check_list'                                       
=>      true,
-                       'generate_check_lists_for_control'      =>      true,
-                       'view_check_lists_for_control'          =>      true,
-                       'get_controls_by_control_area'          =>      true,
-                       'get_locations_for_control'                     =>      
true,
-                       'add_location_to_control'                       =>      
true
-               );
-
-               public function __construct()
-               {
-                       parent::__construct();
-
-                       $this->so = CreateObject('controller.socontrol');
-                       $this->bo = CreateObject('property.boevent',true);
-                       $this->so_procedure = 
CreateObject('controller.soprocedure');
-                       $this->so_control_group = 
CreateObject('controller.socontrol_group');
-                       $this->so_control_area = 
CreateObject('controller.socontrol_area');
-                       $this->so_control_item = 
CreateObject('controller.socontrol_item');
-                       $this->so_control_item_list = 
CreateObject('controller.socontrol_item_list');
-                       $this->so_control_group_list = 
CreateObject('controller.socontrol_group_list');
-                       $this->so_check_list = 
CreateObject('controller.socheck_list');
-                       $this->so_check_item = 
CreateObject('controller.socheck_item');
-
-                       $config = CreateObject('phpgwapi.config','controller');
-                       $config->read();
-                       $this->_category_acl = 
isset($config->config_data['acl_at_control_area']) && 
$config->config_data['acl_at_control_area'] == 1 ? true : false;
-
-                       self::set_active_menu('controller::control');
-               }
-
-               public function control_list()
-               {
-                       if(phpgw::get_var('phpgw_return_as') == 'json') {
-                               return $this->query();
-                       }
-                       self::add_javascript('controller', 'yahoo', 
'datatable.js');
-                       phpgwapi_yui::load_widget('datatable');
-                       phpgwapi_yui::load_widget('paginator');
-
-
-                       // Sigurd: START as categories
-                       $cats   = CreateObject('phpgwapi.categories', -1, 
'controller', '.control');
-                       $cats->supress_info     = true;
-
-                       $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','selected' => 
$control_area_id,'globals' => true,'use_acl' => $this->_category_acl));
-                       array_unshift($control_areas['cat_list'],array 
('cat_id'=>'','name'=> lang('select value')));
-                       $control_areas_array2 = array();
-                       foreach($control_areas['cat_list'] as $cat_list)
-                       {
-                               $control_areas_array2[] = array
-                               (
-                                       'id'    => $cat_list['cat_id'],
-                                       'name'  => $cat_list['name'],
-                               );              
-                       }
-
-
-
-                       $data = array(
-                               'form' => array(
-                                       'toolbar' => array(
-                                               'item' => array(
-                                                       array('type' => 
'filter', 
-                                                               'name' => 
'status',
-                                                               'text' => 
lang('Status'),
-                                                               'list' => array(
-                                                                       array(
-                                                                               
'id' => 'none',
-                                                                               
'name' => lang('Not selected')
-                                                                       ), 
-                                                                       array(
-                                                                               
'id' => 'NEW',
-                                                                               
'name' => lang('NEW')
-                                                                       ), 
-                                                                       array(
-                                                                               
'id' => 'PENDING',
-                                                                               
'name' =>  lang('PENDING')
-                                                                       ), 
-                                                                       array(
-                                                                               
'id' => 'REJECTED',
-                                                                               
'name' => lang('REJECTED')
-                                                                       ), 
-                                                                       array(
-                                                                               
'id' => 'ACCEPTED',
-                                                                               
'name' => lang('ACCEPTED')
-                                                                       )
-                                                               )
-                                                       ),
-                                                       array('type' => 
'filter',
-                                                               'name' => 
'control_areas',
-                                                               'text' => 
lang('Control_area'),
-                                                               'list' => 
$this->so_control_area->get_control_area_select_array(),
-                                                       ),
-                                                       
-                                                       //as categories
-                                                       array('type' => 
'filter',
-                                                               'name' => 
'control_areas',
-                                                               'text' => 
lang('Control_area') . 2,
-                                                               'list' => 
$control_areas_array2,
-                                                       ),
-                                                       array('type' => 
'filter',
-                                                               'name' => 
'responsibilities',
-                                                               'text' => 
lang('Responsibility'),
-                                                               'list' => 
$this->so->get_roles(),
-                                                       ),
-                                                       array('type' => 'text', 
-                                                               'text' => 
lang('searchfield'),
-                                                               'name' => 
'query'
-                                                       ),
-                                                       array(
-                                                               'type' => 
'submit',
-                                                               'name' => 
'search',
-                                                               'value' => 
lang('Search')
-                                                       ),
-                                                       array(
-                                                               'type' => 
'link',
-                                                               'value' => 
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
-                                                               'href' => 
self::link(array('menuaction' => $this->url_prefix.'.toggle_show_inactive'))
-                                                       ),
-                                                       array(
-                                                               'type' => 
'link',
-                                                               'value' => 
lang('New control'),
-                                                               'href' => 
self::link(array('menuaction' => 'controller.uicontrol.view_control_details')),
-                                                               'class' => 
'new_item'
-                                                       ),
-                                               ),
-                                       ),
-                               ),
-                               'datatable' => array(
-                                       'source' => 
self::link(array('menuaction' => 'controller.uicontrol.control_list', 
'phpgw_return_as' => 'json')),
-                                       'field' => array(
-                                               array(
-                                                       'key' => 'id',
-                                                       'label' => lang('ID'),
-                                                       'sortable'      => true,
-                                                       'formatter' => 
'YAHOO.portico.formatLink'
-                                               ),
-                                               array(
-                                                       'key'   =>      'title',
-                                                       'label' =>      
lang('Control title'),
-                                                       'sortable'      =>      
false
-                                               ),
-                                               array(
-                                                       'key' => 'description',
-                                                       'label' => 
lang('description'),
-                                                       'sortable'      => false
-                                               ),
-                                               array(
-                                                       'key' => 
'control_area_name',
-                                                       'label' => 
lang('Control area'),
-                                                       'sortable'      => false
-                                               ),
-                                               array(
-                                                       'key' => 
'responsibility_name',
-                                                       'label' => 
lang('Responsibility'),
-                                                       'sortable'      => false
-                                               ),
-                                               array(
-                                                       'key' => 'link',
-                                                       'hidden' => true
-                                               )
-                                       )
-                               ),
-                       );
-//_debug_array($data);
-
-                       self::render_template_xsl('datatable', $data);
-               }
-
-               public function view_control_details()
-               {
-                       $control_id = phpgw::get_var('id');
-
-                       if(isset($control_id) && $control_id > 0)
-                       {
-                               $control = $this->so->get_single($control_id);
-                       }
-
-                       $control_areas_array = 
$this->so_control_area->get_control_areas_as_array();
-                       
-                       // Sigurd: START as categories
-                       $cats   = CreateObject('phpgwapi.categories', -1, 
'controller', '.control');
-                       $cats->supress_info     = true;
-
-                       $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','selected' => 
$control_area_id,'globals' => true,'use_acl' => $this->_category_acl));
-                       array_unshift($control_areas['cat_list'],array 
('cat_id'=>'','name'=> lang('select value')));
-                       $control_areas_array2 = array();
-                       foreach($control_areas['cat_list'] as $cat_list)
-                       {
-                               $control_areas_array2[] = array
-                               (
-                                       'id'    => $cat_list['cat_id'],
-                                       'name'  => $cat_list['name'],
-                               );              
-                       }
-                       // END as categories
-
-
-                       // Fetches prosedures that are related to first control 
area in list
-                       $control_area_id = $control_areas_array[0]['id'];
-                       $procedures_array = 
$this->so_procedure->get_procedures_by_control_area_id($control_area_id);
-                       $role_array = $this->so->get_roles();
-
-                       $tabs = array( array(
-                                                       'label' => "1: " . 
lang('Details')
-                                               ), array(
-                                                       'label' => "2: " . 
lang('Choose_control_groups')
-                                               ), array(
-                                                       'label' => "3: " . 
lang('Choose_control_items')
-                                               ), array(
-                                                       'label' => "4: " . 
lang('Sort_check_list')
-                                               ));
-
-                       $data = array
-                       (
-                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 0),
-                               'view'                                          
=> "control_details",
-                               'editable'                                      
=> true,
-                               'control'                                       
=> (isset($control)) ? $control->toArray(): null,
-                               'control_areas_array'           => 
$control_areas_array,
-                               'control_areas_array2'          => 
array('options' => $control_areas_array2),
-                               'procedures_array'                      => 
$procedures_array,
-                               'role_array'                            => 
$role_array,
-                               'start_date'                            => 
$GLOBALS['phpgw']->yuical->add_listener('start_date',date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],
 time())),
-                               'end_date'                                      
=> 
$GLOBALS['phpgw']->yuical->add_listener('end_date',date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],
 ''))
-                       );
-
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-                       self::add_javascript('controller', 'controller', 
'jquery.js');
-                       self::add_javascript('controller', 'controller', 
'ajax.js');
-                       self::render_template_xsl(array('control_tabs', 
'control'), $data);
-
-                       $this->use_yui_editor(array('description'));
-               }
-
-               public function save_control_details(){
-                       $control_id = phpgw::get_var('control_id');
-
-                       // Update control details
-                       if(isset($control_id) && $control_id > 0 )
-                       {
-                               $control = $this->so->get_single($control_id);
-                       }
-                       // Add details for control
-                       else {
-                               $control = new controller_control();
-                       }
-
-                       $control->populate();
-
-                       if( $control->get_title() == "" ){
-                               $this->redirect(array('menuaction' => 
'controller.uicontrol.view_control_details', 'control_id'=>$control_id, 
'control_area_id'=>$control->get_control_area_id()));
-                       }
-                       else
-                       {
-                               $control_id = $this->so->store($control);
-                               $this->redirect(array('menuaction' => 
'controller.uicontrol.view_control_groups', 'control_id'=>$control_id, 
'control_area_id'=>$control->get_control_area_id()));
-                       }
-               }
-
-               // Displays control groups based on previously chosen control 
area
-               public function view_control_groups(){
-                       $control_id = phpgw::get_var('control_id');
-                       $control = $this->so->get_single($control_id);
-
-                       // Fetches saved control groups from db
-                       $saved_control_groups = 
$this->so_control_group_list->get_control_groups_by_control_id($control_id);
-                       $saved_control_group_ids = array();
-
-                       foreach($saved_control_groups as $control_group){
-                               $saved_control_group_ids[] = 
$control_group->get_id();
-                       }
-
-                       // Fetches  control groups based on selected control 
area
-                       $control_area = $this->so_control_area->get_single( 
$control->get_control_area_id );
-                       $control_groups_as_array = 
$this->so_control_group->get_control_groups_as_array($control->get_control_area_id());
-
-                       $control_groups = array();
-                       foreach($control_groups_as_array as $control_group){
-                               $control_group_id = $control_group['id'];
-
-                               if( in_array($control_group_id, 
$saved_control_group_ids )){
-                                       $control_groups[] = array("checked" => 
1, "control_group" => $control_group);
-                               }
-                               else
-                               {
-                                       $control_groups[] = array("checked" => 
0, "control_group" => $control_group);
-                               }
-                       }
-
-                       $tabs = array(
-                                               array(
-                                                       'label' => "1: " . 
lang('Details'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 
-                                                                               
                                                                                
   'view' => "view_control_details", 'id' => $control_id))
-                                               ), 
-                                               array(
-                                                       'label' => "2: " . 
lang('Choose_control_groups')
-                                               ), 
-                                               array(
-                                                       'label' => "3: " . 
lang('Choose_control_items')
-                                               ), 
-                                               array(
-                                                       'label' => "4: " . 
lang('Sort_check_list')
-                                               ));
-
-                       $data = array
-                       (
-                               'tabs'                                          
        => $GLOBALS['phpgw']->common->create_tabs($tabs, 1),
-                               'view'                                          
        => "control_groups",
-                               'editable'                                      
        => true,
-                               'control'                                       
        => $control->toArray(),
-                               'control_area'                                  
=> $control_area->toArray(),
-                               'control_groups'                                
=> $control_groups,
-                       );
-
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-                       self::render_template_xsl(array('control_tabs', 
'control_groups'), $data);
-               }
-
-               public function save_control_groups(){
-                       $control_id = phpgw::get_var('control_id');
-                       $control_group_ids = 
phpgw::get_var('control_group_ids');
-
-                       // Deleting earlier saved control groups
-                       
$this->so_control_group_list->delete_control_groups($control_id);
-
-                       $group_order_nr = 1;
-
-                       // Saving control groups 
-                       foreach ($control_group_ids as $control_group_id)
-                       {
-                               $control_group_list = new 
controller_control_group_list();
-                               
$control_group_list->set_control_id($control_id);
-                               
$control_group_list->set_control_group_id($control_group_id);
-                               
$control_group_list->set_order_nr($group_order_nr);
-
-                               
$this->so_control_group_list->add($control_group_list);
-                               $group_order_nr++;
-                       }
-
-                       // Redirect: view_control_items
-                       $this->redirect(array('menuaction' => 
'controller.uicontrol.view_control_items', 
-                                                                 
'control_id'=>$control_id, 'control_group_ids'=>$control_group_ids));
-               }
-
-               // Gets a comma separated list of control groups, and displays 
control items for these groups
-               public function view_control_items(){
-                       $control_id = phpgw::get_var('control_id', 'int');
-                       $control = $this->so->get_single($control_id);
-
-                       $control_group_ids = 
phpgw::get_var('control_group_ids');
-
-                       // Fetches saved control items from db
-                       $saved_control_items = 
$this->so_control_item->get_control_items_by_control_id($control_id);
-                       $saved_control_item_ids = array();
-
-                       foreach($saved_control_items as $control_item){
-                               $saved_control_item_ids[] = 
$control_item->get_id();
-                       }
-
-                       // Array with selected control groups and items
-                       $groups_with_control_items = array();
-
-                       // Fetches control items for control group and 
populates groups_with_control_items with groups and chosen control items
-                       foreach ($control_group_ids as $control_group_id)
-                       {
-                               $group_control_items_array = 
$this->so_control_item->get_control_items_as_array($control_group_id);
-
-                               $control_items_for_group_array = array();
-
-                               foreach($group_control_items_array as 
$control_item){
-                                       $control_item_id = $control_item['id'];
-
-                                       if( in_array($control_item_id, 
$saved_control_item_ids )){
-                                               
$control_items_for_group_array[] = array("checked" => 1, "control_item" => 
$control_item);
-                                       }
-                                       else
-                                       {
-                                               
$control_items_for_group_array[] = array("checked" => 0, "control_item" => 
$control_item);
-                                       }
-                               }
-
-                               $control_group = 
$this->so_control_group->get_single($control_group_id);
-
-                               $groups_with_control_items[] = 
array("control_group" => $control_group->toArray(), "group_control_items" => 
$control_items_for_group_array);
-                       }
-
-                       //print_r( $groups_with_control_items[0] );
-
-                       $tabs = array(
-                                               array(
-                                                       'label' => "1: " . 
lang('Details'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 'view' => "view_control_details", 
-                                                                               
                                                                                
   'id' => $control_id))
-                                               ), 
-                                                       array(
-                                                       'label' => "2: " . 
lang('Choose_control_groups'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_groups', 'view' => "view_control_groups", 
-                                                                               
                                                                                
   'control_id' => $control_id, 'control_group_ids' => $control_group_ids, 
-                                                                               
                                                                                
   'control_area_id' => $control->get_control_area_id()))
-                                               ),
-                                               array('label' => "3: " . 
lang('Choose_control_items')),
-                                               array(
-                                                       'label' => "4: " . 
lang('Sort_check_list')
-                                               ));
-
-                       $data = array
-                       (
-                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 2),
-                               'view'                                          
=> 'control_items',
-                               'control_group_ids'                     => 
implode($control_group_ids, ","),
-                               'control'                                       
=> $control->toArray(),
-                               'groups_with_control_items'     => 
$groups_with_control_items
-                       );
-
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-                       self::add_javascript('controller', 'controller', 
'jquery.js');
-                       self::add_javascript('controller', 'controller', 
'custom_ui.js');
-                       self::render_template_xsl(array('control_tabs', 
'choose_control_items'), $data); 
-               }
-
-               // Saves chosen control items through receiving a comma 
separated list of control tags (1:2, control_group_id:control_item_id) 
-               public function save_control_items(){
-                       $control_id = phpgw::get_var('control_id');
-                       $control_group_ids = explode(",", 
phpgw::get_var('control_group_ids'));
-
-                       // Fetching selected control items. Tags are on the 
format 1:2 (group:item). 
-                       $control_tag_ids = phpgw::get_var('control_tag_ids');
-
-                       // Deleting earlier saved control groups
-                       
$this->so_control_group_list->delete_control_groups($control_id);
-
-                       // Deleting earlier saved control items
-                       
$this->so_control_item_list->delete_control_items($control_id);
-
-                       $group_order_nr = 1;
-
-                       // Saving control groups 
-                       foreach ($control_group_ids as $control_group_id)
-                       {
-                               $control_group_list = new 
controller_control_group_list();
-                               
$control_group_list->set_control_id($control_id);
-                               
$control_group_list->set_control_group_id($control_group_id);
-                               
$control_group_list->set_order_nr($group_order_nr);
-
-                               
$this->so_control_group_list->add($control_group_list);
-                               $group_order_nr++;
-                       }
-
-                       // Saving control items if submit save control items is 
clicked 
-                       foreach ($control_tag_ids as $control_item_tag)
-                       {
-                               // Fetch control_item_id from tag string
-                               $control_item_id = substr($control_item_tag, 
strpos($control_item_tag, ":")+1, strlen($control_item_tag));
-
-                               // Saves control item
-                               $control_item_list = new 
controller_control_item_list();
-                               $control_item_list->set_control_id($control_id);
-                               
$control_item_list->set_control_item_id($control_item_id);
-                               
$this->so_control_item_list->add($control_item_list);
-                       }
-
-                       $this->redirect(array('menuaction' => 
'controller.uicontrol.view_check_list', 'control_id'=>$control_id, 
'control_title'=>$control_title, 'control_group_ids'=>$control_group_ids, 
'control_tag_ids'=>$control_tag_ids ));
-               }
-
-               public function view_check_list(){
-                       $control_id = phpgw::get_var('control_id');
-                       $control = $this->so->get_single($control_id);
-
-                       $control_group_ids = 
phpgw::get_var('control_group_ids');
-
-                       // Fetching selected control tag items. Tags are on the 
format 1:2 (control_group_id:control_item_id) 
-                       $control_tag_ids = phpgw::get_var('control_tag_ids');
-
-                       $control_group_ids = array();
-
-                       //Putting control_group_ids in array control_group_ids
-                       foreach ($control_tag_ids as $control_tag)
-                       {
-                               // Fetching group id from tag
-                               $control_group_id = substr($control_tag, 0, 
strpos($control_tag, ":"));
-
-                               if(!in_array($control_group_id, 
$control_group_ids))
-                                       $control_group_ids[] = 
$control_group_id;  
-                       }
-
-                       $saved_groups_with_items_array = array();
-
-                       //Populating array with saved control items for each 
group
-                       foreach ($control_group_ids as $control_group_id)
-                       {
-                               $saved_control_items = 
$this->so_control_item->get_control_items_by_control_id_and_group($control_id, 
$control_group_id);
-
-                               $control_group = 
$this->so_control_group->get_single($control_group_id);
-
-                               $control_item = 
$this->so_control_item->get_single($control_item_id);
-
-                               $saved_groups_with_items_array[] = 
array("control_group" => $control_group->toArray(), "control_items" => 
$saved_control_items);
-                       }
-
-                       $tabs = array(
-                                               array(
-                                                       'label' => "1: " . 
lang('Details'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 
-                                                                               
                                                                                
   'view' => "view_control_details", 'id' => $control_id))
-                                               ),array(
-                                                       'label' => "2: " . 
lang('Choose_control_groups'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_groups', 
-                                                                               
                                                                                
   'view' => "view_control_groups", 'control_id' => $control_id, 
-                                                                               
                                                                                
   'control_group_ids' => $control_group_ids, 
-                                                                               
                                                                                
   'control_area_id' => $control->get_control_area_id()))
-                                               ),array(
-                                                       'label' => "3: " . 
lang('Choose_control_items'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_items', 
-                                                                               
                                                                                
   'view' => "view_control_items", 'control_id' => $control_id, 
-                                                                               
                                                                                
   'control_group_ids' => $control_group_ids))
-                                               ),array('label' => "4: " . 
lang('Sort_check_list')
-                                               )
-
-                                       );
-
-                       $data = array
-                       (
-                               'tabs'                                  => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 3),
-                               'view'                                  => 
"sort_check_list",
-                               'control'                               => 
$control->toArray(),
-                               'saved_groups_with_items_array' => 
$saved_groups_with_items_array
-                       );
-
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-                       self::add_javascript('controller', 'controller', 
'jquery.js');
-                       self::add_javascript('controller', 'controller', 
'custom_ui.js');
-                       self::add_javascript('controller', 'controller', 
'yui_min_3_4_3.js');
-                       self::add_javascript('controller', 'controller', 
'custom_drag_drop.js');
-                       self::add_javascript('controller', 'controller', 
'ajax.js');
-                       self::render_template_xsl(array('control_tabs', 
'sort_check_list'), $data);
-               }
-
-               public function generate_check_lists_for_control(){
-                       $control_id = phpgw::get_var('control_id');
-                       $control = $this->so->get_single($control_id);
-
-                       $start_date = $control->get_start_date();
-                       $end_date = $control->get_end_date();
-                       $repeat_type = $control->get_repeat_type();
-                       $repeat_interval = $control->get_repeat_interval();
-
-                       $status = FALSE;
-                       $comment = "Kommentar for sjekkliste";
-                       $deadline = $start_date;
-
-                       // Saving check_list
-                       $new_check_list = new controller_check_list();
-                       $new_check_list->set_control_id( $control_id );
-                       $new_check_list->set_status( $status );
-                       $new_check_list->set_comment( $comment );
-                       $new_check_list->set_deadline( $deadline );
-
-                       $check_list_id = $this->so_check_list->store( 
$new_check_list );
-
-                       $control_items_list = 
$this->so_control_item->get_control_items_by_control_id($control_id);
-
-                       foreach($control_items_list as $control_item){
-
-                               $status = '0';
-                               $comment = "Kommentar for sjekk item";
-
-                               // Saving check_items for a list
-                               $new_check_item = new controller_check_item();
-                               $new_check_item->set_check_list_id( 
$check_list_id );
-
-                               $new_check_item->set_control_item_id( 
$control_item->get_id() );
-                               $new_check_item->set_status( $status );
-                               $new_check_item->set_comment( $comment );
-
-                               $saved_check_item = 
$this->so_check_item->store( $new_check_item );
-                       }
-
-                       $this->redirect(array('menuaction' => 
'controller.uicontrol.view_check_lists_for_control', 'control_id'=>$control_id 
));
-               }
-
-               public function view_check_lists_for_control()
-               {
-                       $control_id = phpgw::get_var('control_id');
-                       $control = $this->so->get_single($control_id);
-
-                       $date_format = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-
-                       $check_list_array = 
$this->so_check_list->get_check_lists_for_control( $control_id );
-
-                       $tabs = array(
-                                               array(
-                                                       'label' => "1: " . 
lang('Details'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 
-                                                                               
                                                                                
   'view' => "view_control_details", 'id' => $control_id))
-                                               ),array(
-                                                       'label' => "2: " . 
lang('Choose_control_groups'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_groups', 
-                                                                               
                                                                                
   'view' => "view_control_groups", 'control_id' => $control_id, 
-                                                                               
                                                                                
   'control_group_ids' => $control_group_ids, 
-                                                                               
                                                                                
   'control_area_id' => $control->get_control_area_id()))
-                                               ),array(
-                                                       'label' => "3: " . 
lang('Choose_control_items'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_items', 
-                                                                               
                                                                                
   'view' => "view_control_items", 'control_id' => $control_id, 
-                                                                               
                                                                                
   'control_group_ids' => $control_group_ids))
-                                               ),array('label' => "4: " . 
lang('Sort_check_list')
-                                               )
-                                       );
-
-                       $data = array
-                       (
-                               'tabs'                          => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 4),
-                               'view'                          => 
"view_check_lists",
-                               'control_as_array'      => $control->toArray(),
-                               'check_list_array'      => $check_list_array,
-                               'date_format'           => $date_format
-                       );
-
-                       self::render_template_xsl(array('control_tabs', 
'tab_view_check_lists'), $data);
-                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
-               }
-
-               // Returns control list info as JSON
-               public function get_controls_by_control_area()
-               {
-                       $control_area_id = phpgw::get_var('control_area_id');
-
-                       $controls_array = 
$this->so->get_controls_by_control_area($control_area_id);
-
-                       if(count($controls_array)>0)
-                               return json_encode( $controls_array );
-                       else
-                               return null;
-               }
-
-               // Returns locations for a control
-               public function get_locations_for_control()
-               {
-                       $control_id = phpgw::get_var('control_id');
-                       $locations_for_control_array = 
$this->so->get_locations_for_control($control_id);
-
-                       foreach($locations_for_control_array as $location)
-                       {
-                               $results['results'][]= $location;
-                       }
-
-                       $results['total_records'] = count( 
$locations_for_control_array );
-                       $results['start'] = 1;
-                       $results['sort'] = 'location_code';
-
-                       array_walk($results['results'], array($this, 
'add_actions'), array($type));
-
-                       return $this->yui_results($results);
-               }
-
-               public function add_location_to_control()
-               {
-                       $control_id = phpgw::get_var('control_id');
-                       $location_code = phpgw::get_var('location_code');
-
-                       $this->so->add_location_to_control($control_id, 
$location_code);
-               }
-
-               public function get_bim_types()
-               {
-                       return $this->so->get_bim_types();
-               }
-
-               public function query()
-               {
-                       $params = array(
-                               'start' => phpgw::get_var('startIndex', 'int', 
'REQUEST', 0),
-                               'results' => phpgw::get_var('results', 'int', 
'REQUEST', null),
-                               'query' => phpgw::get_var('query'),
-                               'sort'  => phpgw::get_var('sort'),
-                               'dir'   => phpgw::get_var('dir'),
-                               'filters' => $filters
-                       );
-
-                       $ctrl_area = phpgw::get_var('control_areas');
-                       if(isset($ctrl_area) && $ctrl_area > 0)
-                       {
-                               $filters['control_areas'] = $ctrl_area; 
-                       }
-                       $responsibility = phpgw::get_var('responsibilities');
-                       if(isset($responsibility) && $responsibility > 0)
-                       {
-                               $filters['responsibilities'] = $responsibility; 
-                       }
-
-                       $search_for = phpgw::get_var('query');
-
-                       
if($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
-                       {
-                               $user_rows_per_page = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
-                       }
-                       else {
-                               $user_rows_per_page = 10;
-                       }
-
-                       // YUI variables for paging and sorting
-                       $start_index    = phpgw::get_var('startIndex', 'int');
-                       $num_of_objects = phpgw::get_var('results', 'int', 
'GET', $user_rows_per_page);
-                       $sort_field             = phpgw::get_var('sort');
-                       if($sort_field == null)
-                       {
-                               $sort_field = 'control_group_id';
-                       }
-                       $sort_ascending = phpgw::get_var('dir') == 'desc' ? 
false : true;
-                       //Create an empty result set
-                       $records = array();
-
-                       //Retrieve a contract identifier and load corresponding 
contract
-                       $control_id = phpgw::get_var('control_id');
-                       if(isset($control_id))
-                       {
-                               $control = $this->so->get_single($control_id);
-                       }
-
-                       $result_objects = $this->so->get($start_index, 
$num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, 
$filters);
-                       $object_count = $this->so->get_count($search_for, 
$search_type, $filters);
-                       //var_dump($result_objects);
-
-                       $results = array();
-
-                       foreach($result_objects as $control_obj)
-                       {
-                               $results['results'][] = 
$control_obj->serialize();
-                       }
-
-                       $results['total_records'] = $object_count;
-                       $results['start'] = $params['start'];
-                       $results['sort'] = $params['sort'];
-                       $results['dir'] = $params['dir'];
-
-                       array_walk($results["results"], array($this, 
"_add_links"), "controller.uicontrol.view_control_details");
-
-                       return $this->yui_results($results);
-               }
-       }
+<?php 
+       phpgw::import_class('controller.uicommon');
+       phpgw::import_class('property.boevent');
+       phpgw::import_class('controller.socontrol');
+       phpgw::import_class('controller.socontrol_group');
+       phpgw::import_class('controller.socontrol_area');
+       phpgw::import_class('controller.socontrol_item');
+       phpgw::import_class('controller.socontrol_item_list');
+       phpgw::import_class('controller.soprocedure');
+       
+       include_class('controller', 'control', 'inc/model/');
+       include_class('controller', 'control_area', 'inc/model/');
+       include_class('controller', 'control_item_list', 'inc/model/');
+       include_class('controller', 'control_group_list', 'inc/model/');
+       include_class('controller', 'check_item', 'inc/model/');
+       
+       class controller_uicontrol extends controller_uicommon
+       {
+               private $bo;
+               private $so;
+               private $so_procedure;
+               private $so_control_group;
+               private $so_control_area; 
+               private $so_control_item;
+               private $so_control_item_list;
+               private $so_control_group_list;
+               private $so_check_list_list;
+               private $so_check_item;
+               
+               public $public_functions = array
+               (
+                       'index' =>      true,
+                       'control_list'  =>      true,
+                       'view'  =>      true,
+                       'view_control_details'                          =>      
true,
+                       'save_control_details'                          =>      
true,
+                       'view_control_groups'                           =>      
true,
+                       'save_control_groups'                           =>      
true,
+                       'view_control_items'                            =>      
true,
+                       'save_control_items'                            =>      
true,
+                       'view_check_list'                                       
=>      true,
+                       'generate_check_lists_for_control'      =>      true,
+                       'view_check_lists_for_control'          =>      true,
+                       'get_controls_by_control_area'          =>      true,
+                       'get_locations_for_control'                     =>      
true,
+                       'add_location_to_control'                       =>      
true
+               );
+
+               public function __construct()
+               {
+                       parent::__construct();
+
+                       $this->so = CreateObject('controller.socontrol');
+                       $this->bo = CreateObject('property.boevent',true);
+                       $this->so_procedure = 
CreateObject('controller.soprocedure');
+                       $this->so_control_group = 
CreateObject('controller.socontrol_group');
+                       $this->so_control_area = 
CreateObject('controller.socontrol_area');
+                       $this->so_control_item = 
CreateObject('controller.socontrol_item');
+                       $this->so_control_item_list = 
CreateObject('controller.socontrol_item_list');
+                       $this->so_control_group_list = 
CreateObject('controller.socontrol_group_list');
+                       $this->so_check_list = 
CreateObject('controller.socheck_list');
+                       $this->so_check_item = 
CreateObject('controller.socheck_item');
+                       
+                       self::set_active_menu('controller::control');
+               }
+               
+               public function control_list()
+               {
+                       if(phpgw::get_var('phpgw_return_as') == 'json') {
+                               return $this->query();
+                       }
+                       self::add_javascript('controller', 'yahoo', 
'datatable.js');
+                       phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('paginator');
+
+                       $data = array(
+                               'form' => array(
+                                       'toolbar' => array(
+                                               'item' => array(
+                                                       array('type' => 
'filter', 
+                                                               'name' => 
'status',
+                                'text' => lang('Status'),
+                                'list' => array(
+                                    array(
+                                        'id' => 'none',
+                                        'name' => lang('Not selected')
+                                    ), 
+                                    array(
+                                        'id' => 'NEW',
+                                        'name' => lang('NEW')
+                                    ), 
+                                    array(
+                                        'id' => 'PENDING',
+                                        'name' =>  lang('PENDING')
+                                    ), 
+                                    array(
+                                        'id' => 'REJECTED',
+                                        'name' => lang('REJECTED')
+                                    ), 
+                                    array(
+                                        'id' => 'ACCEPTED',
+                                        'name' => lang('ACCEPTED')
+                                    )
+                                )
+                            ),
+                                                       array('type' => 
'filter',
+                                                               'name' => 
'control_areas',
+                                'text' => lang('Control_area'),
+                                'list' => 
$this->so_control_area->get_control_area_select_array(),
+                                                       ),
+                                                       array('type' => 
'filter',
+                                                               'name' => 
'responsibilities',
+                                'text' => lang('Responsibility'),
+                                'list' => $this->so->get_roles(),
+                                                       ),
+                                                       array('type' => 'text', 
+                                'text' => lang('searchfield'),
+                                                               'name' => 
'query'
+                                                       ),
+                                                       array(
+                                                               'type' => 
'submit',
+                                                               'name' => 
'search',
+                                                               'value' => 
lang('Search')
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
+                                                               'href' => 
self::link(array('menuaction' => $this->url_prefix.'.toggle_show_inactive'))
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
lang('New control'),
+                                                               'href' => 
self::link(array('menuaction' => 'controller.uicontrol.view_control_details')),
+                                                               'class' => 
'new_item'
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                               'datatable' => array(
+                                       'source' => 
self::link(array('menuaction' => 'controller.uicontrol.control_list', 
'phpgw_return_as' => 'json')),
+                                       'field' => array(
+                                               array(
+                                                       'key' => 'id',
+                                                       'label' => lang('ID'),
+                                                       'sortable'      => true,
+                                                       'formatter' => 
'YAHOO.portico.formatLink'
+                                               ),
+                                               array(
+                                                       'key'   =>      'title',
+                                                       'label' =>      
lang('Control title'),
+                                                       'sortable'      =>      
false
+                                               ),
+                                               array(
+                                                       'key' => 'description',
+                                                       'label' => 
lang('description'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 
'control_area_name',
+                                                       'label' => 
lang('Control area'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 
'responsibility_name',
+                                                       'label' => 
lang('Responsibility'),
+                                                       'sortable'      => false
+                                               ),
+                                               array(
+                                                       'key' => 'link',
+                                                       'hidden' => true
+                                               )
+                                       )
+                               ),
+                       );
+//_debug_array($data);
+
+                       self::render_template_xsl('datatable', $data);
+               }
+               
+               public function view_control_details()
+               {
+                       $control_id = phpgw::get_var('id');
+               
+                       if(isset($control_id) && $control_id > 0)
+                       {
+                               $control = $this->so->get_single($control_id);
+                       }
+
+                       $control_areas_array = 
$this->so_control_area->get_control_areas_as_array();
+
+                       // Fetches prosedures that are related to first control 
area in list
+                       $control_area_id = $control_areas_array[0]['id'];
+                       $procedures_array = 
$this->so_procedure->get_procedures_by_control_area_id($control_area_id);
+                       $role_array = $this->so->get_roles();
+                       
+                       $tabs = array( array(
+                                                       'label' => "1: " . 
lang('Details')
+                                               ), array(
+                                                       'label' => "2: " . 
lang('Choose_control_groups')
+                                               ), array(
+                                                       'label' => "3: " . 
lang('Choose_control_items')
+                                               ), array(
+                                                       'label' => "4: " . 
lang('Sort_check_list')
+                                               ));
+                       
+                       $data = array
+                       (
+                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 0),
+                               'view'                                          
=> "control_details",
+                               'editable'                                      
=> true,
+                               'control'                                       
=> (isset($control)) ? $control->toArray(): null,
+                               'control_areas_array'           => 
$control_areas_array,
+                               'procedures_array'                      => 
$procedures_array,
+                               'role_array'                            => 
$role_array,
+                               'start_date'                            => 
$GLOBALS['phpgw']->yuical->add_listener('start_date',date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],
 time())),
+                               'end_date'                                      
=> 
$GLOBALS['phpgw']->yuical->add_listener('end_date',date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],
 ''))
+                       );
+                       
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'ajax.js');
+                       self::render_template_xsl(array('control_tabs', 
'control'), $data);
+                       
+                       $this->use_yui_editor(array('description'));
+               }
+               
+               public function save_control_details(){
+                       $control_id = phpgw::get_var('control_id');             
+                       
+                       // Update control details
+                       if(isset($control_id) && $control_id > 0 )
+                       {
+                               $control = $this->so->get_single($control_id);
+                       }
+                       // Add details for control
+                       else {
+                               $control = new controller_control();
+                       }
+                       
+                       $control->populate();
+                                                                       
+                       if( $control->get_title() == "" ){
+                               $this->redirect(array('menuaction' => 
'controller.uicontrol.view_control_details', 'control_id'=>$control_id, 
'control_area_id'=>$control->get_control_area_id()));     
+                       }
+                       else
+                       {
+                               $control_id = $this->so->store($control);
+                               $this->redirect(array('menuaction' => 
'controller.uicontrol.view_control_groups', 'control_id'=>$control_id, 
'control_area_id'=>$control->get_control_area_id()));
+                       }
+               }
+                                               
+               // Displays control groups based on previously chosen control 
area
+               public function view_control_groups(){
+                       $control_id = phpgw::get_var('control_id');
+                       $control = $this->so->get_single($control_id);  
+                                                                       
+                       // Fetches saved control groups from db
+                       $saved_control_groups = 
$this->so_control_group_list->get_control_groups_by_control_id($control_id);
+                       $saved_control_group_ids = array();
+                       
+                       foreach($saved_control_groups as $control_group){
+                               $saved_control_group_ids[] = 
$control_group->get_id();
+                       }
+                       
+                       // Fetches  control groups based on selected control 
area                                               
+                       $control_area = $this->so_control_area->get_single( 
$control->get_control_area_id );            
+                       $control_groups_as_array = 
$this->so_control_group->get_control_groups_as_array($control->get_control_area_id());
+                       
+                       $control_groups = array();
+                       foreach($control_groups_as_array as $control_group){
+                               $control_group_id = $control_group['id'];
+                               
+                               if( in_array($control_group_id, 
$saved_control_group_ids )){
+                                       $control_groups[] = array("checked" => 
1, "control_group" => $control_group);
+                               }
+                               else
+                               {
+                                       $control_groups[] = array("checked" => 
0, "control_group" => $control_group);
+                               }
+                       }
+                       
+                       $tabs = array(
+                                               array(
+                                                       'label' => "1: " . 
lang('Details'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 
+                                                                               
                                                                                
   'view' => "view_control_details", 'id' => $control_id))
+                                               ), 
+                                               array(
+                                                       'label' => "2: " . 
lang('Choose_control_groups')
+                                               ), 
+                                               array(
+                                                       'label' => "3: " . 
lang('Choose_control_items')
+                                               ), 
+                                               array(
+                                                       'label' => "4: " . 
lang('Sort_check_list')
+                                               ));
+                       
+                       $data = array
+                       (
+                               'tabs'                                          
        => $GLOBALS['phpgw']->common->create_tabs($tabs, 1),
+                               'view'                                          
        => "control_groups",
+                               'editable'                                      
        => true,
+                               'control'                                       
        => $control->toArray(),
+                               'control_area'                                  
=> $control_area->toArray(),
+                               'control_groups'                                
=> $control_groups,
+                       );
+                       
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+                       self::render_template_xsl(array('control_tabs', 
'control_groups'), $data);
+               }
+               
+               public function save_control_groups(){
+                       $control_id = phpgw::get_var('control_id');
+                       $control_group_ids = 
phpgw::get_var('control_group_ids');               
+
+                       // Deleting earlier saved control groups
+                       
$this->so_control_group_list->delete_control_groups($control_id);
+                       
+                       $group_order_nr = 1;
+
+                       // Saving control groups 
+                       foreach ($control_group_ids as $control_group_id)
+                       {
+                               $control_group_list = new 
controller_control_group_list();
+                               
$control_group_list->set_control_id($control_id);
+                               
$control_group_list->set_control_group_id($control_group_id);
+                               
$control_group_list->set_order_nr($group_order_nr);
+                                                       
+                               
$this->so_control_group_list->add($control_group_list);
+                               $group_order_nr++;
+                       }
+
+                       // Redirect: view_control_items
+                       $this->redirect(array('menuaction' => 
'controller.uicontrol.view_control_items', 
+                                                                 
'control_id'=>$control_id, 'control_group_ids'=>$control_group_ids)); 
+               }
+               
+               // Gets a comma separated list of control groups, and displays 
control items for these groups
+               public function view_control_items(){
+                       $control_id = phpgw::get_var('control_id', 'int');
+                       $control = $this->so->get_single($control_id);
+                       
+                       $control_group_ids = 
phpgw::get_var('control_group_ids');
+               
+                       // Fetches saved control items from db
+                       $saved_control_items = 
$this->so_control_item->get_control_items_by_control_id($control_id);
+                       $saved_control_item_ids = array();
+                       
+                       foreach($saved_control_items as $control_item){
+                               $saved_control_item_ids[] = 
$control_item->get_id();
+                       }
+                       
+                       // Array with selected control groups and items
+                       $groups_with_control_items = array();
+                       
+                       // Fetches control items for control group and 
populates groups_with_control_items with groups and chosen control items
+                       foreach ($control_group_ids as $control_group_id)
+                       {       
+                               $group_control_items_array = 
$this->so_control_item->get_control_items_as_array($control_group_id);
+                               
+                               $control_items_for_group_array = array();
+                               
+                               foreach($group_control_items_array as 
$control_item){
+                                       $control_item_id = $control_item['id'];
+                                       
+                                       if( in_array($control_item_id, 
$saved_control_item_ids )){
+                                               
$control_items_for_group_array[] = array("checked" => 1, "control_item" => 
$control_item);
+                                       }
+                                       else
+                                       {
+                                               
$control_items_for_group_array[] = array("checked" => 0, "control_item" => 
$control_item);
+                                       }
+                               }
+                               
+                               $control_group = 
$this->so_control_group->get_single($control_group_id);
+                               
+                               $groups_with_control_items[] = 
array("control_group" => $control_group->toArray(), "group_control_items" => 
$control_items_for_group_array);
+                       }                       
+                       
+                       //print_r( $groups_with_control_items[0] );
+                       
+                       $tabs = array(
+                                               array(
+                                                       'label' => "1: " . 
lang('Details'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 'view' => "view_control_details", 
+                                                                               
                                                                                
   'id' => $control_id))
+                                               ), 
+                                                       array(
+                                                       'label' => "2: " . 
lang('Choose_control_groups'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_groups', 'view' => "view_control_groups", 
+                                                                               
                                                                               
'control_id' => $control_id, 'control_group_ids' => $control_group_ids, 
+                                                                               
                                                                               
'control_area_id' => $control->get_control_area_id()))
+                                               ),
+                                               array('label' => "3: " . 
lang('Choose_control_items')),
+                                               array(
+                                                       'label' => "4: " . 
lang('Sort_check_list')
+                                               ));
+                                       
+                       $data = array
+                       (
+                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 2),
+                               'view'                                          
=> 'control_items',
+                               'control_group_ids'                     => 
implode($control_group_ids, ","),
+                               'control'                                   => 
$control->toArray(),
+                               'groups_with_control_items'     => 
$groups_with_control_items                   
+                       );
+                       
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'custom_ui.js');
+                       self::render_template_xsl(array('control_tabs', 
'choose_control_items'), $data); 
+               }
+               
+               // Saves chosen control items through receiving a comma 
separated list of control tags (1:2, control_group_id:control_item_id) 
+               public function save_control_items(){
+                       $control_id = phpgw::get_var('control_id');
+                       $control_group_ids = explode(",", 
phpgw::get_var('control_group_ids'));
+                       
+                       // Fetching selected control items. Tags are on the 
format 1:2 (group:item). 
+                       $control_tag_ids = phpgw::get_var('control_tag_ids');
+                       
+                       // Deleting earlier saved control groups
+                       
$this->so_control_group_list->delete_control_groups($control_id);
+                       
+                       // Deleting earlier saved control items
+                       
$this->so_control_item_list->delete_control_items($control_id);
+                                               
+                       $group_order_nr = 1;
+                       
+                       // Saving control groups 
+                       foreach ($control_group_ids as $control_group_id)
+                       {
+                               $control_group_list = new 
controller_control_group_list();
+                               
$control_group_list->set_control_id($control_id);
+                               
$control_group_list->set_control_group_id($control_group_id);
+                               
$control_group_list->set_order_nr($group_order_nr);
+                                                       
+                               
$this->so_control_group_list->add($control_group_list);
+                               $group_order_nr++;
+                       }
+
+                       // Saving control items if submit save control items is 
clicked 
+                       foreach ($control_tag_ids as $control_item_tag)
+                       {       
+                               // Fetch control_item_id from tag string
+                               $control_item_id = substr($control_item_tag, 
strpos($control_item_tag, ":")+1, strlen($control_item_tag));
+                                                       
+                               // Saves control item
+                               $control_item_list = new 
controller_control_item_list();
+                               $control_item_list->set_control_id($control_id);
+                               
$control_item_list->set_control_item_id($control_item_id);
+                               
$this->so_control_item_list->add($control_item_list);
+                       }       
+       
+                       $this->redirect(array('menuaction' => 
'controller.uicontrol.view_check_list', 'control_id'=>$control_id, 
'control_title'=>$control_title, 'control_group_ids'=>$control_group_ids, 
'control_tag_ids'=>$control_tag_ids ));      
+               }
+               
+               public function view_check_list(){
+                       $control_id = phpgw::get_var('control_id');
+                       $control = $this->so->get_single($control_id);
+                       
+                       $control_group_ids = 
phpgw::get_var('control_group_ids');
+                       
+                       // Fetching selected control tag items. Tags are on the 
format 1:2 (control_group_id:control_item_id) 
+                       $control_tag_ids = phpgw::get_var('control_tag_ids');
+                       
+                       $control_group_ids = array();
+                       
+                       //Putting control_group_ids in array control_group_ids
+                       foreach ($control_tag_ids as $control_tag)
+                       {       
+                               // Fetching group id from tag   
+                               $control_group_id = substr($control_tag, 0, 
strpos($control_tag, ":"));
+
+                               if(!in_array($control_group_id, 
$control_group_ids))
+                                       $control_group_ids[] = 
$control_group_id;  
+                       }
+                       
+                       $saved_groups_with_items_array = array();
+                       
+                       //Populating array with saved control items for each 
group
+                       foreach ($control_group_ids as $control_group_id)
+                       {       
+                               $saved_control_items = 
$this->so_control_item->get_control_items_by_control_id_and_group($control_id, 
$control_group_id);
+                               
+                               $control_group = 
$this->so_control_group->get_single($control_group_id);
+                               
+                               $control_item = 
$this->so_control_item->get_single($control_item_id);
+                               
+                               $saved_groups_with_items_array[] = 
array("control_group" => $control_group->toArray(), "control_items" => 
$saved_control_items);
+                       }
+                       
+                       $tabs = array(
+                                               array(
+                                                       'label' => "1: " . 
lang('Details'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 
+                                                                               
                                                                                
   'view' => "view_control_details", 'id' => $control_id))
+                                               ),array(
+                                                       'label' => "2: " . 
lang('Choose_control_groups'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_groups', 
+                                                                               
                                                                                
   'view' => "view_control_groups", 'control_id' => $control_id, 
+                                                                               
                                                                                
   'control_group_ids' => $control_group_ids, 
+                                                                               
                                                                                
   'control_area_id' => $control->get_control_area_id()))
+                                               ),array(
+                                                       'label' => "3: " . 
lang('Choose_control_items'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_items', 
+                                                                               
                                                                                
   'view' => "view_control_items", 'control_id' => $control_id, 
+                                                                               
                                                                                
   'control_group_ids' => $control_group_ids))
+                                               ),array('label' => "4: " . 
lang('Sort_check_list')
+                                               )
+                                               
+                                       );
+                       
+                       $data = array
+                       (
+                               'tabs'                                  => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 3),
+                               'view'                                  => 
"sort_check_list",
+                               'control'                               => 
$control->toArray(),
+                               'saved_groups_with_items_array' => 
$saved_groups_with_items_array
+                       );
+                       
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'custom_ui.js');
+                       self::add_javascript('controller', 'controller', 
'yui_min_3_4_3.js');
+                       self::add_javascript('controller', 'controller', 
'custom_drag_drop.js');
+                       self::add_javascript('controller', 'controller', 
'ajax.js');
+                       self::render_template_xsl(array('control_tabs', 
'sort_check_list'), $data);
+               }
+               
+               public function generate_check_lists_for_control(){
+                       $control_id = phpgw::get_var('control_id');
+                       $control = $this->so->get_single($control_id);
+
+                       $start_date = $control->get_start_date();
+                       $end_date = $control->get_end_date();
+                       $repeat_type = $control->get_repeat_type();
+                       $repeat_interval = $control->get_repeat_interval();
+                       
+                       $status = FALSE;
+                       $comment = "Kommentar for sjekkliste";
+                       $deadline = $start_date;
+                       
+                       // Saving check_list
+                       $new_check_list = new controller_check_list();
+                       $new_check_list->set_control_id( $control_id );
+                       $new_check_list->set_status( $status );
+                       $new_check_list->set_comment( $comment );
+                       $new_check_list->set_deadline( $deadline );
+                       
+                       $check_list_id = $this->so_check_list->store( 
$new_check_list );
+                       
+                       $control_items_list = 
$this->so_control_item->get_control_items_by_control_id($control_id);
+                       
+                       foreach($control_items_list as $control_item){
+                               
+                               $status = '0';
+                               $comment = "Kommentar for sjekk item";
+                               
+                               // Saving check_items for a list
+                               $new_check_item = new controller_check_item();
+                               $new_check_item->set_check_list_id( 
$check_list_id );
+                               
+                               $new_check_item->set_control_item_id( 
$control_item->get_id() );
+                               $new_check_item->set_status( $status );
+                               $new_check_item->set_comment( $comment );
+                                                               
+                               $saved_check_item = 
$this->so_check_item->store( $new_check_item );
+                       }       
+                       
+                       $this->redirect(array('menuaction' => 
'controller.uicontrol.view_check_lists_for_control', 'control_id'=>$control_id 
));
+               }
+               
+               public function view_check_lists_for_control()
+               {
+                       $control_id = phpgw::get_var('control_id');
+                       $control = $this->so->get_single($control_id);
+                       
+                       $date_format = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+               
+                       $check_list_array = 
$this->so_check_list->get_check_lists_for_control( $control_id );   
+                       
+                       $tabs = array(
+                                               array(
+                                                       'label' => "1: " . 
lang('Details'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_details', 
+                                                                               
                                                                                
   'view' => "view_control_details", 'id' => $control_id))
+                                               ),array(
+                                                       'label' => "2: " . 
lang('Choose_control_groups'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_groups', 
+                                                                               
                                                                                
   'view' => "view_control_groups", 'control_id' => $control_id, 
+                                                                               
                                                                                
   'control_group_ids' => $control_group_ids, 
+                                                                               
                                                                                
   'control_area_id' => $control->get_control_area_id()))
+                                               ),array(
+                                                       'label' => "3: " . 
lang('Choose_control_items'),
+                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol.view_control_items', 
+                                                                               
                                                                                
   'view' => "view_control_items", 'control_id' => $control_id, 
+                                                                               
                                                                                
   'control_group_ids' => $control_group_ids))
+                                               ),array('label' => "4: " . 
lang('Sort_check_list')
+                                               )
+                                       );
+                       
+                       $data = array
+                       (
+                               'tabs'                          => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 4),
+                               'view'                          => 
"view_check_lists",
+                               'control_as_array'      => $control->toArray(),
+                               'check_list_array'      => $check_list_array,
+                               'date_format'           => $date_format
+                       );
+                       
+                       self::render_template_xsl(array('control_tabs', 
'tab_view_check_lists'), $data);
+                       self::add_javascript('controller', 'yahoo', 
'control_tabs.js');
+               }
+                       
+               // Returns control list info as JSON
+               public function get_controls_by_control_area()
+               {
+                       $control_area_id = phpgw::get_var('control_area_id');
+                       
+                       $controls_array = 
$this->so->get_controls_by_control_area($control_area_id);
+                       
+                       if(count($controls_array)>0)
+                               return json_encode( $controls_array );
+                       else
+                               return null;
+               }
+               
+               // Returns locations for a control
+               public function get_locations_for_control()
+               {
+                       $control_id = phpgw::get_var('control_id');
+                       $locations_for_control_array = 
$this->so->get_locations_for_control($control_id);
+                       
+                       foreach($locations_for_control_array as $location)
+                       {
+                               $results['results'][]= $location;       
+                       }
+                       
+                       $results['total_records'] = count( 
$locations_for_control_array );
+                       $results['start'] = 1;
+                       $results['sort'] = 'location_code';
+                                               
+                       array_walk($results['results'], array($this, 
'add_actions'), array($type));
+                                                       
+                       return $this->yui_results($results);
+               }
+               
+               public function add_actions(&$value, $key, $params)
+               {
+                       unset($value['query_location']);
+                       
+                       $value['ajax'] = array();
+                       $value['actions'] = array();
+                       $value['labels'] = array();
+                       $value['parameters'] = array();
+                       
+                       $value['ajax'][] = false;
+                       $value['actions'][] = 
html_entity_decode(self::link(array('menuaction' => 
'controller.uicheck_list_for_location.add_check_list_for_location', 
'location_code' => $value['location_code'])));
+                       $value['labels'][] = lang('add_check_list_to_location');
+                       $value['parameters'][] = "control_id";
+               }
+               
+               public function add_location_to_control()
+               {
+                       $control_id = phpgw::get_var('control_id');
+                       $location_code = phpgw::get_var('location_code');
+                       
+                       $this->so->add_location_to_control($control_id, 
$location_code);
+               }
+               
+               public function query()
+               {
+                       $params = array(
+                               'start' => phpgw::get_var('startIndex', 'int', 
'REQUEST', 0),
+                               'results' => phpgw::get_var('results', 'int', 
'REQUEST', null),
+                               'query' => phpgw::get_var('query'),
+                               'sort'  => phpgw::get_var('sort'),
+                               'dir'   => phpgw::get_var('dir'),
+                               'filters' => $filters
+                       );
+                       
+                       $ctrl_area = phpgw::get_var('control_areas');
+                       if(isset($ctrl_area) && $ctrl_area > 0)
+                       {
+                               $filters['control_areas'] = $ctrl_area; 
+                       }
+                       $responsibility = phpgw::get_var('responsibilities');
+                       if(isset($responsibility) && $responsibility > 0)
+                       {
+                               $filters['responsibilities'] = $responsibility; 
+                       }
+                                                                               
+                       $search_for = phpgw::get_var('query');
+
+                       
if($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
+                       {
+                               $user_rows_per_page = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+                       }
+                       else {
+                               $user_rows_per_page = 10;
+                       }
+                       
+                       // YUI variables for paging and sorting
+                       $start_index    = phpgw::get_var('startIndex', 'int');
+                       $num_of_objects = phpgw::get_var('results', 'int', 
'GET', $user_rows_per_page);
+                       $sort_field             = phpgw::get_var('sort');
+                       if($sort_field == null)
+                       {
+                               $sort_field = 'control_group_id';
+                       }
+                       $sort_ascending = phpgw::get_var('dir') == 'desc' ? 
false : true;
+                       //Create an empty result set
+                       $records = array();
+                       
+                       //Retrieve a contract identifier and load corresponding 
contract
+                       $control_id = phpgw::get_var('control_id');
+                       if(isset($control_id))
+                       {
+                               $control = $this->so->get_single($control_id);
+                       }
+
+                       $result_objects = $this->so->get($start_index, 
$num_of_objects, $sort_field, $sort_ascending, $search_for, $search_type, 
$filters);
+                       $object_count = $this->so->get_count($search_for, 
$search_type, $filters);
+                       //var_dump($result_objects);
+                                                               
+                       $results = array();
+                       
+                       foreach($result_objects as $control_obj)
+                       {
+                               $results['results'][] = 
$control_obj->serialize();      
+                       }
+                       
+                       $results['total_records'] = $object_count;
+                       $results['start'] = $params['start'];
+                       $results['sort'] = $params['sort'];
+                       $results['dir'] = $params['dir'];
+
+                       array_walk($results["results"], array($this, 
"_add_links"), "controller.uicontrol.view_control_details");
+
+                       return $this->yui_results($results);
+               }
+       }
\ No newline at end of file

Modified: trunk/controller/js/controller/custom_ui.js
===================================================================
--- trunk/controller/js/controller/custom_ui.js 2011-12-15 08:59:28 UTC (rev 
8307)
+++ trunk/controller/js/controller/custom_ui.js 2011-12-15 09:02:09 UTC (rev 
8308)
@@ -1,5 +1,23 @@
 $(document).ready(function() {
 
+       $("#calendar_dates span").click(function(){
+               var thisSpan = $(this);
+               
+               $("#calendar_dates span").css("border", "2px solid black");
+               $(thisSpan).css("border", "2px solid red");
+               
+               var date = $(thisSpan).text();
+               var day = date.substring(0, date.indexOf("/"));
+               var month = date.substring(date.indexOf("/")+1, 
date.indexOf("-"));
+               var year = date.substring(date.indexOf("-")+1, date.length);
+               
+               var valid_save_date = year + "-" + month + "-" + day;  
+               
+               $("#deadline_date").val(valid_save_date);
+               
+               
+       });
+       
        $("ul.control_items ul:first").find("h4 img").attr("src", 
"controller/images/arrow_down.png");
        $("ul.control_items ul:first").find("li ul").slideDown("slow");
        $("ul.control_items ul:first").addClass('active');
@@ -18,6 +36,30 @@
                }
        });
        
+       $("ul.check_items h4.expand_list").click(function(){
+               if( $(this).parent().parent().hasClass('expanded')){
+                       $(this).parent().find("div.check_item").slideUp("slow");
+                       $(this).find("img").attr("src", 
"controller/images/arrow_left.png");
+                       $(this).parent().parent().removeClass('expanded');
+               }else{
+                       
$(this).parent().find("div.check_item").slideDown("slow");
+                       $(this).find("img").attr("src", 
"controller/images/arrow_down.png");
+                       $(this).parent().parent().addClass('expanded');
+               }
+       });
+       
+       $("ul.check_items h4.expand_list").load(function(){
+               if( $(this).parent().parent().hasClass('expanded')){
+                       $(this).parent().find("div.check_item").slideUp("slow");
+                       $(this).find("img").attr("src", 
"controller/images/arrow_left.png");
+                       $(this).parent().parent().removeClass('expanded');
+               }else{
+                       
$(this).parent().find("div.check_item").slideDown("slow");
+                       $(this).find("img").attr("src", 
"controller/images/arrow_down.png");
+                       $(this).parent().parent().addClass('active');
+               }
+       });
+       
        /* 
=============================================================================== 
*/
        
        $(".expand_all").click(function(){

Added: trunk/controller/js/controller/jquery-ui.custom.min.js
===================================================================
--- trunk/controller/js/controller/jquery-ui.custom.min.js                      
        (rev 0)
+++ trunk/controller/js/controller/jquery-ui.custom.min.js      2011-12-15 
09:02:09 UTC (rev 8308)
@@ -0,0 +1,102 @@
+/*!
+ * jQuery UI 1.8.16
+ *
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * http://docs.jquery.com/UI
+ */
+(function(c,j){function k(a,b){var 
d=a.nodeName.toLowerCase();if("area"===d){b=a.parentNode;d=b.name;if(!a.href||!d||b.nodeName.toLowerCase()!=="map")return
 
false;a=c("img[usemap=#"+d+"]")[0];return!!a&&l(a)}return(/input|select|textarea|button|object/.test(d)?!a.disabled:"a"==d?a.href||b:b)&&l(a)}function
 l(a){return!c(a).parents().andSelf().filter(function(){return 
c.curCSS(this,"visibility")==="hidden"||c.expr.filters.hidden(this)}).length}c.ui=c.ui||{};if(!c.ui.version){c.extend(c.ui,{version:"1.8.16",
+keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});c.fn.extend({propAttr:c.fn.prop||c.fn.attr,_focus:c.fn.focus,focus:function(a,b){return
 typeof a==="number"?this.each(function(){var d=
+this;setTimeout(function(){c(d).focus();b&&b.call(d)},a)}):this._focus.apply(this,arguments)},scrollParent:function(){var
 
a;a=c.browser.msie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(c.curCSS(this,"position",1))&&/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(c.curCSS(this,
+"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0);return/fixed/.test(this.css("position"))||!a.length?c(document):a},zIndex:function(a){if(a!==j)return
 this.css("zIndex",a);if(this.length){a=c(this[0]);for(var 
b;a.length&&a[0]!==document;){b=a.css("position");if(b==="absolute"||b==="relative"||b==="fixed"){b=parseInt(a.css("zIndex"),10);if(!isNaN(b)&&b!==0)return
 b}a=a.parent()}}return 0},disableSelection:function(){return 
this.bind((c.support.selectstart?"selectstart":
+"mousedown")+".ui-disableSelection",function(a){a.preventDefault()})},enableSelection:function(){return
 
this.unbind(".ui-disableSelection")}});c.each(["Width","Height"],function(a,b){function
 
d(f,g,m,n){c.each(e,function(){g-=parseFloat(c.curCSS(f,"padding"+this,true))||0;if(m)g-=parseFloat(c.curCSS(f,"border"+this+"Width",true))||0;if(n)g-=parseFloat(c.curCSS(f,"margin"+this,true))||0});return
 g}var 
e=b==="Width"?["Left","Right"]:["Top","Bottom"],h=b.toLowerCase(),i={innerWidth:c.fn.innerWidth,innerHeight:c.fn.innerHeight,
+outerWidth:c.fn.outerWidth,outerHeight:c.fn.outerHeight};c.fn["inner"+b]=function(f){if(f===j)return
 i["inner"+b].call(this);return 
this.each(function(){c(this).css(h,d(this,f)+"px")})};c.fn["outer"+b]=function(f,g){if(typeof
 f!=="number")return i["outer"+b].call(this,f);return 
this.each(function(){c(this).css(h,d(this,f,true,g)+"px")})}});c.extend(c.expr[":"],{data:function(a,b,d){return!!c.data(a,d[3])},focusable:function(a){return
 k(a,!isNaN(c.attr(a,"tabindex")))},tabbable:function(a){var b=c.attr(a,
+"tabindex"),d=isNaN(b);return(d||b>=0)&&k(a,!d)}});c(function(){var 
a=document.body,b=a.appendChild(b=document.createElement("div"));c.extend(b.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});c.support.minHeight=b.offsetHeight===100;c.support.selectstart="onselectstart"in
 
b;a.removeChild(b).style.display="none"});c.extend(c.ui,{plugin:{add:function(a,b,d){a=c.ui[a].prototype;for(var
 e in 
d){a.plugins[e]=a.plugins[e]||[];a.plugins[e].push([b,d[e]])}},call:function(a,b,d){if((b=a.plugins[b])&&
+a.element[0].parentNode)for(var 
e=0;e<b.length;e++)a.options[b[e][0]]&&b[e][1].apply(a.element,d)}},contains:function(a,b){return
 
document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(a,b){if(c(a).css("overflow")==="hidden")return
 false;b=b&&b==="left"?"scrollLeft":"scrollTop";var d=false;if(a[b]>0)return 
true;a[b]=1;d=a[b]>0;a[b]=0;return d},isOverAxis:function(a,b,d){return 
a>b&&a<b+d},isOver:function(a,b,d,e,h,i){return c.ui.isOverAxis(a,d,h)&&
+c.ui.isOverAxis(b,e,i)}})}})(jQuery);
+;/*
+ * jQuery UI Datepicker 1.8.16
+ *
+ * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * http://docs.jquery.com/UI/Datepicker
+ *
+ * Depends:
+ *     jquery.ui.core.js
+ */
+(function(d,C){function 
M(){this.debug=false;this._curInst=null;this._keyEvent=false;this._disabledInputs=[];this._inDialog=this._datepickerShowing=false;this._mainDivId="ui-datepicker-div";this._inlineClass="ui-datepicker-inline";this._appendClass="ui-datepicker-append";this._triggerClass="ui-datepicker-trigger";this._dialogClass="ui-datepicker-dialog";this._disableClass="ui-datepicker-disabled";this._unselectableClass="ui-datepicker-unselectable";this._currentClass="ui-datepicker-current-day";this._dayOverClass=
+"ui-datepicker-days-cell-over";this.regional=[];this.regional[""]={closeText:"Done",prevText:"Prev",nextText:"Next",currentText:"Today",monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su",
+"Mo","Tu","We","Th","Fr","Sa"],weekHeader:"Wk",dateFormat:"mm/dd/yy",firstDay:0,isRTL:false,showMonthAfterYear:false,yearSuffix:""};this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},defaultDate:null,appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:false,hideIfNoPrevNext:false,navigationAsDateFormat:false,gotoCurrent:false,changeMonth:false,changeYear:false,yearRange:"c-10:c+10",showOtherMonths:false,selectOtherMonths:false,showWeek:false,calculateWeek:this.iso8601Week,shortYearCutoff:"+10",
+minDate:null,maxDate:null,duration:"fast",beforeShowDay:null,beforeShow:null,onSelect:null,onChangeMonthYear:null,onClose:null,numberOfMonths:1,showCurrentAtPos:0,stepMonths:1,stepBigMonths:12,altField:"",altFormat:"",constrainInput:true,showButtonPanel:false,autoSize:false,disabled:false};d.extend(this._defaults,this.regional[""]);this.dpDiv=N(d('<div
 id="'+this._mainDivId+'" class="ui-datepicker ui-widget ui-widget-content 
ui-helper-clearfix ui-corner-all"></div>'))}function N(a){return 
a.bind("mouseout",
+function(b){b=d(b.target).closest("button, .ui-datepicker-prev, 
.ui-datepicker-next, .ui-datepicker-calendar td 
a");b.length&&b.removeClass("ui-state-hover ui-datepicker-prev-hover 
ui-datepicker-next-hover")}).bind("mouseover",function(b){b=d(b.target).closest("button,
 .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td 
a");if(!(d.datepicker._isDisabledDatepicker(J.inline?a.parent()[0]:J.input[0])||!b.length)){b.parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");
+b.addClass("ui-state-hover");b.hasClass("ui-datepicker-prev")&&b.addClass("ui-datepicker-prev-hover");b.hasClass("ui-datepicker-next")&&b.addClass("ui-datepicker-next-hover")}})}function
 H(a,b){d.extend(a,b);for(var c in b)if(b[c]==null||b[c]==C)a[c]=b[c];return 
a}d.extend(d.ui,{datepicker:{version:"1.8.16"}});var B=(new 
Date).getTime(),J;d.extend(M.prototype,{markerClassName:"hasDatepicker",maxRows:4,log:function(){this.debug&&console.log.apply("",arguments)},_widgetDatepicker:function(){return
 this.dpDiv},
+setDefaults:function(a){H(this._defaults,a||{});return 
this},_attachDatepicker:function(a,b){var c=null;for(var e in 
this._defaults){var 
f=a.getAttribute("date:"+e);if(f){c=c||{};try{c[e]=eval(f)}catch(h){c[e]=f}}}e=a.nodeName.toLowerCase();f=e=="div"||e=="span";if(!a.id){this.uuid+=1;a.id="dp"+this.uuid}var
 
i=this._newInst(d(a),f);i.settings=d.extend({},b||{},c||{});if(e=="input")this._connectDatepicker(a,i);else
 
f&&this._inlineDatepicker(a,i)},_newInst:function(a,b){return{id:a[0].id.replace(/([^A-Za-z0-9_-])/g,
+"\\\\$1"),input:a,selectedDay:0,selectedMonth:0,selectedYear:0,drawMonth:0,drawYear:0,inline:b,dpDiv:!b?this.dpDiv:N(d('<div
 class="'+this._inlineClass+' ui-datepicker ui-widget ui-widget-content 
ui-helper-clearfix 
ui-corner-all"></div>'))}},_connectDatepicker:function(a,b){var 
c=d(a);b.append=d([]);b.trigger=d([]);if(!c.hasClass(this.markerClassName)){this._attachments(c,b);c.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).keyup(this._doKeyUp).bind("setData.datepicker",
+function(e,f,h){b.settings[f]=h}).bind("getData.datepicker",function(e,f){return
 
this._get(b,f)});this._autoSize(b);d.data(a,"datepicker",b);b.settings.disabled&&this._disableDatepicker(a)}},_attachments:function(a,b){var
 
c=this._get(b,"appendText"),e=this._get(b,"isRTL");b.append&&b.append.remove();if(c){b.append=d('<span
 
class="'+this._appendClass+'">'+c+"</span>");a[e?"before":"after"](b.append)}a.unbind("focus",this._showDatepicker);b.trigger&&b.trigger.remove();c=this._get(b,"showOn");if(c==
+"focus"||c=="both")a.focus(this._showDatepicker);if(c=="button"||c=="both"){c=this._get(b,"buttonText");var
 
f=this._get(b,"buttonImage");b.trigger=d(this._get(b,"buttonImageOnly")?d("<img/>").addClass(this._triggerClass).attr({src:f,alt:c,title:c}):d('<button
 
type="button"></button>').addClass(this._triggerClass).html(f==""?c:d("<img/>").attr({src:f,alt:c,title:c})));a[e?"before":"after"](b.trigger);b.trigger.click(function(){d.datepicker._datepickerShowing&&d.datepicker._lastInput==a[0]?d.datepicker._hideDatepicker():
+d.datepicker._showDatepicker(a[0]);return 
false})}},_autoSize:function(a){if(this._get(a,"autoSize")&&!a.inline){var 
b=new Date(2009,11,20),c=this._get(a,"dateFormat");if(c.match(/[DM]/)){var 
e=function(f){for(var 
h=0,i=0,g=0;g<f.length;g++)if(f[g].length>h){h=f[g].length;i=g}return 
i};b.setMonth(e(this._get(a,c.match(/MM/)?"monthNames":"monthNamesShort")));b.setDate(e(this._get(a,c.match(/DD/)?"dayNames":"dayNamesShort"))+20-b.getDay())}a.input.attr("size",this._formatDate(a,b).length)}},_inlineDatepicker:function(a,
+b){var 
c=d(a);if(!c.hasClass(this.markerClassName)){c.addClass(this.markerClassName).append(b.dpDiv).bind("setData.datepicker",function(e,f,h){b.settings[f]=h}).bind("getData.datepicker",function(e,f){return
 
this._get(b,f)});d.data(a,"datepicker",b);this._setDate(b,this._getDefaultDate(b),true);this._updateDatepicker(b);this._updateAlternate(b);b.settings.disabled&&this._disableDatepicker(a);b.dpDiv.css("display","block")}},_dialogDatepicker:function(a,b,c,e,f){a=this._dialogInst;if(!a){this.uuid+=
+1;this._dialogInput=d('<input type="text" id="'+("dp"+this.uuid)+'" 
style="position: absolute; top: -100px; width: 0px; z-index: 
-10;"/>');this._dialogInput.keydown(this._doKeyDown);d("body").append(this._dialogInput);a=this._dialogInst=this._newInst(this._dialogInput,false);a.settings={};d.data(this._dialogInput[0],"datepicker",a)}H(a.settings,e||{});b=b&&b.constructor==Date?this._formatDate(a,b):b;this._dialogInput.val(b);this._pos=f?f.length?f:[f.pageX,f.pageY]:null;if(!this._pos)this._pos=[document.documentElement.clientWidth/
+2-100+(document.documentElement.scrollLeft||document.body.scrollLeft),document.documentElement.clientHeight/2-150+(document.documentElement.scrollTop||document.body.scrollTop)];this._dialogInput.css("left",this._pos[0]+20+"px").css("top",this._pos[1]+"px");a.settings.onSelect=c;this._inDialog=true;this.dpDiv.addClass(this._dialogClass);this._showDatepicker(this._dialogInput[0]);d.blockUI&&d.blockUI(this.dpDiv);d.data(this._dialogInput[0],"datepicker",a);return
 this},_destroyDatepicker:function(a){var b=
+d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var 
e=a.nodeName.toLowerCase();d.removeData(a,"datepicker");if(e=="input"){c.append.remove();c.trigger.remove();b.removeClass(this.markerClassName).unbind("focus",this._showDatepicker).unbind("keydown",this._doKeyDown).unbind("keypress",this._doKeyPress).unbind("keyup",this._doKeyUp)}else
 
if(e=="div"||e=="span")b.removeClass(this.markerClassName).empty()}},_enableDatepicker:function(a){var
 b=d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=
+a.nodeName.toLowerCase();if(e=="input"){a.disabled=false;c.trigger.filter("button").each(function(){this.disabled=false}).end().filter("img").css({opacity:"1.0",cursor:""})}else
 
if(e=="div"||e=="span"){b=b.children("."+this._inlineClass);b.children().removeClass("ui-state-disabled");b.find("select.ui-datepicker-month,
 
select.ui-datepicker-year").removeAttr("disabled")}this._disabledInputs=d.map(this._disabledInputs,function(f){return
 f==a?null:f})}},_disableDatepicker:function(a){var b=d(a),c=d.data(a,
+"datepicker");if(b.hasClass(this.markerClassName)){var 
e=a.nodeName.toLowerCase();if(e=="input"){a.disabled=true;c.trigger.filter("button").each(function(){this.disabled=true}).end().filter("img").css({opacity:"0.5",cursor:"default"})}else
 
if(e=="div"||e=="span"){b=b.children("."+this._inlineClass);b.children().addClass("ui-state-disabled");b.find("select.ui-datepicker-month,
 
select.ui-datepicker-year").attr("disabled","disabled")}this._disabledInputs=d.map(this._disabledInputs,function(f){return
 f==
+a?null:f});this._disabledInputs[this._disabledInputs.length]=a}},_isDisabledDatepicker:function(a){if(!a)return
 false;for(var 
b=0;b<this._disabledInputs.length;b++)if(this._disabledInputs[b]==a)return 
true;return false},_getInst:function(a){try{return 
d.data(a,"datepicker")}catch(b){throw"Missing instance data for this 
datepicker";}},_optionDatepicker:function(a,b,c){var 
e=this._getInst(a);if(arguments.length==2&&typeof b=="string")return 
b=="defaults"?d.extend({},d.datepicker._defaults):e?b=="all"?
+d.extend({},e.settings):this._get(e,b):null;var f=b||{};if(typeof 
b=="string"){f={};f[b]=c}if(e){this._curInst==e&&this._hideDatepicker();var 
h=this._getDateDatepicker(a,true),i=this._getMinMaxDate(e,"min"),g=this._getMinMaxDate(e,"max");H(e.settings,f);if(i!==null&&f.dateFormat!==C&&f.minDate===C)e.settings.minDate=this._formatDate(e,i);if(g!==null&&f.dateFormat!==C&&f.maxDate===C)e.settings.maxDate=this._formatDate(e,g);this._attachments(d(a),e);this._autoSize(e);this._setDate(e,h);this._updateAlternate(e);
+this._updateDatepicker(e)}},_changeDatepicker:function(a,b,c){this._optionDatepicker(a,b,c)},_refreshDatepicker:function(a){(a=this._getInst(a))&&this._updateDatepicker(a)},_setDateDatepicker:function(a,b){if(a=this._getInst(a)){this._setDate(a,b);this._updateDatepicker(a);this._updateAlternate(a)}},_getDateDatepicker:function(a,b){(a=this._getInst(a))&&!a.inline&&this._setDateFromField(a,b);return
 a?this._getDate(a):null},_doKeyDown:function(a){var 
b=d.datepicker._getInst(a.target),c=true,e=b.dpDiv.is(".ui-datepicker-rtl");
+b._keyEvent=true;if(d.datepicker._datepickerShowing)switch(a.keyCode){case 
9:d.datepicker._hideDatepicker();c=false;break;case 
13:c=d("td."+d.datepicker._dayOverClass+":not(."+d.datepicker._currentClass+")",b.dpDiv);c[0]&&d.datepicker._selectDay(a.target,b.selectedMonth,b.selectedYear,c[0]);if(a=d.datepicker._get(b,"onSelect")){c=d.datepicker._formatDate(b);a.apply(b.input?b.input[0]:null,[c,b])}else
 d.datepicker._hideDatepicker();return false;case 
27:d.datepicker._hideDatepicker();break;case 
33:d.datepicker._adjustDate(a.target,
+a.ctrlKey?-d.datepicker._get(b,"stepBigMonths"):-d.datepicker._get(b,"stepMonths"),"M");break;case
 
34:d.datepicker._adjustDate(a.target,a.ctrlKey?+d.datepicker._get(b,"stepBigMonths"):+d.datepicker._get(b,"stepMonths"),"M");break;case
 
35:if(a.ctrlKey||a.metaKey)d.datepicker._clearDate(a.target);c=a.ctrlKey||a.metaKey;break;case
 
36:if(a.ctrlKey||a.metaKey)d.datepicker._gotoToday(a.target);c=a.ctrlKey||a.metaKey;break;case
 37:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,e?+1:-1,"D");c=
+a.ctrlKey||a.metaKey;if(a.originalEvent.altKey)d.datepicker._adjustDate(a.target,a.ctrlKey?-d.datepicker._get(b,"stepBigMonths"):-d.datepicker._get(b,"stepMonths"),"M");break;case
 
38:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,-7,"D");c=a.ctrlKey||a.metaKey;break;case
 
39:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,e?-1:+1,"D");c=a.ctrlKey||a.metaKey;if(a.originalEvent.altKey)d.datepicker._adjustDate(a.target,a.ctrlKey?+d.datepicker._get(b,"stepBigMonths"):+d.datepicker._get(b,
+"stepMonths"),"M");break;case 
40:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,+7,"D");c=a.ctrlKey||a.metaKey;break;default:c=false}else
 if(a.keyCode==36&&a.ctrlKey)d.datepicker._showDatepicker(this);else 
c=false;if(c){a.preventDefault();a.stopPropagation()}},_doKeyPress:function(a){var
 
b=d.datepicker._getInst(a.target);if(d.datepicker._get(b,"constrainInput")){b=d.datepicker._possibleChars(d.datepicker._get(b,"dateFormat"));var
 c=String.fromCharCode(a.charCode==C?a.keyCode:a.charCode);
+return a.ctrlKey||a.metaKey||c<" 
"||!b||b.indexOf(c)>-1}},_doKeyUp:function(a){a=d.datepicker._getInst(a.target);if(a.input.val()!=a.lastVal)try{if(d.datepicker.parseDate(d.datepicker._get(a,"dateFormat"),a.input?a.input.val():null,d.datepicker._getFormatConfig(a))){d.datepicker._setDateFromField(a);d.datepicker._updateAlternate(a);d.datepicker._updateDatepicker(a)}}catch(b){d.datepicker.log(b)}return
 
true},_showDatepicker:function(a){a=a.target||a;if(a.nodeName.toLowerCase()!="input")a=d("input",
+a.parentNode)[0];if(!(d.datepicker._isDisabledDatepicker(a)||d.datepicker._lastInput==a)){var
 
b=d.datepicker._getInst(a);if(d.datepicker._curInst&&d.datepicker._curInst!=b){d.datepicker._datepickerShowing&&d.datepicker._triggerOnClose(d.datepicker._curInst);d.datepicker._curInst.dpDiv.stop(true,true)}var
 
c=d.datepicker._get(b,"beforeShow");c=c?c.apply(a,[a,b]):{};if(c!==false){H(b.settings,c);b.lastVal=null;d.datepicker._lastInput=a;d.datepicker._setDateFromField(b);if(d.datepicker._inDialog)a.value=
+"";if(!d.datepicker._pos){d.datepicker._pos=d.datepicker._findPos(a);d.datepicker._pos[1]+=a.offsetHeight}var
 
e=false;d(a).parents().each(function(){e|=d(this).css("position")=="fixed";return!e});if(e&&d.browser.opera){d.datepicker._pos[0]-=document.documentElement.scrollLeft;d.datepicker._pos[1]-=document.documentElement.scrollTop}c={left:d.datepicker._pos[0],top:d.datepicker._pos[1]};d.datepicker._pos=null;b.dpDiv.empty();b.dpDiv.css({position:"absolute",display:"block",top:"-1000px"});d.datepicker._updateDatepicker(b);
+c=d.datepicker._checkOffset(b,c,e);b.dpDiv.css({position:d.datepicker._inDialog&&d.blockUI?"static":e?"fixed":"absolute",display:"none",left:c.left+"px",top:c.top+"px"});if(!b.inline){c=d.datepicker._get(b,"showAnim");var
 f=d.datepicker._get(b,"duration"),h=function(){var 
i=b.dpDiv.find("iframe.ui-datepicker-cover");if(i.length){var 
g=d.datepicker._getBorders(b.dpDiv);i.css({left:-g[0],top:-g[1],width:b.dpDiv.outerWidth(),height:b.dpDiv.outerHeight()})}};b.dpDiv.zIndex(d(a).zIndex()+1);d.datepicker._datepickerShowing=
+true;d.effects&&d.effects[c]?b.dpDiv.show(c,d.datepicker._get(b,"showOptions"),f,h):b.dpDiv[c||"show"](c?f:null,h);if(!c||!f)h();b.input.is(":visible")&&!b.input.is(":disabled")&&b.input.focus();d.datepicker._curInst=b}}}},_updateDatepicker:function(a){this.maxRows=4;var
 
b=d.datepicker._getBorders(a.dpDiv);J=a;a.dpDiv.empty().append(this._generateHTML(a));var
 
c=a.dpDiv.find("iframe.ui-datepicker-cover");c.length&&c.css({left:-b[0],top:-b[1],width:a.dpDiv.outerWidth(),height:a.dpDiv.outerHeight()});
+a.dpDiv.find("."+this._dayOverClass+" 
a").mouseover();b=this._getNumberOfMonths(a);c=b[1];a.dpDiv.removeClass("ui-datepicker-multi-2
 ui-datepicker-multi-3 
ui-datepicker-multi-4").width("");c>1&&a.dpDiv.addClass("ui-datepicker-multi-"+c).css("width",17*c+"em");a.dpDiv[(b[0]!=1||b[1]!=1?"add":"remove")+"Class"]("ui-datepicker-multi");a.dpDiv[(this._get(a,"isRTL")?"add":"remove")+"Class"]("ui-datepicker-rtl");a==d.datepicker._curInst&&d.datepicker._datepickerShowing&&a.input&&a.input.is(":visible")&&
+!a.input.is(":disabled")&&a.input[0]!=document.activeElement&&a.input.focus();if(a.yearshtml){var
 
e=a.yearshtml;setTimeout(function(){e===a.yearshtml&&a.yearshtml&&a.dpDiv.find("select.ui-datepicker-year:first").replaceWith(a.yearshtml);e=a.yearshtml=null},0)}},_getBorders:function(a){var
 
b=function(c){return{thin:1,medium:2,thick:3}[c]||c};return[parseFloat(b(a.css("border-left-width"))),parseFloat(b(a.css("border-top-width")))]},_checkOffset:function(a,b,c){var
 e=a.dpDiv.outerWidth(),f=a.dpDiv.outerHeight(),
+h=a.input?a.input.outerWidth():0,i=a.input?a.input.outerHeight():0,g=document.documentElement.clientWidth+d(document).scrollLeft(),j=document.documentElement.clientHeight+d(document).scrollTop();b.left-=this._get(a,"isRTL")?e-h:0;b.left-=c&&b.left==a.input.offset().left?d(document).scrollLeft():0;b.top-=c&&b.top==a.input.offset().top+i?d(document).scrollTop():0;b.left-=Math.min(b.left,b.left+e>g&&g>e?Math.abs(b.left+e-g):0);b.top-=Math.min(b.top,b.top+f>j&&j>f?Math.abs(f+i):0);return
 b},_findPos:function(a){for(var b=
+this._get(this._getInst(a),"isRTL");a&&(a.type=="hidden"||a.nodeType!=1||d.expr.filters.hidden(a));)a=a[b?"previousSibling":"nextSibling"];a=d(a).offset();return[a.left,a.top]},_triggerOnClose:function(a){var
 
b=this._get(a,"onClose");if(b)b.apply(a.input?a.input[0]:null,[a.input?a.input.val():"",a])},_hideDatepicker:function(a){var
 
b=this._curInst;if(!(!b||a&&b!=d.data(a,"datepicker")))if(this._datepickerShowing){a=this._get(b,"showAnim");var
 c=this._get(b,"duration"),e=function(){d.datepicker._tidyDialog(b);
+this._curInst=null};d.effects&&d.effects[a]?b.dpDiv.hide(a,d.datepicker._get(b,"showOptions"),c,e):b.dpDiv[a=="slideDown"?"slideUp":a=="fadeIn"?"fadeOut":"hide"](a?c:null,e);a||e();d.datepicker._triggerOnClose(b);this._datepickerShowing=false;this._lastInput=null;if(this._inDialog){this._dialogInput.css({position:"absolute",left:"0",top:"-100px"});if(d.blockUI){d.unblockUI();d("body").append(this.dpDiv)}}this._inDialog=false}},_tidyDialog:function(a){a.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar")},
+_checkExternalClick:function(a){if(d.datepicker._curInst){a=d(a.target);a[0].id!=d.datepicker._mainDivId&&a.parents("#"+d.datepicker._mainDivId).length==0&&!a.hasClass(d.datepicker.markerClassName)&&!a.hasClass(d.datepicker._triggerClass)&&d.datepicker._datepickerShowing&&!(d.datepicker._inDialog&&d.blockUI)&&d.datepicker._hideDatepicker()}},_adjustDate:function(a,b,c){a=d(a);var
 
e=this._getInst(a[0]);if(!this._isDisabledDatepicker(a[0])){this._adjustInstDate(e,b+(c=="M"?this._get(e,"showCurrentAtPos"):
+0),c);this._updateDatepicker(e)}},_gotoToday:function(a){a=d(a);var 
b=this._getInst(a[0]);if(this._get(b,"gotoCurrent")&&b.currentDay){b.selectedDay=b.currentDay;b.drawMonth=b.selectedMonth=b.currentMonth;b.drawYear=b.selectedYear=b.currentYear}else{var
 c=new 
Date;b.selectedDay=c.getDate();b.drawMonth=b.selectedMonth=c.getMonth();b.drawYear=b.selectedYear=c.getFullYear()}this._notifyChange(b);this._adjustDate(a)},_selectMonthYear:function(a,b,c){a=d(a);var
 e=this._getInst(a[0]);e["selected"+(c=="M"?
+"Month":"Year")]=e["draw"+(c=="M"?"Month":"Year")]=parseInt(b.options[b.selectedIndex].value,10);this._notifyChange(e);this._adjustDate(a)},_selectDay:function(a,b,c,e){var
 
f=d(a);if(!(d(e).hasClass(this._unselectableClass)||this._isDisabledDatepicker(f[0]))){f=this._getInst(f[0]);f.selectedDay=f.currentDay=d("a",e).html();f.selectedMonth=f.currentMonth=b;f.selectedYear=f.currentYear=c;this._selectDate(a,this._formatDate(f,f.currentDay,f.currentMonth,f.currentYear))}},_clearDate:function(a){a=d(a);
+this._getInst(a[0]);this._selectDate(a,"")},_selectDate:function(a,b){a=this._getInst(d(a)[0]);b=b!=null?b:this._formatDate(a);a.input&&a.input.val(b);this._updateAlternate(a);var
 c=this._get(a,"onSelect");if(c)c.apply(a.input?a.input[0]:null,[b,a]);else 
a.input&&a.input.trigger("change");if(a.inline)this._updateDatepicker(a);else{this._hideDatepicker();this._lastInput=a.input[0];typeof
 
a.input[0]!="object"&&a.input.focus();this._lastInput=null}},_updateAlternate:function(a){var
 b=this._get(a,"altField");
+if(b){var 
c=this._get(a,"altFormat")||this._get(a,"dateFormat"),e=this._getDate(a),f=this.formatDate(c,e,this._getFormatConfig(a));d(b).each(function(){d(this).val(f)})}},noWeekends:function(a){a=a.getDay();return[a>0&&a<6,""]},iso8601Week:function(a){a=new
 Date(a.getTime());a.setDate(a.getDate()+4-(a.getDay()||7));var 
b=a.getTime();a.setMonth(0);a.setDate(1);return 
Math.floor(Math.round((b-a)/864E5)/7)+1},parseDate:function(a,b,c){if(a==null||b==null)throw"Invalid
 arguments";b=typeof b=="object"?
+b.toString():b+"";if(b=="")return null;var 
e=(c?c.shortYearCutoff:null)||this._defaults.shortYearCutoff;e=typeof 
e!="string"?e:(new Date).getFullYear()%100+parseInt(e,10);for(var 
f=(c?c.dayNamesShort:null)||this._defaults.dayNamesShort,h=(c?c.dayNames:null)||this._defaults.dayNames,i=(c?c.monthNamesShort:null)||this._defaults.monthNamesShort,g=(c?c.monthNames:null)||this._defaults.monthNames,j=c=-1,l=-1,u=-1,k=false,o=function(p){(p=A+1<a.length&&a.charAt(A+1)==p)&&A++;return
 p},m=function(p){var D=
+o(p);p=new 
RegExp("^\\d{1,"+(p=="@"?14:p=="!"?20:p=="y"&&D?4:p=="o"?3:2)+"}");p=b.substring(q).match(p);if(!p)throw"Missing
 number at position "+q;q+=p[0].length;return 
parseInt(p[0],10)},n=function(p,D,K){p=d.map(o(p)?K:D,function(w,x){return[[x,w]]}).sort(function(w,x){return-(w[1].length-x[1].length)});var
 
E=-1;d.each(p,function(w,x){w=x[1];if(b.substr(q,w.length).toLowerCase()==w.toLowerCase()){E=x[0];q+=w.length;return
 false}});if(E!=-1)return E+1;else throw"Unknown name at position "+q;},s=

@@ Diff output truncated at 153600 characters. @@



reply via email to

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