fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [9609] Merged trunk into branch


From: Alexander Stevenson
Subject: [Fmsystem-commits] [9609] Merged trunk into branch
Date: Mon, 18 Jun 2012 12:44:17 +0000

Revision: 9609
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9609
Author:   andvare
Date:     2012-06-18 12:44:16 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
Merged trunk into branch

Modified Paths:
--------------
    branches/stavangerkommune/activitycalendar/inc/class.soactivity.inc.php
    branches/stavangerkommune/activitycalendar/inc/class.soarena.inc.php
    branches/stavangerkommune/activitycalendar/inc/class.sogroup.inc.php
    branches/stavangerkommune/activitycalendar/inc/class.soorganization.inc.php
    branches/stavangerkommune/activitycalendar/inc/class.uiorganization.inc.php
    branches/stavangerkommune/activitycalendar/templates/base/activity.php
    branches/stavangerkommune/activitycalendar/templates/base/arena.php
    branches/stavangerkommune/activitycalendar/templates/base/group.php
    branches/stavangerkommune/activitycalendar/templates/base/organization.php
    
branches/stavangerkommune/activitycalendarfrontend/inc/class.uiactivity.inc.php
    
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity.php
    
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_edit.php
    
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new.php
    
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new_org.php
    
branches/stavangerkommune/activitycalendarfrontend/templates/base/organization_edit.php
    branches/stavangerkommune/controller/inc/class.menu.inc.php
    branches/stavangerkommune/controller/inc/class.socheck_list.inc.php
    branches/stavangerkommune/controller/inc/class.socontrol.inc.php
    branches/stavangerkommune/controller/inc/class.uicalendar.inc.php
    branches/stavangerkommune/controller/inc/class.uicheck_list.inc.php
    branches/stavangerkommune/controller/inc/class.uicommon.inc.php
    branches/stavangerkommune/controller/inc/class.uicontrol.inc.php
    branches/stavangerkommune/controller/inc/class.uicontrol_group.inc.php
    branches/stavangerkommune/controller/inc/class.uicontrol_item.inc.php
    branches/stavangerkommune/controller/inc/class.uicontrol_location.inc.php
    branches/stavangerkommune/controller/inc/class.uiprocedure.inc.php
    
branches/stavangerkommune/controller/inc/component/class.year_calendar.inc.php
    branches/stavangerkommune/controller/inc/hook_home.inc.php
    branches/stavangerkommune/controller/inc/model/class.control.inc.php
    branches/stavangerkommune/controller/js/controller/ajax.js
    branches/stavangerkommune/controller/js/controller/custom_ui.js
    branches/stavangerkommune/controller/js/controller/jquery.js
    branches/stavangerkommune/controller/setup/phpgw_no.lang
    branches/stavangerkommune/controller/setup/setup.inc.php
    branches/stavangerkommune/controller/setup/tables_current.inc.php
    branches/stavangerkommune/controller/setup/tables_update.inc.php
    
branches/stavangerkommune/controller/templates/base/add_component_to_control.xsl
    
branches/stavangerkommune/controller/templates/base/add_component_to_control_group.xsl
    
branches/stavangerkommune/controller/templates/base/calendar/check_list_status_checker.xsl
    
branches/stavangerkommune/controller/templates/base/calendar/select_my_locations.xsl
    
branches/stavangerkommune/controller/templates/base/calendar/view_calendar_month.xsl
    
branches/stavangerkommune/controller/templates/base/calendar/view_calendar_month_for_locations.xsl
    
branches/stavangerkommune/controller/templates/base/calendar/view_calendar_year.xsl
    
branches/stavangerkommune/controller/templates/base/calendar/view_calendar_year_for_locations.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/print_check_list.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/view_cases_for_check_list.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/view_check_lists.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/view_control_details.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/view_control_info.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/view_control_items.xsl
    
branches/stavangerkommune/controller/templates/base/check_list/view_open_cases.xsl
    branches/stavangerkommune/controller/templates/base/component.xsl
    branches/stavangerkommune/controller/templates/base/control/control.xsl
    branches/stavangerkommune/controller/templates/base/control/control_tabs.xsl
    
branches/stavangerkommune/controller/templates/base/control_group/control_group.xsl
    
branches/stavangerkommune/controller/templates/base/control_group/control_group_items.xsl
    
branches/stavangerkommune/controller/templates/base/control_group/control_group_tabs.xsl
    
branches/stavangerkommune/controller/templates/base/control_item/choose_control_items.xsl
    
branches/stavangerkommune/controller/templates/base/control_item/control_item.xsl
    
branches/stavangerkommune/controller/templates/base/control_item/view_control_item_list.xsl
    
branches/stavangerkommune/controller/templates/base/control_location/control_location_tabs.xsl
    
branches/stavangerkommune/controller/templates/base/control_location/register_control_to_location.xsl
    
branches/stavangerkommune/controller/templates/base/control_location/view_locations_for_control.xsl
    branches/stavangerkommune/controller/templates/base/css/base.css
    branches/stavangerkommune/controller/templates/base/datatable.xsl
    
branches/stavangerkommune/controller/templates/base/procedure/print_procedure.xsl
    
branches/stavangerkommune/controller/templates/base/procedure/procedure_documents.xsl
    
branches/stavangerkommune/controller/templates/base/procedure/procedure_item.xsl
    
branches/stavangerkommune/controller/templates/base/procedure/view_procedures_for_control.xsl
    
branches/stavangerkommune/controller/templates/base/view_component_for_control.xsl
    
branches/stavangerkommune/controller/templates/base/view_component_for_control_group.xsl
    branches/stavangerkommune/frontend/inc/class.bofellesdata.inc.php
    branches/stavangerkommune/frontend/inc/class.uifrontend.inc.php
    branches/stavangerkommune/frontend/setup/default_records.inc.php
    branches/stavangerkommune/frontend/setup/phpgw_no.lang
    branches/stavangerkommune/frontend/setup/setup.inc.php
    branches/stavangerkommune/frontend/setup/tables_update.inc.php
    branches/stavangerkommune/frontend/templates/base/frontend.xsl
    branches/stavangerkommune/phpgwapi/inc/class.custom_fields.inc.php
    branches/stavangerkommune/phpgwapi/inc/class.jqcal.inc.php
    branches/stavangerkommune/phpgwapi/inc/class.jquery.inc.php
    branches/stavangerkommune/phpgwapi/inc/class.yui.inc.php
    branches/stavangerkommune/phpgwapi/setup/setup.inc.php
    branches/stavangerkommune/phpgwapi/setup/tables_current.inc.php
    branches/stavangerkommune/phpgwapi/setup/tables_update.inc.php
    branches/stavangerkommune/property/inc/class.bocommon.inc.php
    branches/stavangerkommune/property/inc/class.boentity.inc.php
    branches/stavangerkommune/property/inc/class.boinvoice.inc.php
    branches/stavangerkommune/property/inc/class.bolocation.inc.php
    branches/stavangerkommune/property/inc/class.botts.inc.php
    branches/stavangerkommune/property/inc/class.menu.inc.php
    branches/stavangerkommune/property/inc/class.soXport.inc.php
    branches/stavangerkommune/property/inc/class.soadmin_entity.inc.php
    branches/stavangerkommune/property/inc/class.socommon.inc.php
    branches/stavangerkommune/property/inc/class.soentity.inc.php
    branches/stavangerkommune/property/inc/class.soinvoice.inc.php
    branches/stavangerkommune/property/inc/class.solocation.inc.php
    branches/stavangerkommune/property/inc/class.soproject.inc.php
    branches/stavangerkommune/property/inc/class.soworkorder.inc.php
    branches/stavangerkommune/property/inc/class.uiadmin_entity.inc.php
    branches/stavangerkommune/property/inc/class.uiinvoice.inc.php
    branches/stavangerkommune/property/inc/class.uiinvoice2.inc.php
    branches/stavangerkommune/property/inc/class.uiproject.inc.php
    branches/stavangerkommune/property/inc/class.uitts.inc.php
    branches/stavangerkommune/property/inc/class.uiworkorder.inc.php
    
branches/stavangerkommune/property/inc/cron/default/Import_fra_basware_X205.php
    branches/stavangerkommune/property/inc/export/default/Basware_X114
    
branches/stavangerkommune/property/inc/import/default/cvs_import_kunstoversikt_bkb
    branches/stavangerkommune/property/js/portico/ajax_invoice.js
    branches/stavangerkommune/property/setup/phpgw_no.lang
    branches/stavangerkommune/property/setup/setup.inc.php
    branches/stavangerkommune/property/setup/tables_current.inc.php
    branches/stavangerkommune/property/setup/tables_update.inc.php
    branches/stavangerkommune/property/templates/base/admin_entity.xsl
    branches/stavangerkommune/property/templates/base/invoice2.xsl
    branches/stavangerkommune/property/templates/base/project.xsl

Added Paths:
-----------
    branches/stavangerkommune/controller/inc/model/class.component.inc.php
    
branches/stavangerkommune/controller/js/controller/ajax_control_to_component.js
    
branches/stavangerkommune/controller/js/yahoo/register_control_to_component2.js
    
branches/stavangerkommune/controller/js/yahoo/register_control_to_location.js
    
branches/stavangerkommune/controller/templates/base/calendar/select_buildings_on_property.xsl
    
branches/stavangerkommune/controller/templates/base/control/controls_datatable.xsl
    
branches/stavangerkommune/controller/templates/base/control_group/control_groups_datatable.xsl
    
branches/stavangerkommune/controller/templates/base/control_item/control_items_datatable.xsl
    
branches/stavangerkommune/controller/templates/base/control_location/register_control_to_component.xsl
    
branches/stavangerkommune/controller/templates/base/procedure/procedures_datatable.xsl
    branches/stavangerkommune/frontend/inc/class.uicontract_documents.inc.php
    branches/stavangerkommune/frontend/templates/base/document.xsl

Property Changed:
----------------
    branches/stavangerkommune/
    
branches/stavangerkommune/property/inc/cron/default/Import_fra_basware_X205.php


Property changes on: branches/stavangerkommune
___________________________________________________________________
Added: svn:mergeinfo
   + /trunk:9468-9608

Modified: 
branches/stavangerkommune/activitycalendar/inc/class.soactivity.inc.php
===================================================================
--- branches/stavangerkommune/activitycalendar/inc/class.soactivity.inc.php     
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/inc/class.soactivity.inc.php     
2012-06-18 12:44:16 UTC (rev 9609)
@@ -1362,7 +1362,7 @@
                        
$activity->set_title($this->unmarshal($this->db->f('title'), 'string'));
                        
$activity->set_organization_id($this->unmarshal($this->db->f('organization_id'),
 'int'));
                        
$activity->set_group_id($this->unmarshal($this->db->f('group_id'), 'int'));
-                       
$activity->set_district($this->unmarshal($this->db->f('district'), 'int'));
+                       
$activity->set_district($this->unmarshal($this->db->f('district'), 'string'));
                        
$activity->set_office($this->unmarshal($this->db->f('office'), 'int'));
                        
$activity->set_category($this->unmarshal($this->db->f('category'), 'int'));
                        
$activity->set_state($this->unmarshal($this->db->f('state'), 'int'));

