fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [14685] booking: allow resources to be member of mult


From: Sigurd Nes
Subject: [Fmsystem-commits] [14685] booking: allow resources to be member of multiple resource-pools
Date: Mon, 01 Feb 2016 10:13:07 +0000

Revision: 14685
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14685
Author:   sigurdne
Date:     2016-02-01 10:13:06 +0000 (Mon, 01 Feb 2016)
Log Message:
-----------
booking: allow resources to be member of multiple resource-pools

Modified Paths:
--------------
    branches/dev-syncromind/activitycalendar/setup/setup.inc.php
    branches/dev-syncromind/activitycalendarfrontend/setup/setup.inc.php
    branches/dev-syncromind/booking/inc/class.boapplication.inc.php
    branches/dev-syncromind/booking/inc/class.boresource.inc.php
    branches/dev-syncromind/booking/inc/class.soapplication.inc.php
    branches/dev-syncromind/booking/inc/class.sobooking.inc.php
    branches/dev-syncromind/booking/inc/class.sobuilding.inc.php
    branches/dev-syncromind/booking/inc/class.socommon.inc.php
    branches/dev-syncromind/booking/inc/class.soevent.inc.php
    branches/dev-syncromind/booking/inc/class.soorganization.inc.php
    branches/dev-syncromind/booking/inc/class.soresource.inc.php
    branches/dev-syncromind/booking/inc/class.uiallocation.inc.php
    branches/dev-syncromind/booking/inc/class.uireports.inc.php
    branches/dev-syncromind/booking/inc/class.uiresource.inc.php
    branches/dev-syncromind/booking/js/booking/resource_new.js
    branches/dev-syncromind/booking/setup/setup.inc.php
    branches/dev-syncromind/booking/setup/tables_current.inc.php
    branches/dev-syncromind/booking/setup/tables_update.inc.php
    branches/dev-syncromind/booking/templates/base/resource.xsl
    branches/dev-syncromind/booking/templates/base/resource_form.xsl
    branches/dev-syncromind/bookingfrontend/inc/class.bosearch.inc.php
    branches/dev-syncromind/bookingfrontend/inc/class.uiresource.inc.php
    branches/dev-syncromind/bookingfrontend/js/bookingfrontend/schedule.js
    branches/dev-syncromind/bookingfrontend/setup/setup.inc.php
    branches/dev-syncromind/bookingfrontend/templates/base/resource.xsl
    branches/dev-syncromind/bookingfrontend/templates/base/resource_schedule.xsl

