fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11987] Start implementing yui3 for tables


From: Sigurd Nes
Subject: [Fmsystem-commits] [11987] Start implementing yui3 for tables
Date: Thu, 22 May 2014 14:09:29 +0000

Revision: 11987
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11987
Author:   sigurdne
Date:     2014-05-22 14:09:28 +0000 (Thu, 22 May 2014)
Log Message:
-----------
Start implementing yui3 for tables

Modified Paths:
--------------
    trunk/frontend/inc/class.uientity.inc.php
    trunk/phpgwapi/inc/class.uicommon.inc.php
    trunk/property/inc/class.bodocument.inc.php
    trunk/property/templates/base/admin_entity.xsl

Added Paths:
-----------
    trunk/phpgwapi/js/yui3/common.js
    trunk/phpgwapi/js/yui3/datatable.js
    trunk/property/inc/class.uidocument2.inc.php

Modified: trunk/frontend/inc/class.uientity.inc.php
===================================================================
--- trunk/frontend/inc/class.uientity.inc.php   2014-05-22 10:12:03 UTC (rev 
11986)
+++ trunk/frontend/inc/class.uientity.inc.php   2014-05-22 14:09:28 UTC (rev 
11987)
@@ -638,6 +638,13 @@
                                                                        
$datatable['rows']['row'][$j]['column'][$i]['link']                     = 
$entity_entry[$uicols['name'][$i]];
                                                                        
$datatable['rows']['row'][$j]['column'][$i]['target']      = '_blank';
                                                                }
+                                                               //override 
action
+                                                               
if(isset($uicols['javascript_action']) && 
isset($uicols['javascript_action'][$uicols['name'][$i]]))
+                                                               {
+                                                                       
$datatable['rows']['row'][$j]['column'][$i]['format']                           
= 'javascript_action';          
+                                                                       
$datatable['rows']['row'][$j]['column'][$i]['javascript_action']        = 
$entity_entry[$uicols['name'][$i]];
+                                                                       
$datatable['rows']['row'][$j]['column'][$i]['value']                            
= $uicols['descr'][$i];
+                                                               }
                                                        }
                                                }
                                                else
@@ -821,10 +828,13 @@
                        unset($parameters);
 
                        //$uicols_count indicates the number of columns to 