Modified: branches/stavangerkommune/activitycalendar/inc/class.soarena.inc.php
===================================================================
--- branches/stavangerkommune/activitycalendar/inc/class.soarena.inc.php        
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/inc/class.soarena.inc.php        
2012-06-18 12:44:16 UTC (rev 9609)
@@ -289,13 +289,18 @@
        public function get_address($search)
        {
                $result_arr = array();
+           $curr_index=0;
                if($search)
                {
                        $sql = "select * from fm_streetaddress where 
UPPER(descr) like UPPER('{$search}%')";
                        $this->db->query($sql, __LINE__, __FILE__);
                        while($this->db->next_record()){
                                //$result_arr = $this->db->f('name');
+                               //if($curr_index == 0){
+                                   //$result_arr[] = "<option value='0'>Velg 
gateadresse</option>";
+                               //}
                                $result_arr[] = "<option value='" . 
$this->db->f('descr') . "'>" . $this->db->f('descr') . "</option>";
+                               //$curr_index++;
                        }
                }
                $result = implode(' ' , $result_arr);

Modified: branches/stavangerkommune/activitycalendar/inc/class.sogroup.inc.php
===================================================================
--- branches/stavangerkommune/activitycalendar/inc/class.sogroup.inc.php        
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/inc/class.sogroup.inc.php        
2012-06-18 12:44:16 UTC (rev 9609)
@@ -87,7 +87,7 @@
                if(isset($filters['new_groups'])){
                        $use_local_group = true;
                        unset($filter_clauses);
-                       $filter_clauses[] = "activity_group.change_type = 
'new'";
+                       $filter_clauses[] = "activity_group.change_type = 'new' 
OR activity_group.change_type = 'change' ";
                        if(isset($filters[$this->get_id_field_name()])){
                                $id = 
$this->marshal($filters[$this->get_id_field_name()],'int');
                                $filter_clauses[] = "activity_group.id = {$id}";

Modified: 
branches/stavangerkommune/activitycalendar/inc/class.soorganization.inc.php
===================================================================
--- branches/stavangerkommune/activitycalendar/inc/class.soorganization.inc.php 
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/inc/class.soorganization.inc.php 
2012-06-18 12:44:16 UTC (rev 9609)
@@ -114,7 +114,7 @@
                        //$id = 
$this->marshal($filters[$this->get_id_field_name()],'int');
                        //$filter_clauses[] = "org.id = {$id}";
                        unset($filter_clauses);
-                       $filter_clauses[] = "org.change_type = 'new'";
+                       $filter_clauses[] = "org.change_type = 'new' OR 
org.change_type = 'change' ";
                        if(isset($filters[$this->get_id_field_name()])){
                                $id = 
$this->marshal($filters[$this->get_id_field_name()],'int');
                                $filter_clauses[] = "org.id = {$id}";
@@ -649,7 +649,7 @@
                $zip = $org_info['zip'];
                if($zip && strlen($zip) > 5)
                {
-                       $zip_code = substr($zip,0,4);
+                       $zip_code = substr($zip,0,5);
                        $city = substr($zip, 5);
                }
                else

Modified: 
branches/stavangerkommune/activitycalendar/inc/class.uiorganization.inc.php
===================================================================
--- branches/stavangerkommune/activitycalendar/inc/class.uiorganization.inc.php 
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/inc/class.uiorganization.inc.php 
2012-06-18 12:44:16 UTC (rev 9609)
@@ -171,13 +171,15 @@
                                        $group_org_id = 
$sogroup->get_orgid_from_group($new_group_id);
                                        
                                        //get affected activities and update 
with new org id
-                                       $update_activities = 
$soactivity->get_activities_for_update($new_group_id, true);
+                                       $update_activities = 
$soactivity->get_activities_for_update($id, true);
+                                       var_dump($update_activities);
                                        foreach($update_activities as $act)
                                        {
                                                
$act->set_organization_id($group_org_id);
                                                
$act->set_group_id($new_group_id);
                                                $act->set_new_org(false);
                                                $soactivity->store($act);
+                                               var_dump($act);
                                        }
                                        
                                        //set local group as stored
@@ -185,6 +187,10 @@
                                        $group->set_transferred(true);
                                        $sogroup->update_local($group);
                                        $message = lang('messages_saved_form');
+                                       
+                                       $contact_persons = 
$socontact->get_booking_contact_persons($group->get_id(), true);
+                               $cp1 = $contact_persons[0];
+                               $cp2 = $contact_persons[1];
                                }
                                else
                                {
@@ -319,7 +325,7 @@
                                        $contact2 = array();
                                        $contact2['name'] = $contact2_name;
                                        $contact2['phone'] = $contact2_phone;
-                                       $contact2['mail'] = $contact_mail_2;
+                                       $contact2['mail'] = $contact2_email;
                                        $contact2['org_id'] = $new_org_id;
                                        
$so_activity->add_contact_person_org($contact2);
                                        
@@ -444,6 +450,7 @@
                $id = (int)phpgw::get_var('id');
                $type = phpgw::get_var('type');
                $cancel_link = self::link(array('menuaction' => 
'activitycalendar.uiorganization.changed_organizations'));
+               $socontact = activitycalendar_socontactperson::get_instance();
                if($type)
                {
                        if(isset($_POST['edit_group'])) // The user has pressed 
the save button
@@ -462,12 +469,17 @@
                        if(count($group_array) > 0){
                                $keys = array_keys($group_array);
                                $group = $group_array[$keys[0]];
-                               _debug_array($group);
+//                             _debug_array($group);
                        }
+                       $contact_persons = 
$socontact->get_local_contact_persons($group->get_id(), true);
+                       $cp1 = $contact_persons[0];
+                       $cp2 = $contact_persons[1];
                        
                        $data = array
                        (
                                'group'         => $group,
+                               'contactperson1' => $cp1,
+                               'contactperson2' => $cp2,
                                'cancel_link' => $cancel_link,
                                'message' => $message,
                                'errorMsgs' => $errorMsgs,
@@ -495,11 +507,15 @@
                                $org = $org_array[$keys[0]];
                        }
                        
-                       //var_dump($org);
+                       $contact_persons = 
$socontact->get_local_contact_persons($org->get_id());
+                       $cp1 = $contact_persons[0];
+                       $cp2 = $contact_persons[1];
                        
                        $data = array
                        (
                                'organization'  => $org,
+                               'contactperson1' => $cp1,
+                               'contactperson2' => $cp2,
                                'cancel_link' => $cancel_link,
                                'message' => $message,
                                'errorMsgs' => $errorMsgs,

Modified: branches/stavangerkommune/activitycalendar/templates/base/activity.php
===================================================================
--- branches/stavangerkommune/activitycalendar/templates/base/activity.php      
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/templates/base/activity.php      
2012-06-18 12:44:16 UTC (rev 9609)
@@ -33,6 +33,42 @@
        
 }
 
+function get_address_search_cp2()
+{
+       var address = document.getElementById('contact_person_2_address').value;
+       var div_address = document.getElementById('contact2_address_container');
+       div_address.style.display="block";
+
+       //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
+       url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
+
+var divcontent_start = "<select name=\"contact2_address_select\" 
id=\"address_cp2\" size=\"5\" onChange='setAddressValue(this)'>";
+var divcontent_end = "</select>";
+       
+       var callback = {
+               success: function(response){
+                                       div_address.innerHTML = 
divcontent_start + JSON.parse(response.responseText) + divcontent_end; 
+                               },
+               failure: function(o) {
+                                        alert("AJAX doesn't work"); //FAILURE
+                                }
+       }
+       var trans = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
+       
+}
+
+function setAddressValue(field)
+{
+       if(field.name == 'contact2_address_select')
+       {
+       var address = document.getElementById('contact_person_2_address');
+       var div_address = document.getElementById('contact2_address_container');
+    
+       address.value=field.value;
+               div_address.style.display="none";
+       }
+}
+
 YAHOO.util.Event.onDOMReady(function()
 {
        get_available_groups();
@@ -541,7 +577,8 @@
                                        if ($editable)
                                        {
                                        ?>
-                                               <input type="text" 
name="contact_person_2_address" id="contact_person_2_address" value="<?php echo 
$activity->get_contact_person_2_address() ?>" />
+                                               <input type="text" 
name="contact_person_2_address" id="contact_person_2_address" value="<?php echo 
$activity->get_contact_person_2_address() ?>" 
onkeyup="javascript:get_address_search_cp2()"/>
+                                               <div 
id="contact2_address_container"></div>
                                        <?php
                                        }
                                        else

Modified: branches/stavangerkommune/activitycalendar/templates/base/arena.php
===================================================================
--- branches/stavangerkommune/activitycalendar/templates/base/arena.php 
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/templates/base/arena.php 
2012-06-18 12:44:16 UTC (rev 9609)
@@ -7,18 +7,18 @@
 
 function get_address_search()
 {
-       var address = document.getElementById('address_txt').value;
+       var address = document.getElementById('address').value;
        var div_address = document.getElementById('address_container');
+       div_address.style.display="block";
 
        url = 
"index.php?menuaction=activitycalendar.uiarena.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"address\" id=\"address\" size\"5\">";
+var divcontent_start = "<select name=\"address_select\" id=\"address\" 
size=\"5\" onChange='setAddressValue(this)'>";
 var divcontent_end = "</select>";
-var divcontent_number = "&nbsp;&nbsp;<label for=\"address_number\"><?php echo 
lang('address_number') ?></label><input type=\"text\" name=\"address_no\" 
id=\"address_no\" size=\"6\"/>"
        
        var callback = {
                success: function(response){
-                                       div_address.innerHTML = 
divcontent_start + JSON.parse(response.responseText) + divcontent_end + 
divcontent_number; 
+                                       div_address.innerHTML = 
divcontent_start + JSON.parse(response.responseText) + divcontent_end; 
                                },
                failure: function(o) {
                                         alert("AJAX doesn't work"); //FAILURE
@@ -27,6 +27,16 @@
        var trans = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
        
 }
+
+function setAddressValue(field)
+{
+       var address = document.getElementById('address');
+       var div_address = document.getElementById('address_container');
+
+       address.value=field.value;
+       div_address.style.display="none";
+}
+
 </script>
 <?php echo activitycalendar_uicommon::get_page_message($message) ?>
 <div class="identifier-header">
@@ -75,8 +85,9 @@
                                        if ($editable)
                                        {
                                        ?>
-                                               <input type="text" 
name="address" id="address_txt" value="<?php echo $arena->get_address() ?>" 
onkeyup="javascript:get_address_search()"/>
+                                               <input type="text" 
name="address" id="address" value="<?php echo $arena->get_address() ?>" 
onkeyup="javascript:get_address_search()"/>
                                                <div 
id="address_container"></div>
+                                               <label 
for="address_number"><?php echo lang('address_number') ?></label><input 
type="text" name="address_no" id="address_no" size="6"/>
                                        <?php
                                        }
                                        else

Modified: branches/stavangerkommune/activitycalendar/templates/base/group.php
===================================================================
--- branches/stavangerkommune/activitycalendar/templates/base/group.php 
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/templates/base/group.php 
2012-06-18 12:44:16 UTC (rev 9609)
@@ -27,15 +27,27 @@
                                <dd><input type="hidden" name="contact1_id" 
value="<?php echo $contactperson1->get_id();?>"/></dd>
                                <dt><label for="contact1_name">Navn</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" name="contact1_name" 
value="<?php echo $contactperson1->get_name();?>"/><br/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson1->get_name();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_phone">Telefon</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact1_phone" value="<?php echo $contactperson1->get_phone();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson1->get_phone();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_mail">E-post</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact1_email" value="<?php echo $contactperson1->get_email();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson1->get_email();?>
+                               <?php }?>
                                </dd>
                                <?php }?>
                                <dt><label>Kontaktperson 2</label></dt>
@@ -43,15 +55,27 @@
                                <dd><input type="hidden" name="contact2_id" 
value="<?php echo $contactperson2->get_id();?>"/></dd>
                                <dt><label for="contact1_name">Navn</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" name="contact2_name" 
value="<?php echo $contactperson2->get_name();?>"/><br/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson2->get_name();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_phone">Telefon</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact2_phone" value="<?php echo $contactperson2->get_phone();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson2->get_phone();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_mail">E-post</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact2_email" value="<?php echo $contactperson2->get_email();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson2->get_email();?>
+                               <?php }?>
                                </dd>
                                <?php }?>
                        </dl>

Modified: 
branches/stavangerkommune/activitycalendar/templates/base/organization.php
===================================================================
--- branches/stavangerkommune/activitycalendar/templates/base/organization.php  
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/activitycalendar/templates/base/organization.php  
2012-06-18 12:44:16 UTC (rev 9609)
@@ -98,15 +98,27 @@
                                <dd><input type="hidden" name="contact1_id" 
value="<?php echo $contactperson1->get_id();?>"/></dd>
                                <dt><label for="contact1_name">Navn</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" name="contact1_name" 
value="<?php echo $contactperson1->get_name();?>"/><br/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson1->get_name();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_phone">Telefon</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact1_phone" value="<?php echo $contactperson1->get_phone();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson1->get_phone();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_mail">E-post</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact1_email" value="<?php echo $contactperson1->get_email();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson1->get_email();?>
+                               <?php }?>
                                </dd>
                                <?php }?>
                                <?php if($contactperson2){?>
@@ -114,15 +126,27 @@
                                <dd><input type="hidden" name="contact2_id" 
value="<?php echo $contactperson2->get_id();?>"/></dd>
                                <dt><label for="contact1_name">Navn</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" name="contact2_name" 
value="<?php echo $contactperson2->get_name();?>"/><br/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson2->get_name();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_phone">Telefon</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact2_phone" value="<?php echo $contactperson2->get_phone();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson2->get_phone();?>
+                               <?php }?>
                                </dd>
                                <dt><label 
for="contact1_mail">E-post</label></dt>
                                <dd>
+                               <?php if($editable){?>
                                        <input type="text" 
name="contact2_email" value="<?php echo $contactperson2->get_email();?>"/>
+                               <?php }else{?>
+                                       <?php echo 
$contactperson2->get_email();?>
+                               <?php }?>
                                </dd>
                                <?php }?>
                        </dl>

Modified: 
branches/stavangerkommune/activitycalendarfrontend/inc/class.uiactivity.inc.php
===================================================================
--- 
branches/stavangerkommune/activitycalendarfrontend/inc/class.uiactivity.inc.php 
    2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/activitycalendarfrontend/inc/class.uiactivity.inc.php 
    2012-06-18 12:44:16 UTC (rev 9609)
@@ -285,7 +285,8 @@
                                        else if(isset($g_id) && 
is_numeric($g_id) && $g_id > 0)
                                        {
                                                $person_ids = 
$this->so_group->get_contacts($g_id);
-                                               $person_arr = 
$this->so_contact->get_local_contact_persons($g_id, true);
+                                               //$person_arr = 
$this->so_contact->get_local_contact_persons($g_id, true);
+                                               $person_arr = 
$this->so_contact->get_booking_contact_persons($g_id, true);
                                                foreach($person_arr as $p)
                                                {
                                                        //var_dump($p);
@@ -583,7 +584,7 @@
                                                $person_arr = 
$this->so_contact->get_booking_contact_persons($activity->get_group_id(), true);
                                                foreach($person_arr as $p)
                                                {
-                                                       $persons[] = $p;
+                                                       $persons_array[] = $p;
                                                }
                                                $desc = 
$this->so_group->get_description($activity->get_group_id());
                                                $group = 
$this->so_group->get_single($activity->get_group_id());
@@ -658,6 +659,8 @@
                                                                                
                'activity'      => $activity,
                                                                                
                'organization' => $organization,
                                                                                
                'group' => $group,
+                                                                               
        'contact1' => $persons_array[0],
+                                                                               
        'contact2' => $persons_array[1],
                                                                                
                'arenas' => $arenas,
                                                                                
                'buildings' => $buildings,
                                                                                
                'categories' => $categories,
@@ -684,6 +687,8 @@
                                                                        (
                                                                                
'activity'      => $activity,
                                                                                
'organization' => $organization,
+                                                                           
'contact1' => $persons_array[0],
+                                                                               
'contact2' => $persons_array[1],
                                                                                
'org_name' => $org_name,
                                                                                
'group' => $group,
                                                                                
'arenas' => $arenas,
@@ -711,6 +716,8 @@
                                                                                
'activity'      => $activity,
                                                                                
'organization' => $organization,
                                                                                
'group' => $group,
+                                                                               
'contact1' => $persons_array[0],
+                                                                               
'contact2' => $persons_array[1],
                                                                                
'arenas' => $arenas,
                                                                                
'buildings' => $buildings,
                                                                                
'categories' => $categories,

Modified: 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity.php
===================================================================
--- 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity.php  
    2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity.php  
    2012-06-18 12:44:16 UTC (rev 9609)
@@ -130,7 +130,9 @@
                                </dt>
                                <dd>
                                        <?php echo $organization->get_name();?>
-                                       <a 
href="index.php?menuaction=activitycalendarfrontend.uiactivity.edit_organization_values&amp;organization_id=<?php
 echo $organization->get_id();?>"><?php echo lang('edit_organization');?></a>
+                                       <?php if(!$activity->get_new_org()){?>
+                                               <a 
href="index.php?menuaction=activitycalendarfrontend.uiactivity.edit_organization_values&amp;organization_id=<?php
 echo $organization->get_id();?>"><?php echo lang('edit_organization');?></a>
+                                       <?php }?>
                                </dd>
                                <dt>
                                        <label for="group_id" 
id="group_label"><?php echo lang('group') ?></label>

Modified: 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_edit.php
===================================================================
--- 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_edit.php
 2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_edit.php
 2012-06-18 12:44:16 UTC (rev 9609)
@@ -78,14 +78,15 @@
 
 function get_address_search()
 {
-       var address = document.getElementById('address_txt').value;
+       var address = document.getElementById('address').value;
        var div_address = document.getElementById('address_container');
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"address\" id=\"address\" size\"5\">";
-var divcontent_end = "</select>";
+       var divcontent_start = "<select name=\"address_select\" id=\"address\" 
size=\"5\" onChange='setAddressValue(this)'>";
+       var divcontent_end = "</select>";
        
        var callback = {
                success: function(response){
@@ -101,14 +102,15 @@
 
 function get_address_search_cp2()
 {
-       var address = document.getElementById('contact2_address_txt').value;
-       var div_address = document.getElementById('contact2_address_container');
+       var address = document.getElementById('contact2_address').value;
+       var div_address = 
document.getElementById('contact2_address_container');'
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"contact2_address\" id=\"address_cp2\" 
size\"5\">";
-var divcontent_end = "</select>";
+       var divcontent_start = "<select name=\"contact2_address_select\" 
id=\"address_cp2\" size=\"5\" onChange='setAddressValue(this)'>";
+       var divcontent_end = "</select>";
        
        var callback = {
                success: function(response){
@@ -122,6 +124,26 @@
        
 }
 
+function setAddressValue(field)
+{
+       if(field.name == 'contact2_address_select')
+       {
+       var address = document.getElementById('contact2_address');
+       var div_address = document.getElementById('contact2_address_container');
+    
+       address.value=field.value;
+               div_address.style.display="none";
+       }
+       else
+       {
+       var address = document.getElementById('address');
+       var div_address = document.getElementById('address_container');
+    
+       address.value=field.value;
+               div_address.style.display="none";
+       }
+}
+
 function allOK()
 {
        if(document.getElementById('title').value == null || 
document.getElementById('title').value == '')
@@ -234,7 +256,7 @@
                                        <label for="special_adaptation"><?php 
echo lang('special_adaptation') ?></label>
                                </dt>
                                <dd>
-                                       <input type="checkbox" 
name="special_adaptation" id="special_adaptation" />
+                                       <input type="checkbox" 
name="special_adaptation" id="special_adaptation" <?php echo 
$activity->get_special_adaptation() ? ' checked="checked"' : '' ?>/>
                                </dd>
                                <hr />
                                <h2><?php echo lang('where_when')?></h2>

Modified: 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new.php
===================================================================
--- 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new.php
  2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new.php
  2012-06-18 12:44:16 UTC (rev 9609)
@@ -35,13 +35,14 @@
 
 function get_address_search()
 {
-       var address = document.getElementById('address_txt').value;
+       var address = document.getElementById('address').value;
        var div_address = document.getElementById('address_container');
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"address\" id=\"address\" size\"5\">";
+var divcontent_start = "<select name=\"address\" id=\"address\" size=\"5\" 
onChange='setAddressValue(this)'>";
 var divcontent_end = "</select>";
        
        var callback = {
@@ -58,13 +59,14 @@
 
 function get_address_search_arena()
 {
-       var address = document.getElementById('arena_address_txt').value;
+       var address = document.getElementById('arena_address').value;
        var div_address = document.getElementById('arena_address_container');
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"arena_address\" id=\"arena_address\" 
size\"5\">";
+var divcontent_start = "<select name=\"arena_address_select\" 
id=\"arena_address\" size=\"5\" onChange='setAddressValue(this)'>";
 var divcontent_end = "</select>";
        
        var callback = {
@@ -81,13 +83,14 @@
 
 function get_address_search_cp2()
 {
-       var address = document.getElementById('contact2_address_txt').value;
+       var address = document.getElementById('contact2_address').value;
        var div_address = document.getElementById('contact2_address_container');
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"contact2_address\" id=\"address_cp2\" 
size\"5\">";
+var divcontent_start = "<select name=\"contact2_address_select\" 
id=\"address_cp2\" size=\"5\" onChange='setAddressValue(this)'>";
 var divcontent_end = "</select>";
        
        var callback = {
@@ -102,6 +105,34 @@
        
 }
 
+function setAddressValue(field)
+{
+       if(field.name == 'contact2_address_select')
+       {
+       var address = document.getElementById('contact2_address');
+       var div_address = document.getElementById('contact2_address_container');
+    
+       address.value=field.value;
+               div_address.style.display="none";
+       }
+       else if(field.name == 'arena_address_select')
+       {
+       var address = document.getElementById('arena_address');
+       var div_address = document.getElementById('arena_address_container');
+    
+       address.value=field.value;
+               div_address.style.display="none";
+       }
+       else
+       {
+               var address = document.getElementById('address');
+               var div_address = document.getElementById('address_container');
+
+               address.value=field.value;
+               div_address.style.display="none";
+       }
+}
+
 function run_checks()
 {
        check_external();
@@ -239,12 +270,10 @@
                                </dt>
                                <dd>
                                        <?php
-                                       $current_district_ids = 
$activity->get_district();
-                                       $current_district_id_array=explode(",", 
$current_district_ids);
                                        foreach($districts as $d)
                                        {
                                        ?>
-                                               <input name="district[]" 
type="checkbox" value="<?php echo $d['part_of_town_id']?>" <?php echo 
(in_array($d['part_of_town_id'], $current_district_id_array) ? 'checked' : 
"")?>/><?php echo $d['name']?><br/>
+                                               <input name="district[]" 
type="checkbox" value="<?php echo $d['part_of_town_id']?>" /><?php echo 
$d['name']?><br/>
                                        <?php
                                        }
                                        ?>
@@ -303,7 +332,7 @@
                                        <dt><label for="arena_name"><?php echo 
lang('name') ?></label></dt>
                                        <dd><input type="text" 
name="arena_name" id="arena_name" /></dd>
                                        <dt><label for="arena_address"><?php 
echo lang('address') ?></label></dt>
-                                       <dd><input type="text" 
name="arena_address_txt" id="arena_address_txt" 
onkeyup="javascript:get_address_search_arena()"/>
+                                       <dd><input type="text" 
name="arena_address" id="arena_address" 
onkeyup="javascript:get_address_search_arena()"/>
                                        <div id="arena_address_container"></div>
                                        <label for="arena_number">Nummer</label>
                                        <input type="text" 
name="arena_number"/><br/>
@@ -335,7 +364,7 @@
                                </dd>
                                <dt>Kontaktinformasjon for kulturkontoret 
(*)</dt>
                                <dt><label 
for="contact2_address">Adresse</label>
-                               <dd><input type="text" 
name="contact2_address_txt" id="contact2_address_txt" 
onkeyup="javascript:get_address_search_cp2()"/>
+                               <dd><input type="text" name="contact2_address" 
id="contact2_address" onkeyup="javascript:get_address_search_cp2()"/>
                                <div id="contact2_address_container"></div></dd>
                                <dt><label 
for="contact2_number">Husnummer</label></dt>
                                <dd><input type="text" 
name="contact2_number"/></dd>

Modified: 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new_org.php
===================================================================
--- 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new_org.php
      2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/activitycalendarfrontend/templates/base/activity_new_org.php
      2012-06-18 12:44:16 UTC (rev 9609)
@@ -22,18 +22,19 @@
 
 function get_address_search()
 {
-       var address = document.getElementById('address_txt').value;
+       var address = document.getElementById('address').value;
        var div_address = document.getElementById('address_container');
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = "<?php echo 
$ajaxURL?>index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"address\" id=\"address\" size\"5\">";
+var divcontent_start = "<select name=\"address_select\" id=\"address_select\" 
size=\"5\" onChange='setAddressValue(this)'>";
 var divcontent_end = "</select>";
        
        var callback = {
                success: function(response){
-                                       div_address.innerHTML = 
divcontent_start + JSON.parse(response.responseText) + divcontent_end; 
+                                       div_address.innerHTML = 
divcontent_start + JSON.parse(response.responseText) + divcontent_end;
                                },
                failure: function(o) {
                                         alert("AJAX doesn't work"); //FAILURE
@@ -43,6 +44,15 @@
        
 }
 
+function setAddressValue(field)
+{
+       var address = document.getElementById('address');
+       var div_address = document.getElementById('address_container');
+
+       address.value=field.value;
+       div_address.style.display="none";
+}
+
 function allOK()
 {
        if(document.getElementById('orgname').value == null || 
document.getElementById('orgname').value == '')
@@ -137,7 +147,7 @@
                                <dt><label for="phone">Telefon (*)</label></dt>
                                <dd><input type="text" name="phone"/></dd>
                                <dt><label for="street">Gate (*)</label></dt>
-                               <dd><input type="text" name="address_txt" 
id="address_txt" onkeyup="javascript:get_address_search()"/>
+                               <dd><input type="text" name="address" 
id="address" onkeyup="javascript:get_address_search()"/>
                                <div id="address_container"></div></dd>
                                <dt><label for="number">Husnummer</label></dt>
                                <dd><input type="text" name="number"/><br/></dd>

Modified: 
branches/stavangerkommune/activitycalendarfrontend/templates/base/organization_edit.php
===================================================================
--- 
branches/stavangerkommune/activitycalendarfrontend/templates/base/organization_edit.php
     2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/activitycalendarfrontend/templates/base/organization_edit.php
     2012-06-18 12:44:16 UTC (rev 9609)
@@ -6,13 +6,14 @@
 <script type="text/javascript">
 function get_address_search()
 {
-       var address = document.getElementById('address_txt').value;
+       var address = document.getElementById('address').value;
        var div_address = document.getElementById('address_container');
+       div_address.style.display="block";
 
        //url = 
"/aktivby/registreringsskjema/ny/index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
        url = 
"index.php?menuaction=activitycalendarfrontend.uiactivity.get_address_search&amp;phpgw_return_as=json&amp;search="
 + address;
 
-var divcontent_start = "<select name=\"address\" id=\"address\" size\"5\">";
+var divcontent_start = "<select name=\"address_select\" id=\"address_select\" 
size\"5\">";
 var divcontent_end = "</select>";
        
        var callback = {
@@ -27,6 +28,15 @@
        
 }
 
+function setAddressValue(field)
+{
+       var address = document.getElementById('address');
+       var div_address = document.getElementById('address_container');
+
+       address.value=field.value;
+       div_address.style.display="none";
+}
+
 function allOK()
 {
        if(document.getElementById('title').value == null || 
document.getElementById('title').value == '')
@@ -359,6 +369,7 @@
                                                <dd><input type="text" 
name="phone" value="<?php echo $organization->get_phone()?>"/></dd>
                                                <dt><label 
for="street">Gate</label></dt>
                                                <dd><input type="text" 
name="address" id="address" value="<?php echo $organization->get_address()?>"/>
+                                               <div 
id="address_container"></div></dd>
                                                <dt><label 
for="org_description">Beskrivelse</label></dt>
                                                <dd><textarea rows="10" 
cols="100" name="org_description"><?php echo 
$organization->get_description()?></textarea></dd>
                                        <hr/>

Modified: branches/stavangerkommune/controller/inc/class.menu.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.menu.inc.php 2012-06-18 
09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.menu.inc.php 2012-06-18 
12:44:16 UTC (rev 9609)
@@ -64,12 +64,12 @@
                                                                                
                'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 'controller.uicontrol_location.index') ),
                                                                                
                'image' => array('property', 'location_1')
                                                                                
        ),
-/*                                                                             
        'component_for_check_list' => array
+                                                                               
        'component_for_check_list' => array
                                                                                
        (
                                                                                
                'text'  => lang('component'),
-                                                                               
                'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 'controller.uicheck_list_for_component.index') ),
+                                                                               
                'url'   => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction'=> 
'controller.uicontrol_location.register_control_to_component') ),
                                                                                
                'image' => array('property', 'entity_1')
-                                                                               
        )*/
+                                                                               
        )
                                                                                
)
                                        ),
 /*                                     'location_for_check_list' => array

Modified: branches/stavangerkommune/controller/inc/class.socheck_list.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.socheck_list.inc.php 
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.socheck_list.inc.php 
2012-06-18 12:44:16 UTC (rev 9609)
@@ -224,6 +224,8 @@
                $sql .= "FROM controller_check_list cl ";
                $sql .= "WHERE cl.control_id = $control_id ";
                $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND NOT cl.planned_date IS NULL ";
+               $sql .= "AND cl.completed_date IS NULL ";
                $sql .= "ORDER BY cl.id;";
                //var_dump($sql);
                $this->db->query($sql);
@@ -261,6 +263,97 @@
                }
        }
        
+       function get_unplanned_check_lists_for_control($control_id, 
$location_code){
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, component_id, location_code, 
num_open_cases, num_pending_cases ";
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "WHERE cl.control_id = $control_id ";
+               $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND cl.planned_date IS NULL ";
+               $sql .= "AND cl.completed_date IS NULL ";
+               $sql .= "ORDER BY cl.id;";
+
+               $this->db->query($sql);
+               
+               $check_list_id = 0;
+               $check_list = null;
+               while ($this->db->next_record()) {
+               
+                       if( $this->db->f('cl_id', true) != $check_list_id ){
+                               
+                               if($check_list_id != 0){
+                                       $check_list_array[] = $check_list;
+                               }
+                               
+                               $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), 
'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int')); 
+                               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id', 
true), 'int'));
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int')); 
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
+                       }
+                       $check_list_id =  $check_list->get_id();
+               }
+               
+               if($check_list != null){
+                       $check_list_array[] = $check_list;
+               
+                       return $check_list_array;
+               }else {
+                       return null;
+               }
+       }
+       
+       function get_open_check_lists_for_control($control_id, $location_code, 
$from_date){
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, component_id, location_code, 
num_open_cases, num_pending_cases ";
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "WHERE cl.control_id = $control_id ";
+               $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND (cl.planned_date IS NULL OR cl.planned_date < 
$from_date) ";
+               $sql .= "AND cl.deadline < $from_date ";
+               $sql .= "AND cl.completed_date IS NULL ";
+               $sql .= "ORDER BY cl.id;";
+               //var_dump($sql);
+               $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_array[] = $check_list;
+                               }
+                               
+                               $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), 
'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int')); 
+                               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id', 
true), 'int'));
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int')); 
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
+                       }
+                       $check_list_id =  $check_list->get_id();
+               }
+               
+               if($check_list != null){
+                       $check_list_array[] = $check_list;
+               
+                       return $check_list_array;
+               }else {
+                       return null;
+               }
+       }
+       
        function get_agg_check_lists_for_location( $location_code, 
$from_date_ts, $to_date_ts, $control_id = 0 ){
                                
                $sql =  "SELECT c.id as c_id, title, start_date, end_date, 
cl.id as cl_id, c.repeat_type, c.repeat_interval, cl.deadline, 
count(cl.num_open_cases) ";
@@ -319,11 +412,18 @@
                }       
        }
        
-       function get_num_open_cases_for_control( $control_id, $location_code, 
$from_date_ts, $to_date_ts ){
+       function get_num_open_cases_for_control( $control_id, $location_code, 
$from_date_ts, $to_date_ts, $component ){
                
                $sql =  "SELECT c.id as c_id, sum(cl.num_open_cases) as count ";
                $sql .= "FROM controller_check_list cl, controller_control c ";
-               $sql .= "WHERE cl.location_code = '{$location_code}' ";
+               if($component)
+               {
+                   $sql .= "WHERE cl.component_id = {$location_code} ";
+               }
+               else
+               {
+                   $sql .= "WHERE cl.location_code = '{$location_code}' ";
+               }
                $sql .= "AND c.id = $control_id ";
                $sql .= "AND cl.control_id = c.id ";
                $sql .= "AND cl.deadline >= $from_date_ts AND $to_date_ts > 
cl.deadline ";
@@ -506,6 +606,40 @@
                return array( "location_code" => $location_code, 
"check_lists_array" => $check_lists_array);
        }
        
+// Fetches check lists for component and control id
+       function get_check_lists_for_control_and_component( $control_id, 
$component_id, $from_date_ts, $to_date_ts, $repeat_type = null ){
+               $sql =  "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, completed_date, ";
+               $sql .= "cl.component_id as cl_component_id, cl.location_code 
as cl_location_code, num_open_cases, num_pending_cases "; 
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "LEFT JOIN controller_control c on cl.control_id = c.id 
";
+               $sql .= "WHERE cl.control_id = {$control_id} ";
+               $sql .= "AND cl.component_id = {$component_id} ";
+               
+               if( $repeat_type != null )
+                       $sql .= "AND c.repeat_type = $repeat_type ";
+               
+               $sql .= "AND deadline BETWEEN $from_date_ts AND $to_date_ts ";
+               
+               $this->db->query($sql);
+               
+               while ($this->db->next_record()) {
+                       $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+                       
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'int'));
+                       
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                       
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
+                       
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
+                       
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int')); 
+                       
$check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id', 
true), 'int'));
+                       
$check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code',
 true), 'string'));
+                       
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int'));
+                       
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
+                       
+                       $check_lists_array[] = $check_list;
+               }
+               
+               return array( "location_code" => $location_code, 
"check_lists_array" => $check_lists_array);
+       }
+       
        function get_check_list_for_date($control_id, $current_date){
                $sql =  "SELECT c.id as c_id, title, description, start_date, 
end_date, control_area_id, c.location_code as c_location_code, repeat_type, 
repeat_interval, ";
                $sql .= "cl.id as cl_id, cl.status as cl_status, cl.comment as 
cl_comment, deadline, planned_date, completed_date, ";

Modified: branches/stavangerkommune/controller/inc/class.socontrol.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.socontrol.inc.php    
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.socontrol.inc.php    
2012-06-18 12:44:16 UTC (rev 9609)
@@ -113,8 +113,26 @@
                        //return isset($result);
                }
 
-               public function get_controls_by_location($location_code, 
$from_date, $to_date, $repeat_type, $return_type = "return_object")
+               function get_controls_for_location($location_code, $role_id, 
$from_date, $to_date, $repeat_type)
                {
+                   $controls = array();
+                   $controls_loc = 
$this->get_controls_by_location($location_code, $from_date, $to_date, 
$repeat_type, '', $role_id );
+                   $controls_comp = 
$this->get_controls_for_components_by_location($location_code, $from_date, 
$to_date, $repeat_type, '', $role_id );
+                   
+                   foreach($controls_loc as $cl)
+                   {
+                       $controls[] = $cl;
+                   }
+                   foreach($controls_comp as $cc)
+                   {
+                       $controls[] = $cc;
+                   }
+                   
+                   return $controls;
+               }
+               
+               public function get_controls_by_location($location_code, 
$from_date, $to_date, $repeat_type, $return_type = "return_object", $role_id = 
'')
+               {
                        $controls_array = array();
                        $joins .= " {$this->left_join} fm_responsibility_role 
ON (c.responsibility_id = fm_responsibility_role.id)";
                        
@@ -125,10 +143,12 @@
                        
                        if( is_numeric($repeat_type) )
                                $sql .= "AND c.repeat_type = $repeat_type ";
+                       if( is_numeric($role_id))
+                           $sql .= "AND c.responsibility_id = $role_id ";
                        
                        $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
                        $sql .= "OR c.start_date > $from_date AND c.start_date 
< $to_date)";
-                       
+                       //var_dump($sql."<br/>");
                        $this->db->query($sql);
 
                        while($this->db->next_record()) {
@@ -143,9 +163,6 @@
                                
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), 'int'));
                                
$control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
 true), 'string'));
                                
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_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), 'string'));
                                
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
                                
$control->set_repeat_type_label($this->unmarshal($this->db->f('repeat_type', 
true), 'int'));
                                
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
@@ -164,9 +181,114 @@
                                return null;
                        }
                }
+               
+           public function 
get_controls_for_components_by_location($location_code, $from_date, $to_date, 
$repeat_type, $return_type = "return_object", $role_id = '')
+               {
+                       $controls_array = array();
+                       $joins .= " {$this->left_join} fm_responsibility_role 
ON (c.responsibility_id = fm_responsibility_role.id)";
+                       
+                       $sql  = "SELECT distinct c.*, 
fm_responsibility_role.name AS responsibility_name FROM 
controller_control_component_list ccl "; 
+                       $sql .= "LEFT JOIN controller_control c on 
ccl.control_id=c.id ";
+                       $sql .= "LEFT JOIN fm_responsibility_role ON 
fm_responsibility_role.id = c.responsibility_id ";
+                       $sql .= "LEFT JOIN fm_bim_item ON fm_bim_item.id = 
ccl.component_id ";
+                       $sql .= "WHERE fm_bim_item.loc1 = '$location_code' ";
+                       
+                       if( is_numeric($repeat_type) )
+                               $sql .= "AND c.repeat_type = $repeat_type ";
+                       if( is_numeric($role_id))
+                           $sql .= "AND c.responsibility_id = $role_id ";
+                       
+                       $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
+                       $sql .= "OR c.end_date > $from_date AND c.start_date < 
$to_date)";
+                       //var_dump($sql."<br/>");
+                       $this->db->query($sql);
+                       
+                       while($this->db->next_record()) {
+                               $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($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_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_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
 true), 'string'));
+                               
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
+                               
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
+                               
$control->set_repeat_type_label($this->unmarshal($this->db->f('repeat_type', 
true), 'int'));
+                               
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
+                               
+                               if($return_type == "return_object")
+                                       $controls_array[] = $control;
+                               else
+                                       $controls_array[] = $control->toArray();
+                       }
 
+                       if( count( $controls_array ) > 0 ){
+                               return $controls_array; 
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+               
+               public function get_controls_by_component($location_code, 
$from_date, $to_date, $repeat_type = null, $return_type = "return_object")
+               {
+                       $controls_array = array();
+                       
+                       $sql   = "SELECT c.id as control_id, c.*, bim_item.id, 
xpath('/beskrivelse/text()', xml_representation), bim_item.location_code, 
bim_item.address ";
+                       $sql  .= "FROM controller_control_component_list cl ";
+                       $sql  .= "JOIN fm_bim_item bim_item on cl.component_id 
= bim_item.id ";
+                       $sql  .= "JOIN fm_bim_type bim_type on cl.location_id = 
bim_type.location_id ";
+                       $sql  .= "JOIN controller_control c on cl.control_id = 
c.id ";
+                       $sql  .= "AND bim_item.type = bim_type.id ";
+                       $sql  .= "AND bim_item.location_code LIKE 
'$location_code%'";
+                       
+                       if( $repeat_type != null){
+                               $sql .= "AND c.repeat_type = $repeat_type ";
+                       }
+                       
+                       $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
+                       $sql .= "OR c.start_date > $from_date AND c.start_date 
< $to_date)";
+                       
+                       $this->db->query($sql);
+                       
+                       while($this->db->next_record()) {
+                               $control = new 
controller_control($this->unmarshal($this->db->f('control_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_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_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
 true), 'string'));
+                               
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 
true), 'int'));
+                               
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
+                               
$control->set_repeat_type_label($this->unmarshal($this->db->f('repeat_type', 
true), 'int'));
+                               
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
+                               
+                               if($return_type == "return_object")
+                                       $controls_array[] = $control;
+                               else
+                                       $controls_array[] = $control->toArray();
+                       }
+
+                       if( count( $controls_array ) > 0 ){
+                               return $controls_array; 
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+
                function get_controls_by_control_area($control_area_id)
                {
+                       $control_area_id = (int) $control_area_id;
                        $controls_array = array();
 
                        $sql = "SELECT * FROM controller_control WHERE 
control_area_id=$control_area_id";
@@ -185,9 +307,6 @@
                                
$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), 'string'));
                                
$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'));
                                
@@ -217,7 +336,7 @@
                        while($this->db->next_record()) {
                                $control_id = 
$this->unmarshal($this->db->f('id', true), 'int');
                                $title = $this->unmarshal($this->db->f('title', 
true), 'string');
-                               $location_code = 
$this->unmarshal($this->db->f('location_code', true), 'strign');
+                               $location_code = 
$this->unmarshal($this->db->f('location_code', true), 'string');
 
                                $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
 
@@ -232,18 +351,57 @@
                                return null;
                        }
                }
+               
+           function get_components_for_control($control_id)
+               {
+                       $controls_array = array();
 
+                       $sql =  "SELECT c.id, c.title, ccl.component_id, 
bim_type.description, bim.location_code ";
+            $sql .= "FROM controller_control c, 
controller_control_component_list ccl, fm_bim_item bim, fm_bim_type bim_type "; 
+                       $sql .= "WHERE ccl.control_id = $control_id ";
+            $sql .= "AND ccl.control_id = c.id ";
+                       $sql .= "AND bim.id = ccl.component_id ";
+                       $sql .= "AND bim_type.id = bim.type";
+
+                       $this->db->query($sql);
+
+                       while($this->db->next_record()) {
+                               $control_id = 
$this->unmarshal($this->db->f('id', true), 'int');
+                               $title = $this->unmarshal($this->db->f('title', 
true), 'string');
+                               $component_id = 
$this->unmarshal($this->db->f('component_id', true), 'int');
+                               $component_type = 
$this->unmarshal($this->db->f('description', true), 'string');
+                               $component_location_code = 
$this->unmarshal($this->db->f('location_code', true), 'string');
+                               //$component_guid = 
$this->unmarshal($this->db->f('guid', true), 'string');
+                               //$component_description = 
$this->getBimItemAttributeValue($component_guid, "beskrivelse");
+                               //$component_name = 
$this->getBimItemAttributeValue($component_guid, "betegnelse");
+                               //$component_author = 
$this->getBimItemAttributeValue($component_guid, "juridisk_person");
+                               
+                               $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$component_location_code));
+                               
+                               $controls_array[] = array("id" => $control_id, 
"title" => $title, "component_id" => $component_id, "component_description" => 
$component_type, "component_location" => $location_array["loc1_name"]);
+                       }
+
+                       if( count( $controls_array ) > 0 ){
+                               return $controls_array; 
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+
                function get_control_location($control_id, $location_code)
                {
+                       $control_id = (int)$control_id;
                        $sql =  "SELECT * FROM controller_control_location_list 
WHERE control_id = $control_id AND location_code = '$location_code'";
                        
                        $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
                        
                        if($this->db->next_record()){
-                               $control_location = new 
controller_control_location($this->unmarshal($this->db->f('id', true), 'int'));
+                               $control_location = new 
controller_control_location($this->unmarshal($this->db->f('id'), 'int'));
        
                                
$control_location->set_location_code($this->unmarshal($this->db->f('location_code',
 true), 'string'));
-                               
$control_location->set_control_id($this->unmarshal($this->db->f('control_id', 
true), 'int'));
+                               
$control_location->set_control_id($this->unmarshal($this->db->f('control_id'), 
'int'));
                                                        
                                return $control_location;
                        }
@@ -253,13 +411,120 @@
                        }
                }
                
-               function register_control_to_location($control_id, 
$location_code)
+               public function register_control_to_location($control_id, $data)
                {
-                       $sql =  "INSERT INTO controller_control_location_list 
(control_id, location_code) values($control_id, $location_code)";
+
+                       $control_id = (int) $control_id;
+                       $delete_location = array();
+                       $add_location = array();
+                       foreach($data['control_location_orig'] as 
$location_code)
+                       {
+                               if(!in_array($location_code, 
$data['control_location']))
+                               {
+                                       $delete_location[] = $location_code;
+                               }
+                       }
+
+                       foreach($data['control_location'] as $location_code)
+                       {
+                               if(!in_array($location_code, 
$data['control_location_orig']))
+                               {
+                                       $add_location[] = $location_code;
+                               }
+                       }
+
+                       $this->db->transaction_begin();
+                       foreach ($delete_location as $location_code)
+                       {
+                               $sql =  "DELETE FROM 
controller_control_location_list  WHERE control_id = {$control_id} AND 
location_code = '{$location_code}'";
+                               $this->db->query($sql);
+                       }
+
+                       foreach ($add_location as $location_code)
+                       {
+                               $sql =  "SELECT * FROM 
controller_control_location_list WHERE control_id = {$control_id} AND 
location_code = '$location_code'";
+                               $this->db->query($sql, __LINE__, __FILE__);
                        
-                       return $this->db->query($sql);
+                               if(!$this->db->next_record())
+                               {
+                                       $sql =  "INSERT INTO 
controller_control_location_list (control_id, location_code) VALUES ( 
{$control_id}, '{$location_code}')";
+                                       $this->db->query($sql);
+                               }
+                       }
+
+                       return $this->db->transaction_commit();
                }
 
+               public function check_control_component($control_id, 
$location_id, $component_id)
+               {
+                       $control_id             = (int) $control_id;
+                       $location_id    = (int) $location_id;
+                       $component_id   = (int) $component_id;
+                       $sql =  "SELECT * FROM 
controller_control_component_list WHERE control_id = {$control_id} AND 
location_id = {$location_id} AND component_id = {$component_id}";
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       return $this->db->next_record();
+               }
+
+               function register_control_to_component($data)
+               {
+
+                       $delete_component = array();
+                       $add_component = array();
+                       $this->db->transaction_begin();
+
+                       if(isset($data['register_component']) && 
is_array($data['register_component']))
+                       {
+                               foreach($data['register_component'] as 
$component_info)
+                               {
+                                       $component_arr = explode('_', 
$component_info);
+                                       if(count($component_arr)!=3)
+                                       {
+                                               continue;
+                                       }
+                                       
+                                       $control_id             = (int) 
$component_arr[0];
+                                       $location_id    = (int) 
$component_arr[1];
+                                       $component_id   = (int) 
$component_arr[2];
+
+                                       if(!$control_id)
+                                       {
+                                               return false;
+                                       }
+
+                                       $sql =  "SELECT * FROM 
controller_control_component_list WHERE control_id = {$control_id} AND 
location_id = {$location_id} AND component_id = {$component_id}";
+                                       $this->db->query($sql, __LINE__, 
__FILE__);
+                       
+                                       if(!$this->db->next_record())
+                                       {
+                                               $sql =  "INSERT INTO 
controller_control_component_list (control_id, location_id, component_id) 
VALUES ( {$control_id}, {$location_id}, {$component_id})";
+                                               $this->db->query($sql);
+                                       }
+                               }
+                       }
+
+                       if(isset($data['delete']) && is_array($data['delete']))
+                       {
+                               foreach($data['delete'] as $component_info)
+                               {
+                                       $component_arr = explode('_', 
$component_info);
+                                       if(count($component_arr)!=3)
+                                       {
+                                               continue;
+                                       }
+                                       
+                                       $control_id             = (int) 
$component_arr[0];
+                                       $location_id    = (int) 
$component_arr[1];
+                                       $component_id   = (int) 
$component_arr[2];
+                               
+                                       $sql =  "DELETE FROM 
controller_control_component_list WHERE control_id = {$control_id} AND 
location_id = {$location_id} AND component_id = {$component_id}";
+                                       $this->db->query($sql);
+                               }
+                       }
+
+                       return $this->db->transaction_commit();
+               }
+
+
                function add_component_to_control($control_id, $component_id)
                {
                        $sql =  "INSERT INTO controller_control_component_list 
(control_id, component_id) values($control_id, $component_id)";
@@ -332,8 +597,6 @@
                        $condition =  join(' AND ', $clauses);
 
                        $tables = "controller_control";
-                       //$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)";
                        $joins .= " {$this->left_join} fm_responsibility_role 
ON (controller_control.responsibility_id = fm_responsibility_role.id)";
 
@@ -343,7 +606,7 @@
                        }
                        else
                        {
-                               $cols = 'controller_control.id, 
controller_control.title, controller_control.description, 
controller_control.start_date, controller_control.end_date, 
controller_control.procedure_id, controller_control.control_area_id, 
controller_control.requirement_id, controller_control.costresponsibility_id, 
controller_control.responsibility_id, controller_control.component_type_id, 
controller_control.component_id, controller_control.location_code, 
controller_control.repeat_type, controller_control.repeat_interval, 
controller_control.enabled, controller_procedure.title AS procedure_name, 
fm_responsibility_role.name AS responsibility_name ';
+                               $cols = 'controller_control.id, 
controller_control.title, controller_control.description, 
controller_control.start_date, controller_control.end_date, 
controller_control.procedure_id, controller_control.control_area_id, 
controller_control.requirement_id, controller_control.costresponsibility_id, 
controller_control.responsibility_id, controller_control.repeat_type, 
controller_control.repeat_interval, controller_control.enabled, 
controller_procedure.title AS procedure_name, fm_responsibility_role.name AS 
responsibility_name ';
                        }
 
                        $dir = $ascending ? 'ASC' : 'DESC';
@@ -381,9 +644,6 @@
                                $category = 
execMethod('phpgwapi.categories.return_single', 
$this->unmarshal($this->db->f('control_area_id', 'int')));
                                
$control->set_control_area_name($category[0]['name']);
        //                      
$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), 'string'));
                                
$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'));
                        }
@@ -425,9 +685,6 @@
                        
//$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
 true), 'string'));
                        $category = 
execMethod('phpgwapi.categories.return_single', 
$this->unmarshal($this->db->f('control_area_id', 'int')));
                        $control->set_control_area_name($category[0]['name']);
-                       
$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), 'string'));
                        
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
                        
$control->set_repeat_type_label($control->get_repeat_type());
                        
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
@@ -541,6 +798,7 @@
                {
                        $columnAlias = "attribute_values";
                        $sql = "select 
array_to_string(xpath('descendant-or-self::*[{$attribute}]/{$attribute}/text()',
 (select xml_representation from fm_bim_item where guid='{$bimItemGuid}')), 
',') as $columnAlias";
+                       //var_dump($sql);
                        $this->db->query($sql,__LINE__,__FILE__);
                        if($this->db->num_rows() > 0)
                        {

Modified: branches/stavangerkommune/controller/inc/class.uicalendar.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicalendar.inc.php   
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicalendar.inc.php   
2012-06-18 12:44:16 UTC (rev 9609)
@@ -51,8 +51,8 @@
                                
                public $public_functions = array
                (
-                       'view_calendar_for_month'                       =>      
true,
-                       'view_calendar_for_year'                        =>      
true,
+                       'view_calendar_for_month'                             
=>        true,
+                       'view_calendar_for_year'                              
=>        true,
                        'view_calendar_year_for_locations'      =>  true,
                        'view_calendar_month_for_locations'     =>  true
                );
@@ -61,20 +61,20 @@
                {
                        parent::__construct();
                        
-                       $read    = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_READ, 'controller');//1 
-                       $add     = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_ADD, 'controller');//2 
-                       $edit    = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_EDIT, 'controller');//4 
-                       $delete  = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_DELETE, 'controller');//8 
+                       $read    = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_READ, 'controller'); //1 
+                       $add     = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_ADD, 'controller'); //2 
+                       $edit    = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_EDIT, 'controller'); //4 
+                       $delete  = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_DELETE, 'controller'); //8 
                        
-                       $manage  = $GLOBALS['phpgw']->acl->check('.control', 
16, 'controller');//16
+                       $manage  = $GLOBALS['phpgw']->acl->check('.control', 
16, 'controller'); //16
                        
-                       $this->so = CreateObject('controller.socheck_list');
-                       $this->so_control = 
CreateObject('controller.socontrol');
-                       $this->so_control_group = 
CreateObject('controller.socontrol_group');
-                       $this->so_control_group_list = 
CreateObject('controller.socontrol_group_list');
-                       $this->so_control_item = 
CreateObject('controller.socontrol_item');
-                       $this->so_check_list = 
CreateObject('controller.socheck_list');
-                       $this->so_check_item = 
CreateObject('controller.socheck_item');
+                       $this->so                                               
                                = CreateObject('controller.socheck_list');
+                       $this->so_control                                       
        = CreateObject('controller.socontrol');
+                       $this->so_control_group                         = 
CreateObject('controller.socontrol_group');
+                       $this->so_control_group_list    = 
CreateObject('controller.socontrol_group_list');
+                       $this->so_control_item                          = 
CreateObject('controller.socontrol_item');
+                       $this->so_check_list                                    
= CreateObject('controller.socheck_list');
+                       $this->so_check_item                                    
= CreateObject('controller.socheck_item');
                        
                        
self::set_active_menu('controller::location_check_list');
                }
@@ -85,27 +85,28 @@
                        $year = phpgw::get_var('year');
                        $month = phpgw::get_var('month');
                        
-                       $year = intval( $year );
-                       $from_month = intval( $month );
-                               
-                       $from_date_ts = 
month_calendar::get_start_month_date_ts($year, $month);
-                       $to_date_ts = 
month_calendar::get_end_month_date_ts($year, $month);
-                                                                               
                                        
-                       $criteria = array
-                       (
-                               'user_id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
-                               'type_id' => 1,
-                               'role_id' => 0, // For å begrense til en 
bestemt rolle - ellers listes alle roller for brukeren
-                               'allrows' => false
-                       );
-               
-                       $location_finder = new location_finder();
-                       $my_locations = $location_finder->get_responsibilities( 
$criteria );
+                       // Validates year. If year is not set, current year is 
chosen
+                       $year = $this->validate_year($year);
+                       
+                       // Validates month. If year is not set, current month 
in current year is chosen
+                       $month = $this->validate_month($month);
+                       
+                       // Gets timestamp value of first day in month
+                       $from_date_ts = 
month_calendar::get_start_month_date_ts($year, intval( $month ));
 
-                       if(empty($location_code)){
-                               $location_code = 
$my_locations[0]["location_code"];
-                       }
+                       // Gets timestamp value of first day in month
+                       $to_date_ts = 
month_calendar::get_end_month_date_ts($year, intval( $month ));
+
+                       // Validates location_code. If not set, first location 
among assigned locations
+                       $location_code = 
$this->validate_location_code($location_code);
                        
+                       $level = $this->get_location_level($location_code);
+                                               
+      $user_role = true;
+
+      // Fetches buildings on property
+      $buildings_on_property = $this->get_buildings_on_property($user_role, 
$location_code, $level);
+                       
                        // Fetches controls for location within specified time 
period
                        $controls_for_location_array = 
$this->so_control->get_controls_by_location($location_code, $from_date_ts, 
$to_date_ts);
 
@@ -126,24 +127,34 @@
                        $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
                
                        $property_array = 
execMethod('property.solocation.read', array('type_id' => 1, 'allrows' => 
true));
-                                               
+                       
+                       // Gets array of locations assigned to current user
+                       $my_locations = $this->get_my_assigned_locations();
+                       
+                       $heading_array = 
month_calendar::get_heading_array($year, $month);
+                       
                        $data = array
                        (               
-                               'my_locations'                    => 
$my_locations,
-                               'property_array'                  => 
$property_array,
-                               'current_location'                => 
$location_array,
-                               'heading_array'                   => 
month_calendar::get_heading_array($year, $month),
+                               'buildings_on_property'         => 
$buildings_on_property,
+                               'my_locations'                          => 
$my_locations,
+                               'property_array'                        => 
$property_array,
+                               'current_location'                      => 
$location_array,
+                               'heading_array'                         => 
$heading_array,
                                'controls_calendar_array' => 
$controls_calendar_array,
-                               'date_format'                     => 
$date_format,
-                               'current_year'                    => $year,
-                               'current_month_nr'                => $month,
+                               'date_format'                                   
=> $date_format,
+                               'current_year'                                  
=> $year,
+                               'current_month_nr'                      => 
$month,
+                               'location_level'                                
=> $level,
                        );
                        
                        self::add_javascript('controller', 'controller', 
'jquery.js');
                        self::add_javascript('controller', 'controller', 
'ajax.js');
+                       self::add_javascript('controller', 'controller', 
'jquery-ui-1.8.20.custom.min.js');
+                       
self::add_stylesheet('controller/templates/base/css/jquery-ui-1.8.20.custom.css');
                        
                        
self::render_template_xsl(array('calendar/view_calendar_month', 
'calendar/check_list_status_checker', 
-                                                                               
        'calendar/icon_color_map', 'calendar/select_my_locations'), $data);
+                                                                               
                                                                        
'calendar/icon_color_map', 'calendar/select_my_locations', 
+                                                                               
                                                                        
'calendar/select_buildings_on_property'), $data);
                }
                
                public function view_calendar_for_year()
@@ -151,44 +162,34 @@
                        $location_code = phpgw::get_var('location_code');
                        $year = phpgw::get_var('year');
                        
-                       // Array that should conatain control and calendar 
objects that will be sent to view
+                       // Validates year. If year is not set, current year is 
chosen
+                       $year = $this->validate_year($year);
+                       
+                       // Gets timestamp of first day in year
+                       $from_date_ts = $this->get_start_date_year_ts($year);
+
+                       // Gets timestamp of first day in next year
+                       $to_date_ts = $this->get_end_date_year_ts($year);
+
+                       // Array that will be populated with controls and 
calendar objects that will be sent to view
                        $controls_calendar_array = array();
+                               
+       // Validates location_code. If not set, first location among assigned 
locations
+                       $location_code = 
$this->validate_location_code($location_code);
                        
-                       if(empty($year)){
-                               $year = date("Y");
-                       }
-                       
-                       $year = intval($year);
+                       $level = $this->get_location_level($location_code);
+                                               
+      $user_role = true;
 
-                       $from_date_ts = strtotime("01/01/$year");
-                       $to_year = $year + 1;
-                       $to_date_ts = strtotime("01/01/$to_year");
+      // Fetches buildings on property
+      $buildings_on_property = $this->get_buildings_on_property($user_role, 
$location_code, $level);
                        
-                       $manage = false;
-               
-                       if($manage)
-            {
-               $locations = execMethod('property.solocation.get_children', 
$location_code);
-            }else{
-               $criteria = array
-                               (
-                                       'user_id' => 
$GLOBALS['phpgw_info']['user']['account_id'], // 
-                                       'type_id' => 1, // Nivå i 
bygningsregisteret 1:eiendom
-                                       'role_id' => 0, // For å begrense til 
en bestemt rolle - ellers listes alle roller for brukeren
-                                       'allrows' => false
-                               );
-               
-                               $location_finder = new location_finder();
-                               $my_locations = 
$location_finder->get_responsibilities( $criteria );
-            }
-                               
-                       if(empty($location_code)){
-                               $location_code = 
$my_locations[0]["location_code"];
-                       }
-                       
                        // Fetches all controls for the location within time 
period
-                       $controls_for_location_array = 
$this->so_control->get_controls_by_location($location_code, $from_date_ts, 
$to_date_ts,  $repeat_type = null);
+                       $controls_for_location_array = 
$this->so_control->get_controls_by_location($location_code, $from_date_ts, 
$to_date_ts, $repeat_type = null);
                        
+                       // Fetches all controls for the components on location 
within time period
+                       $controls_for_component_array = 
$this->so_control->get_controls_by_component($location_code, $from_date_ts, 
$to_date_ts, $repeat_type = null);
+                       
                        $controls_calendar_array = array();
                        
                        // Loops through controls with repeat type day or week 
in controls_for_location_array
@@ -200,7 +201,7 @@
                                        $agg_open_cases_pr_month_array = 
$this->build_agg_open_cases_pr_month_array($control, $location_code, $year);
                                        
                                        $year_calendar = new 
year_calendar($control, $year);
-                                       $calendar_array = 
$year_calendar->build_agg_calendar($agg_open_cases_pr_month_array);
+                                       $calendar_array = 
$year_calendar->build_agg_month_calendar($agg_open_cases_pr_month_array);
                                                
                                        $controls_calendar_array[] = 
array("control" => $control->toArray(), "calendar_array" => $calendar_array);
                                }
@@ -231,19 +232,27 @@
                        }
                        
                        $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
+
+                       // Gets array of locations assigned to current user
+                       $my_locations = $this->get_my_assigned_locations();
                        
+                       $heading_array = year_calendar::get_heading_array();
+                       
                        $data = array
                        (
-                               'my_locations'                    => 
$my_locations,
-                               'current_location'        => $location_array,
-                               'heading_array'                   => 
year_calendar::get_heading_array(),
+                               'buildings_on_property'         => 
$buildings_on_property,
+                               'my_locations'                                  
        => $my_locations,
+                               'current_location'              => 
$location_array,
+                               'heading_array'                         => 
$heading_array,
                                'controls_calendar_array' => 
$controls_calendar_array,
-                               'date_format'                     => 
$date_format,
-                               'current_year'                    => $year,
+                               'date_format'                                   
=> $date_format,
+                               'current_year'                                  
=> $year,
+                               'location_level'                                
=> $level,
                        );
                        
                        
self::render_template_xsl(array('calendar/view_calendar_year', 
'calendar/check_list_status_checker', 
-                                                                               
        'calendar/icon_color_map', 'calendar/select_my_locations'), $data);
+                                                                               
                                                                        
'calendar/icon_color_map', 'calendar/select_my_locations', 
+                                                                               
                                                                        
'calendar/select_buildings_on_property'), $data);
                        
                        self::add_javascript('controller', 'controller', 
'jquery.js');
                        self::add_javascript('controller', 'controller', 
'ajax.js');
@@ -260,15 +269,17 @@
                        if(is_numeric($control_id) & $control_id > 0)
                        {
                                $locations_for_control_array = 
$this->so_control->get_locations_for_control($control_id);
+                               $components_for_control_array = 
$this->so_control->get_components_for_control($control_id);
                        }
                        
-                       if(empty($year)){
-                               $year = intval( date("Y") );
-                       }
+                       // Validates year. If year is not set, current year is 
chosen
+                       $year = $this->validate_year($year);
                        
-                       $from_date_ts = strtotime("01/01/$year");
-                       $to_year = $year + 1;
-                       $to_date_ts = strtotime("01/01/$to_year");
+                       // Gets timestamp of first day in year
+                       $from_date_ts = $this->get_start_date_year_ts($year);
+
+                       // Gets timestamp of first day in next year
+                       $to_date_ts = $this->get_end_date_year_ts($year);
                        
                        $locations_with_calendar_array = array();
                        
@@ -280,9 +291,31 @@
                                        $agg_open_cases_pr_month_array = 
$this->build_agg_open_cases_pr_month_array($control, $curr_location_code, 
$year);
                                        
                                        $year_calendar = new 
year_calendar($control, $year);
-                                       $calendar_array = 
$year_calendar->build_agg_calendar($agg_open_cases_pr_month_array);
+                                       $calendar_array = 
$year_calendar->build_agg_month_calendar($agg_open_cases_pr_month_array);
                                        $locations_with_calendar_array[] = 
array("location" => $location, "calendar_array" => $calendar_array);
                                }
+                               
+                           foreach($components_for_control_array as 
$component){
+                                       $curr_component_id = 
$component['component_id'];
+                                       
+                                       // Loops through controls in 
controls_for_location_array and populates aggregate open cases pr month array.
+                                       $agg_open_cases_pr_month_array = 
$this->build_agg_open_cases_pr_month_array($control, $curr_component_id, $year, 
true);
+                                       
+                                       $year_calendar = new 
year_calendar($control, $year);
+                                       $calendar_array = 
$year_calendar->build_agg_calendar($agg_open_cases_pr_month_array);
+                                       $components_with_calendar_array[] = 
array("component" => $component, "calendar_array" => $calendar_array);
+                               }
+                               
+                           foreach($components_for_control_array as 
$component){
+                                       $curr_component_id = 
$component['component_id'];
+                                       
+                                       // Loops through controls in 
controls_for_location_array and populates aggregate open cases pr month array.
+                                       $agg_open_cases_pr_month_array = 
$this->build_agg_open_cases_pr_month_array($control, $curr_component_id, $year, 
true);
+                                       
+                                       $year_calendar = new 
year_calendar($control, $year);
+                                       $calendar_array = 
$year_calendar->build_agg_calendar($agg_open_cases_pr_month_array);
+                                       $components_with_calendar_array[] = 
array("component" => $component, "calendar_array" => $calendar_array);
+                               }
                        }else if($control->get_repeat_type() > 1){
                                foreach($locations_for_control_array as 
$location){
                                        $curr_location_code = 
$location['location_code'];
@@ -297,31 +330,40 @@
 
                                        $locations_with_calendar_array[] = 
array("location" => $location, "calendar_array" => $calendar_array);
                                }
+                               
+                         foreach($components_for_control_array as $component){
+                                       $curr_component_id = 
$component['component_id'];
+                                       
+                                       $repeat_type = 
$control->get_repeat_type();
+                                       $component_with_check_lists = 
$this->so->get_check_lists_for_control_and_component($control_id, 
$curr_component_id, $from_date_ts, $to_date_ts, $repeat_type);  
+                                       
+                                       $check_lists_array = 
$component_with_check_lists["check_lists_array"];
+                                       
+                                       $year_calendar = new 
year_calendar($control, $year);
+                                       $calendar_array = 
$year_calendar->build_calendar( $check_lists_array );
+
+                                       $components_with_calendar_array[] = 
array("component" => $component, "calendar_array" => $calendar_array);
+                               }
                        }
                        
-                       $criteria = array
-                       (
-                               'user_id' => 
$GLOBALS['phpgw_info']['user']['account_id'], //
-                               'type_id' => 1, // Nivå i bygningsregisteret 
1:eiendom
-                               'role_id' => 0, // For å begrense til en 
bestemt rolle - ellers listes alle roller for brukeren
-                               'allrows' => false
-                       );
-               
-                       $location_finder = new location_finder();
-                       $my_locations = $location_finder->get_responsibilities( 
$criteria );
+                       // Gets array of locations assigned to current user
+                       $my_locations = $this->get_my_assigned_locations();
                        
+                       $heading_array = year_calendar::get_heading_array();
+                       
                        $data = array
                        (
-                               'my_locations'                                  
=> $my_locations,
-                               'control'                                       
        => $control->toArray(),
-                               'heading_array'                                 
=> year_calendar::get_heading_array(),
-                               'locations_with_calendar_array' => 
$locations_with_calendar_array,
-                               'date_format'                                   
=> $date_format,
-                               'current_year'                                  
=> $year,
+                               'my_locations'                                  
                        => $my_locations,
+                               'control'                                       
                                                => $control->toArray(),
+                               'heading_array'                                 
                        => $heading_array,
+                               'locations_with_calendar_array'         => 
$locations_with_calendar_array,
+                         'components_with_calendar_array'      => 
$components_with_calendar_array,
+                               'date_format'                                   
                                => $date_format,
+                               'current_year'                                  
                => $year,
                        );
                        
                        self::render_template_xsl( 
array('calendar/view_calendar_year_for_locations', 
'calendar/check_list_status_checker', 
-                                                                               
         'calendar/icon_color_map', 'calendar/select_my_locations'), $data);
+                                                                               
                                                                         
'calendar/icon_color_map', 'calendar/select_my_locations'), $data);
                        
                        self::add_javascript('controller', 'controller', 
'jquery.js');
                        self::add_javascript('controller', 'controller', 
'ajax.js');
@@ -337,18 +379,20 @@
                        if(is_numeric($control_id) & $control_id > 0)
                        {
                                $locations_for_control_array = 
$this->so_control->get_locations_for_control($control_id);
+                               $components_for_control_array = 
$this->so_control->get_components_for_control($control_id);
                        }
 
-                       if(empty($year)){
-                               $year = intval( date("Y") );
-                       }
+                       // Validates year. If year is not set, current year is 
chosen
+                       $year = $this->validate_year($year);
                        
-                       if(empty($month)){
-                               $month = date("n");
-                       }
+                       // Validates month. If year is not set, current month 
in current year is chosen
+                       $month = $this->validate_month($month);
                        
-                       $from_date_ts = 
month_calendar::get_start_month_date_ts($year, $month);
-                       $to_date_ts = 
month_calendar::get_end_month_date_ts($year, $month);
+                       // Gets timestamp value of first day in month
+                       $from_date_ts = 
month_calendar::get_start_month_date_ts($year, intval( $month ));
+
+                       // Gets timestamp value of first day in month
+                       $to_date_ts = 
month_calendar::get_end_month_date_ts($year, intval( $month ));
                        
                        $locations_with_calendar_array = array();
                        
@@ -366,28 +410,22 @@
                                $locations_with_calendar_array[] = 
array("location" => $location, "calendar_array" => $calendar_array);
                        }
                        
-                       $criteria = array
-                       (
-                               'user_id' => 
$GLOBALS['phpgw_info']['user']['account_id'], // 
-                               'type_id' => 1, // Nivå i bygningsregisteret 
1:eiendom
-                               'role_id' => 0, // For å begrense til en 
bestemt rolle - ellers listes alle roller for brukeren
-                               'allrows' => false
-                       );
-               
-                       $location_finder = new location_finder();
-                       $my_locations = $location_finder->get_responsibilities( 
$criteria );
+                       // Gets array of locations assigned to current user
+                       $my_locations = $this->get_my_assigned_locations();
                        
+                       $heading_array = 
month_calendar::get_heading_array($year, $month);
+                       
                        $data = array
                        (               
-                               'control'                                       
        => $control->toArray(),
-                               'my_locations'                                  
=> $my_locations,
-                               'property_array'                                
=> $property_array,
-                               'location_array'                                
=> $location_array,
-                               'heading_array'                                 
=> month_calendar::get_heading_array($year, $month),
+                               'control'                                       
                                        => $control->toArray(),
+                               'my_locations'                                  
                => $my_locations,
+                               'property_array'                                
                => $property_array,
+                               'location_array'                                
                        => $location_array,
+                               'heading_array'                                 
                => $heading_array,
                                'locations_with_calendar_array' => 
$locations_with_calendar_array,
-                               'date_format'                                   
=> $date_format,
-                               'current_month_nr'                              
=> $month,
-                               'current_year'                                  
=> $year,
+                               'date_format'                                   
                        => $date_format,
+                               'current_month_nr'                              
                => $month,
+                               'current_year'                                  
                => $year,
                        );
                        
                        self::render_template_xsl( 
array('calendar/view_calendar_month_for_locations', 
'calendar/check_list_status_checker', 
@@ -413,7 +451,7 @@
                }
                
                // Generates array of aggregated number of open cases for each 
month in time period 
-               function build_agg_open_cases_pr_month_array($control, 
$location_code, $year){
+               function build_agg_open_cases_pr_month_array($control, 
$location_code, $year, $component=false ){
                                
                        // Checks if control starts in the year that is 
displayed 
                        if( date("Y", $control->get_start_date()) == $year ){
@@ -447,7 +485,7 @@
                                $num_open_cases_for_control_array = array();
                                
                                // Fetches aggregate value for open cases in a 
month from db    
-                               $num_open_cases_for_control_array = 
$this->so_check_list->get_num_open_cases_for_control( $control->get_id(), 
$location_code, $month_start_ts, $month_end_ts ); 
+                               $num_open_cases_for_control_array = 
$this->so_check_list->get_num_open_cases_for_control( $control->get_id(), 
$location_code, $month_start_ts, $month_end_ts, $component );     
                                
                                // If there is a aggregated value for the 
month, add aggregated status object to agg_open_cases_pr_month_array
                                if( !empty($num_open_cases_for_control_array) ){
@@ -461,6 +499,106 @@
                        return $agg_open_cases_pr_month_array;
                }
                
+               function get_buildings_on_property($user_role, $location_code, 
$level){
+                                       
+                       // Property level
+                       if($level == 1){
+                               $property_location_code = $location_code;
+                       }
+                       // Building level
+                       else if($level > 1){
+                               $split_loc_code_array = explode('-', 
$location_code);
+                               $property_location_code = 
$split_loc_code_array[0];
+                       }       
+               
+                 if($user_role){
+                               $criteria = array();
+                               $criteria['location_code'] = 
$property_location_code;
+                               $criteria['field_name'] = 'loc2_name';
+                               $criteria['child_level'] = '2';
+                               
+       $buildings_on_property = execMethod('property.solocation.get_children', 
$criteria);
+      }else{
+        $buildings_on_property = 
execMethod('property.solocation.get_children', $property_location_code);
+      }
+                       
+      return $buildings_on_property;
+               }
+               
+               function get_location_level($location_code){
+                       $level = count(explode('-', $location_code));
 
+                       return $level;
+               }       
+               
+               function validate_location_code($location_code){
+                       $criteria = array
+                       (
+                               'user_id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
+                               'type_id' => 1,
+                               'role_id' => 0, // For å begrense til en 
bestemt rolle - ellers listes alle roller for brukeren
+                               'allrows' => false
+                       );
+               
+                       $location_finder = new location_finder();
+                       $my_locations = $location_finder->get_responsibilities( 
$criteria );
+
+                       if(empty($location_code)){
+                               $location_code = 
$my_locations[0]["location_code"];
+                       }
+                       
+                       return $location_code;
+               }
+               
+               function get_my_assigned_locations($location_code){
+                       $criteria = array
+                       (
+                               'user_id' => 
$GLOBALS['phpgw_info']['user']['account_id'], // 
+                               'type_id' => 1, // Nivå i bygningsregisteret 
1:eiendom
+                               'role_id' => 0, // For å begrense til en 
bestemt rolle - ellers listes alle roller for brukeren
+                               'allrows' => false
+                       );
+               
+                       $location_finder = new location_finder();
+                       $my_locations = $location_finder->get_responsibilities( 
$criteria );
+                       
+                       return $my_locations;
+               }
+               
+               function get_start_date_year_ts($year){
+                       $start_date_year_ts = strtotime("01/01/$year");
+                       
+                       return $start_date_year_ts;
+               }
+               
+               function get_end_date_year_ts($year){
+                       $to_year = $year + 1;
+                       $end_date_year_ts = strtotime("01/01/$to_year");
+                       
+                       return $end_date_year_ts;
+               }
+               
+               function validate_year($validate_year){
+                       
+                       if( empty( $validate_year ) ){
+                               $validate_year = date("Y");
+                       }
+                       
+                       $validate_year = intval($validate_year);
+                       
+                       return $validate_year;
+               }
+               
+               function validate_month($month){
+                       
+                       if( empty( $month ) ){
+                               $month = date("n");
+                       }
+                       
+                       $month = intval($month);
+                       
+                       return $month;
+               }
+
                public function query(){}
-       }
\ No newline at end of file
+       }

Modified: branches/stavangerkommune/controller/inc/class.uicheck_list.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicheck_list.inc.php 
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicheck_list.inc.php 
2012-06-18 12:44:16 UTC (rev 9609)
@@ -320,12 +320,6 @@
                        
self::render_template_xsl(array('check_list/check_list_tab_menu','check_list/edit_check_list'),
 $data);
                }
                
-               /**
-                * Public function for displaying the edit check list form
-                * 
-                * @param HTTP:: check list id
-                * @return data array
-               */
                function view_cases_for_check_list(){
                        $check_list_id = phpgw::get_var('check_list_id');
                        
@@ -339,8 +333,8 @@
                        
                        $data = array
                        (
-                               'control'                       => 
$control->toArray(),
-                               'check_list'            => 
$check_list->toArray(),
+                               'control'                               => 
$control->toArray(),
+                               'check_list'                    => 
$check_list->toArray(),
                                'location_array'        => $location_array,
                                'date_format'           => $date_format
                        );
@@ -355,14 +349,6 @@
                        
self::render_template_xsl(array('check_list/check_list_tab_menu', 
'check_list/view_cases_for_check_list'), $data);
                }
                
-       
-               
-               /**
-                * Public function for displaying the create message form
-                * 
-                * @param HTTP:: check list id 
-                * @return data array
-               */
                function create_case_message(){
                        $check_list_id = phpgw::get_var('check_list_id');
                                                
@@ -379,10 +365,10 @@
                        
                        $data = array
                        (
-                               'location_array'                => 
$location_array,
-                               'control_array'                 => 
$control->toArray(),
+                               'location_array'        => $location_array,
+                               'control_array'         => $control->toArray(),
                                'check_list'                    => 
$check_list_with_check_items,
-                               'date_format'                   => $date_format
+                               'date_format'           => $date_format
                        );
                        
                        self::add_javascript('controller', 'controller', 
'jquery.js');
@@ -395,59 +381,6 @@
                        self::render_template_xsl('create_case_messsage', 
$data);
                }
                
-               /**
-                * Public function for displaying the create message form
-                * 
-                * @param HTTP:: check list id 
-                * @return data array
-               */
-               public function view_control_info(){
-                       $check_list_id = phpgw::get_var('check_list_id');
-                       
-                       $check_list = $this->so->get_single($check_list_id);
-                       $control = 
$this->so_control->get_single($check_list->get_control_id());
-                       
-                       $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'],
-                               );              
-                       }
-
-                       // Fetches prosedures that are related to first control 
area in list
-                       $control_area_id = $control_areas_array2[1]['id'];
-                       $procedures_array = 
$this->so_procedure->get_procedures_by_control_area($control_area_id);
-                       $role_array = $this->so_control->get_roles();
-                       
-                       $location_code = $check_list->get_location_code();  
-                       $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
-                       
-                       $data = array
-                       (
-                               'location_array'                => 
$location_array,
-                               'control'                               => 
$control->toArray(),
-                               'check_list'                    => 
$check_list->toArray(),
-                               'date_format'                   => $date_format,
-                               'control_areas_array2'  => array('options' => 
$control_areas_array2),
-                               'procedures_array'              => 
$procedures_array,
-                               'role_array'                    => $role_array
-                       );
-
-                       self::add_javascript('controller', 'controller', 
'jquery.js');
-                       self::add_javascript('controller', 'controller', 
'jquery-ui.custom.min.js');
-                       
-                       
self::render_template_xsl(array('check_list/check_list_tab_menu','check_list/view_control_info'),
 $data);
-               }
-               
                // Saves a check list that already exists. Returns status for 
update as a JSON array with values update/not updated  
                public function update_check_list(){
                        $check_list_id = phpgw::get_var('check_list_id');
@@ -512,42 +445,42 @@
                        
self::render_template_xsl('check_list/print_check_list', $data);
                }
                
+               public function view_control_info(){
+                       $check_list_id = phpgw::get_var('check_list_id');
+                       
+                       $check_list = $this->so->get_single($check_list_id);
+                       $control = 
$this->so_control->get_single($check_list->get_control_id());
+                       
+                       $location_code = $check_list->get_location_code();  
+                       $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
+                       
+                       $data = array
+                       (
+                               'location_array'                                
=> $location_array,
+                               'control'                                       
                        => $control->toArray(),
+                               'check_list'                                    
        => $check_list->toArray(),
+                       );
+
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'jquery-ui.custom.min.js');
+                       
+                       
self::render_template_xsl(array('check_list/check_list_tab_menu','check_list/view_control_info'),
 $data);
+               }
+               
                function view_control_details(){
                        $control_id = phpgw::get_var('control_id');
                        
                        $control = $this->so_control->get_single($control_id);
                        
-                       // 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
-                       $control_area_id = $control_areas_array2[1]['id'];
-                       $procedures_array = 
$this->so_procedure->get_procedures_by_control_area($control_area_id);
-                       $role_array = $this->so_control->get_roles();
-                       
                        $data = array
                        (
-                               'control'       => $control->toArray(),
-                               'procedures_array'                      => 
$procedures_array,
-                               'role_array'                            => 
$role_array
+                               'control'                                       
        => $control->toArray(),
                        );
                        
                        
self::render_template_xsl('check_list/view_control_details', $data);
                }
                                                
-               // Function that displays control groups and control items for 
a check list
+               // Displays control groups and control items for a check list
                function register_case(){
                        $check_list_id = phpgw::get_var('check_list_id');
                        
@@ -704,6 +637,7 @@
                        return json_encode( $check_list );
                }
                
+               // Returns open cases for a check list as JSON 
                public function get_cases_for_check_list()
                {
                        $check_list_id = phpgw::get_var('check_list_id');

Modified: branches/stavangerkommune/controller/inc/class.uicommon.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicommon.inc.php     
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicommon.inc.php     
2012-06-18 12:44:16 UTC (rev 9609)
@@ -754,7 +754,7 @@
                {
                        return self::get_messages($messages, 'info');
                }
-
+ 
                /**
                 * Download xls, csv or similar file representation of a data 
table
                 */

Modified: branches/stavangerkommune/controller/inc/class.uicontrol.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicontrol.inc.php    
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicontrol.inc.php    
2012-06-18 12:44:16 UTC (rev 9609)
@@ -1,4 +1,4 @@
-<?php 
+<?php
        /**
        * phpGroupWare - controller: a part of a Facilities Management System.
        *
@@ -28,64 +28,61 @@
        * @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');
+  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');
        
-       phpgw::import_class('phpgwapi.yui');
+  phpgw::import_class('phpgwapi.yui');
        
-       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/');
+  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;         
+  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_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,
+    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,
+                       'get_controls_by_control_area'  =>      true,
                );
 
                public function __construct()
                {
                        parent::__construct();
 
-                       $read        = 
$GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_READ, 'controller');//1 
-                       $add         = 
$GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_ADD, 'controller');//2 
-                       $edit         = 
$GLOBALS['phpgw']->acl->check('.control', PHPGW_ACL_EDIT, 'controller');//4 
-                       $delete     = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_DELETE, 'controller');//8 
+                       $read    = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_READ, 'controller');//1 
+                       $add     = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_ADD, 'controller');//2 
+                       $edit    = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_EDIT, 'controller');//4 
+                       $delete  = $GLOBALS['phpgw']->acl->check('.control', 
PHPGW_ACL_DELETE, 'controller');//8 
                        
-                       $manage     = $GLOBALS['phpgw']->acl->check('.control', 
16, 'controller');//16
+                       $manage  = $GLOBALS['phpgw']->acl->check('.control', 
16, 'controller');//16
 
                        //if(!$manage)
                        
@@ -188,13 +185,7 @@
                                                                'type' => 
'submit',
                                                                'name' => 
'search',
                                                                'value' => 
lang('Search')
-                                                       ),
-                                                       array(
-                                                               'type' => 
'link',
-                                                               'value' => 
lang('New control'),
-                                                               'href' => 
self::link(array('menuaction' => 'controller.uicontrol.view_control_details')),
-                                                               'class' => 
'new_item'
-                                                       ),
+                                                       )
                                                ),
                                        ),
                                ),
@@ -240,47 +231,8 @@
                                        )
                                ),
                        );
-/*     
- *                                             ,
-                                               array(
-                                                       'key' => 'actions',
-                                                       'hidden' => true
-                                               ),
-                                               array(
-                                                       'key' => 'labels',
-                                                       'hidden' => true
-                                               ),
-                                               array(
-                                                       'key' => 'ajax',
-                                                       'hidden' => true
-                                               )               
- * 
- * $parameters3 = array
-                                       (
-                                               'parameter' => array
-                                               (
-                                                       array
-                                                       (
-                                                               'name'          
=> 'search_for',
-                                                               'source'        
=> 'location_code'
-                                                       ),
-                                               )
-                                       );
-                       $data['rowactions']['action'][] = array
-                                               (
-                                                       'my_name'               
        => 'view',
-                                                       'text'                  
=> lang('composites'),
-                                                       'action'                
=> $GLOBALS['phpgw']->link('/index.php',array
-                                                       (
-                                                               'menuaction'    
  => 'rental.uicomposite.index',
-                                                               'search_type'   
  => 'location_id',
-                                                               'populate_form' 
  => 'yes'
-                                                       )),
-                                                       'parameters'    => 
$parameters3
-                                               );*/
-//_debug_array($data); 
 
-                       self::render_template_xsl('datatable', $data);
+                       self::render_template_xsl(array( 
'control/controls_datatable', 'datatable' ), $data);
                }
                
                /**
@@ -304,7 +256,6 @@
                        
                        $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','globals' => true,'use_acl' 
=> $this->_category_acl));
                        $control_areas_array = $control_areas['cat_list'];
-                       
                        // END as categories
                
                        if($control != null)
@@ -323,13 +274,13 @@
                        
                        $data = array
                        (
-                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 0),
-                               'view'                                          
=> "control_details",
-                               'editable'                                      
=> true,
-                               'control'                                       
=> ($control != null) ? $control->toArray() : null,
+                               'tabs'                                          
                        => $GLOBALS['phpgw']->common->create_tabs($tabs, 0),
+                               'view'                                          
                        => "control_details",
+                               'editable'                                      
                => true,
+                               'control'                                       
                        => ($control != null) ? $control->toArray() : null,
                                'control_areas_array'           => 
$control_areas_array,
                                'procedures_array'                      => 
$procedures_array,
-                               'role_array'                            => 
$role_array,
+                               'role_array'                                    
        => $role_array,
                                'repeat_type_array'                     => 
$repeat_type_array
                        );
                        
@@ -547,10 +498,10 @@
                                        
                        $data = array
                        (
-                               'tabs'                                          
=> $GLOBALS['phpgw']->common->create_tabs($tabs, 2),
-                               'view'                                          
=> 'control_items',
-                               'control_group_ids'                     => 
implode($control_group_ids, ","),
-                               'control'                                   => 
$control->toArray(),
+                               '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                   
                        );
                        
@@ -764,22 +715,18 @@
                        $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.uicontrol.view_control_details', 'id' => $value['control_id'])));
                        $value['labels'][] = lang('View control');
-                       //$value['parameters'][] = "control_id";
                        
                        $value['ajax'][] = false;
                        $value['actions'][] = 
html_entity_decode(self::link(array('menuaction' => 
'controller.uicontrol.view_locations_for_control', 'id' => 
$value['control_id'])));
                        $value['labels'][] = lang('View locations for control');
-                       //$value['parameters'][] = "control_id";
                        
                        $value['ajax'][] = false;
                        $value['actions'][] = 
html_entity_decode(self::link(array('menuaction' => 
'controller.uicheck_list.add_check_list', 'location_code' => 
$value['location_code'])));
                        $value['labels'][] = lang('add_check_list_to_location');
-                       //$value['parameters'][] = "control_id";
                }
                
                public function register_control_to_location()
@@ -826,11 +773,14 @@
                        $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();
                        
@@ -843,18 +793,11 @@
 
                        $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)
                        {
-/*                             $obj_serialized = $control_obj->serialize();
-                               $obj_serialized['show_locations'] = array(
-                                       'href' => 
html_entity_decode(self::link(array('menuaction' => 
'controller.uicontrol.view_locations_for_control', 'id' => 
$result['location_id']))),
-                                       'label' => 
lang('show_controls_for_location')
-                               );
-                               $results['results'][] = $obj_serialized;*/
                                $results['results'][] = 
$control_obj->serialize();      
                        }
                        
@@ -863,7 +806,6 @@
                        $results['sort'] = $params['sort'];
                        $results['dir'] = $params['dir'];
 
-                       //array_walk($results["results"], array($this, 
"add_actions"), array($type));
                        array_walk($results["results"], array($this, 
"_add_links"), "controller.uicontrol.view_control_details");
                        
                        foreach($results["results"] as &$res) {

Modified: branches/stavangerkommune/controller/inc/class.uicontrol_group.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicontrol_group.inc.php      
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicontrol_group.inc.php      
2012-06-18 12:44:16 UTC (rev 9609)
@@ -118,13 +118,7 @@
                                                                '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 group'),
-                                                               'href' => 
self::link(array('menuaction' => 'controller.uicontrol_group.add')),
-                                                               'class' => 
'new_item'
-                                                       ),
+                                                       )
                                                ),
                                        ),
                                ),
@@ -166,7 +160,7 @@
                        );
 //_debug_array($data);
 
-                       self::render_template_xsl('datatable', $data);
+                       self::render_template_xsl(array( 
'control_group/control_groups_datatable', 'datatable' ), $data);
                }
 
                /**

Modified: branches/stavangerkommune/controller/inc/class.uicontrol_item.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicontrol_item.inc.php       
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicontrol_item.inc.php       
2012-06-18 12:44:16 UTC (rev 9609)
@@ -123,13 +123,7 @@
                                                                'type' => 
'submit',
                                                                'name' => 
'search',
                                                                'value' => 
lang('Search')
-                                                       ),
-                                                       array(
-                                                               'type' => 
'link',
-                                                               'value' => 
lang('New control item'),
-                                                               'href' => 
self::link(array('menuaction' => 'controller.uicontrol_item.add')),
-                                                               'class' => 
'new_item'
-                                                       ),
+                                                       )
                                                ),
                                        ),
                                ),
@@ -173,9 +167,8 @@
                        phpgwapi_yui::load_widget('paginator');
                        phpgwapi_yui::load_widget('datatable');
                        self::add_javascript('controller', 'yahoo', 
'datatable.js');
-//_debug_array($data);
-
-                       self::render_template_xsl('datatable', $data);
+               
+                       self::render_template_xsl( array( 
'control_item/control_items_datatable', 'datatable' ), $data);
                }
 
                /**
@@ -198,109 +191,73 @@
                public function edit()
                {
                        $control_item_id = phpgw::get_var('id');
-               
-                       if(isset($control_item_id) && $control_item_id > 0)
-                       {
-                               $control_item = 
$this->so->get_single($control_item_id);
-                       }
-                       else
-                       {
-                               $control_item = new controller_control_item();
-                       }
+                       
+                       // Sigurd: START as categories
+                       $cats   = CreateObject('phpgwapi.categories', -1, 
'controller', '.control');
+                       $cats->supress_info     = true;
+                       
+                       $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','globals' => true,'use_acl' 
=> $this->_category_acl));
+                       $control_areas_array = $control_areas['cat_list'];
 
-                       if(isset($_POST['save_control_item'])) // The user has 
pressed the save button
-                       {
-                               if(isset($control_item)) // Add new values to 
the control item
-                               {
-                                       $what_to_do_txt = 
phpgw::get_var('what_to_do','html');
-                                       $what_to_do_txt = str_replace("&nbsp;", 
" ", $what_to_do_txt);
-                                       $how_to_do_txt = 
phpgw::get_var('how_to_do','html');
-                                       $how_to_do_txt = str_replace("&nbsp;", 
" ", $how_to_do_txt);
-                                       
$control_item->set_title(phpgw::get_var('title'));
-                                       
$control_item->set_required(phpgw::get_var('required') == 'on' ? true : false);
-                                       
$control_item->set_type(phpgw::get_var('control_item_type'));
-                                       $control_item->set_what_to_do( 
$what_to_do_txt );
-                                       $control_item->set_how_to_do( 
$how_to_do_txt );
-                                       $control_item->set_control_group_id( 
phpgw::get_var('control_group') );
-                                       $control_item->set_control_area_id( 
phpgw::get_var('control_area') );
-                               
-                                       $control_item_id = 
$this->so->store($control_item);
-                                               
-                                       if($control_item_id > 0)
-                                       {
-                                               $message = 
lang('messages_saved_form');
-                                               
-                                               if($control_item->get_type() == 
'control_item_type_3' | $control_item->get_type() == 'control_item_type_4'){
-                                                       $option_values = 
phpgw::get_var('option_values');
-                               
-                                                       foreach($option_values 
as $option_value){
-                                                               
$control_item_option = new controller_control_item_option($option_value, 
$control_item_id);
-                                                               
$control_item_option_id = $this->so_control_item_option->store( 
$control_item_option );
-                                                       }
-                                               }
-                                       }
-                                       else
-                                       {
-                                               $ctrl_item_id = 
$this->so->add($control_item);
-                                               if($ctrl_item_id)
-                                               {
-                                                       $message = 
lang('messages_saved_form');
-                                               }
-                                               else
-                                               {
-                                                       $error = 
lang('messages_form_error');
-                                               }
-                                       }
+                       $control_groups_array = 
$this->so_control_group->get_control_group_array();
+                       
+                       /*
+                        * hack to fix display of &nbsp; char 
+                        */
+                       $control_item->set_what_to_do(str_replace("&nbsp;", " 
",$control_item->get_what_to_do()));
+                       $control_item->set_how_to_do(str_replace('&nbsp;', ' ', 
$control_item->get_how_to_do()));
 
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'controller.uicontrol_item.index', 'dir' => 'desc'));
-                               }
-                       }
-                       else if(isset($_POST['cancel_control_item'])) // The 
user has pressed the cancel button
-                       {
-                               if(isset($control_item_id) && $control_item_id 
> 0)
-                               {
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'controller.uicontrol_item.view', 'id' => $control_item_id));
-                               }
-                               else
-                               {
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'controller.uicontrol_item.index'));
-                               }
-                       }
-                       else
-                       {
-                               // Sigurd: START as categories
-                               $cats   = CreateObject('phpgwapi.categories', 
-1, 'controller', '.control');
-                               $cats->supress_info     = true;
-                               
-                               $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','globals' => true,'use_acl' 
=> $this->_category_acl));
-                               $control_areas_array = 
$control_areas['cat_list'];
+                       $control_item_array = $control_item->toArray();
+                       
+                       $data = array
+                       (
+                               'editable'                              => true,
+                               'control_item'                  => 
$control_item_array,
+                               'control_areas'                 => 
$control_areas_array,
+                               'control_groups'                => 
$control_groups_array,
+                       );
 