Modified: branches/dev-syncromind/activitycalendar/setup/setup.inc.php
===================================================================
--- branches/dev-syncromind/activitycalendar/setup/setup.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/activitycalendar/setup/setup.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -30,7 +30,7 @@
 
        $setup_info['activitycalendar']['depends'][] = array(
                'appname' => 'booking',
-               'versions' => 
array('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.2.25','0.2.26')
+               'versions' => 
array('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.2.25','0.2.26','0.2.27')
        );
 
        $setup_info['activitycalendar']['depends'][] = array(

Modified: branches/dev-syncromind/activitycalendarfrontend/setup/setup.inc.php
===================================================================
--- branches/dev-syncromind/activitycalendarfrontend/setup/setup.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/activitycalendarfrontend/setup/setup.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -22,7 +22,7 @@
 
 $setup_info['activitycalendarfrontend']['depends'][] = array(
     'appname' => 'booking',
-       'versions' => 
array('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.2.25','0.2.26')
+       'versions' => 
array('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.2.25','0.2.26','0.2.27')
 );
 
 $setup_info['activitycalendarfrontend']['depends'][] = array(

Modified: branches/dev-syncromind/booking/inc/class.boapplication.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.boapplication.inc.php     
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.boapplication.inc.php     
2016-02-01 10:13:06 UTC (rev 14685)
@@ -221,18 +221,14 @@
                        $applications    = array();
                        $this->db                = & $GLOBALS['phpgw']->db;
 
-#                      $sql = "select distinct ap.id
-#                                      from bb_application ap
-#                                      inner join bb_application_resource ar 
on ar.application_id = ap.id
-#                                      inner join bb_resource re on re.id = 
ar.resource_id
-#                                      inner join bb_building bu on bu.id = 
re.building_id";
-                       $sql     = "select distinct ap.id
-                                       from bb_application ap
-                                       inner join bb_application_resource ar 
on ar.application_id = ap.id
-                                       inner join bb_resource re on re.id = 
ar.resource_id
-                                       inner join bb_building bu on bu.id = 
re.building_id
-                                       inner join bb_permission pe on 
pe.object_id = bu.id and pe.object_type = 'building'
-                                       where pe.subject_id = " . $user_id;
+                       $sql     = "SELECT DISTINCT ap.id
+                                       FROM bb_application ap
+                                       INNER JOIN bb_application_resource ar 
ON ar.application_id = ap.id
+                                       INNER JOIN bb_resource re ON re.id = 
ar.resource_id
+                                       INNER JOIN bb_building_resource br ON 
re.id = br.resource_id
+                                       INNER JOIN bb_building bu ON bu.id = 
br.resource_id
+                                       INNER JOIN bb_permission pe ON 
pe.object_id = bu.id and pe.object_type = 'building'
+                                       WHERE pe.subject_id = " . $user_id;
                        $this->db->query($sql);
                        $result  = $this->db->resultSet;
 
@@ -263,7 +259,10 @@
 
                        if($building_id = phpgw::get_var('filter_building_id', 
'int', 'REQUEST', 0))
                        {
-                               $where_clauses[] = "(%%table%%.id IN (SELECT 
DISTINCT a.id FROM bb_application a, bb_application_resource ar, bb_resource r 
WHERE ar.application_id = a.id AND ar.resource_id = r.id AND r.building_id = " 
. intval($building_id) . "))";
+                               $where_clauses[] = "(%%table%%.id IN ("
+                               . " SELECT DISTINCT a.id"
+                               . " FROM bb_application a, 
bb_application_resource ar, bb_resource r, bb_building_resource br "
+                               . " WHERE ar.application_id = a.id AND 
ar.resource_id = r.id AND br.resource_id =r.id  AND br.building_id = " . 
intval($building_id) . "))";
                        }
 
                        if($status = phpgw::get_var('status') != '')

Modified: branches/dev-syncromind/booking/inc/class.boresource.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.boresource.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.boresource.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -29,12 +29,16 @@
 
                        if(is_array($for_object))
                        {
-                               if(!isset($for_object['building_id']))
+
+                               /**FIXME: Sigurd 30 jan 2016: convert from 
single id to array of ids
+                                *
+                                */
+                               if(!isset($for_object['buildings'][0]))
                                {
                                        throw new 
InvalidArgumentException('Cannot initialize object parent roles unless 
building_id is provided');
                                }
 
-                               $parent_building = 
$this->building_bo->read_single($for_object['building_id']);
+                               $parent_building = 
$this->building_bo->read_single($for_object['buildings'][0]);
                        }
 
                        //Note that a null value for $parent_building is 
acceptable. That only signifies
@@ -115,21 +119,41 @@
                {
                        $resources = $this->read();
 
+                       $building_ids = array();
                        foreach($resources['results'] as &$resource)
                        {
                                $resource['link']                = 
$this->link(array('menuaction' => $menuaction, 'id' => $resource['id']));
                                $resource['type']                = 
lang($resource['type']);
+//                             $resource['full_name']   = 
$resource['building_name'] . ' / ' . $resource['name'];
+                               if(isset($resource['buildings']))
+                               {
+                                       $building_ids = 
array_merge($building_ids, $resource['buildings']);
+                               }
+                       }
+                       unset($resource);
+
+                       $buildings = 
$this->building_bo->get_building_names(array_unique($building_ids));
+
+                       foreach($resources['results'] as &$resource)
+                       {
+                               $_building_names = array();
+                               if(is_array($resource['buildings']))
+                               {
+
+                                       $resource['building_street'] = 
$buildings[$resource['buildings'][0]]['street'];
+                                       $resource['building_city'] = 
$buildings[$resource['buildings'][0]]['zip_code'];
+                                       $resource['building_district'] = 
$buildings[$resource['buildings'][0]]['district'];
+
+                                       foreach($resource['buildings'] as 
$building_id)
+                                       {
+                                               $_building_names[] = 
"{$buildings[$building_id]['name']} ({$buildings[$building_id]['activity']})";
+                                       }
+
+                               }
+                               $resource['building_name'] = implode(', <br/>', 
$_building_names);
+
                                $resource['full_name']   = 
$resource['building_name'] . ' / ' . $resource['name'];
                        }
-//                     $data = array(
-//                              'ResultSet' => array(
-//                                     'totalResultsAvailable' => 
$resources['total_records'], 
-//                                     'startIndex' => $resources['start'], 
-//                                     'sortKey' => $resources['sort'], 
-//                                     'sortDir' => $resources['dir'], 
-//                                     'Result' => $resources['results']
-//                             )
-//                     );
 
                        $data = array(
                                'total_records'  => $resources['total_records'],
@@ -183,4 +207,23 @@
                        }
                        return $resource;
                }
+
+               function add_building($entity, $resource_id, $building_id)
+               {
+                       if($this->authorize_write($entity))
+                       {
+                               return parent::add_building($resource_id, 
$building_id);
+                       }
+                       return false;
+               }
+
+               function remove_building($entity, $resource_id, $building_id)
+               {
+                       if($this->authorize_write($entity))
+                       {
+                               return parent::remove_building($resource_id, 
$building_id);
+                       }
+                       return false;
+               }
+
        }
\ No newline at end of file

Modified: branches/dev-syncromind/booking/inc/class.soapplication.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.soapplication.inc.php     
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.soapplication.inc.php     
2016-02-01 10:13:06 UTC (rev 14685)
@@ -116,7 +116,12 @@
 
                function get_building_info($id)
                {
-                       $this->db->limit_query("SELECT bb_building.id, 
bb_building.name FROM bb_building, bb_resource, bb_application_resource WHERE 
bb_building.id=bb_resource.building_id AND 
bb_resource.id=bb_application_resource.resource_id AND 
bb_application_resource.application_id=" . intval($id), 0, __LINE__, __FILE__, 
1);
+                       $id = (int) $id;
+                       $sql = "SELECT bb_building.id, bb_building.name"
+                       . " FROM bb_building, bb_resource, 
bb_application_resource, bb_building_resource"
+                       . " WHERE bb_building.id= 
bb_building_resource.building_id AND  bb_resource.id = 
bb_building_resource.resource_id AND 
bb_resource.id=bb_application_resource.resource_id AND 
bb_application_resource.application_id=({$id})";
+
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
                        if(!$this->db->next_record())
                        {
                                return False;

Modified: branches/dev-syncromind/booking/inc/class.sobooking.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.sobooking.inc.php 2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.sobooking.inc.php 2016-02-01 
10:13:06 UTC (rev 14685)
@@ -300,7 +300,13 @@
                        $end             = $end->format('Y-m-d H:i');
                        $building_id = intval($building_id);
                        $results         = array();
-                       $this->db->query("SELECT DISTINCT(bb_event.id) AS id 
FROM bb_event JOIN bb_event_resource ON (bb_event.id=event_id AND resource_id 
IN(SELECT id FROM bb_resource WHERE building_id=$building_id)) WHERE 
bb_event.active=1 AND ((bb_event.from_ >= '$start' AND bb_event.from_ < '$end') 
OR (bb_event.to_ > '$start' AND bb_event.to_ <= '$end') OR (bb_event.from_ < 
'$start' AND bb_event.to_ > '$end'))", __LINE__, __FILE__);
+                       $sql = "SELECT DISTINCT(bb_event.id) AS id"
+                       . " FROM bb_event JOIN bb_event_resource ON 
(bb_event.id=event_id AND resource_id"
+                       . " IN(SELECT id FROM bb_resource JOIN 
bb_building_resource ON bb_building_resource.resource_id = bb_resource.id WHERE 
building_id=$building_id))"
+                       . " WHERE bb_event.active=1 AND ((bb_event.from_ >= 
'$start' AND bb_event.from_ < '$end')"
+                       . " OR (bb_event.to_ > '$start' AND bb_event.to_ <= 
'$end')"
+                       . " OR (bb_event.from_ < '$start' AND bb_event.to_ > 
'$end'))";
+                       $this->db->query($sql, __LINE__, __FILE__);
                        while($this->db->next_record())
                        {
                                $results[] = 
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -314,7 +320,17 @@
                        $end             = $end->format('Y-m-d H:i');
                        $resource_id = intval($resource_id);
                        $results         = array();
-                       $this->db->query("SELECT bb_allocation.id AS id FROM 
bb_allocation JOIN bb_allocation_resource ON (allocation_id=id AND 
resource_id=$resource_id) JOIN bb_resource as res ON ( res.id=$resource_id) 
JOIN bb_season ON (bb_allocation.season_id=bb_season.id AND 
bb_allocation.active=1) WHERE bb_season.building_id=res.building_id AND 
bb_season.active=1 AND bb_season.status='PUBLISHED' AND ((bb_allocation.from_ 
>= '$start'AND bb_allocation.from_ < '$end') OR (bb_allocation.to_ > '$start' 
AND bb_allocation.to_ <= '$end') OR (bb_allocation.from_ < '$start' AND 
bb_allocation.to_ > '$end'))", __LINE__, __FILE__);
+                       $sql = "SELECT bb_allocation.id AS id"
+                       . " FROM bb_allocation JOIN bb_allocation_resource ON 
(allocation_id=id AND resource_id=$resource_id)"
+                       . " JOIN bb_resource as res ON ( res.id=$resource_id)"
+                       . " JOIN bb_season ON 
(bb_allocation.season_id=bb_season.id AND bb_allocation.active=1)"
+                       . " JOIN bb_building_resource ON 
bb_building_resource.resource_id = res.id "
+                       . " WHERE 
bb_season.building_id=bb_building_resource.building_id AND bb_season.active=1"
+                       . " AND bb_season.status='PUBLISHED' AND 
((bb_allocation.from_ >= '$start'"
+                       . " AND bb_allocation.from_ < '$end') OR 
(bb_allocation.to_ > '$start'"
+                       . " AND bb_allocation.to_ <= '$end') OR 
(bb_allocation.from_ < '$start' AND bb_allocation.to_ > '$end'))";
+
+                       $this->db->query($sql, __LINE__, __FILE__);
                        while($this->db->next_record())
                        {
                                $results[] = 
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -328,7 +344,18 @@
                        $end             = $end->format('Y-m-d H:i');
                        $resource_id = intval($resource_id);
                        $results         = array();
-                       $this->db->query("SELECT bb_booking.id AS id FROM 
bb_booking JOIN bb_booking_resource ON (booking_id=id AND 
resource_id=$resource_id) JOIN bb_resource as res ON ( res.id=$resource_id) 
JOIN bb_season ON (bb_booking.season_id=bb_season.id AND bb_booking.active=1) 
WHERE bb_season.building_id=res.building_id AND bb_season.active=1 AND 
bb_season.status='PUBLISHED' AND ((bb_booking.from_ >= '$start' AND 
bb_booking.from_ < '$end') OR (bb_booking.to_ > '$start' AND bb_booking.to_ <= 
'$end') OR (bb_booking.from_ < '$start' AND bb_booking.to_ > '$end'))", 
__LINE__, __FILE__);
+                       $sql = "SELECT bb_booking.id AS id"
+                       . " FROM bb_booking JOIN bb_booking_resource ON 
(booking_id=id AND resource_id=$resource_id)"
+                       . " JOIN bb_resource as res ON ( res.id=$resource_id)"
+                       . " JOIN bb_season ON 
(bb_booking.season_id=bb_season.id AND bb_booking.active=1)"
+                       . " JOIN bb_building_resource ON 
bb_building_resource.resource_id = res.id "
+                       . " WHERE 
bb_season.building_id=bb_building_resource.building_id AND bb_season.active=1"
+                       . " AND bb_season.status='PUBLISHED' AND 
((bb_booking.from_ >= '$start'"
+                       . " AND bb_booking.from_ < '$end') OR (bb_booking.to_ > 
'$start'"
+                       . " AND bb_booking.to_ <= '$end') OR (bb_booking.from_ 
< '$start'"
+                       . " AND bb_booking.to_ > '$end'))";
+
+                       $this->db->query($sql, __LINE__, __FILE__);
                        while($this->db->next_record())
                        {
                                $results[] = 
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -342,7 +369,11 @@
                        $end             = $end->format('Y-m-d H:i');
                        $resource_id = intval($resource_id);
                        $results         = array();
-                       $this->db->query("SELECT id FROM bb_event JOIN 
bb_event_resource ON (event_id=id AND resource_id=$resource_id) WHERE active=1 
AND ((from_ >= '$start' AND from_ < '$end') OR (to_ > '$start' AND to_ <= 
'$end') OR (from_ < '$start' AND to_ > '$end'))", __LINE__, __FILE__);
+                       $this->db->query("SELECT id FROM bb_event"
+                       . " JOIN bb_event_resource ON (event_id=id AND 
resource_id=$resource_id)"
+                       . " WHERE active=1 AND ((from_ >= '$start' AND from_ < 
'$end')"
+                       . " OR (to_ > '$start' AND to_ <= '$end') OR (from_ < 
'$start'"
+                       . " AND to_ > '$end'))", __LINE__, __FILE__);
                        while($this->db->next_record())
                        {
                                $results[] = 
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -597,9 +628,10 @@
                        }
                        $results = array();
                        $sql     = "SELECT br.id
-                    FROM bb_resource br, bb_activity ba
+                    FROM bb_resource br, bb_activity ba, bb_building_resource 
bre
                     WHERE ba.id = br.activity_id " . $type . "
-                    AND br.building_id = " . $building_id . "
+                    AND br.id = bre.resource_id
+                    AND bre.building_id = " . $building_id . "
                     AND br.active = 1
                     ORDER by br.sort";
 
@@ -626,15 +658,16 @@
                     bb_resource.id AS resource_id,
                     bb_resource.name AS resource_name,
                     bb_resource.sort AS sort,
-                    bb_resource.building_id AS building_id,
+                    bb_building_resource.building_id AS building_id,
                     bb_organization.name AS organization_name,
                     bb_organization.shortname AS organization_shortname
                     FROM bb_allocation
                     INNER JOIN bb_allocation_resource ON (bb_allocation.id = 
bb_allocation_resource.allocation_id)
-                    INNER JOIN bb_resource ON  
(bb_allocation_resource.resource_id  = bb_resource.id)
+                    INNER JOIN bb_resource ON 
(bb_allocation_resource.resource_id  = bb_resource.id)
+                    INNER JOIN bb_building_resource ON 
(bb_building_resource.resource_id  = bb_resource.id)
                     INNER JOIN bb_organization ON  (bb_organization.id  = 
bb_allocation.organization_id)
                     WHERE bb_allocation.from_ > '" . $start . "' AND 
bb_allocation.to_ < '" . $end . "'
-                    AND bb_resource.building_id = (" . $building_id . ")
+                    AND bb_building_resource.building_id = (" . $building_id . 
")
                      " . $resources . "
                     AND bb_allocation.active = 1
                     ORDER BY building_name, sort, from_;";
@@ -674,15 +707,16 @@
                     bb_resource.id AS resource_id,
                     bb_resource.name AS resource_name,
                     bb_resource.sort AS sort,
-                    bb_resource.building_id AS building_id,
+                    bb_building_resource.building_id AS building_id,
                     bb_group.name AS group_name,
                     bb_group.shortname AS group_shortname
                     FROM bb_booking
                     INNER JOIN bb_booking_resource ON 
(bb_booking_resource.booking_id = bb_booking.id)
                     INNER JOIN bb_resource ON  
(bb_booking_resource.resource_id  = bb_resource.id)
+                    INNER JOIN bb_building_resource ON 
(bb_building_resource.resource_id  = bb_resource.id)
                     INNER JOIN bb_group ON (bb_group.id = bb_booking.group_id)
                     WHERE bb_booking.from_ > '" . $start . "' AND 
bb_booking.to_ < '" . $end . "'
-                    AND bb_resource.building_id = (" . $building_id . ")
+                    AND bb_building_resource.building_id = (" . $building_id . 
")
                      " . $resources . "
                     AND bb_booking.active = 1
                     ORDER BY building_name,sort, from_;";
@@ -732,10 +766,11 @@
                     bb_resource.sort AS sort,
                     bb_resource.id AS resource_id,
                     bb_resource.name AS resource_name,
-                    bb_resource.building_id AS building_id
+                    bb_building_resource.building_id AS building_id
                     FROM bb_event
                     INNER JOIN bb_event_resource ON 
(bb_event_resource.event_id = bb_event.id)
                     INNER JOIN bb_resource ON (bb_resource.id = 
bb_event_resource.resource_id)
+                    INNER JOIN bb_building_resource ON 
(bb_building_resource.resource_id  = bb_resource.id)
                     WHERE
                     (
                     (bb_event.from_ >= '" . $start . "' AND bb_event.to_ <= '" 
. $end . "')
@@ -743,7 +778,7 @@
                     OR (bb_event.from_ >='" . $start . "' AND bb_event.from_ < 
'" . $end . "' AND bb_event.to_ > '" . $end . "')
                     OR (bb_event.from_ < '" . $start . "' AND bb_event.to_ > 
'" . $end . "')
                     )
-                    AND bb_resource.building_id = (" . $building_id . ")
+                    AND bb_building_resource.building_id = (" . $building_id . 
")
                      " . $resources . "
                     AND bb_event.active = 1
                     ORDER BY building_name,sort,from_;";

Modified: branches/dev-syncromind/booking/inc/class.sobuilding.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.sobuilding.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.sobuilding.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -90,8 +90,9 @@
                        { $params['filters']['where'] = array();}
 
                        $params['filters']['where'][] = '%%table%%.id IN (' .
-                       'SELECT r.building_id FROM bb_allocation_resource ar ' .
+                       'SELECT br.building_id FROM bb_allocation_resource ar ' 
.
                        'JOIN bb_resource r ON ar.resource_id = r.id ' .
+                       'JOIN bb_building_resource br ON (br.resource_id  = 
r.id)  '.
                        'JOIN bb_allocation a ON a.id = ar.allocation_id AND 
(a.from_ - \'now\'::timestamp < \'300 days\') AND a.organization_id = ' . 
$this->_marshal($organization_id, 'int') . ' ' .
                        ')';
 
@@ -118,12 +119,43 @@
                        {
                                return $buildings;
                        }
-                       $sql = 'SELECT building_id FROM bb_resource WHERE 
activity_id IN (' . implode(',', $activity_ids) . ')';
+                       $sql = 'SELECT id FROM bb_building WHERE activity_id IN 
(' . implode(',', $activity_ids) . ')';
                        $this->db->query($sql, __LINE__, __FILE__);
                        while($this->db->next_record())
                        {
-                               $buildings[] = $this->db->f('building_id');
+                               $buildings[] = $this->db->f('id');
                        }
                        return $buildings;
                }
+
+               /**
+                * Returns buildingnames associated with the id
+                * @param array $ids
+                * @return array buildingnames
+                */
+               function get_building_names($ids = array())
+               {
+                       $buildings               = array();
+                       if(!$ids)
+                       {
+                               return $buildings;
+                       }
+                       $sql = 'SELECT bb_building.id, bb_building.name, 
bb_building.street, bb_building.zip_code, bb_building.district, 
bb_activity.name as activity'
+                       . ' FROM bb_building JOIN bb_activity ON 
bb_building.activity_id = bb_activity.id'
+                       . ' WHERE bb_building.id IN (' . implode(',', $ids) . 
')';
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       while($this->db->next_record())
+                       {
+                               $buildings[$this->db->f('id')] = array
+                               (
+                                       'name'          => 
$this->db->f('name',true),
+                                       'street'        => 
$this->db->f('street',true),
+                                       'zip_code'      => 
$this->db->f('zip_code'),
+                                       'district'      => 
$this->db->f('district',true),
+                                       'activity'      => 
$this->db->f('activity',true),
+                               );
+
+                       }
+                       return $buildings;
+               }
        }
\ No newline at end of file

Modified: branches/dev-syncromind/booking/inc/class.socommon.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.socommon.inc.php  2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.socommon.inc.php  2016-02-01 
10:13:06 UTC (rev 14685)
@@ -133,7 +133,7 @@
                        return 
"{$params['join']['table']}_{$params['join']['column']}_{$field}";
                }
 
-               public function _get_cols_and_joins()
+               public function _get_cols_and_joins($filters=array())
                {
                        $cols = array();
                        $joins = array();
@@ -146,6 +146,11 @@
                                }
                                else if(isset($params['join']) && 
$params['join'])
                                {
+                                       if($params['join_type'] == 'manytomany' 
&& ! isset($filters[$field]))
+                                       {
+                                               continue;
+                                       }
+
                                        $join_table_alias = 
$this->build_join_table_alias($field, $params);
                                        $cols[] = 
"{$join_table_alias}.{$params['join']['column']} AS {$field}";
                                        $joins[] = "LEFT JOIN 
{$params['join']['table']} AS {$join_table_alias} 
ON({$join_table_alias}.{$params['join']['key']}={$this->table_name}.{$params['join']['fkey']})";
@@ -250,7 +255,7 @@
                        }
                        else if($type == 'json')
                        {
-                               return json_decode($value);
+                               return json_decode($value, true);
                        }
 
                        //Sanity check
@@ -370,7 +375,7 @@
                                                $column = $params['join'] ? 
$params['join']['column'] : $field;
                                                if($params['type'] == 'int')
                                                {
-                                                       $like_clauses[] = 
"{$table}.{$column} = " . $this->db->db_addslashes($query);
+                                                       $like_clauses[] = 
"{$table}.{$column} = " . (int)$query;//$this->db->db_addslashes($query);
                                                }
                                                else
                                                {
@@ -446,7 +451,7 @@
                        $dir = isset($params['dir']) && $params['dir'] ? 
$params['dir'] : 'asc';
                        $query = isset($params['query']) && $params['query'] ? 
$params['query'] : null;
                        $filters = isset($params['filters']) && 
$params['filters'] ? $params['filters'] : array();
-                       $cols_joins = $this->_get_cols_and_joins();
+                       $cols_joins = $this->_get_cols_and_joins($filters);
                        $cols = join(',', $cols_joins[0]);
                        $joins = join(' ', $cols_joins[1]);
                        $condition = $this->_get_conditions($query, $filters);

Modified: branches/dev-syncromind/booking/inc/class.soevent.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.soevent.inc.php   2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.soevent.inc.php   2016-02-01 
10:13:06 UTC (rev 14685)
@@ -94,7 +94,15 @@
 
                function get_building_info($id)
                {
-                       $this->db->limit_query("SELECT bb_building.id, 
bb_building.name, bb_building.email, bb_building.tilsyn_email, 
bb_building.tilsyn_email2 FROM bb_building, bb_resource, bb_event_resource 
WHERE bb_building.id=bb_resource.building_id AND 
bb_resource.id=bb_event_resource.resource_id AND bb_event_resource.event_id=" . 
intval($id), 0, __LINE__, __FILE__, 1);
+                       $sql = "SELECT bb_building.id, bb_building.name, 
bb_building.email,"
+                       . " bb_building.tilsyn_email, bb_building.tilsyn_email2"
+                       . " FROM bb_building, bb_resource, bb_event_resource, 
bb_building_resource"
+                       . " WHERE 
bb_resource.id=bb_building_resource.resource_id"
+                       . " AND bb_building.id=bb_building_resource.building_id"
+                       . " AND bb_resource.id=bb_event_resource.resource_id"
+                       . " AND bb_event_resource.event_id=" . intval($id);
+
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
                        if(!$this->db->next_record())
                        {
                                return False;

Modified: branches/dev-syncromind/booking/inc/class.soorganization.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.soorganization.inc.php    
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.soorganization.inc.php    
2016-02-01 10:13:06 UTC (rev 14685)
@@ -182,10 +182,11 @@
                        {
                                $params['filters']['where'][] = '%%table%%.id 
IN (' .
                                'SELECT DISTINCT o.id FROM bb_resource r ' .
-                               'JOIN bb_allocation_resource ar ON 
ar.resource_id = r.id AND r.building_id = ' . $this->_marshal($building_id, 
'int') . ' ' .
+                               'JOIN bb_allocation_resource ar ON 
ar.resource_id = r.id '.
                                'JOIN bb_allocation a ON a.id = 
ar.allocation_id ' .
+                               'JOIN bb_building_resource br ON r.id = 
br.resource_id AND br.building_id = ' . $this->_marshal($building_id, 'int') . 
' ' .
                                'JOIN bb_organization o ON o.id = 
a.organization_id ' .
-                               'JOIN bb_season s ON s.building_id = 
r.building_id ' .
+                               'JOIN bb_season s ON s.building_id = 
br.building_id ' .
                                'WHERE s.active = 1 ' .
                                'AND s.from_ <= \'now\'::timestamp ' .
                                'AND s.to_ >= \'now\'::timestamp ' .
@@ -197,7 +198,8 @@
                        {
                                $params['filters']['where'][] = '%%table%%.id 
IN (' .
                                'SELECT DISTINCT o.id FROM bb_resource r ' .
-                               'JOIN bb_allocation_resource ar ON 
ar.resource_id = r.id AND r.building_id = ' . $this->_marshal($building_id, 
'int') . ' ' .
+                               'JOIN bb_allocation_resource ar ON 
ar.resource_id = r.id ' .
+                               'JOIN bb_building_resource br ON r.id = 
br.resource_id AND br.building_id = ' . $this->_marshal($building_id, 'int') . 
' ' .
                                'JOIN bb_allocation a ON a.id = 
ar.allocation_id AND (a.from_ - \'now\'::timestamp < \'300 days\') ' .
                                'JOIN bb_organization o ON o.id = 
a.organization_id ' . $test . ' ORDER BY o.id ASC' .
                                ')';

Modified: branches/dev-syncromind/booking/inc/class.soresource.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.soresource.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.soresource.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -13,16 +13,27 @@
                                'id'                             => 
array('type' => 'int'),
                                'active'                         => 
array('type' => 'int', 'required' => true),
                                'sort'                           => 
array('type' => 'int', 'required' => false),
-                               'building_id'            => array('type' => 
'int', 'required' => true),
+//                             'building_id'            => array('type' => 
'int', 'required' => true),
                                'name'                           => 
array('type' => 'string', 'query' => true, 'required' => true),
                                'type'                           => 
array('type' => 'string', 'query' => true, 'required' => true),
                                'description'            => array('type' => 
'string', 'query' => true, 'required' => false),
                                'activity_id'            => array('type' => 
'int', 'required' => false),
                                'organizations_ids'      => array('type' => 
'string'),
                                'json_representation'    => array('type' => 
'json'),
-                               'building_name'          => array('type'        
 => 'string',
+                               'building_id'            => array(
+                                       'type'   => 'int',
                                        'query'  => true,
+                                       'join_type'      => 'manytomany',
                                        'join'   => array(
+                                               'table'  => 
'bb_building_resource',
+                                               'fkey'   => 'id',
+                                               'key'    => 'resource_id',
+                                               'column' => 'building_id'
+                                       )),
+
+/*                             'building_name'          => array('type'        
 => 'string',
+                                       'query'  => true,
+                                       'join'   => array(
                                                'table'  => 'bb_building',
                                                'fkey'   => 'building_id',
                                                'key'    => 'id',
@@ -51,14 +62,20 @@
                                                'fkey'   => 'building_id',
                                                'key'    => 'id',
                                                'column' => 'district'
-                                       )),
+                                       )),*/
                                'activity_name'          => array('type'        
 => 'string', 'query'    => true,
                                        'join'   => array(
                                                'table'  => 'bb_activity',
                                                'fkey'   => 'activity_id',
                                                'key'    => 'id',
                                                'column' => 'name'
-                                       ))
+                                       )),
+                               'buildings'                      => 
array('type'                 => 'int', 'required'    => true,
+                                       'manytomany' => array(
+                                               'table'  => 
'bb_building_resource',
+                                               'key'    => 'resource_id',
+                                               'column' => 'building_id'
+                                       )),
                        )
                        );
                        $this->account = 
$GLOBALS['phpgw_info']['user']['account_id'];
@@ -66,16 +83,22 @@
 
                function get_metainfo($id)
                {
-                       $this->db->limit_query("SELECT br.name, bb.name as 
building, bb.city, bb.district, br.description FROM bb_resource as br, 
bb_building as bb where br.building_id=bb.id and br.id=" . intval($id), 0, 
__LINE__, __FILE__, 1);
+                       $id = (int)$id;
+                       $sql = "SELECT bb_resource.name, bb_building.name as 
building, bb_building.city, bb_building.district, bb_resource.description"
+                       . " FROM bb_resource JOIN bb_building_resource ON  
bb_resource.id =bb_building_resource.resource_id"
+                       . " JOIN bb_building ON 
bb_building_resource.building_id = bb_building.id"
+                       . " WHERE bb_resource.id={$id}";
+
+                       $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
                        if(!$this->db->next_record())
                        {
                                return False;
                        }
-                       return array('name'                      => 
$this->db->f('name', false),
-                               'building'               => 
$this->db->f('building', false),
-                               'district'               => 
$this->db->f('district', false),
-                               'city'                   => 
$this->db->f('city', false),
-                               'description'    => $this->db->f('description', 
false));
+                       return array('name'                      => 
$this->db->f('name', true),
+                               'building'               => 
$this->db->f('building', true),
+                               'district'               => 
$this->db->f('district', true),
+                               'city'                   => 
$this->db->f('city', true),
+                               'description'    => $this->db->f('description', 
true));
                }
 
                public static function allowed_types()
@@ -146,7 +169,7 @@
                                                continue;
                                        }
                                        
-                                       $sub_condition[] = " 
json_representation @> '{\"schema_location\":$location_id}'";
+//                                     $sub_condition[] = " 
json_representation @> '{\"schema_location\":$location_id}'";
                                        
                                        
if($custom_fields[$criteria['attribute_id']]['datatype'] == 'CH') // in array
                                        {
@@ -156,11 +179,11 @@
                                                 * CREATE OPERATOR ~@| (LEFTARG 
= jsonb, RIGHTARG = text[], PROCEDURE = jsonb_exists_any);
                                                 * CREATE OPERATOR ~@& (LEFTARG 
= jsonb, RIGHTARG = text[], PROCEDURE = jsonb_exists_all);
                                                 */
-                                               $sub_condition[] = " 
json_representation #> '{data,$field_name}' ~@ '$field_value'";
+                                               $sub_condition[] = " 
json_representation #> '{{$location_id},{$field_name}}' ~@ '$field_value'";
                                        }
                                        else // discrete value
                                        {
-                                               $sub_condition[] = " 
json_representation #> '{data,$field_name}' = '\"$field_value\"'";
+                                               $sub_condition[] = " 
json_representation #> '{{$location_id},{$field_name}}' = '\"$field_value\"'";
                                        }
 
 
@@ -211,4 +234,48 @@
 //                     _debug_array($conditions);
                        return $conditions;
                }
+               
+               function add_building($resource_id, $building_id)
+               {
+
+                       if(!$resource_id || !$building_id)
+                       {
+                               return false;
+                       }
+
+                       //check for duplicate
+                       $this->db->query("SELECT resource_id FROM 
bb_building_resource " .
+                       "WHERE resource_id = {$resource_id} AND building_id = 
{$building_id}" , __LINE__, __FILE__);
+                       if($this->db->next_record())
+                       {
+                               return false;
+                       }
+                       else
+                       {
+                               return  $this->db->query("INSERT INTO 
bb_building_resource (resource_id, building_id)"
+                               . " VALUES ({$resource_id}, {$building_id})" , 
__LINE__, __FILE__);
+                       }
+               }
+
+               function remove_building($resource_id, $building_id)
+               {
+
+                       if(!$resource_id || !$building_id)
+                       {
+                               return false;
+                       }
+
+                       $this->db->query("SELECT resource_id FROM 
bb_building_resource " .
+                       "WHERE resource_id = {$resource_id} AND building_id = 
{$building_id}" , __LINE__, __FILE__);
+                       if($this->db->next_record())
+                       {
+                               return $this->db->query("DELETE FROM 
bb_building_resource " .
+                               "WHERE resource_id = {$resource_id} AND 
building_id = {$building_id}" , __LINE__, __FILE__);
+                       }
+                       else
+                       {
+                               return false;
+                       }
+               }
+
        }
\ No newline at end of file

Modified: branches/dev-syncromind/booking/inc/class.uiallocation.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.uiallocation.inc.php      
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.uiallocation.inc.php      
2016-02-01 10:13:06 UTC (rev 14685)
@@ -425,7 +425,7 @@
                                        $timeTo[]        = $dateTimeToE[1];
                                }
 
-                               array_set_default($allocation, 'resources', 
array(get_var('resource', 'int')));
+                               array_set_default($allocation, 'resources', 
array(phpgw::get_var('resource', 'int')));
                                array_set_default($allocation, 'building_id', 
phpgw::get_var('building_id', 'int'));
                                array_set_default($allocation, 'building_name', 
phpgw::get_var('building_name', 'string'));
                                array_set_default($allocation, 'from_', 
$timeFrom);

Modified: branches/dev-syncromind/booking/inc/class.uireports.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.uireports.inc.php 2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.uireports.inc.php 2016-02-01 
10:13:06 UTC (rev 14685)
@@ -195,14 +195,16 @@
                        $resources = array();
                        if($data['all_buildings'])
                        {
-                               $sql = "SELECT DISTINCT bb_resource.id FROM 
bb_building"
-                               . " JOIN bb_resource ON bb_resource.building_id 
= bb_building.id"
+                               $sql = "SELECT DISTINCT 
bb_building_resource.resource_id FROM bb_building"
+                               . " JOIN bb_building_resource ON 
bb_building_resource.building_id = bb_building.id"
+                               . " JOIN bb_resource ON 
bb_building_resource.resource_id = bb_resource.id"
                                . " WHERE bb_building.active = 1"
-                               . " AND activity_id IN (" . implode(',', 
$data['activity_ids']) . ')';
+                               . " AND bb_resource.active = 1"
+                               . " AND bb_building.activity_id IN (" . 
implode(',', $data['activity_ids']) . ')';
                                $db->query($sql);
                                while($db->next_record())
                                {
-                                       $resources[] = $db->f('id');
+                                       $resources[] = $db->f('resource_id');
                                }
                        }
                        else
@@ -237,9 +239,10 @@
                                $weekday         = $dt->format('N');
                                $sql             = "SELECT sb.wday AS wday, 
sb.from_ as boundary_from, sb.to_ as boundary_to,bu.id as building_id,"
                                . " bu.name as building_name, re.id AS 
resource_id, re.name AS resource_name, EXTRACT(EPOCH FROM (sb.to_ - sb.from_)) 
as timespan"
-                               . " FROM bb_building bu, bb_season se, 
bb_season_boundary sb, bb_resource re, bb_season_resource sr"
+                               . " FROM bb_building bu, bb_season se, 
bb_season_boundary sb, bb_resource re, bb_season_resource sr, 
bb_building_resource br"
                                . " WHERE bu.id = se.building_id"
-                               . " AND bu.id = re.building_id"
+                               . " AND re.id = br.resource_id"
+                               . " AND bu.id = br.building_id"
                                . " AND sr.season_id = se.id"
                                . " AND sr.resource_id = re.id"
                                . " AND sb.season_id = se.id"
@@ -300,7 +303,8 @@
                                        INNER JOIN bb_agegroup ag ON ag.id = 
ea.agegroup_id and ag.active = 1
                                        INNER JOIN bb_event_resource er ON 
er.event_id = ev.id
                                        INNER JOIN bb_resource re ON re.id = 
er.resource_id
-                                       INNER JOIN bb_building bu ON bu.id = 
re.building_id
+                                       INNER JOIN bb_building_resource bre ON 
re.id = bre.resource_id
+                                       INNER JOIN bb_building bu ON bu.id = 
bre.building_id
                                        WHERE date_trunc('day' ,ev.from_) >= 
to_date('{$check_date}' ,'YYYY-MM-DD')
                                        AND date_trunc('day' ,ev.from_) <= 
to_date('{$check_date}', 'YYYY-MM-DD')
                                        AND EXTRACT(DOW FROM ev.from_) = 
{$entry['wday']}
@@ -365,14 +369,16 @@
                        $resources = array();
                        if($data['all_buildings'])
                        {
-                               $sql = "SELECT DISTINCT bb_resource.id FROM 
bb_building"
-                               . " JOIN bb_resource ON bb_resource.building_id 
= bb_building.id"
+                               $sql = "SELECT DISTINCT 
bb_building_resource.resource_id FROM bb_building"
+                               . " JOIN bb_building_resource ON 
bb_building_resource.building_id = bb_building.id"
+                               . " JOIN bb_resource ON 
bb_building_resource.resource_id = bb_resource.id"
                                . " WHERE bb_building.active = 1"
-                               . " AND activity_id IN (" . implode(',', 
$data['activity_ids']) . ')';
+                               . " AND bb_resource.active = 1"
+                               . " AND bb_building.activity_id IN (" . 
implode(',', $data['activity_ids']) . ')';
                                $db->query($sql);
                                while($db->next_record())
                                {
-                                       $resources[] = $db->f('id');
+                                       $resources[] = $db->f('resource_id');
                                }
                        }
                        else
@@ -457,12 +463,13 @@
                        $to              = 
$db->to_timestamp(phpgwapi_datetime::date_to_timestamp($data['end_date']) + 24 
* 3600 - 1);
 
 
-                       $sql = "select distinct al.id, al.from_, al.to_, 
EXTRACT(DOW FROM al.to_) as day_of_week, bu.id as building_id, bu.name as 
building_name, br.id as resource_id, br.name as resource_name
-                               from bb_allocation al
-                               inner join bb_allocation_resource ar on 
ar.allocation_id = al.id
-                               inner join bb_resource br on br.id = 
ar.resource_id and br.active = 1
-                               inner join bb_building bu on bu.id = 
br.building_id
-                               left join bb_booking bb on bb.allocation_id = 
al.id
+                       $sql = "SELECT DISTINCT al.id, al.from_, al.to_, 
EXTRACT(DOW FROM al.to_) as day_of_week, bu.id as building_id, bu.name as 
building_name, br.id as resource_id, br.name as resource_name
+                               FROM bb_allocation al
+                               INNER JOIN bb_allocation_resource ar on 
ar.allocation_id = al.id
+                               INNER JOIN bb_resource br on br.id = 
ar.resource_id and br.active = 1
+                               INNER JOIN bb_building_resource bre ON br.id = 
bre.resource_id
+                               INNER JOIN bb_building bu on bu.id = 
bre.building_id
+                               LEFT JOIN bb_booking bb on bb.allocation_id = 
al.id
                                WHERE bb.id is null
                                AND al.from_ >= '{$from}'
                                AND al.to_ <= '{$to}'"
@@ -682,15 +689,16 @@
                        $buildings       = implode(",", $buildings);
                        $weekdays        = implode(",", $weekdays);
 
-                       $sql = "select distinct al.id, al.from_, al.to_, 
EXTRACT(DOW FROM al.to_) as day_of_week, bu.id as building_id, bu.name as 
building_name, br.id as resource_id, br.name as resource_name
-                               from bb_allocation al
-                               inner join bb_allocation_resource ar on 
ar.allocation_id = al.id
-                               inner join bb_resource br on br.id = 
ar.resource_id and br.active = 1
-                               inner join bb_building bu on bu.id = 
br.building_id
-                               left join bb_booking bb on bb.allocation_id = 
al.id
-                               where bb.id is null 
-                               and al.from_ >= '" . $from . " 00:00:00'
-                               and al.to_ <= '" . $to . " 23:59:59' ";
+                       $sql = "SELECT DISTINCT al.id, al.from_, al.to_, 
EXTRACT(DOW FROM al.to_) as day_of_week, bu.id as building_id, bu.name as 
building_name, br.id as resource_id, br.name as resource_name
+                               FROM bb_allocation al
+                               INNER JOIN bb_allocation_resource ar on 
ar.allocation_id = al.id
+                               INNER JOIN bb_resource br on br.id = 
ar.resource_id and br.active = 1
+                               INNER JOIN bb_building_resource bre ON br.id = 
bre.resource_id
+                               inner join bb_building bu on bu.id = 
bre.building_id
+                               LEFT JOIN bb_booking bb on bb.allocation_id = 
al.id
+                               WHERE bb.id is null
+                               AND al.from_ >= '" . $from . " 00:00:00'
+                               AND al.to_ <= '" . $to . " 23:59:59' ";
 
                        if($buildings)
                                $sql .= "and building_id in (" . $buildings . 
") ";

Modified: branches/dev-syncromind/booking/inc/class.uiresource.inc.php
===================================================================
--- branches/dev-syncromind/booking/inc/class.uiresource.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/inc/class.uiresource.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -13,34 +13,36 @@
 
                public $public_functions = array
                        (
-                       'index'                                  => true,
-                       'query'                                  => true,
-                       'add'                                    => true,
-                       'edit'                                   => true,
-                       'get_custom'                     => true,
-                       'show'                                   => true,
-                       'schedule'                               => true,
-                       'toggle_show_inactive'   => true,
+                       'index' => true,
+                       'query' => true,
+                       'add' => true,
+                       'edit' => true,
+                       'get_custom' => true,
+                       'show' => true,
+                       'schedule' => true,
+                       'toggle_show_inactive' => true,
+                       'get_buildings' => true,
+                       'add_building' => true,
+                       'remove_building' => true
                );
 
                public function __construct()
                {
                        parent::__construct();
+                       $this->sobuilding = CreateObject('booking.sobuilding');
 
 //                     Analizar esta linea de permiso 
self::process_booking_unauthorized_exceptions();
 
-                       $this->bo                        = 
CreateObject('booking.boresource');
-                       $this->activity_bo       = 
CreateObject('booking.boactivity');
-                       $this->fields            = array(
-                               'name'                           => 'string',
-                               'building_id'            => 'string',
-                               'building_name'          => 'string',
-                               'description'            => 'html',
-                               'activity_id'            => 'int',
-                               'active'                         => 'int',
-                               'type'                           => 'string',
-                               'sort'                           => 'string',
-                               'organizations_ids'      => 'string',
+                       $this->bo = CreateObject('booking.boresource');
+                       $this->activity_bo = CreateObject('booking.boactivity');
+                       $this->fields = array(
+                               'name' => 'string',
+                               'description' => 'html',
+                               'activity_id' => 'int',
+                               'active' => 'int',
+                               'type' => 'string',
+                               'sort' => 'string',
+                               'organizations_ids' => 'string',
                        );
                        self::set_active_menu('booking::buildings::resources');
                }
@@ -53,60 +55,60 @@
                        }
 
                        $data = array(
-                               'form'           => array(
+                               'form' => array(
                                        'toolbar' => array(
                                                'item' => array(
                                                        array(
-                                                               'type'   => 
'link',
-                                                               'value'  => 
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
-                                                               'href'   => 
self::link(array('menuaction' => $this->url_prefix . '.toggle_show_inactive'))
+                                                               'type' => 
'link',
+                                                               'value' => 
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
+                                                               'href' => 
self::link(array('menuaction' => $this->url_prefix . '.toggle_show_inactive'))
                                                        ),
                                                )
                                        ),
                                ),
-                               'datatable'      => array(
+                               'datatable' => array(
                                        'source' => 
self::link(array('menuaction' => 'booking.uiresource.index', 'phpgw_return_as' 
=> 'json')),
-                                       'field'  => array(
+                                       'field' => array(
                                                array(
-                                                       'key'            => 
'name',
-                                                       'label'          => 
lang('Resource Name'),
-                                                       'formatter'      => 
'JqueryPortico.formatLink'
+                                                       'key' => 'name',
+                                                       'label' => 
lang('Resource Name'),
+                                                       'formatter' => 
'JqueryPortico.formatLink'
                                                ),
                                                array(
-                                                       'key'    => 'sort',
-                                                       'label'  => 
lang('Order')
+                                                       'key' => 'sort',
+                                                       'label' => lang('Order')
                                                ),
                                                array(
-                                                       'key'    => 'link',
+                                                       'key' => 'link',
                                                        'hidden' => true
                                                ),
                                                array(
-                                                       'key'    => 
'building_name',
-                                                       'label'  => 
lang('Building name')
+                                                       'key' => 
'building_name',
+                                                       'label' => 
lang('Building name')
                                                ),
                                                array(
-                                                       'key'    => 'type',
-                                                       'label'  => 
lang('Resource Type')
+                                                       'key' => 'type',
+                                                       'label' => 
lang('Resource Type')
                                                ),
                                                array(
-                                                       'key'    => 
'activity_name',
-                                                       'label'  => 
lang('Activity')
+                                                       'key' => 
'activity_name',
+                                                       'label' => 
lang('Activity')
                                                ),
                                                array(
-                                                       'key'    => 
'building_street',
-                                                       'label'  => 
lang('Street')
+                                                       'key' => 
'building_street',
+                                                       'label' => 
lang('Street')
                                                ),
                                                array(
-                                                       'key'    => 
'building_city',
-                                                       'label'  => 
lang('Postal city')
+                                                       'key' => 
'building_city',
+                                                       'label' => lang('Postal 
city')
                                                ),
                                                array(
-                                                       'key'    => 
'building_district',
-                                                       'label'  => 
lang('District')
+                                                       'key' => 
'building_district',
+                                                       'label' => 
lang('District')
                                                ),
                                                array(
-                                                       'key'    => 'active',
-                                                       'label'  => 
lang('Active'),
+                                                       'key' => 'active',
+                                                       'label' => 
lang('Active'),
                                                ),
                                        )
                                )
@@ -115,9 +117,9 @@
                        if($this->bo->allow_create())
                        {
                                array_unshift($data['form']['toolbar']['item'], 
array(
-                                       'type'   => 'link',
-                                       'value'  => lang('New resource'),
-                                       'href'   => 
self::link(array('menuaction' => 'booking.uiresource.add'))
+                                       'type' => 'link',
+                                       'value' => lang('New resource'),
+                                       'href' => self::link(array('menuaction' 
=> 'booking.uiresource.add'))
                                ));
                        }
 
@@ -130,22 +132,22 @@
                        return 
$this->jquery_results($this->bo->populate_grid_data("booking.uiresource.show"));
                }
 
-//             public function index_json()
-//             {
-//                     return 
$this->bo->populate_grid_data("booking.uiresource.show");
-//             }
-
                public function add()
                {
-                       $errors                          = array();
-                       $resource                        = array();
-                       $resource['sort']        = '0';
+                       $errors = array();
+                       $resource = array();
+                       $resource['sort'] = '0';
 
                        if($_SERVER['REQUEST_METHOD'] == 'POST')
                        {
-                               $resource                        = 
extract_values($_POST, $this->fields);
-                               $resource['active']      = '1';
-                               $errors                          = 
$this->bo->validate($resource);
+                               $resource = extract_values($_POST, 
$this->fields);
+                               $resource['active'] = '1';
+                               $building_id = phpgw::get_var('building_id', 
'int');
+                               $resource['buildings'] = array('building_id' => 
$building_id);
+                               $building = 
$this->sobuilding->read_single($building_id);
+                               $resource['activity_id'] = 
$building['activity_id'];
+
+                               $errors = $this->bo->validate($resource);
                                if(!$errors)
                                {
                                        try
@@ -168,15 +170,15 @@
                        phpgwapi_jquery::load_widget('autocomplete');
 
                        phpgwapi_jquery::init_ckeditor('field_description');
-                       $activity_data                   = 
$this->activity_bo->fetch_activities();
-                       $resource['types']               = 
$this->resource_types();
+                       $activity_data = $this->activity_bo->fetch_activities();
+                       $resource['types'] = $this->resource_types();
                        $resource['cancel_link'] = 
self::link(array('menuaction' => 'booking.uiresource.index'));
-                       $tabs                                    = array();
-                       $tabs['generic']                 = array('label' => 
lang('Permission Edit'), 'link' => '#resource');
-                       $active_tab                              = 'generic';
+                       $tabs = array();
+                       $tabs['generic'] = array('label' => lang('Permission 
Edit'), 'link' => '#resource');
+                       $active_tab = 'generic';
 
-                       $resource['tabs']                = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
-                       $resource['validator']   = 
phpgwapi_jquery::formvalidator_generate(array('location',
+                       $resource['tabs'] = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
+                       $resource['validator'] = 
phpgwapi_jquery::formvalidator_generate(array('location',
                                'date', 'security', 'file'));
 
                        self::render_template_xsl('resource_form', 
array('resource' => $resource, 'activitydata' => $activity_data,
@@ -187,48 +189,49 @@
                {
                        $types = array();
                        foreach($this->bo->allowed_types() as $type)
-                       { $types[$type] = self::humanize($type);}
+                       {
+                               $types[$type] = self::humanize($type);
+                       }
                        return $types;
                }
 
                public function edit()
                {
-                       $id                                                     
 = phpgw::get_var('id', 'int');
-                       $resource                                        = 
$this->bo->read_single($id);
-                       $resource['id']                          = $id;
-                       $resource['building_link']       = 
self::link(array('menuaction' => 'booking.uibuilding.show',
+                       $id = phpgw::get_var('id', 'int');
+                       $resource = $this->bo->read_single($id);
+                       $resource['id'] = $id;
+                       $resource['building_link'] = 
self::link(array('menuaction' => 'booking.uibuilding.show',
                                'id' => $resource['id']));
-                       $resource['buildings_link']      = 
self::link(array('menuaction' => 'booking.uibuilding.index'));
-                       $resource['cancel_link']         = 
self::link(array('menuaction' => 'booking.uiresource.show',
+                       $resource['buildings_link'] = 
self::link(array('menuaction' => 'booking.uibuilding.index'));
+                       $resource['cancel_link'] = 
self::link(array('menuaction' => 'booking.uiresource.show',
                                'id' => $resource['id']));
-                       $resource['types']                       = 
$this->resource_types();
+                       $resource['types'] = $this->resource_types();
 
                        $errors = array();
                        if($_SERVER['REQUEST_METHOD'] == 'POST')
                        {
-                               $resource        = array_merge($resource, 
extract_values($_POST, $this->fields));
-                               $errors          = 
$this->bo->validate($resource);
-                               $location                = 
$this->get_location();
-                               $location_id    = 
$GLOBALS['phpgw']->locations->get_id('booking', $location);
+                               $resource = array_merge($resource, 
extract_values($_POST, $this->fields));
+                               $errors = $this->bo->validate($resource);
+                               $location = $this->get_location();
+                               $location_id = 
$GLOBALS['phpgw']->locations->get_id('booking', $location);
 
-                               $fields         = 
ExecMethod('booking.custom_fields.get_fields',$location);
+                               $fields = 
ExecMethod('booking.custom_fields.get_fields', $location);
                                $values_attribute = 
phpgw::get_var('values_attribute');
                                $json_representation = array();
                                foreach($fields as $attrib_id => &$attrib)
                                {
                                        $json_representation[$attrib['name']] = 
isset($values_attribute[$attrib_id]['value']) ? 
$values_attribute[$attrib_id]['value'] : null;
-                       //              $attrib['value'] = 
isset($values_attribute[$attrib_id]['value']) ? 
$values_attribute[$attrib_id]['value'] : null;
                                }
-                               $resource['json_representation'] = array(
-                                       'schema_location' => $location_id,
-                                       'data' => $json_representation
-                               );
+
+                               $resource['json_representation'][$location_id] 
=  $json_representation;
+
                                if(!$errors)
                                {
                                        $receipt = $this->bo->update($resource);
                                        $this->redirect(array('menuaction' => 
'booking.uiresource.show', 'id' => $resource['id']));
                                }
                        }
+
                        $this->flash_form_errors($errors);
                        self::add_javascript('booking', 'booking', 
'resource_new.js');
                        phpgwapi_jquery::load_widget('autocomplete');
@@ -238,40 +241,39 @@
                        {
                                
$activity_data['results'][$acKey]['resource_id'] = $resource['activity_id'];
                        }
-                       $tabs                    = array();
+                       $tabs = array();
                        $tabs['generic'] = array('label' => lang('Permission 
Edit'), 'link' => '#resource');
-                       $active_tab              = 'generic';
+                       $active_tab = 'generic';
 
-                       $resource['tabs']                = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
-                       $resource['validator']   = 
phpgwapi_jquery::formvalidator_generate(array('location',
+                       $resource['tabs'] = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
+                       $resource['validator'] = 
phpgwapi_jquery::formvalidator_generate(array('location',
                                'date', 'security', 'file'));
 
-                       self::render_template_xsl('resource_form', 
array('resource' => $resource, 'activitydata' => $activity_data));
+                       self::render_template_xsl(array('resource_form', 
'datatable_inline'), array('datatable_def' => 
self::get_building_datatable_def($id),
+                               'resource' => $resource, 'activitydata' => 
$activity_data));
                }
 
-
                private function get_location()
                {
-                       $activity_id             = 
phpgw::get_var('activity_id', 'int');
-                       $activity_path           = 
$this->activity_bo->get_path($activity_id);
-                       $top_level_activity      = $activity_path ? 
$activity_path[0]['id'] : 0;
+                       $activity_id = phpgw::get_var('schema_activity_id', 
'int');
+                       $activity_path = 
$this->activity_bo->get_path($activity_id);
+                       $top_level_activity = $activity_path ? 
$activity_path[0]['id'] : 0;
                        return ".resource.{$top_level_activity}";
                }
 
                public function get_custom()
                {
-                       $resource_id            = phpgw::get_var('resource_id', 
'int');
-                       $resource                       = 
$this->bo->read_single($resource_id);
-                       $custom_values          = 
$resource['json_representation']->data;
-//                     _debug_array($custom_values);
-
-
-                       $location                        = 
$this->get_location();
-                       $custom_fields          = 
createObject('booking.custom_fields');
-                       $fields = $custom_fields->get_fields($location);
+                       $type = phpgw::get_var('type', 'string', 'REQUEST', 
'form');
+                       $resource_id = phpgw::get_var('resource_id', 'int');
+                       $resource = $this->bo->read_single($resource_id);
+                       $location = $this->get_location();
+                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('booking', $location);
+                       $custom_values = 
$resource['json_representation'][$location_id];
+                       $custom_fields = createObject('booking.custom_fields');
+                       $fields = $custom_fields->get_fields($location);
                        foreach($fields as $attrib_id => &$attrib)
                        {
-                               $attrib['value'] = 
isset($custom_values->$attrib['name']) ? $custom_values->$attrib['name'] : null;
+                               $attrib['value'] = 
isset($custom_values[$attrib['name']]) ? $custom_values[$attrib['name']] : null;
 
                                if(isset($attrib['choice']) && 
is_array($attrib['choice']) && $attrib['value'])
                                {
@@ -289,66 +291,178 @@
                                }
                        }
 //                     _debug_array($fields);
-                       $organized_fields        = 
$custom_fields->organize_fields($location, $fields);
+                       $organized_fields = 
$custom_fields->organize_fields($location, $fields);
 
                        $data = array(
-                               'attributes_group'      => $organized_fields,
+                               'attributes_group' => $organized_fields,
                        );
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('attributes_form'));
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array("attributes_{$type}"));
                        $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('custom_fields' => $data));
                }
 
+               private static function get_building_columns()
+               {
+                       $columns = array
+                               (
+                               array('key' => 'id', 'label' => '#', 'sortable' 
=> true, 'resizeable' => true),
+                               array('key' => 'name', 'label' => lang('name'), 
'sortable' => true, 'resizeable' => true),
+                               array('key' => 'street', 'label' => 
lang('street'), 'sortable' => true, 'resizeable' => true),
+                               array('key' => 'activity_name', 'label' => 
lang('activity'), 'sortable' => true,
+                                       'resizeable' => true, 'formatter' => 
'ChangeSchema'),
+                               array('key' => 'active', 'label' => 
lang('active'), 'sortable' => true, 'resizeable' => true)
+                       );
+                       return $columns;
+               }
+
+               private static function get_building_datatable_def($id)
+               {
+                       return array
+                               (
+                               array
+                                       (
+                                       'container' => 'datatable-container_0',
+                                       'requestUrl' => 
json_encode(self::link(array('menuaction' => 'booking.uiresource.get_buildings',
+                                               'resource_id' => $id, 
'phpgw_return_as' => 'json'))),
+                                       'ColumnDefs' => 
self::get_building_columns(),
+                                       'data' => json_encode(array()),
+                                       'config' => array(
+                                               array('disableFilter' => true),
+                                               array('disablePagination' => 
true)
+                                       )
+                               )
+                       );
+               }
+
+               public function get_buildings()
+               {
+                       $resource = 
$this->bo->read_single(phpgw::get_var('resource_id', 'int'));
+
+                       $_filter_building['id'] = array_merge(array(-1), 
$resource['buildings']);
+
+                       $bui_result = $this->sobuilding->read(array("sort" => 
"name", "dir" => "asc",
+                               "filters" => $_filter_building));
+
+                       return $this->jquery_results($bui_result);
+               }
+
+               public function add_building()
+               {
+                       $resource_id = phpgw::get_var('resource_id', 'int');
+                       if(!$building_id = phpgw::get_var('building_id', 'int'))
+                       {
+                               return array(
+                                       'ok' => false,
+                                       'msg' => lang('select')
+                               );
+                       }
+
+                       try
+                       {
+                               $resource = 
$this->bo->read_single($resource_id);
+                               $receipt = $this->bo->add_building($resource, 
$resource_id, $building_id);
+                               $msg = $receipt ? '' : lang('duplicate');
+                       }
+                       catch(booking_unauthorized_exception $e)
+                       {
+                               return false;
+                               $msg = lang('Could not add object due to 
insufficient permissions');
+                       }
+
+                       return array(
+                               'ok' => $receipt,
+                               'msg' => $msg
+                       );
+               }
+
+               public function remove_building()
+               {
+                       $resource_id = phpgw::get_var('resource_id', 'int');
+                       if(!$building_id = phpgw::get_var('building_id', 'int'))
+                       {
+                               return array(
+                                       'ok' => false,
+                                       'msg' => lang('select')
+                               );
+                       }
+                       try
+                       {
+                               $resource = 
$this->bo->read_single($resource_id);
+                               $receipt = 
$this->bo->remove_building($resource, $resource_id, $building_id);
+                               $msg = '';
+                       }
+                       catch(booking_unauthorized_exception $e)
+                       {
+                               return false;
+                               $msg = lang('Could not update object due to 
insufficient permissions');
+                       }
+
+                       return array(
+                               'ok' => $receipt,
+                               'msg' => $msg
+                       );
+               }
+
                public function show()
                {
-                       $resource                                               
 = $this->bo->read_single(phpgw::get_var('id', 'int'));
-                       $resource['edit_link']                   = 
self::link(array('menuaction' => 'booking.uiresource.edit',
+                       $id = phpgw::get_var('id', 'int');
+                       $resource = $this->bo->read_single($id);
+
+                       $_filter_building['id'] = array_merge(array(-1), 
$resource['buildings']);
+
+                       $bui_result = $this->sobuilding->read(array("sort" => 
"name", "dir" => "asc",
+                               "filters" => $_filter_building));
+
+
+                       $resource['edit_link'] = self::link(array('menuaction' 
=> 'booking.uiresource.edit',
                                'id' => $resource['id']));
-                       $resource['building_link']               = 
self::link(array('menuaction' => 'booking.uibuilding.show',
+                       $resource['building_link'] = 
self::link(array('menuaction' => 'booking.uibuilding.show',
                                'id' => $resource['building_id']));
-                       $resource['buildings_link']              = 
self::link(array('menuaction' => 'booking.uibuilding.index'));
-                       $resource['schedule_link']               = 
self::link(array('menuaction' => 'booking.uiresource.schedule',
+                       $resource['buildings_link'] = 
self::link(array('menuaction' => 'booking.uibuilding.index'));
+                       $resource['schedule_link'] = 
self::link(array('menuaction' => 'booking.uiresource.schedule',
                                'id' => $resource['id']));
-                       $resource['cancel_link']                 = 
self::link(array('menuaction' => 'booking.uiresource.index'));
-                       $resource['add_document_link']   = 
booking_uidocument::generate_inline_link('resource', $resource['id'], 'add');
+                       $resource['cancel_link'] = 
self::link(array('menuaction' => 'booking.uiresource.index'));
+                       $resource['add_document_link'] = 
booking_uidocument::generate_inline_link('resource', $resource['id'], 'add');
                        $resource['add_permission_link'] = 
booking_uipermission::generate_inline_link('resource', $resource['id'], 'add');
 
-                       $tabs                            = array();
-                       $tabs['generic']         = array(
-                               'label'  => lang('Resource'),
-                               'link'   => '#resource'
+                       $tabs = array();
+                       $tabs['generic'] = array(
+                               'label' => lang('Resource'),
+                               'link' => '#resource'
                        );
-                       $active_tab                      = 'generic';
-                       $resource['tabs']        = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
-                       $data                            = array(
+                       $active_tab = 'generic';
+                       $resource['tabs'] = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
+
+                       $data = array(
+                               'datatable_def' => 
self::get_building_datatable_def($id),
                                'resource' => $resource
                        );
                        self::add_javascript('booking', 'booking', 
'resource_new.js'); // to render custom fields
-                       self::render_template_xsl('resource', $data);
+                       self::render_template_xsl(array('resource', 
'datatable_inline'), $data);
                }
 
                public function schedule()
                {
-                       $resource                                               
 = $this->bo->get_schedule(phpgw::get_var('id', 'int'), 'booking.uibuilding', 
'booking.uiresource');
-                       $resource['application_link']    = self::link(array(
-                               'menuaction'     => 'booking.uiapplication.add',
-                               'building_id'    => $resource['building_id'],
-                               'building_name'  => $resource['building_name'],
-                               'activity_id'    => $resource['activity_id'],
-                               'resource'               => $resource['id']
+                       $resource = 
$this->bo->get_schedule(phpgw::get_var('id', 'int'), 'booking.uibuilding', 
'booking.uiresource');
+                       $resource['application_link'] = self::link(array(
+                               'menuaction' => 'booking.uiapplication.add',
+                               'building_id' => $resource['building_id'],
+                               'building_name' => $resource['building_name'],
+                               'activity_id' => $resource['activity_id'],
+                               'resource' => $resource['id']
                        ));
-                       $resource['datasource_url']              = 
self::link(array(
-                               'menuaction'             => 
'booking.uibooking.resource_schedule',
-                               'resource_id'            => $resource['id'],
-                               'phpgw_return_as'        => 'json',
+                       $resource['datasource_url'] = self::link(array(
+                               'menuaction' => 
'booking.uibooking.resource_schedule',
+                               'resource_id' => $resource['id'],
+                               'phpgw_return_as' => 'json',
                        ));
 
                        $resource['picker_img'] = 
$GLOBALS['phpgw']->common->image('phpgwapi', 'cal');
 
-                       $tabs                    = array();
+                       $tabs = array();
                        $tabs['generic'] = array('label' => lang('Resource 
Schedule'), 'link' => '#resource_schedule');
-                       $active_tab              = 'generic';
+                       $active_tab = 'generic';
 
-                       $resource['tabs']                = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
+                       $resource['tabs'] = 
phpgwapi_jquery::tabview_generate($tabs, $active_tab);
                        $resource['cancel_link'] = 
self::link(array('menuaction' => 'booking.uiresource.show',
                                'id' => $resource['id']));
 

Modified: branches/dev-syncromind/booking/js/booking/resource_new.js
===================================================================
--- branches/dev-syncromind/booking/js/booking/resource_new.js  2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/js/booking/resource_new.js  2016-02-01 
10:13:06 UTC (rev 14685)
@@ -2,30 +2,96 @@
        
JqueryPortico.autocompleteHelper('index.php?menuaction=booking.uibuilding.index&phpgw_return_as=json&',
                        'field_building_name', 'field_building_id', 
'building_container');
 
-       get_custom_fields();
+       $("#field_schema_activity_id").val($("#field_activity_id").val());
 
+       get_custom_fields($("#field_activity_id").val(),default_schema);
 
        $("#field_activity_id").change(function () {
-               get_custom_fields();
+               get_custom_fields($(this).val());
        });
 });
 
-get_custom_fields = function () {
+get_custom_fields = function (schema_activity_id, schema) {
+       $("#field_schema_activity_id").val(schema_activity_id);
        var oArgs = {menuaction: 'booking.uiresource.get_custom', resource_id: 
resource_id};
        var requestUrl = phpGWLink('index.php', oArgs);
        requestUrl += "&phpgw_return_as=stripped_html";
-       var activity_id = $("#field_activity_id").val();
+       schema = schema || default_schema;
+
        $.ajax({
                type: 'POST',
-               data: {activity_id: activity_id},
+               data: {schema_activity_id: schema_activity_id, type: 
schema_type},
                dataType: 'html',
                url: requestUrl,
                success: function (data) {
                        if (data != null)
                        {
                                var custom_fields = data;
+                               $("#schema_name").html(schema);
                                $("#custom_fields").html(custom_fields);
                        }
                }
        });
 };
+
+addBuilding = function () {
+       var oArgs = {menuaction: 'booking.uiresource.add_building'};
+       var requestUrl = phpGWLink('index.php', oArgs, true);
+       var building_id = $("#field_building_id").val();
+       $.ajax({
+               type: 'POST',
+               data: {building_id: building_id, resource_id: resource_id},
+               dataType: 'JSON',
+               url: requestUrl,
+               success: function (data) {
+                       if (data.ok == true)
+                       {
+                               oTable0.fnDraw();
+                               $("#field_building_id").val('');
+                               $("#field_building_name").val('');
+                       }
+                       if (data.msg !== '')
+                       {
+                               alert(data.msg);
+                       }
+               }
+       });
+};
+
+removeBuilding = function () {
+       var oArgs = {menuaction: 'booking.uiresource.remove_building'};
+       var requestUrl = phpGWLink('index.php', oArgs, true);
+       var building_id = $("#field_building_id").val();
+       $.ajax({
+               type: 'POST',
+               data: {building_id: building_id, resource_id: resource_id},
+               dataType: 'JSON',
+               url: requestUrl,
+               success: function (data) {
+                       if (data.ok == true)
+                       {
+                               oTable0.fnDraw();
+                               $("#field_building_id").val('');
+                               $("#field_building_name").val('');
+                       }
+                       if (data.msg !== '')
+                       {
+                               alert(data.msg);
+                       }
+               }
+       });
+};
+
+
+ChangeSchema = function (key, oData)
+{
+       var schema_activity_id = oData['activity_id'];
+       var activity_name = oData[key];
+       if (resource_id > 0)
+       {
+               return '<a class="button" onclick="get_custom_fields(' + 
schema_activity_id + ",'" + activity_name + "'" + ')">' + activity_name + 
'</a>';
+       } else
+       {
+               return oData[key];
+       }
+};

Modified: branches/dev-syncromind/booking/setup/setup.inc.php
===================================================================
--- branches/dev-syncromind/booking/setup/setup.inc.php 2016-01-27 12:24:06 UTC 
(rev 14684)
+++ branches/dev-syncromind/booking/setup/setup.inc.php 2016-02-01 10:13:06 UTC 
(rev 14685)
@@ -1,6 +1,6 @@
 <?php
        $setup_info['booking']['name'] = 'booking';
-       $setup_info['booking']['version'] = '0.2.26';
+       $setup_info['booking']['version'] = '0.2.27';
        $setup_info['booking']['app_order'] = 9;
        $setup_info['booking']['enable'] = 1;
        $setup_info['booking']['app_group'] = 'office';
@@ -14,6 +14,7 @@
                'bb_contact_person',
                'bb_organization',
                'bb_resource',
+               'bb_building_resource',
                'bb_group',
                'bb_season',
                'bb_season_boundary',

Modified: branches/dev-syncromind/booking/setup/tables_current.inc.php
===================================================================
--- branches/dev-syncromind/booking/setup/tables_current.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/setup/tables_current.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -109,7 +109,6 @@
                        'fd' => array(
                                'id' => array('type' => 'auto', 'nullable' => 
false),
                                'active' => array('type' => 'int', 'nullable' 
=> False,'precision' => '4', 'default' => 1),
-                               'building_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'name' => array('type' => 'varchar','precision' 
=> '150','nullable' => False),
                                'type' => array('type' => 'varchar', 
'precision' => '50', 'nullable' => False),
                                'description' => array('type' => 'text', 
'nullable' => True),
@@ -120,11 +119,23 @@
                        ),
                        'pk' => array('id'),
                        'fk' => array(
-                               'bb_building' => array('building_id' => 'id'),
                                'bb_activity' => array('activity_id' => 'id')),
                        'ix' => array(),
                        'uc' => array()
                ),
+               'bb_building_resource' => array(
+                       'fd' => array(
+                               'building_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                               'resource_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                       ),
+                       'pk' => array('building_id', 'resource_id'),
+                       'fk' => array(
+                               'bb_building' => array('building_id' => 'id'),
+                               'bb_resource' => array('resource_id' => 'id')
+                       ),
+                       'ix' => array(),
+                       'uc' => array()
+               ),
                'bb_group' => array(
                        'fd' => array(
                                'id' => array('type' => 'auto', 'nullable' => 
false),

Modified: branches/dev-syncromind/booking/setup/tables_update.inc.php
===================================================================
--- branches/dev-syncromind/booking/setup/tables_update.inc.php 2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/setup/tables_update.inc.php 2016-02-01 
10:13:06 UTC (rev 14685)
@@ -3446,4 +3446,67 @@
                        $GLOBALS['setup_info']['booking']['currentver'] = 
'0.2.26';
                        return $GLOBALS['setup_info']['booking']['currentver'];
                }
-       }
\ No newline at end of file
+       }
+
+       $test[] = '0.2.26';
+       /**
+        * Update booking version from 0.2.26 to 0.2.27
+        *
+        */
+       function booking_upgrade0_2_26()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               $GLOBALS['phpgw_setup']->oProc->CreateTable(
+                       'bb_building_resource', array(
+                               'fd' => array(
+                                       'building_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                                       'resource_id' => array('type' => 
'int','precision' => '4','nullable' => False),
+                               ),
+                               'pk' => array('building_id', 'resource_id'),
+                               'fk' => array(
+                                       'bb_building' => array('building_id' => 
'id'),
+                                       'bb_resource' => array('resource_id' => 
'id')
+                               ),
+                               'ix' => array(),
+                               'uc' => array()
+                       )
+               );
+
+               $GLOBALS['phpgw_setup']->oProc->query('SELECT id, building_id 
FROM bb_resource',__LINE__,__FILE__);
+
+               // using stored prosedures
+               $sql = 'INSERT INTO bb_building_resource (building_id, 
resource_id)'
+                                                       . ' VALUES(?, ?)';
+               $valueset = array();
+
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $valueset[] = array
+                       (
+                               1       => array
+                               (
+                                       'value' => 
$GLOBALS['phpgw_setup']->oProc->f('building_id'),
+                                       'type'  => 1 //PDO::PARAM_INT
+                               ),
+                               2       => array
+                               (
+                                       'value' => 
$GLOBALS['phpgw_setup']->oProc->f('id'),
+                                       'type'  =>      1 //PDO::PARAM_INT
+                               )
+                       );
+               }
+
+               if($valueset)
+               {
+                       $GLOBALS['phpgw_setup']->oProc->m_odb->insert($sql, 
$valueset, __LINE__, __FILE__);
+               }
+
+               $GLOBALS['phpgw_setup']->oProc->DropColumn('bb_resource', 
array(), 'building_id');
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['booking']['currentver'] = 
'0.2.27';
+                       return $GLOBALS['setup_info']['booking']['currentver'];
+               }
+       }

Modified: branches/dev-syncromind/booking/templates/base/resource.xsl
===================================================================
--- branches/dev-syncromind/booking/templates/base/resource.xsl 2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/templates/base/resource.xsl 2016-02-01 
10:13:06 UTC (rev 14685)
@@ -7,6 +7,14 @@
                        <div id="resource" class="booking-container">
                                <div class="pure-control-group">
                                        <label>
+                                               <xsl:value-of 
select="php:function('lang', 'Name')" />
+                                       </label>
+                                       <div class="custom-container">
+                                               <xsl:value-of 
select="resource/name" disable-output-escaping="yes"/>
+                                       </div>
+                               </div>
+                               <div class="pure-control-group">
+                                       <label>
                                                <xsl:value-of 
select="php:function('lang', 'Description')" />
                                        </label>
                                        <div class="custom-container">
@@ -15,11 +23,21 @@
                                </div>
                                <div class="pure-control-group">
                                        <label>
-                                               <xsl:value-of 
select="php:function('lang', 'Building')" />
+                                               <xsl:value-of 
select="php:function('lang', 'Building')"/>
                                        </label>
-                                       <span>
-                                               <xsl:value-of 
select="resource/building_name"/>
-                                       </span>
+                                       <div class = 'pure-u-md-1-2'>
+                                               <xsl:for-each 
select="datatable_def">
+                                                       <xsl:if test="container 
= 'datatable-container_0'">
+                                                               
<xsl:call-template name="table_setup">
+                                                                       
<xsl:with-param name="container" select ='container'/>
+                                                                       
<xsl:with-param name="requestUrl" select ='requestUrl'/>
+                                                                       
<xsl:with-param name="ColumnDefs" select ='ColumnDefs'/>
+                                                                       
<xsl:with-param name="data" select ='data'/>
+                                                                       
<xsl:with-param name="config" select ='config'/>
+                                                               
</xsl:call-template>
+                                                       </xsl:if>
+                                               </xsl:for-each>
+                                       </div>
                                </div>
                                <div class="pure-control-group">
                                        <label>
@@ -28,6 +46,11 @@
                                        <span>
                                                <xsl:value-of 
select="resource/activity_name"/>
                                        </span>
+                                       <script type="text/javascript">
+                                               var default_schema = 
"<xsl:value-of select="resource/activity_name"/>";
+                                               var schema_type = "view";
+                                       </script>
+
                                </div>
                                <div class="pure-control-group">
                                        <label>

Modified: branches/dev-syncromind/booking/templates/base/resource_form.xsl
===================================================================
--- branches/dev-syncromind/booking/templates/base/resource_form.xsl    
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/booking/templates/base/resource_form.xsl    
2016-02-01 10:13:06 UTC (rev 14685)
@@ -1,7 +1,9 @@
 <xsl:template match="data" xmlns:php="http://php.net/xsl";>
        <xsl:call-template name="msgbox"/>
        <script type="text/javascript">
-               var resource_id = <xsl:value-of select="resource/id"/>;
+               var resource_id = "<xsl:value-of select="resource/id"/>";
+               var default_schema = "<xsl:value-of 
select="resource/activity_name"/>";
+               var schema_type = "form";
        </script>
 
        <form action="" method="POST" id="form" class="pure-form 
pure-form-aligned" name="form">
@@ -22,49 +24,92 @@
                                                </xsl:attribute>
                                        </input>
                                </div>
+                               <xsl:if test="not(new_form)">
+                                       <div class="pure-control-group">
+                                               <label>
+                                                       <xsl:value-of 
select="php:function('lang', 'Activity')" />
+                                               </label>
+                                               <input 
id="field_schema_activity_id" type="hidden" name="schema_activity_id" value=""/>
+                                               <select id="field_activity_id" 
name="activity_id">
+                                                       <xsl:for-each 
select="activitydata/results">
+                                                               <option 
value="{id}">
+                                                                       <xsl:if 
test="resource_id=id">
+                                                                               
<xsl:attribute name="selected">selected</xsl:attribute>
+                                                                       
</xsl:if>
+                                                                       
<xsl:value-of select="name" />
+                                                               </option>
+                                                       </xsl:for-each>
+                                               </select>
+                                       </div>
+                               </xsl:if>
                                <div class="pure-control-group">
                                        <label>
-                                               <xsl:value-of 
select="php:function('lang', 'Activity')" />
-                                       </label>
-                                       <select id="field_activity_id" 
name="activity_id">
-                                               <xsl:for-each 
select="activitydata/results">
-                                                       <option value="{id}">
-                                                               <xsl:if 
test="resource_id=id">
-                                                                       
<xsl:attribute name="selected">selected</xsl:attribute>
-                                                               </xsl:if>
-                                                               <xsl:value-of 
select="name" />
-                                                       </option>
-                                               </xsl:for-each>
-                                       </select>
-                               </div>
-                               <div class="pure-control-group">
-                                       <label>
                                                <xsl:value-of 
select="php:function('lang', 'Sort order')" />
                                        </label>
                                        <input name="sort" id="field_sort" 
type="text" value="{resource/sort}"/>
                                </div>
+                               <xsl:if test="not(new_form)">
+                                       <div class="pure-control-group">
+                                               <label>
+                                                       <xsl:value-of 
select="php:function('lang', 'Building')"/>
+                                               </label>
+                                               <div class = 'pure-u-md-1-2'>
+                                                       <xsl:for-each 
select="datatable_def">
+                                                               <xsl:if 
test="container = 'datatable-container_0'">
+                                                                       
<xsl:call-template name="table_setup">
+                                                                               
<xsl:with-param name="container" select ='container'/>
+                                                                               
<xsl:with-param name="requestUrl" select ='requestUrl'/>
+                                                                               
<xsl:with-param name="ColumnDefs" select ='ColumnDefs'/>
+                                                                               
<xsl:with-param name="data" select ='data'/>
+                                                                               
<xsl:with-param name="config" select ='config'/>
+                                                                       
</xsl:call-template>
+                                                               </xsl:if>
+                                                       </xsl:for-each>
+                                               </div>
+                                       </div>
+                               </xsl:if>
                                <div class="pure-control-group">
                                        <label>
                                                <xsl:value-of 
select="php:function('lang', 'Building')" />
                                        </label>
-                                       <xsl:if test="new_form or 
resource/permission/write/building_id">
-                                               <input id="field_building_id" 
name="building_id" type="hidden" value="{resource/building_id}"/>
-                                       </xsl:if>
-                                       <input id="field_building_name" 
name="building_name" type="text" value="{resource/building_name}">
-                                               <xsl:if test="not(new_form) and 
not(resource/permission/write/building_id)">
-                                                       <xsl:attribute 
name="disabled">disabled</xsl:attribute>
+                                       <input id="field_building_id" 
name="building_id" type="hidden" value=""/>
+                                       <input id="field_building_name" 
name="building_name" type="text" value="">
+                                               <xsl:if test="new_form">
+                                                       <xsl:attribute 
name="data-validation">
+                                                               
<xsl:text>required</xsl:text>
+                                                       </xsl:attribute>
+                                                       <xsl:attribute 
name="data-validation-error-msg">
+                                                               <xsl:value-of 
select="php:function('lang', 'Please enter a building name')" />
+                                                       </xsl:attribute>
                                                </xsl:if>
-                                               <xsl:attribute 
name="data-validation">
-                                                       
<xsl:text>required</xsl:text>
-                                               </xsl:attribute>
-                                               <xsl:attribute 
name="data-validation-error-msg">
-                                                       <xsl:value-of 
select="php:function('lang', 'Please enter a building name')" />
-                                               </xsl:attribute>
                                        </input>
                                        <div id="building_container" 
class="custom-container"></div>
+                                       <xsl:if 
test="resource/permission/write">
+                                               <a class='button'>
+                                                       <xsl:attribute 
name="onClick">
+                                                               
<xsl:text>addBuilding()</xsl:text>
+                                                       </xsl:attribute>
+                                                       <xsl:value-of 
select="php:function('lang', 'Add')" />
+                                               </a>
+                                               <xsl:text> | </xsl:text>
+                                               <a class='button'>
+                                                       <xsl:attribute 
name="onClick">
+                                                               
<xsl:text>removeBuilding()</xsl:text>
+                                                       </xsl:attribute>
+                                                       <xsl:value-of 
select="php:function('lang', 'Delete')" />
+                                               </a>
+                                       </xsl:if>
+
                                </div>
                                <div class="pure-control-group">
                                        <label>
+                                               <div id="schema_name"></div>
+                                       </label>
+                               </div>
+                               <div id="custom_fields"></div>
+
+                               <div class="pure-control-group">
+                                       <label>
                                                <xsl:value-of 
select="php:function('lang', 'Resource Type')" />
                                        </label>
                                        <select name='type' id='field_type'>
@@ -117,7 +162,6 @@
                                                </textarea>
                                        </div>
                                </div>
-                               <div id="custom_fields"></div>
                                <div class="pure-control-group">
                                        <label>
                                                <xsl:value-of 
select="php:function('lang', 'organzations_ids')" />

Modified: branches/dev-syncromind/bookingfrontend/inc/class.bosearch.inc.php
===================================================================
--- branches/dev-syncromind/bookingfrontend/inc/class.bosearch.inc.php  
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/bookingfrontend/inc/class.bosearch.inc.php  
2016-02-01 10:13:06 UTC (rev 14685)
@@ -137,10 +137,23 @@
                                        
$_filter_resource['custom_fields_criteria'] = $activity_criteria;
                                }
 
-                               $res_result = 
$this->soresource->read(array("query" => $searchterm, "sort" => "name",
+                               $_res_result = 
$this->soresource->read(array("query" => $searchterm, "sort" => "name",
                                        "dir" => "asc", "filters" => 
$_filter_resource));
-                               foreach($res_result['results'] as &$res)
+
+                               $_check_duplicate = array();
+                               $res_result = array(
+                                       'total_records' => 0,
+                                       'start' => $_res_result['start'],
+                                       'sort' => $_res_result['sort'],
+                                       'dir' => $_res_result['dir']
+                               );
+                               foreach($_res_result['results'] as &$res)
                                {
+                                       if(isset($_check_duplicate[$res['id']]))
+                                       {
+                                               continue;
+                                       }
+
                                        
$_resource_buildings[$res['building_id']] = true;
                                        $res['name']                     = 
$res['building_name'] . ' / ' . $res['name'];
                                        $res['type']                     = 
"resource";
@@ -149,6 +162,12 @@
                                        $res['img_container']    = "resource-" 
. $res['id'];
                                        $res['img_url']                  = 
$GLOBALS['phpgw']->link('/bookingfrontend/', array('menuaction' => 
'bookingfrontend.uidocument_resource.index_images',
                                                'filter_owner_id' => 
$res['id'], 'phpgw_return_as' => 'json', 'results' => '1'));
+
+                                       $_check_duplicate[$res['id']] = true;
+
+                                       $res_result['total_records'] ++;
+                                       $res_result['results'][] = $res;
+
                                }
 
                                if(isset($bui_result['total_records']) && 
$bui_result['total_records'] > 0)

Modified: branches/dev-syncromind/bookingfrontend/inc/class.uiresource.inc.php
===================================================================
--- branches/dev-syncromind/bookingfrontend/inc/class.uiresource.inc.php        
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/bookingfrontend/inc/class.uiresource.inc.php        
2016-02-01 10:13:06 UTC (rev 14685)
@@ -7,19 +7,19 @@
                public $public_functions = array
                        (
                        'index_json' => true,
-                       'query'          => true,
-                       'show'           => true,
+                       'query' => true,
+                       'show' => true,
                        'get_custom' => true,
-                       'schedule'       => true
+                       'schedule' => true
                );
 
                public function __construct()
                {
                        parent::__construct();
-                       $this->bo                        = 
CreateObject('booking.boresource');
-                       $this->building_bo       = 
CreateObject('booking.bobuilding');
-                       $this->activity_bo       = 
CreateObject('booking.boactivity');
-                       $old_top                         = 
array_pop($this->tmpl_search_path);
+                       $this->bo = CreateObject('booking.boresource');
+                       $this->building_bo = CreateObject('booking.bobuilding');
+                       $this->activity_bo = CreateObject('booking.boactivity');
+                       $old_top = array_pop($this->tmpl_search_path);
                        array_push($this->tmpl_search_path, PHPGW_SERVER_ROOT . 
'/bookingfrontend/templates/base');
                        array_push($this->tmpl_search_path, $old_top);
                }
@@ -28,9 +28,9 @@
                {
                        if($sub_activity_id = phpgw::get_var('sub_activity_id'))
                        {
-                               $activity_path                                  
 = ExecMethod('booking.boactivity.get_path', $sub_activity_id);
-                               $top_level_activity                             
 = $activity_path ? $activity_path[0]['id'] : -1;
-                               $_REQUEST['filter_activity_id']  = 
$top_level_activity;
+                               $activity_path = 
ExecMethod('booking.boactivity.get_path', $sub_activity_id);
+                               $top_level_activity = $activity_path ? 
$activity_path[0]['id'] : -1;
+                               $_REQUEST['filter_activity_id'] = 
$top_level_activity;
                        }
                        return 
$this->bo->populate_grid_data("bookingfrontend.uiresource.show");
                }
@@ -42,18 +42,34 @@
 
                public function show()
                {
-                       $resource                                        = 
$this->bo->read_single(phpgw::get_var('id', 'int', 'GET'));
-                       $resource['building']            = 
ExecMethod('booking.bobuilding.read_single', $resource['building_id']);
-                       $resource['building_link']       = 
self::link(array('menuaction' => 'bookingfrontend.uibuilding.show',
+                       $resource = $this->bo->read_single(phpgw::get_var('id', 
'int', 'GET'));
+                       $pathway = array();
+                       $lang_home = lang('home');
+                       foreach($resource['buildings'] as $building_id)
+                       {
+                               $building = 
$this->building_bo->read_single($building_id);
+                               $pathway[] = array(
+                                       'lang_home' => $lang_home,
+                                       'building_name' => $building['name'],
+                                       'building_name' => $building['name'],
+                                       'building_link' => 
self::link(array('menuaction' => 'bookingfrontend.uibuilding.show',
+                                               'id' => $building['id'])),
+                                       'resource_name' => $resource['name'],
+                               );
+                       }
+
+//                     $resource['building']            = 
ExecMethod('booking.bobuilding.read_single', $resource['building_id']);
+                       $resource['building_link'] = 
self::link(array('menuaction' => 'bookingfrontend.uibuilding.show',
                                'id' => $resource['building_id']));
-                       $resource['buildings_link']      = 
self::link(array('menuaction' => 'bookingfrontend.uisearch.index',
+                       $resource['buildings_link'] = 
self::link(array('menuaction' => 'bookingfrontend.uisearch.index',
                                'type' => 'building'));
-                       $resource['resources_link']      = 
self::link(array('menuaction' => 'bookingfrontend.uisearch.index',
+                       $resource['resources_link'] = 
self::link(array('menuaction' => 'bookingfrontend.uisearch.index',
                                'type' => 'resource'));
-                       $resource['schedule_link']       = 
self::link(array('menuaction' => 'bookingfrontend.uiresource.schedule',
+                       $resource['schedule_link'] = 
self::link(array('menuaction' => 'bookingfrontend.uiresource.schedule',
                                'id' => $resource['id']));
-                       $data                                            = 
array(
-                               'resource' => $resource
+                       $data = array(
+                               'resource' => $resource,
+                               'pathway'       => $pathway
                        );
 
                        self::render_template_xsl('resource', $data);
@@ -61,26 +77,26 @@
 
                private function get_location()
                {
-                       $activity_id             = 
phpgw::get_var('activity_id', 'int');
-                       $activity_path           = 
$this->activity_bo->get_path($activity_id);
-                       $top_level_activity      = $activity_path ? 
$activity_path[0]['id'] : 0;
+                       $activity_id = phpgw::get_var('activity_id', 'int');
+                       $activity_path = 
$this->activity_bo->get_path($activity_id);
+                       $top_level_activity = $activity_path ? 
$activity_path[0]['id'] : 0;
                        return ".resource.{$top_level_activity}";
                }
 
                public function get_custom()
                {
-                       $resource_id            = phpgw::get_var('resource_id', 
'int');
-                       $resource                       = 
$this->bo->read_single($resource_id);
-                       $custom_values          = 
$resource['json_representation']->data;
+                       $resource_id = phpgw::get_var('resource_id', 'int');
+                       $resource = $this->bo->read_single($resource_id);
+                       $location = $this->get_location();
+                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('booking', $location);
+                       $custom_values = 
$resource['json_representation'][$location_id];
 //                     _debug_array($custom_values);
 
-
-                       $location                        = 
$this->get_location();
-                       $custom_fields          = 
createObject('booking.custom_fields');
-                       $fields = $custom_fields->get_fields($location);
+                       $custom_fields = createObject('booking.custom_fields');
+                       $fields = $custom_fields->get_fields($location);
                        foreach($fields as $attrib_id => &$attrib)
                        {
-                               $attrib['value'] = 
isset($custom_values->$attrib['name']) ? $custom_values->$attrib['name'] : null;
+                               $attrib['value'] = 
isset($custom_values[$attrib['name']]) ? $custom_values[$attrib['name']] : null;
 
                                if(isset($attrib['choice']) && 
is_array($attrib['choice']) && $attrib['value'])
                                {
@@ -97,11 +113,11 @@
                                        }
                                }
                        }
-                       $organized_fields        = 
$custom_fields->organize_fields($location, $fields);
+                       $organized_fields = 
$custom_fields->organize_fields($location, $fields);
 //                     _debug_array($organized_fields);
 
                        $data = array(
-                               'attributes_group'      => $organized_fields,
+                               'attributes_group' => $organized_fields,
                        );
                        
$GLOBALS['phpgw']->xslttpl->add_file(array('attributes_view'));
                        $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('custom_fields' => $data));
@@ -109,30 +125,55 @@
 
                public function schedule()
                {
-                       $resource                                               
         = $this->bo->get_schedule(phpgw::get_var('id', 'int', 'GET'), 
'bookingfrontend.uibuilding', 'bookingfrontend.uiresource', 
'bookingfrontend.uisearch.index');
-                       $building                                               
         = $this->building_bo->read_single($resource['building_id']);
-                       $resource['deactivate_application']      = 
$building['deactivate_application'];
+                       $resource = 
$this->bo->get_schedule(phpgw::get_var('id', 'int', 'GET'), 
'bookingfrontend.uibuilding', 'bookingfrontend.uiresource', 
'bookingfrontend.uisearch.index');
+                       /*FIXME: Sigurd: handle multiple buildings*/
+
+                       $pathway = array();
+                       $lang_home = lang('home');
+                       $lang_schedule = lang('schedule');
+                       foreach($resource['buildings'] as $building_id)
+                       {
+                               $building = 
$this->building_bo->read_single($building_id);
+                               $pathway[] = array(
+                                       'lang_home' => $lang_home,
+                                       'building_name' => $building['name'],
+                                       'building_name' => $building['name'],
+                                       'building_link' => 
self::link(array('menuaction' => 'bookingfrontend.uibuilding.show',
+                                               'id' => $building['id'])),
+                                       'resource_name' => $resource['name'],
+                                       'resource_link' => 
self::link(array('menuaction' => 'bookingfrontend.uiresource.show',
+                                               'id' => $resource['id'])),
+                                       'lang_schedule' => $lang_schedule,
+                               );
+                       }
+
+                       //$building = 
$this->building_bo->read_single($resource['building_id']);
+
+                       $building = 
$this->building_bo->read_single($resource['buildings'][0]);
+                       $resource['deactivate_application'] = 
$building['deactivate_application'];
                        if($building['deactivate_application'] == 0)
                        {
-                               $resource['application_link'] = 
self::link(array('menuaction'    => 'bookingfrontend.uiapplication.add',
-                                       'building_id'    => 
$resource['building_id'],
-                                       'building_name'  => 
$resource['building_name'],
-                                       'resource'               => 
$resource['id']));
+                               $resource['application_link'] = 
self::link(array('menuaction' => 'bookingfrontend.uiapplication.add',
+               //                      'building_id' => 
$resource['building_id'],
+               //                      'building_name' => 
$resource['building_name'],
+                                       'building_id' => $building['id'],
+                                       'building_name' => $building['name'],
+                                       'resource' => $resource['id']));
                        }
                        else
                        {
                                $resource['application_link'] = 
self::link(array('menuaction' => 'bookingfrontend.uiresource.schedule',
-                                       'id'             => $resource['id']));
+                                       'id' => $resource['id']));
                        }
-                       $resource['datasource_url']      = self::link(array(
-                               'menuaction'             => 
'bookingfrontend.uibooking.resource_schedule',
-                               'resource_id'            => $resource['id'],
-                               'phpgw_return_as'        => 'json',
+                       $resource['datasource_url'] = self::link(array(
+                               'menuaction' => 
'bookingfrontend.uibooking.resource_schedule',
+                               'resource_id' => $resource['id'],
+                               'phpgw_return_as' => 'json',
                        ));
                        self::add_javascript('bookingfrontend', 
'bookingfrontend', 'schedule.js');
                        phpgwapi_jquery::load_widget("datepicker");
-                       $resource['picker_img']          = 
$GLOBALS['phpgw']->common->image('phpgwapi', 'cal');
+                       $resource['picker_img'] = 
$GLOBALS['phpgw']->common->image('phpgwapi', 'cal');
 
-                       self::render_template_xsl('resource_schedule', 
array('resource' => $resource,));
+                       self::render_template_xsl('resource_schedule', 
array('resource' => $resource,'pathway'  => $pathway));
                }
        }
\ No newline at end of file

Modified: branches/dev-syncromind/bookingfrontend/js/bookingfrontend/schedule.js
===================================================================
--- branches/dev-syncromind/bookingfrontend/js/bookingfrontend/schedule.js      
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/bookingfrontend/js/bookingfrontend/schedule.js      
2016-02-01 10:13:06 UTC (rev 14685)
@@ -43,7 +43,7 @@
                changeMonth: true,
                changeYear: true,
                firstDay: 1,
-               dateFormat: 'dd/mm/yy',
+               dateFormat: 'yy,mm,dd',
                onSelect: function (a, e) {
                        if (a != schedule.dateSelected) {
                                var date = new Date(a);

Modified: branches/dev-syncromind/bookingfrontend/setup/setup.inc.php
===================================================================
--- branches/dev-syncromind/bookingfrontend/setup/setup.inc.php 2016-01-27 
12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/bookingfrontend/setup/setup.inc.php 2016-02-01 
10:13:06 UTC (rev 14685)
@@ -21,7 +21,7 @@
 
        $setup_info['bookingfrontend']['depends'][] = array(
                'appname' => 'booking',
-               'versions' => 
array('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.2.25','0.2.26')
+               'versions' => 
array('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.2.25','0.2.26','0.2.27')
        );
 
        $setup_info['bookingfrontend']['depends'][] = array(

Modified: branches/dev-syncromind/bookingfrontend/templates/base/resource.xsl
===================================================================
--- branches/dev-syncromind/bookingfrontend/templates/base/resource.xsl 
2016-01-27 12:24:06 UTC (rev 14684)
+++ branches/dev-syncromind/bookingfrontend/templates/base/resource.xsl 
2016-02-01 10:13:06 UTC (rev 14685)
@@ -1,20 +1,23 @@
 <xsl:template match="data" xmlns:php="http://php.net/xsl";>
        <div id="content">
-               <ul class="pathway">
-                       <li>
-                               <a 
href="index.php?menuaction=bookingfrontend.uisearch.index">
-                                       <xsl:value-of 
select="php:function('lang', 'Home')" />
-                               </a>
-                       </li>
-                       <li>
-                               <a href="{resource/building_link}">
-                                       <xsl:value-of 
select="resource/building_name"/>
-                               </a>
-                       </li>
-                       <li>
-                               <xsl:value-of select="resource/name"/>
-                       </li>
-               </ul>
+               <xsl:for-each select="pathway">
+                       <ul class="pathway">
+                               <li>
+                                       <a 
href="index.php?menuaction=bookingfrontend.uisearch.index">
+                                               <xsl:value-of 
select="lang_home" />
+                                       </a>
+                               </li>
+                               <li>
+                                       <a href="{building_link}">
+                                               <xsl:value-of 
select="building_name"/>
+                                       </a>
+                               </li>
+                               <li>
+                                       <xsl:value-of select="resource_name"/>
+                               </li>
+                       </ul>                   
+               </xsl:for-each>
+
                <div>
                        <button 
onclick="window.location.href='{resource/schedule_link}'">
                                <xsl:value-of select="php:function('lang', 
'Resource schedule')" />

Modified: 
branches/dev-syncromind/bookingfrontend/templates/base/resource_schedule.xsl
===================================================================
--- 
branches/dev-syncromind/bookingfrontend/templates/base/resource_schedule.xsl    
    2016-01-27 12:24:06 UTC (rev 14684)
+++ 
branches/dev-syncromind/bookingfrontend/templates/base/resource_schedule.xsl    
    2016-02-01 10:13:06 UTC (rev 14685)
@@ -1,33 +1,30 @@
 <xsl:template match="data" xmlns:php="http://php.net/xsl";>
        
        <div id="content">
-               <ul class="pathway">
-                       <li>
-                               <a 
href="index.php?menuaction=bookingfrontend.uisearch.index">
-                                       <xsl:value-of 
select="php:function('lang', 'Home')" />
-                               </a>
-                       </li>
-                       <li>
-                               <a>
-                                       <xsl:attribute name="href">
-                                               <xsl:value-of 
select="resource/building_link"/>
-                                       </xsl:attribute>
-                                       <xsl:value-of 
select="resource/building_name"/>
-                               </a>
-                       </li>
-                       <li>
-                               <a>
-                                       <xsl:attribute name="href">
-                                               <xsl:value-of 
select="resource/resource_link"/>
-                                       </xsl:attribute>
-                                       <xsl:value-of select="resource/name"/>
-                               </a>
-                       </li>
-                       <li>
-                               <xsl:value-of select="php:function('lang', 
'schedule')"/>
-                       </li>
-               </ul>
+               <xsl:for-each select="pathway">
+                       <ul class="pathway">
+                               <li>
+                                       <a 
href="index.php?menuaction=bookingfrontend.uisearch.index">
+                                               <xsl:value-of 
select="lang_home" />
+                                       </a>
+                               </li>
+                               <li>
+                                       <a href="{building_link}">
+                                               <xsl:value-of 
select="building_name"/>
+                                       </a>
+                               </li>
+                               <li>
+                                       <a href="{resource_link}">
+                                               <xsl:value-of 
select="resource_name"/>
+                                       </a>
+                               </li>
+                               <li>
+                                       <xsl:value-of select="lang_schedule"/>
+                               </li>
+                       </ul>
+               </xsl:for-each>
 
+
                <button 
onclick="window.location.href='{resource/application_link}'">
                        <xsl:value-of select="php:function('lang', 'New booking 
application')" />
                </button>




reply via email to

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