display in actuall option-menu. this variable was set in $this->bo->read()
-                       $link = $GLOBALS['phpgw']->link(
+                       if(!isset($uicols['javascript_action']) || 
!$uicols['javascript_action'])
+                       {
+                               $link = $GLOBALS['phpgw']->link(
                                        '/index.php',
                                        array('menuaction'      => 
'frontend.uientity.view'));
-                       $datatable['exchange_values'] = "document.location = 
'{$link}&id=' + data.getData().id + '&location_id={$this->location_id}';";
+                               $datatable['exchange_values'] = 
"document.location = '{$link}&id=' + data.getData().id + 
'&location_id={$this->location_id}';";
+                       }
 
 
                        $uicols_count   = count($uicols['descr']);
@@ -929,6 +939,10 @@
                                                {
                                                        
$json_row[$column['name']] = "<a href='".$column['link']."' target='_blank'>" 
.$column['value']."</a>";
                                                }
+                                               else 
if(isset($column['format']) && $column['format']== "javascript_action")
+                                               {
+                                                       
$json_row[$column['name']] = "<a href='#' title='{$column['statustext']}' 
onclick='javascript:{$column['javascript_action']}'>{$column['value']}</a>";
+                                               }
                                                else
                                                {
                                                        
$json_row[$column['name']] = $column['value'];

Modified: trunk/phpgwapi/inc/class.uicommon.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.uicommon.inc.php   2014-05-22 10:12:03 UTC (rev 
11986)
+++ trunk/phpgwapi/inc/class.uicommon.inc.php   2014-05-22 14:09:28 UTC (rev 
11987)
@@ -53,9 +53,10 @@
 
        //      public $flash_msgs;
 
-               public function __construct($currentapp ='')
+               public function __construct($currentapp ='', $yui = '')
                {
 
+                       $yui = isset($yui) && $yui == 'yui3' ? 'yui3' : 'yahoo';
                        $currentapp = $currentapp ? $currentapp : 
$GLOBALS['phpgw_info']['flags']['currentapp'];
 
                //      self::set_active_menu('controller');
@@ -81,7 +82,7 @@
                        phpgwapi_yui::load_widget('autocomplete');
                        phpgwapi_yui::load_widget('animation');
 
-                       self::add_javascript('phpgwapi', 'yahoo', 'common.js');
+                       self::add_javascript('phpgwapi', $yui, 'common.js');
 
                        $this->url_prefix = str_replace('_', '.', 
get_class($this));
 

Added: trunk/phpgwapi/js/yui3/common.js
===================================================================
--- trunk/phpgwapi/js/yui3/common.js                            (rev 0)
+++ trunk/phpgwapi/js/yui3/common.js    2014-05-22 14:09:28 UTC (rev 11987)
@@ -0,0 +1,1154 @@
+/*$Id: yui_booking_i18n.xsl 8267 2011-12-11 12:27:18Z sigurdne $*/
+YAHOO.namespace('portico');
+
+YAHOO.portico.js_alias_method_chain = function(constructor_func, func_name, 
new_feature_name, feature_impl_func) {
+       constructor_func.prototype[func_name+'_without_'+new_feature_name] = 
constructor_func.prototype[func_name];
+       constructor_func.prototype[func_name+'_with_'+new_feature_name] = 
feature_impl_func;
+       constructor_func.prototype[func_name] = 
constructor_func.prototype[func_name+'_with_'+new_feature_name];
+};
+
+YAHOO.portico.lang = function(section, config) {
+       config = config || {};
+       if (YAHOO && YAHOO.portico && YAHOO.portico.i18n && 
YAHOO.portico.i18n[section]) {
+               YAHOO.portico.i18n[section](config);
+       }
+       return config;
+};
+
+
+YAHOO.portico.FormatterAmount0 = function(elCell, oRecord, oColumn, oData)
+{
+       var amount = YAHOO.util.Number.format(oData, {decimalPlaces:0, 
decimalSeparator:",", thousandsSeparator:" "});
+       elCell.innerHTML = "<div class='nowrap' 
align=\"right\">"+amount+"</div>";
+}      
+
+
+/** Hook widgets to translations **/
+YAHOO.portico.js_alias_method_chain(YAHOO.widget.Calendar, 'init', 'i18n', 
function(id, container, config) {
+       YAHOO.portico.lang('Calendar', config);
+       return this.init_without_i18n(id, container, config);
+});
+
+YAHOO.portico.js_alias_method_chain(YAHOO.widget.DataTable, '_initConfigs', 
'i18n', function(config) {
+       YAHOO.portico.lang('DataTable', config);
+       return this._initConfigs_without_i18n(config);
+});
+
+function y2k(number) { return (number < 1000) ? number + 1900 : number; }
+YAHOO.portico.weeknumber = function(when) {
+       var year = when.getFullYear();
+       var month = when.getMonth();
+       var day = when.getDate();
+
+       var newYear = new Date(year,0,1);
+       var modDay = newYear.getDay();
+       if (modDay == 0) modDay=6; else modDay--;
+
+       var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) 
- Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;
+
+  if (modDay < 4 ) {
+       var weeknum = Math.floor((daynum+modDay-1)/7)+1;
+  } else {
+       var weeknum = Math.floor((daynum+modDay-1)/7);
+       if (weeknum == 0) {
+         year--;
+         var prevNewYear = new Date(year,0,1);
+         var prevmodDay = prevNewYear.getDay();
+         if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;
+         if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
+       }
+  }
+  return + weeknum;
+}
+
+parseISO8601 = function (string) {
+       var regexp = "(([0-9]{4})(-([0-9]{1,2})(-([0-9]{1,2}))))?( 
)?(([0-9]{1,2}):([0-9]{1,2}))?";
+       var d = string.match(new RegExp(regexp));
+       var year = d[2] ? (d[2] * 1) : 0;
+       date = new Date(year, (d[4]||1)-1, d[6]||0);
+       if(d[9])
+               date.setHours(d[9]);
+       if(d[10])
+               date.setMinutes(d[10]);
+       return date;
+};
+
+YAHOO.portico.serializeForm = function(formID) {
+       var form = YAHOO.util.Dom.get(formID);
+       var values = [];
+       for(var i=0; i < form.elements.length; i++) {
+               var e = form.elements[i];
+               if(e.type=='checkbox' || e.type=='radio') {
+                       if(e.checked) {
+                               values.push(e.name + '=' + 
encodeURIComponent(e.value));
+                       }
+               } 
+               else if(e.name) {
+                       values.push(e.name + '=' + encodeURIComponent(e.value));
+               }
+       }
+       return values.join('&');
+};
+
+YAHOO.portico.fillForm = function(formID, params) {
+       var form = YAHOO.util.Dom.get(formID);
+       var values = [];
+       for(var i=0; i < form.elements.length; i++) {
+               var e = form.elements[i];
+               if((e.type=='checkbox' || e.type=='radio') && params[e.name]) {
+                       e.checked = true;
+               } 
+               else if(e.name && params[e.name] != undefined) {
+                       e.value = params[e.name];
+                       if(e._update) { // Is this connected to a date picker?
+                               e._update();
+                       }
+               }
+       }
+       return values.join('&');
+};
+
+YAHOO.portico.parseQS = function(qs) {
+       qs = qs.replace(/\+/g, ' ');
+       var args = qs.split('&');
+       var params = {};
+       for (var i = 0; i < args.length; i++) {
+               var pair = args[i].split('=');
+               var name = decodeURIComponent(pair[0]);
+               var value = (pair.length==2) ? decodeURIComponent(pair[1]) : 
name;
+               params[name] = value;
+       }
+       return params;
+}
+
+YAHOO.portico.formatLink = function(elCell, oRecord, oColumn, oData) { 
+       var name = oRecord.getData(oColumn.key);
+       var link = oRecord.getData('link');
+       elCell.innerHTML = '<a href="' + link + '">' + name + '</a>'; 
+};
+
+YAHOO.portico.formatGenericLink = function(elCell, oRecord, oColumn, oData)
+{
+       var data = oRecord.getData(oColumn.key);
+       //console.log(data['href']);
+       var link = data['href'];
+       var name = data['label'];
+       
+       elCell.innerHTML = '<a href="' + link + '">' + name + '</a>';
+};
+
+/*
+YAHOO.portico.formatGenericLink = function() {
+       var links = [];
+       var nOfLinks = arguments.length;
+
+       for (var i=0; i < nOfLinks; i++) { links[i] = arguments[i]; }
+       
+       return function(elCell, oRecord, oColumn, oData)
+       {
+               var nOfLinks = links.length;
+               var data = oRecord.getData(oColumn.key);
+               
+               var linksHtml = '';
+               if (nOfLinks > 0) {
+                       //Use specified link names
+                       for (var i=0; i < nOfLinks; i++) {
+                               if (data[i])
+                               {
+                                       linksHtml += '<div><a href="' + data[i] 
+ '">' + links[i] + '</a></div>';
+                               }
+                       }
+               } else {
+                       //Get label from embedded data
+                       if (data['href'] != undefined && data['label'] != 
undefined) {
+                               linksHtml += '<div><a href="' + data['href'] + 
'">' + data['label'] + '</a></div>';
+                       } else if(data['href'] == undefined && data['label'] != 
undefined) {
+                               linksHtml += '<div>'+data['label']+'</div>';
+                       }
+               }
+               
+               elCell.innerHTML = linksHtml;
+       };
+};
+*/
+YAHOO.portico.autocompleteHelper = function(url, field, hidden, container, 
label_attr) {
+       url += '&';
+       label_attr = label_attr || 'name';
+       var myDataSource = new YAHOO.util.DataSource(url);
+       myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+       myDataSource.connXhrMode = "queueRequests";
+       myDataSource.responseSchema = {
+               resultsList: "ResultSet.Result",
+               fields: [label_attr, 'id']
+       };
+       myDataSource.maxCacheEntries = 5; 
+       var ac = new YAHOO.widget.AutoComplete(field, container, myDataSource);
+       ac.queryQuestionMark = false;
+       ac.resultTypeList = false;
+       ac.forceSelection = true;
+       ac.itemSelectEvent.subscribe(function(sType, aArgs) {
+               YAHOO.util.Dom.get(hidden).value = aArgs[2].id;
+       });
+       return ac;
+};
+
+YAHOO.portico.setupInlineTablePaginator = function(container) {
+       var paginatorConfig = {
+               rowsPerPage: 10,
+               alwaysVisible: false,
+               template: "{PreviousPageLink} 
<strong>{CurrentPageReport}</strong> {NextPageLink}",
+               pageReportTemplate: "Showing items {startRecord} - {endRecord} 
of {totalRecords}",
+               containers: [YAHOO.util.Dom.get(container)]
+       };
+       
+       YAHOO.portico.lang('setupPaginator', paginatorConfig);
+       var pag = new YAHOO.widget.Paginator(paginatorConfig);
+   pag.render();
+       return pag;
+};
+
+YAHOO.portico.getTotalSum = function(name_column,round,paginator,datatable)
+{
+       if(!paginator.getPageRecords())
+       {
+               return '0,00';
+       }
+       begin = end = 0;
+       end = datatable.getRecordSet().getLength();
+       tmp_sum = 0;
+       for(i = begin; i < end; i++)
+       {
+               tmp_sum = tmp_sum + 
parseFloat(datatable.getRecordSet().getRecords(0)[i].getData(name_column));
+       }
+
+       return tmp_sum = YAHOO.util.Number.format(tmp_sum, 
{decimalPlaces:round, decimalSeparator:",", thousandsSeparator:" "});
+}
+
+       YAHOO.portico.td_sum = function(sum)
+       {
+               newTD = document.createElement('td');
+               newTD.colSpan = 1;
+               newTD.style.borderTop="1px solid #000000";
+               newTD.style.fontWeight = 'bolder';
+               newTD.style.textAlign = 'right';
+               newTD.style.paddingRight = '0.8em';
+               newTD.style.whiteSpace = 'nowrap';
+               newTD.appendChild(document.createTextNode(sum));
+               newTR.appendChild(newTD);
+       }
+
+       YAHOO.portico.td_empty = function(colspan)
+       {
+               newTD = document.createElement('td');
+               newTD.colSpan = colspan;
+               newTD.style.borderTop="1px solid #000000";
+               newTD.appendChild(document.createTextNode(''));
+               newTR.appendChild(newTD);
+       }
+
+
+YAHOO.portico.updateinlineTableHelper = function(container, requestUrl)
+{
+
+       var DatatableName = 'datatable_container' + container;
+       var PaginatorName = 'paginator_container' + container;
+//console.log(YAHOO.portico.Paginator);
+       requestUrl = requestUrl ? requestUrl : 
YAHOO.portico.requestUrl[DatatableName];
+
+       var callback =
+       {
+               success: function(o)
+               {
+                       values_ds = JSON.parse(o.responseText);
+
+                       if(values_ds && values_ds['sessionExpired'] == true)
+                       {
+                               window.alert('sessionExpired - please log in');
+                               return;
+                       }
+
+                       var Paginator = YAHOO.portico.Paginator[PaginatorName];
+
+                       //delete values of datatable
+                       var DataTable = YAHOO.portico.DataTable[DatatableName];
+                       DataTable.getRecordSet().reset();
+
+                       //obtain records of the last DS and add to datatable
+                       var record = values_ds.ResultSet.Result;
+                       var newTotalRecords = 
values_ds.ResultSet.totalResultsAvailable;
+
+                       if(record.length)
+                       {
+                               DataTable.addRows(record);
+                       }
+                       else
+                       {
+                               DataTable.render();
+                       }
+
+                       if(Paginator)
+                       {
+                               
Paginator.setRowsPerPage(values_ds.ResultSet.Result.length,true);
+                               //reset total records always to zero
+                               Paginator.setTotalRecords(0,true);
+
+                               //update paginator with news values
+                               Paginator.setTotalRecords(newTotalRecords,true);
+                               if(typeof(values_ds.ResultSet.results) == 
'undefined')
+                               {
+                                       var results = 10;
+                               }
+                               else
+                               {
+                                       var results = 
values_ds.ResultSet.results;
+                               }
+                               
+                               var activePage = 
Math.floor(values_ds.ResultSet.startIndex / results) + 1;
+                               Paginator.setPage(activePage,true); //true no 
fuerza un recarge solo cambia el paginator
+                       }
+
+                       //update "sortedBy" values
+                       values_ds.ResultSet.sortDir == "asc"? dir_ds = 
YAHOO.widget.DataTable.CLASS_ASC : dir_ds = YAHOO.widget.DataTable.CLASS_DESC;
+                       
DataTable.set("sortedBy",{key:values_ds.ResultSet.sortKey,dir:dir_ds});
+               },
+               failure: function(o) {window.alert('Server or your connection 
is dead.')},
+               timeout: 10000,
+               cache: false
+       }
+
+       try
+       {
+               YAHOO.util.Connect.asyncRequest('POST',requestUrl,callback);
+       }
+       catch(e_async)
+       {
+          alert(e_async.message);
+       }
+};
+
+YAHOO.portico.inlineTableHelper = function(container, url, colDefs, options, 
disablePagination) {
+
+       var DatatableName = 'datatable_container' + container;
+       var PaginatorName = 'paginator_container' + container;
+       var Dom = YAHOO.util.Dom;
+
+       if(typeof(YAHOO.portico.Paginator) == 'undefined' || 
!YAHOO.portico.Paginator )
+       {
+               YAHOO.portico.Paginator = {};
+       }
+
+       if(typeof(YAHOO.portico.DataTable) == 'undefined' || 
!YAHOO.portico.DataTable )
+       {
+               YAHOO.portico.DataTable = {};
+       }
+
+       if(typeof(YAHOO.portico.requestUrl) == 'undefined' || 
!YAHOO.portico.requestUrl )
+       {
+               YAHOO.portico.requestUrl = {};
+       }
+
+       var container = Dom.get(container);
+       if(!disablePagination)
+       {
+
+               if ( container.hasChildNodes() )
+               {
+                       while ( container.childNodes.length >= 1 )
+                   {
+                       container.removeChild( container.firstChild );
+                   }
+               }
+
+               var paginatorContainer = 
container.appendChild(document.createElement('div'));
+               var dataTableContainer = 
container.appendChild(document.createElement('div'));
+       }
+       else
+       {
+               dataTableContainer = container;
+       }
+       options = options || {};
+       options.dynamicData = true;
+       
+       YAHOO.portico.Paginator[PaginatorName] = {};
+       if(!disablePagination)
+       {
+               options.paginator = 
YAHOO.portico.setupInlineTablePaginator(paginatorContainer);
+//             options.paginator.setRowsPerPage(20,true);
+
+               url += '&results=' + options.paginator.getRowsPerPage() + '&';
+
+               YAHOO.portico.Paginator[PaginatorName] =options.paginator;
+       }
+
+
+//    options.sortedBy = {key:"id", dir:YAHOO.widget.DataTable.CLASS_ASC}; // 
Sets UI initial sort arrow
+
+       var myDataSource = new YAHOO.util.DataSource(url);
+       myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+       myDataSource.connXhrMode = "queueRequests";
+       myDataSource.responseSchema = {
+               resultsList: "ResultSet.Result",
+               metaFields : { 
+                       totalResultsAvailable: 
'ResultSet.totalResultsAvailable',
+                       actions: 'Actions',
+                       pageSize: 'ResultSet.pageSize',
+                       startIndex: 'ResultSet.startIndex',
+                       sortKey: 'ResultSet.sortKey',
+                       sortDir: 'ResultSet.sortDir'
+               }
+       };
+       
+       var myDataTable = new YAHOO.widget.DataTable(dataTableContainer, 
colDefs, myDataSource, options);
+       
+       myDataTable.subscribe("rowMouseoverEvent", 
myDataTable.onEventHighlightRow);
+       myDataTable.subscribe("rowMouseoutEvent", 
myDataTable.onEventUnhighlightRow);
+
+       myDataTable.handleDataReturnPayload = function(oRequest, oResponse, 
oPayload) {
+          oPayload.totalRecords = oResponse.meta.totalResultsAvailable;
+          return oPayload;
+   }
+       
+
+       myDataTable.doBeforeLoadData = function(nothing, oResponse, oPayload) {
+
+        oPayload.totalRecords = oResponse.meta.totalResultsAvailable;
+//             oPayload.pagination.rowsPerPage= oResponse.meta.pageSize || 10;
+
+               oPayload.pagination = { 
+                       rowsPerPage: oResponse.meta.pageSize || 10, 
+                       recordOffset: oResponse.meta.startIndex || 0 
+           }
+/*
+               oPayload.sortedBy = { 
+                       key: oResponse.meta.sortKey || "id", 
+                       dir: (oResponse.meta.sortDir) ? "yui-dt-" + 
oResponse.meta.sortDir : "yui-dt-asc" 
+               };
+*/
+               if (!oResponse.meta.actions) return oResponse;
+               
+               actions = oResponse.meta.actions;
+               
+               for (var key in actions) {
+                       var actionLink = document.createElement('a');
+                       actionLink.href = actions[key].href.replace(/&amp;/gi, 
'&');
+                       actionLink.innerHTML = actions[key].text;
+                       YAHOO.util.Dom.insertAfter(actionLink, container);
+               };
+               
+               return oResponse;
+       };
+
+       YAHOO.portico.DataTable[DatatableName] = myDataTable;
+       YAHOO.portico.requestUrl[DatatableName] = url;
+
+       return {dataTable: myDataTable, dataSource: myDataSource};
+};
+
+YAHOO.portico.inlineImages = function(container, url, options)
+{
+       options = options || {};
+       var myDataSource = new YAHOO.util.DataSource(url);
+       myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+       myDataSource.connXhrMode = "queueRequests";
+       myDataSource.responseSchema = {
+               resultsList: "ResultSet.Result",
+               metaFields : { totalResultsAvailable: 
"ResultSet.totalResultsAvailable", actions: 'Actions' }
+       };
+       
+       myDataSource.sendRequest('', {success: function(sRequest, oResponse, 
oPayload) {
+               var dlImages = new 
YAHOO.util.Element(document.createElement('dl'));
+               dlImages.addClass('proplist images');
+               
+               var displayContainer = false;
+               
+               for(var key in oResponse.results) { 
+                       displayContainer = true;
+                       var imgEl = 
dlImages.appendChild(document.createElement('dd')).appendChild(document.createElement('img'));
+                       var captionEl = 
dlImages.appendChild(document.createElement('dt'));
+                       imgEl.src = 
oResponse.results[key].src.replace(/&amp;/gi, '&');
+                       
captionEl.appendChild(document.createTextNode(oResponse.results[key].description));
+               }
+               
+               if (displayContainer)
+               {
+                       new YAHOO.util.Element(container).appendChild(dlImages);
+               } else {
+                       new YAHOO.util.Element(container).setStyle('display', 
'none');
+               }
+       }});
+};
+
+YAHOO.portico.radioTableHelper = function(container, url, name, selection) {
+       return YAHOO.portico.checkboxTableHelper(container, url, name, 
selection, {type: 'radio'});
+};
+
+YAHOO.portico.checkboxTableHelper = function(container, url, name, selection, 
options) {
+       options = YAHOO.lang.isObject(options) ? options : {};
+       
+       options = YAHOO.lang.merge(
+               {type: 'checkbox', selectionFieldOptions: {}, nameFieldOptions: 
{}, defaultChecked: false}, 
+               options
+       );
+       
+       var type = options['type'] || 'checkbox';
+       selection = selection || [];
+       var myDataSource = new YAHOO.util.DataSource(url);
+       myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+       myDataSource.connXhrMode = "queueRequests";
+       myDataSource.responseSchema = {
+               resultsList: "ResultSet.Result",
+               metaFields : { totalResultsAvailable: 
"ResultSet.totalResultsAvailable" }
+       };
+       
+       var lang = {LBL_NAME: 'Name'};
+       YAHOO.portico.lang('common', lang);
+       
+       var changeListener = false;
+       
+       if (options.onSelectionChanged) {
+               changeListener = function(e) {
+                       var selectedItems = [];
+                       var items = 
YAHOO.util.Dom.getElementsBy(function(i){return i.checked;}, 'input', 
container);
+                       
+                       YAHOO.util.Dom.batch(items, function(e, selectedItems) {
+                               selectedItems.push(e.value);
+                       }, selectedItems);
+                       
+                       options.onSelectionChanged(selectedItems);
+               };
+       }
+       
+       var checkboxFormatter = function(elCell, oRecord, oColumn, oData) { 
+               var checked = false;
+               var newInput; 
+               for(var i=0; i < selection.length; i++) {
+                       if (selection[i] == oData) {
+                               checked = true;
+                               break;
+                       }
+               }
+               
+               newInput = document.createElement('input');
+               newInput.setAttribute('type', type);
+               newInput.setAttribute('name', name);
+               newInput.setAttribute('value', oData);
+               if (checked || options.defaultChecked) {
+                       newInput.setAttribute('checked', 'checked');
+                       newInput.setAttribute('defaultChecked', true); //Needed 
for IE compatibility
+               }
+               
+               if (changeListener != false) {
+                       //Using 'click' event on IE as the change event does 
not work as expected there.
+                       YAHOO.util.Event.addListener(newInput, (YAHOO.env.ua.ie 
> 0 ? 'click' : 'change'), changeListener);
+               }
+               
+               elCell.appendChild(newInput);
+               
+       };
+       var colDefs = [
+               YAHOO.lang.merge({key: "id", formatter: checkboxFormatter, 
label: ''}, options.selectionFieldOptions),
+               YAHOO.lang.merge({key: "name", label: lang['LBL_NAME'], 
sortable: true}, options.nameFieldOptions)
+       ];
+       
+       if (options['additional_fields'] && 
YAHOO.lang.isArray(options['additional_fields'])) {
+               for (var i=0; i < options['additional_fields'].length; i++) {
+                       colDefs.push(options['additional_fields'][i]);
+               }
+       }
+       
+       var myDataTable = new YAHOO.widget.DataTable(container, colDefs, 
myDataSource, {
+          sortedBy: {key: 'name', dir: YAHOO.widget.DataTable.CLASS_ASC}
+       });
+};
+
+YAHOO.portico.setupDatePickers = function() { 
+       YAHOO.util.Dom.getElementsByClassName('date-picker', null, null, 
YAHOO.portico.setupDatePickerHelper, [true, false]);
+       YAHOO.util.Dom.getElementsByClassName('time-picker', null, null, 
YAHOO.portico.setupDatePickerHelper, [false, true]);
+       YAHOO.util.Dom.getElementsByClassName('datetime-picker', null, null, 
YAHOO.portico.setupDatePickerHelper, [true, true]);
+};
+
+YAHOO.portico.setupDatePickerHelper = function(field, args) {
+       if (!YAHOO.portico.setupDatePickerHelper.groups) {
+               YAHOO.portico.setupDatePickerHelper.groups = {};
+       }
+       
+       var groups = YAHOO.portico.setupDatePickerHelper.groups;
+       var Dom = YAHOO.util.Dom;
+       
+       if(field._converted)
+               return;
+       field._converted = true;
+       var date = args[0];
+       var time = args[1];
+       var Dom = YAHOO.util.Dom;
+       var Event = YAHOO.util.Event;
+       var oCalendarMenu = new YAHOO.widget.Overlay(Dom.generateId(), { 
visible: false});
+       var oButton = new YAHOO.widget.Button({type: "menu", id: 
Dom.generateId(), menu: oCalendarMenu, container: field});
+       
+       oButton.with_time = time;
+       oButton.with_date = date;
+       
+       var lang = {LBL_CHOOSE_DATE: 'Choose a date'};
+       YAHOO.portico.lang('setupDatePickerHelper', lang);
+       
+       oButton._calendarMenu = oCalendarMenu;
+       oButton._input = field._input = Dom.getElementsBy(function(){return 
true;}, 'input', field)[0];
+       
+       oButton.hasDateSection = function() { return this.with_date; };
+       oButton.hasTimeSection = function() { return this.with_time; };
+       
+       oButton.fireUpdateEvent = function() {
+               if (oButton.on_update) {
+                       oButton.on_update.func.call(oButton.on_update.context, 
oButton);
+               }
+       };
+       
+       oButton.on("appendTo", function () {
+               this._calendarMenu.setBody(" ");
+               this._calendarMenu.body.id = Dom.generateId();
+       });
+       if(!date)
+               oButton.setStyle('display', 'none');
+       //oButton._input.setAttribute('type', 'hidden');
+       oButton._input.style.display = 'none';
+       if(oButton._input.value)
+               oButton._date = parseISO8601(oButton._input.value);
+       else
+               oButton._date = new Date(1, 1, 1);
+       oButton._input._update = function() {
+               if(oButton._input.value)
+                       oButton._date = parseISO8601(oButton._input.value);
+               else
+                       oButton._date = new Date(1, 1, 1);
+               oButton._update(false);
+       };
+       oButton._update = function(fire_update_event) {
+               var year = this._date.getFullYear();
+               var month = this._date.getMonth() + 1;
+               var day = this._date.getDate();
+               var hours = this._date.getHours();
+               var minutes = this._date.getMinutes();
+               var month = month < 10 ? '0' + month : '' + month;
+               var day = day < 10 ? '0' + day : '' + day;
+               var hours = hours < 10 ? '0' + hours : '' + hours;
+               var minutes = minutes  < 10 ? '0' + minutes : '' + minutes;
+               var dateValue = year + '-' + month + '-' + day;
+               var timeValue = hours + ':' + minutes;
+               if(year == 1901) {
+                       this.set('label', lang.LBL_CHOOSE_DATE);
+               } else {
+                       this.set('label', dateValue);
+               }
+               if(time) {
+                       this._hours.set('value', parseInt(hours, 10));
+                       this._minutes.set('value', parseInt(minutes, 10));
+                       this._hours.update();
+                       this._minutes.update();
+               }
+               if(year != 1901 && date && time)
+                       this._input.value = dateValue + ' ' + timeValue;
+               else if (year != 1901 && date)
+                       this._input.value = dateValue;
+               else if(!date && time)
+                       this._input.value = timeValue;
+               
+               if (fire_update_event) {
+                       oButton.fireUpdateEvent();
+               }
+       };
+       
+       oButton.getDate = function() {
+               return this._date;
+       };
+
+       oButton.on("click", function () {
+               YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE = 4;
+               var oCalendar = new YAHOO.widget.Calendar(Dom.generateId(), 
this._calendarMenu.body.id, {START_WEEKDAY: 1,SHOW_WEEK_HEADER:true});
+               oCalendar._button = this;
+               if(this._date.getFullYear() == 1901) {
+                       var d = new Date();
+                       oCalendar.cfg.setProperty("pagedate", (d.getMonth()+1) 
+ "/" + d.getFullYear());
+               } else {
+                       oCalendar.select(this._date);
+                       oCalendar.cfg.setProperty("pagedate", 
(this._date.getMonth()+1) + "/" + this._date.getFullYear());
+               }
+               
+               oCalendar.render();
+               // Hide date picker on ESC
+               Event.on(this._calendarMenu.element, "keydown", function 
(p_oEvent) {
+                       if (Event.getCharCode(p_oEvent) === 27) {
+                               this._calendarMenu.hide();
+                               this.focus();
+                       }
+               }, null, this);
+               oCalendar.selectEvent.subscribe(function (p_sType, p_aArgs) {
+                       if (p_aArgs) {
+                               var aDate = p_aArgs[0][0];
+                               this._date.setFullYear(aDate[0]);
+                               this._date.setMonth(aDate[1]-1);
+                               this._date.setDate(aDate[2]);
+                               this._update(true);
+                               //this._input.value = value;
+                       }
+                       this._calendarMenu.hide();
+               }, this, true);
+       });
+       if(time) {
+               oButton._hours = new YAHOO.portico.InputNumberRange({min: 0, 
max:23});
+               oButton._minutes = new YAHOO.portico.InputNumberRange({min: 0, 
max:59});
+               
+               oButton._hours.on('updateEvent', function() {
+                       oButton._date.setHours(this.get('value'));
+                       oButton._update(true);
+               });
+               
+               oButton._minutes.on('updateEvent', function() {
+                       oButton._date.setMinutes(this.get('value'));
+                       oButton._update(true);
+               });
+               
+               oButton.on("appendTo", function () {
+                       var timePicker = 
Dom.get(field).appendChild(document.createElement('span'));
+                       Dom.addClass(timePicker, 'time-picker-inputs');
+                       timePicker.appendChild(document.createTextNode(' '));
+                       oButton._hours.render(timePicker);
+                       timePicker.appendChild(document.createTextNode(' : '));
+                       oButton._minutes.render(timePicker);
+                       oButton._update(false);
+               });
+       }
+       oButton._update(false);
+       
+       var id = Dom.getAttribute(oButton._input, 'id');
+       var matches = /^([a-zA-Z][\w0-9\-_.:]+)_(from|to)$/.exec(id);
+       
+       var group_name = matches ? matches[1] : false;
+       var from_to = matches ? matches[2] : false;
+       
+       if (group_name && from_to && oButton.hasDateSection()) {
+               if (!groups[group_name]) { groups[group_name] = {}; }
+               
+               groups[group_name][from_to] = oButton;
+
+               if (groups[group_name]['from'] && groups[group_name]['to']) {
+                       groups[group_name]['from'].on_update = {
+                               context: groups[group_name]['to'], 
+                               func: function(fromDateButton) {
+                                       var fromDate = fromDateButton.getDate();
+                                       var currentYear = 
this._date.getFullYear();
+                                       
+                                       if (this._date.getFullYear() == 1901) {
+                                               
this._date.setFullYear(fromDate.getFullYear());
+                                               
this._date.setMonth(fromDate.getMonth());
+                                               
this._date.setDate(fromDate.getDate());
+                                       } else if (fromDate.getFullYear() <= 
this._date.getFullYear() && fromDate.getMonth() <= this._date.getMonth() && 
fromDate.getDate() <= this._date.getDate()) {
+                                               //this._date.
+                                       }
+                               
+                                       this._update(false);
+                               }
+                       };
+                       
+                       delete groups[group_name];
+               }
+       }
+};
+
+// Executed on all booking.uicommon-based pages
+YAHOO.util.Event.addListener(window, "load", function() {
+       YAHOO.portico.setupDatePickers(); 
+});
+var showIfNotEmpty = function(event, fieldname) {
+       if (document.getElementById(fieldname).value.length > 1) {
+               YAHOO.util.Dom.replaceClass(fieldname + "_edit", "hideit", 
"showit");
+       } else {
+               YAHOO.util.Dom.replaceClass(fieldname + "_edit", "showit", 
"hideit");
+       }
+};
+
+YAHOO.portico.rtfEditorHelper = function(textarea_id, options) {
+       options = YAHOO.lang.merge({width:522, height:300}, (options || {}));
+       var descEdit = new YAHOO.widget.SimpleEditor(textarea_id, {
+               height: options.height+'px',
+               width: options.width+'px',
+               dompath: true,
+               animate: true,
+               handleSubmit: true
+       });
+       descEdit.render();
+       return descEdit;
+};
+
+YAHOO.portico.postToUrl = function(path, params, method) {
+       method = method || "post"; // Set method to post by default, if not 
specified.
+       var form = document.createElement("form");
+       form.setAttribute("method", method);
+       form.setAttribute("action", path);
+
+       for(var key in params) {
+               var hiddenField = document.createElement("input");
+               hiddenField.setAttribute("type", "hidden");
+               hiddenField.setAttribute("name", params[key][0]);
+               hiddenField.setAttribute("value", params[key][1]);
+               form.appendChild(hiddenField);
+       }
+       document.body.appendChild(form);        // Not entirely sure if this is 
necessary
+       form.submit();
+};
+
+(function(){
+       var Dom = YAHOO.util.Dom,
+               Event = YAHOO.util.Event,
+               Panel = YAHOO.widget.Panel,
+               Lang = YAHOO.lang;
+
+       var CSS_PREFIX = 'booking_number_range_';
+ 
+       var InputNumberRange = function(oConfigs) {
+               InputNumberRange.superclass.constructor.call(this, 
document.createElement('span'), oConfigs);
+               this.createEvent('updateEvent');
+               this.refresh(['id'],true);
+       };
+
+       YAHOO.portico.InputNumberRange = InputNumberRange;
+
+       Lang.extend(InputNumberRange, YAHOO.util.Element, {
+               initAttributes: function (oConfigs) { 
+                       InputNumberRange.superclass.initAttributes.call(this, 
oConfigs);
+                       
+                       var container = this.get('element');
+               
+                       this.setAttributeConfig('inputEl', {
+                               readOnly: true,
+                               value: 
container.appendChild(document.createElement('span'))
+                       });
+       
+                       this.setAttributeConfig('id', {
+                               writeOnce: true,
+                               validator: function (value) {
+                                       return 
/^[a-zA-Z][\w0-9\-_.:]*$/.test(value);
+                               },
+                               value: Dom.generateId(),
+                               method: function (value) {
+                                       this.get('inputEl').id = value;
+                               }
+                       });
+       
+                       this.setAttributeConfig('value', {
+                               value: 0,
+                               validator: Lang.isNumber
+                 });
+               
+                       this.setAttributeConfig('input', {
+                               value: null
+                 });
+               
+                       this.setAttributeConfig('min', {
+                               validator: Lang.isNumber,
+                               value: 100
+                 });
+               
+                       this.setAttributeConfig('max', {
+                               validator: Lang.isNumber,
+                               value: 0
+                       });
+               
+                       this.setAttributeConfig('input_length', {
+                               validator: Lang.isNumber,
+                               value: null
+                       });
+               },
+       
+               destroy: function () { 
+                       var el = this.get('element');
+                       Event.purgeElement(el, true);
+                       el.parentNode.removeChild(el);
+               },
+               
+               _padValue: function(value)
+               {
+                       value = value.toString('10');
+                       var padding = this.get('input_length') - value.length;
+                       if (padding > 0) {
+                               return ((new Array(padding+1).join('0')) + 
value);
+                       }
+                       return value;
+               },
+               
+               _updateValue: function() {
+                       var input = this.get('input');
+                       var value;
+                       
+                       if (input.value.length > 0) {
+                               value = parseInt(input.value, 10);
+                       } else {
+                               value = 0;
+                       }
+                               
+                       if (isNaN(value)) { 
+                               value = this.get('min');
+                       }
+                       
+                       if (value < this.get('min')) {
+                               value = this.get('min');
+                       }
+                       
+                       if (value > this.get('max')) {
+                               value = this.get('max');
+                       }
+                       
+                       this.set('value', value);
+               },
+               
+               _fireUpdateEvent: function()
+               {
+                       this._updateValue();
+                       this.update();
+                       
+                       this.fireEvent('updateEvent');
+               },
+               
+               update: function() {
+                       if (!this.get('input')) { return; }
+                       this.get('input').value = 
this._padValue(this.get('value'));
+               },
+               
+               render: function (parentEl) {
+                       parentEl = Dom.get(parentEl);
+               
+                       if (!parentEl) {
+                               YAHOO.log('Missing mandatory argument in 
YAHOO.portico.InputNumberRange.render:  parentEl','error','Field');
+                               return null;
+                 }
+               
+                       var containerEl = this.get('element');
+                       this.addClass(CSS_PREFIX + 'container');
+               
+                       var inputEl = this.get('inputEl');
+                       Dom.addClass(inputEl, CSS_PREFIX + 'input');
+               
+                       this._renderInputEl(inputEl);
+               
+                       parentEl.appendChild(containerEl); //Appends to 
document to show the component
+               },
+               
+               _renderInputEl: function (containerEl) { 
+                       var input = 
containerEl.appendChild(document.createElement('input'));
+               
+                       if (!this.get('input_length')) {
+                               this.set('input_length', 
this.get('max').toString().length);
+                       }
+               
+                       var size = this.get('input_length');
+                       input.setAttribute('size', size);
+                       input.setAttribute('maxlength', size);
+                       
+                       if (YAHOO.env.ua.ie > 6) {
+                               YAHOO.util.Dom.setStyle(input, 'width', '2em');
+                       }
+                       
+                       input.value = this._padValue(this.get('value'));
+               
+                       this.set('input', input);
+               
+                       Event.on(input,'keyup', function (oArgs) {
+                               this._updateValue();
+                               }, this, true);
+               
+                       Event.on(input, 'change', function(oArgs) {
+                               this._fireUpdateEvent();
+                       }, this, true);
+                       
+                       oForm = input.form;
+                       
+                       if (oForm) {
+                               Event.on(oForm, "submit", function() {
+                                       this._fireUpdateEvent();
+                               }, null, this);
+                       }
+                       
+               }
+       });
+
+})();
+
+       YAHOO.portico.html_entity_decode = function(string)
+       {
+               var histogram = {}, histogram_r = {}, code = 0;
+               var entity = chr = '';
+
+               histogram['34'] = 'quot';
+               histogram['38'] = 'amp';
+               histogram['60'] = 'lt';
+               histogram['62'] = 'gt';
+               histogram['160'] = 'nbsp';
+               histogram['161'] = 'iexcl';
+               histogram['162'] = 'cent';
+               histogram['163'] = 'pound';
+               histogram['164'] = 'curren';
+               histogram['165'] = 'yen';
+               histogram['166'] = 'brvbar';
+               histogram['167'] = 'sect';
+               histogram['168'] = 'uml';
+               histogram['169'] = 'copy';
+               histogram['170'] = 'ordf';
+               histogram['171'] = 'laquo';
+               histogram['172'] = 'not';
+               histogram['173'] = 'shy';
+               histogram['174'] = 'reg';
+               histogram['175'] = 'macr';
+               histogram['176'] = 'deg';
+               histogram['177'] = 'plusmn';
+               histogram['178'] = 'sup2';
+               histogram['179'] = 'sup3';
+               histogram['180'] = 'acute';
+               histogram['181'] = 'micro';
+               histogram['182'] = 'para';
+               histogram['183'] = 'middot';
+               histogram['184'] = 'cedil';
+               histogram['185'] = 'sup1';
+               histogram['186'] = 'ordm';
+               histogram['187'] = 'raquo';
+               histogram['188'] = 'frac14';
+               histogram['189'] = 'frac12';
+               histogram['190'] = 'frac34';
+               histogram['191'] = 'iquest';
+               histogram['192'] = 'Agrave';
+               histogram['193'] = 'Aacute';
+               histogram['194'] = 'Acirc';
+               histogram['195'] = 'Atilde';
+               histogram['196'] = 'Auml';
+               histogram['197'] = 'Aring';
+               histogram['198'] = 'AElig';
+               histogram['199'] = 'Ccedil';
+               histogram['200'] = 'Egrave';
+               histogram['201'] = 'Eacute';
+               histogram['202'] = 'Ecirc';
+               histogram['203'] = 'Euml';
+               histogram['204'] = 'Igrave';
+               histogram['205'] = 'Iacute';
+               histogram['206'] = 'Icirc';
+               histogram['207'] = 'Iuml';
+               histogram['208'] = 'ETH';
+               histogram['209'] = 'Ntilde';
+               histogram['210'] = 'Ograve';
+               histogram['211'] = 'Oacute';
+               histogram['212'] = 'Ocirc';
+               histogram['213'] = 'Otilde';
+               histogram['214'] = 'Ouml';
+               histogram['215'] = 'times';
+               histogram['216'] = 'Oslash';
+               histogram['217'] = 'Ugrave';
+               histogram['218'] = 'Uacute';
+               histogram['219'] = 'Ucirc';
+               histogram['220'] = 'Uuml';
+               histogram['221'] = 'Yacute';
+               histogram['222'] = 'THORN';
+               histogram['223'] = 'szlig';
+               histogram['224'] = 'agrave';
+               histogram['225'] = 'aacute';
+               histogram['226'] = 'acirc';
+               histogram['227'] = 'atilde';
+               histogram['228'] = 'auml';
+               histogram['229'] = 'aring';
+               histogram['230'] = 'aelig';
+               histogram['231'] = 'ccedil';
+               histogram['232'] = 'egrave';
+               histogram['233'] = 'eacute';
+               histogram['234'] = 'ecirc';
+               histogram['235'] = 'euml';
+               histogram['236'] = 'igrave';
+               histogram['237'] = 'iacute';
+               histogram['238'] = 'icirc';
+               histogram['239'] = 'iuml';
+               histogram['240'] = 'eth';
+               histogram['241'] = 'ntilde';
+               histogram['242'] = 'ograve';
+               histogram['243'] = 'oacute';
+               histogram['244'] = 'ocirc';
+               histogram['245'] = 'otilde';
+               histogram['246'] = 'ouml';
+               histogram['247'] = 'divide';
+               histogram['248'] = 'oslash';
+               histogram['249'] = 'ugrave';
+               histogram['250'] = 'uacute';
+               histogram['251'] = 'ucirc';
+               histogram['252'] = 'uuml';
+               histogram['253'] = 'yacute';
+               histogram['254'] = 'thorn';
+               histogram['255'] = 'yuml';
+
+               // Reverse table. Cause for maintainability purposes, the 
histogram is
+               // identical to the one in htmlentities.
+               for (code in histogram) {
+                       entity = histogram[code];
+                       histogram_r[entity] = code;
+               }
+
+               return (string+'').replace(/(\&([a-zA-Z]+)\;)/g, function(full, 
m1, m2){
+                       if (m2 in histogram_r) {
+                               return String.fromCharCode(histogram_r[m2]);
+                       } else {
+                               return m2;
+                       }
+               });
+};
+
+
+       YAHOO.portico.substr_count =  function ( haystack, needle, offset, 
length )
+       {
+               var pos = 0, cnt = 0;
+
+               haystack += '';
+               needle += '';
+               if(isNaN(offset)) offset = 0;
+               if(isNaN(length)) length = 0;
+               offset--;
+
+               while( (offset = haystack.indexOf(needle, offset+1)) != -1 )
+               {
+                       if(length > 0 && (offset+needle.length) > length)
+                       {
+                               return false;
+                       } else
+                       {
+                               cnt++;
+                       }
+               }
+               return cnt;
+       };
+
+
+// parseUri 1.2.2
+// (c) Steven Levithan <stevenlevithan.com>
+// MIT License
+
+function parseUri (str) {
+       var     o   = parseUri.options,
+               m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
+               uri = {},
+               i   = 14;
+
+       while (i--) uri[o.key[i]] = m[i] || "";
+
+       uri[o.q.name] = {};
+       uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
+               if ($1) uri[o.q.name][$1] = $2;
+       });
+
+       return uri;
+};
+
+parseUri.options = {
+       strictMode: false,
+       key: 
["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
+       q:   {
+               name:   "queryKey",
+               parser: /(?:^|&)([^&=]*)=?([^&]*)/g
+       },
+       parser: {
+               strict: 
/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
+               loose:  
/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
+       }
+};
+

Added: trunk/phpgwapi/js/yui3/datatable.js
===================================================================
--- trunk/phpgwapi/js/yui3/datatable.js                         (rev 0)
+++ trunk/phpgwapi/js/yui3/datatable.js 2014-05-22 14:09:28 UTC (rev 11987)
@@ -0,0 +1,589 @@
+YAHOO.portico.setupToolbar = function() {
+       YAHOO.portico.renderUiFormItems('toolbar');
+};
+
+YAHOO.portico.setupListActions = function() {
+       YAHOO.portico.renderUiFormItems('list_actions');
+};
+
+YAHOO.portico.renderUiFormItems = function(container) {
+       var items = YAHOO.util.Dom.getElementsBy(function(){return true;}, 
'input', container);
+   for(var i=0; i < items.length; i++) {
+       var type = items[i].getAttribute('type');
+       if(type == 'link') {
+           new YAHOO.widget.Button(items[i], 
+                                   {type: 'link', 
+                                    href: items[i].getAttribute('href')});
+       }
+       else if(type == 'submit') {
+           new YAHOO.widget.Button(items[i], {type: 'submit'});
+       }
+   }
+};
+
+YAHOO.portico.setupPaginator = function() {
+       var paginatorConfig = {
+        rowsPerPage: 10,
+        alwaysVisible: true,
+        template: "{PreviousPageLink} <strong>{CurrentPageReport}</strong> 
{NextPageLink}",
+        pageReportTemplate: "Showing items {startRecord} - {endRecord} of 
{totalRecords}",
+        containers: ['paginator']
+    };
+       
+       YAHOO.portico.lang('setupPaginator', paginatorConfig);
+       var pag = new YAHOO.widget.Paginator(paginatorConfig);
+    pag.render();
+       return pag;
+};
+
+YAHOO.portico.preSerializeQueryFormListeners = new Array();
+
+       YAHOO.portico.addPreSerializeQueryFormListener = function(func) {
+       YAHOO.portico.preSerializeQueryFormListeners.push(func);
+}
+
+YAHOO.portico.preSerializeQueryForm = function(form) {
+       for (var key in YAHOO.portico.preSerializeQueryFormListeners) {
+               YAHOO.portico.preSerializeQueryFormListeners[key](form);
+       }
+}
+
+YAHOO.portico.initializeDataTable = function()
+{
+       YAHOO.portico.setupToolbar();
+       YAHOO.portico.setupListActions();
+       YAHOO.portico.setupDatasource();
+       var pag = YAHOO.portico.setupPaginator();
+
+    var fields = [];
+    for(var i=0; i < YAHOO.portico.columnDefs.length; i++) {
+        fields.push(YAHOO.portico.columnDefs[i].key);
+    }
+    var baseUrl = YAHOO.portico.dataSourceUrl;
+    if(baseUrl[baseUrl.length - 1] != '&') {
+        baseUrl += '&';
+    }
+
+    if (YAHOO.portico.initialSortedBy) {
+//      baseUrl += 'sort=' + YAHOO.portico.initialSortedBy.key + '&dir=' + 
YAHOO.portico.initialSortedBy.dir;
+    } else {
+//      baseUrl += 'sort=' + fields[0];
+    }
+       
+//       baseUrl += '&results=' + pag.getRowsPerPage() + '&';
+    var myDataSource = new YAHOO.util.DataSource(baseUrl);
+
+    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
+    myDataSource.connXhrMode = "queueRequests";
+    myDataSource.responseSchema = {
+        resultsList: "ResultSet.Result",
+        fields: fields,
+        metaFields : {
+            totalResultsAvailable: "ResultSet.totalResultsAvailable",
+                       startIndex: 'ResultSet.startIndex',
+                       pageSize: 'ResultSet.pageSize',
+                       sortKey: 'ResultSet.sortKey',
+                       sortDir: 'ResultSet.sortDir'
+        }
+    };
+
+    var myDataTable = new YAHOO.widget.DataTable("datatable-container", 
+        YAHOO.portico.columnDefs, myDataSource, {
+            paginator: pag,
+            dynamicData: true,
+            sortedBy: YAHOO.portico.initialSortedBy || {key: fields[0], dir: 
YAHOO.widget.DataTable.CLASS_ASC}
+    });
+    var handleSorting = function (oColumn) {
+        var sDir = this.getColumnSortDir(oColumn);
+        var newState = getState(oColumn.key, sDir);
+        History.navigate("state", newState);
+    };
+    myDataTable.sortColumn = handleSorting;
+
+       /* Inline editor from 'rental'*/
+
+
+       var highlightEditableCell = function(oArgs) {
+               var elCell = oArgs.target;
+               if(YAHOO.util.Dom.hasClass(elCell, "yui-dt-editable")) {
+                       myDataTable.highlightCell(elCell);
+               }
+       };
+
+       myDataTable.editor_action = YAHOO.portico.editor_action;
+
+               // Handle mouseover and click events for inline editing
+               myDataTable.subscribe("cellMouseoverEvent", 
highlightEditableCell);
+               myDataTable.subscribe("cellMouseoutEvent", 
myDataTable.onEventUnhighlightCell);
+               myDataTable.subscribe("cellClickEvent", 
myDataTable.onEventShowCellEditor);
+
+               myDataTable.subscribe("editorSaveEvent", function(oArgs) {
+                       var field = oArgs.editor.getColumn().field;
+                       var value = oArgs.newData;
+                       var id = oArgs.editor.getRecord().getData().id;
+//console.log(oArgs.editor.getRecord());
+                       var action = oArgs.editor.getDataTable().editor_action;
+
+                       // Translate to unix time if the editor is a calendar.
+                       if (oArgs.editor._sType == 'date') {
+                               var selectedDate = 
oArgs.editor.calendar.getSelectedDates()[0];
+                               //alert("selDate1: " + selectedDate);
+                               // Make sure we're at midnight GMT
+                               selectedDate = selectedDate.toString().split(" 
");
+                               //for(var e=0;e<selectedDate.length;e++){
+                               //      alert("element " + e + ": " + 
selectedDate[e]);
+                               //}
+                               if(selectedDate[3] == "00:00:00"){
+                               //      alert("seldate skal byttes!");
+                                       selectedDate = 
selectedDate.slice(0,3).join(" ") + " " + selectedDate[5] + " 00:00:00 GMT"; 
+                               }
+                               else{
+                                       selectedDate = 
selectedDate.slice(0,4).join(" ") + " 00:00:00 GMT";
+                               }
+                               //selectedDate = 
selectedDate.toString().split(" ").slice(0, 4).join(" ") + " 00:00:00 GMT";
+                               //alert("selDate2: " + selectedDate);
+                               var value = Math.round(Date.parse(selectedDate) 
/ 1000);
+                               //alert("selDate3 value: " + value);
+                       }
+
+                       var oArgs_edit = 
{menuaction:action,field:field,value:value,id:id};
+                       var edit_Url = phpGWLink('index.php', oArgs_edit,true);
+
+                       var request = YAHOO.util.Connect.asyncRequest(
+                                       'GET',
+                                       edit_Url,
+                                       {
+                                               success: ajaxResponseSuccess,
+                                               failure: ajaxResponseFailure,
+                                               args:oArgs.editor.getDataTable()
+                                       }
+                               );
+               });
+
+/*
+               // Don't set the row to be left-clickable if the table is 
editable by inline editors.
+               // In that case we use cellClickEvents instead
+               var table_should_be_clickable = true;
+               for (i in YAHOO.portico.columnDefs) {
+                       if (YAHOO.portico.columnDefs[i].editor) {
+                               //table_should_be_clickable = false;
+                       }
+               }
+
+               if (table_should_be_clickable && 
!YAHOO.portico.disable_left_click) {
+                       //... create a handler for regular clicks on a table row
+                       myDataTable.subscribe("rowClickEvent", function(e,obj) {
+                               YAHOO.util.Event.stopEvent(e);
+
+                               var target = e.target;
+                               var record = this.getRecord(target);
+                               var row = this.getRow(target);
+                               //once you get here you can access values like 
..
+                               //record.getData("ColumnName") or row.rowIndex
+
+                               //... trigger first action on row click
+                       //      var row = obj.table.getTrEl(e.target);
+                               if(row)
+                               {
+                       //              var record = obj.table.getRecord(row);
+                                       //... check whether this action should 
be an AJAX call
+                                       if(record.getData().ajax[0]) {
+                                               var request = 
YAHOO.util.Connect.asyncRequest(
+                                                       'GET',
+                                                       //... execute first 
action
+                                                       
record.getData().actions[0],
+                                                       {
+                                                               success: 
ajaxResponseSuccess,
+                                                               failure: 
ajaxResponseFailure,
+                                                               args:obj.table
+                                                       }
+                                               );
+                                       } else {
+                                               //... execute first action
+                                               window.location = 
record.getData().actions[0];
+                                       }
+                               }
+                       },this);
+
+                       //... highlight rows on mouseover.  This too only 
happens if the table is
+                       // not editable.
+                       myDataTable.subscribe("rowMouseoverEvent", 
myDataTable.onEventHighlightRow);
+                       myDataTable.subscribe("rowMouseoutEvent", 
myDataTable.onEventUnhighlightRow);
+               }
+
+*/
+
+
+       /*  Inline editor from 'rental'*/
+
+
+       /* Start from Property*/
+
+  
/********************************************************************************
+ *
+ */
+       var onContextMenuBeforeShow = function(p_sType, p_aArgs)
+       {
+               var prefixSelected = '';
+               var oTarget = this.contextEventTarget;
+               if (this.getRoot() == this)
+               {
+                       if(oTarget.tagName != "TD")
+                       {
+                               oTarget = 
YAHOO.util.Dom.getAncestorByTagName(oTarget, "td");
+                       }
+                       oSelectedTR = 
YAHOO.util.Dom.getAncestorByTagName(oTarget, "tr");
+                       oSelectedTR.style.backgroundColor  = '#AAC1D8' ;
+                       oSelectedTR.style.color = "black";
+                       YAHOO.util.Dom.addClass(oSelectedTR, prefixSelected);
+               }
+       }
+
+
+ 
/********************************************************************************
+ *
+ */
+       var onContextMenuHide = function(p_sType, p_aArgs)
+       {
+               var prefixSelected = '';
+               if (this.getRoot() == this && oSelectedTR)
+               {
+                       oSelectedTR.style.backgroundColor  = "" ;
+                       oSelectedTR.style.color = "";
+                       YAHOO.util.Dom.removeClass(oSelectedTR, prefixSelected);
+               }
+       }
+ 
/********************************************************************************
+ *
+ */
+       var onContextMenuClick = function(p_sType, p_aArgs, p_myDataTable)
+       {
+               var task = p_aArgs[1];
+                       if(task)
+                       {
+                               // Extract which TR element triggered the 
context menu
+                               var elRow = 
p_myDataTable.getTrEl(this.contextEventTarget);
+                               if(elRow)
+                               {
+                                       var oRecord = 
p_myDataTable.getRecord(elRow);
+                                       var url = 
YAHOO.portico.actions[task.groupIndex].action;
+                                       var sUrl = "";
+                                       var vars2 = "";
+
+                                       
if(YAHOO.portico.actions[task.groupIndex].parameters!=null)
+                                       {
+                                               for(f=0; 
f<YAHOO.portico.actions[task.groupIndex].parameters.parameter.length; f++)
+                                               {
+                                                       param_name = 
YAHOO.portico.actions[task.groupIndex].parameters.parameter[f].name;
+                                                       param_source = 
YAHOO.portico.actions[task.groupIndex].parameters.parameter[f].source;
+                                                       vars2 = vars2 + 
"&"+param_name+"=" + oRecord.getData(param_source);
+                                               }
+                                               sUrl = url + vars2;
+                                       }
+                                       
if(YAHOO.portico.actions[task.groupIndex].parameters.parameter.length > 0)
+                                       {
+                                               //nothing
+                                       }
+                                       else //for New
+                                       {
+                                               sUrl = url;
+                                       }
+                                       //Convert all HTML entities to their 
applicable characters
+
+                                       
sUrl=YAHOO.portico.html_entity_decode(sUrl);
+
+                                       // look for the word "DELETE" in URL
+                                       
if(YAHOO.portico.substr_count(sUrl,'delete')>0)
+                                       {
+                                               confirm_msg = 
YAHOO.portico.actions[task.groupIndex].confirm_msg;
+                                               if(confirm(confirm_msg))
+                                               {
+                                                       sUrl = sUrl + 
"&confirm=yes&phpgw_return_as=json";
+                                                       delete_record(sUrl);
+                                               }
+                                       }
+                                       else
+                                       {
+                                               
if(YAHOO.portico.substr_count(sUrl,'target=_blank')>0)
+                                               {
+                                                       
window.open(sUrl,'_blank');
+                                               }
+                                               else 
if(YAHOO.portico.substr_count(sUrl,'target=_lightbox')>0)
+                                               {
+                                                       //have to be defined as 
a local function. Example in invoice.list_sub.js
+                                                       //console.log(sUrl); // 
firebug
+                                                       showlightbox(sUrl);
+                                               }
+                                               else 
if(YAHOO.portico.substr_count(sUrl,'target=_tinybox')>0)
+                                               {
+                                                       //have to be defined as 
a local function. Example in invoice.list_sub.js
+                                                       //console.log(sUrl); // 
firebug
+                                                       showtinybox(sUrl);
+                                               }
+                                               else
+                                               {
+                                                       
window.open(sUrl,'_self');
+                                               }
+                                       }
+                               }
+                       }
+       };
+ 
/********************************************************************************
+ *
+ */
+       var GetMenuContext = function()
+       {
+               var opts = new Array();
+               var p=0;
+               for(var k =0; k < YAHOO.portico.actions.length; k ++)
+               {
+                       if(YAHOO.portico.actions[k].my_name != 'add')
+                       {       opts[p]=[{text: YAHOO.portico.actions[k].text}];
+                               p++;
+                       }
+               }
+               return opts;
+   }
+
+
+       if(!myDataTable.editor_action)
+       {
+               myDataTable.subscribe("rowMouseoverEvent", 
myDataTable.onEventHighlightRow);
+       }
+
+       myDataTable.subscribe("rowMouseoutEvent", 
myDataTable.onEventUnhighlightRow);
+
+       myContextMenu = new YAHOO.widget.ContextMenu("mycontextmenu", 
{trigger:myDataTable.getTbodyEl()});
+       myContextMenu.addItems(GetMenuContext());
+
+       myContextMenu.subscribe("beforeShow", onContextMenuBeforeShow);
+       myContextMenu.subscribe("hide", onContextMenuHide);
+       //Render the ContextMenu instance to the parent container of the 
DataTable
+       myContextMenu.subscribe("click", onContextMenuClick, myDataTable);
+       myContextMenu.render("datatable-container");
+
+
+       for(var i=0; i < YAHOO.portico.columnDefs.length;i++)
+       {
+               if( YAHOO.portico.columnDefs[i].sortable )
+               {
+                       YAHOO.util.Dom.getElementsByClassName( 
'yui-dt-resizerliner' , 'div' )[i].style.background  = '#D8D8DA 
url(phpgwapi/js/yahoo/assets/skins/sam/sprite.png) repeat-x scroll 0 -100px';
+               }
+               //title columns alwyas center
+//             YAHOO.util.Dom.getElementsByClassName( 'yui-dt-resizerliner', 
'div' )[0].style.textAlign = 'center';
+       }
+
+
+               //... calback methods for handling ajax calls
+               var ajaxResponseSuccess = function(o){
+                       message_delete = 
o.responseText.toString().replace("\"","").replace("\"","");
+                       delete_content_div("message",1);
+                       if(message_delete != "")
+                       {
+                               oDiv=document.createElement("DIV");
+                               txtNode = 
document.createTextNode(message_delete);
+                               oDiv.appendChild(txtNode);
+                               oDiv.style.color = '#009900';
+                               oDiv.style.fontWeight = 'bold';
+                               div_message.appendChild(oDiv);
+//                     alert(message_delete);
+                               message_delete = "";
+                       }
+
+                       var state = YAHOO.util.History.getCurrentState('state');
+                       handleHistoryNavigation(state);
+               };
+
+               var ajaxResponseFailure = function(o)
+               {
+                       alert('feil');
+               };
+
+
+       var delete_record = function(sUrl)
+       {
+               var callback =  {       success: function(o){
+                                                                       
message_delete = o.responseText.toString().replace("\"","").replace("\"","");
+                                                                       //shown 
message if delete records
+                                                                       
delete_content_div("message",1);
+                                                                       
if(message_delete != "")
+                                                                       {
+                                                                               
oDiv=document.createElement("DIV");
+                                                                               
txtNode = document.createTextNode(message_delete);
+                                                                               
oDiv.appendChild(txtNode);
+                                                                               
oDiv.style.color = '#009900';
+                                                                               
oDiv.style.fontWeight = 'bold';
+                                                                               
div_message.appendChild(oDiv);
+                                                                               
message_delete = "";
+                                                                       }
+
+                                                                       var 
state = YAHOO.util.History.getCurrentState('state');
+                                                                       
handleHistoryNavigation(state);
+                                                                       },
+                                                       failure: 
function(o){window.alert('Server or your connection is dead.')},
+                                                       timeout: 10000
+                                               };
+               var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, 
callback);
+       }
+
+ 
/********************************************************************************
+ * Delete all message un DIV 'message'
+ * type == 1   always delete div content
+ * type == 2   depende of if exists  "values_ds.message" values
+ */
+       var delete_content_div = function(mydiv,type)
+       {
+               div_message= YAHOO.util.Dom.get(mydiv);
+               //flag borrar
+               borrar = false;
+               //depende of values_ds.message
+               if(type == 2)
+               {
+                       //FIXME
+                       if(window.values_ds.message && 
window.values_ds.message.length)
+                       {
+                               //delete content
+                               borrar = true;
+                       }
+               }
+
+               //always delete div content
+               if(type == 1 || borrar)
+               {
+                       if ( div_message.hasChildNodes() )
+                       {
+                               while ( div_message.childNodes.length >= 1 )
+                           {
+                               div_message.removeChild( div_message.firstChild 
);
+                           }
+                       }
+               }
+       }
+
+
+
+       /* End from Property*/
+
+    var handlePagination = function(state) {
+        var sortedBy  = this.get("sortedBy");
+        var newState = getState(sortedBy.key, sortedBy.dir, 
state.recordOffset);
+        History.navigate("state", newState);
+     };
+    pag.unsubscribe("changeRequest", myDataTable.onPaginatorChangeRequest);
+    pag.subscribe("changeRequest", handlePagination, myDataTable, true);
+
+    myDataTable.doBeforeLoadData = function(oRequest, oResponse, oPayload) {
+        oPayload.totalRecords = oResponse.meta.totalResultsAvailable;
+               oPayload.pagination = { 
+                       rowsPerPage: oResponse.meta.pageSize || 10, 
+                       recordOffset: oResponse.meta.startIndex || 0 
+           }
+               oPayload.sortedBy = { 
+                       key: oResponse.meta.sortKey || "id", 
+                       dir: (oResponse.meta.sortDir) ? "yui-dt-" + 
oResponse.meta.sortDir : "yui-dt-asc" 
+               };
+               return true;
+    }
+
+       YAHOO.util.Event.on(
+           YAHOO.util.Selector.query('select'), 'change', function (e) {
+               //var val = this.value;
+                       var state = getState();
+                       YAHOO.util.Dom.setStyle('list_flash', 'display', 
'none');
+                       History.navigate('state', state);
+       });
+
+    YAHOO.util.Event.addListener('queryForm', "submit", function(e){
+        YAHOO.util.Event.stopEvent(e);
+               var state = getState();
+               YAHOO.util.Dom.setStyle('list_flash', 'display', 'none');
+               History.navigate('state', state);
+    });
+
+       YAHOO.util.Event.addListener('list_actions_form', "submit", function(e){
+               YAHOO.util.Event.stopEvent(e);
+               window.setTimeout(function() {
+                       var state = getState();
+                       var action = myDataSource.liveData + '&' + state;
+                       action = action.replace('&phpgw_return_as=json', '');
+                       
YAHOO.util.Dom.setAttribute(document.getElementById('list_actions_form'), 
'action', action);
+                  document.getElementById('list_actions_form').submit();
+               }, 0);
+       });
+
+       var History = YAHOO.util.History; 
+       var getState = function(skey, sdir, start) {
+               var state = YAHOO.portico.serializeForm('queryForm');
+               var sortedBy  = myDataTable.get("sortedBy");
+               skey = skey ? skey : sortedBy.key;
+               sdir = sdir ? sdir : sortedBy.dir; 
+               sdir = sdir == 'yui-dt-asc' ? 'asc' : 'desc';
+               start = start ? start : 0;
+               state += '&sort=' + skey;
+               state += '&dir=' + sdir;
+               state += '&startIndex=' + start;
+               return state;
+       }
+
+       var handleHistoryNavigation = function (state) {
+               var params = YAHOO.portico.parseQS(state);
+               YAHOO.portico.fillForm('queryForm', params);
+               myDataSource.sendRequest(state, {success: function(sRequest, 
oResponse, oPayload) {
+                       myDataTable.onDataReturnInitializeTable(sRequest, 
oResponse, pag);
+               }});
+       };
+       
+       var initialRequest = History.getBookmarkedState("state") || getState();
+       History.register("state", initialRequest, handleHistoryNavigation);
+/*
+       History.onReady(function() {
+               var state = YAHOO.util.History.getCurrentState('state');
+               handleHistoryNavigation(state);
+       });
+
+*/
+       History.initialize("yui-history-field", "yui-history-iframe");
+
+
+};
+
+
+
+
+       onDownloadClick = function()
+       {
+               var state = YAHOO.util.History.getCurrentState('state');
+               uri = parseUri(YAHOO.portico.dataSourceUrl);
+
+               var oArgs = uri.queryKey;
+               oArgs.phpgw_return_as = '';
+               oArgs.click_history = '';
+
+               donwload_func = oArgs.menuaction;
+               // modify actual function for "download" in path_values
+               // for example: property.uilocation.index --> 
property.uilocation.download
+               tmp_array= donwload_func.split(".")
+               tmp_array[2]="download"; //set function DOWNLOAD
+               donwload_func = tmp_array.join('.');
+               oArgs.menuaction=donwload_func;
+               oArgs.allrows=1;
+               oArgs.start=0;
+
+
+               if(typeof(config_values) != 'undefined' && 
config_values.particular_download != 'undefined' && 
config_values.particular_download)
+               {
+                       oArgs.menuaction = config_values.particular_download;
+               }
+
+               var requestUrl = phpGWLink('index.php', oArgs);
+               
+               requestUrl += '&' + state;
+
+               window.open(requestUrl,'window');
+   }
+
+
+
+YAHOO.util.Event.addListener(window, "load", 
YAHOO.portico.initializeDataTable);
+
+

Modified: trunk/property/inc/class.bodocument.inc.php
===================================================================
--- trunk/property/inc/class.bodocument.inc.php 2014-05-22 10:12:03 UTC (rev 
11986)
+++ trunk/property/inc/class.bodocument.inc.php 2014-05-22 14:09:28 UTC (rev 
11987)
@@ -44,6 +44,7 @@
                var $entity_id;
                var $status_id;
                var $allrows;
+               var $acl_location       = '.document';
 
                var $public_functions = array
                        (

Added: trunk/property/inc/class.uidocument2.inc.php
===================================================================
--- trunk/property/inc/class.uidocument2.inc.php                                
(rev 0)
+++ trunk/property/inc/class.uidocument2.inc.php        2014-05-22 14:09:28 UTC 
(rev 11987)
@@ -0,0 +1,1630 @@
+<?php
+
+       /**
+        * phpGroupWare - property: a part of a Facilities Management System.
+        *
+        * @author Sigurd Nes <address@hidden>
+        * @copyright Copyright (C) 2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+        * This file is part of phpGroupWare.
+        *
+        * phpGroupWare is free software; you can redistribute it and/or modify
+        * it under the terms of the GNU General Public License as published by
+        * the Free Software Foundation; either version 2 of the License, or
+        * (at your option) any later version.
+        *
+        * phpGroupWare is distributed in the hope that it will be useful,
+        * but WITHOUT ANY WARRANTY; without even the implied warranty of
+        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+        * GNU General Public License for more details.
+        *
+        * You should have received a copy of the GNU General Public License
+        * along with phpGroupWare; if not, write to the Free Software
+        * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
02110-1301  USA
+        *
+        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+        * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
+        * @package property
+        * @subpackage logistic
+        * @version $Id: class.uidocument2.inc.php 11942 2014-05-04 19:43:36Z 
sigurdne $
+        */
+       phpgw::import_class('phpgwapi.uicommon');
+       phpgw::import_class('phpgwapi.jquery');
+
+       class property_uidocument2 extends phpgwapi_uicommon
+       {
+
+               private $bo;
+               private $receipt = array();
+               public $public_functions = array
+               (
+                       'query'                                         => true,
+                       'index'                                         => true,
+                       'view'                                          => true,
+                       'add'                                           => true,
+                       'edit'                                          => true,
+                       'save'                                          => true,
+                       'delete'                                        => true,
+                       'delete_imported_records'       => true,
+                       'get_vendors'                           => true,
+                       'get_users'                                     => true,
+                       'edit_survey_title'                     => true,
+                       'get_files'                                     => true,
+                       'get_request'                           => true,
+                       'get_summation'                         => true,
+                       'view_file'                                     => true,
+                       'import'                                        => true,
+                       'download'                                      => true,
+                       'summation'                                     => true
+               );
+
+               public function __construct()
+               {
+                       parent::__construct('', 'yui3');
+
+                       $this->bo                                       = 
CreateObject('property.bodocument');
+                       $this->bocommon                         = & 
$this->bo->bocommon;
+                       $this->acl                                      = & 
$GLOBALS['phpgw']->acl;
+                       $this->acl_location                     = 
$this->bo->acl_location;
+                       $this->acl_read                         = 
$this->acl->check($this->acl_location, PHPGW_ACL_READ, 'property');
+                       $this->acl_add                          = 
$this->acl->check($this->acl_location, PHPGW_ACL_ADD, 'property');
+                       $this->acl_edit                         = 
$this->acl->check($this->acl_location, PHPGW_ACL_EDIT, 'property');
+                       $this->acl_delete                       = 
$this->acl->check($this->acl_location, PHPGW_ACL_DELETE, 'property');
+                       $this->acl_manage                       = 
$this->acl->check($this->acl_location, 16, 'property');
+
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
"property::documentation";
+       //                      
$GLOBALS['phpgw']->css->add_external_file('logistic/templates/base/css/base.css');
+               }
+
+
+               public function download()
+               {
+                       if(!$this->acl_read)
+                       {
+                               $this->bocommon->no_access();
+                               return;
+                       }
+
+                       $values = $this->query();
+
+                       $descr = array();
+                       $columns = array();
+                       $columns[]      = 'id';
+                       $columns[]      = 'title';
+                       $columns[]      = 'descr';
+                       $columns[]      = 'address';
+                       $columns[]      = 'cnt';
+
+                       foreach($columns as $_column)
+                       {
+                               $descr[] = lang(str_replace('_', ' ', 
$_column));
+                       }
+
+                       $this->bocommon->download($values,$columns,$descr);
+
+               }
+
+
+               private function _get_columns()
+               {
+
+           $columns = array();
+
+                       $columns[] = array(
+                                                       'key' => 'id',
+                                                       'label' => 'id',
+                                                       'hidden' => true
+                                               );
+                       $columns[] = array(
+                                                       'key' => 'loc1',
+                                                       'label' => 
lang('property'),
+                                                       'sortable' => true,
+                                               );
+                       $columns[] = array(
+                                                       'key' => 'loc2',
+                                                       'label' => 
lang('building'),
+                                                       'sortable' => true
+                                               );
+                       $columns[] = array(
+                                                       'key' => 'loc1_name',
+                                                       'label' => 'loc1_name',
+                                                       'sortable' => true
+                                               );
+                       $columns[] =                    array(
+                                                       'key' => 'loc2_name',
+                                                       'label' => 'loc2_name',
+                                                       'sortable' => true
+                                               );
+                       $columns[] =    array(
+                                                       'key' => 'address',
+                                                       'label' => 
lang('address'),
+                                                       'sortable' => true,
+                                               );
+                       $columns[] = array(
+                                                       'key' => 'link',
+                                                       'hidden' => true
+                                               );
+
+
+
+                       return $columns;
+               }
+               
+               public function index()
+               {
+                       if(!$this->acl_read)
+                       {
+                               $this->bocommon->no_access();
+                               return;
+                       }
+
+                       if (phpgw::get_var('phpgw_return_as') == 'json')
+                       {
+                               return $this->query();
+                       }
+
+                       self::add_javascript('phpgwapi', 'yui3', 
'datatable.js');
+                       phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('paginator');
+
+                       $categories = $this->_get_categories();
+                       $columns        = $this->_get_columns();
+
+
+                       $data = array(
+                               'datatable_name'        => lang('documents'),
+                               'form' => array(
+                                       'toolbar' => array(
+                                               'item' => array(
+                                                       array('type' => 
'filter',
+                                                               'name' => 
'cat_id',
+                                                               'text' => 
lang('category') . ':',
+                                                               'list' => 
$categories,
+                                                       ),
+                                                       array('type' => 'text',
+                                                               'text' => 
lang('search'),
+                                                               'name' => 
'query'
+                                                       ),
+                                                       array(
+                                                               'type' => 
'submit',
+                                                               'name' => 
'search',
+                                                               'value' => 
lang('Search')
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
lang('new'),
+                                                               'href' => 
self::link(array('menuaction' => 'property.uidocument2.add')),
+                                                               'class' => 
'new_item'
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
lang('download'),
+                                                               'href' => 
'javascript:window.open("'. self::link(array('menuaction' => 
'property.uidocument2.download', 'export' => true, 'allrows' => true)) . 
'","window")',
+                                                               'class' => 
'new_item'
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
$_SESSION['allrows'] ? lang('Show only active') : lang('Show all'),
+                                                               'href' => 
self::link(array('menuaction' => 'property.uidocument2.index', 'allrows' => 
true))
+                                                       ),
+
+                                               ),
+                                       ),
+                               ),
+                               'datatable' => array(
+                                       'source' => 
self::link(array('menuaction' => 'property.uidocument2.index', 
'phpgw_return_as' => 'json')),
+                                       'editor_action' => 
'property.uidocument2.edit_survey_title',
+                                       'field' => $columns
+                               ),
+                       );
+
+                       $parameters = array
+                               (
+                                       'parameter' => array
+                                       (
+                                               array
+                                               (
+                                                       'name'          => 'id',
+                                                       'source'        => 'id'
+                                               ),
+                                       )
+                               );
+
+                       $data['datatable']['actions'][] = array
+                                       (
+                                               'my_name'               => 
'view_survey',
+                                               'text'                  => 
lang('view'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'property.uidocument2.view'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+
+                       $data['datatable']['actions'][] = array
+                                       (
+                                               'my_name'               => 
'edit_survey',
+                                               'text'                  => 
lang('edit'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'property.uidocument2.edit'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+
+                       $data['datatable']['actions'][] = array
+                                       (
+                                               'my_name'               => 
'import_survey',
+                                               'text'                  => 
lang('import'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'property.uidocument2.import'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+
+
+                       if($GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_DELETE, 'property'))
+                       {
+                               $data['datatable']['actions'][] = array
+                                       (
+                                               'my_name'               => 
'delete_imported_records',
+                                               'text'                  => 
lang('delete imported records'),
+                                               'confirm_msg'   => lang('do you 
really want to delete this entry') . '?',
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'property.uidocument2.delete_imported_records'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+                       }
+
+                       if($GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_DELETE, 'property'))
+                       {
+                               $data['datatable']['actions'][] = array
+                                       (
+                                               'my_name'               => 
'delete_survey',
+                                               'text'                  => 
lang('delete'),
+                                               'confirm_msg'   => lang('do you 
really want to delete this entry') . '?',
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'property.uidocument2.delete'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+                       }
+
+                       self::render_template_xsl('datatable_common', $data);
+               }
+
+
+               public function query()
+               {
+                       $params = array(
+                               'start' => phpgw::get_var('startIndex', 'int', 
'REQUEST', 0),
+                               'results' => phpgw::get_var('results', 'int', 
'REQUEST', 0),
+                               'query' => phpgw::get_var('query'),
+                               'sort' => phpgw::get_var('sort'),
+                               'dir' => phpgw::get_var('dir'),
+                               'cat_id' => phpgw::get_var('cat_id', 'int', 
'REQUEST', 0),
+                               'allrows' => phpgw::get_var('allrows', 'bool')
+                       );
+
+                       $result_objects = array();
+                       $result_count = 0;
+
+                       $values = $this->bo->read($params);
+                       if ( phpgw::get_var('export', 'bool'))
+                       {
+                               return $values;
+                       }
+
+                       $result_data = array('results' => $values);
+
+                       $result_data['total_records'] = 
$this->bo->total_records;
+                       $result_data['start'] = $params['start'];
+                       $result_data['sort'] = $params['sort'];
+                       $result_data['dir'] = $params['dir'];
+
+                       array_walk(     $result_data['results'], array($this, 
'_add_links'), "property.uidocument2.view" );
+
+                       return $this->yui_results($result_data);
+               }
+
+
+               public function view()
+               {
+                       if(!$this->acl_read)
+                       {
+                               $this->bocommon->no_access();
+                               return;
+                       }
+                       $this->edit(null, $mode = 'view');
+               }
+
+               public function add()
+               {
+                       $this->edit();
+               }
+
+               /**
+               * Prepare data for view and edit - depending on mode
+               *
+               * @param array  $values  populated object in case of retry
+               * @param string $mode    edit or view
+               * @param int    $id      entity id - no id means 'new'
+               *
+               * @return void
+               */
+
+               public function edit($values = array(), $mode = 'edit')
+               {
+                       $id     = (int)phpgw::get_var('id');
+
+                       if(!$this->acl_add && !$this->acl_edit)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'property.uidocument2.view', 'id'=> $id));
+                       }
+
+                       if($mode == 'view')
+                       {
+                               if( !$this->acl_read)
+                               {
+                                       $this->bocommon->no_access();
+                                       return;
+                               }
+                       }
+                       else
+                       {
+                               if(!$this->acl_add && !$this->acl_edit)
+                               {
+                                       $this->bocommon->no_access();
+                                       return;
+                               }
+                       }
+
+                       
phpgwapi_cache::session_clear('property.request','session_data');
+
+                       phpgwapi_yui::tabview_setup('survey_edit_tabview');
+                       $tabs = array();
+                       $tabs['generic']        = array('label' => 
lang('generic'), 'link' => '#generic');
+                       $active_tab = 'generic';
+                       $tabs['documents']      = array('label' => 
lang('documents'), 'link' => null);
+                       $tabs['request']        = array('label' => 
lang('request'), 'link' => null);
+                       $tabs['summation']      = array('label' => 
lang('summation'), 'link' => null);
+                       $tabs['import']         = array('label' => 
lang('import'), 'link' => null);
+
+                       if ($id)
+                       {
+                               if($mode == 'edit')
+                               {
+                                       $tabs['import']['link'] = '#import';
+                               }
+                               $tabs['documents']['link'] = '#documents';
+                               $tabs['request']['link'] = '#request';
+                               $tabs['summation']['link'] = '#summation';
+
+                               if (!$values)
+                               {
+                                       $values = $this->bo->read_single( 
array('id' => $id,  'view' => $mode == 'view') );
+                               }
+                       }
+
+                       if(isset($values['location_code']) && 
$values['location_code'])
+                       {
+                               $values['location_data'] = 
execMethod('property.solocation.read_single', $values['location_code']);
+                       }
+
+                       $categories = $this->_get_categories($values['cat_id']);
+
+                       $bolocation     = CreateObject('property.bolocation');
+                       $location_data = $bolocation->initiate_ui_location(array
+                               (
+                                       'values'        => 
$values['location_data'],
+                                       'type_id'       => 2,
+                                       'required_level' => 1,
+                                       'no_link'       => $_no_link, // 
disable lookup links for location type less than type_id
+                                       'lookup_type'   => $mode == 'edit' ? 
'form2' : 'view2',
+                                       'tenant'        => false,
+                                       'lookup_entity' => array(),
+                                       'entity_data'   => 
isset($values['p'])?$values['p']:''
+                               ));
+
+                       $msgbox_data = 
$this->bocommon->msgbox_data($this->receipt);
+
+                       $file_def = array
+                       (
+                               array('key' => 
'file_name','label'=>lang('Filename'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 
'delete_file','label'=>lang('Delete 
file'),'sortable'=>false,'resizeable'=>true),
+                       );
+
+
+                       $datatable_def = array();
+                       $datatable_def[] = array
+                       (
+                               'container'             => 
'datatable-container_0',
+                               'requestUrl'    => 
json_encode(self::link(array('menuaction' => 'property.uidocument2.get_files', 
'id' => $id,'phpgw_return_as'=>'json'))),
+                               'ColumnDefs'    => $file_def,
+
+                       );
+
+                       $related_def = array
+                       (
+                               array('key' => 
'url','label'=>lang('id'),'sortable'=>true,'resizeable'=>true),
+                               array('key' => 
'title','label'=>lang('title'),'sortable'=>false,'resizeable'=>true,'width' => 
'100'),//width not working...
+                               array('key' => 
'status','label'=>lang('status'),'sortable'=>true,'resizeable'=>true),
+//                             array('key' => 
'category','label'=>lang('category'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 
'condition_degree','label'=>lang('condition 
degree'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 
'score','label'=>lang('score'),'sortable'=>true,'resizeable'=>true),
+                               array('key' => 
'amount_investment','label'=>lang('investment'),'sortable'=>true,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 
'amount_operation','label'=>lang('operation'),'sortable'=>true,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 
'amount_potential_grants','label'=>lang('potential 
grants'),'sortable'=>true,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+//                             array('key' => 
'planned_budget','label'=>lang('planned 
budget'),'sortable'=>true,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 
'recommended_year','label'=>lang('recommended 
year'),'sortable'=>true,'resizeable'=>true),
+                               array('key' => 
'planned_year','label'=>lang('planned 
year'),'sortable'=>true,'resizeable'=>true),
+                               array('key' => 
'related','label'=>lang('related'),'sortable'=>false,'resizeable'=>true),
+                       );
+
+                       $datatable_def[] = array
+                       (
+                               'container'             => 
'datatable-container_1',
+                               'requestUrl'    => 
json_encode(self::link(array('menuaction' => 
'property.uidocument2.get_request', 'id' => $id,'phpgw_return_as'=>'json'))),
+                               'ColumnDefs'    => $related_def
+                       );
+
+                       $summation_def = array
+                       (
+                               array('key' => 
'building_part','label'=>lang('building 
part'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 
'category','label'=>lang('category'),'sortable'=>true,'resizeable'=>true),
+                               array('key' => 'period_1','label'=>lang('year') 
. ':: < 1' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_2','label'=>lang('year') 
. ':: 1 - 5' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_3','label'=>lang('year') 
. ':: 6 - 10' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_4','label'=>lang('year') 
. ':: 11 - 15' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_5','label'=>lang('year') 
. ':: 16 - 20' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_6','label'=>lang('year') 
. ':: 21 +' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 
'sum','label'=>lang('sum'),'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                       );
+
+                       $datatable_def[] = array
+                       (
+                               'container'             => 
'datatable-container_2',
+                               'requestUrl'    => 
json_encode(self::link(array('menuaction' => 
'property.uidocument2.get_summation', 'id' => $id,'phpgw_return_as'=>'json'))),
+                               'ColumnDefs'    => $summation_def
+                       );
+
+                       $this->config                           = 
CreateObject('phpgwapi.config','property');
+                       $this->config->read();
+
+                       $data = array
+                       (
+                               'datatable_def'                                 
=> $datatable_def,
+                               'msgbox_data'                                   
=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                               'survey'                                        
        => $values,
+                               'location_data2'                                
=> $location_data,
+                               'lang_coordinator'                              
=> isset($this->config->config_data['lang_request_coordinator']) && 
$this->config->config_data['lang_request_coordinator'] ? 
$this->config->config_data['lang_request_coordinator'] : lang('coordinator'),
+                               'categories'                                    
=> array('options' => $categories),
+                               'status_list'                                   
=> array('options' => execMethod('property.bogeneric.get_list',array('type' => 
'condition_survey_status', 'selected' => $values['status_id'], 'add_empty' => 
true))),
+                               'editable'                                      
        => $mode == 'edit',
+                               'tabs'                                          
        => phpgwapi_yui::tabview_generate($tabs, $active_tab),
+                               'multiple_uploader'                             
=> $mode == 'edit' ? true : '',
+                       );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . '::' . lang('condition survey');
+
+                       if($mode == 'edit')
+                       {
+                               
$GLOBALS['phpgw']->jqcal->add_listener('report_date');
+                               phpgwapi_jquery::load_widget('core');
+                               self::add_javascript('property', 'portico', 
'condition_survey_edit.js');
+                               self::add_javascript('phpgwapi', 'yui3', 
'yui/yui-min.js');
+                               self::add_javascript('phpgwapi', 
'yui3-gallery', 'gallery-formvalidator/gallery-formvalidator-min.js');
+                               
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yui3-gallery/gallery-formvalidator/validatorCss.css');
+                       }
+
+                       self::add_javascript('property', 'portico', 
'condition_survey.js');
+
+                       self::add_javascript('phpgwapi', 'tinybox2', 
'packed.js');
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/tinybox2/style.css');
+
+//                     $GLOBALS['phpgw_info']['server']['no_jscombine'] = true;
+
+                       self::render_template_xsl(array('condition_survey'), 
$data);
+               }
+
+
+               /**
+               * Saves an entry to the database for new/edit - redirects to 
view
+               *
+               * @param int  $id  entity id - no id means 'new'
+               *
+               * @return void
+               */
+
+               public function save()
+               {
+                       $id = (int)phpgw::get_var('id');
+
+                       if ($id )
+                       {
+                               $values = $this->bo->read_single( array('id' => 
$id,  'view' => true) );
+                       }
+                       else
+                       {
+                               $values = array();
+                       }
+
+                       /*
+                       * Overrides with incoming data from POST
+                       */
+                       $values = $this->_populate($values);
+
+                       if( $this->receipt['error'] )
+                       {
+                               $this->edit( $values );
+                       }
+                       else
+                       {
+
+                               try
+                               {
+                                       $id = $this->bo->save($values);
+                               }
+
+                               catch(Exception $e)
+                               {
+                                       if ( $e )
+                                       {
+                                               
phpgwapi_cache::message_set($e->getMessage(), 'error'); 
+                                               $this->edit( $values );
+                                               return;
+                                       }
+                               }
+
+                               $this->_handle_files($id);
+                               if($_FILES['import_file']['tmp_name'])
+                               {
+                                       $this->_handle_import($id);
+                               }
+                               else
+                               {
+                                       phpgwapi_cache::message_set('ok!', 
'message'); 
+                                       
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'property.uidocument2.edit', 'id' => $id));
+                               }
+                       }
+               }
+
+               /**
+               * Fetch a list of files to be displayed in view/edit
+               *
+               * @param int  $id  entity id
+               *
+               * @return array $ResultSet json resultset
+               */
+
+               public function get_files()
+               {
+                       $id     = phpgw::get_var('id', 'int', 'REQUEST');
+
+                       if( !$this->acl_read)
+                       {
+                               return;
+                       }
+
+                       $link_file_data = array
+                       (
+                               'menuaction'    => 
'property.uidocument2.view_file',
+                               'id'                    => $id
+                       );
+
+
+                       $link_view_file = self::link($link_file_data);
+
+                       $vfs = CreateObject('phpgwapi.vfs');
+                       $vfs->override_acl = 1;
+
+                       $files = $vfs->ls(array(
+                               'string' => "/property/condition_survey/{$id}",
+                               'relatives' => array(RELATIVE_NONE)));
+
+                       $vfs->override_acl = 0;
+
+
+//------ Start pagination
+
+                       $start = phpgw::get_var('startIndex', 'int', 'REQUEST', 
0);
+                       $total_records = count($files);
+
+                       $num_rows = 
isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) && 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] ? (int) 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] : 15;
+
+                       if($allrows)
+                       {
+                               $out = $files;
+                       }
+                       else
+                       {
+                       //      $page = ceil( ( $start / $total_records ) * 
($total_records/ $num_rows) );
+                               $page = ceil( ( $start / $num_rows) );
+                               $files_part = array_chunk($files, $num_rows);
+                               $out = $files_part[$page];
+                       }
+
+//------ End pagination
+
+
+                       $lang_view = lang('click to view file');
+                       $lang_delete = lang('click to delete file');
+
+                       $values = array();
+                       foreach($out as $_entry )
+                       {
+                               $values[] = array
+                               (
+                                       'file_name' => "<a 
href='{$link_view_file}&amp;file_name={$_entry['name']}' target='_blank' 
title='{$lang_view}'>{$_entry['name']}</a>",
+                                       'delete_file' => "<input 
type='checkbox' name='file_action[]' value='{$_entry['name']}' 
title='$lang_delete'>",
+                               );
+                       }
+
+                       $data = array(
+                                'ResultSet' => array(
+                                       'totalResultsAvailable' => 
$total_records,
+                                       'startIndex' => $start,
+                                       'sortKey' => 'type', 
+                                       'sortDir' => "ASC", 
+                                       'Result' => $values,
+                                       'pageSize' => $num_rows,
+                                       'activePage' => floor($start / 
$num_rows) + 1
+                               )
+                       );
+                       return $data;
+
+               }
+
+               function get_summation()
+               {
+                       $id     = phpgw::get_var('id', 'int', 'REQUEST');
+                       $year   = phpgw::get_var('year', 'int', 'REQUEST');
+
+                       if( !$this->acl_read)
+                       {
+                               return;
+                       }
+
+                       $values = $this->bo->get_summation($id, $year);
+
+                       $total_records = count($values);
+
+                       $num_rows = 
isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) && 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] ? (int) 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] : 15;
+                       $start = phpgw::get_var('startIndex', 'int', 'REQUEST', 
0);
+
+                       $allrows = true;
+                       $num_rows = $total_records;
+
+                       if($allrows)
+                       {
+                               $out = $values;
+                       }
+                       else
+                       {
+                               $page = ceil( ( $start / $total_records ) * 
($total_records/ $num_rows) );
+                               $values_part = array_chunk($values, $num_rows);
+                               $out = $values_part[$page];
+                       }
+
+
+                       $data = array(
+                                'ResultSet' => array(
+                                       'totalResultsAvailable' => 
$total_records,
+                                       'startIndex' => $start,
+                                       'sortKey' => 'building_part', 
+                                       'sortDir' => "ASC", 
+                                       'Result' => $out,
+                                       'pageSize' => $num_rows,
+                                       'activePage' => floor($start / 
$num_rows) + 1
+                               )
+                       );
+                       return $data;
+               }
+
+
+               function get_request()
+               {
+                       $id     = phpgw::get_var('id', 'int', 'REQUEST');
+
+                       if( !$this->acl_read)
+                       {
+                               return;
+                       }
+
+                       $borequest      = CreateObject('property.borequest');
+                       $start = phpgw::get_var('startIndex', 'int', 'REQUEST', 
0);
+                       $sortKey = phpgw::get_var('sort', 'string', 'REQUEST', 
'request_id');
+                       $sortDir = phpgw::get_var('dir', 'string', 'REQUEST', 
'ASC');
+
+                       $criteria = array
+                       (
+                               'condition_survey_id'   => $id,
+                               'start'                                 => 
$start,
+                               'order'                                 => 
$sortKey,
+                               'sort'                                  => 
$sortDir
+                       );
+
+                       $values = $borequest->read_survey_data($criteria);
+                       $total_records = $borequest->total_records;
+
+                       $base_url = self::link(array('menuaction' => 
'property.uirequest.edit'));
+                       foreach ($values as &$_entry)
+                       {
+                                       $_entry['url']  = "<a 
href=\"{$base_url}&id={$_entry['id']}\" >{$_entry['id']}</a>";
+                       }
+
+                       $num_rows = 
isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) && 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] ? (int) 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] : 15;
+                       $data = array(
+                                'ResultSet' => array(
+                                       'totalResultsAvailable' => 
$total_records,
+                                       'startIndex' => $start,
+                                       'sortKey' => $sortKey, 
+                                       'sortDir' => $sortDir, 
+                                       'Result' => $values,
+                                       'pageSize' => $num_rows,
+                                       'activePage' => floor($start / 
$num_rows) + 1
+                               )
+                       );
+                       return $data;
+               }
+
+
+               /**
+               * Dowloads a single file to the browser
+               *
+               * @param int  $id  entity id
+               *
+               * @return file
+               */
+
+               function view_file()
+               {
+                       if(!$this->acl_read)
+                       {
+                               return lang('no access');
+                       }
+
+                       $bofiles        = CreateObject('property.bofiles');
+                       $bofiles->view_file('condition_survey');
+               }
+
+
+               /**
+               * Store and / or delete files related to an entity
+               *
+               * @param int  $id  entity id
+               *
+               * @return void
+               */
+               private function _handle_files($id)
+               {
+                       $id = (int)$id;
+                       if(!$id)
+                       {
+                               throw new 
Exception('uidocument2::_handle_files() - missing id');
+                       }
+                       $bofiles        = CreateObject('property.bofiles');
+
+                       if(isset($_POST['file_action']) && 
is_array($_POST['file_action']))
+                       {
+                               
$bofiles->delete_file("/condition_survey/{$id}/", array('file_action' => 
$_POST['file_action']));
+                       }
+                       $file_name=str_replace(' ','_',$_FILES['file']['name']);
+
+                       if($file_name)
+                       {
+                               if(!is_file($_FILES['file']['tmp_name']))
+                               {
+                                       
phpgwapi_cache::message_set(lang('Failed to upload file !'), 'error');
+                                       return;
+                               }
+
+                               $to_file = $bofiles->fakebase . 
'/condition_survey/' . $id . '/' . $file_name;
+                               if($bofiles->vfs->file_exists(array(
+                                       'string' => $to_file,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                               {
+                                       phpgwapi_cache::message_set(lang('This 
file already exists !'), 'error'); 
+                               }
+                               else
+                               {
+                                       
$bofiles->create_document_dir("condition_survey/{$id}");
+                                       $bofiles->vfs->override_acl = 1;
+
+                                       if(!$bofiles->vfs->cp (array (
+                                               'from'  => 
$_FILES['file']['tmp_name'],
+                                               'to'    => $to_file,
+                                               'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+                                       {
+                                               
phpgwapi_cache::message_set(lang('Failed to upload file !'), 'error'); 
+                                       }
+                                       $bofiles->vfs->override_acl = 0;
+                               }
+                       }
+               }
+
+
+
+               public function import()
+               {
+                       $id = phpgw::get_var('id', 'int', 'REQUEST');
+                       $this->_handle_import($id);
+               }
+
+               /**
+               * Import deviations found in the survey to the database from a 
spreadsheet
+               *
+               * @param int  $id  entity id
+               *
+               * @return void
+               */
+               private function _handle_import($id)
+               {
+                       $id = (int)$id;
+                       if(!$id)
+                       {
+                               throw new 
Exception('uidocument2::_handle_import() - missing id');
+                       }
+
+                       $step                   = phpgw::get_var('step', 'int', 
'REQUEST');
+                       $sheet_id               = phpgw::get_var('sheet_id', 
'int', 'REQUEST');
+
+                       $sheet_id = $sheet_id ? $sheet_id : 
phpgw::get_var('selected_sheet_id', 'int', 'REQUEST');
+
+                       if(!$step )
+                       {
+                               if($cached_file = 
phpgwapi_cache::session_get('property', 'condition_survey_import_file'))
+                               {
+                                       
phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
+                                       unlink($cached_file);
+                                       unset($cached_file);
+                               }
+                       }
+
+                       if($start_line  = phpgw::get_var('start_line', 'int', 
'REQUEST'))
+                       {
+                               phpgwapi_cache::system_set('property', 
'import_sheet_start_line', $start_line);
+                       }
+                       else
+                       {
+                               $start_line = 
phpgwapi_cache::system_get('property', 'import_sheet_start_line');
+                               $start_line = $start_line  ? $start_line : 1;
+                       }
+
+
+                       if($columns = phpgw::get_var('columns'))
+                       {
+                               phpgwapi_cache::system_set('property', 
'import_sheet_columns', $columns);
+                       }
+                       else
+                       {
+                               $columns = 
phpgwapi_cache::system_get('property', 'import_sheet_columns');
+                               $columns = $columns && is_array($columns) ? 
$columns : array();
+                       }
+
+
+                       if($step > 1)
+                       {
+                               $cached_file = 
phpgwapi_cache::session_get('property', 'condition_survey_import_file');
+                       }
+
+                       if($step ==1 || 
isset($_FILES['import_file']['tmp_name']))
+                       {
+                               $file = $_FILES['import_file']['tmp_name'];
+                               $cached_file ="{$file}_temporary_import_file";
+                               // save a copy to survive multiple steps
+                               file_put_contents($cached_file, 
file_get_contents($file));
+                               phpgwapi_cache::session_set('property', 
'condition_survey_import_file',$cached_file);
+                               $step = 1;
+
+                               // Add the file to documents
+                               $bofiles        = 
CreateObject('property.bofiles');
+                               $to_file = 
"{$bofiles->fakebase}/condition_survey/{$id}/" . str_replace(' 
','_',$_FILES['import_file']['name']);
+
+                               $bofiles->vfs->rm(array(
+                                               'string' => $to_file,
+                                               'relatives' => array(
+                                                       RELATIVE_NONE
+                                               )
+                                       )
+                               );
+
+                               
$bofiles->create_document_dir("condition_survey/{$id}");
+                               $bofiles->vfs->override_acl = 1;
+
+                               $bofiles->vfs->cp (array (
+                                       'from'  => 
$_FILES['import_file']['tmp_name'],
+                                       'to'    => $to_file,
+                                       'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)));
+                               $bofiles->vfs->override_acl = 0;
+                               unset($bofiles);
+                       }
+
+                       $tabs = array();
+
+                       switch ($step)
+                       {
+                               case 0:
+                                       $active_tab = 'step_1';
+                                       $lang_submit = lang('continue');
+                                       $tabs['step_1'] = array('label' => 
lang('choose file'), 'link' => '#step_1');
+                                       $tabs['step_2'] = array('label' => 
lang('choose sheet'), 'link' => null);
+                                       $tabs['step_3'] = array('label' => 
lang('choose start line'), 'link' => null);
+                                       $tabs['step_4'] = array('label' => 
lang('choose columns'), 'link' => null);
+                                       break;
+                               case 1:
+                                       $active_tab = 'step_2';
+                                       $lang_submit = lang('continue');
+                                       $tabs['step_1'] = array('label' => 
lang('choose file'), 'link' => self::link(array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 0, 'sheet_id' => 
$sheet_id, 'start_line' => $start_line )));
+                                       $tabs['step_2'] = array('label' => 
lang('choose sheet'), 'link' =>  '#step_2');
+                                       $tabs['step_3'] = array('label' => 
lang('choose start line'), 'link' => null);
+                                       $tabs['step_4'] = array('label' => 
lang('choose columns'), 'link' => null);
+                                       break;
+                               case 2:
+                                       $active_tab = 'step_3';
+                                       $lang_submit = lang('continue');
+                                       $tabs['step_1'] = array('label' => 
lang('choose file'), 'link' => self::link(array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 0, 'sheet_id' => 
$sheet_id, 'start_line' => $start_line )));
+                                       $tabs['step_2'] = array('label' => 
lang('choose sheet'), 'link' => self::link(array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 1, 'sheet_id' => 
$sheet_id, 'start_line' => $start_line )));
+                                       $tabs['step_3'] = array('label' => 
lang('choose start line'), 'link' => '#step_3');
+                                       $tabs['step_4'] = array('label' => 
lang('choose columns'), 'link' => null);
+                                       break;
+                               case 3:
+                                       $active_tab = 'step_4';
+                                       $lang_submit = lang('import');
+                                       $tabs['step_1'] = array('label' => 
lang('choose file'), 'link' => self::link(array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 0, 'sheet_id' => 
$sheet_id, 'start_line' => $start_line )));
+                                       $tabs['step_2'] = array('label' => 
lang('choose sheet'), 'link' => self::link(array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 1, 'sheet_id' => 
$sheet_id, 'start_line' => $start_line )));
+                                       $tabs['step_3'] = array('label' => 
lang('choose start line'), 'link' => self::link(array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 2, 'sheet_id' => 
$sheet_id, 'start_line' => $start_line )));
+                                       $tabs['step_4'] = array('label' => 
lang('choose columns'), 'link' =>  '#step_4');
+                                       break;
+/*
+                               case 4://temporary
+                                       
phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
+                                       unlink($cached_file);
+                                       
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction' => 
'property.uidocument2.import', 'id' =>$id, 'step' => 0));
+                                       break;
+*/
+                       }
+
+//-----------
+
+                       if(!$step )
+                       {
+                               phpgwapi_cache::session_clear('property', 
'condition_survey_import_file');
+                               unlink($cached_file);
+                       }
+                       else if ($cached_file)
+                       {
+                               phpgw::import_class('phpgwapi.phpexcel');
+
+                               try
+                               {
+                                       $objPHPExcel = 
PHPExcel_IOFactory::load($cached_file);
+                                       $AllSheets = 
$objPHPExcel->getSheetNames();
+
+                                       $sheets = array();
+                                       if($AllSheets)
+                                       {
+                                               foreach ($AllSheets as $key => 
$sheet)
+                                               $sheets[] = array
+                                               (
+                                                       'id'    => $key,
+                                                       'name'  => $sheet,
+                                                       'selected' => $sheet_id 
== $key
+                                               );
+                                       }
+
+                                       
$objPHPExcel->setActiveSheetIndex((int)$sheet_id);
+                               }
+                               catch(Exception $e)
+                               {
+                                       if ( $e )
+                                       {
+                                               
phpgwapi_cache::message_set($e->getMessage(), 'error'); 
+                                               
phpgwapi_cache::session_clear('property', 'condition_survey_import_file');
+                                               unlink($cached_file);
+                                       }
+                               }
+                       }
+
+                       $survey = $this->bo->read_single( array('id' => $id,  
'view' => $mode == 'view') );
+
+                       $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+                       $highestColumm = 
$objPHPExcel->getActiveSheet()->getHighestDataColumn();
+               $highestColumnIndex = 
PHPExcel_Cell::columnIndexFromString($highestColumm);
+
+                       $i = 0;
+                       $html_table = '<table border="1">';
+                       if($rows > 1 && $step == 2)
+                       {
+
+                               $cols = array();
+                               for ($j=0; $j < $highestColumnIndex; $j++ )
+                               {
+                                       $cols[] = $this->getexcelcolumnname($j);
+                               }
+
+                               $html_table .= "<tr><th align = 'center'>". 
lang('start'). "</th><th align='center'>" . implode("</th><th align='center'>", 
$cols) . '</th></tr>';
+                               foreach 
($objPHPExcel->getActiveSheet()->getRowIterator() as $row)
+                               {
+                                       if($i>20)
+                                       {
+                                               break;
+                                       }
+                                       $i++;
+
+                                       $row_key = $i;
+                                       $_checked = '';
+                                       if($start_line == $row_key)
+                                       {
+                                               $_checked = 'checked="checked"';
+                                       }
+
+                                       $_radio = "[{$row_key}]<input 
id=\"start_line\" type =\"radio\" {$_checked} name=\"start_line\" 
value=\"{$row_key}\">";
+
+                                       $cellIterator = $row->getCellIterator();
+                                       
$cellIterator->setIterateOnlyExistingCells(false);
+
+                                       $row_values = array();
+                                       foreach ($cellIterator as $cell)
+                                       {
+                                               if (!is_null($cell))
+                                               {
+                                                       $row_values[] = 
$cell->getCalculatedValue();
+                                               }
+                                       }
+                                       $html_table .= 
"<tr><td><pre>{$_radio}</pre></td><td>" . implode('</td><td>',$row_values) . 
'</td></tr>';
+                               }
+                               echo '</table>';
+                       }
+                       else if($rows > 1 && $step == 3)
+                       {
+                               $_options = array
+                               (
+                                       '_skip_import_'                         
=> 'Utelates fra import/implisitt',
+                                       'import_type'                           
=> 'import type',
+                                       'building_part'                         
=> 'bygningsdels kode',
+                                       'descr'                                 
        => 'Tilstandbeskrivelse',
+                                       'title'                                 
        => 'Tiltak/overskrift',
+                                       'condition_degree'                      
=> 'Tilstandsgrad',
+                                       'condition_type'                        
=> 'Konsekvenstype',
+                                       'consequence'                           
=> 'Konsekvensgrad',
+                                       'probability'                           
=> 'Sannsynlighet',
+                                       'due_year'                              
        => 'År (innen)',
+                                       'amount_investment'                     
=> 'Beløp investering',
+                                       'amount_operation'                      
=> 'Beløp drift',
+                                       'amount_potential_grants'       => 
'Potensial for offentlig støtte',
+                               );
+
+                               $custom = 
createObject('phpgwapi.custom_fields');
+                               $attributes = 
$custom->find('property','.project.request', 0, '','','',true, true);
+
+                               foreach($attributes as $attribute)
+                               {
+                                       
$_options["custom_attribute_{$attribute['id']}"] = $attribute['input_text'];
+                               }
+
+                               phpgw::import_class('phpgwapi.sbox');
+
+                               for ($j=0; $j < $highestColumnIndex; $j++ )
+                               {
+                                       $_column = 
$this->getexcelcolumnname($j);
+                                       $_value = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$start_line)->getCalculatedValue();
+                                       $selected = isset($columns[$_column]) 
&& $columns[$_column] ? $columns[$_column] : '';
+
+                                       $_listbox = 
phpgwapi_sbox::getArrayItem("columns[{$_column}]", $selected, $_options, true );
+                                       $html_table .= "<tr><td>[{$_column}] 
{$_value}</td><td>{$_listbox}</td><tr>";
+                               }
+                       }
+                       else if($rows > 1 && $step == 4)
+                       {
+
+                               $rows = 
$objPHPExcel->getActiveSheet()->getHighestDataRow();
+                               $rows = $rows ? $rows +1 : 0;
+
+                               $import_data = array();
+
+                               for ($i=$start_line; $i<$rows; $i++ )
+                               {
+                                       $_result = array();
+
+                                       foreach ($columns as $_row_key => 
$_value_key)
+                                       {
+                                               if($_value_key != 
'_skip_import_')
+                                               {
+                                                       $_result[$_value_key] = 
$objPHPExcel->getActiveSheet()->getCell("{$_row_key}{$i}")->getCalculatedValue();
+                                               }
+
+                                       }
+                                       $import_data[] = $_result;
+                               }
+                               if($import_data)
+                               {
+                                       try
+                                       {
+                                               $this->bo->import($survey, 
$import_data);
+                                       }
+                                       catch(Exception $e)
+                                       {
+                                               if ( $e )
+                                               {
+                                                       
phpgwapi_cache::message_set($e->getMessage(), 'error'); 
+                                               }
+                                       }
+                               }
+
+//                             $msg = "'{$cached_file}' contained " . 
count($import_data) . " lines";
+//                             phpgwapi_cache::message_set($msg, 'message'); 
+
+                       }
+
+
+
+                       $html_table .= '</table>';
+
+
+
+
+                       if(isset($survey['location_code']) && 
$survey['location_code'])
+                       {
+                               $survey['location_data'] = 
execMethod('property.solocation.read_single', $survey['location_code']);
+                       }
+
+                       $bolocation     = CreateObject('property.bolocation');
+                       $location_data = $bolocation->initiate_ui_location(array
+                               (
+                                       'values'        => 
$survey['location_data'],
+                                       'type_id'       => 2,
+                                       'lookup_type'   => 'view2',
+                                       'tenant'        => false,
+                                       'lookup_entity' => array(),
+                                       'entity_data'   => 
isset($survey['p'])?$survey['p']:''
+                               ));
+
+                       $data = array
+                       (
+                               'lang_submit'                                   
=> $lang_submit,
+                               'survey'                                        
        => $survey,
+                               'location_data2'                                
=> $location_data,
+                               'step'                                          
        => $step +1,
+                               'sheet_id'                                      
        => $sheet_id,
+                               'start_line'                                    
=> $start_line,
+                               'html_table'                                    
=> $html_table,
+                               'sheets'                                        
        => array('options' => $sheets),
+                               'tabs'                                          
        =>$GLOBALS['phpgw']->common->create_tabs($tabs, $active_tab),
+                       );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . '::' . lang('condition survey import');
+
+                       
self::render_template_xsl(array('condition_survey_import'), $data);
+
+               }
+
+
+               /**
+                * Get excel column name
+                * @param index : a column index we want to get the value in 
excel column format
+                * @return (string) : excel column format
+                */
+               private function getexcelcolumnname($index)
+               {
+                       //Get the quotient : if the index superior to base 26 
max ?
+                       $quotient = $index / 26;
+                       if ($quotient >= 1)
+                       {
+                               //If yes, get top level column + the current 
column code
+                               return getexcelcolumnname($quotient-1). 
chr(($index % 26)+65);
+                       }
+                       else
+                       {
+                               //If no just return the current column code
+                               return chr(65 + $index);
+                       }
+               }
+
+               /**
+               * Gets user candidates to be used as coordinator - called as 
ajax from edit form
+               *
+               * @param string  $query
+               *
+               * @return array 
+               */
+
+               public function get_users()
+               {
+                       if(!$this->acl_read)
+                       {
+                               return;
+                       }
+
+                       $query = phpgw::get_var('query');
+
+                       $accounts = 
$GLOBALS['phpgw']->accounts->get_list('accounts', $start, $sort, $order, 
$query,$offset);
+
+                       $values = array();
+                       foreach($accounts as $account)
+                       {
+                               if ($account->enabled)
+                               {
+                                       $values[] = array
+                                       (
+                                               'id'    => $account->id,
+                                               'name'  => 
$account->__toString(),
+                                       );
+                               }
+                       }
+                       return array('ResultSet'=> array('Result'=>$values));
+               }
+
+               /**
+               * Gets vendor canidated to be used as vendor - called as ajax 
from edit form
+               *
+               * @param string  $query
+               *
+               * @return array 
+               */
+
+               public function get_vendors()
+               {
+                       if(!$this->acl_read)
+                       {
+                               return;
+                       }
+
+                       $query = phpgw::get_var('query');
+
+                       $sogeneric = CreateObject('property.sogeneric', 
'vendor');
+                       $values = $sogeneric->read(array('query' => $query));
+                       foreach ($values as &$entry)
+                       {
+                               $entry['name'] = $entry['org_name'];
+                       }
+                       return array('ResultSet'=> array('Result'=>$values));
+               }
+
+               /**
+               * Edit title fo entity directly from table
+               *
+               * @param int  $id  id of entity
+               * @param string  $value new title of entity
+               *
+               * @return string text to appear in ui as receipt on action
+               */
+
+               public function edit_survey_title()
+               {
+                       $id = phpgw::get_var('id', 'int', 'GET');
+
+                       if(!$this->acl_edit)
+                       {
+                               return lang('no access');
+                       }
+
+                       if ($id )
+                       {
+                               $values = $this->bo->read_single( array('id' => 
$id,  'view' => true) );
+                               $values['title'] = phpgw::get_var('value');
+
+                               try
+                               {
+                                       $this->bo->edit_title($values);
+                               }
+
+                               catch(Exception $e)
+                               {
+                                       if ( $e )
+                                       {
+                                               return $e->getMessage(); 
+                                       }
+                               }
+                               return 'OK';
+                       }
+               }
+
+               /**
+               * Delete survey and all related info
+               *
+               * @param int  $id  id of entity
+               *
+               * @return string text to appear in ui as receipt on action
+               */
+
+               public function delete()
+               {
+                       if(!$GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_DELETE, 'property'))
+                       {
+                               return 'No access';
+                       }
+                       $id = phpgw::get_var('id', 'int', 'GET');
+
+                       try
+                       {
+                               $this->bo->delete($id);
+                       }
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       return $e->getMessage(); 
+                               }
+                       }
+                       return 'Deleted';
+               }
+
+               /**
+               * Delete related requests only
+               *
+               * @param int  $id  id of entity
+               *
+               * @return string text to appear in ui as receipt on action
+               */
+
+               public function delete_imported_records()
+               {
+                       if(!$GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_DELETE, 'property'))
+                       {
+                               return 'No access';
+                       }
+                       $id = phpgw::get_var('id', 'int', 'GET');
+
+                       try
+                       {
+                               $this->bo->delete_imported_records($id);
+                       }
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       return $e->getMessage(); 
+                               }
+                       }
+                       return 'Deleted';
+               }
+
+
+               /**
+               * Prepare data for summation - single survey or all
+               *
+               * @return void
+               */
+
+               public function summation()
+               {
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
"property::project::condition_survey::summation";
+
+                       if(!$this->acl_read)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'property.uidocument2.index'));
+                       }
+
+                       $params = array
+                       (
+                               'start'         => 0,
+                               'sort'          => 'id',
+                               'dir'           => 'asc',
+                               'cat_id'        => 0,
+                               'allrows'       => true
+                       );
+
+                       $survey_list = $this->bo->read($params);
+                       
+                       $surveys = array();
+                       $surveys[] = array
+                       (
+                               'id' => 0, 
+                               'name' => lang('select'), 
+                       );
+                       $surveys[] = array
+                       (
+                               'id' => -1, 
+                               'name' => lang('all'), 
+                       );
+
+                       foreach($survey_list as $survey)
+                       {
+                               $surveys[] = array
+                               (
+                                       'id'                    => 
$survey['id'], 
+                                       'name'                  => 
$survey['title'], 
+                                       'description'   => $survey['address'], 
+                               );
+                       }
+
+
+
+                       $current_year = date('Y');
+
+                       $years = array();
+
+                       for ($i=0; $i < 6; $i++ )
+                       {
+                               $years[] = array
+                               (
+                                       'id'    => $current_year,
+                                       'name'  => $current_year
+                               );
+                               $current_year++;
+                       }
+
+                       $summation_def = array
+                       (
+                               array('key' => 
'building_part','label'=>lang('building 
part'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 
'category','label'=>lang('category'),'sortable'=>false,'resizeable'=>true),
+                               array('key' => 'period_1','label'=>lang('year') 
. ':: < 1' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_2','label'=>lang('year') 
. ':: 1 - 5' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_3','label'=>lang('year') 
. ':: 6 - 10' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_4','label'=>lang('year') 
. ':: 11 - 15' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_5','label'=>lang('year') 
. ':: 16 - 20' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 'period_6','label'=>lang('year') 
. ':: 21 +' 
,'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                               array('key' => 
'sum','label'=>lang('sum'),'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.portico.FormatterAmount0'),
+                       );
+
+                       $datatable_def = array();
+                       $datatable_def[] = array
+                       (
+                               'container'             => 
'datatable-container_0',
+                               'requestUrl'    => 
json_encode(self::link(array('menuaction' => 
'property.uidocument2.get_summation', 'id' => $id,'phpgw_return_as'=>'json'))),
+                               'ColumnDefs'    => $summation_def
+                       );
+
+                       $data = array
+                       (
+                               'datatable_def'                 => 
$datatable_def,
+                               'surveys'                               => 
array('options' => $surveys),
+                               'years'                                 => 
array('options' => $years),
+                       );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . '::' . lang('condition survey');
+
+                       
self::render_template_xsl(array('condition_survey_summation'), $data);
+               }
+
+
+               /*
+               * Overrides with incoming data from POST
+               */
+               private function _populate($data = array())
+               {
+                       $insert_record = 
phpgwapi_cache::session_get('property', 'insert_record');
+
+                       $values = phpgw::get_var('values');
+
+                       $_fields = array
+                       (
+                               array
+                               (
+                                       'name' => 'title',
+                                       'type'  => 'string',
+                                       'required'      => true
+                               ),
+                               array
+                               (
+                                       'name' => 'descr',
+                                       'type'  => 'string',
+                                       'required'      => true
+                               ),
+                               array
+                               (
+                                       'name' => 'cat_id',
+                                       'type'  => 'integer',
+                                       'required'      => true
+                               ),
+                               array
+                               (
+                                       'name' => 'report_date',
+                                       'type'  => 'string',
+                                       'required'      => true
+                               ),
+                               array
+                               (
+                                       'name' => 'status_id',
+                                       'type'  => 'integer',
+                                       'required'      => true
+                               ),
+                               array
+                               (
+                                       'name' => 'vendor_id',
+                                       'type'  => 'integer',
+                                       'required'      => false
+                               ),
+                               array
+                               (
+                                       'name' => 'vendor_name',
+                                       'type'  => 'string',
+                                       'required'      => false
+                               ),
+                               array
+                               (
+                                       'name' => 'coordinator_id',
+                                       'type'  => 'integer',
+                                       'required'      => false
+                               ),
+                               array
+                               (
+                                       'name' => 'coordinator_name',
+                                       'type'  => 'string',
+                                       'required'      => false
+                               ),
+                               array
+                               (
+                                       'name' => 'multiplier',
+                                       'type'  => 'float',
+                                       'required'      => false
+                               ),
+                       );
+
+
+                       foreach ($_fields as $_field)
+                       {
+                               if($data[$_field['name']] = 
$_POST['values'][$_field['name']])
+                               {
+                                       $data[$_field['name']] =  
phpgw::clean_value($data[$_field['name']], $_field['type']);
+                               }
+                               if($_field['required'] && 
!$data[$_field['name']])
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('Please enter value for attribute 
%1', $_field['name']));
+                               }
+                       }
+
+//_debug_array($data);die();
+
+                       $values = 
$this->bocommon->collect_locationdata($data,$insert_record);
+
+                       if(!isset($values['location_code']) || ! 
$values['location_code'])
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('Please select a location !'));
+                       }
+
+                       /*
+                       * Extra data from custom fields
+                       */
+                       $values['attributes']   = 
phpgw::get_var('values_attribute');
+
+                       if(is_array($values['attributes']))
+                       {
+                               foreach ($values['attributes'] as $attribute )
+                               {
+                                       if($attribute['nullable'] != 1 && 
(!$attribute['value'] && !$values['extra'][$attribute['name']]))
+                                       {
+                                               
$this->receipt['error'][]=array('msg'=>lang('Please enter value for attribute 
%1', $attribute['input_text']));
+                                       }
+                               }
+                       }
+
+                       if(!isset($values['cat_id']) || !$values['cat_id'])
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('Please select a category !'));
+                       }
+
+                       if(!isset($values['title']) || !$values['title'])
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('Please give a title !'));
+                       }
+
+                       if(!isset($values['report_date']) || 
!$values['report_date'])
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('Please select a date!'));
+                       }
+
+                       return $values;
+               }
+
+               private function _get_categories($selected = 0)
+               {
+                       $cats   = CreateObject('phpgwapi.categories', -1, 
'property', $this->acl_location);
+                       $cats->supress_info     = true;
+                       $categories = 
$cats->formatted_xslt_list(array('format'=>'filter','selected' => 
$selected,'globals' => true,'use_acl' => $this->_category_acl));
+                       $default_value = array ('cat_id'=>'','name'=> lang('no 
category'));
+                       array_unshift ($categories['cat_list'],$default_value);
+
+                       foreach ($categories['cat_list'] as & $_category)
+                       {
+                               $_category['id'] = $_category['cat_id'];
+                       }
+
+                       return $categories['cat_list'];
+               }
+       }

Modified: trunk/property/templates/base/admin_entity.xsl
===================================================================
--- trunk/property/templates/base/admin_entity.xsl      2014-05-22 10:12:03 UTC 
(rev 11986)
+++ trunk/property/templates/base/admin_entity.xsl      2014-05-22 14:09:28 UTC 
(rev 11987)
@@ -1671,7 +1671,26 @@
                                                        </textarea>
                                                </td>
                                        </tr>
+
                                        <xsl:choose>
+                                               <xsl:when test="datatype = 
'link'">
+                                                       <tr>
+                                                               <td 
valign="top">
+                                                                       
<xsl:value-of select="php:function('lang', 'action')"/>
+                                                               </td>
+                                                               <td 
align="left">
+                                                                       
<textarea cols="60" rows="10" name="values[javascript_action]">
+                                                                               
<xsl:attribute name="title">
+                                                                               
        <xsl:text>optional javascript, __id__ is replaced by id</xsl:text>
+                                                                               
</xsl:attribute>
+                                                                               
<xsl:value-of select="value_javascript_action"/>
+                                                                       
</textarea>
+                                                               </td>
+                                                       </tr>
+                                               </xsl:when>
+                                       </xsl:choose>
+
+                                       <xsl:choose>
                                                <xsl:when test="multiple_choice 
= 1">
                                                        <tr>
                                                                <td 
valign="top">




reply via email to

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