-                               $control_groups_array = 
$this->so_control_group->get_control_group_array();
-                               
-                               /*
-                                * hack to fix display of &nbsp; char 
-                                */
-                               
$control_item->set_what_to_do(str_replace("&nbsp;", " 
",$control_item->get_what_to_do()));
-                               
$control_item->set_how_to_do(str_replace('&nbsp;', ' ', 
$control_item->get_how_to_do()));
+                       $this->use_yui_editor(array('what_to_do','how_to_do'));
+                       
+                       self::add_javascript('controller', 'controller', 
'jquery.js');
+                       self::add_javascript('controller', 'controller', 
'ajax.js');
+                       self::add_javascript('controller', 'controller', 
'jquery-ui.custom.min.js');
 
-                               $control_item_array = $control_item->toArray();
+                       self::render_template_xsl('control_item/control_item', 
$data);
+               }
+               
+               public function save()
+               {
+                       $control_item_id = phpgw::get_var('id');
+                       $what_to_do_txt = phpgw::get_var('what_to_do','html');
+                       $what_to_do_txt = str_replace("&nbsp;", " ", 
$what_to_do_txt);
+                       $how_to_do_txt = phpgw::get_var('how_to_do','html');
+                       $how_to_do_txt = str_replace("&nbsp;", " ", 
$how_to_do_txt);
+                       $control_item->set_title(phpgw::get_var('title'));
+                       $control_item->set_required(phpgw::get_var('required') 
== 'on' ? true : false);
+                       
$control_item->set_type(phpgw::get_var('control_item_type'));
+                       $control_item->set_what_to_do( $what_to_do_txt );
+                       $control_item->set_how_to_do( $how_to_do_txt );
+                       $control_item->set_control_group_id( 
phpgw::get_var('control_group') );
+                       $control_item->set_control_area_id( 
phpgw::get_var('control_area') );
                                
-                               $data = array
-                               (
-                                       'editable'                              
=> true,
-                                       'control_item'                  => 
$control_item_array,
-                                       'control_areas'                 => 
$control_areas_array,
-                                       'control_groups'                => 
$control_groups_array,
-                               );
-
-                               
$this->use_yui_editor(array('what_to_do','how_to_do'));
+                       $control_item_id = $this->so->store($control_item);
                                
-                               self::add_javascript('controller', 
'controller', 'jquery.js');
-                               self::add_javascript('controller', 
'controller', 'ajax.js');
-                               self::add_javascript('controller', 
'controller', 'jquery-ui.custom.min.js');
-
-                               
self::render_template_xsl('control_item/control_item', $data);
+                       if($control_item_id > 0)
+                       {
+                               $message = lang('messages_saved_form');
+                               
+                               if($control_item->get_type() == 
'control_item_type_3' | $control_item->get_type() == 'control_item_type_4'){
+                                       $option_values = 
phpgw::get_var('option_values');
+               
+                                       foreach($option_values as 
$option_value){
+                                               $control_item_option = new 
controller_control_item_option($option_value, $control_item_id);
+                                               $control_item_option_id = 
$this->so_control_item_option->store( $control_item_option );
+                                       }
+                               }
                        }
+                       
+                       $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'controller.uicontrol_item.index', 'dir' => 'desc'));
                }
 
                public function query()
@@ -327,6 +284,7 @@
                        {
                                $filters['control_areas'] = $ctrl_area; 
                        }
+                       
                        $ctrl_group = phpgw::get_var('control_groups');
                        if(isset($ctrl_group) && $ctrl_group > 0)
                        {

Modified: 
branches/stavangerkommune/controller/inc/class.uicontrol_location.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uicontrol_location.inc.php   
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uicontrol_location.inc.php   
2012-06-18 12:44:16 UTC (rev 9609)
@@ -29,6 +29,12 @@
        */
        
        phpgw::import_class('phpgwapi.yui');
+
+       /**
+       * Import the jQuery class
+       */
+       phpgw::import_class('phpgwapi.jquery');
+
        phpgw::import_class('controller.uicommon');
        phpgw::import_class('controller.socontrol_area');
        
@@ -56,15 +62,23 @@
                private $so_check_item;
                private $so_procedure;
        
-               var $public_functions = array(
-                                                                               
'index' => true,
-                                                                               
'view_locations_for_control'            => true,
-                                                                               
'register_control_to_location'          => true,
-                                                                               
'register_control_to_location_2'        => true,
-                                                                               
'get_locations_for_control'             => true,
-                                                                               
'get_location_category'                         => true,
-                                                                               
'get_district_part_of_town'                     => true
-                                                                       );
+               var $public_functions = array
+               (
+                       'index'                                                 
        => true,
+                       'view_locations_for_control'            => true,
+                       'register_control_to_location'          => true,
+                       'register_control_to_location_2'        => true,
+                       'register_control_to_component'         => true,
+                       'edit_component'                                        
=> true,
+                       'get_locations_for_control'             => true,
+                       'get_location_category'                         => true,
+                       'get_district_part_of_town'                     => true,
+                       'query2'                                                
        => true,
+                       'get_category_by_entity'                        => true,
+                       'get_entity_table_def'                          => true,
+                       'get_locations'                                         
=> true,
+                       'get_location_type_category'            => true
+               );
 
                function __construct()
                {
@@ -109,10 +123,10 @@
                        
                        $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','globals' => true,'use_acl' 
=> $this->_category_acl));
                                                        
-                       $control_areas_array2 = array();
+                       $control_areas_array = array();
                        foreach($control_areas['cat_list'] as $cat_list)
                        {
-                               $control_areas_array2[] = array
+                               $control_areas_array[] = array
                                (
                                        'id'    => $cat_list['cat_id'],
                                        'name'  => $cat_list['name'],
@@ -120,17 +134,28 @@
                        }
                        // END as categories
 
-                       $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.uicontrol_location.register_control_to_location'))
-                                       ));
+                       $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.uicontrol_location.register_control_to_location'))
+                               ),
+                               array
+                               (
+                                       'label' => lang('add components for 
control'),
+                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol_location.register_control_to_component'))
+                               )
+                       );
                        
                        $data = array(
                                'tabs'                                  => 
$GLOBALS['phpgw']->common->create_tabs($tabs, 0),
                                'view'                                  => 
"view_locations_for_control",
-                               'control_areas_array2'  => 
$control_areas_array2,
+                               'control_areas_array'   => $control_areas_array,
                                'locations_table' => array(
                                        'source' => 
self::link(array('menuaction' => 
'controller.uicontrol_location.get_locations_for_control', 'control_id' => 
$control_id ,'phpgw_return_as' => 'json')),
                                        'field' => array(
@@ -183,40 +208,26 @@
                
                function register_control_to_location()
                {
+                       $control_id = phpgw::get_var('control_id');
                        if(phpgw::get_var('save_location'))
                        {
+                               $values = phpgw::get_var('values');
                                //add component to control using component item 
ID
-                               $items_checked = array();
-                               $items = phpgw::get_var('values_assign');
-                               $item_arr = explode('|',$items);
-                               foreach($item_arr as $item)
-                               {
-                                       $items_checked[] = explode(';',$item);
-                               }
-                               //var_dump($items_checked);
+                               $values['control_location'] = 
isset($values['control_location']) && $values['control_location'] ? 
array_unique($values['control_location']) : array();
+                               $values['control_location_orig'] = 
isset($values['control_location_orig']) && $values['control_location_orig'] ? 
array_unique($values['control_location_orig']) : array();
 
-                               $control_id = phpgw::get_var('control_id');
-                               //$location_code = 
phpgw::get_var('location_code');
-                               
-                               $control_location  = null;
-                               $control_location_id = 0;
-                               
-                               foreach($items_checked as $location_code)
+                               $ok = 
$this->so_control->register_control_to_location($control_id, $values);
+
+/*                             if($ok)
                                {
-                                       $control_location = 
$this->so_control->get_control_location($control_id, $location_code[0]);
-                                       
-                                       if($control_location == null )
-                                       {                                       
-                                               $control_location_id = 
$this->so_control->register_control_to_location($control_id, $location_code[0]);
-                                       }
+                                       return json_encode( array( "status" => 
"saved" ) );
                                }
-                               
-/*                             if($control_location_id > 0)
-                                       return json_encode( array( "status" => 
"saved" ) );
                                else
+                               {
                                        return json_encode( array( "status" => 
"not_saved" ) );
+                               }
 */
-                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'controller.uicontrol_location.index'));
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 
'controller.uicontrol_location.register_control_to_location', 'control_id' => 
$control_id));
 
                        }
                        else
@@ -258,39 +269,50 @@
                                $default_value = array 
('id'=>'','name'=>lang('no role'));
                                array_unshift 
($responsibility_roles,$default_value);
                                
-                               // Sigurd: START as categories
                                $cats   = CreateObject('phpgwapi.categories', 
-1, 'controller', '.control');
                                $cats->supress_info     = true;
                                
                                $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','globals' => true,'use_acl' 
=> $this->_category_acl));
                                                                
-                               $control_areas_array2 = array();
+                               $control_areas_array = array();
                                foreach($control_areas['cat_list'] as $cat_list)
                                {
-                                       $control_areas_array2[] = array
+                                       $control_areas_array[] = array
                                        (
                                                'id'    => $cat_list['cat_id'],
                                                'name'  => $cat_list['name'],
                                        );              
                                }
-                               // END as categories
-                               
-                               
-                               $tabs = array( array(
-                                                       'label' => 
lang('View_locations_for_control'),
-                                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol_location.index'))
-                               
-                                               ), array(
-                                                       'label' => 
lang('Add_locations_for_control')
-                                               ));
+
+/*
+                               $control_info = 
execMethod('controller.socontrol.get_single', $control_id);
+                               if($control_info)
+                               {
+                                       $control_array = array
+                                       (
+                                               'id' => $control_id,
+                                               'title' => 
$control_info->get_title()
+                                       );
+                               }
+*/
+                               $tabs = array
+                               ( 
+                                       array
+                                       (
+                                               'label' => 
lang('View_locations_for_control'),
+                                               'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol_location.index'))
+                                       ),
+                                       array
+                                       (
+                                               'label' => 
lang('Add_locations_for_control')
+                                       )
+                               );
                                                
                                $data = array(
                                        'tabs'                                  
        => $GLOBALS['phpgw']->common->create_tabs($tabs, 1),
                                        'view'                                  
        => "register_control_to_location",
-                                       'control_filters'                       
=> array(
-                                               'control_areas_array2'  => 
$control_areas_array2,
-                                               'control_array'                 
        => $control_array
-                                       ),
+                                       'control_id'                            
=> $control_id,
+                                       'control_areas_array'           => 
$control_areas_array,
                                        'filter_form'                           
=> array(
                                                'building_types'                
        => $building_types,
                                                'category_types'                
        => $category_types,
@@ -298,9 +320,13 @@
                                                'part_of_town_list'             
=> $part_of_town_list
                                        ),
                                        'datatable' => array(
-                                               'source' => 
self::link(array('menuaction' => 'controller.uicontrol_location.index', 
'phpgw_return_as' => 'json', 'view_type' => 'register_control')),
+                                               'source' => 
self::link(array('menuaction' => 'controller.uicontrol_location.index', 
'phpgw_return_as' => 'json', 'view_type' => 
'register_control','control_id_init'    => $control_id)),
                                                'field' => array(
                                                        array(
+                                                               'key' => 
'location_registered',
+                                                               'hidden' => true
+                                                       ),
+                                                       array(
                                                                'key' => 
'location_code',
                                                                'label' => 
lang('Property'),
                                                                'sortable'      
=> true,
@@ -322,10 +348,15 @@
                                                                'sortable'      
=> false
                                                        ),
                                                        array(
+                                                               'key' => 
'control_name',
+                                                               'label' => 
lang('control'),
+                                                               'sortable'      
=> false
+                                                       ),
+                                                       array(
                                                                        'key' 
=> 'checked',
                                                                        'label' 
=> 'Velg',
                                                                        
'sortable' => false,
-                                                                       
'formatter' => 'YAHOO.widget.DataTable.formatCheckbox',
+                                                                       
'formatter' => 'formatterCheckLocation',
                                                                        
'className' => 'mychecks'
                                                        ),
                                                        array(
@@ -351,11 +382,14 @@
                                
                                self::add_javascript('controller', 
'controller', 'jquery.js');
                                self::add_javascript('controller', 
'controller', 'ajax.js');
+                               self::add_javascript('controller', 'yahoo', 
'register_control_to_location.js');
        
                                
self::render_template_xsl(array('control_location/control_location_tabs', 
'control_location/register_control_to_location', 'common'), $data);
                        }               
                }
                
+
+
                // Returns locations for a control
                public function get_locations_for_control()
                {
@@ -382,9 +416,27 @@
                        return $this->yui_results($results);
                }
                
-               public function query(){
-                       $type_id = phpgw::get_var('type_id');
-                       //var_dump($type_id);
+               public function query()
+               {
+                       $type_id = phpgw::get_var('type_id', 'int');
+                       $control_id = phpgw::get_var('control_id', 'int');
+                       $control_id_init = phpgw::get_var('control_id_init', 
'int');
+                       $control_area_id = phpgw::get_var('control_area_id', 
'int');
+
+                       $control_id = $control_id ? $control_id : 
$control_id_init;
+                       
+                       if($control_area_id && 
!execMethod('controller.socontrol.get_controls_by_control_area',$control_area_id))
+                       {
+                               $control_id = 0;
+                       }
+
+                       $control_info = 
execMethod('controller.socontrol.get_single', $control_id);
+                       $control_name = '';
+                       if($control_info)
+                       {
+                               $control_name = $control_info->get_title();
+                       }
+
                        $view_type = phpgw::get_var('view_type');
                        $return_results = phpgw::get_var('results', 'int', 
'REQUEST', 0);
                        
@@ -397,15 +449,15 @@
                        
                        $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));
-//_debug_array($location_list);
-                       $rows_total = $this->bo->read(array('type_id' => 
$type_id, 'allrows' => true));
-                       
-                       foreach($location_list as $location)
+
+                       foreach($location_list as &$location)
                        {
+                               $location['control_name'] = $control_name;
+                               $location['location_registered'] = 
!!$this->so_control->get_control_location($control_id, 
$location['location_code']);
                                $results['results'][]= $location;       
                        }
                        
-                       $results['total_records'] = count($rows_total);
+                       $results['total_records'] = $this->bo->total_records;
                        $results['start'] = $this->start;
                        $results['sort'] = 'location_code';
                        $results['dir'] = "ASC";
@@ -482,4 +534,350 @@
 
                        return json_encode( $part_of_town_list );
                }
+
+
+               /*
+
+                * Return parts of town based on chosen district
+                */
+               public function get_category_by_entity()
+               {
+                       $entity_id              = phpgw::get_var('entity_id');
+                       $entity                 = 
CreateObject('property.soadmin_entity');
+
+                       $category_list = 
$entity->read_category(array('allrows'=>true,'entity_id'=>$entity_id));
+
+/*                     $default_value = array 
('id'=>'','name'=>lang('select'));
+                       array_unshift($category_list,$default_value);
+*/
+                       return $category_list;
+               }
+
+               function register_control_to_component()
+               {
+                   
self::set_active_menu('controller::control::component_for_check_list');
+                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
+                       $receipt = array();
+
+                       if(phpgw::get_var('phpgw_return_as') == 'json')
+                       {
+                               return $this->query2();
+                       }
+
+                       $msgbox_data = array();
+                       if( phpgw::get_var('phpgw_return_as') != 'json' && 
$receipt = phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))
+                       {
+                               phpgwapi_cache::session_clear('phpgwapi', 
'phpgw_messages');
+                               $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox_data($receipt);
+                               $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox($msgbox_data);
+                       }
+
+                       $myColumnDefs = array();
+                       $datavalues = array();
+                       $myButtons      = array();
+
+                       $datavalues[] = array
+                       (
+                               'name'                          => "0",
+                               'values'                        => 
json_encode(array()),
+                               'total_records'         => 0,
+                               'permission'            => "''",
+                               'is_paginator'          => 1,
+                               'edit_action'           => "''",
+                               'footer'                        => 0
+                       );
+
+                       $myColumnDefs[0] = array
+                       (
+                               'name'          => "0",
+                               'values'        =>      json_encode(array())
+                       );      
+
+                       $GLOBALS['phpgw']->translation->add_app('property');
+                       $entity                 = 
CreateObject('property.soadmin_entity');
+                       $entity_list    = $entity->read(array('allrows' => 
true));
+
+                       $district_list  = 
$this->bocommon->select_district_list('filter',$this->district_id);
+
+                       $part_of_town_list = 
execMethod('property.bogeneric.get_list', array('type'=>'part_of_town', 
'selected' => $part_of_town_id ));
+                       $location_type_list = 
execMethod('property.soadmin_location.select_location_type');
+
+                       array_unshift($entity_list ,array 
('id'=>'','name'=>lang('select')));
+                       array_unshift($district_list ,array 
('id'=>'','name'=>lang('select')));
+                       array_unshift($part_of_town_list ,array 
('id'=>'','name'=>lang('select')));
+                       array_unshift($location_type_list ,array 
('id'=>'','name'=>lang('select')));
+
+                       $cats   = CreateObject('phpgwapi.categories', -1, 
'controller', '.control');
+                       $cats->supress_info     = true;
+
+                       $control_area = 
$cats->formatted_xslt_list(array('format'=>'filter','globals' => true,'use_acl' 
=> $this->_category_acl));
+
+                                                               
+                       $control_area_list = array();
+                       foreach($control_area['cat_list'] as $cat_list)
+                       {
+                               $control_area_list[] = array
+                               (
+                                       'id'    => $cat_list['cat_id'],
+                                       'name'  => $cat_list['name'],
+                               );              
+                       }
+
+                       array_unshift ($control_area_list ,array 
('id'=>'','name'=>lang('select')));
+
+                       $tabs = array
+                       ( 
+/*                             array
+                               (
+                                       'label' => 
lang('View_locations_for_control'),
+                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol_location.index'))
+                               ),
+                               array
+                               (
+                                       'label' => 
lang('Add_locations_for_control'),
+                                       'link'  => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicontrol_location.register_control_to_location'))
+                               ),*/
+                               array
+                               (
+                                       'label' => lang('add components for 
control')
+                               )
+                       );
+                                       
+                       $data = array
+                       (
+                               'tabs'                                          
        => $GLOBALS['phpgw']->common->create_tabs($tabs, 2),
+                               'td_count'                                      
        => '""',
+               //              'property_js'                                   
=> 
json_encode($GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property2.js"),
+                               'datatable'                                     
        => $datavalues,
+                               'myColumnDefs'                                  
=> $myColumnDefs,
+                               'myButtons'                                     
        => $myButtons,
+
+                               'msgbox_data'                                   
=> $msgbox_data,
+                               'control_area_list'             => 
array('options' => $control_area_list),
+                               'filter_form'                                   
=> array
+                                                                               
                        (
+                                                                               
                                'control_area_list'             => 
array('options' => $control_area_list),
+                                                                               
                                'entity_list'                   => 
array('options' => $entity_list),
+                                                                               
                                'district_list'                 => 
array('options' => $district_list),
+                                                                               
                                'part_of_town_list'             => 
array('options' => $part_of_town_list),
+                                                                               
                                'location_type_list'    => array('options' => 
$location_type_list),
+                                                                               
                        ),
+                               'update_action'                                 
=> self::link(array('menuaction' => 
'controller.uicontrol_location.edit_component'))
+                       );
+
+
+
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+                       $theme = 'ui-lightness';
+                       
$GLOBALS['phpgw']->css->add_external_file("phpgwapi/js/jquery/development-bundle/themes/{$theme}/jquery.ui.autocomplete.css");
+
+                       phpgwapi_yui::load_widget('dragdrop');
+                       phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('connection');
+                       phpgwapi_yui::load_widget('loader');
+                       phpgwapi_yui::load_widget('tabview');
+                       phpgwapi_yui::load_widget('paginator');
+                       phpgwapi_yui::load_widget('animation');
+//                     phpgwapi_yui::load_widget('autocomplete');
+
+                       phpgwapi_jquery::load_widget('core');
+                       phpgwapi_jquery::load_widget('autocomplete');
+
+                       self::add_javascript('controller', 'controller', 
'ajax_control_to_component.js');
+       //              self::add_javascript('controller', 'yahoo', 
'register_control_to_component.js');
+                       self::add_javascript('controller', 'yahoo', 
'register_control_to_component2.js');
+
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('control_location/register_control_to_component'));
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('data' => $data));
+               }
+       
+
+               public function get_location_type_category()
+               {
+                       $location_type                  = 
phpgw::get_var('location_type', 'int');
+
+                       $values  = $this->bocommon->select_category_list(array
+                                       (
+                                               'format'=>'filter',
+                                       //      'selected' => $this->cat_id,
+                                               'type' =>'location',
+                                               'type_id' =>$location_type,
+                                               'order'=>'descr'
+                                       )
+                               );
+
+                       return $values;
+               }
+
+
+               public function get_entity_table_def()
+               {
+                       $entity_id                      = 
phpgw::get_var('entity_id', 'int');
+                       $cat_id                         = 
phpgw::get_var('cat_id', 'int');
+                       $boentity       = 
CreateObject('property.boentity',false, 'entity');
+                       $boentity->read(array('dry_run' => true));
+                       $uicols = $boentity->uicols;
+                       $columndef = array();
+
+                       $columndef[] = array
+                       (
+                               'key'           => 'select',
+                               'label'         => lang('select'),
+                               'sortable'      => false,
+                               'formatter'     => false,
+                               'hidden'        => false,
+                               'formatter' => '',
+                               'className' => ''
+                       );
+
+                       $columndef[] = array
+                       (
+                               'key'           => 'delete',
+                               'label'         => lang('delete'),
+                               'sortable'      => false,
+                               'formatter'     => false,
+                               'hidden'        => false,
+                               'formatter' => '',
+                               'className' => ''
+                       );
+
+                       $count_fields = 16;//count($uicols['name']);
+
+                       for ($i=0;$i<$count_fields;$i++)
+                       {
+                               if( $uicols['name'][$i])
+                               {
+                                       $columndef[] = array
+                                       (
+                                               'key'           => 
$uicols['name'][$i],
+                                               'label'         => 
$uicols['descr'][$i],
+                                               'sortable'      => 
$uicols['sortable'][$i],
+                                               'formatter'     => 
$uicols['formatter'][$i],
+                                               'hidden'        => 
$uicols['input_type'][$i] == 'hidden' ? true : false ,               
+                                               'className'     => 
$uicols['classname'][$i],
+                                       );
+                               }
+                       }
+
+//_debug_array($columndef);
+                       return $columndef;
+               }
+
+
+               public function get_locations()
+               {
+                       $location_code = phpgw::get_var('location_code');
+                       $child_level = phpgw::get_var('child_level', 'int', 
'REQUEST', 1);
+                       $part_of_town_id = phpgw::get_var('part_of_town_id', 
'int');
+
+                       $criteria = array
+                       (
+                               'location_code'         => $location_code,
+                               'child_level'           => $child_level,
+                               'field_name'            => 
"loc{$child_level}_name",
+                               'part_of_town_id'       => $part_of_town_id
+                       );
+       
+                       $locations = 
execMethod('property.solocation.get_children',$criteria);
+                       return $locations;
+               }
+
+
+
+               public function query2()
+               {
+                       $entity_id                      = 
phpgw::get_var('entity_id', 'int');
+                       $cat_id                         = 
phpgw::get_var('cat_id', 'int');
+                       $district_id            = phpgw::get_var('district_id', 
'int');
+                       $part_of_town_id        = 
phpgw::get_var('part_of_town_id', 'int');
+                       $control_id                     = 
phpgw::get_var('control_id', 'int');
+                       $results                        = 
phpgw::get_var('results', 'int');
+                       $control_registered     = 
phpgw::get_var('control_registered', 'bool');
+
+                       if(!$entity_id && !$cat_id)
+                       {
+                               $values = array();
+                       }
+                       else
+                       {
+                               $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$entity_id}.{$cat_id}");
+                               $boentity       = 
CreateObject('property.boentity',false, 'entity');
+                               $boentity->results = $results;
+                               $values = 
$boentity->read(array('control_registered' => $control_registered, 'control_id' 
=> $control_id));
+                       }               
+
+                       foreach($values as &$entry)
+                       {
+                               $checked = '';
+                               
if($this->so_control->check_control_component($control_id,$location_id,$entry['id']))
+                               {
+                                       $checked =  'checked = "checked" 
disabled = "disabled"';
+                                       $entry['delete'] = "<input class 
=\"mychecks_delete\" type =\"checkbox\" name=\"values[delete][]\" 
value=\"{$control_id}_{$location_id}_{$entry['id']}\">";
+                               }
+                               $entry['select'] = "<input class 
=\"mychecks_add\" type =\"checkbox\" $checked 
name=\"values[register_component][]\" 
value=\"{$control_id}_{$location_id}_{$entry['id']}\">";
+                       }
+
+                       
+                       $results = $results ? $results : 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+                       $return_data['recordsReturned'] = count($values);
+                       $return_data['totalRecords'] = $boentity->total_records;
+                       $return_data['startIndex'] = $this->start;
+                       $return_data['sort'] = 'location_code';
+                       $return_data['dir'] = "ASC";
+                       $return_data['pageSize'] = $results;
+                       $return_data['activePage'] = floor($this->start / 
$results) + 1;
+                       $return_data['records'] = $values;
+
+                       return $return_data;
+               }
+
+               public function edit_component()
+               {
+                       if($values = phpgw::get_var('values'))
+                       {
+                               if(!$GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_EDIT, 'property'))
+                               {
+                                       $receipt['error'][]=true;
+                                       phpgwapi_cache::message_set(lang('you 
are not approved for this task'), 'error');
+                               }
+                               if(!$receipt['error'])
+                               {
+
+                                       
if($this->so_control->register_control_to_component($values))
+                                       {
+                                               $result =  array
+                                               (
+                                                       'status'        => 
'updated'
+                                               );
+                                       }
+                                       else
+                                       {
+                                               $result =  array
+                                               (
+                                                       'status'        => 
'error'
+                                               );
+                                       }
+                               }
+                       }
+
+                       if(phpgw::get_var('phpgw_return_as') == 'json')
+                       {
+                               if( $receipt = 
phpgwapi_cache::session_get('phpgwapi', 'phpgw_messages'))
+                               {
+                                       
phpgwapi_cache::session_clear('phpgwapi', 'phpgw_messages');
+                                       $result['receipt'] = $receipt;
+                               }
+                               else
+                               {
+                                       $result['receipt'] = array();
+                               }
+                               return $result;
+                       }
+                       else
+                       {
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 
'controller.uicontrol_location.register_control_to_component'));
+                       }
+               }
        }

Modified: branches/stavangerkommune/controller/inc/class.uiprocedure.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/class.uiprocedure.inc.php  
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/class.uiprocedure.inc.php  
2012-06-18 12:44:16 UTC (rev 9609)
@@ -118,13 +118,7 @@
                                                                'type' => 
'submit',
                                                                'name' => 
'search',
                                                                'value' => 
lang('Search')
-                                                       ),
-                                                       array(
-                                                               'type' => 
'link',
-                                                               'value' => 
lang('t_new_procedure'),
-                                                               'href' => 
self::link(array('menuaction' => 'controller.uiprocedure.add')),
-                                                               'class' => 
'new_item'
-                                                       ),
+                                                       )
                                                ),
                                        ),
                                ),
@@ -166,7 +160,7 @@
                        );
 //_debug_array($data);
 
-                       self::render_template_xsl('datatable', $data);
+                       self::render_template_xsl(array( 
'procedure/procedures_datatable', 'datatable' ), $data);
                }
 
                public function edit()

Modified: 
branches/stavangerkommune/controller/inc/component/class.year_calendar.inc.php
===================================================================
--- 
branches/stavangerkommune/controller/inc/component/class.year_calendar.inc.php  
    2012-06-18 09:08:08 UTC (rev 9608)
+++ 
branches/stavangerkommune/controller/inc/component/class.year_calendar.inc.php  
    2012-06-18 12:44:16 UTC (rev 9609)
@@ -6,46 +6,43 @@
        
 
 class year_calendar {
-       
-       private $period_start_date_ts;
-    private $period_end_date_ts;
+  private $period_start_date_ts;
+  private $period_end_date_ts;
        private $year;
        private $control;
        private $calendar_array = array();
        
-       public function __construct($control, $year){
-        $this->year = $year;
-        $this->control = $control;
+  public function __construct($control, $year){
+    $this->year = $year;
+    $this->control = $control;
         
-        $this->period_start_date_ts = strtotime("01/01/$year");
-               $to_year = $year + 1;
-               $this->period_end_date_ts = strtotime("01/01/$to_year");
+    $this->period_start_date_ts = strtotime("01/01/$year");
+    $to_year = $year + 1;
+    $this->period_end_date_ts = strtotime("01/01/$to_year");
         
-        $this->init_calendar();
-       }
+    $this->init_calendar();
+  }
                
        function init_calendar(){
-
-               for($i = 1;$i <= 12;$i++){
-                       $this->calendar_array[$i] = null;
-               }
+    for($i = 1;$i <= 12;$i++){
+                 $this->calendar_array[$i] = null;
+    }
                
-               $date_generator = new 
date_generator($this->control->get_start_date(), 
$this->control->get_end_date(), $this->period_start_date_ts, 
$this->period_end_date_ts, $this->control->get_repeat_type(), 
$this->control->get_repeat_interval());
-               $dates_array = $date_generator->get_dates();
+    $date_generator = new date_generator($this->control->get_start_date(), 
$this->control->get_end_date(), $this->period_start_date_ts, 
$this->period_end_date_ts, $this->control->get_repeat_type(), 
$this->control->get_repeat_interval());
+    $dates_array = $date_generator->get_dates();
                
-               // Inserts dates 
-               foreach($dates_array as $date){
+    // Inserts dates 
+    foreach($dates_array as $date){
+      $todays_date = mktime(0,0,0,date("m"), date("d"), date("Y"));
                        
-                       $todays_date = mktime(0,0,0,date("m"), date("d"), 
date("Y"));
+      if($date < $todays_date){
+        $status = "CONTROL_NOT_DONE";
+      }else{
+        $status = "CONTROL_REGISTERED";
+      }
                        
-                       if($date < $todays_date){
-                               $status = "CONTROL_NOT_DONE";
-                       }else{
-                               $status = "CONTROL_REGISTERED";
-                       }
-                       
-                       $this->calendar_array[ date("n", $date) ]["status"]  = 
$status;
-                       $this->calendar_array[ date("n", $date) ]["info"]  = 
array("date" => $date, "control_id" => $this->control->get_id());
+      $this->calendar_array[ date("n", $date) ]["status"]  = $status;
+      $this->calendar_array[ date("n", $date) ]["info"]  = array("date" => 
$date, "control_id" => $this->control->get_id());
                }
        }
        
@@ -63,7 +60,7 @@
                return $this->calendar_array;
        }
        
-       public function build_agg_calendar( $agg_open_cases_pr_month_array ){
+       public function build_agg_month_calendar( 
$agg_open_cases_pr_month_array ){
                
                foreach($agg_open_cases_pr_month_array as 
$status_agg_month_info)
                {

Modified: branches/stavangerkommune/controller/inc/hook_home.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/hook_home.inc.php  2012-06-18 
09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/hook_home.inc.php  2012-06-18 
12:44:16 UTC (rev 9609)
@@ -67,14 +67,15 @@
 
        $location_finder = new location_finder();
        $my_locations = $location_finder->get_responsibilities( $criteria );
-       
+
        $repeat_type = null;
        $controls_for_location_array = array();
        foreach($my_locations as $location)
        {
-               $controls_for_location_array[] = 
array($location["location_code"], 
$so_control->get_controls_by_location($location["location_code"], 
$from_date_ts, $to_date_ts, $repeat_type ));
+           $controls_for_location_array[] = array($location["location_code"], 
$so_control->get_controls_for_location($location["location_code"], 
$location["role_id"], $from_date_ts, $to_date_ts, $repeat_type ));
        }
        
+
        $controls_array = array();
        $control_dates = array();
        foreach($controls_for_location_array as $control_arr){
@@ -82,11 +83,89 @@
                $controls_for_loc_array = $control_arr[1];
                foreach($controls_for_loc_array as $control)
                {
-                       $date_generator = new 
date_generator($control->get_start_date(), $control->get_end_date(), 
$from_date_ts, $to_date_ts, $control->get_repeat_type(), 
$control->get_repeat_interval());
+                       $date_generator = new 
date_generator($control["start_date"], $control["end_date"], $from_date_ts, 
$to_date_ts, $control["repeat_type"], $control["repeat_interval"]);
                        $controls_array[] = array($current_location, $control, 
$date_generator->get_dates());
                }
        }
        
+       $portalbox0 = CreateObject('phpgwapi.listbox', array
+       (
+               'title'         => "Mine glemte kontroller",
+               'primary'       => $GLOBALS['phpgw_info']['theme']['navbar_bg'],
+               'secondary'     => $GLOBALS['phpgw_info']['theme']['navbar_bg'],
+               'tertiary'      => $GLOBALS['phpgw_info']['theme']['navbar_bg'],
+               'width' => '100%',
+               'outerborderwidth'      => '0',
+               'header_background_image'       => 
$GLOBALS['phpgw']->common->image('phpgwapi','bg_filler', '.png', False)
+       ));
+
+       $app_id = $GLOBALS['phpgw']->applications->name2id('controller');
+       if( !isset($GLOBALS['portal_order']) ||!in_array($app_id, 
$GLOBALS['portal_order']) )
+       {
+               $GLOBALS['portal_order'][] = $app_id;
+       }
+       $var = array
+       (
+               'up'    => array('url'  => '/set_box.php', 'app'        => 
$app_id),
+               'down'  => array('url'  => '/set_box.php', 'app'        => 
$app_id),
+               'close' => array('url'  => '/set_box.php', 'app'        => 
$app_id),
+               'question'      => array('url'  => '/set_box.php', 'app'        
=> $app_id),
+               'edit'  => array('url'  => '/set_box.php', 'app'        => 
$app_id)
+       );
+
+       foreach ( $var as $key => $value )
+       {
+               //                      $portalbox->set_controls($key,$value);
+       }
+
+       $category_name = array(); // caching
+       
+       $cats   = CreateObject('phpgwapi.categories', -1, 'controller', 
'.control');
+       $cats->supress_info     = true;
+       $control_areas = 
$cats->formatted_xslt_list(array('format'=>'filter','selected' => '','globals' 
=> true,'use_acl' => $this->_category_acl));
+
+       $portalbox0->data = array();
+       $portalbox0_data = array();
+       foreach ($controls_array as $control_instance)
+       {
+               $curr_location = $control_instance[0];
+               $current_control = $control_instance[1];
+               $check_lists = 
$so->get_open_check_lists_for_control($current_control["id"], $curr_location, 
$from_date_ts);
+               $location_array = execMethod('property.bolocation.read_single', 
array('location_code' => $curr_location));
+               $location_name = $location_array["loc1_name"];
+               foreach($control_areas['cat_list'] as $area)
+               {
+                       if($area['cat_id'] == 
$current_control["control_area_id"])
+                       {
+                               $control_area_name = $area['name'];
+                       }
+               }
+               foreach($check_lists as $check_list)
+               {
+                       $next_date = "Frist: " . date('d/m/Y', 
$check_list->get_deadline());
+                       $portalbox0_data[] = array
+                       ($check_list->get_deadline(), array
+                       (
+                               'text' => "{$location_name} - 
{$control_area_name} - {$current_control["title"]} :: {$next_date}",
+                               'link' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicheck_list.edit_check_list', 
'check_list_id' => $check_list->get_id()))
+                       ));
+               }
+       }
+       //sort data by planned date for check list
+       sort($portalbox0_data);
+       //$limit = 5;
+       $tmp = 0;
+       foreach($portalbox0_data as $check_list_dates)
+       {
+               if($tmp < $limit_no_of_planned)
+               {
+                       $portalbox0->data[] = $check_list_dates[1];
+               }
+               $tmp++;
+       }
+
+       echo "\n".'<!-- BEGIN checklist info -->'."\n<div 
class='controller_checklist' style='padding-left: 10px; background-color: 
red;'>".$portalbox0->draw()."</div>\n".'<!-- END checklist info -->'."\n";
+       
        $portalbox1 = CreateObject('phpgwapi.listbox', array
        (
                'title'         => "Mine planlagte kontroller",
@@ -129,13 +208,12 @@
        {
                $curr_location = $control_instance[0];
                $current_control = $control_instance[1];
-               $check_lists = 
$so->get_planned_check_lists_for_control($current_control->get_id(), 
$curr_location);
-               //_debug_array($check_lists);
+               $check_lists = 
$so->get_planned_check_lists_for_control($current_control["id"], 
$curr_location);
                $location_array = execMethod('property.bolocation.read_single', 
array('location_code' => $curr_location));
                $location_name = $location_array["loc1_name"];
                foreach($control_areas['cat_list'] as $area)
                {
-                       if($area['cat_id'] == 
$current_control->get_control_area_id())
+                       if($area['cat_id'] == 
$current_control["control_area_id"])
                        {
                                $control_area_name = $area['name'];
                        }
@@ -146,7 +224,7 @@
                        $portalbox1_data[] = array
                        ($check_list->get_planned_date(), array
                        (
-                               'text' => "{$location_name} - 
{$control_area_name} - {$current_control->get_title()} :: {$next_date}",
+                               'text' => "{$location_name} - 
{$control_area_name} - {$current_control["title"]} :: {$next_date}",
                                'link' => $GLOBALS['phpgw']->link('/index.php', 
array('menuaction' => 'controller.uicheck_list.edit_check_list', 
'check_list_id' => $check_list->get_id()))
                        ));
                }
@@ -203,22 +281,19 @@
        {
                $curr_location = $control_instance[0];
                $current_control = $control_instance[1];
-               $check_lists = 
$so->get_planned_check_lists_for_control($current_control->get_id(), 
$curr_location);
+               //unset($check_lists);
+               $check_lists = 
$so->get_unplanned_check_lists_for_control($current_control["id"], 
$curr_location);
                //$control_location = 
$so_control->getLocationCodeFromControl($current_control->get_id());
                $location_array = execMethod('property.bolocation.read_single', 
array('location_code' => $curr_location));
                $location_name = $location_array["loc1_name"];
                foreach($control_areas['cat_list'] as $area)
                {
-                       if($area['cat_id'] == 
$current_control->get_control_area_id())
+                       if($area['cat_id'] == 
$current_control["control_area_id"])
                        {
                                $control_area_name = $area['name'];
                        }
                }
-               $planned_lists = array();
-               foreach($check_lists as $check_list)
-               {
-                       $planned_lists = $check_list->get_deadline();
-               }
+
                $current_dates = $control_instance[2];
                
                foreach($current_dates as $current_date)
@@ -227,16 +302,26 @@
                        {
                                foreach($check_lists as $check_list)
                                {
-                                       if($current_date != 
$check_list->get_deadline())
+                                       if($current_date > 
$check_list->get_deadline() && $current_date != $check_list->get_deadline())
                                        {
                                                $next_date = "Fristdato: " . 
date('d/m/Y', $current_date);
                                                $portalbox2_data[] = array
                                                ($current_date, array
                                                (
-                                                       'text' => 
"{$location_name} - {$control_area_name} - {$current_control->get_title()} :: 
{$next_date}",
-                                                       'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.add_check_list', 'date' => $current_date, 'control_id' 
=> $current_control->get_id(), 'location_code' => $curr_location))
+                                                       'text' => 
"{$location_name} - {$control_area_name} - {$current_control["title"]} :: 
{$next_date}",
+                                                       'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.add_check_list', 'date' => $current_date, 'control_id' 
=> $current_control["id"], 'location_code' => $curr_location))
                                                ));
                                        }
+                                       else
+                                       {
+                                               $next_date = "Fristdato: " . 
date('d/m/Y', $check_list->get_deadline());
+                                               $portalbox2_data[] = array
+                                               ($check_list->get_deadline(), 
array
+                                               (
+                                                       'text' => 
"{$location_name} - {$control_area_name} - {$current_control["title"]} :: 
{$next_date}",
+                                                       'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.edit_check_list', 'check_list_id' => 
$check_list->get_id()))
+                                               ));                             
            
+                                       }
                                }
                        }
                        else
@@ -245,8 +330,8 @@
                                $portalbox2_data[] = array
                                ($current_date, array
                                (
-                                       'text' => "{$location_name} - 
{$control_area_name} - {$current_control->get_title()} :: {$next_date}",
-                                       'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.add_check_list', 'date' => $current_date, 'control_id' 
=> $current_control->get_id(), 'location_code' => $curr_location))
+                                       'text' => "{$location_name} - 
{$control_area_name} - {$current_control["title"]} :: {$next_date}",
+                                       'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.add_check_list', 'date' => $current_date, 'control_id' 
=> $current_control["id"], 'location_code' => $curr_location))
                                ));                                     
                        }
                }
@@ -254,6 +339,7 @@
        //sort data by due date for check list
        sort($portalbox2_data);
        //$limit = 20;
+       //$limit_no_of_assigned = 50;
        $tmp = 0;
        foreach($portalbox2_data as $check_list_dates)
        {

Copied: branches/stavangerkommune/controller/inc/model/class.component.inc.php 
(from rev 9608, trunk/controller/inc/model/class.component.inc.php)
===================================================================
--- branches/stavangerkommune/controller/inc/model/class.component.inc.php      
                        (rev 0)
+++ branches/stavangerkommune/controller/inc/model/class.component.inc.php      
2012-06-18 12:44:16 UTC (rev 9609)
@@ -0,0 +1,125 @@
+<?php
+       /**
+       * phpGroupWare - controller: a part of a Facilities Management System.
+       *
+       * @author Erink Holm-Larsen <address@hidden>
+       * @author Torstein Vadla <address@hidden>
+       * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
+       * @package property
+       * @subpackage controller
+       * @version $Id: class.control.inc.php 9548 2012-06-11 12:40:52Z vator $
+       */
+
+       include_class('controller', 'model', 'inc/model/');
+       include_class('controller', 'date_helper', 'inc/helper/');
+
+       class controller_control extends controller_model
+       {
+               public static $so;
+               
+               protected $type;
+               protected $id;
+               protected $guid;
+               protected $xml;
+               protected $location_code;
+               protected $loc_1;
+               protected $address;
+               
+               // Objects
+               protected $controls_list_array = array();
+               
+               /**
+                * Constructor.  Takes an optional ID.  If a contract is 
created from outside
+                * the database the ID should be empty so the database can add 
one according to its logic.
+                * 
+                * @param int $id the id of this composite
+                */
+               
+               public function set_type($type)
+               {
+                       $this->type = $type;
+               }
+               
+               public function get_type() { return $this->type; }
+                       
+               public function set_id($id)
+               {
+                       $this->id = $id;
+               }
+               
+               public function get_id() { return $this->id; }
+               
+               public function set_guid($guid)
+               {
+                       $this->guid = $guid;
+               }
+               
+               public function get_guid() { return $this->guid; }
+               
+               
+               public function set_xml($xml)
+               {
+                       $this->xml = $xml;
+               }
+               
+               public function get_xml() { return $this->xml; }
+               
+               public function set_location_code($location_code)
+               {
+                       $this->location_code = $location_code;
+               }
+               
+               public function get_location_code() { return 
$this->location_code; }
+               
+               public function set_loc_1($loc_1)
+               {
+                       $this->loc_1 = $loc_1;
+               }
+               
+               public function get_loc_1() { return $this->loc_1; }
+               
+               public function set_address($address)
+               {
+                       $this->address = $address;
+               }
+               
+               public function get_address() { return $this->address; }
+               
+               public function set_controls_list_array($controls_list_array)
+               {
+                       $this->controls_list_array = $controls_list_array;
+               }
+               
+               public function get_controls_list_array() { return 
$this->controls_list_array; }
+               
+               public function serialize()
+               {
+                       return array(
+                               'type' => $this->get_type(),
+                               'id' => $this->get_id(),
+                               'guid' => $this->get_guid(),
+                               'xml' => $this->get_xml(),
+                               'location_code' => $this->get_location_code(),
+                               'loc_1' => $this->get_loc_1(),
+                               'address' => $this->get_address()
+                       );
+               }
+       }

Modified: branches/stavangerkommune/controller/inc/model/class.control.inc.php
===================================================================
--- branches/stavangerkommune/controller/inc/model/class.control.inc.php        
2012-06-18 09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/inc/model/class.control.inc.php        
2012-06-18 12:44:16 UTC (rev 9609)
@@ -55,9 +55,6 @@
                protected $costresponsibility_id;
                protected $responsibility_id;
                protected $responsibility_name;
-               protected $component_id;
-               protected $component_type_id;
-               //protected $location_code;
                protected $control_area_id;
                protected $control_area_name;
 
@@ -199,27 +196,6 @@
                
                public function get_responsibility_name() { return 
$this->responsibility_name; }
                
-               public function set_component_id($component_id)
-               {
-                       $this->component_id = $component_id;
-               }
-               
-               public function get_component_id() { return 
$this->component_id; }
-               
-               public function set_component_type_id($component_type_id)
-               {
-                       $this->component_type_id = $component_type_id;
-               }
-               
-               public function get_component_type_id() { return 
$this->component_type_id; }
-               /*
-               public function set_location_code($location_code)
-               {
-                       $this->location_code = $location_code;
-               }
-               
-               public function get_location_code() { return 
$this->location_code; }
-               */
                public function set_control_area_id($control_area_id)
                {
                        $this->control_area_id = $control_area_id;

Modified: branches/stavangerkommune/controller/js/controller/ajax.js
===================================================================
--- branches/stavangerkommune/controller/js/controller/ajax.js  2012-06-18 
09:08:08 UTC (rev 9608)
+++ branches/stavangerkommune/controller/js/controller/ajax.js  2012-06-18 
12:44:16 UTC (rev 9609)
@@ -1,137 +1,35 @@
 $(document).ready(function(){
 
-       /*      
-       $("#searchLocationName").bind("keyup", function(event) {
-               var thisTextField = $(this);
-           var location_name = String.fromCharCode(event.which);
-           var level = 1;
-           var locationSearchString = $(this).val();
-           
-           var oArgs = 
{menuaction:'property.bolocation.get_locations_by_name'};
-               var baseUrl = phpGWLink('index.php', oArgs, false);

@@ Diff output truncated at 153600 characters. @@



reply via email to

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