[20848] update property

Sigurd Nes <[email protected]>
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 20848
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20848
Author:   sigurdne
Date:     2009-11-20 10:29:01 +0000 (Fri, 20 Nov 2009)
Log Message:
-----------
update property

Modified Paths:
--------------
    people/sigurdne/modules/property/trunk/help/NO/location.edit.odt
    people/sigurdne/modules/property/trunk/help/NO/location.index.odt
    people/sigurdne/modules/property/trunk/help/NO/location.view.odt
    people/sigurdne/modules/property/trunk/help/NO/project.edit.odt
    people/sigurdne/modules/property/trunk/help/NO/project.index.odt
    people/sigurdne/modules/property/trunk/help/NO/project.view.odt
    people/sigurdne/modules/property/trunk/help/NO/request.edit.odt
    people/sigurdne/modules/property/trunk/help/NO/request.index.odt
    people/sigurdne/modules/property/trunk/help/NO/request.view.odt
    people/sigurdne/modules/property/trunk/help/NO/template.edit_template.odt
    people/sigurdne/modules/property/trunk/help/NO/template.index.odt
    people/sigurdne/modules/property/trunk/help/NO/tts.add.odt
    people/sigurdne/modules/property/trunk/help/NO/tts.index.odt
    people/sigurdne/modules/property/trunk/help/NO/tts.view.odt
    people/sigurdne/modules/property/trunk/help/NO/wo_hour.index.odt
    people/sigurdne/modules/property/trunk/help/NO/workorder.edit.odt
    people/sigurdne/modules/property/trunk/help/NO/workorder.index.odt
    people/sigurdne/modules/property/trunk/inc/class.XmlToArray.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boXport.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boactor.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boadmin.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boadmin_entity.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boadmin_location.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boagreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boalarm.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boasync.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bobudget.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bocategory.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bocommon.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bodocument.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boentity.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bofiles.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bogab.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boifc.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boinvestment.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boinvoice.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bolocation.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bolookup.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bomigrate.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bor_agreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.borequest.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boresponsible.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bos_agreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.botenant_claim.inc.php
    people/sigurdne/modules/property/trunk/inc/class.botts.inc.php
    people/sigurdne/modules/property/trunk/inc/class.bowo_hour.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php
    people/sigurdne/modules/property/trunk/inc/class.custom_fields.inc.php
    people/sigurdne/modules/property/trunk/inc/class.custom_functions.inc.php
    people/sigurdne/modules/property/trunk/inc/class.excel.inc.php
    people/sigurdne/modules/property/trunk/inc/class.historylog.inc.php
    people/sigurdne/modules/property/trunk/inc/class.import.inc.php
    people/sigurdne/modules/property/trunk/inc/class.interlink.inc.php
    people/sigurdne/modules/property/trunk/inc/class.menu.inc.php
    people/sigurdne/modules/property/trunk/inc/class.ods.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soXport.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soactor.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soadmin.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soadmin_entity.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soadmin_location.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soagreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soalarm.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soasync.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sob_account.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sobudget.inc.php
    people/sigurdne/modules/property/trunk/inc/class.socategory.inc.php
    people/sigurdne/modules/property/trunk/inc/class.socommon.inc.php
    people/sigurdne/modules/property/trunk/inc/class.socustom.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sodocument.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soentity.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sogab.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soinvestment.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soinvoice.inc.php
    people/sigurdne/modules/property/trunk/inc/class.solocation.inc.php
    people/sigurdne/modules/property/trunk/inc/class.solookup.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sop_of_town.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sopricebook.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sor_agreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sorequest.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soresponsible.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sos_agreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sostandard_2.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sostandard_3.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sotemplate.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sotenant_claim.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sotts.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sowo_hour.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiXport.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiactor.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiadmin.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiadmin_entity.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiadmin_location.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiagreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uialarm.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiasync.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uib_account.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uibudget.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uicategory.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uicustom.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uidocument.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uientity.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uigab.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiinvestment.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiinvoice.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uilocation.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uilookup.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uimigrate.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uipricebook.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiproject.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uir_agreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uirequest.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiresponsible.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uis_agreement.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uistandard_2.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uistandard_3.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uitemplate.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uitenant_claim.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uitts.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiwo_hour.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiworkorder.inc.php
    people/sigurdne/modules/property/trunk/inc/cron/cron.php
    people/sigurdne/modules/property/trunk/inc/hook_home.inc.php
    people/sigurdne/modules/property/trunk/inc/hook_settings.inc.php
    people/sigurdne/modules/property/trunk/login.php
    people/sigurdne/modules/property/trunk/setup/default_records.inc.php
    people/sigurdne/modules/property/trunk/setup/phpgw_en.lang
    people/sigurdne/modules/property/trunk/setup/phpgw_no.lang
    people/sigurdne/modules/property/trunk/setup/setup.inc.php
    people/sigurdne/modules/property/trunk/setup/tables_current.inc.php
    people/sigurdne/modules/property/trunk/setup/tables_update.inc.php
    people/sigurdne/modules/property/trunk/templates/base/actor.xsl
    people/sigurdne/modules/property/trunk/templates/base/admin.xsl
    people/sigurdne/modules/property/trunk/templates/base/admin_entity.xsl
    people/sigurdne/modules/property/trunk/templates/base/admin_location.xsl
    people/sigurdne/modules/property/trunk/templates/base/agreement.xsl
    people/sigurdne/modules/property/trunk/templates/base/alarm_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/attrib_history.xsl
    people/sigurdne/modules/property/trunk/templates/base/attributes_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/b_account_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/budget.xsl
    people/sigurdne/modules/property/trunk/templates/base/category.xsl
    people/sigurdne/modules/property/trunk/templates/base/columns.xsl
    people/sigurdne/modules/property/trunk/templates/base/config.tpl
    people/sigurdne/modules/property/trunk/templates/base/css/base.css
    people/sigurdne/modules/property/trunk/templates/base/date_search.xsl
    people/sigurdne/modules/property/trunk/templates/base/document.xsl
    people/sigurdne/modules/property/trunk/templates/base/entity.xsl
    people/sigurdne/modules/property/trunk/templates/base/files.xsl
    people/sigurdne/modules/property/trunk/templates/base/group_select.xsl
    people/sigurdne/modules/property/trunk/templates/base/location.xsl
    people/sigurdne/modules/property/trunk/templates/base/lookup.xsl
    people/sigurdne/modules/property/trunk/templates/base/project.xsl
    people/sigurdne/modules/property/trunk/templates/base/r_agreement.xsl
    people/sigurdne/modules/property/trunk/templates/base/request.xsl
    people/sigurdne/modules/property/trunk/templates/base/responsible.xsl
    people/sigurdne/modules/property/trunk/templates/base/s_agreement.xsl
    people/sigurdne/modules/property/trunk/templates/base/tenant_claim.xsl
    people/sigurdne/modules/property/trunk/templates/base/tts.xsl
    people/sigurdne/modules/property/trunk/templates/base/user_id_select.xsl
    people/sigurdne/modules/property/trunk/templates/base/wo_hour.xsl
    people/sigurdne/modules/property/trunk/templates/base/workorder.xsl
    people/sigurdne/modules/property/trunk/tutorials/property/examples/install.apache.sh

Added Paths:
-----------
    people/sigurdne/modules/property/trunk/help/NO/wo_hour.deviation.odt
    people/sigurdne/modules/property/trunk/help/NO/wo_hour.edit.odt
    people/sigurdne/modules/property/trunk/help/NO/wo_hour.edit_deviation.odt
    people/sigurdne/modules/property/trunk/help/NO/wo_hour.prizebook.odt
    people/sigurdne/modules/property/trunk/help/NO/wo_hour.view.odt
    people/sigurdne/modules/property/trunk/help/NO/workorder.add.odt
    people/sigurdne/modules/property/trunk/help/NO/workorder.view.odt
    people/sigurdne/modules/property/trunk/inc/class.boevent.inc.php
    people/sigurdne/modules/property/trunk/inc/class.html2pdf.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soevent.inc.php
    people/sigurdne/modules/property/trunk/inc/class.sopending_action.inc.php
    people/sigurdne/modules/property/trunk/inc/class.test.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uicommon.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uidebug_json.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uievent.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uigab.inc_.php
    people/sigurdne/modules/property/trunk/inc/cron/README
    people/sigurdne/modules/property/trunk/inc/cron/default/
    people/sigurdne/modules/property/trunk/inc/cron/default/catch_ppc.php
    people/sigurdne/modules/property/trunk/inc/cron/default/export_info_as_files.php
    people/sigurdne/modules/property/trunk/inc/cron/default/forward_mail_as_sms.php
    people/sigurdne/modules/property/trunk/inc/cron/default/import_files.php
    people/sigurdne/modules/property/trunk/inc/cron/default/import_from_scanner.php
    people/sigurdne/modules/property/trunk/inc/cron/default/lag_lang_filer.php
    people/sigurdne/modules/property/trunk/inc/cron/default/oppdater_antall_leieobjekt.php
    people/sigurdne/modules/property/trunk/inc/cron/default/oppdater_namssakstatus_pr_leietaker.php
    people/sigurdne/modules/property/trunk/inc/cron/default/oppdater_utgaatt_objekt.php
    people/sigurdne/modules/property/trunk/inc/cron/default/organize_drawing.php
    people/sigurdne/modules/property/trunk/inc/cron/default/synkroniser_med_boei.php
    people/sigurdne/modules/property/trunk/inc/cron/default/update_googlemap.php
    people/sigurdne/modules/property/trunk/inc/cron/default/update_phpgw.php
    people/sigurdne/modules/property/trunk/inc/cron/default/update_workorder_status.php
    people/sigurdne/modules/property/trunk/inc/custom/README
    people/sigurdne/modules/property/trunk/inc/custom/default/
    people/sigurdne/modules/property/trunk/inc/custom/default/estimert_ferdigdato_til_leieobjekt_BBB.php
    people/sigurdne/modules/property/trunk/inc/custom/default/hent_maaler_nr_til_besikt_rapport.php
    people/sigurdne/modules/property/trunk/inc/custom/default/innflyttetdato_entity_2_11_BBB.php
    people/sigurdne/modules/property/trunk/inc/custom/default/kalkuler_risiko_for_ros.php
    people/sigurdne/modules/property/trunk/inc/export/README
    people/sigurdne/modules/property/trunk/inc/export/default/
    people/sigurdne/modules/property/trunk/inc/export/default/Agresso
    people/sigurdne/modules/property/trunk/inc/export/default/Basware_X114
    people/sigurdne/modules/property/trunk/inc/export/default/Ecolink
    people/sigurdne/modules/property/trunk/inc/export/default/GABNr
    people/sigurdne/modules/property/trunk/inc/export/default/Kemner_kvittering
    people/sigurdne/modules/property/trunk/inc/hook_config.inc.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_LGPL.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/FAQ.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/acceptpagebreak.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/addfont.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/addlink.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/addpage.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/aliasnbpages.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/cell.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/close.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/error.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/footer.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/fpdf.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/getstringwidth.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/getx.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/gety.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/header.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/image.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/index.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/line.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/link.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/ln.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/multicell.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/output.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/pageno.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/rect.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setauthor.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setautopagebreak.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setcompression.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setcreator.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setdisplaymode.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setdrawcolor.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setfillcolor.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setfont.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setfontsize.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setkeywords.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setleftmargin.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setlinewidth.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setlink.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setmargins.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setrightmargin.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setsubject.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/settextcolor.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/settitle.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/settopmargin.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setx.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/setxy.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/sety.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/text.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/doc/write.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/courier.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/helvetica.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/helveticab.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/helveticabi.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/helveticai.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1250.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1251.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1252.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1253.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1254.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1255.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1257.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp1258.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/cp874.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-1.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-11.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-15.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-16.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-2.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-4.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-5.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-7.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/iso-8859-9.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/koi8-r.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/koi8-u.map
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/makefont/makefont.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/symbol.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/times.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/timesb.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/timesbi.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/timesi.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/font/zapfdingbats.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/fpdf.css
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/fpdf.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/histo.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/install.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/license.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/20k_c1.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/20k_c2.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/calligra.afm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/calligra.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/calligra.ttf
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/calligra.z
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/countries.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/index.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/logo.png
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/logo_pb.png
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/makefont.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto1.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto1.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto2.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto2.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto3.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto3.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto4.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto4.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto5.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto5.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto6.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto6.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto7.htm
    people/sigurdne/modules/property/trunk/inc/html2pdf/_fpdf/tutorial/tuto7.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_lisez_moi.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/_mypdf/
    people/sigurdne/modules/property/trunk/inc/html2pdf/_mypdf/00_fpdf_codebar.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_mypdf/01_fpdf_bookmark.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_mypdf/02_fpdf_formulaire.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_mypdf/99_fpdf_protection.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_mypdf/mypdf.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/_read_me.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/about.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple00.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple01.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple02.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple03.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple04.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple05.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple06.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple07.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple08.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple09.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple10.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple11.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple12.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple13.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/exemple14.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/js1.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/js2.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/js3.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/qrcode.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/regle.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/about.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/bas_page.png
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple00.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple01.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple02.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple03.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple04.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple05.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple06.css
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple06.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple07a.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple07b.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple08.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple09.png.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple10.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple10a.gif
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple10b.jpg
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple10c.gif
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple11.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple12.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple13.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/exemple14.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/logoHTMLtoPDF.gif
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/off.png
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/puce.gif
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/puce2.gif
    people/sigurdne/modules/property/trunk/inc/html2pdf/exemples/res/regle.png
    people/sigurdne/modules/property/trunk/inc/html2pdf/html2pdf.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/ca.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/da.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/de.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/en.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/es.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/fr.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/it.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/nl.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/pt.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/langues/tr.txt
    people/sigurdne/modules/property/trunk/inc/html2pdf/parsingHTML.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/qrcode/
    people/sigurdne/modules/property/trunk/inc/html2pdf/qrcode/qrcode.class.php
    people/sigurdne/modules/property/trunk/inc/html2pdf/styleHTML.class.php
    people/sigurdne/modules/property/trunk/inc/import/README
    people/sigurdne/modules/property/trunk/inc/import/default/
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_BKK
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_BKK_csv
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_Kemner
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_Kemner_xml
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_Service
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_Service_xml
    people/sigurdne/modules/property/trunk/inc/import/default/Import_fra_basware_X205
    people/sigurdne/modules/property/trunk/inc/import/default/import_fra_Service_xls
    people/sigurdne/modules/property/trunk/js/newdesign/
    people/sigurdne/modules/property/trunk/js/newdesign/CRUDTable.php
    people/sigurdne/modules/property/trunk/js/yahoo/
    people/sigurdne/modules/property/trunk/js/yahoo/account.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/actor.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_entity.attribute.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_entity.attribute_group.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_entity.category.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_entity.function_group.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_entity.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_location.attribute.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_location.attribute_group.js
    people/sigurdne/modules/property/trunk/js/yahoo/admin_location.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/agreement.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/agreement.edit_item.js
    people/sigurdne/modules/property/trunk/js/yahoo/agreement.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/agreement.view.js
    people/sigurdne/modules/property/trunk/js/yahoo/agreement.view_item.js
    people/sigurdne/modules/property/trunk/js/yahoo/alarm.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/alarm.list_alarm.js
    people/sigurdne/modules/property/trunk/js/yahoo/budget.basis.js
    people/sigurdne/modules/property/trunk/js/yahoo/budget.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/budget.obligations.js
    people/sigurdne/modules/property/trunk/js/yahoo/category.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/custom.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/custom.view.js
    people/sigurdne/modules/property/trunk/js/yahoo/document.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/document.list_doc.js
    people/sigurdne/modules/property/trunk/js/yahoo/document.view.js
    people/sigurdne/modules/property/trunk/js/yahoo/entity.attrib_history.js
    people/sigurdne/modules/property/trunk/js/yahoo/entity.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/entity.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/event.schedule.js
    people/sigurdne/modules/property/trunk/js/yahoo/gab.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/gab.list_detail.js
    people/sigurdne/modules/property/trunk/js/yahoo/investment.history.js
    people/sigurdne/modules/property/trunk/js/yahoo/investment.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/invoice.consume.js
    people/sigurdne/modules/property/trunk/js/yahoo/invoice.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/invoice.list_sub.js
    people/sigurdne/modules/property/trunk/js/yahoo/invoice.paid.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/location.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/location.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/location.summary.js
    people/sigurdne/modules/property/trunk/js/yahoo/lookup.entity.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/lookup.tenant.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/lookup.vendor.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/pricebook.activity.js
    people/sigurdne/modules/property/trunk/js/yahoo/pricebook.agreement_group.js
    people/sigurdne/modules/property/trunk/js/yahoo/project.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/project.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/property.js
    people/sigurdne/modules/property/trunk/js/yahoo/property2.js
    people/sigurdne/modules/property/trunk/js/yahoo/request.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/request.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/responsible.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/schedule.js
    people/sigurdne/modules/property/trunk/js/yahoo/template.hour.js
    people/sigurdne/modules/property/trunk/js/yahoo/template.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/tenant_claim.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/tts.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/tts.index.simple.js
    people/sigurdne/modules/property/trunk/js/yahoo/tts.view.js
    people/sigurdne/modules/property/trunk/js/yahoo/ui_agreement.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/uiasync.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/uis_agreement.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/uis_agreement.edit_item.js
    people/sigurdne/modules/property/trunk/js/yahoo/uisagreement.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/uistandard_2.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/uistandard_3.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/uitenant.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/wo_hour.deviation.js
    people/sigurdne/modules/property/trunk/js/yahoo/wo_hour.index.js
    people/sigurdne/modules/property/trunk/js/yahoo/wo_hour.prizebook.js
    people/sigurdne/modules/property/trunk/js/yahoo/wo_hour.save_template.js
    people/sigurdne/modules/property/trunk/js/yahoo/wo_hour.template.js
    people/sigurdne/modules/property/trunk/js/yahoo/wo_hour.view.js
    people/sigurdne/modules/property/trunk/js/yahoo/workorder.edit.js
    people/sigurdne/modules/property/trunk/js/yahoo/workorder.index.js
    people/sigurdne/modules/property/trunk/setup/default/
    people/sigurdne/modules/property/trunk/setup/default/README
    people/sigurdne/modules/property/trunk/setup/default/phpgw_no.lang_example
    people/sigurdne/modules/property/trunk/templates/base/cat_sub_select.xsl
    people/sigurdne/modules/property/trunk/templates/base/contact_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/contact_view.xsl
    people/sigurdne/modules/property/trunk/templates/base/css/property.css
    people/sigurdne/modules/property/trunk/templates/base/ecodimb_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/ecodimb_view.xsl
    people/sigurdne/modules/property/trunk/templates/base/event.xsl
    people/sigurdne/modules/property/trunk/templates/base/event_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/event_schedule.xsl
    people/sigurdne/modules/property/trunk/templates/base/event_schedule_week.xsl
    people/sigurdne/modules/property/trunk/templates/base/project_group_form.xsl
    people/sigurdne/modules/property/trunk/templates/base/project_group_view.xsl
    people/sigurdne/modules/property/trunk/templates/base/yui_property_i18n.xsl
    people/sigurdne/modules/property/trunk/templates/portico/
    people/sigurdne/modules/property/trunk/templates/portico/css/
    people/sigurdne/modules/property/trunk/templates/portico/css/base.css
    people/sigurdne/modules/property/trunk/templates/portico/images/
    people/sigurdne/modules/property/trunk/templates/portico/images/agreement.png
    people/sigurdne/modules/property/trunk/templates/portico/images/budget.png
    people/sigurdne/modules/property/trunk/templates/portico/images/check.png
    people/sigurdne/modules/property/trunk/templates/portico/images/custom.png
    people/sigurdne/modules/property/trunk/templates/portico/images/documentation.png
    people/sigurdne/modules/property/trunk/templates/portico/images/entity_1.png
    people/sigurdne/modules/property/trunk/templates/portico/images/entity_2.png
    people/sigurdne/modules/property/trunk/templates/portico/images/helpdesk.png
    people/sigurdne/modules/property/trunk/templates/portico/images/ifc.png
    people/sigurdne/modules/property/trunk/templates/portico/images/invoice.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_1.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_2.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_3.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_4.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_gabnr.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_summary.png
    people/sigurdne/modules/property/trunk/templates/portico/images/location_tenant.png
    people/sigurdne/modules/property/trunk/templates/portico/images/navbar.png
    people/sigurdne/modules/property/trunk/templates/portico/images/project.png
    people/sigurdne/modules/property/trunk/templates/portico/images/project_request.png
    people/sigurdne/modules/property/trunk/templates/portico/images/project_template.png
    people/sigurdne/modules/property/trunk/templates/portico/images/project_tenant_claim.png
    people/sigurdne/modules/property/trunk/templates/portico/images/project_workorder.png
    people/sigurdne/modules/property/trunk/templates/portico/images/report.png

Modified: people/sigurdne/modules/property/trunk/help/NO/location.edit.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/location.index.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/location.view.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/project.edit.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/project.index.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/project.view.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/request.edit.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/request.index.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/request.view.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/template.edit_template.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/template.index.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/tts.add.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/tts.index.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/tts.view.odt
===================================================================
(Binary files differ)

Added: people/sigurdne/modules/property/trunk/help/NO/wo_hour.deviation.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/wo_hour.deviation.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: people/sigurdne/modules/property/trunk/help/NO/wo_hour.edit.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/wo_hour.edit.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: people/sigurdne/modules/property/trunk/help/NO/wo_hour.edit_deviation.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/wo_hour.edit_deviation.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: people/sigurdne/modules/property/trunk/help/NO/wo_hour.index.odt
===================================================================
(Binary files differ)

Added: people/sigurdne/modules/property/trunk/help/NO/wo_hour.prizebook.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/wo_hour.prizebook.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: people/sigurdne/modules/property/trunk/help/NO/wo_hour.view.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/wo_hour.view.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: people/sigurdne/modules/property/trunk/help/NO/workorder.add.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/workorder.add.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: people/sigurdne/modules/property/trunk/help/NO/workorder.edit.odt
===================================================================
(Binary files differ)

Modified: people/sigurdne/modules/property/trunk/help/NO/workorder.index.odt
===================================================================
(Binary files differ)

Added: people/sigurdne/modules/property/trunk/help/NO/workorder.view.odt
===================================================================
(Binary files differ)


Property changes on: people/sigurdne/modules/property/trunk/help/NO/workorder.view.odt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: people/sigurdne/modules/property/trunk/inc/class.XmlToArray.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.XmlToArray.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.XmlToArray.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -525,7 +525,7 @@
 			$children = array(); // Contains node data
 			if (isset($vals[$i]['tag']))
 			{
-				if( trim($vals[$i]['value']) != '' )
+				if( isset($vals[$i]['value']) && trim($vals[$i]['value']) != '' )
 				{
 					$children = $this->_onValue( $vals[$i]['value'] );
 				}

Modified: people/sigurdne/modules/property/trunk/inc/class.boXport.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boXport.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boXport.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -109,11 +109,11 @@
 
 		function select_import_conv($selected='')
 		{
-			$dir_handle = @opendir(PHPGW_APP_INC . '/import');
-			$i=0; $myfilearray = '';
+			$dir_handle = @opendir(PHPGW_SERVER_ROOT . "/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}");
+			$i=0; $myfilearray = array();
 			while ($file = readdir($dir_handle))
 			{
-				if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . '/import/' . $file) )
+				if ((substr($file, 0, 1) != '.') && is_file(PHPGW_SERVER_ROOT . "/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$file}") )
 				{
 					$myfilearray[$i] = $file;
 					$i++;
@@ -153,11 +153,11 @@
 
 		function select_export_conv($selected='')
 		{
-			$dir_handle = @opendir(PHPGW_APP_INC . '/export');
-			$i=0; $myfilearray = '';
+			$dir_handle = @opendir(PHPGW_SERVER_ROOT . "/property/inc/export/{$GLOBALS['phpgw_info']['user']['domain']}");
+			$i=0; $myfilearray = array();
 			while ($file = readdir($dir_handle))
 			{
-				if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . '/export/' . $file) )
+				if ((substr($file, 0, 1) != '.') && is_file(PHPGW_SERVER_ROOT . "/property/inc/export/{$GLOBALS['phpgw_info']['user']['domain']}/{$file}") )
 				{
 					$myfilearray[$i] = $file;
 					$i++;
@@ -197,7 +197,7 @@
 
 		function select_rollback_file($selected='')
 		{
-			$this->config->read_repository();
+			$this->config->read();
 			$file_catalog = $this->config->config_data['export_path'];
 
 			$dir_handle = @opendir($file_catalog);
@@ -244,7 +244,7 @@
 
 		function import($invoice_common,$download)
 		{
-			include (PHPGW_APP_INC . '/import/' . $invoice_common['conv_type']);
+			include (PHPGW_SERVER_ROOT . "/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$invoice_common['conv_type']}");
 			$invoice = new import_conv;
 
 			$buffer = $invoice->import($invoice_common,$download);
@@ -268,7 +268,7 @@
 			$pre_transfer = $data['pre_transfer'];
 			$force_period_year = $data['force_period_year'];
 
-		 	include(PHPGW_SERVER_ROOT.'/'.'property'.'/inc/export/' . $conv_type);
+		 	include(PHPGW_SERVER_ROOT . "/property/inc/export/{$GLOBALS['phpgw_info']['user']['domain']}/{$conv_type}");
 			$invoice = new export_conv;
 
 			$buffer = $invoice->overfor($download,$pre_transfer,$force_period_year);
@@ -278,7 +278,7 @@
 
 		function rollback($conv_type,$role_back_date,$rollback_file)
 		{
-			include (PHPGW_APP_INC . '/export/' . $conv_type);
+			include (PHPGW_SERVER_ROOT . "/property/inc/export/{$GLOBALS['phpgw_info']['user']['domain']}/{$conv_type}");
 			$invoice = new export_conv;
 			$buffer = $invoice->RullTilbake($role_back_date,$rollback_file);
 			return $buffer;

Modified: people/sigurdne/modules/property/trunk/inc/class.boactor.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boactor.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boactor.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -24,7 +24,7 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage admin
- 	* @version $Id$
+ 	* @version $Id$
 	*/
 
 	/**
@@ -59,10 +59,9 @@
 
 		function property_boactor($session=false)
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->so 		= CreateObject('property.soactor');
-			$this->bocommon 	= CreateObject('property.bocommon');
-			$this->custom 		= createObject('property.custom_fields');
+			$this->bocommon 	= & $this->so->bocommon;
+			$this->custom 		= & $this->so->custom;
 
 			if ($session)
 			{
@@ -155,10 +154,11 @@
 			return (!!($has & $needed) == true);
 		}
 
-		function read()
+		function read($dry_run='')
 		{
 			$actor = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'filter' => $this->filter,'cat_id' => $this->cat_id,'allrows'=>$this->allrows,'member_id'=>$this->member_id));
+											'filter' => $this->filter,'cat_id' => $this->cat_id,'allrows'=>$this->allrows,
+											'member_id'=>$this->member_id, 'dry_run' => $dry_run));
 			$this->total_records = $this->so->total_records;
 
 			$this->uicols	= $this->so->uicols;
@@ -185,6 +185,20 @@
 			return $values;
 		}
 
+		/**
+		* Arrange attributes within groups
+		*
+		* @param string  $location    the name of the location of the attribute
+		* @param array   $attributes  the array of the attributes to be grouped
+		*
+		* @return array the grouped attributes
+		*/
+
+		public function get_attribute_groups($location, $attributes = array())
+		{
+			return $this->custom->get_attribute_groups('property', $location, $attributes);
+		}
+
 		function save($actor,$values_attribute='')
 		{
 			if(is_array($values_attribute))
@@ -218,7 +232,8 @@
 			{
 				$selected=$GLOBALS['phpgw_info']['user']['preferences']['property']["actor_columns_" . $this->role];
 			}
-			$columns = $this->custom->find('property','.' . $this->role, 0, '','','',true);
+			$filter = array('list' => ''); // translates to "list IS NULL"
+			$columns = $this->custom->find('property','.' . $this->role, 0, '','','',true, false, $filter);
 			$column_list=$this->bocommon->select_multi_list($selected,$columns);
 
 			return $column_list;
@@ -236,4 +251,3 @@
 			return $this->bocommon->preserve_attribute_values($values,$values_attribute);
 		}
 	}
-

Modified: people/sigurdne/modules/property/trunk/inc/class.boadmin.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boadmin.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boadmin.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -4,7 +4,7 @@
 	*
 	* @author Sigurd Nes <[email protected]>
 	* @copyright Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. http://www.fsf.org/
-	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3 or later
+	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v2 or later
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage admin
@@ -14,7 +14,7 @@
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -49,6 +49,7 @@
 			$this->acl 			= & $GLOBALS['phpgw']->acl;
 			$this->bocommon 	= CreateObject('property.bocommon');
 			$this->right		= array(1,2,4,8,16);
+			$this->account_id	= $GLOBALS['phpgw_info']['user']['account_id'];
 
 			if ($session)
 			{
@@ -192,7 +193,7 @@
 			foreach ( $totalacl as $user_id => $rights )
 			{
 				$user_checked[] = $user_id;
-				$this->acl->set_account_id($user_id, true);
+				$this->acl->set_account_id($user_id, true, $this->acl_app, $this->location, $account_type = 'accounts');
 				$this->acl->delete($this->acl_app, $this->location, $grantor, $type);
 				$this->acl->add($this->acl_app, $this->location, $rights, $grantor, $type);
 				$this->acl->save_repository($this->acl_app, $this->location);
@@ -253,7 +254,7 @@
 				}
 				else
 				{
-					$grantor = $GLOBALS['phpgw_info']['user']['account_id'];
+					$grantor = $this->account_id;
 				}
 			}
 
@@ -271,10 +272,12 @@
 			if($type == 'groups')
 			{
 				$check_account_type = array('accounts');
+				$acl_account_type = 'accounts';
 			}
 			else
 			{
 				$check_account_type = array('groups','accounts');
+				$acl_account_type = 'both';
 			}
 
 			$grantor = -1;
@@ -286,7 +289,7 @@
 				}
 				else
 				{
-					$grantor = $GLOBALS['phpgw_info']['user']['account_id'];
+					$grantor = $this->account_id;
 				}
 			}
 
@@ -321,7 +324,7 @@
 						$user_list[$j]['initials']			= $this->so->get_initials($account->id);
 					}
 
-					$this->acl->set_account_id($account->id, true);
+					$this->acl->set_account_id($account->id, true, $this->acl_app, $this->location, $acl_account_type);
 
 					$count_right=count($right);
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boadmin_entity.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boadmin_entity.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boadmin_entity.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -55,6 +55,11 @@
 		public $order;
 
 		/**
+		* @var string $type entity set
+		*/
+
+		public $type;
+		/**
 		* @var integer $entity_id entity type
 		*/
 		public $entity_id;
@@ -83,9 +88,14 @@
 			'check_perms'		=> true
 		);
 
+		var $type_app = array
+		(
+			'entity'	=> 'property',
+			'catch'		=> 'catch'
+		);
+
 		function __construct($session=false)
 		{
-			$this->so			= CreateObject('property.soadmin_entity');
 			$this->bocommon		= CreateObject('property.bocommon');
 			$this->custom		= createObject('property.custom_fields');
 
@@ -99,43 +109,23 @@
 			$query	= phpgw::get_var('query');
 			$sort	= phpgw::get_var('sort');
 			$order	= phpgw::get_var('order');
+			$type	= phpgw::get_var('type');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
 			$allrows	= phpgw::get_var('allrows', 'bool');
 			$entity_id	= phpgw::get_var('entity_id', 'int');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->type				= isset($type)  && $type && $this->type_app[$type] ? $type : 'entity';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->entity_id		= isset($entity_id) && $entity_id ? $entity_id : '';
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
+			$this->so				= CreateObject('property.soadmin_entity','', '', $this->bocommon);
+			$this->so->type			= $this->type;
+			$this->so->type_app		= $this->type_app;
 
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(isset($entity_id))
-			{
-				$this->entity_id = $entity_id;
-			}
-			if(isset($allrows))
-			{
-				$this->allrows = $allrows;
-			}
 		}
 
 
@@ -249,6 +239,7 @@
 			else
 			{
 				$receipt = $this->so->add_entity($values);
+				execMethod('phpgwapi.menu.clear');
 			}
 			return $receipt;
 		}
@@ -265,31 +256,67 @@
 			else
 			{
 				$receipt = $this->so->add_category($values);
+				execMethod('phpgwapi.menu.clear');
 			}
 			return $receipt;
 		}
 
-		function delete($cat_id='',$entity_id='',$attrib_id='',$acl_location='',$custom_function_id='')
+		function delete($cat_id='',$entity_id='',$attrib_id='',$acl_location='',$custom_function_id='', $group_id ='')
 		{
-			if(!$attrib_id && !$cat_id && $entity_id && !$custom_function_id)
+			if(!$attrib_id && !$cat_id && $entity_id && !$custom_function_id  && !$group_id)
 			{
 				$this->so->delete_entity($entity_id);
+				execMethod('phpgwapi.menu.clear');
 			}
-			else if(!$attrib_id && $cat_id && $entity_id && !$custom_function_id)
+			else if(!$attrib_id && $cat_id && $entity_id && !$custom_function_id  && !$group_id)
 			{
 				$this->so->delete_category($entity_id, $cat_id);
+				execMethod('phpgwapi.menu.clear');
 			}
-			else if($attrib_id && $cat_id && $entity_id && !$custom_function_id)
+			else if($group_id && $cat_id && $entity_id && !$custom_function_id && !$attrib_id)
 			{
-				$this->custom->delete('property', ".entity.{$entity_id}.{$cat_id}", $attrib_id);
+				$this->custom->delete_group($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $group_id);
+			}
+			else if($attrib_id && $cat_id && $entity_id && !$custom_function_id  && !$group_id)
+			{
+				$this->custom->delete($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $attrib_id);
 				$this->so->delete_history($entity_id, $cat_id,$attrib_id);
 			}
 			else if($custom_function_id && $acl_location)
 			{
-				$GLOBALS['phpgw']->custom_functions->delete('property', $acl_location,$custom_function_id);
+				$GLOBALS['phpgw']->custom_functions->delete($this->type_app[$this->type], $acl_location,$custom_function_id);
 			}
 		}
 
+		function get_attrib_group_list($entity_id,$cat_id, $selected)
+		{
+			$group_list = $this->read_attrib_group($entity_id, $cat_id, true);
+			
+			foreach($group_list as &$group)
+			{
+				if( $group['id'] ==  $selected )
+				{
+					$group['selected'] = true;
+			}
+		}
+//_debug_array($group_list);die();
+			return $group_list;
+		}
+
+		function read_attrib_group($entity_id='',$cat_id='',$allrows='')
+		{
+			if($allrows)
+			{
+				$this->allrows = $allrows;
+			}
+
+			$attrib = $this->custom->find_group($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $this->start, $this->query, $this->sort, $this->order, $this->allrows);
+
+			$this->total_records = $this->custom->total_records;
+
+			return $attrib;
+		}
+
 		function read_attrib($entity_id='',$cat_id='',$allrows='')
 		{
 			if($allrows)
@@ -297,7 +324,7 @@
 				$this->allrows = $allrows;
 			}
 
-			$attrib = $this->custom->find('property', '.entity.' . $entity_id . '.' . $cat_id, $this->start, $this->query, $this->sort, $this->order, $this->allrows);
+			$attrib = $this->custom->find($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $this->start, $this->query, $this->sort, $this->order, $this->allrows);
 
 			$this->total_records = $this->custom->total_records;
 
@@ -306,57 +333,96 @@
 
 		function read_single_attrib($entity_id,$cat_id,$id)
 		{
-			return $this->custom->get('property', '.entity.' . $entity_id . '.' . $cat_id, $id, true);
+			return $this->custom->get($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $id, true);
 		}
 
+		function read_single_attrib_group($entity_id,$cat_id,$id)
+		{
+			return $this->custom->get_group($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $id, true);
+		}
+
+		function resort_attrib_group($id,$resort)
+		{
+			$this->custom->resort_group($id, $resort, $this->type_app[$this->type], ".{$this->type}.{$this->entity_id}.{$this->cat_id}");
+		}
+
 		function resort_attrib($id,$resort)
 		{
-			$this->custom->resort($id, $resort, 'property', '.entity.' . $this->entity_id . '.' . $this->cat_id);
+			$this->custom->resort($id, $resort, $this->type_app[$this->type], ".{$this->type}.{$this->entity_id}.{$this->cat_id}");
 		}
 
+		public function save_attrib_group($group, $action='')
+		{
+			$receipt = array();
+			$group['appname'] = $this->type_app[$this->type];
+ 			$group['location'] = ".{$this->type}.{$group['entity_id']}.{$group['cat_id']}";
+			if ( $action=='edit' && $group['id'] )
+			{
+				if ( $this->custom->edit_group($group) )
+				{
+					$receipt['message'][]=array('msg'=>lang('group has been updated'));
+					return $receipt;
+				}
+
+				$receipt['error'][]=array('msg'=>lang('unable to update group'));
+				return $receipt;
+			}
+			else
+			{
+				$id = $this->custom->add_group($group);
+				if ( $id <= 0  )
+				{
+					$receipt['error'][]=array('msg'=>lang('unable to add group'));
+					return $receipt;
+				}
+				else if ( $id == -1 )
+				{
+					$receipt['id']= 0;
+					$receipt['error'][]= array('msg' => lang('group already exists, please choose another name'));
+					$receipt['error'][]= array('msg' => lang('Attribute group has NOT been saved'));
+					return $receipt;
+		}
+
+				$receipt['id']= $id;
+				$receipt['message'][]=array('msg'=>lang('group has been created'));
+				return $receipt;
+			}
+		}
 		public function save_attrib($attrib, $action='')
 		{
-			$attrib['appname'] = 'property';
- 			$attrib['location'] = '.entity.' . $attrib['entity_id'] . '.' . $attrib['cat_id'];
+			$receipt = array();
+			$attrib['appname'] = $this->type_app[$this->type];
+ 			$attrib['location'] = ".{$this->type}.{$attrib['entity_id']}.{$attrib['cat_id']}";
 			if ( $action=='edit' && $attrib['id'] )
 			{
 				if ( $this->custom->edit($attrib) )
 				{
-					return array
-					(
-						'msg'	=> array('msg' => lang('Field has been updated'))
-					);
+					$receipt = $this->custom->receipt;
+					$receipt['message'][]=array('msg'=>lang('Field has been updated'));
+					return $receipt;
 				}
-
-				return array('error' => lang('Unable to update field'));
+				$receipt['error'][]=array('msg'=>lang('Unable to update field'));
+				return $receipt;
 			}
 			else
 			{
 				$id = $this->custom->add($attrib);
 				if ( $id <= 0  )
 				{
-					$this->custom->add($attrib);
-
-					return array('error' => lang('Unable to add field'));
+					$receipt['error'][]=array('msg'=>lang('Unable to add field'));
+					return $receipt;
 				}
 				else if ( $id == -1 )
 				{
-					return array
-					(
-						'id'	=> 0,
-						'error'	=> array
-						(
-							array('msg' => lang('field already exists, please choose another name')),
-							array('msg' => lang('Attribute has NOT been saved'))
-						)
-					);
+					$receipt['id']= 0;
+					$receipt['error'][]= array('msg' => lang('field already exists, please choose another name'));
+					$receipt['error'][]= array('msg' => lang('Attribute has NOT been saved'));
+					return $receipt;
 				}
 
-				return array
-				(
-					'id'	=> $id,
-					'msg'	=> array('msg' => lang('Custom field has been created'))
-				);
+				$receipt['id']= $id;
+				$receipt['message'][]=array('msg'=>lang('Custom field has been created'));
+				return $receipt;
 			}
 		}
 
@@ -369,11 +435,11 @@
 
 			if (!$acl_location && $entity_id && $cat_id)
 			{
-				$acl_location = '.entity.' . $entity_id . '.' . $cat_id;
+				$acl_location = ".{$this->type}.{$entity_id}.{$cat_id}";
 			}
 
 			$values = $GLOBALS['phpgw']->custom_functions->find(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'appname'=>'property','location' => $acl_location,'allrows'=>$this->allrows));
+											'appname'=> $this->type_app[$this->type],'location' => $acl_location,'allrows'=>$this->allrows));
 
 			$this->total_records = $GLOBALS['phpgw']->custom_functions->total_records;
 
@@ -382,16 +448,16 @@
 
 		function resort_custom_function($id,$resort)
 		{
-			$location = '.entity.' . $this->entity_id . '.' . $this->cat_id;
-			return $GLOBALS['phpgw']->custom_functions->resort($id, $resort, 'property', $location);
+			$location = ".{$this->type}.{$this->entity_id}.{$this->cat_id}";
+			return $GLOBALS['phpgw']->custom_functions->resort($id, $resort, $this->type_app[$this->type], $location);
 		}
 
 		function save_custom_function($custom_function,$action='')
 		{
-			$custom_function['appname']='property';
+			$custom_function['appname']= $this->type_app[$this->type];
 			if(!$custom_function['location'] && $custom_function['entity_id'] && $custom_function['cat_id'])
 			{
-				$custom_function['location'] = '.entity.' . $custom_function['entity_id'] . '.' . $custom_function['cat_id'];
+				$custom_function['location'] = ".{$this->type}.{$custom_function['entity_id']}.{$custom_function['cat_id']}";
 			}
 
 			if ($action=='edit')
@@ -412,16 +478,16 @@
 		function select_custom_function($selected='')
 		{
 			$admin_custom = createObject('admin.bo_custom');
-			return $admin_custom->select_custom_function($selected, 'property');
+			return $admin_custom->select_custom_function($selected, $this->type_app[$this->type]);
 		}
 
 		function read_single_custom_function($entity_id='',$cat_id='',$id,$location='')
 		{
 			if (!$location && $entity_id && $cat_id)
 			{
-				$location = '.entity.' . $entity_id . '.' . $cat_id;
+				$location = ".{$this->type}.{$entity_id}.{$cat_id}";
 			}
-			return $GLOBALS['phpgw']->custom_functions->get('property',$location,$id);
+			return $GLOBALS['phpgw']->custom_functions->get($this->type_app[$this->type],$location,$id);
 		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boadmin_location.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boadmin_location.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boadmin_location.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -91,31 +91,11 @@
 			$order	= phpgw::get_var('order');
 			$allrows	= phpgw::get_var('allrows', 'bool');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($allrows))
-			{
-				$this->allrows = $allrows;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
 		}
 
 
@@ -181,26 +161,140 @@
 			return $receipt;
 		}
 
-		function delete($type_id,$id,$attrib='')
+		function delete($type_id,$id,$attrib='',$group_id)
 		{
 			if($id && !$attrib)
 			{
-				$this->so->delete($id);
+				$receipt = $this->so->delete($id);
 			}
 			else if($type_id && $id && $attrib)
 			{
-				$this->custom->delete('property',".location.{$type_id}", $id , "fm_location{$type_id}_history", true );
-				$this->custom->delete('property',".location.{$type_id}", $id , "fm_location{$type_id}" );
+				$ok = 0;
+				$receipt = array();
+				
+				if($this->custom->delete('property',".location.{$type_id}", $id , "fm_location{$type_id}_history", true ))
+				{
+					$ok++;
+				}
+				if($this->custom->delete('property',".location.{$type_id}", $id , "fm_location{$type_id}" ))
+				{
+					$ok++;
+				}
+				if ($ok == 2)
+				{
+					$receipt['message'][] = array('msg' => lang('attibute has been deleted'));
+				}
+				else
+				{
+					$receipt['error'][] = array('msg' => lang('something went wrong'));
+				}
 			}
+			else if($type_id && $group_id)
+			{
+				if($this->custom->delete_group('property',".location.{$type_id}", $group_id))
+				{
+					$receipt['message'][] = array('msg' => lang('attibute group %1 has been deleted',$group_id));
+				}
+				else
+				{
+					$receipt['error'][] = array('msg' => lang('something went wrong'));
+				}
+			}
+
+			return $receipt;
 		}
 
-		function read_attrib($type_id)
+
+		function get_attrib_group_list($type_id, $selected)
 		{
+			$location = ".location.{$type_id}";
+			$group_list = $this->read_attrib_group($location, true);
+			
+			foreach($group_list as &$group)
+			{
+				if( $group['id'] ==  $selected )
+				{
+					$group['selected'] = true;
+				}
+			}
+			return $group_list;
+		}
+
+		function read_attrib_group($location, $allrows='')
+		{
 			if($allrows)
 			{
 				$this->allrows = $allrows;
 			}
 
+			$attrib = $this->custom->find_group('property', $location, $this->start, $this->query, $this->sort, $this->order, $this->allrows);
+			$this->total_records = $this->custom->total_records;
+
+			return $attrib;
+		}
+
+		function read_single_attrib_group($location, $id)
+		{
+			return $this->custom->get_group('property', $location, $id, true);
+		}
+
+		function resort_attrib_group($location, $id, $resort)
+		{
+			$this->custom->resort_group($id, $resort, 'property', $location);
+		}
+
+		public function save_attrib_group($group, $action='')
+		{
+			$group['appname'] = 'property';
+
+			if ( $action=='edit' && $group['id'] )
+			{
+				if ( $this->custom->edit_group($group) )
+				{
+					return array
+					(
+						'msg'	=> array('msg' => lang('group has been updated'))
+					);
+				}
+
+				return array('error' => lang('Unable to update group'));
+			}
+			else
+			{
+				$id = $this->custom->add_group($group);
+				if ( $id <= 0  )
+				{
+					return array('error' => lang('Unable to add group'));
+				}
+				else if ( $id == -1 )
+				{
+					return array
+					(
+						'id'	=> 0,
+						'error'	=> array
+						(
+							array('msg' => lang('group already exists, please choose another name')),
+							array('msg' => lang('Attribute group has NOT been saved'))
+						)
+					);
+				}
+
+				return array
+				(
+					'id'	=> $id,
+					'msg'	=> array('msg' => lang('group has been created'))
+				);
+			}
+		}
+
+
+		function read_attrib($type_id, $allrows = '')
+		{
+			if($allrows || phpgw::get_var('allrows') == 1)
+			{
+				$this->allrows = true;
+			}
+
 			$attrib = $this->custom->find('property', '.location.' . $type_id, $this->start, $this->query, $this->sort, $this->order, $this->allrows);
 
 			$this->total_records = $this->custom->total_records;

Modified: people/sigurdne/modules/property/trunk/inc/class.boagreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boagreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boagreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -105,10 +105,9 @@
 			{
 				$this->sort = $sort;
 			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
+
+			$this->order	= isset($order) && $order ? $order : '';
+
 			if(isset($cat_id))
 			{
 				$this->cat_id = $cat_id;
@@ -232,7 +231,7 @@
 		function read_event($data)
 		{
 			$boalarm		= CreateObject('property.boalarm');
-			$event	= $this->so->read_single($data);
+			$event	= $this->so->read_single($data['agreement_id']);
 			$event['alarm_date']=$event['termination_date'];
 			$event['alarm']	= $boalarm->read_alarms($type='agreement',$data['agreement_id']);
 			return $event;
@@ -290,6 +289,20 @@
 			return $values;
 		}
 
+		/**
+		* Arrange attributes within groups
+		*
+		* @param string  $location    the name of the location of the attribute
+		* @param array   $attributes  the array of the attributes to be grouped
+		*
+		* @return array the grouped attributes
+		*/
+
+		public function get_attribute_groups($location, $attributes = array())
+		{
+			return $this->custom->get_attribute_groups('property', $location, $attributes);
+		}
+
 		function save($values,$values_attribute='',$action='')
 		{
 			$values['start_date']	= $this->bocommon->date_to_timestamp($values['start_date']);
@@ -367,7 +380,8 @@
 				$selected = isset($GLOBALS['phpgw_info']['user']['preferences']['property']["agreement_columns"])?$GLOBALS['phpgw_info']['user']['preferences']['property']["agreement_columns"]:'';
 			}
 
-			$columns = $this->custom->find('property','.agreement', 0, '','','',true);
+			$filter = array('list' => ''); // translates to "list IS NULL"
+			$columns = $this->custom->find('property','.agreement', 0, '','','',true, false, $filter);
 
 			$column_list=$this->bocommon->select_multi_list($selected,$columns);
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boalarm.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boalarm.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boalarm.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -368,8 +368,8 @@
 				return false;	// event not found
 			}
 
-			$this->config		= CreateObject('phpgwapi.config');
-			$this->config->read_repository();
+			$this->config		= CreateObject('phpgwapi.config','property');
+			$this->config->read();
 			$this->send			= CreateObject('phpgwapi.send');
 
 			$members = array();
@@ -467,10 +467,8 @@
 				$receipt['error'][] = array('msg'=> 'group: '.$group_name);
 				$receipt['error'][] = array('msg'=> 'err_code: '.$this->send->err['code']);
 				$receipt['error'][] = array('msg'=> 'err_msg: '. htmlspecialchars($this->send->err['msg']));
-				$receipt['error'][] = array('msg'=> 'err_desc: '. $GLOBALS['phpgw']->err['desc']);
+				$receipt['error'][] = array('msg'=> 'err_desc: '. $this->send->err['desc']);
 			}
-
-//_debug_array($receipt);
 //			return $receipt;
 		}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boasync.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boasync.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boasync.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -40,6 +40,7 @@
 		var $sort;
 		var $order;
 		var $cat_id;
+		var $allrows;
 
 		var $public_functions = array
 		(
@@ -85,38 +86,16 @@
 			$query	= phpgw::get_var('query');
 			$sort	= phpgw::get_var('sort');
 			$order	= phpgw::get_var('order');
-			$filter	= phpgw::get_var('filter', 'int');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
+			$allrows	= phpgw::get_var('allrows', 'bool');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
 
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(!empty($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
 		}
 
 		function save_sessiondata($data)
@@ -142,7 +121,8 @@
 
 		function read()
 		{
-			$method = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order));
+			$method = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
+											'allrows' => $this->allrows));
 
 			$this->total_records = $this->so->total_records;
 

Modified: people/sigurdne/modules/property/trunk/inc/class.bobudget.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bobudget.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bobudget.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -45,6 +45,7 @@
 		var $grouping;
 		var $revision;
 		var $allrows;
+		var $details;
 
 		var $public_functions = array
 		(
@@ -57,12 +58,9 @@
 
 		function property_bobudget($session=false)
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->so 		= CreateObject('property.sobudget');
 			$this->bocommon 	= CreateObject('property.bocommon');
-			$this->cats					= CreateObject('phpgwapi.categories');
-			$this->cats->app_name		= 'property.project';
-			$this->cats->supress_info	= true;
+			$this->cats					= & $this->so->cats;
 
 			if ($session)
 			{
@@ -76,64 +74,30 @@
 			$order		= phpgw::get_var('order');
 			$filter		= phpgw::get_var('filter', 'int');
 			$cat_id		= phpgw::get_var('cat_id', 'int');
+			$dimb_id				= phpgw::get_var('dimb_id', 'int');
 			$allrows	= phpgw::get_var('allrows', 'bool');
 			$district_id	= phpgw::get_var('district_id', 'int');
 			$year		= phpgw::get_var('year', 'int');
 			$grouping	= phpgw::get_var('grouping', 'int');
 			$revision	= phpgw::get_var('revision', 'int');
-			$this->allrows = phpgw::get_var('allrows', 'bool');
+			$allrows				= phpgw::get_var('allrows', 'bool');
+			$details				= phpgw::get_var('details', 'bool');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
+			$this->start			= $start;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->filter			= isset($filter) && $filter ? $filter : '';
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->dimb_id			= isset($dimb_id) && $dimb_id ? $dimb_id : '';
+			$this->part_of_town_id	= isset($part_of_town_id) && $part_of_town_id ? $part_of_town_id : '';
+			$this->district_id		= isset($district_id) && $district_id ? $district_id : '';
+			$this->grouping			= isset($grouping) && $grouping ? $grouping : '';
+			$this->revision			= isset($revision) && $revision ? $revision : 1;
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
+			$this->year				= isset($year) && $year ? $year : '';
+			$this->details			= $details;
 
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(!empty($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id) && !empty($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			else
-			{
-				$this->cat_id = '';
-			}
-
-			if(isset($district_id))
-			{
-				$this->district_id = $district_id;
-			}
-			if(isset($year))
-			{
-				$this->year = $year;
-			}
-			if(isset($grouping))
-			{
-				$this->grouping = $grouping;
-			}
-			if(isset($revision))
-			{
-				$this->revision = $revision;
-			}
-
 			if(isset($year) && !$this->year == $year && !$GLOBALS['phpgw_info']['menuaction']=='property.uibudget.obligations')
 			{
 				$this->grouping = '';
@@ -154,12 +118,13 @@
 		{
 			$data = $GLOBALS['phpgw']->session->appsession('session_data','budget');
 
-			$this->start	= $data['start'];
-			$this->query	= $data['query'];
-			$this->filter	= $data['filter'];
-			$this->sort		= $data['sort'];
-			$this->order	= $data['order'];
-			$this->cat_id	= $data['cat_id'];
+			$this->start			= isset($data['start'])?$data['start']:'';
+			$this->filter			= isset($data['filter'])?$data['filter']:'';
+			$this->sort				= isset($data['sort'])?$data['sort']:'';
+			$this->order			= isset($data['order'])?$data['order']:'';;
+			$this->cat_id			= isset($data['cat_id'])?$data['cat_id']:'';
+			$this->dimb_id			= isset($data['dimb_id'])?$data['dimb_id']:'';
+			$this->details			= isset($data['details'])?$data['details']:'';
 		}
 
 		function check_perms($has, $needed)
@@ -172,14 +137,18 @@
 		{
 			$budget = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 							'filter' => $this->filter,'cat_id' => $this->cat_id,'allrows'=>$this->allrows,
-							'district_id' => $this->district_id,'year' => $this->year,'grouping' => $this->grouping,'revision' => $this->revision,));
+							'district_id' => $this->district_id,'year' => $this->year,'grouping' => $this->grouping,'revision' => $this->revision,
+							'cat_id' => $this->cat_id, 'dimb_id' => $this->dimb_id));
 
 			$this->total_records = $this->so->total_records;
 
-			for ($i=0; $i<count($budget); $i++)
+			foreach ($budget as & $entry)
 			{
-				$budget[$i]['entry_date']  = $GLOBALS['phpgw']->common->show_date($budget[$i]['entry_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+//				$entry['entry_date']	= $GLOBALS['phpgw']->common->show_date($entry['entry_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+				$category = $this->cats->return_single($entry['cat_id']);
+				$entry['category']		=$category[0]['name'];
 			}
+
 			return $budget;
 		}
 
@@ -201,9 +170,12 @@
 
 		function read_obligations()
 		{
-			$obligations = $this->so->read_obligations(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-							'filter' => $this->filter,'cat_id' => $this->cat_id,'allrows'=>$this->allrows,
-							'district_id' => $this->district_id,'year' => $this->year,'grouping' => $this->grouping,'revision' => $this->revision,));
+			//cramirez: add strtoupper function for $this->sort. in YUI use asc/desc (lowercase letters)
+			$obligations = $this->so->read_obligations(array('start' => $this->start, 'query' => $this->query,
+							'sort' => strtoupper($this->sort), 'order' => $this->order, 'filter' => $this->filter,
+							'cat_id' => $this->cat_id, 'allrows'=>$this->allrows, 'district_id' => $this->district_id,
+							'year' => $this->year, 'grouping' => $this->grouping, 'revision' => $this->revision,
+							'details' => $this->details));
 
 			$this->total_records = $this->so->total_records;
 			return $obligations;
@@ -317,10 +289,6 @@
 
 		function get_year_filter_list($selected ='',$basis = '')
 		{
-			if(!isset($_GET['year']))
-			{
-				$selected = date('Y');
-			}
 			$year_list = $this->so->get_year_filter_list($basis);
 			return $this->bocommon->select_list($selected,$year_list);
 		}
@@ -329,11 +297,16 @@
 		{
 			$year_list = $this->so->get_year_filter_list();
 
+			if(!$year_list)
+			{
+				$year_list = array(array('id' =>date('Y'), 'name' =>date('Y')));
+			}
+			$k = date('Y') - $year_list[0]['id'] + 5;
 			$j = count($year_list);
-			for ($i=0; $i < 4; $i++)
+			for ($i=0; $i < $k; $i++)
 			{
 				// FIXME
-				if($year_list[$j-1]['id'] < date('Y') + 3)
+			//	if($year_list[$j-1]['id'] < date('Y') + 3)
 				{
 					$year_list[$j+$i]['id'] = $year_list[$j+$i-1]['id'] + 1;
 					$year_list[$j+$i]['name'] = $year_list[$j+$i-1]['id'] + 1;

Modified: people/sigurdne/modules/property/trunk/inc/class.bocategory.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bocategory.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bocategory.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -3,7 +3,7 @@
 	* phpGroupWare - property: a Facilities Management System.
 	*
 	* @author Sigurd Nes <[email protected]>
-	* @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software Foundation, Inc. http://www.fsf.org/
+	* @copyright Copyright (C) 2003,2004,2005,2006,2007,2008,2009 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
@@ -40,16 +40,8 @@
 		var $sort;
 		var $order;
 		var $cat_id;
+		var $location_info = array();
 
-		var $public_functions = array
-		(
-			'read'				=> true,
-			'read_single'		=> true,
-			'save'				=> true,
-			'delete'			=> true,
-			'check_perms'		=> true
-		);
-
 		var $soap_functions = array(
 			'list' => array(
 				'in'  => array('int','int','struct','string','int'),
@@ -69,11 +61,11 @@
 			)
 		);
 
-		function property_bocategory($session=false)
+		function __construct($session=false)
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->so 		= CreateObject('property.socategory');
 			$this->socommon = CreateObject('property.socommon');
+			$this->custom 		= & $this->so->custom;
 
 			if ($session)
 			{
@@ -87,45 +79,23 @@
 			$order	= phpgw::get_var('order');
 			$filter	= phpgw::get_var('filter', 'int');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
-			$allrows= phpgw::get_var('allrows', 'bool');
+			$allrows			= phpgw::get_var('allrows', 'bool');
+			$type				= phpgw::get_var('type');
+			$type_id			= phpgw::get_var('type_id', 'int');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
+			$this->start		= $start ? $start : 0;
+			$this->query		= isset($_REQUEST['query']) ? $query : $this->query;
+			$this->sort			= isset($_REQUEST['sort']) ? $sort : $this->sort;
+			$this->order		= isset($_REQUEST['order']) ? $order : $this->order;
+			$this->filter		= isset($_REQUEST['filter']) ? $filter : $this->filter;
+			$this->cat_id		= isset($_REQUEST['cat_id'])  ? $cat_id :  $this->cat_id;
+			$this->allrows		= isset($allrows) ? $allrows : false;
 
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(!empty($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(isset($allrows))
-			{
-				$this->allrows = $allrows;
-			}
+			$this->location_info = $this->so->get_location_info($type, $type_id);
+
 		}
 
-
-		function save_sessiondata($data)
+		public function save_sessiondata($data)
 		{
 			if ($this->use_session)
 			{
@@ -137,7 +107,7 @@
 		{
 			$data = $GLOBALS['phpgw']->session->appsession('session_data','category');
 
-			//_debug_array($data);
+	//		_debug_array($data);
 
 			$this->start	= $data['start'];
 			$this->query	= $data['query'];
@@ -148,48 +118,69 @@
 			$this->allrows	= $data['allrows'];
 		}
 
+		public function get_location_info($type,$type_id)
+		{
+			return $this->so->get_location_info($type,$type_id);
+		}
 
-		function read($type='',$type_id='')
+		public function read()
 		{
-			$category = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'type' => $type,type_id=>$type_id,'allrows'=>$this->allrows));
+			$values = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
+											'allrows'=>$this->allrows));
 
 			$this->total_records = $this->so->total_records;
+			$this->uicols = $this->so->uicols;
 
-			return $category;
+			return $values;
 		}
 
-		function read_single($id,$type,$type_id)
+		public function read_single($data=array())
 		{
-			return $this->so->read_single($id,$type,$type_id);
+			$custom_fields = false;
+			if($GLOBALS['phpgw']->locations->get_attrib_table('property', $this->location_info['acl_location']))
+			{
+				$custom_fields = true;
+				$values = array();
+				$values['attributes'] = $this->custom->find('property', $this->location_info['acl_location'], 0, '', 'ASC', 'attrib_sort', true, true);
 		}
 
-		function select_part_of_town($part_of_town_id)
+			if(isset($data['id']) && $data['id'])
+			{
+				$values = $this->so->read_single($data, $values);
+			}
+			if($custom_fields)
 		{
-			return $this->socommon->select_part_of_town($part_of_town_id);
+				$values = $this->custom->prepare($values, 'property',$this->location_info['acl_location'], $data['view']);
+			}
+			return $values;
 		}
 
-		function save($category,$action='',$type ='',$type_id)
+		public function save($data,$action='',$values_attribute = array())
 		{
+			if(is_array($values_attribute))
+			{
+				$values_attribute = $this->custom->convert_attribute_save($values_attribute);
+			}
+
 			if ($action=='edit')
 			{
-				if ($category['id'] != '')
+				if ($data['id'] != '')
 				{
 
-					$receipt = $this->so->edit($category,$type,$type_id);
+					$receipt = $this->so->edit($data,$values_attribute);
 				}
 			}
 			else
 			{
-				$receipt = $this->so->add($category,$type,$type_id);
+				$receipt = $this->so->add($data,$values_attribute);
 			}
 
 			return $receipt;
 		}
 
-		function delete($id,$type,$type_id)
+		public function delete($id)
 		{
-			$this->so->delete($id,$type,$type_id);
+			$this->so->delete($id);
 		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.bocommon.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bocommon.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bocommon.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -67,8 +67,9 @@
 			)
 		);
 
-		function property_bocommon()
+		function __construct()
 		{
+//_debug_array($bt = debug_backtrace());
 			$this->socommon			= CreateObject('property.socommon');
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 
@@ -128,26 +129,25 @@
 
 		function msgbox_data($receipt)
 		{
-			$msgbox_data_error=array();
+			$msgbox_data_error	 = array();
+			$msgbox_data_message = array();
 			if (isSet($receipt['error']) AND is_array($receipt['error']))
 			{
-				foreach($receipt['error'] as $errors)
+				foreach($receipt['error'] as $dummy => $error)
 				{
-					$msgbox_data_error += array($errors['msg']=> false);
+					$msgbox_data_error[$error['msg']] = false;
 				}
 			}
 
-			$msgbox_data_message=array();
-
 			if (isSet($receipt['message']) AND is_array($receipt['message']))
 			{
-				foreach($receipt['message'] as $messages)
+				foreach($receipt['message'] as $dummy => $message)
 				{
-					$msgbox_data_message += array($messages['msg']=> true);
+					$msgbox_data_message[$message['msg']] = true;
 				}
 			}
 
-			$msgbox_data = $msgbox_data_error + $msgbox_data_message;
+			$msgbox_data = array_merge($msgbox_data_error, $msgbox_data_message);
 
 			return $msgbox_data;
 		}
@@ -269,7 +269,7 @@
 		}
 
 
-		function get_user_list($format='',$selected='',$extra='',$default='',$start='', $sort='', $order='', $query='',$offset='')
+		function get_user_list($format='',$selected='',$extra='',$default='',$start='', $sort='', $order='', $query='',$offset='', $enabled = false)
 		{
 			switch($format)
 			{
@@ -302,11 +302,14 @@
 
 			$accounts = & $GLOBALS['phpgw']->accounts;
 			$users = $accounts->get_list('accounts', $start, $sort, $order, $query,$offset);
+
 			unset($accounts);
 			if (is_array($users))
 			{
 				foreach($users as $user)
 				{
+					if (($enabled && $user->enabled) || !$enabled)
+					{
 					$all_users[] = array
 					(
 						'user_id'	=> $user->id,
@@ -314,6 +317,7 @@
 					);
 				}
 			}
+			}
 
 			if (count($all_users)>0)
 			{
@@ -393,13 +397,18 @@
 		}
 
 
-		function get_user_list_right($right='',$selected='',$acl_location='',$extra='',$default='')
+		function get_user_list_right($rights,$selected='',$acl_location='',$extra='',$default='')
 		{
 			if(!$selected && $default)
 			{
 				$selected = $default;
 			}
 
+			if (!is_array($rights))
+			{
+				$rights = array($rights);
+			}
+
 			if (is_array($extra))
 			{
 				foreach($extra as $extra_user)
@@ -413,19 +422,53 @@
 				}
 			}
 
-			if(!$users = $this->socommon->fm_cache('acl_userlist_'. $right . '_' . $acl_location))
+			if(!$users = $this->socommon->fm_cache('acl_userlist_'. $rights[0] . '_' . $acl_location))
 			{
-				$users = $GLOBALS['phpgw']->acl->get_user_list_right($right, $acl_location);
-				$this->socommon->fm_cache('acl_userlist_'. $right . '_' . $acl_location,$users);
+				$users_gross = array();
+				foreach ($rights as $right)
+				{
+					$users_gross = array_merge($users_gross, $GLOBALS['phpgw']->acl->get_user_list_right($right, $acl_location));
+				}
+				
+				$accounts	= array();
+				$users			= array();
+
+				foreach ($users_gross as $entry => $user)
+				{
+
+					if( !array_search($user['account_id'], $accounts ) )
+					{
+						$users[] = $user;
+					}
+					$accounts[] = $user['account_id'];
+				}
+				unset($users_gross);
+				unset($accounts);
+
+				foreach ($users as $key => $row) 
+				{
+					$account_lastname[$key]  = $row['account_lastname'];
+					$account_firstname[$key] = $row['account_firstname'];
+				}
+
+				// Sort the data with account_lastname ascending, account_firstname ascending
+				// Add $data as the last parameter, to sort by the common key
+				if($users)
+				{
+					array_multisort($account_lastname, SORT_ASC, $account_firstname, SORT_ASC, $users);
+				}
+
+				$this->socommon->fm_cache('acl_userlist_'. $rights[0] . '_' . $acl_location,$users);
 			}
 
 			if (isset($users_extra) && is_array($users_extra) && is_array($users))
 			{
-				$users = $users_extra + $users;
+				$users = array_merge($users_extra, $users);
 			}
 
+			$user_list = array();
 
-			while (is_array($users) && list(,$user) = each($users))
+			foreach ($users as $user)
 			{
 				if ($user['account_lid']==$selected)
 				{
@@ -501,7 +544,8 @@
 				{
 					$user_list[] = array
 					(
-						'user_id'	=> $user['account_id'],
+						//'user_id'	=> $user['account_id'],
+						'id'	=> $user['account_id'],
 						'name'		=> $name,
 						'selected'	=> 'selected'
 					);
@@ -510,7 +554,8 @@
 				{
 					$user_list[] = array
 					(
-						'user_id'	=> $user['account_id'],
+						//'user_id'	=> $user['account_id'],
+						'id'	=> $user['account_id'],
 						'name'		=> $name
 					);
 				}
@@ -569,6 +614,43 @@
 			return $vendor;
 		}
 
+
+		function initiate_ui_contact_lookup($data)
+		{
+//_debug_array($data);
+
+			$field = $data['field'];
+			if( isset($data['type']) && $data['type']=='view')
+			{
+				$GLOBALS['phpgw']->xslttpl->add_file(array('contact_view'));
+			}
+			else
+			{
+				$GLOBALS['phpgw']->xslttpl->add_file(array('contact_form'));
+			}
+
+			$contact['value_contact_id']		= $data['contact_id'];
+//			$contact['value_contact_name']		= $data['contact_name'];
+
+			if(isset($data['contact_id']) && $data['contact_id'] && !$data['contact_name'])
+			{
+				$contacts							= CreateObject('phpgwapi.contacts');
+				$contact_data						= $contacts->read_single_entry($data['contact_id'], array('fn','tel_work','email'));
+				$contact['value_contact_name']		= $contact_data[0]['fn'];
+				$contact['value_contact_email']		= $contact_data[0]['email'];
+				$contact['value_contact_tel']		= $contact_data[0]['tel_work'];
+
+				unset($contacts);
+			}
+
+			$contact['field']						= $field;
+			$contact['contact_link']				= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uilookup.addressbook', 'column' => $field));
+			$contact['lang_contact']				= lang('contact');
+			$contact['lang_select_contact_help']	= lang('click this link to select');
+//_debug_array($contact);
+			return $contact;
+		}
+
 		function initiate_ui_tenant_lookup($data)
 		{
 			if($data['type']=='view')
@@ -648,12 +730,171 @@
 				$b_account_data	= $b_account_object->read_single($data['b_account_id']);
 				$b_account['value_b_account_name']	= $b_account_data['descr'];
 			}
-
+			$b_account['disabled']				= isset($data['disabled']) && $data['disabled'] ? true : false;
 //_debug_array($b_account);
 			return $b_account;
 		}
 
+		function initiate_project_group_lookup($data)
+		{
+			$project_group = array();
 
+			if( isset($data['type']) && $data['type']=='view')
+			{
+				if(!isset($data['project_group']) || !$data['project_group'])
+				{
+					return $project_group;
+				}
+
+				$GLOBALS['phpgw']->xslttpl->add_file(array('project_group_view'));
+			}
+			else
+			{
+				$GLOBALS['phpgw']->xslttpl->add_file(array('project_group_form'));
+			}
+
+			$project_group['value_project_group']				= $data['project_group'];
+			$project_group['value_project_group_descr']			= $data['project_group_descr'];
+			$project_group['project_group_url']					= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uilookup.project_group'));
+			$project_group['lang_select_project_group_help']	= lang('click to select project group');
+			$project_group['lang_project_group']				= lang('project group');
+			if($data['project_group'] && (!isset($data['project_group_descr']) || !$data['project_group_descr']))
+			{
+				$project_group_object				= CreateObject('property.socategory');
+				$project_group_object->get_location_info('project_group',false);
+				$project_group_data					= $project_group_object->read_single(array('id'=> $data['project_group']));
+				$project_group['value_project_group_descr']	= $project_group_data['descr'];
+			}
+
+			return $project_group;
+		}
+
+		function initiate_ecodimb_lookup($data)
+		{
+			$ecodimb = array();
+
+			if( isset($data['type']) && $data['type']=='view')
+			{
+				if(!isset($data['ecodimb']) || !$data['ecodimb'])
+				{
+					return $ecodimb;
+				}
+
+				$GLOBALS['phpgw']->xslttpl->add_file(array('ecodimb_view'));
+			}
+			else
+			{
+				$GLOBALS['phpgw']->xslttpl->add_file(array('ecodimb_form'));
+			}
+
+			$ecodimb['value_ecodimb']				= $data['ecodimb'];
+			$ecodimb['value_ecodimb_descr']			= $data['ecodimb_descr'];
+			$ecodimb['ecodimb_url']					= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uilookup.ecodimb'));
+			$ecodimb['lang_select_ecodimb_help']	= lang('click to select dimb');
+			$ecodimb['lang_ecodimb']				= lang('dimb');
+			if($data['ecodimb'] && (!isset($data['ecodimb_descr']) || !$data['ecodimb_descr']))
+			{
+				$ecodimb_object					= CreateObject('property.socategory');
+				$ecodimb_object->get_location_info('dimb',false);
+				$ecodimb_data					= $ecodimb_object->read_single(array('id'=> $data['ecodimb']));
+				$ecodimb['value_ecodimb_descr']	= $ecodimb_data['descr'];
+			}
+			$ecodimb['disabled']				= isset($data['disabled']) && $data['disabled'] ? true : false;
+
+			return $ecodimb;
+		}
+
+
+		function initiate_event_lookup($data)
+		{
+			$event = array();
+			$event['name'] = $data['name']; // attribute name
+			$event['event_name'] = $data['event_name']; // Human readable description
+			if( isset($data['type']) && $data['type']=='view')
+			{
+				if(!isset($data['event']) || !$data['event'])
+				{
+//					return $event;
+				}
+
+				$GLOBALS['phpgw']->xslttpl->add_file(array('event_view'));
+			}
+			else
+			{
+				$GLOBALS['phpgw']->xslttpl->add_file(array('event_form'));
+			}
+
+			// If the record is not saved - issue a warning
+			if(isset($data['item_id']) || $data['item_id'])
+			{
+				$event['item_id'] = $data['item_id'];
+			}
+			else if(isset($data['location_code']) || $data['location_code'])
+			{
+				$event['item_id'] = execMethod('property.solocation.get_item_id', $data['location_code']);
+			}
+			else
+			{
+				$event['warning']			= lang('Warning: the record has to be saved in order to plan an event');
+			}
+
+			if(isset($data['event_id']) && $data['event_id'])
+			{
+				$event['value']			= $data['event_id'];
+				$event_info 			= execMethod('property.soevent.read_single', $data['event_id']);
+				$event['descr']			= $event_info['descr'];
+				$event['enabled']		= $event_info['enabled'] ? lang('yes') : lang('no');
+				$event['lang_enabled']	= lang('enabled');
+
+				$job_id					= "property{$data['location']}::{$data['item_id']}::{$data['name']}";
+				$job					= execMethod('phpgwapi.asyncservice.read', $job_id);
+
+				$event['next']			= $GLOBALS['phpgw']->common->show_date($job[$job_id]['next'],$dateformat);
+				$event['lang_next_run']	= lang('next run');
+
+				$criteria = array
+				(
+					'start_date'		=> $event_info['start_date'],
+					'end_date'			=> $event_info['end_date'],
+					'location_id'		=> $event_info['location_id'],
+					'location_item_id'	=> $event_info['location_item_id']
+				);
+
+				$event['count'] = 0;
+				$boevent	= CreateObject('property.boevent');
+				$boevent->find_scedules($criteria);
+				$schedules =  $boevent->cached_events;
+				foreach($schedules as $day => $set)
+				{
+					foreach ($set as $entry)
+					{
+						if($entry['enabled'] && (!isset($entry['exception']) || !$entry['exception']==true))
+						{
+							$event['count']++;
+						}
+					}
+				}
+
+				unset($event_info);
+				unset($job_id);
+				unset($job);
+			}
+
+			$event['event_link'] = $GLOBALS['phpgw']->link('/index.php',array
+			(
+				'menuaction'	=> 'property.uievent.edit',
+				'location'		=> $data['location'],
+				'attrib_id'		=> $event['name'],
+				'item_id'		=> isset($event['item_id']) ? $event['item_id'] : '',
+				'id'			=> isset($event['value']) && $event['value'] ? $event['value'] : '')
+			);
+
+			$event['function_name']	= 'lookup_'. $event['name'] .'()';
+
+			return $event;
+		}
+
+
 		function initiate_ui_alarm($data)
 		{
 			$boalarm		= CreateObject('property.boalarm');
@@ -815,6 +1056,42 @@
 			return (isset($datatype_precision[$datatype])?$datatype_precision[$datatype]:'');
 		}
 
+		/**
+		 * Convert a datatype to a format to output
+		 *
+		 * @param string $datatype the dataype to convert
+		 *
+		 * @return string the format - incoming of translation is not found
+		 */
+		function translate_datatype_format($datatype)
+		{
+			$datatype_text = array(
+				'V' => 'varchar',
+				'I' => 'number',
+				'C' => 'char',
+				'N' => 'float',
+				'D' => 'date',
+				'T' => 'memo',
+				'R' => 'radio',
+				'CH' => 'checkbox',
+				'LB' => 'listbox',
+				'AB' => 'contact',
+				'VENDOR' => 'vendor',
+				'email' => 'email',
+				'link' => 'link',
+				'pwd' => 'password',
+				'user' => 'phpgw_user'
+			);
+
+
+			if ( isset($datatype_text[$datatype]) )
+			{
+				return $datatype_text[$datatype];
+			}
+			return $datatype;
+		}
+
+
 		function save_attributes($values_attribute,$type)
 		{
 
@@ -1009,6 +1286,9 @@
 				$uicols['name'][]		= 'loc' . $location_types[$i]['id'];
 				$uicols['descr'][]		= $location_types[$i]['name'];
 				$uicols['statustext'][]		= $location_types[$i]['descr'];
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
 			}
 /*
 			$fm_location_cols = $soadmin_location->read_attrib(array('type_id'=>$type_id,'lookup_type'=>$type_id));
@@ -1043,6 +1323,9 @@
 				$uicols['name'][]			= 'loc1_name';
 				$uicols['descr'][]			= lang('Property Name');
 				$uicols['statustext'][]			= lang('Property Name');
+				$uicols['exchange'][]		= true;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
 
 				for ($i=2;$i<($type_id+1);$i++)
 				{
@@ -1051,6 +1334,9 @@
 					$uicols['name'][]		= 'loc' . $i . '_name';
 					$uicols['descr'][]		= '';
 					$uicols['statustext'][]		= '';
+					$uicols['exchange'][]		= true;
+					$uicols['align'][] 			= '';
+					$uicols['datatype'][]		= '';
 				}
 			}
 
@@ -1062,6 +1348,9 @@
 				$uicols['name'][]			= 'address';
 				$uicols['descr'][]			= lang('address');
 				$uicols['statustext'][]		= lang('address');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
 			}
 
 			$config_count	= count($config);
@@ -1079,18 +1368,27 @@
 						$uicols['name'][]			= 'street_name';
 						$uicols['descr'][]			= lang('street name');
 						$uicols['statustext'][]		= lang('street name');
+						$uicols['exchange'][]		= false;
+						$uicols['align'][] 			= '';
+						$uicols['datatype'][]		= '';
 
 						$cols_return[] 				= 'street_number';
 						$uicols['input_type'][]		= 'hidden';
 						$uicols['name'][]			= 'street_number';
 						$uicols['descr'][]			= lang('street number');
 						$uicols['statustext'][]		= lang('street number');
+						$uicols['exchange'][]		= false;
+						$uicols['align'][] 			= '';
+						$uicols['datatype'][]		= '';
 
 						$cols_return[] 				= $config[$i]['column_name'];
 						$uicols['input_type'][]		= 'hidden';
 						$uicols['name'][]			= $config[$i]['column_name'];
 						$uicols['descr'][]			= lang($config[$i]['input_text']);
 						$uicols['statustext'][]		= lang($config[$i]['input_text']);
+						$uicols['exchange'][]		= false;
+						$uicols['align'][] 			= '';
+						$uicols['datatype'][]		= '';
 						if($lookup)
 						{
 							$cols_extra[] 			= 'street_name';
@@ -1106,6 +1404,9 @@
 						$uicols['name'][]			= $config[$i]['column_name'];
 						$uicols['descr'][]			= $config[$i]['input_text'];
 						$uicols['statustext'][]		= $config[$i]['input_text'];
+						$uicols['exchange'][]		= false;
+						$uicols['align'][] 			= '';
+						$uicols['datatype'][]		= '';
 
 						if($lookup)
 						{
@@ -1141,7 +1442,9 @@
 			}
 
 			$parts= $this->socommon->select_part_of_town($district_id);
-
+			$part_of_town_list = array();
+			//[email protected] 09/09/08 validate for YUI.
+			if(is_array($parts)&& (count($parts))){
 			foreach($parts as $entry)
 			{
 				if ($entry['id']==$selected)
@@ -1164,6 +1467,8 @@
 					);
 				}
 			}
+			}
+
 			return $part_of_town_list;
 		}
 
@@ -1276,43 +1581,19 @@
 
 		function select_datatype($selected='', $sub_module = '')
 		{
-			$datatypes[0]['id']= 'V';
-			$datatypes[0]['name']= lang('varchar');
-			$datatypes[1]['id']= 'C';
-			$datatypes[1]['name']= lang('Character');
-			$datatypes[2]['id']= 'I';
-			$datatypes[2]['name']= lang('Integer');
-			$datatypes[3]['id']= 'N';
-			$datatypes[3]['name']= lang('Decimal');
-			$datatypes[4]['id']= 'D';
-			$datatypes[4]['name']= lang('Date');
-			$datatypes[5]['id']= 'T';
-			$datatypes[5]['name']= lang('Memo');
-			$datatypes[6]['id']= 'R';
-			$datatypes[6]['name']= lang('Multiple radio');
-			$datatypes[7]['id']= 'CH';
-			$datatypes[7]['name']= lang('Multiple Checkbox');
-			$datatypes[8]['id']= 'LB';
-			$datatypes[8]['name']= lang('ListBox');
-			$datatypes[9]['id']= 'AB';
-			$datatypes[9]['name']= lang('Contact');
-			$datatypes[10]['id']= 'VENDOR';
-			$datatypes[10]['name']= lang('Vendor');
-			$datatypes[11]['id']= 'email';
-			$datatypes[11]['name']= lang('Email');
-			$datatypes[12]['id']= 'link';
-			$datatypes[12]['name']= lang('Link');
 
-			if($sub_module == 'actor')
+			$custom 		= createObject('phpgwapi.custom_fields');
+
+			foreach( $custom->datatype_text as $key => $name)
 			{
-				$datatypes[13]['id']= 'pwd';
-				$datatypes[13]['name']= lang('Password');
-				$datatypes[14]['id']= 'user';
-				$datatypes[14]['name']= lang('phpgw user');
+				$datatypes[] = array
+				(
+					'id'	=> $key,
+					'name'	=> $name,
+				);
 			}
 
 			return $this->select_list($selected,$datatypes);
-
 		}
 
 		function select_nullable($selected='')
@@ -1403,10 +1684,12 @@
 				}
 
 				$line = 0;
+
 				foreach($content as $row)
 				{
 					$line++;
-					for ($i=0; $i<count($row); $i++)
+					$rows = count($row);
+					for ($i=0; $i < $rows; $i++)
 					{
 						$worksheet1->write($line,$i, $this->utf2ascii($row[$i]));
 					}
@@ -1591,6 +1874,7 @@
 		*/
 		public function preserve_attribute_values($values, $values_attributes)
 		{
+
 			if ( !is_array($values_attributes ) )
 			{
 				return array();
@@ -1600,12 +1884,13 @@
 			{	
 				foreach ( $values['attributes'] as &$val_attrib )
 				{
+
 					if ( $val_attrib['id'] != $attribute['attrib_id'] )
 					{
 						continue;
 					}
 
-					if( !isset($attribute['value']) )
+					if( !isset($attribute['value']) && !isset($values['extra'][$val_attrib['name']]))
 					{
 						continue;
 					}
@@ -1634,6 +1919,10 @@
 							}
 						}
 					}
+					else if (isset($values['extra'][$val_attrib['name']]))
+					{
+						$val_attrib['value'] =$values['extra'][$val_attrib['name']];
+					}
 					else
 					{
 						$val_attrib['value'] = $attribute['value'];
@@ -1709,7 +1998,7 @@
 				{
 					foreach ($insert_record['extra'] as $key => $column)
 					{
-						if(isset($_POST[$key]) && $_POST[$key])
+						if(isset($_POST[$key]))
 						{
 							$values['extra'][$column]	= phpgw::get_var($key, 'string', 'POST');
 						}
@@ -1726,21 +2015,22 @@
 			return $values;
 		}
 
-		function get_menu()
+		function get_menu($app = 'property')
 		{
+			$GLOBALS['phpgw_info']['flags']['nonavbar'] = false;
 			if(!isset($GLOBALS['phpgw_info']['user']['preferences']['property']['horisontal_menus']) || $GLOBALS['phpgw_info']['user']['preferences']['property']['horisontal_menus'] == 'no')
 			{
 				return;
 			}
 			$GLOBALS['phpgw']->xslttpl->add_file(array('menu'));
 
-			if(!$menu = $GLOBALS['phpgw']->session->appsession($GLOBALS['phpgw_info']['flags']['menu_selection'], 'menu'))
+			if(!$menu = $GLOBALS['phpgw']->session->appsession($GLOBALS['phpgw_info']['flags']['menu_selection'], "menu_{$app}"))
 			{
-				$menu_gross = execMethod('property.menu.get_menu');
+				$menu_gross = execMethod("{$app}.menu.get_menu", 'horisontal');
 				$selection = explode('::',$GLOBALS['phpgw_info']['flags']['menu_selection']);
 				$level=0;
 				$menu['navigation'] = $this->get_sub_menu($menu_gross['navigation'],$selection,$level);
-				$GLOBALS['phpgw']->session->appsession(isset($GLOBALS['phpgw_info']['flags']['menu_selection']) && $GLOBALS['phpgw_info']['flags']['menu_selection'] ? $GLOBALS['phpgw_info']['flags']['menu_selection'] : 'property_missing_selection', 'menu', $menu);
+				$GLOBALS['phpgw']->session->appsession(isset($GLOBALS['phpgw_info']['flags']['menu_selection']) && $GLOBALS['phpgw_info']['flags']['menu_selection'] ? $GLOBALS['phpgw_info']['flags']['menu_selection'] : 'property_missing_selection', "menu_{$app}", $menu);
 				unset($menu_gross);
 			}
 			return $menu;
@@ -1805,4 +2095,88 @@
 		{
 			return $this->socommon->get_location_list($required);
 		}
+
+
+
+		public function select2String($array_values, $id = 'id', $name = 'name',$name2 = '' )
+        {
+             $str_array_values = "";
+             for($i = 0; $i < count($array_values); $i++)
+             {
+                foreach( $array_values[$i] as $key => $value )
+                {
+                    if ($key == $id)
+                    {
+                     $str_array_values .= $value;
+                     $str_array_values .= "#";
+                    }
+                    if ($key == $name)
+                    {
+                      $str_array_values .= $value;
+                      $str_array_values .= "@";
+                    }
+                 if ($key == $name2)
+                 {
+                 // eliminate hte last @ in $str_array_values
+                 $str_array_values = substr($str_array_values, 0, strrpos($str_array_values,'@'));
+                 $str_array_values .= " ".$value;
+                 $str_array_values .= "@";
+                 }
+                }
+             }
+             return $str_array_values;
+        }
+        
+		public function make_menu_date($array,$id_buttons,$name_hidden) 
+		{
+			$split_values = array ();			
+			foreach ($array as $value)
+			{
+				array_push($split_values,array (text => "$value[id]", value => $value[id], onclick => array(fn => onDateClick, obj => array (id_button=>$id_buttons, opt=>$value[id], hidden_name=>$name_hidden))));
+			}	
+			return 	$split_values;	
+		}
+		
+		public function make_menu_user($array,$id_buttons,$name_hidden)  
+		{
+			$split_values = array ();			
+			foreach ($array as $value)
+			{
+				array_push($split_values,array (text => "$value[name]", value => $value[id], onclick => array(fn => onUserClick, obj => array (id_button=>$id_buttons, id=>$value[id], name =>$value[name], hidden_name=>$name_hidden))));
+			}	
+			return 	$split_values;	
+		}
+		
+		public function choose_select($array, $index_return) 
+		{
+			foreach ($array as $value)
+			{
+				if($value["selected"]=="selected")
+				{
+					return 	$value[$index_return];
+				}
+			}	
+			//for avoid erros, return the last value
+			return $array[count($array)-1][$index_return];
+		}		
+
+		/**
+		* pending action for items across the system.
+		*
+		* @param array   $data array containing string  'appname'			- the name of the module being looked up
+		*										string  'location'			- the location within the module to look up
+		* 										integer 'id'				- id of the referenced item - could possibly be a bigint
+		* 										integer 'responsible'		- the user_id asked for approval
+		* 										string  'responsible_type'  - what type of responsible is asked for action (user,vendor or tenant)
+		* 										string  'action'			- what type of action is pending
+		* 										string  'remark'			- a general remark - if any
+		* 										integer 'deadline'			- unix timestamp if any deadline is given.
+		*
+		* @return integer $reminder  number of request for this action
+		*/
+
+		public function set_pending_action($action_params)
+		{
+			return $this->socommon->set_pending_action($action_params);
+		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.bodocument.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bodocument.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bodocument.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -42,6 +42,7 @@
 		var $cat_id;
 		var $entity_id;
 		var $status_id;
+		var $allrows;
 
 		var $public_functions = array
 		(
@@ -54,13 +55,14 @@
 
 		function property_bodocument($session=false)
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->so 			= CreateObject('property.sodocument');
 			$this->bocommon 	= CreateObject('property.bocommon');
 			$this->solocation 	= CreateObject('property.solocation');
 			$this->historylog	= CreateObject('property.historylog','document');
 			$this->contacts		= CreateObject('property.soactor');
-			$this->contacts->role='vendor';
+			$this->contacts->role	='vendor';
+			$this->cats				= & $this->so->cats;
+			$this->bofiles			= CreateObject('property.bofiles');
 
 			if ($session)
 			{
@@ -78,54 +80,19 @@
 			$entity_id	= phpgw::get_var('entity_id', 'int');
 			$doc_type	= phpgw::get_var('doc_type');
 			$query_location	= phpgw::get_var('query_location');
+			$allrows		= phpgw::get_var('allrows', 'bool');
 
-
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(isset($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(isset($status_id))
-			{
-				$this->status_id = $status_id;
-			}
-			if($entity_id)
-			{
-				$this->entity_id = $entity_id;
-			}
-			if(isset($doc_type))
-			{
-				$this->doc_type = $doc_type;
-			}
-			if(isset($query_location))
-			{
-				$this->query_location = $query_location;
-			}
-
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : '';
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->filter			= isset($filter) && $filter ? $filter : '';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->status_id		= isset($status_id) && $status_id ? $status_id : '';
+			$this->entity_id		= isset($entity_id) && $entity_id ? $entity_id : '';
+			$this->doc_type			= isset($doc_type) && $doc_type ? $doc_type : '';
+			$this->query_location	= isset($query_location) && $query_location ? $query_location : '';
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
 		}
 
 		function save_sessiondata($data)
@@ -198,20 +165,37 @@
 			return $document;
 		}
 
+		function get_files_at_location($location_code)
+		{
+			return $this->so->get_files_at_location($location_code);
+		}
+
+
 		function read_at_location($location_code='')
 		{
+			$use_svn = false;
+			if(ereg('svn[s:][:/]/', $GLOBALS['phpgw_info']['server']['files_dir']))
+			{
+		//		$use_svn = true;
+			}
+
+
 			$document = $this->so->read_at_location(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'filter' => $this->filter,'cat_id' => $this->cat_id,'entity_id' => $this->entity_id,
-											'location_code' => $location_code,'doc_type'=>$this->doc_type));
+											'location_code' => $location_code,'doc_type'=>$this->doc_type, 'allrows' => $this->allrows));
 			$this->total_records = $this->so->total_records;
 
 			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 
-			for ($i=0; $i<count($document); $i++)
+			foreach ($document as & $entry)
 			{
-				$document[$i]['user'] = $GLOBALS['phpgw']->accounts->id2name($document[$i]['user_id']);
-				$document[$i]['document_date'] = $GLOBALS['phpgw']->common->show_date($document[$i]['start_date'],$dateformat);
-				$document[$i]['entry_date'] = $GLOBALS['phpgw']->common->show_date($document[$i]['entry_date'],$dateformat);
+				$entry['user'] = $GLOBALS['phpgw']->accounts->id2name($entry['user_id']);
+				$entry['document_date'] = $GLOBALS['phpgw']->common->show_date($entry['start_date'],$dateformat);
+				$entry['entry_date'] 	= $GLOBALS['phpgw']->common->show_date($entry['entry_date'],$dateformat);
+				if($use_svn)
+			{
+					$entry['journal'] 		= $this->get_file($entry['document_id'], true);
+				}
 			}
 
 			return $document;
@@ -223,6 +207,11 @@
 			$dateformat						= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 			$document['document_date']		= $GLOBALS['phpgw']->common->show_date($document['document_date'],$dateformat);
 
+			if(ereg('svn[s:][:/]/', $GLOBALS['phpgw_info']['server']['files_dir']))
+			{
+				$document['journal']			= $this->get_file($document_id, true, $document);
+			}
+
 			if(isset($document['vendor_id']) && $document['vendor_id'])
 			{
 				$custom 				= createObject('property.custom_fields');
@@ -253,7 +242,6 @@
 				$document['p'][$document['p_entity_id']]['p_cat_id']=$document['p_cat_id'];
 				$document['p'][$document['p_entity_id']]['p_cat_name'] = $category['name'];
 			}
-
 			return $document;
 		}
 
@@ -330,7 +318,13 @@
 				}
 				else if ($value['status'] == 'T' || $value['status'] == 'TO')
 				{
-					$record_history[$i]['value_new_value']	= $this->so->read_single_category($value['new_value']);
+					$category 								= $this->cats->return_single($value['new_value']);
+					$record_history[$i]['value_new_value']	= $category[0]['name'];
+					if($value['old_value'])
+					{
+						$category 								= $this->cats->return_single($value['old_value']);
+						$record_history[$i]['value_old_value']	= $category[0]['name'];
+					}
 				}
 				else if ($value['status'] != 'O' && $value['new_value'])
 				{
@@ -347,22 +341,49 @@
 			return $record_history;
 		}
 
-		function save($values)
+		function get_file($document_id, $get_journal = false, $values = array())
 		{
+			if(!$values)
+			{
+				$values = $this->read_single($document_id);
+			}
 
-			$document_date	= $this->bocommon->date_array($values['document_date']);
-			$values['document_date']	= mktime (2,0,0,$document_date['month'],$document_date['day'],$document_date['year']);
+			if($values['p_num'])
+			{
+				$file	= "{$this->bofiles->fakebase}/document/entity_{$values['p_entity_id']}_{$values['p_cat_id']}/{$values['p_num']}/{$values['doc_type']}/{$values['document_name']}";
+			}
+			else
+			{
+				$file	= "{$this->bofiles->fakebase}/document/{$values['location_code']}/{$values['doc_type']}/{$values['document_name']}";
+			}
 
-			while (is_array($values['location']) && list(,$value) = each($values['location']))
+			if($this->bofiles->vfs->file_exists(array(
+					'string' => $file,
+					'relatives' => Array(RELATIVE_NONE)
+				)))
 			{
-				if($value)
+
+				if($get_journal)
 				{
-					$location[] = $value;
+					return $this->bofiles->vfs->get_journal(array(
+							'string' => $file,
+							'relatives' => Array(RELATIVE_NONE)
+							));
 				}
+				else
+				{
+					return $file;
+				}
 			}
+			return false;
+			}
 
-			$values['location_code']=implode("-", $location);
+		function save($values)
+		{
 
+			$document_date	= $this->bocommon->date_array($values['document_date']);
+			$values['document_date']	= mktime (2,0,0,$document_date['month'],$document_date['day'],$document_date['year']);
+
 //_debug_array($values);
 			if ($values['document_id'])
 			{

Modified: people/sigurdne/modules/property/trunk/inc/class.boentity.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boentity.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boentity.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -42,6 +42,7 @@
 		var $cat_id;
 		var $allrows;
 		var $part_of_town_id;
+		var $location_code;
 
 		/**
 		* @var object $custom reference to custom fields object
@@ -76,11 +77,16 @@
 			)
 		);
 
+		var $type_app = array
+		(
+			'entity'	=> 'property',
+			'catch'		=> 'catch'
+		);
+
 		function property_boentity($session=false)
 		{
 			$this->solocation 	= CreateObject('property.solocation');
 			$this->bocommon 	= CreateObject('property.bocommon');
-			$this->custom 		= createObject('property.custom_fields');
 
 			if ($session)
 			{
@@ -100,20 +106,23 @@
 			$start_date	= phpgw::get_var('start_date');
 			$end_date	= phpgw::get_var('end_date');
 			$allrows	= phpgw::get_var('allrows', 'bool');
+			$type		= phpgw::get_var('type');
+			$location_code		= phpgw::get_var('location_code');
+			$this->type	= isset($type)  && $type && $this->type_app[$type] ? $type : 'entity';
+			$this->location_code	= isset($location_code)  && $location_code ? $location_code : '';
 
-
 			$this->soadmin_entity 	= CreateObject('property.soadmin_entity',$entity_id,$cat_id);
 			$this->so 		= CreateObject('property.soentity',$entity_id,$cat_id);
-			$this->category_dir = 'entity_' . $entity_id . '_' . $cat_id;
+			$this->custom 					= & $this->so->custom;
+			$this->soadmin_entity->type		= $this->type;
+			$this->soadmin_entity->type_app	= $this->type_app;
+			$this->so->type					= $this->type;
+			$this->so->type_app				= $this->type_app;
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
+			$this->category_dir = "{$this->type}_{$entity_id}_{$cat_id}";
+
+			$this->start			= $start ? $start : 0;
+
 			if(isset($_POST['query']) || isset($_GET['query']))
 			{
 				$this->query = $query;
@@ -164,13 +173,13 @@
 		{
 			if ($this->use_session)
 			{
-				$GLOBALS['phpgw']->session->appsession('session_data','entity',$data);
+				$GLOBALS['phpgw']->session->appsession('session_data',$this->type,$data);
 			}
 		}
 
 		function read_sessiondata()
 		{
-			$data = $GLOBALS['phpgw']->session->appsession('session_data','entity');
+			$data = $GLOBALS['phpgw']->session->appsession('session_data',$this->type);
 			//_debug_array($data);
 			$this->start		= isset($data['start'])?$data['start']:'';
 			$this->query		= isset($data['query'])?$data['query']:'';
@@ -188,9 +197,10 @@
 		{
 			if(!$selected)
 			{
-				$selected=$GLOBALS['phpgw_info']['user']['preferences']['property']["entity_columns_" . $this->entity_id . '_' . $this->cat_id];
+				$selected=$GLOBALS['phpgw_info']['user']['preferences'][$this->type_app[$this->type]]["{$this->type}_columns_{$this->entity_id}_{$this->cat_id}"];
 			}
-			$columns = $this->custom->find('property','.entity.' . $entity_id . '.' . $cat_id, 0, '','','',true);
+			$filter = array('list' => ''); // translates to "list IS NULL"
+			$columns = $this->custom->find($this->type_app[$this->type],".{$this->type}.{$entity_id}.{$cat_id}", 0, '','','',true, false, $filter);
 			$column_list=$this->bocommon->select_multi_list($selected,$columns);
 			return $column_list;
 		}
@@ -230,7 +240,7 @@
 			return $this->bocommon->select_list($selected,$status_entries);
 		}
 
-		function read($data='')
+		function read($data= array())
 		{
 			if(isset($this->allrows))
 			{
@@ -239,8 +249,11 @@
 
 			$entity = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' => $this->district_id,
-											'lookup'=>isset($data['lookup'])?$data['lookup']:'','allrows'=>isset($data['allrows'])?$data['allrows']:'','entity_id'=>$this->entity_id,'cat_id'=>$this->cat_id,'status'=>$this->status,
-											'start_date'=>$this->bocommon->date_to_timestamp($data['start_date']),'end_date'=>$this->bocommon->date_to_timestamp($data['end_date'])));
+											'lookup'=>isset($data['lookup'])?$data['lookup']:'','allrows'=>isset($data['allrows'])?$data['allrows']:'',
+											'entity_id'=>$this->entity_id,'cat_id'=>$this->cat_id,'status'=>$this->status,
+											'start_date'=>$this->bocommon->date_to_timestamp($data['start_date']),
+											'end_date'=>$this->bocommon->date_to_timestamp($data['end_date']),
+											'dry_run'=>$data['dry_run'], 'type'=>$data['type'], 'location_code' => $this->location_code));
 
 			$this->total_records = $this->so->total_records;
 			$this->uicols	= $this->so->uicols;
@@ -273,16 +286,16 @@
 			return $entity;
 		}
 
-		function read_single($data)
+		function read_single($data, $values = array())
 		{
-			$values['attributes'] = $this->custom->find('property','.entity.' . $data['entity_id'] .'.' . $data['cat_id'], 0, '', 'ASC', 'attrib_sort', true, true);
+			$values['attributes'] = $this->custom->find($this->type_app[$this->type],".{$this->type}.{$data['entity_id']}.{$data['cat_id']}", 0, '', 'ASC', 'attrib_sort', true, true);
 			if(isset($data['id']) && $data['id'])
 			{
 				$values = $this->so->read_single($data, $values);
 			}
-			$values = $this->custom->prepare($values, 'property','.entity.' . $data['entity_id'] .'.' . $data['cat_id'], $data['view']);
+			$values = $this->custom->prepare($values, $this->type_app[$this->type],".{$this->type}.{$data['entity_id']}.{$data['cat_id']}", $data['view']);
 
-			$soadmin_entity	= CreateObject('property.soadmin_entity');
+	//		$soadmin_entity	= CreateObject('property.soadmin_entity');
 
 			if($values['location_code'])
 			{
@@ -299,7 +312,7 @@
 
 			if($values['p_num'])
 			{
-				$category = $soadmin_entity->read_single_category($values['p_entity_id'],$values['p_cat_id']);
+				$category = $this->soadmin_entity->read_single_category($values['p_entity_id'],$values['p_cat_id']);
 				$values['p'][$values['p_entity_id']]['p_num']=$values['p_num'];
 				$values['p'][$values['p_entity_id']]['p_entity_id']=$values['p_entity_id'];
 				$values['p'][$values['p_entity_id']]['p_cat_id']=$values['p_cat_id'];
@@ -308,23 +321,60 @@
 
 			$vfs = CreateObject('phpgwapi.vfs');
 			$vfs->override_acl = 1;
-			$values['files'] = $vfs->ls (array(
-			     'string' => "/property/{$this->category_dir}/{$values['location_data']['loc1']}/{$data['id']}",
+			
+			$loc1 = isset($values['location_data']['loc1']) && $values['location_data']['loc1'] ? $values['location_data']['loc1'] : 'dummy';
+
+			if($this->type_app[$this->type] == 'catch')
+			{
+				$loc1 = 'dummy';
+			}
+
+			$files = $vfs->ls (array(
+			     'string' => "/property/{$this->category_dir}/{$loc1}/{$data['id']}",
 			     'relatives' => array(RELATIVE_NONE)));
 
 			$vfs->override_acl = 0;
 
-			if(!isset($values['files'][0]['file_id']) || !$values['files'][0]['file_id'])
+			$values['jasperfiles']	= array();
+			$values['files']		= array();
+			foreach ($files as $file)
 			{
-				unset($values['files']);
+				if (strpos($file['name'], 'jasper::')===0)// check for jasper
+			{
+					$values['jasperfiles'][] = array
+					(
+						'name' 		=> $file['name']
+					);
+				}
+				else
+				{
+					$values['files'][] = array
+					(
+						'name' 		=> $file['name']
+					);
+				}
 			}
 
 			$interlink 	= CreateObject('property.interlink');
-			$values['origin'] = $interlink->get_relation('property', ".entity.{$data['entity_id']}.{$data['cat_id']}", $data['id'], 'origin');
-			$values['target'] = $interlink->get_relation('property', ".entity.{$data['entity_id']}.{$data['cat_id']}", $data['id'], 'target');
+			$values['origin'] = $interlink->get_relation($this->type_app[$this->type], ".{$this->type}.{$data['entity_id']}.{$data['cat_id']}", $data['id'], 'origin');
+			$values['target'] = $interlink->get_relation($this->type_app[$this->type], ".{$this->type}.{$data['entity_id']}.{$data['cat_id']}", $data['id'], 'target');
 			return $values;
 		}
 
+		/**
+		* Arrange attributes within groups
+		*
+		* @param string  $location    the name of the location of the attribute
+		* @param array   $attributes  the array of the attributes to be grouped
+		*
+		* @return array the grouped attributes
+		*/
+
+		public function get_attribute_groups($location, $attributes = array())
+		{
+			return $this->custom->get_attribute_groups($this->type_app[$this->type], $location, $attributes);
+		}
+
 		function save($values,$values_attribute,$action='',$entity_id,$cat_id)
 		{
 			while (is_array($values['location']) && list(,$value) = each($values['location']))
@@ -355,8 +405,8 @@
 
 			$criteria = array
 			(
-				'appname'	=> 'property',
-				'location'	=> ".entity.{$entity_id}.{$cat_id}",
+				'appname'	=> $this->type_app[$this->type],
+				'location'	=> ".{$this->type}.{$entity_id}.{$cat_id}",
 				'allrows'	=> true
 			);
 
@@ -370,10 +420,11 @@
 					continue;
 				}
 
-				$file = PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+				$file = PHPGW_SERVER_ROOT . "/{$this->type_app[$this->type]}/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+
 				if ( $entry['active'] && is_file($file) )
 				{
-					require_once PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+					require_once $file;
 				}
 			}
 
@@ -393,11 +444,50 @@
 			}
 		}
 
+		function get_history_type_for_location($acl_location)
+		{
+			switch($acl_location)
+			{
+				case '.project.request':
+					$history_type ='request';
+					break;
+				case '.project.workorder':
+					$history_type ='workorder';
+					break;
+				case '.project':
+					$history_type ='project';
+					break;
+				case '.tts':
+					$history_type ='tts';
+					break;
+				case '.document':
+					$history_type ='document';
+					break;
+				case 'entity':
+					$this->table='fm_entity_history';
+					$this->attrib_id_field = ',history_attrib_id';
+					break;
+				case '.s_agreement':
+					$history_type ='s_agreement';
+					break;
+				case '.s_agreement.detail':
+					$history_type ='s_agreement';
+				default:
+					$history_type = str_replace('.','_',substr($acl_location,-strlen($acl_location)+1));
+			}
+			if(!$history_type)
+			{
+					throw new Exception(lang('Unknown history type for acl_location: %1', $acl_location));
+			}
+			return $history_type;
+		}
+		
 		function read_attrib_history($data)
 		{
 		//	_debug_array($data);
-			$historylog = CreateObject('property.historylog','entity_' . $data['entity_id'] .'_' . $data['cat_id']);
-			$history_values = $historylog->return_array(array(),array('SO'),'history_timestamp','ASC',$data['id'],$data['attrib_id']);
+			$history_type = $this->get_history_type_for_location($data['acl_location']);
+			$historylog = CreateObject('property.historylog',$history_type);
+			$history_values = $historylog->return_array(array(),array('SO'),'history_timestamp','ASC',$data['id'],$data['attrib_id'], $data['detail_id']);
 			$this->total_records = count($history_values);
 		//	_debug_array($history_values);
 			return $history_values;
@@ -405,7 +495,8 @@
 
 		function delete_history_item($data)
 		{
-			$historylog = CreateObject('property.historylog','entity_' . $data['entity_id'] .'_' . $data['cat_id']);
+			$history_type = $this->get_history_type_for_location($data['acl_location']);
+			$historylog = CreateObject('property.historylog', $history_type);
 			$historylog->delete_single_record($data['history_id']);
 		}
 

Added: people/sigurdne/modules/property/trunk/inc/class.boevent.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boevent.inc.php	                        (rev 0)
+++ people/sigurdne/modules/property/trunk/inc/class.boevent.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -0,0 +1,1159 @@
+<?php
+	/**
+	* phpGroupWare - property: a Facilities Management System.
+	*
+	* @author Sigurd Nes <[email protected]>
+	* @copyright Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. http://www.fsf.org/
+	* This file is part of phpGroupWare.
+	*
+	* phpGroupWare is free software; you can redistribute it and/or modify
+	* it under the terms of the GNU General Public License as published by
+	* the Free Software Foundation; either version 2 of the License, or
+	* (at your option) any later version.
+	*
+	* phpGroupWare is distributed in the hope that it will be useful,
+	* but WITHOUT ANY WARRANTY; without even the implied warranty of
+	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	* GNU General Public License for more details.
+	*
+	* You should have received a copy of the GNU General Public License
+	* along with phpGroupWare; if not, write to the Free Software
+	* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+	*
+	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
+	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
+	* @package property
+	* @subpackage admin
+ 	* @version $Id$
+	*/
+
+	/*
+	 * Import the datetime class for date processing
+	 */
+	phpgw::import_class('phpgwapi.datetime');
+
+if ( !extension_loaded('mcal') )
+{
+	define('MCAL_RECUR_NONE',0);
+	define('MCAL_RECUR_DAILY',1);
+	define('MCAL_RECUR_WEEKLY',2);
+	define('MCAL_RECUR_MONTHLY_MDAY',3);
+	define('MCAL_RECUR_MONTHLY_WDAY',4);
+	define('MCAL_RECUR_YEARLY',5);
+	
+	define('MCAL_M_SUNDAY',1);
+	define('MCAL_M_MONDAY',2);
+	define('MCAL_M_TUESDAY',4);
+	define('MCAL_M_WEDNESDAY',8);
+	define('MCAL_M_THURSDAY',16);
+	define('MCAL_M_FRIDAY',32);
+	define('MCAL_M_SATURDAY',64);
+	
+	define('MCAL_M_WEEKDAYS',62);
+	define('MCAL_M_WEEKEND',65);
+	define('MCAL_M_ALLDAYS',127);
+}
+
+	/**
+	 * Description
+	 * @package property
+	 */
+
+	class property_boevent
+	{
+		var $start;
+		var $query;
+		var $filter;
+		var $sort;
+		var $order;
+		var $cat_id;
+		var $location_info = array();
+		var $cached_events;
+		protected $event_functions = array
+		(
+			'send_sms'	=> 'send SMS'
+		);
+
+		var $public_functions = array
+		(
+			'event_schedule_data'		=> true,
+			'event_schedule_week_data'	=> true
+		);
+
+	
+		function __construct($session=false)
+		{
+			$this->so 			= CreateObject('property.soevent');
+			$this->custom 		= CreateObject('property.custom_fields');//& $this->so->custom;
+	//		$this->bocommon 	= CreateObject('property.bocommon');
+			$this->sbox 		= CreateObject('phpgwapi.sbox');
+			$this->asyncservice = CreateObject('phpgwapi.asyncservice');
+
+			if ($session)
+			{
+				$this->read_sessiondata();
+				$this->use_session = true;
+			}
+
+			$start				= phpgw::get_var('start', 'int', 'REQUEST', 0);
+			$query				= phpgw::get_var('query');
+			$sort				= phpgw::get_var('sort');
+			$order				= phpgw::get_var('order');
+			$filter				= phpgw::get_var('filter', 'int');
+			$cat_id				= phpgw::get_var('cat_id', 'int');
+			$allrows			= phpgw::get_var('allrows', 'bool');
+			$type				= phpgw::get_var('type');
+			$type_id			= phpgw::get_var('type_id', 'int');
+
+			$this->start		= $start ? $start : 0;
+			$this->query		= isset($_REQUEST['query']) ? $query : $this->query;
+			$this->sort			= isset($_REQUEST['sort']) ? $sort : $this->sort;
+			$this->order		= isset($_REQUEST['order']) ? $order : $this->order;
+			$this->filter		= isset($_REQUEST['filter']) ? $filter : $this->filter;
+			$this->cat_id		= isset($_REQUEST['cat_id'])  ? $cat_id :  $this->cat_id;
+			$this->allrows		= isset($allrows) ? $allrows : false;
+
+			//$this->location_info = $this->so->get_location_info($type, $type_id);
+
+		}
+
+		public function save_sessiondata($data)
+		{
+			if ($this->use_session)
+			{
+				$GLOBALS['phpgw']->session->appsession('session_data','category',$data);
+			}
+		}
+
+		function read_sessiondata()
+		{
+			$data = $GLOBALS['phpgw']->session->appsession('session_data','category');
+
+	//		_debug_array($data);
+
+			$this->start	= $data['start'];
+			$this->query	= $data['query'];
+			$this->filter	= $data['filter'];
+			$this->sort		= $data['sort'];
+			$this->order	= $data['order'];
+			$this->cat_id	= $data['cat_id'];
+			$this->allrows	= $data['allrows'];
+		}
+
+		public function read()
+		{
+			$values = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
+											'allrows'=>$this->allrows));
+
+			$this->total_records = $this->so->total_records;
+			$this->uicols = $this->so->uicols;
+
+			return $values;
+		}
+
+		public function read_single($id)
+		{
+			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+			$values = $this->so->read_single($id);
+			if($values)
+			{
+				$values['start_date']		= $GLOBALS['phpgw']->common->show_date($values['start_date'],$dateformat);
+				$values['end_date']		= $GLOBALS['phpgw']->common->show_date($values['end_date'],$dateformat);
+				if($values['rpt_day'])
+				{
+					$rpt_day = array
+					(
+						1		=> 'Sunday',
+						2		=> 'Monday',
+						4		=> 'Tuesday',
+						8		=> 'Wednesday',
+						16		=> 'Thursday',
+						32		=> 'Friday',
+						64		=> 'Saturday'
+					);
+
+					foreach ($rpt_day as $mask => $name)
+					{
+						if($mask & $values['rpt_day'])
+						{
+							$values['repeat_day'][$mask] = $name;
+						}
+					}
+				}
+
+				$location	= phpgw::get_var('location');
+				$job_id = "property{$location}::{$values['location_item_id']}::{$values['attrib_id']}";
+				$job = execMethod('phpgwapi.asyncservice.read', $job_id);
+
+				$values['next'] = $GLOBALS['phpgw']->common->show_date($job[$job_id]['next'],$dateformat);
+			}
+
+	//		$this->find_scedules($criteria);
+
+			return $values;
+		}
+
+		public function save($data)
+		{
+			$data['start_date'] = phpgwapi_datetime::date_to_timestamp($data['start_date']);
+			$data['end_date'] = phpgwapi_datetime::date_to_timestamp($data['end_date']);
+
+			if (isset($data['id']) && $data['id'] > 0 && $this->so->read_single($data['id']))
+			{
+				$receipt = $this->so->edit($data);
+			}
+			else
+			{
+				$receipt = $this->so->add($data);
+			}
+
+			$action_object		= CreateObject('property.socategory');
+			$action_object->get_location_info('event_action',false);
+			$action	= $action_object->read_single(array('id'=> $data['action']),$values = array());
+
+			$rpt_day = array
+			(
+				1		=> 0, //'Sunday',
+				2		=> 1, //'Monday',
+				4		=> 2, //'Tuesday',
+				8		=> 3, //'Wednesday',
+				16		=> 4, //'Thursday',
+				32		=> 5, //'Friday',
+				64		=> 6  //'Saturday'
+			);
+
+			$repeat_day = array();
+			if ($data['repeat_day'])
+			{
+				foreach ($data['repeat_day'] as $day)
+				{
+					if (isset($rpt_day[$day]))
+					{
+						$repeat_day[] = $rpt_day[$day];
+					}
+				}
+				$repeat_day = implode(',', $repeat_day);
+			}
+
+			if(!isset($data['repeat_type']) || !$data['repeat_type'])
+			{
+				$times = $data['start_date'];
+			}
+			else
+			{
+				$dow = $rpt_day[$data['repeat_day'][0]];
+				switch($data['repeat_type'])
+				{
+					case '0':
+						$times = $data['start_date'];
+						break;
+					case '1': //'Daily'
+						if($data['repeat_interval'])
+						{
+							$times = array('day' => "*/{$data['repeat_interval']}");
+						}
+						else
+						{
+							$times = array('day' => "*/1");
+						}
+						break;
+					case '2': //'Weekly'
+						if($data['repeat_interval'])
+						{
+							$day = $data['repeat_interval'] * 7;
+							$times = array('day' => "*/{$day}");
+						}
+						else
+						{
+							$times = array('day' => "*/7");
+						}
+						if ($data['repeat_day'])
+						{
+							$times['dow'] = $repeat_day;
+						}
+						break;
+					case '3': //'Monthly (by day)'
+						if( !isset($data['repeat_day']) || !is_array($data['repeat_day']) )
+						{
+							$dow = 1;
+						}
+						
+						if($data['repeat_interval'])
+						{
+							$times = array('month' => "*/{$data['repeat_interval']}", 'dow' => $dow);
+						}
+						else
+						{
+							$times = array('month' => "*/1", 'dow' => $dow);
+						}
+						break;
+					case '4': //'Monthly (by date)'
+						if($data['repeat_interval'])
+						{
+							$times = array('month' => "*/{$data['repeat_interval']}", 'day' => 1);
+						}
+						else
+						{
+							$times = array('day' => 1);
+						}
+						break;
+					case '5': //'Yearly'
+						$month = date(n, $data['start_date']);
+						if($data['repeat_interval'])
+						{
+							$times = array('year' => "*/{$data['repeat_interval']}", 'month' => $month);
+						}
+						else
+						{
+							$times = array('month' => $month);
+						}
+						break;
+					default:
+						$times = $data['start_date'];
+						break;
+				}
+			}
+
+			//$times['min']= '*'; // for testing the  - every minute
+
+			$account_id = execMethod('property.soresponsible.get_responsible_user_id', $data['responsible']);
+
+			$timer_data = array
+			(
+				'start'		=> $data['start_date'],
+				'enabled'	=> true,
+				'owner'		=> $account_id,
+				'enabled'	=> !! $data['enabled'],
+				'action'	=> $action['action']
+			);
+				
+			if($data['end_date'])
+			{
+				$timer_data['end'] = $data['end_date'];
+			}
+
+			if($action['data'])
+			{
+				str_replace(";", '', $action['data']);
+				eval('$action_data = ' . htmlspecialchars_decode($action['data']) . ';');
+				$timer_data = array_merge($timer_data, $action_data);
+			}
+
+			$location	= phpgw::get_var('location');
+
+			$id = "property{$location}::{$data['item_id']}::{$data['attrib_id']}";
+			$timer_data['id'] = $id;
+
+			$this->asyncservice->cancel_timer($id);
+			$this->asyncservice->set_timer($times, $id, 'property.boevent.action', $timer_data, $account_id);
+
+			return $receipt;
+		}
+
+		public function action($data)
+		{
+			$parts = explode('::',$data['id']);
+			$id = end($parts);
+
+			if($data['enabled'] && !$this->so->check_event_exception($id,$data['time']))
+			{
+				list($module, $classname) = explode('.', $data['action'], 2);
+				if ( is_file(PHPGW_INCLUDE_ROOT . "/{$module}/class.{$classname}.inc.php") )
+				{
+					$message = execMethod($data['action'], $data);
+				}
+				else
+				{
+					$message = "No such file: {$module}/class.{$classname}.inc.php";
+				}
+
+				$this->so->cron_log(array
+					(
+						'cron'		=> true, // or false for manual...
+						'action'	=> $data['action'],
+						'message'	=> $message
+					)
+				);
+			}
+		}
+
+		public function delete($id)
+		{
+			$values = $this->read_single($id);
+			$location	= phpgw::get_var('location');
+			$job_id = "property{$location}::{$values['location_item_id']}::{$values['attrib_id']}";
+			$job = execMethod('phpgwapi.asyncservice.cancel_timer', $job_id);
+
+			return $this->so->delete($id);
+		}
+
+		public function get_rpt_type_list($selected='')
+		{
+			$rpt_type = array
+			(
+				0	=> 'None',
+				1	=> 'Daily',
+				2	=> 'Weekly',
+				3	=> 'Monthly (by date)',
+				4	=> 'Monthly (by day)',
+				5	=> 'Yearly'
+			);
+
+
+			return $this->sbox->getArrayItem('values[repeat_type]', $selected, $rpt_type);
+		}
+
+		public function get_rpt_day_list($selected=array())
+		{
+			$rpt_day = array
+			(
+				1		=> 'Sunday',
+				2		=> 'Monday',
+				4		=> 'Tuesday',
+				8		=> 'Wednesday',
+				16		=> 'Thursday',
+				32		=> 'Friday',
+				64		=> 'Saturday'
+			);
+
+			$title = lang('(for weekly)');
+			$i = 0; $boxes = '';
+			foreach ($rpt_day as $mask => $name)
+			{
+				$boxes .= '<input type="checkbox" title = "' . $title . '"name="values[repeat_day][]" value="'.$mask.'"'.(isset($selected[$mask]) && $selected[$mask] ? ' checked' : '').'></input> '.lang($name)."\n";
+				if (++$i == 5) $boxes .= '<br />';
+			}
+			return $boxes;
+		}
+
+		public function get_responsible($selected = '')
+		{
+			$responsible = CreateObject('property.soresponsible');
+			
+			$location = phpgw::get_var('location');
+			$values = $responsible->read_type(array('start' => 0, 'query' =>'', 'sort' => '',
+												'order' => '', 'location' => $location, 'allrows'=>true,
+												'filter' => ''));
+
+			$list = array(0 => lang('none'));
+			foreach($values as $entry)
+			{
+				$list[$entry['id']] = $entry['name'];
+			}
+
+			return $this->sbox->getArrayItem('values[responsible]', $selected, $list, true);
+		}
+
+		public function get_action($selected = '')
+		{
+/*			$action_object					= CreateObject('property.socategory');
+			$action_object->get_location_info('event_action',false);
+			$values					= $action_object->read(array('allrows'=> true));
+*/
+			$list = array(0 => lang('none'));
+/*
+			foreach($values as $entry)
+			{
+				$list[$entry['id']] = $entry['name'];
+			}
+*/
+			$list = array_merge($list,$this->event_functions);
+
+			return $this->sbox->getArrayItem('values[action]', $selected, $list, true);
+		}
+		
+		protected function send_sms()
+		{
+			$data = array
+			(
+				'p_num_text'	=> 'xxxxxxxx',//number
+				'message'		=> 'dette er en melding'
+			);
+
+			execMethod('sms.bosms.send_sms', $data);
+		}
+
+		/**
+		* Find recurring events
+		*
+		* @param array $date the date array to convert, must contain keys 'start_date', 'end_date', 'appname', 'location'
+		* @return array events
+		*/
+
+		function find_scedules($params)
+		{			
+			if(!is_array($params))
+			{
+				return False;
+			}
+
+			if(!isset($params['location_id']) || !$params['location_id'])
+			{
+				if(!isset($params['appname']) || !$params['appname'] || !isset($params['location']) || !$params['location'])
+				{
+					throw new Exception("property_boevent::find_scedules - Missing location info in input");
+				}
+				$location_id = $GLOBALS['phpgw']->locations->get_id($params['appname'], $params['location']);
+			}
+			else
+			{
+				$location_id = $params['location_id'];
+			}
+
+			if(!isset($params['location_item_id']) || !$params['location_item_id'])
+			{
+					throw new Exception("property_boevent::find_scedules - Missing location_item_id in input");
+			}
+			$location_item_id = $params['location_item_id'];
+
+			if($params['start_date'])
+			{
+				$syear = date('Y',$params['start_date']);
+				$smonth = date('m',$params['start_date']);
+				$sday = date('d',$params['start_date']);
+			}
+
+			$eyear = $params['end_date'] ? date('Y',$params['end_date']) : 0;
+			$emonth = $params['end_date'] ? date('m',$params['end_date']) : 0;
+			$eday = $params['end_date'] ? date('d',$params['end_date']) : 0;
+
+			$owner_id = (isset($params['owner'])?$params['owner']:0);
+			if($owner_id==0 && $this->is_group)
+			{
+				unset($owner_id);
+				$owner_id = $this->g_owner;
+				if($this->debug)
+				{
+					echo '<!-- owner_id in ('.implode($owner_id,',').') -->'."\n";
+				}
+			}
+			
+			if(!$eyear && !$emonth && !$eday)
+			{
+				$edate = mktime(23,59,59,$smonth + 1,$sday + 1,$syear);
+				$eyear = date('Y',$edate);
+				$emonth = date('m',$edate);
+				$eday = date('d',$edate);
+			}
+			else
+			{
+				if(!$eyear)
+				{
+					$eyear = $syear;
+				}
+				if(!$emonth)
+				{
+					$emonth = $smonth + 1;
+					if($emonth > 12)
+					{
+						$emonth = 1;
+						$eyear++;
+					}
+				}
+				if(!$eday)
+				{
+					$eday = $sday + 1;
+				}
+				$edate = mktime(23,59,59,$emonth,$eday,$eyear);
+			}
+			
+			if($this->debug)
+			{
+				echo '<!-- Start Date : '.sprintf("%04d%02d%02d",$syear,$smonth,$sday).' -->'."\n";
+				echo '<!-- End   Date : '.sprintf("%04d%02d%02d",$eyear,$emonth,$eday).' -->'."\n";
+			}
+
+			$find_criteria = array
+			(
+				'syear'				=> $syear,
+				'smonth'			=> $smonth,
+				'sday'				=> $sday,
+				'eyear'				=> $eyear,
+				'emonth'			=> $emonth,
+				'eday'				=> $eday,
+				'tz_offset'			=> 0,
+				'extra'				=> '',
+				'owner_id'			=> $owner_id,
+				'location_id'		=> $location_id,
+				'location_item_id'	=> $location_item_id
+			);
+
+			$cached_event_ids			= $this->so->list_events($find_criteria);
+			$cached_event_ids_repeating	= $this->so->list_repeated_events($find_criteria);
+//_debug_array($cached_event_ids_repeating);die();
+			unset($find_criteria);
+
+			if($this->debug)
+			{
+				echo '<!-- events cached : '.count($cached_event_ids).' : for : '.sprintf("%04d%02d%02d",$syear,$smonth,$sday).' -->'."\n";
+				echo '<!-- repeating events cached : '.count($cached_event_ids_repeating).' : for : '.sprintf("%04d%02d%02d",$syear,$smonth,$sday).' -->'."\n";
+			}
+
+			$this->cached_events = array();
+			
+			if(!$cached_event_ids && !$cached_event_ids_repeating)
+			{
+				return;
+			}
+
+
+			foreach($cached_event_ids as $cached_event_id)
+			{
+				$event = $this->so->read_single($cached_event_id);
+				$startdate = intval(date('Ymd',$event['start_date']));
+				$enddate = intval(date('Ymd',$event['end_date']));
+				$this->cached_events[$startdate][] = $event;
+				if($startdate != $enddate && !$cached_event_ids_repeating)
+				{
+					$start['year'] = intval(substr($startdate,0,4));
+					$start['month'] = intval(substr($startdate,4,2));
+					$start['mday'] = intval(substr($startdate,6,2));
+					for($j=$startdate,$k=0;$j<=$enddate;$k++,$j=intval(date('Ymd',mktime(0,0,0,$start['month'],$start['mday'] + $k,$start['year']))))
+					{
+						$c_evt_day = 0;
+						if(isset($this->cached_events[$j]) && is_array($this->cached_events[$j]))
+						{
+							$c_evt_day = count($this->cached_events[$j])-1;
+						}
+						if($this->debug)
+						{
+							echo 'Date: '.$j.' Count : '.count($this->cached_events[$j])."\n";
+						}
+
+						if(!isset($this->cached_events[$j][$c_evt_day])
+							||$this->cached_events[$j][$c_evt_day]['id'] != $event['id'])
+						{
+							if($this->debug)
+							{
+								echo "Adding Event ID {$event['id']} for Date: {$j}</br>";
+							}
+							$this->cached_events[$j][] = $event;
+						}
+					}
+				}
+			}
+
+			$this->repeating_events = array();
+			if($cached_event_ids_repeating)
+			{
+//_debug_array($cached_event_ids_repeating);die();
+				$i = 0;
+				foreach($cached_event_ids_repeating as $cached_event_id)
+				{
+					$this->repeating_events[] = $this->so->read_single($cached_event_id);
+
+					if($this->debug)
+					{
+						echo 'Cached Events ID: '.$cached_event_id.' ('.sprintf("%04d%02d%02d",$this->repeating_events[$i]['start']['year'],$this->repeating_events[$i]['start']['month'],$this->repeating_events[$i]['start']['mday']).')</br>';
+					}
+					$i++;
+				}
+//				$edate -= phpgwapi_datetime::user_timezone();
+//				for($date=mktime(0,0,0,$smonth,$sday,$syear) - phpgwapi_datetime::tz_offset;$date<=$edate;$date += 86400)
+				for($date=mktime(0,0,0,$smonth,$sday,$syear);$date<=$edate;$date += phpgwapi_datetime::SECONDS_IN_DAY)
+				{
+					if($this->debug)
+					{
+						$search_date = date('Ymd',$date);
+						echo 'Calling check_repeating_events('.$search_date.')</br>';
+					}
+					$this->check_repeating_events($date);
+					if($this->debug)
+					{
+						echo 'Total events found matching '.$search_date.' = '.count($this->cached_events[$search_date]).'</br>';
+						for($i=0;$i<count($this->cached_events[$search_date]);$i++)
+						{
+							echo '<!-- Date: '.$search_date.' ['.$i.'] = '.$this->cached_events[$search_date][$i]['id'].' -->'."\n";
+						}
+					}
+				}
+			}
+			$retval = array();
+			for($j=date('Ymd',mktime(0,0,0,$smonth,$sday,$syear)),$k=0;$j<=date('Ymd',mktime(0,0,0,$emonth,$eday,$eyear));$k++,$j=date('Ymd',mktime(0,0,0,$smonth,$sday + $k,$syear)))
+			{
+				if(isset($this->cached_events[$j]) && is_array($this->cached_events[$j]))
+				{
+					$retval[$j] = $this->cached_events[$j];
+				}
+			}
+//_debug_array($this->cached_events);die();
+			return $retval;
+//			return $this->cached_events;
+		}
+
+		function check_repeating_events($datetime)
+		{
+			@reset($this->repeating_events);
+			$search_date_full = date('Ymd',$datetime);
+			$search_date_year = date('Y',$datetime);
+			$search_date_month = date('m',$datetime);
+			$search_date_day = date('d',$datetime);
+			$search_date_dow = date('w',$datetime);
+			$search_date_week = date('YW',$datetime);
+			$search_beg_day = mktime(13,0,0,$search_date_month,$search_date_day,$search_date_year);
+			if($this->debug)
+			{
+				echo '<!-- Search Date Full = '.$search_date_full.' -->'."\n";
+			}
+			$repeated = $this->repeating_events;
+			$r_events = count($repeated);
+			for ($i=0;$i<$r_events;$i++)
+			{
+				if($this->repeating_events[$i]['repeat_type'] !=0)
+				{
+					$rep_events = $this->repeating_events[$i];
+
+					$id = $rep_events['id'];
+					$rep_events['start']['month']	= date('m',$rep_events['start_date']);
+					$rep_events['start']['mday']	= date('d',$rep_events['start_date']);
+					$rep_events['start']['year']	= date('Y',$rep_events['start_date']);
+
+//					$event_beg_day = mktime(0,0,0,$rep_events['start']['month'],$rep_events['start']['mday'],$rep_events['start']['year']);
+					$event_beg_day = $rep_events['start_date'];
+					$event_beg_week = date('YW',$rep_events['start_date']);
+
+					if(isset($rep_events['end_date']) && $rep_events['end_date'])
+					{
+						$event_recur_time = $rep_events['end_date'];
+					}
+					else
+					{
+						$event_recur_time = mktime(0,0,0,1,1,2030);
+					}
+/*
+					if($rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0)
+					{
+						$event_recur_time = $this->maketime($rep_events['recur_enddate']);
+					}
+					else
+					{
+						$event_recur_time = mktime(0,0,0,1,1,2030);
+					}
+*/
+					$end_recur_date = date('Ymd',$event_recur_time);
+					$full_event_date = date('Ymd',$event_beg_day);
+
+					if($this->debug)
+					{
+						echo '<!-- check_repeating_events - Processing ID - '.$id.' -->'."\n";
+						echo '<!-- check_repeating_events - Recurring End Date - '.$end_recur_date.' -->'."\n";
+					}
+
+					// only repeat after the beginning, and if there is an rpt_end before the end date
+					if (($search_date_full > $end_recur_date) || ($search_date_full < $full_event_date))
+					{
+						continue;
+					}
+
+					if ($search_date_full == $full_event_date)
+					{
+						$this->sort_event($rep_events,$search_date_full);
+						continue;
+					}
+					else
+					{				
+						$freq = (isset($rep_events['repeat_interval']) && $rep_events['repeat_interval'] ?$rep_events['repeat_interval']:1);
+						$type = $rep_events['repeat_type'];
+						switch($type)
+						{
+							case MCAL_RECUR_DAILY:
+								if($this->debug)
+								{
+									echo '<!-- check_repeating_events - MCAL_RECUR_DAILY - '.$id.' -->'."\n";
+								}
+//								if ($freq == 1 && $rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0 && $search_date_full <= $end_recur_date)
+								if ($freq == 1 && $rep_events['end_date'] && $search_date_full <= $end_recur_date)
+								{
+									$this->sort_event($rep_events,$search_date_full);
+								}
+								elseif (floor(($search_beg_day - $event_beg_day)/86400) % $freq)
+								{
+									continue;
+								}
+								else
+								{
+									$this->sort_event($rep_events,$search_date_full);
+								}
+							break;
+							case MCAL_RECUR_WEEKLY:
+								$test = (($search_beg_day - $event_beg_day)/604800)/$freq;
+								$test_subtract = floor($test);
+
+								//if (floor(($search_beg_day - $event_beg_day)/604800) % $freq)
+								if(!$rep_events['rpt_day'])
+								{
+									if(!($test - $test_subtract))
+									{
+										$this->sort_event($rep_events,$search_date_full);
+									}
+								}
+								else
+								{
+									$test = ($search_date_week - $event_beg_week)/$freq;
+									$test_subtract = floor($test);
+									if(($test - $test_subtract))
+									{
+										continue;
+									}
+
+									$check = 0;
+									switch($search_date_dow)
+									{
+										case 0:
+											$check = MCAL_M_SUNDAY;
+											break;
+										case 1:
+											$check = MCAL_M_MONDAY;
+											break;
+										case 2:
+											$check = MCAL_M_TUESDAY;
+											break;
+										case 3:
+											$check = MCAL_M_WEDNESDAY;
+											break;
+										case 4:
+											$check = MCAL_M_THURSDAY;
+											break;
+										case 5:
+											$check = MCAL_M_FRIDAY;
+											break;
+										case 6:
+											$check = MCAL_M_SATURDAY;
+											break;
+									}
+
+									if ($rep_events['rpt_day'] & $check)
+									{
+										$this->sort_event($rep_events,$search_date_full);
+									}
+								}
+								break;
+							case MCAL_RECUR_MONTHLY_WDAY:
+								if ((($search_date_year - $rep_events['start']['year']) * 12 + $search_date_month - $rep_events['start']['month']) % $freq)
+								{
+									continue;
+								}
+	  
+								if ((phpgwapi_datetime::day_of_week($rep_events['start']['year'],$rep_events['start']['month'],$rep_events['start']['mday']) == phpgwapi_datetime::day_of_week($search_date_year,$search_date_month,$search_date_day)) &&
+									(ceil($rep_events['start']['mday']/7) == ceil($search_date_day/7)))
+								{
+									$this->sort_event($rep_events,$search_date_full);
+								}
+								break;
+							case MCAL_RECUR_MONTHLY_MDAY:
+								if ((($search_date_year - $rep_events['start']['year']) * 12 + $search_date_month - $rep_events['start']['month']) % $freq)
+								{
+									continue;
+								}
+								if ($search_date_day == $rep_events['start']['mday'])
+								{
+									$this->sort_event($rep_events,$search_date_full);
+								}
+								break;
+							case MCAL_RECUR_YEARLY:
+								if (($search_date_year - $rep_events['start']['year']) % $freq)
+								{
+									continue;
+								}
+								if (date('dm',$datetime) == date('dm',$event_beg_day))
+								{
+									$this->sort_event($rep_events,$search_date_full);
+								}
+								break;
+						}
+					}
+				}
+			}	// end for loop
+		}	// end function
+
+
+		function sort_event($event,$date)
+		{
+			$inserted = False;
+			$event['start']['month']	= date('m',$event['start_date']);
+			$event['start']['mday']		= date('d',$event['start_date']);
+			$event['start']['year']		= date('Y',$event['start_date']);
+
+			if(isset($event['repeat_exception']))
+			{
+//				$event_time = mktime($event['start']['hour'],$event['start']['min'],0,intval(substr($date,4,2)),intval(substr($date,6,2)),intval(substr($date,0,4))) - phpgwapi_datetime::user_timezone();
+				$event_time = mktime($event['start']['hour'],$event['start']['min'],0,intval(substr($date,4,2)),intval(substr($date,6,2)),intval(substr($date,0,4)));
+				while($inserted == false && list($key,$exception_time) = each($event['repeat_exception']))
+				{
+					if($this->debug)
+					{
+						echo '<!-- checking exception datetime '.$exception_time.' to event datetime '.$event_time.' -->'."\n";
+					}
+					if($exception_time == $event_time)
+					{
+//_debug_array(date('Y-m-d',$event_time));die();
+//						_debug_array($event);
+//						_debug_array($this->cached_events);die();
+//						$inserted = true;
+						$event['exception'] = true;
+
+/*
+						for($i=0;$i<count($this->cached_events[$date]);$i++)
+						{
+							if($this->cached_events[$date][$i]['id'] == $event['id'])
+							{
+							die();
+							}
+						}
+*/
+					}
+				}
+			}
+			if(isset($this->cached_events[$date]) && $this->cached_events[$date] && $inserted == false)
+			{
+				
+				if($this->debug)
+				{
+					echo '<!-- Cached Events found for '.$date.' -->'."\n";
+				}
+				$year = substr($date,0,4);
+				$month = substr($date,4,2);
+				$day = substr($date,6,2);
+
+				if($this->debug)
+				{
+					echo '<!-- Date : '.$date.' Count : '.count($this->cached_events[$date]).' -->'."\n";
+				}
+				
+				for($i=0;$i<count($this->cached_events[$date]);$i++)
+				{
+					$events = $this->cached_events[$date][$i];
+					if($this->cached_events[$date][$i]['id'] == $event['id'] || $this->cached_events[$date][$i]['reference'] == $event['id'])
+					{
+						if($this->debug)
+						{
+							echo '<!-- Item already inserted! -->'."\n";
+						}
+						$inserted = True;
+						break;
+					}
+					/* This puts all spanning events across multiple days up at the top. */
+					if($this->cached_events[$date][$i]['repeat_type'] == MCAL_RECUR_NONE)
+					{
+						if($this->cached_events[$date][$i]['start']['mday'] != $day && $this->cached_events[$date][$i]['end']['mday'] >= $day)
+						{
+							continue;
+						}
+					}
+					if(date('Hi',mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$day,$year)) < date('Hi',mktime($this->cached_events[$date][$i]['start']['hour'],$this->cached_events[$date][$i]['start']['min'],$this->cached_events[$date][$i]['start']['sec'],$month,$day,$year)))
+					{
+		//				for($j=count($this->cached_events[$date]);$j>=$i;$j--)
+						for($j=count($this->cached_events[$date]);$j>=($i+1);$j--)
+						{
+							$this->cached_events[$date][$j] = $this->cached_events[$date][$j-1];
+						}
+						if($this->debug)
+						{
+							echo '<!-- Adding event ID: '.$event['id'].' to cached_events -->'."\n";
+						}
+						$inserted = True;
+						$this->cached_events[$date][$i] = $event;
+						break;
+					}
+				}
+			}
+			if(!$inserted)
+			{
+				if($this->debug)
+				{
+					echo '<!-- Adding event ID: '.$event['id'].' to cached_events -->'."\n";
+				}
+				$this->cached_events[$date][] = $event;
+			}
+		}
+
+		public function init_schedule_week($id, $buildingmodule, $resourcemodule, $search = null)
+		{
+			$date = new DateTime(phpgw::get_var('date'));
+			// Make sure $from is a monday
+			if($date->format('w') != 1)
+			{
+				$date->modify('last monday');
+			}
+
+			$prev_date = clone $date;
+			$next_date = clone $date;
+			$prev_date->modify('-1 week');
+			$next_date->modify('+1 week');
+			$resource = $this->read_single($id);
+            if ($search)
+            {
+                $resource['buildings_link'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => $search, "type" => "building"));
+            }
+            else
+            {
+                $resource['buildings_link'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => $buildingmodule . '.index'));
+            }
+
+			$resource['building_link'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => $buildingmodule . '.show', 'id' => $resource['building_id']));
+			$resource['resource_link'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => $resourcemodule . '.show', 'id' => $resource['id']));
+			$resource['date'] = $date->format('Y-m-d');
+			$resource['week'] = intval($date->format('W'));
+			$resource['year'] = intval($date->format('Y'));
+			$resource['prev_link'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => $resourcemodule . '.schedule_week', 'id' => $resource['id'], 'date'=> $prev_date->format('Y-m-d')));
+			$resource['next_link'] = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => $resourcemodule . '.schedule_week', 'id' => $resource['id'], 'date'=> $next_date->format('Y-m-d')));
+			for($i = 0; $i < 7; $i++)
+			{
+				$resource['days'][] = array('label' => sprintf('%s<br/>%s %s', lang($date->format('l')), lang($date->format('M')), $date->format('d')), 'key' => $date->format('D'));
+				$date->modify('+1 day');
+			}
+			return $resource;
+		}
+
+
+		/**
+		* Find recurring events for a week
+		*
+		* @return array schedule
+		*/
+
+		public function event_schedule_week_data()
+		{
+//		    $date = new DateTime(phpgw::get_var('date')); Use this one when moving to php 5.3
+
+			$datetime = CreateObject('phpgwapi.datetime');
+			$date = $datetime->convertDate(phpgw::get_var('date'), 'Y-m-d', $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+			$datetime_start = $datetime->date_to_timestamp($date);
+	    
+			$id = phpgw::get_var('resource_id', 'int');
+	
+			$event = $this->so->read_single($id);
+			$criteria = array
+			(
+				'start_date'		=> $datetime_start,
+				'end_date'			=> $datetime_start + (86400 * 6),
+				'location_id'		=> $event['location_id'],
+				'location_item_id'	=> $event['location_item_id']
+			);
+
+			$this->find_scedules($criteria);
+			$schedules =  $this->cached_events;
+
+			$total_records = 0;
+			foreach($schedules as $_date => $set)
+			{
+				if(count($set) > $total_records)
+				{
+					$total_records = count($set);
+				}
+			}
+
+			$lang_exception	 = lang('exception');
+			$values = array();
+			for($i = 0; $i < $total_records; $i++)
+			{
+				$values[$i] = array
+				(
+					'resource'			=> 'descr',
+					'resource_id'		=> 11,
+					'time'				=> $i+1,
+					'_from'				=> '16:30',
+					'_to'				=> '17:00'
+				);
+
+				foreach($schedules as $_date => $set)
+				{
+					$__date = substr($_date,0,4) . '-' . substr($_date,4,2) . '-' . substr($_date,6,2);
+					$date = new DateTime($__date);
+					$day_of_week = $date->format('D');
+					$values[$i][$day_of_week] = array
+					(
+						'exception' => $set[$i]['exception'],
+						'lang_exception' => $lang_exception,
+						'type' => 'event',
+						'name' => $set[$i]['descr'],
+						'link' => $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'booking.uievent.show', 'location_id' => $set[$i]['location_id'], 'location_item_id' => $set[$i]['location_item_id']))
+					);
+				}
+			}
+
+			$data = array
+			(
+				'ResultSet' => array(
+					"totalResultsAvailable" => $total_records, 
+					"Result" => $values
+				)
+			);
+//_debug_array($data);die();
+			return $data;
+
+		}
+
+		/**
+		* Find recurring events for a period defined by the event
+		*
+		* @return array schedule
+		*/
+
+		public function event_schedule_data()
+		{
+			$id = phpgw::get_var('id', 'int');
+	
+			$event = $this->so->read_single($id);
+
+			$criteria = array
+			(
+				'start_date'		=> $event['start_date'],
+				'end_date'			=> $event['end_date'],
+				'location_id'		=> $event['location_id'],
+				'location_item_id'	=> $event['location_item_id']
+			);
+
+			$this->find_scedules($criteria);
+			$schedules =  $this->cached_events;
+
+			$total_records = 0;
+
+			$lang_exception	 = lang('exception');
+			$values = array();
+
+			$i = 1;
+			foreach($schedules as $_date => $set)
+			{
+				$__date = substr($_date,0,4) . '-' . substr($_date,4,2) . '-' . substr($_date,6,2);
+				$date = phpgwapi_datetime::convertDate($__date, 'Y-m-d', $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+
+				foreach($set as $entry)
+				{
+					$values[] = array
+					(
+						'time'				=> $i,
+						'date'				=> array
+						(
+							'exception' => $entry['exception'],
+							'lang_exception' => $lang_exception,
+							'type' => 'event',
+							'name' => $date,
+							'link' => $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'booking.uievent.show', 'location_id' => $entry['location_id'], 'location_item_id' => $entry['location_item_id']))
+						)
+					);
+
+					$i++;
+				}
+			}
+
+			$data = array
+			(
+				'ResultSet' => array(
+					"totalResultsAvailable" => $total_records, 
+					"Result" => $values
+				)
+			);
+
+			return $data;
+		}
+
+		public function set_exceptions($data = array())
+		{
+			if(!isset($data['event_id']) || !$data['event_id'])
+			{
+					throw new Exception("property_boevent::set_exceptions - Missing event_id info in input");
+			}
+			$this->so->set_exceptions($data);
+		}
+	}


Property changes on: people/sigurdne/modules/property/trunk/inc/class.boevent.inc.php
___________________________________________________________________
Added: svn:keywords
   + Id Revision
Added: svn:eol-style
   + native

Modified: people/sigurdne/modules/property/trunk/inc/class.bofiles.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bofiles.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bofiles.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -8,13 +8,13 @@
 	 * @package phpgroupware
 	 * @subpackage property
 	 * @category core
- 	 * @version $Id: class.botts.inc.php 836 2008-03-15 14:39:28Z sigurd $
+ 	 * @version $Id: class.bofiles.inc.php 4058 2009-11-06 14:50:54Z sigurd $
 	 */
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -61,6 +61,21 @@
 		}
 
 		/**
+		 * Set the account id used for cron jobs where there is no user-session
+		 *
+		 * @param integer $account_id the account id to use - 0 = current user
+		 *
+		 * @return null
+		 */
+		public function set_account_id($account_id = 0)
+		{
+			if($account_id)
+			{
+				$this->vfs->working_id = $account_id;
+			}
+		}
+
+		/**
 		* Create catalog - starting with fakebase
 		*
 		* @param string $type part of path pointing to end target
@@ -179,7 +194,7 @@
 		* @return null
 		*/
 
-		function view_file($type = '', $file = '')
+		function view_file($type = '', $file = '', $jasper = '')
 		{
 			$GLOBALS['phpgw_info']['flags']['noheader'] = true;
 			$GLOBALS['phpgw_info']['flags']['nofooter'] = true;
@@ -187,10 +202,15 @@
 
 			if(!$file)
 			{
-				$file_name = realpath(urldecode(phpgw::get_var('file_name')));
-				$id        = phpgw::get_var('id', 'int');
+				$file_name = urldecode(phpgw::get_var('file_name'));
+				$id        = phpgw::get_var('id');
 				$file      = "{$this->fakebase}/{$type}/{$id}/{$file_name}";
 			}
+			// prevent path traversal
+			if ( preg_match('/\.\./', $file) )
+			{
+				return false;
+			}
 
 			if($this->vfs->file_exists(array(
 				'string' => $file,
@@ -204,6 +224,10 @@
 						'nofiles'		=> true
 					));
 
+				$browser = CreateObject('phpgwapi.browser');
+
+				if(!$jasper)
+				{
 				$this->vfs->override_acl = 1;
 
 				$document = $this->vfs->read(array(
@@ -212,11 +236,55 @@
 
 				$this->vfs->override_acl = 0;
 
-				$browser = CreateObject('phpgwapi.browser');
 				$browser->content_header($ls_array[0]['name'],$ls_array[0]['mime_type'],$ls_array[0]['size']);
-
 				echo $document;
 			}
+				else //Execute the jasper report
+				{
+					//class_path
+				//	$dirname = PHPGW_API_INC . '/jasper/lib';
+					$dirname = 'phpgwapi/inc/jasper/lib';
+					$file_list = array();
+				//	$file_list[] = PHPGW_API_INC . '/jasper/bin';
+					$file_list[] = 'phpgwapi/inc/jasper/bin';
+					$dir = new DirectoryIterator($dirname); 
+					if ( is_object($dir) )
+					{
+						foreach ( $dir as $_file )
+						{
+							if ( $_file->isDot()
+								|| !$_file->isFile()
+								|| !$_file->isReadable()
+								|| mime_content_type($_file->getPathname()) == 'text/xml')
+							{
+								continue;
+							}
+
+							$file_list[] = (string) "{$dirname}/{$_file}";
+						}
+					}
+					
+					if (stristr(PHP_OS, 'WIN')) 
+					{ 
+						$sep = ';';// Win 
+					}
+					else
+					{ 
+						$sep = ':';// Other
+					}
+
+					$class_path = implode($sep, $file_list);
+					$type = 'pdf';
+					$select_criteria = '//Record';
+					$template = "{$this->rootdir}/{$file}";
+
+					$cmd = "java -Djava.awt.headless=true -cp {$class_path} XmlJasperInterface -o{$type} -f{$template} -x{$select_criteria} < " . PHPGW_SERVER_ROOT . "/catch/test_data/jasper/tilstand.xml";
+
+					$browser->content_header('report.pdf','application/pdf');
+
+					passthru($cmd);
+				}
+			}
 		}
 
 		/**
@@ -231,7 +299,7 @@
 		{
 			$attachments = array();
 
-			foreach ($values['file_action'] as $file_name)
+			foreach ($values as $file_name)
 			{
 				$file = "{$this->fakebase}{$path}{$file_name}";
 

Modified: people/sigurdne/modules/property/trunk/inc/class.bogab.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bogab.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bogab.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -52,15 +52,9 @@
 
 		function property_bogab($session=false)
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
-			$this->bocommon 	= CreateObject('property.bocommon');
 			$this->solocation 	= CreateObject('property.solocation');
-			$this->config		= CreateObject('phpgwapi.config');
-			$this->config->read_repository();
-			$this->gab_insert_level = (isset($this->config->config_data['gab_insert_level'])?$this->config->config_data['gab_insert_level']:3);
+			$this->so 		= CreateObject('property.sogab');
 
-			$this->so 		= CreateObject('property.sogab',$this->gab_insert_level);
-
 			if ($session)
 			{
 				$this->read_sessiondata();
@@ -135,7 +129,7 @@
 		}
 
 
-		function read($loc1='',$gaards_nr='',$bruksnr='',$feste_nr='',$seksjons_nr='',$address='',$check_payments = '',$allrows='')
+		function read($location_code='',$gaards_nr='',$bruksnr='',$feste_nr='',$seksjons_nr='',$address='',$check_payments = '',$allrows='')
 		{
 			if($allrows)
 			{
@@ -143,7 +137,7 @@
 			}
 
 			$gab = $this->so->read(array('start' => $this->start,'sort' => $this->sort,'order' => $this->order,'allrows'=>$this->allrows,
-											'cat_id' => $this->cat_id,'loc1' => $loc1,
+											'cat_id' => $this->cat_id,'location_code' => $location_code,
 											'gaards_nr' => $gaards_nr,'bruksnr' => $bruksnr,'feste_nr' => $feste_nr,
 											'seksjons_nr' => $seksjons_nr,'address' => $address,'check_payments' => $check_payments));
 			$this->total_records = $this->so->total_records;
@@ -151,10 +145,11 @@
 			return $gab;
 		}
 
-		function read_detail($gab_id='')
+		//[email protected] $allrows - variable to display all records
+		function read_detail($gab_id='', $allrows=0)
 		{
 			$gab = $this->so->read_detail(array('start' => $this->start,'sort' => $this->sort,'order' => $this->order,
-											'cat_id' => $this->cat_id,'gab_id' => $gab_id,'allrows'=>$this->allrows));
+											'cat_id' => $this->cat_id,'gab_id' => $gab_id,'allrows'=>$allrows));
 			$this->total_records = $this->so->total_records;
 
 			$this->uicols	= $this->so->uicols;

Modified: people/sigurdne/modules/property/trunk/inc/class.boifc.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boifc.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boifc.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -283,10 +283,10 @@
 					continue;
 				}
 
-				$file = PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+				$file = PHPGW_SERVER_ROOT . "/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
 				if ( $entry['active'] && is_file($file) )
 				{
-					require_once PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+					require_once $file;
 				}
 			}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boinvestment.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boinvestment.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boinvestment.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -285,10 +285,11 @@
 
 			$new_index=str_replace(",",".",$values['new_index']);
 
-			while($entry=each($values['update']))
+			$update = array();
+			foreach($values['update'] as $entry)
 			{
-				$local_error='';
-				$n=$entry[0];
+				$local_error = false;
+				$n = $entry;
 
 				if ($values['value'][$n])
 				{
@@ -312,7 +313,7 @@
 						);
 				}
 			}
-			$this->so->update_investment($update);
+			return $this->so->update_investment($update);
 		}
 
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boinvoice.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boinvoice.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boinvoice.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -56,56 +56,19 @@
 			$allrows		= phpgw::get_var('allrows', 'bool');
 			$b_account_class	= phpgw::get_var('b_account_class', 'int');
 			$district_id		= phpgw::get_var('district_id', 'int');
+			$b_account				= phpgw::get_var('b_account');
 
-
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(isset($district_id))
-			{
-				$this->district_id = $district_id;
-			}
-
-			if(isset($b_account_class))
-			{
-				$this->b_account_class = $b_account_class;
-			}
-
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-
-			if(!empty($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(isset($user_lid))
-			{
-				$this->user_lid = $user_lid;
-			}
-			if(isset($allrows))
-			{
-				$this->allrows = $allrows;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->b_account		= isset($b_account) ? $b_account : $b_account;
+			$this->district_id		= isset($district_id) ? $district_id : $district_id;
+			$this->b_account_class	= isset($b_account_class) ? $b_account_class : $b_account_class;
+			$this->query			= isset($query) ? $query : $query;
+			$this->filter			= isset($filter) ? $filter : $filter;
+			$this->sort				= isset($sort) ? $sort : $sort;
+			$this->order			= isset($order) ? $order : $order;
+			$this->cat_id			= isset($cat_id) ? $cat_id : $cat_id;
+			$this->user_lid			= isset($user_lid) ? $user_lid : $user_lid;
+			$this->allrows			= isset($allrows) ? $allrows : $allrows;
 		}
 
 
@@ -138,6 +101,9 @@
 
 		function read_invoice($paid='',$start_date='',$end_date='',$vendor_id='',$loc1='',$workorder_id='',$voucher_id='')
 		{
+			$start_date	= $this->bocommon->date_to_timestamp($start_date);
+			$end_date	= $this->bocommon->date_to_timestamp($end_date);
+			
 			$invoice = $this->so->read_invoice(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'user_lid' => $this->user_lid,'cat_id' => $this->cat_id, 'paid' => $paid,
 											'start_date'=>$start_date,'end_date'=>$end_date,'vendor_id'=>$vendor_id,
@@ -170,11 +136,14 @@
 
 		function read_consume($start_date='',$end_date='',$vendor_id='',$loc1='',$workorder_id='',$b_account_class='',$district_id='')
 		{
+			$start_date	= $this->bocommon->date_to_timestamp($start_date);
+			$end_date	= $this->bocommon->date_to_timestamp($end_date);
+
 			$invoice = $this->so->read_consume(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'user_lid' => $this->user_lid,'cat_id' => $this->cat_id,
 											'start_date'=>$start_date,'end_date'=>$end_date,'vendor_id'=>$vendor_id,
 											'loc1'=>$loc1,'workorder_id'=>$workorder_id,'b_account_class' =>$b_account_class,
-											'district_id' => $district_id ));
+											'district_id' => $district_id, 'b_account' => $this->b_account ));
 
 			$this->total_records = $this->so->total_records;
 
@@ -307,7 +276,7 @@
 					$GLOBALS['phpgw']->xslttpl->add_file(array('user_lid_filter'));
 					break;
 			}
-			$users=$this->bocommon->get_user_list_right(1,$selected,'.invoice',$extra,$default);
+			$users=$this->bocommon->get_user_list_right(array(32, 64, 128),$selected,'.invoice',$extra,$default);
 			return $users;
 		}
 
@@ -357,15 +326,12 @@
 				$values['dima']=implode('',$values['location']);
 			}
 
-			$values['spbudact_code']=$values['b_account_id'];
-			$values['fakturanr']=$values['invoice_num'];
-			$values['spvend_code']=$values['vendor_id'];
+			$values['spbudact_code']	= $values['b_account_id'];
+			$values['fakturanr']		= $values['invoice_num'];
+			$values['spvend_code']		= $values['vendor_id'];
+			$values['belop'] 			= $values['amount'];
+			$values['godkjentbelop']	= $values['amount'];
 
-			$values['belop'] = str_replace('kr','',$values['amount']);
-			$values['belop'] = str_replace(' ','',$values['belop']);
-			$values['belop'] = str_replace(',','.',$values['belop']);
-			$values['godkjentbelop']=$values['belop'];
-
 			$values['fakturadato'] = date($this->bocommon->dateformat,mktime(2,0,0,$values['smonth'],$values['sday'],$values['syear']));
 
 			if($values['num_days'])

Modified: people/sigurdne/modules/property/trunk/inc/class.bolocation.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bolocation.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bolocation.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -43,6 +43,8 @@
 		var $type_id;
 		var $lookup;
 		var $use_session;
+		var $location_code;
+		var $total_records;
 
 		/**
 		* @var object $custom reference to custom fields object
@@ -79,11 +81,10 @@
 
 		function property_bolocation($session=false)
 		{
-		//	$this->currentapp			= $GLOBALS['phpgw_info']['flags']['currentapp'];
-			$this->so 					= CreateObject('property.solocation');
+			$this->soadmin_location		= CreateObject('property.soadmin_location');
 			$this->bocommon 			= CreateObject('property.bocommon');
-			$this->soadmin_location		= CreateObject('property.soadmin_location');
-			$this->custom 				= createObject('property.custom_fields');
+			$this->so 					= CreateObject('property.solocation', $this->bocommon);
+			$this->custom 				= & $this->so->custom;
 
 			$this->lookup    = phpgw::get_var('lookup', 'bool');
 
@@ -105,6 +106,7 @@
 			$status					= phpgw::get_var('status');
 			$type_id				= phpgw::get_var('type_id', 'int');
 			$allrows				= phpgw::get_var('allrows', 'bool');
+			$location_code			= phpgw::get_var('location_code');
 
 			$this->start			= $start ? $start : 0;
 			$this->query			= isset($query) ? $query : $this->query;
@@ -118,12 +120,23 @@
 			$this->type_id			= isset($type_id) && $type_id ? $type_id : 1;
 			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
 			$this->acl_location		= '.location.' . $this->type_id;
+			$this->location_code	= isset($location_code) && $location_code ? $location_code : '';
+			
+			if(isset($_REQUEST['query']) && !$query && !isset($_REQUEST['block_query']))
+			{
+				$this->location_code = '';
+			}
 		}
 
 		function read_sessiondata()
 		{
 			$referer = parse_url(phpgw::get_var('HTTP_REFERER', 'string', 'SERVER') );
+			//[email protected] validation evita NOTICE  for JSON
+			$referer_out = array();
+			if(isset($referer['query']) && is_array($referer['query'])) {
 			parse_str($referer['query'],$referer_out);
+			}
+			$self_out = array();
 			$self = parse_url(phpgw::get_var('QUERY_STRING', 'string', 'SERVER') );
 			parse_str($self['path'],$self_out);
 
@@ -173,13 +186,14 @@
 			}
 		}
 
-		function column_list($selected='',$type_id='',$allrows='')
+		function column_list($selected = array(),$type_id='',$allrows='')
 		{
 			if(!$selected)
 			{
 				$selected = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['location_columns_' . $this->type_id . !!$this->lookup]) ? $GLOBALS['phpgw_info']['user']['preferences']['property']["location_columns_" . $this->type_id . !!$this->lookup]:'';
 			}
-			$columns = $this->custom->find('property','.location.' . $type_id, 0, '','','',true);
+			$filter = array('list' => ''); // translates to "list IS NULL"
+			$columns = $this->custom->find('property','.location.' . $type_id, 0, '','','',true, false, $filter);
 			$column_list=$this->bocommon->select_multi_list($selected,$columns);
 			return $column_list;
 		}
@@ -244,6 +258,13 @@
 
 		function initiate_ui_location($data)
 		{
+			$config		= CreateObject('phpgwapi.config','property');
+			$config->read();
+			if (isset($config->config_data['suppress_tenant']) &&  $config->config_data['suppress_tenant'])
+			{
+				$data['tenant'] = false;
+			}
+			unset($config);
 
 			if(isset($data['lookup_type']))
 			{
@@ -258,7 +279,9 @@
 				}
 			}
 
-			$location_link		= "menuaction:'". 'property'.".uilocation.index',lookup:1";
+			$filter_location	= isset($data['filter_location']) ? $data['filter_location'] : '';
+			$block_query 		= !!$filter_location;
+			$location_link		= "menuaction:'property.uilocation.index',lookup:1,location_code:'{$filter_location}',block_query:'{$block_query}'";
 
 			$config = $this->soadmin_location->read_config('');
 
@@ -271,13 +294,20 @@
 			{
 				$data['type_id'] = count($location_types);
 			}
-//_debug_array($data);
+//_debug_array($data);die();
 //_debug_array($location_types);
-//			$filtermethod = " OR (type_id < $lookup_type AND lookup_form=1)";
-			$filtermethod = " OR (lookup_form=1)";
-			$fm_location_cols = $this->custom->find('property', '.location.' . $data['type_id'], 0, '', '', '', true,$filtermethod);
+			$fm_location_cols = array();
+			for ($i=1;$i<($data['type_id']+1);$i++)
+			{
+				$fm_location_cols_temp = $this->custom->find('property', '.location.' . $i, 0, '', '', '', true);
+				foreach ($fm_location_cols_temp as & $entry)
+				{
+					$entry['location_type']=$i;
+				}
+				$fm_location_cols = array_merge($fm_location_cols, $fm_location_cols_temp);
+			}
+			unset($fm_location_cols_temp);
 
-
 //_debug_array($fm_location_cols);
 
 			for ($i=0;$i<$data['type_id'];$i++)
@@ -311,17 +341,24 @@
 				}
 
 				$location['location'][$i]['lookup_function_call']			= 'lookup_loc' . ($i+1) . '()';
-				$location['location'][$i]['lookup_link']				= true;
 				$location['location'][$i]['readonly']					= true;
-				$lookup_functions[$i]['name'] 						= 'lookup_loc' . ($i+1) . '()';
-				$lookup_functions[$i]['link']						=  $location_link .',type_id:' . ($i+1) . ',lookup_name:' . $i;
-				$lookup_functions[$i]['action'] 					= 'Window1=window.open(strURL,"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+				
+				if(!isset($data['block_parent']) || $data['block_parent'] < ($i+1))
+				{
+					$location['location'][$i]['lookup_link']				= true;
+					$lookup_functions[] = array
+					(
+						'name' 						=> 'lookup_loc' . ($i+1) . '()',
+						'link'						=>  $location_link .',type_id:' . ($i+1) . ',lookup_name:' . $i,
+						'action' 					=> 'Window1=window.open(strURL,"Search","width=1000,height=700,toolbar=no,scrollbars=yes,resizable=yes");'
+					);
+				}
 
 				if(isset($data['no_link']) && $data['no_link']>=($i+3))
 				{
 					$location['location'][$i]['lookup_link']			= false;
 					$lookup_functions[$i]['link'] 					= $location_link .',type_id:' . ($data['no_link']-1) . ',lookup_name:' . ($data['no_link']-2);
-					$lookup_functions[$i]['action'] 				= 'Window1=window.open(strURL,"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+					$lookup_functions[$i]['action'] 				= 'Window1=window.open(strURL,"Search","width=1000,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
 					$location['location'][$i]['statustext']				= lang('click this link to select') . ' ' . $location_types[($data['no_link']-2)]['name'];
 				}
 
@@ -346,7 +383,6 @@
 			$location_cols_count =count($fm_location_cols);
 			for ($j=0;$j<$location_cols_count;$j++)
 			{
-				//FIXME: location_type is currently empty - should'nt be...
 				if((isset($fm_location_cols[$j]['location_type']) && $fm_location_cols[$j]['location_type'] <= $data['type_id']) && $fm_location_cols[$j]['lookup_form'])
 				{
 					$location['location'][$i]['input_type']				= 'text';
@@ -399,9 +435,12 @@
 					elseif($config[$j]['column_name']=='tenant_id' && $data['tenant']):
 					{
 						$m++;
-						$lookup_functions[$m]['name'] 						= 'lookup_loc' . ($m+1) . '()';
-						$lookup_functions[$m]['link']						= $location_link .',lookup_tenant:1,type_id:' . $config[$j]['location_type'] . ',lookup_name:' . $i;
-						$lookup_functions[$m]['action'] 					= 'Window1=window.open(strURL,"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+						$lookup_functions[] = array
+						(
+							'name' 						=> 'lookup_loc' . ($m+1) . '()',
+							'link'						=> $location_link .',lookup_tenant:1,type_id:' . $config[$j]['location_type'] . ',lookup_name:' . $i,
+							'action' 					=> 'Window1=window.open(strURL,"Search","width=1600,height=700,toolbar=no,scrollbars=yes,resizable=yes");'
+						);
 
 						$location['location'][$i]['lookup_link']			= true;
 						$location['location'][$i]['name']					= lang('Tenant');
@@ -409,7 +448,7 @@
 						$location['location'][$i]['input_name']				= 'tenant_id';
 						$input_name[]										= $location['location'][$i]['input_name'];
 						$location['location'][$i]['value']					= (isset($data['values'][$config[$j]['column_name']])?$data['values'][$config[$j]['column_name']]:'');
-						$location['location'][$i]['lookup_function_call']	= $lookup_functions[$m]['name'];
+						$location['location'][$i]['lookup_function_call']	= 'lookup_loc' . ($m+1) . '()';
 						$location['location'][$i]['statustext']				= lang('tenant');
 						$insert_record['extra']['tenant_id']				= 'tenant_id';
 
@@ -418,7 +457,7 @@
 						$location['location'][$i]['extra'][0]['readonly']	= true;
 						$input_name[]										= $location['location'][$i]['extra'][0]['input_name'];
 						$location['location'][$i]['extra'][0]['size']		= 15;
-						$location['location'][$i]['extra'][0]['lookup_function_call']	= $lookup_functions[$m]['name'];
+						$location['location'][$i]['extra'][0]['lookup_function_call']	= 'lookup_loc' . ($m+1) . '()';
 						$location['location'][$i]['extra'][0]['value']		= (isset($data['values']['last_name'])?$data['values']['last_name']:'');
 						$location['location'][$i]['extra'][0]['statustext']	= lang('last name');
 
@@ -427,7 +466,7 @@
 						$location['location'][$i]['extra'][1]['readonly']	= true;
 						$input_name[]										= $location['location'][$i]['extra'][1]['input_name'];
 						$location['location'][$i]['extra'][1]['size']		= 15;
-						$location['location'][$i]['extra'][1]['lookup_function_call']	= $lookup_functions[$m]['name'];
+						$location['location'][$i]['extra'][1]['lookup_function_call']	= 'lookup_loc' . ($m+1) . '()';
 						$location['location'][$i]['extra'][1]['value']		= (isset($data['values']['first_name'])?$data['values']['first_name']:'');
 						$location['location'][$i]['extra'][1]['statustext']	= lang('first name');
 						$i++;
@@ -467,9 +506,12 @@
 				{
 					$m++;
 
-					$lookup_functions[$m]['name'] = 'lookup_entity_' . $entity['id'] .'()';
-					$lookup_functions[$m]['link'] = "menuaction:'". 'property'.".uilookup.entity',location_type:".$data['type_id'] . ',entity_id:'. $entity['id'];
-					$lookup_functions[$m]['action'] = 'Window1=window.open(strURL,"Search","width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");';
+					$lookup_functions[] = array
+					(
+						'name'		=> 'lookup_entity_' . $entity['id'] .'()',
+						'link'		=> "menuaction:'property.uilookup.entity',location_type:{$data['type_id']},entity_id:{$entity['id']},location_code:'{$filter_location}',block_query:'{$block_query}'",
+						'action'	=> 'Window1=window.open(strURL,"Search","width=1200,height=700,toolbar=no,scrollbars=yes,resizable=yes");'
+					);
 
 					$location['location'][$i]['input_type']						= 'text';
 					$location['location'][$i]['input_name']						= 'entity_num_' . $entity['id'];
@@ -566,15 +608,27 @@
 											'filter' => $this->filter,'cat_id' => $this->cat_id,'type_id' => $data['type_id'],
 											'lookup_tenant'=>$data['lookup_tenant'],'lookup'=>$data['lookup'],
 											'district_id'=>$this->district_id,'allrows'=>$data['allrows'],
-											'status'=>$this->status,'part_of_town_id'=>$this->part_of_town_id));
+											'status'=>$this->status,'part_of_town_id'=>$this->part_of_town_id,'dry_run'=>$data['dry_run'],
+											'location_code' => $this->location_code));
+
 			$this->total_records = $this->so->total_records;
 			$this->uicols = $this->so->uicols;
 
 			return $location;
 		}
 
-		function read_single($location_code='',$extra=array())
+		function read_single($data='',$extra=array())
 		{
+			if(is_array($data))
+			{
+				$location_code	= $data['location_code'];
+				$extra 			= $data['extra'];
+			}
+			else
+			{
+				$location_code = $data;
+			}
+
 			$location_array = split('-',$location_code);
 			$type_id= count($location_array);
 
@@ -583,9 +637,17 @@
 				return;
 			}
 
+			if(!isset($extra['noattrib']) || !$extra['noattrib'])
+			{
 			$values['attributes'] = $this->custom->find('property','.location.' . $type_id, 0, '', 'ASC', 'attrib_sort', true, true);
 			$values = $this->so->read_single($location_code, $values);
-			$values = $this->custom->prepare($values, 'property','.location.' . $type_id, $extra['view']);
+				$values = $this->custom->prepare($values, 'property',".location.{$type_id}", $extra['view']);
+			}
+			else
+			{
+				$values = $this->so->read_single($location_code);
+			}
+			
 
 			if( isset($extra['tenant_id']) && $extra['tenant_id']!='lookup')
 			{
@@ -648,7 +710,20 @@
 			return $this->so->check_location($location_code,$type_id);
 		}
 
+		/**
+		* Arrange attributes within groups
+		*
+		* @param string  $location    the name of the location of the attribute
+		* @param array   $attributes  the array of the attributes to be grouped
+		*
+		* @return array the grouped attributes
+		*/
 
+		public function get_attribute_groups($location, $attributes = array())
+		{
+			return $this->custom->get_attribute_groups('property', $location, $attributes);
+		}
+
 		function save($location,$values_attribute,$action='',$type_id='',$location_code_parent='')
 		{
 			if(is_array($values_attribute))
@@ -692,25 +767,37 @@
 					continue;
 				}
 
-				$file = PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+				$file = PHPGW_SERVER_ROOT . "/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
 				if ( $entry['active'] && is_file($file) )
 				{
-					require_once PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+					require_once $file;
 				}
 			}
 
 			return $receipt;
 		}
 
-		function delete($location_code)
+		/*function delete2($location_code)
 		{
 			$this->so->delete($location_code);
+		}*/
+
+		function delete()
+		{
+			$location_code = phpgw::get_var('location_code','string','GET');
+			$this->so->delete($location_code);
 		}
 
 		function update_cat()
 		{
 			return $this->so->update_cat();
 		}
+
+		function update_location()
+		{
+			return $this->so->update_location();
+		}
+
 		function read_summary($data=array())
 		{
 			$summary = $this->so->read_summary(array('filter' => $this->filter,'type_id' => isset($data['type_id'])?$data['type_id']:'',

Modified: people/sigurdne/modules/property/trunk/inc/class.bolookup.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bolookup.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bolookup.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -60,40 +60,16 @@
 			$filter			= phpgw::get_var('filter', 'int');
 			$cat_id			= phpgw::get_var('cat_id', 'int');
 			$district_id	= phpgw::get_var('district_id', 'int');
+			$allrows	= phpgw::get_var('allrows', 'bool');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(!empty($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(isset($district_id))
-			{
-				$this->district_id = $district_id;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->filter			= isset($filter) && $filter ? $filter : '';
+			$this->district_id		= isset($district_id) && $district_id ? $district_id : '';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
 		}
 
 		function save_sessiondata($data)
@@ -198,14 +174,10 @@
 			return $persons;
 		}
 
-
-
-
-
 		function read_vendor()
 		{
 			$vendor = $this->so->read_vendor(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'filter' => $this->filter,'cat_id' => $this->cat_id));
+											'filter' => $this->filter,'cat_id' => $this->cat_id, 'allrows' => $this->allrows));
 			$this->total_records = $this->so->total_records;
 
 			return $vendor;
@@ -214,7 +186,7 @@
 		function read_b_account()
 		{
 			$b_account = $this->so->read_b_account(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'filter' => $this->filter,'cat_id' => $this->cat_id));
+											'filter' => $this->filter,'cat_id' => $this->cat_id, 'allrows' => $this->allrows));
 			$this->total_records = $this->so->total_records;
 
 			return $b_account;
@@ -223,7 +195,7 @@
 		function read_street()
 		{
 			$street = $this->so->read_street(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'filter' => $this->filter,'cat_id' => $this->cat_id));
+											'filter' => $this->filter,'cat_id' => $this->cat_id, 'allrows' => $this->allrows));
 			$this->total_records = $this->so->total_records;
 
 			return $street;
@@ -232,7 +204,7 @@
 		function read_tenant()
 		{
 			$tenant = $this->so->read_tenant(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'filter' => $this->filter,'cat_id' => $this->cat_id));
+											'filter' => $this->filter,'cat_id' => $this->cat_id, 'allrows' => $this->allrows));
 			$this->total_records = $this->so->total_records;
 
 			return $tenant;
@@ -255,5 +227,27 @@
 
 			return $phpgw_user;
 		}
+
+		function read_project_group()
+		{
+			$project_group	= CreateObject('property.socategory');
+			$project_group->get_location_info('project_group',false);
+			$values = $project_group->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
+											'type' => 'project_group','allrows'=>$this->allrows));
+
+			$this->total_records = $project_group->total_records;
+
+			return $values;
 	}
+		function read_ecodimb()
+		{
+			$ecodimb	= CreateObject('property.socategory');
+			$ecodimb->get_location_info('dimb',false);
+			$values = $ecodimb->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
+											'allrows'=>$this->allrows));
 
+			$this->total_records = $ecodimb->total_records;
+
+			return $values;
+		}
+	}

Modified: people/sigurdne/modules/property/trunk/inc/class.bomigrate.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bomigrate.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bomigrate.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -8,13 +8,13 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage admin
- 	* @version $Id: class.uimigrate.inc.php 732 2008-02-10 16:21:14Z sigurd $
+ 	* @version $Id: class.bomigrate.inc.php 2588 2009-04-14 11:00:02Z sigurd $
 	*/
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -78,8 +78,9 @@
 			return $domain_info;
 		}
 
-		public function migrate($values,$download_script=true)
+		public function migrate($values,$download_script=false)
 		{
+//_debug_array($GLOBALS['phpgw_domain']);die();
 //			_debug_array($values);
 			$oProc							= createObject('phpgwapi.schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
 			$oProc->m_odb					= $GLOBALS['phpgw']->db;
@@ -88,15 +89,7 @@
 
 			$tables = $GLOBALS['phpgw']->db->table_names();
 
-			/* Work out the order of how the tables can be created
-			*/
-			foreach($tables as $tablename)
-			{
-				$ForeignKeys = $GLOBALS['phpgw']->db->MetaForeignKeys($tablename);
-				foreach($ForeignKeys as $table => $keys)
-				{
-				}
-			}
+//			$tables = array('fm_entity_history');
 
 			$setup = createObject('phpgwapi.setup_process');
 
@@ -104,6 +97,8 @@
 			foreach($tables as $table)
 			{
 				$tableinfo = $setup->sql_to_array($table);
+//_debug_array($tableinfo);
+
 				$fd_temp = '$fd = array(' . str_replace("\t",'',$tableinfo[0]) .');';
 				@eval($fd_temp);
 				$table_def[$table]['fd'] = $fd;
@@ -111,16 +106,30 @@
 				$table_def[$table]['fk'] = $tableinfo[2];
 				$table_def[$table]['ix'] = $tableinfo[3];
 				$table_def[$table]['uc'] = $tableinfo[4];
+//_debug_array($table_def);
+//die();
+				/* Work out the order of how the tables can be created
+				*/
+				if($tableinfo[2])
+				{
+					foreach ($tableinfo[2] as $ref_set => $ref_fields)
+					{
+						$fk_temp = '$fk = array(' . $ref_fields .');';
+						@eval($fk_temp);
+						$fk_table = array_keys($fk);
+						$ForeignKeys[$table][] = $fk_table[0];
+					}
+				}
 			}
-//_debug_array($table_def);
-//_debug_array($tables);
 
+			set_time_limit(0);
 			foreach ($values as $domain)
 			{
 				$this->oProc = createObject('phpgwapi.schema_proc',$GLOBALS['phpgw_domain'][$domain]['db_type']);
 				if(!$download_script)
 				{
-					$this->oProc->m_odb           = $GLOBALS['phpgw']->db;
+					$this->oProc->m_odb           = CreateObject('phpgwapi.db');//$GLOBALS['phpgw']->db;
+					$this->oProc->m_odb->Type     = $GLOBALS['phpgw_domain'][$domain]['db_type'];
 					$this->oProc->m_odb->Host     = $GLOBALS['phpgw_domain'][$domain]['db_host'];
 					$this->oProc->m_odb->Database = $GLOBALS['phpgw_domain'][$domain]['db_name'];
 					$this->oProc->m_odb->User     = $GLOBALS['phpgw_domain'][$domain]['db_user'];
@@ -129,16 +138,87 @@
 					$this->oProc->m_odb->connect();
 				}
 
-				$filename = $domain . '_' . $GLOBALS['phpgw_domain'][$domain]['db_name'] . '_' . $GLOBALS['phpgw_domain'][$domain]['db_type'] . '.sql';
-
-				$script = $this->GenerateScripts($table_def, false, true);
 				if($download_script)
 				{
+					$script = $this->GenerateScripts($table_def, false, true);
+					$filename = $domain . '_' . $GLOBALS['phpgw_domain'][$domain]['db_name'] . '_' . $GLOBALS['phpgw_domain'][$domain]['db_type'] . '.sql';
 					$this->download_script($script, $filename);
 				}
+				else
+				{
+					$this->oProc->ExecuteScripts($table_def, true);
+					$this->copy_data($table_def);
+				}
 			}
 		}
 
+		
+		function copy_data($table_def = array())
+		{
+			$db = $GLOBALS['phpgw']->db;
+			$db->fetchmode = 'ASSOC';
+			foreach ($table_def as $table => $fd)
+			{
+				if($table=='fm_ecobilagoverf' || $table== 'phpgw_lang')
+				{
+					continue;
+				}
+				switch ($table)
+				{
+					case 'fm_document_history':
+					case 'fm_entity_history':
+					case 'fm_request_history':
+					case 'fm_project_history':
+					case 'fm_tts_history':
+					case 'fm_s_agreement_history':
+					case 'fm_workorder_history':
+					case 'phpgw_history_log':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET history_new_value = 'NIL' WHERE history_new_value = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'fm_project':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET name = 'NIL' WHERE name = ''", __LINE__ , __FILE__, true);
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET loc1 = '0000', location_code = '0000' WHERE loc1 = ''", __LINE__ , __FILE__, true);
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET status = 'closed' WHERE status = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'fm_workorder':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET title = 'NIL' WHERE title = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'fm_ecodimd':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET descr = 'NIL' WHERE descr = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'phpgw_categories':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET cat_description = 'NIL' WHERE cat_description = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'phpgw_contact_others':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET other_value = 'NIL' WHERE other_value = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'phpgw_contact_person':
+						$GLOBALS['phpgw']->db->query("DELETE FROM {$table} WHERE first_name = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'phpgw_log_msg':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET log_msg_parms = 'NIL' WHERE log_msg_parms = ''", __LINE__ , __FILE__, true);
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET log_msg_file = 'NIL' WHERE log_msg_file = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'phpgw_sms_tbluserphonebook':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET p_email = 'NIL' WHERE p_email = ''", __LINE__ , __FILE__, true);
+						break;
+					case 'phpgw_sms_tblsmsoutgoing':
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET p_footer = 'NIL' WHERE p_footer = ''", __LINE__ , __FILE__, true);
+						$GLOBALS['phpgw']->db->query("UPDATE {$table} SET p_src = 'NIL' WHERE p_src = ''", __LINE__ , __FILE__, true);
+						break;
+					default:
+				}
+
+				$db->query("SELECT * FROM {$table}");
+				foreach($db->resultSet as $row)
+				{
+					$insert_values = $db->validate_insert(array_values($row));
+					$insert_fields = implode(',', array_keys($row));
+					$this->oProc->m_odb->query("INSERT INTO {$table} ({$insert_fields}) VALUES ({$insert_values})");	
+				}
+			}
+		}
+
 		private function download_script($script, $filename)
 		{
 			$GLOBALS['phpgw_info']['flags']['noheader'] = true;

Modified: people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -52,14 +52,13 @@
 
 		function property_boproject($session=false)
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->so 			= CreateObject('property.soproject');
-			$this->bocommon 	= CreateObject('property.bocommon');
-			$this->solocation = CreateObject('property.solocation');
+			$this->bocommon 			= & $this->so->bocommon;
 			$this->cats					= CreateObject('phpgwapi.categories');
 			$this->cats->app_name		= 'property.project';
 			$this->cats->supress_info	= true;
-			$this->interlink 	= CreateObject('property.interlink');
+			$this->interlink 			= & $this->so->interlink;
+			$this->custom 				= & $this->so->custom;
 
 			if ($session)
 			{
@@ -74,45 +73,22 @@
 			$filter	= phpgw::get_var('filter', 'int');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
 			$status_id	= phpgw::get_var('status_id');
+			$user_id	= phpgw::get_var('user_id', 'int');
 			$wo_hour_cat_id	= phpgw::get_var('wo_hour_cat_id', 'int');
+			$district_id	= phpgw::get_var('district_id', 'int');
+			$criteria_id	= phpgw::get_var('criteria_id', 'int');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(isset($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(isset($status_id))
-			{
-				$this->status_id = $status_id;
-			}
-			if(isset($wo_hour_cat_id))
-			{
-				$this->wo_hour_cat_id = $wo_hour_cat_id;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->filter			= isset($filter) && $filter ? $filter : '';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->status_id		= isset($status_id) && $status_id ? $status_id : '';
+			$this->user_id			= isset($user_id) && $user_id ? $user_id : '';
+			$this->wo_hour_cat_id	= isset($wo_hour_cat_id) && $wo_hour_cat_id ? $wo_hour_cat_id : '';
+			$this->district_id		= isset($district_id) && $district_id ? $district_id : '';
+			$this->criteria_id		= isset($criteria_id) && $criteria_id ? $criteria_id : '';
 		}
 
 		function save_sessiondata($data)
@@ -134,7 +110,10 @@
 			$this->order			= isset($data['order'])?$data['order']:'';
 			$this->cat_id			= isset($data['cat_id'])?$data['cat_id']:'';
 			$this->status_id		= isset($data['status_id'])?$data['status_id']:'';
+			$this->user_id			= isset($data['user_id'])?$data['user_id']:'';
 			$this->wo_hour_cat_id	= isset($data['wo_hour_cat_id'])?$data['wo_hour_cat_id']:'';
+			$this->district_id		= isset($data['district_id'])?$data['district_id']:'';
+			$this->criteria_id		= isset($data['criteria_id'])?$data['criteria_id']:'';
 		}
 
 		function select_status_list($format='',$selected='')
@@ -194,7 +173,94 @@
 			return $branch_list;
 		}
 
+		function get_criteria_list($selected='')
+		{
+			$criteria = array
+			(
+				array
+				(
+					'id'	=> '1',
+					'name'	=> lang('project group')
+				),
+				array
+				(
+					'id'	=> '2',
+					'name'	=> lang('project id')
+				),
+				array
+				(
+					'id'	=> '3',
+					'name'	=> lang('address')
+				),
+				array
+				(
+					'id'	=> '4',
+					'name'	=> lang('location code')
+				),
+				array
+				(
+					'id'	=> '5',
+					'name'	=> lang('title')
+				),
+			);
+			return $this->bocommon->select_list($selected,$criteria);
+		}
 
+
+		function get_criteria($id='')
+		{
+			$criteria = array();
+			$criteria[1] = array
+			(
+				'field'		=> 'project_group',
+				'type'		=> 'int',
+				'matchtype' => 'exact',
+				'front' => '',
+				'back' => ''
+			);
+			$criteria[2] = array
+			(
+				'field'		=> 'fm_project.id',
+				'type'		=> 'int',
+				'matchtype' => 'exact',
+				'front' => '',
+				'back' => ''
+			);
+			$criteria[3] = array
+			(
+				'field'	=> 'fm_project.address',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'%",
+				'back' => "%'",
+			);
+			$criteria[4] = array
+			(
+				'field'	=> 'fm_project.location_code',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'",
+				'back' => "%'"
+			);
+			$criteria[5] = array
+			(
+				'field'	=> 'fm_project.name',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'%",
+				'back' => "%'"
+			);
+
+			if($id)
+			{
+				return array($criteria[$id]);
+			}
+			else
+			{
+				return $criteria;
+			}			
+		}
+
 		function select_key_location_list($selected='')
 		{
 
@@ -203,51 +269,83 @@
 			return $this->bocommon->select_list($selected,$key_location_entries);
 		}
 
-		function read($start_date='',$end_date='',$allrows='')
+		function read($data = array())
 		{
-			$start_date	= $this->bocommon->date_to_timestamp($start_date);
-			$end_date	= $this->bocommon->date_to_timestamp($end_date);
+			$start_date	= $this->bocommon->date_to_timestamp($data['start_date']);
+			$end_date	= $this->bocommon->date_to_timestamp($data['end_date']);
 
 			$project = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'filter' => $this->filter,'cat_id' => $this->cat_id,'status_id' => $this->status_id,'wo_hour_cat_id' => $this->wo_hour_cat_id,
-											'start_date'=>$start_date,'end_date'=>$end_date,'allrows'=>$allrows));
+											'start_date'=>$start_date,'end_date'=>$end_date,'allrows'=>isset($data['allrows']) ? $data['allrows'] : '','dry_run' => $data['dry_run'],
+											'district_id' => $this->district_id, 'criteria' => $this->get_criteria($this->criteria_id)));
 			$this->total_records = $this->so->total_records;
 
 			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 
 			$this->uicols	= $this->so->uicols;
-			$this->uicols['input_type'][]	= 'link';
-			$this->uicols['name'][]			= 'ticket_id';
+			if(!isset($data['skip_origin']) || !$data['skip_origin'])
+			{
+				$this->uicols['input_type'][]	= 'text';
+				$this->uicols['name'][]			= 'ticket';
 			$this->uicols['descr'][]		= lang('ticket');
 			$this->uicols['statustext'][]	= false;
+				$this->uicols['exchange'][]		= false;
+				$this->uicols['align'][] 		= '';
+				$this->uicols['datatype'][]		= 'link';
+			}
 
 //			$cols_extra		= $this->so->cols_extra;
 
 			foreach ($project as & $entry)
 			{
 				$entry['start_date'] = $GLOBALS['phpgw']->common->show_date($entry['start_date'],$dateformat);
+				if(!isset($data['skip_origin']) || !$data['skip_origin'])
+				{
 				$origin = $this->interlink->get_relation('property', '.project', $entry['project_id'], 'origin');
-				if($origin[0]['location'] == '.ticket')
+					if(isset($origin[0]['location']) && $origin[0]['location'] == '.ticket')
 				{
-					$entry['ticket_id'] = $origin[0]['data'][0]['id'];
+						$entry['ticket'] = array
+										(
+											'url' 			=> $GLOBALS['phpgw']->link('/index.php', array
+																(
+																	'menuaction'	=> 'property.uitts.view',
+																	'id'			=> $origin[0]['data'][0]['id']
+																)
+															),
+											'text'			=> $origin[0]['data'][0]['id'],
+											'statustext'	=> $origin[0]['data'][0]['statustext'],											
+										);
+					}
 				}
 			}
 			return $project;
 		}
 
-		function read_single($project_id)
+		function read_single($project_id = 0, $values = array(), $view = false)
 		{
 			$contacts		= CreateObject('property.soactor');
 			$contacts->role='vendor';
 
-			$config				= CreateObject('phpgwapi.config');
-			$config->read_repository();
+			$config				= CreateObject('phpgwapi.config','property');
+			$config->read();
 			$tax = 1+(isset($config->config_data['fm_tax'])?$config->config_data['fm_tax']:0)/100;
 
-			$project				= $this->so->read_single($project_id);
+			$values['attributes'] = $this->custom->find('property', '.project', 0, '', 'ASC', 'attrib_sort', true, true);
+			if($project_id)
+			{
+				$values = $this->so->read_single($project_id, $values);
+			}
+
+			$values = $this->custom->prepare($values, 'property', '.project', $view);
+
+			if(!$project_id)
+			{
+				return $values;
+			}
+
 			$dateformat				= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-			$project['start_date']			= $GLOBALS['phpgw']->common->show_date($project['start_date'],$dateformat);
-			$project['end_date']			= isset($project['end_date']) && $project['end_date'] ? $GLOBALS['phpgw']->common->show_date($project['end_date'],$dateformat) : '';
+			$values['start_date']			= $GLOBALS['phpgw']->common->show_date($values['start_date'],$dateformat);
+			$values['end_date']			= isset($values['end_date']) && $values['end_date'] ? $GLOBALS['phpgw']->common->show_date($values['end_date'],$dateformat) : '';
 			$workorder_data				= $this->so->project_workorder_data($project_id);
 
 			$sum_workorder_budget = 0;
@@ -255,7 +353,6 @@
 			$sum_workorder_calculation = 0;
 			$sum_workorder_actual_cost = 0;
 
-			$custom 		= createObject('property.custom_fields');
 			for ($i=0;$i<count($workorder_data);$i++)
 			{
 				$sum_workorder_budget= $sum_workorder_budget+$workorder_data[$i]['budget'];
@@ -263,22 +360,23 @@
 				$sum_workorder_calculation= $sum_workorder_calculation+$workorder_data[$i]['calculation'];
 				$sum_workorder_actual_cost= $sum_workorder_actual_cost+$workorder_data[$i]['act_mtrl_cost']+$workorder_data[$i]['act_vendor_cost'];
 
-				$project['workorder_budget'][$i]['workorder_id']=$workorder_data[$i]['workorder_id'];
-				$project['workorder_budget'][$i]['budget']=number_format($workorder_data[$i]['budget'], 2, ',', '');
-				$project['workorder_budget'][$i]['calculation']=number_format($workorder_data[$i]['calculation']*$tax, 2, ',', '');
-				$project['workorder_budget'][$i]['charge_tenant'] = $workorder_data[$i]['charge_tenant'];
-				$project['workorder_budget'][$i]['status'] = $workorder_data[$i]['status'];
+				$values['workorder_budget'][$i]['workorder_id']=$workorder_data[$i]['workorder_id'];
+				$values['workorder_budget'][$i]['budget']=number_format($workorder_data[$i]['budget'], 2, ',', '');
+				$values['workorder_budget'][$i]['calculation']=number_format($workorder_data[$i]['calculation']*$tax, 2, ',', '');
+				$values['workorder_budget'][$i]['charge_tenant'] = $workorder_data[$i]['charge_tenant'];
+				$values['workorder_budget'][$i]['status'] = $workorder_data[$i]['status'];
+				$values['workorder_budget'][$i]['actual_cost'] = $workorder_data[$i]['act_mtrl_cost']+$workorder_data[$i]['act_vendor_cost'];
 
 				if(isset($workorder_data[$i]['vendor_id']) && $workorder_data[$i]['vendor_id'])
 				{
-					$vendor['attributes'] = $custom->find('property','.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
+					$vendor['attributes'] = $this->custom->find('property','.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
 
 					$vendor	= $contacts->read_single($workorder_data[$i]['vendor_id'], $vendor);
 					foreach($vendor['attributes'] as $attribute)
 					{
 						if($attribute['name']=='org_name')
 						{
-							$project['workorder_budget'][$i]['vendor_name']=$attribute['value'];
+							$values['workorder_budget'][$i]['vendor_name']=$attribute['value'];
 							break;
 						}
 					}
@@ -286,49 +384,49 @@
 			}
 			if($workorder_data)
 			{
-				$project['sum_workorder_budget']= number_format($sum_workorder_budget, 2, ',', '');
-				$project['deviation']= $sum_deviation;
-				$project['sum_workorder_calculation']= number_format($sum_workorder_calculation*$tax, 2, ',', '');
-				$project['sum_workorder_actual_cost']= number_format($sum_workorder_actual_cost, 2, ',', '');
+				$values['sum_workorder_budget']= number_format($sum_workorder_budget, 2, ',', '');
+				$values['deviation']= $sum_deviation;
+				$values['sum_workorder_calculation']= number_format($sum_workorder_calculation*$tax, 2, ',', '');
+				$values['sum_workorder_actual_cost']= number_format($sum_workorder_actual_cost, 2, ',', '');
 			}
 
-			if($project['location_code'])
+			if($values['location_code'])
 			{
-				$project['location_data'] =$this->solocation->read_single($project['location_code']);
+				$values['location_data'] = execMethod('property.solocation.read_single', $values['location_code']);
 			}
 
-			if($project['tenant_id']>0)
+			if($values['tenant_id']>0)
 			{
-				$tenant_data=$this->bocommon->read_single_tenant($project['tenant_id']);
-				$project['location_data']['tenant_id']= $project['tenant_id'];
-				$project['location_data']['contact_phone']= $tenant_data['contact_phone'];
-				$project['location_data']['last_name']	= $tenant_data['last_name'];
-				$project['location_data']['first_name']	= $tenant_data['first_name'];
+				$tenant_data=$this->bocommon->read_single_tenant($values['tenant_id']);
+				$values['location_data']['tenant_id']= $values['tenant_id'];
+				$values['location_data']['contact_phone']= $tenant_data['contact_phone'];
+				$values['location_data']['last_name']	= $tenant_data['last_name'];
+				$values['location_data']['first_name']	= $tenant_data['first_name'];
 			}
 			else
 			{
-				unset($project['location_data']['tenant_id']);
-				unset($project['location_data']['contact_phone']);
-				unset($project['location_data']['last_name']);
-				unset($project['location_data']['first_name']);
+				unset($values['location_data']['tenant_id']);
+				unset($values['location_data']['contact_phone']);
+				unset($values['location_data']['last_name']);
+				unset($values['location_data']['first_name']);
 			}
 
-			if($project['p_num'])
+			if($values['p_num'])
 			{
 				$soadmin_entity	= CreateObject('property.soadmin_entity');
-				$category = $soadmin_entity->read_single_category($project['p_entity_id'],$project['p_cat_id']);
+				$category = $soadmin_entity->read_single_category($values['p_entity_id'],$values['p_cat_id']);
 
-				$project['p'][$project['p_entity_id']]['p_num']=$project['p_num'];
-				$project['p'][$project['p_entity_id']]['p_entity_id']=$project['p_entity_id'];
-				$project['p'][$project['p_entity_id']]['p_cat_id']=$project['p_cat_id'];
-				$project['p'][$project['p_entity_id']]['p_cat_name'] = $category['name'];
+				$values['p'][$values['p_entity_id']]['p_num']=$values['p_num'];
+				$values['p'][$values['p_entity_id']]['p_entity_id']=$values['p_entity_id'];
+				$values['p'][$values['p_entity_id']]['p_cat_id']=$values['p_cat_id'];
+				$values['p'][$values['p_entity_id']]['p_cat_name'] = $category['name'];
 			}
 
-			$project['origin'] = $this->interlink->get_relation('property', '.project', $project_id, 'origin');
-			$project['target'] = $this->interlink->get_relation('property', '.project', $project_id, 'target');
+			$values['origin'] = $this->interlink->get_relation('property', '.project', $project_id, 'origin');
+			$values['target'] = $this->interlink->get_relation('property', '.project', $project_id, 'target');
 
-//_debug_array($project);
-			return $project;
+//_debug_array($values);
+			return $values;
 		}
 
 		function read_single_mini($project_id)
@@ -340,7 +438,7 @@
 
 			if($project['location_code'])
 			{
-				$project['location_data'] =$this->solocation->read_single($project['location_code']);
+				$project['location_data'] = execMethod('property.solocation.read_single', $project['location_code']);
 			}
 
 			if($project['tenant_id']>0)
@@ -369,7 +467,7 @@
 			$historylog	= CreateObject('property.historylog','project');
 			$history_array = $historylog->return_array(array('O'),array(),'','',$id);
 			$i=0;
-			while (is_array($history_array) && list(,$value) = each($history_array))
+			foreach ($history_array as $value) 
 			{
 
 				$record_history[$i]['value_date']	= $GLOBALS['phpgw']->common->show_date($value['datetime']);
@@ -377,6 +475,8 @@
 
 				switch ($value['status'])
 				{
+					case 'B': $type = lang('Budget'); break;
+					case 'BR': $type = lang('reserve'); break;
 					case 'R': $type = lang('Re-opened'); break;
 					case 'RM': $type = lang('remark'); break;
 					case 'X': $type = lang('Closed');    break;
@@ -410,19 +510,46 @@
 					{
 						$record_history[$i]['value_new_value']	= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
 					}
+					if (! $value['old_value'])
+					{
+						$record_history[$i]['value_old_value']	= '';
+					}
+					else
+					{
+						$record_history[$i]['value_old_value']	= $GLOBALS['phpgw']->accounts->id2name($value['old_value']);
+					}
 				}
 				else if ($value['status'] == 'C' || $value['status'] == 'CO')
 				{
 					$record_history[$i]['value_new_value']	= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+					if (! $value['old_value'])
+					{
+						$record_history[$i]['value_old_value']	= '';
+					}
+					else
+					{
+						$record_history[$i]['value_old_value']	= $GLOBALS['phpgw']->accounts->id2name($value['old_value']);
+					}
 				}
 				else if ($value['status'] == 'T' || $value['status'] == 'TO')
 				{
 					$category 								= $this->cats->return_single($value['new_value']);
 					$record_history[$i]['value_new_value']	= $category[0]['name'];
+					if($value['old_value'])
+					{
+						$category 								= $this->cats->return_single($value['old_value']);
+						$record_history[$i]['value_old_value']	= $category[0]['name'];
+					}
 				}
+				else if ($value['status'] == 'B' || $value['status'] == 'BR')
+				{
+					$record_history[$i]['value_new_value']	=number_format($value['new_value'], 0, ',', ' ');
+					$record_history[$i]['value_old_value']	=number_format($value['old_value'], 0, ',', ' ');
+				}
 				else if ($value['status'] != 'O' && $value['new_value'])
 				{
 					$record_history[$i]['value_new_value']	= $value['new_value'];
+					$record_history[$i]['value_old_value']	= $value['old_value'];
 				}
 				else
 				{
@@ -441,7 +568,7 @@
 			return $this->so->next_project_id();
 		}
 
-		function save($project,$action='')
+		function save($project,$action='',$values_attribute = array())
 		{
 
 //_debug_array($project);
@@ -461,14 +588,18 @@
 			$project['start_date']	= mktime (2,0,0,$start_date['month'],$start_date['day'],$start_date['year']);
 			$project['end_date']	= $end_date ? mktime (2,0,0,$end_date['month'],$end_date['day'],$end_date['year']) : '';
 
+			if(is_array($values_attribute))
+			{
+				$values_attribute = $this->custom->convert_attribute_save($values_attribute);
+			}
 
 			if ($action=='edit')
 			{
-					$receipt = $this->so->edit($project);
+					$receipt = $this->so->edit($project, $values_attribute);
 			}
 			else
 			{
-				$receipt = $this->so->add($project);
+				$receipt = $this->so->add($project, $values_attribute);
 			}
 			return $receipt;
 		}

Modified: people/sigurdne/modules/property/trunk/inc/class.bor_agreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bor_agreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bor_agreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -266,7 +266,7 @@
 		function read_event($data)
 		{
 			$boalarm		= CreateObject('property.boalarm');
-			$event	= $this->so->read_single($data);
+			$event	= $this->so->read_single($data['r_agreement_id']);
 			$event['alarm_date']=$event['termination_date'];
 			$event['alarm']	= $boalarm->read_alarms($type='r_agreement',$data['r_agreement_id']);
 			return $event;
@@ -338,6 +338,20 @@
 			return $values;
 		}
 
+		/**
+		* Arrange attributes within groups
+		*
+		* @param string  $location    the name of the location of the attribute
+		* @param array   $attributes  the array of the attributes to be grouped
+		*
+		* @return array the grouped attributes
+		*/
+
+		public function get_attribute_groups($location, $attributes = array())
+		{
+			return $this->custom->get_attribute_groups('property', $location, $attributes);
+		}
+
 		function save($values,$values_attribute='',$action='')
 		{
 
@@ -463,7 +477,8 @@
 			{
 				$selected=$GLOBALS['phpgw_info']['user']['preferences']['property']['r_agreement_columns'];
 			}
-			$columns = $this->custom->find('property','.r_agreement', 0, '','','',true);
+			$filter = array('list' => ''); // translates to "list IS NULL"
+			$columns = $this->custom->find('property','.r_agreement', 0, '','','',true, false, $filter);
 			$column_list=$this->bocommon->select_multi_list($selected,$columns);
 			return $column_list;
 		}

Modified: people/sigurdne/modules/property/trunk/inc/class.borequest.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.borequest.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.borequest.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -267,7 +267,8 @@
 		{
 			$request = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'filter' => $this->filter,'cat_id' => $this->cat_id,'status_id' => $this->status_id,
-											'project_id' => $data['project_id'],'allrows'=>$data['allrows'],'list_descr' => $data['list_descr']));
+											'project_id' => $data['project_id'],'allrows'=>$data['allrows'],'list_descr' => $data['list_descr'],
+											'dry_run'=>$data['dry_run']));
 			$this->total_records = $this->so->total_records;
 
 			$this->uicols	= $this->so->uicols;
@@ -279,13 +280,15 @@
 			{
 				$request[$i]['coordinator'] = $GLOBALS['phpgw']->accounts->id2name($request[$i]['coordinator']);
 				$request[$i]['entry_date'] = $GLOBALS['phpgw']->common->show_date($request[$i]['entry_date'],$dateformat);
+				if($cols_extra)
+				{
 				$location_data=$this->solocation->read_single($request[$i]['location_code']);
-
 				for ($j=0;$j<count($cols_extra);$j++)
 				{
 					$request[$i][$cols_extra[$j]] = $location_data[$cols_extra[$j]];
 				}
 			}
+			}
 
 			return $request;
 		}

Modified: people/sigurdne/modules/property/trunk/inc/class.boresponsible.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boresponsible.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boresponsible.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -9,13 +9,13 @@
 	* @package phpgroupware
 	* @subpackage property
 	* @category core
- 	* @version $Id: class.uiresponsible.inc.php 732 2008-02-10 16:21:14Z sigurd $
+ 	* @version $Id: class.boresponsible.inc.php 3779 2009-09-30 19:30:32Z sigurd $
 	*/
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -92,9 +92,17 @@
 				$this->cat_id = phpgw::get_var('cat_id');
 			}
 
+			switch ($this->location)
+			{
+				case '.project.workorder':
+					$cats_app_name = 'property.project';
+					break;
+					default:
+					$cats_app_name = "property{$this->location}";
+			}
 
 			$this->cats					= CreateObject('phpgwapi.categories');
-			$this->cats->app_name		= "property{$this->location}";
+			$this->cats->app_name		= $cats_app_name;
 			$this->dateformat 			= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 		}
 
@@ -167,6 +175,8 @@
 												'filter' => $filter));
 			$this->total_records = $this->so->total_records;
 			
+			if($value['cat_id'])
+			{
 			foreach($values as & $value)
 			{
 				$category = $this->cats->return_single($value['cat_id']);
@@ -174,7 +184,7 @@
 				$value['app_name']		= $category[0]['app_name'];
 				$value['created_by']	= $GLOBALS['phpgw']->accounts->id2name($value['created_by']);
 				$value['created_on']	= $GLOBALS['phpgw']->common->show_date($value['created_on'], $this->dateformat);
-			
+				}
 			}
 
 			return $values;

Modified: people/sigurdne/modules/property/trunk/inc/class.bos_agreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bos_agreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bos_agreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -42,6 +42,7 @@
 		var $cat_id;
 		var $role;
 		var $member_id;
+		var $uicols = array();
 
 		/**
 		* @var object $custom reference to custom fields object
@@ -62,6 +63,9 @@
 			$this->so = CreateObject('property.sos_agreement');
 			$this->bocommon = CreateObject('property.bocommon');
 			$this->custom 		= createObject('property.custom_fields');
+			$this->cats					= CreateObject('phpgwapi.categories');
+			$this->cats->app_name 		= 'fm_vendor';
+			$this->cats->supress_info	= true;
 
 			if ($session)
 			{
@@ -84,51 +88,15 @@
 			$this->role	= $role;
 			$this->so->role	= $role;
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(isset($query))
-			{
-				$this->query = $query;
-			}
-			if(!empty($filter))
-			{
-				$this->filter = $filter;
-			}
-			if(isset($sort))
-			{
-				$this->sort = $sort;
-			}
-			if(isset($order))
-			{
-				$this->order = $order;
-			}
-			if(isset($cat_id) && !empty($cat_id))
-			{
-				$this->cat_id = $cat_id;
-			}
-			else
-			{
-				$this->cat_id = '';
-			}
-			if(isset($allrows))
-			{
-				$this->allrows = $allrows;
-			}
-			if(isset($member_id))
-			{
-				$this->member_id = $member_id;
-			}
-			if(isset($vendor_id))
-			{
-				$this->vendor_id = $vendor_id;
-			}
+			$this->start			= $start ? $start : 0;
+			$this->query			= isset($query) ? $query : $this->query;
+			$this->sort				= isset($sort) && $sort ? $sort : '';
+			$this->order			= isset($order) && $order ? $order : '';
+			$this->filter			= isset($filter) && $filter ? $filter : '';
+			$this->cat_id			= isset($cat_id) && $cat_id ? $cat_id : '';
+			$this->member_id		= isset($member_id) && $member_id ? $member_id : '';
+			$this->vendor_id		= isset($vendor_id) && $vendor_id ? $vendor_id : '';
+			$this->allrows			= isset($allrows) && $allrows ? $allrows : '';
 		}
 
 		function save_sessiondata($data)
@@ -237,8 +205,8 @@
 		function read_event($data)
 		{
 			$boalarm		= CreateObject('property.boalarm');
-			$event	= $this->so->read_single($data);
-			$event['alarm_date']=$event['termination_date'];
+			$event				= $this->so->read_single($data['s_agreement_id']);
+			$event['alarm_date']= $event['termination_date'];
 			$event['alarm']	= $boalarm->read_alarms($type='s_agreement',$data['s_agreement_id']);
 			return $event;
 		}
@@ -311,6 +279,20 @@
 			return $values;
 		}
 
+		/**
+		* Arrange attributes within groups
+		*
+		* @param string  $location    the name of the location of the attribute
+		* @param array   $attributes  the array of the attributes to be grouped
+		*
+		* @return array the grouped attributes
+		*/
+
+		public function get_attribute_groups($location, $attributes = array())
+		{
+			return $this->custom->get_attribute_groups('property', $location, $attributes);
+		}
+
 		function save($values,$values_attribute='',$action='')
 		{
 
@@ -428,7 +410,8 @@
 				$selected=$GLOBALS['phpgw_info']['user']['preferences']['property']['s_agreement_columns'];
 			}
 
-			$columns = $this->custom->find('property','.s_agreement', 0, '','','',true);
+			$filter = array('list' => ''); // translates to "list IS NULL"
+			$columns = $this->custom->find('property','.s_agreement', 0, '','','',true, false, $filter);
 
 			$column_list=$this->bocommon->select_multi_list($selected,$columns);
 
@@ -455,5 +438,59 @@
 			$historylog = CreateObject('property.historylog','s_agreement');
 			$historylog->delete_single_record($data['history_id']);
 		}
+
+		function get_year_list($agreement_id = '')
+		{
+			if($agreement_id)
+			{
+				$list = $this->so->get_year_filter_list($agreement_id);
+			}
+			else
+			{
+				$list = array();
+			}
+			$year = date('Y');
+			$limit = $year + 4;
+			
+			while ($year < $limit)
+			{
+				$list[] =  $year;
+				$year++;
+			}
+
+			$list = array_unique($list);
+			sort($list);
+			
+			$values;
+			foreach($list as $entry)
+			{
+				$values[] = array
+				(
+					'id'	=> $entry,
+					'name'	=> $entry
+				);
+			}
+			return $values;
+		}
+
+		function get_budget($agreement_id)
+		{
+			$values = $this->so->get_budget($agreement_id);
+
+			$this->cats->app_name		= 'property.project';
+			foreach($values as & $entry)
+			{
+				$category = $this->cats->return_single($entry['cat_id']);
+				$entry['category']		= $category[0]['name'];
+			}
+			$this->cats->app_name 		= 'fm_vendor';	
+			return $values;		
+		}
+
+		function delete_year_from_budget($data,$agreement_id)
+		{
+			return $this->so->delete_year_from_budget($data,$agreement_id);
+		}
+
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.botenant_claim.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.botenant_claim.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.botenant_claim.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -63,6 +63,8 @@
 			$status	= phpgw::get_var('status');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
 			$allrows= phpgw::get_var('allrows', 'bool');
+			$project_id	= phpgw::get_var('project_id', 'int');
+			$this->project_id = $project_id;
 
 			if ($start)
 			{
@@ -147,17 +149,19 @@
 
 			$GLOBALS['phpgw']->xslttpl->add_file(array('status_' . $format));
 
-			$status[0][id]='closed';
-			$status[0][name]=lang('Closed');
+			$status[0][id]='ready';
+			$status[0][name]=lang('ready for processing claim');
+			$status[1][id]='closed';
+			$status[1][name]=lang('Closed');
 			if($format == "filter")
 			{
-				$status[1][id]='all';
-				$status[1][name]=lang('All');
+				$status[2][id]='all';
+				$status[2][name]=lang('All');
 			}
 			else
 			{
-				$status[1][id]='open';
-				$status[1][name]=lang('Open');
+				$status[2][id]='open';
+				$status[2][name]=lang('Open');
 			}
 
 			return $this->bocommon->select_list($selected,$status);
@@ -168,16 +172,19 @@
 			return $this->so->read_category_name($cat_id);
 		}
 
-		function read($data=0)
+		function read($data = array())
 		{
+			$project_id	= isset($data['project_id']) && $data['project_id'] ? $data['project_id'] : phpgw::get_var('project_id');
+
 			$claim = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'filter' => $this->filter,'status' => $this->status,'cat_id' => $this->cat_id,
-											'allrows'=>$this->allrows,'project_id' => $data['project_id']));
+											'allrows'=>$this->allrows,'project_id' => $project_id));
 			$this->total_records = $this->so->total_records;
 
-			for ($i=0; $i<count($claim); $i++)
+			foreach ($claim as &$entry)
 			{
-				$claim[$i]['entry_date']  = $GLOBALS['phpgw']->common->show_date($claim[$i]['entry_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+				$entry['entry_date']  = $GLOBALS['phpgw']->common->show_date($entry['entry_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+				$entry['status'] = lang($entry['status']);
 			}
 			return $claim;
 		}
@@ -221,7 +228,7 @@
 
 
 			$this->config = CreateObject('phpgwapi.config','property');
-			$this->config->read_repository();
+			$this->config->read();
 			$claim_notify_mails = $this->config->config_data['tenant_claim_notify_mails'];
 			if ($claim_notify_mails)
 			{

Modified: people/sigurdne/modules/property/trunk/inc/class.botts.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.botts.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.botts.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -41,6 +41,10 @@
 		var $order;
 		var $cat_id;
 		var $acl_location;
+		var $uicols_related = array();
+		var $start_date;
+		var $end_date;
+		var $fields_updated = false;
 
 		var $public_functions = array
 		(
@@ -73,15 +77,17 @@
 		function property_botts($session=false)
 		{
 			$this->so 			= CreateObject('property.sotts');
-			$this->bocommon 	= & $this->so->bocommon;
+			$this->bocommon 			= CreateObject('property.bocommon');
 			$this->historylog	= & $this->so->historylog;
-			$this->config		= CreateObject('phpgwapi.config');
-			$this->config->read_repository();
+			$this->config				= CreateObject('phpgwapi.config','property');
 			$this->dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 			$this->cats					= CreateObject('phpgwapi.categories');
 			$this->cats->app_name		= 'property.ticket';
 			$this->cats->supress_info	= true;
+			$this->acl_location			= $this->so->acl_location;
 
+			$this->config->read();
+
 			if ($session)
 			{
 				$this->read_sessiondata();
@@ -92,63 +98,27 @@
 			$query	= phpgw::get_var('query');
 			$sort	= phpgw::get_var('sort');
 			$order	= phpgw::get_var('order');
-			$filter	= phpgw::get_var('filter');
-			$user_filter	= phpgw::get_var('user_filter');
+			$status_id				= phpgw::get_var('status_id', 'string');
+			$user_id				= phpgw::get_var('user_id', 'int');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
+			$part_of_town_id		= phpgw::get_var('part_of_town_id', 'int');
 			$district_id	= phpgw::get_var('district_id', 'int');
 			$allrows	= phpgw::get_var('allrows', 'bool');
-			$start_date	= phpgw::get_var('start_date');
-			$end_date	= phpgw::get_var('end_date');
+			$start_date				= phpgw::get_var('start_date', 'string');
+			$end_date				= phpgw::get_var('end_date', 'string');
 
-			if ($start)
-			{
-				$this->start=$start;
-			}
-			else
-			{
-				$this->start=0;
-			}
-
-			if(array_key_exists('query',$_POST) || array_key_exists('query',$_GET))
-			{
-				$this->query = $query;
-			}
-			if(array_key_exists('filter',$_POST))
-			{
-				$this->filter = $filter;
-			}
-			if(array_key_exists('user_filter',$_POST))
-			{
-				$this->user_filter = $user_filter;
-			}
-			if(array_key_exists('sort',$_POST) || array_key_exists('sort',$_GET))
-			{
-				$this->sort = $sort;
-			}
-			if(array_key_exists('order',$_POST) || array_key_exists('order',$_GET))
-			{
-				$this->order = $order;
-			}
-			if(array_key_exists('cat_id',$_POST))
-			{
-				$this->cat_id = $cat_id;
-			}
-			if(array_key_exists('district_id',$_POST))
-			{
-				$this->district_id = $district_id;
-			}
-			if(array_key_exists('allrows',$_POST) || array_key_exists('allrows',$_GET))
-			{
-				$this->allrows = $allrows;
-			}
-			if(array_key_exists('start_date',$_POST))
-			{
-				$this->start_date = $start_date;
-			}
-			if(array_key_exists('end_date',$_POST))
-			{
-				$this->end_date = $end_date;
-			}
+			$this->start			= $start 							? $start 			: 0;
+			$this->query			= isset($_REQUEST['query']) 		? $query			: $this->query;
+			$this->sort				= isset($_REQUEST['sort']) 			? $sort				: $this->sort;
+			$this->order			= isset($_REQUEST['order']) 		? $order			: $this->order;
+			$this->cat_id			= isset($_REQUEST['cat_id']) 		? $cat_id			:  $this->cat_id;
+			$this->status_id		= isset($_REQUEST['status_id'])		? $status_id		: $this->status_id;
+			$this->user_id			= isset($_REQUEST['user_id']) 		? $user_id			: $this->user_id;;
+			$this->part_of_town_id	= isset($_REQUEST['part_of_town_id'])? $part_of_town_id : $this->part_of_town_id;
+			$this->district_id		= isset($_REQUEST['district_id']) 	? $district_id		: $this->district_id;
+			$this->allrows			= isset($allrows) && $allrows 		? $allrows			: '';
+			$this->start_date		= isset($_REQUEST['start_date']) 	? $start_date		: $this->start_date;
+			$this->end_date			= isset($_REQUEST['end_date'])		? $end_date			: $this->end_date;
 		}
 
 
@@ -166,10 +136,10 @@
 
 			$this->start		= isset($data['start'])?$data['start']:'';
 			$this->query		= isset($data['query'])?$data['query']:'';
-			$this->filter		= isset($data['filter'])?$data['filter']:'';
-			$this->user_filter	= isset($data['user_filter'])?$data['user_filter']:'';
+			$this->user_id		= isset($data['user_id'])?$data['user_id']:'';
 			$this->sort			= isset($data['sort'])?$data['sort']:'';
 			$this->order		= isset($data['order'])?$data['order']:'';
+			$this->status_id	= isset($data['status_id'])?$data['status_id']:'';
 			$this->cat_id		= isset($data['cat_id'])?$data['cat_id']:'';
 			$this->district_id	= isset($data['district_id'])?$data['district_id']:'';
 			$this->allrows		= isset($data['allrows'])?$data['allrows']:'';
@@ -239,21 +209,22 @@
 			return $status;
 		}
 
-		function _get_status_text()
+		function get_status_text()
 		{
 			$status_text = array(
-				'R' => 'Re-opened',
-				'X' => 'Closed',
-				'O' => 'Opened',
-				'A' => 'Re-assigned',
-				'G' => 'Re-assigned group',
-				'P' => 'Priority changed',
-				'T' => 'Category changed',
-				'S' => 'Subject changed',
-				'B' => 'Billing rate',
-				'H' => 'Billing hours',
-				'F' => 'finnish date',
-				'SC' => 'Status changed'
+				'R' => lang('Re-opened'),
+				'X' => lang('Closed'),
+				'O' => lang('Opened'),
+				'A' => lang('Re-assigned'),
+				'G' => lang('Re-assigned group'),
+				'P' => lang('Priority changed'),
+				'T' => lang('Category changed'),
+				'S' => lang('Subject changed'),
+				'B' => lang('Billing rate'),
+				'H' => lang('Billing hours'),
+				'F' => lang('finnish date'),
+				'SC' => lang('Status changed'),
+				'M' => lang('Sendt by email to')
 			);
 
 			$custom_status	= $this->so->get_custom_status();
@@ -268,17 +239,20 @@
 
 		function get_priority_list($selected='')
 		{
-			if(!$selected && isset($GLOBALS['phpgw_info']['user']['preferences']['property']['prioritydefault']))
+
+			$prioritylevels = isset($this->config->config_data['prioritylevels']) && $this->config->config_data['prioritylevels'] ? $this->config->config_data['prioritylevels'] : 3;
+
+			if(!$selected)
 			{
-				$selected = $GLOBALS['phpgw_info']['user']['preferences']['property']['prioritydefault'];
+				$selected = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['prioritydefault']) ? $GLOBALS['phpgw_info']['user']['preferences']['property']['prioritydefault'] : $prioritylevels;
 			}
 
-			$priority_comment[1]=' - '.lang('Lowest');
-			$priority_comment[5]=' - '.lang('Medium');
-			$priority_comment[10]=' - '.lang('Highest');
+			$priority_comment[$prioritylevels]=' - '.lang('Lowest');
+//			$priority_comment[2]=' - '.lang('Medium');
+			$priority_comment[1]=' - '.lang('Highest');
 
 			$priorities = array();
-			for ($i=1; $i<=10; $i++)
+			for ($i=1; $i<= $prioritylevels; $i++)
 			{
 				$priorities[$i]['id'] =$i;
 				$priorities[$i]['name'] =$i . (isset($priority_comment[$i])?$priority_comment[$i]:'');
@@ -294,51 +268,93 @@
 		}
 
 
-		function read($start_date='',$end_date='', $external='')
+		function get_origin_entity_type()
 		{
+			$related = $this->so->get_origin_entity_type();
+			$this->uicols_related = $this->so->uicols_related;
+			return $related;
+		}
+
+		function read($start_date='',$end_date='', $external='',$dry_run = '', $download = '')
+		{
+			$category_name = array();
+			$account = array();
+			
 			$interlink 	= CreateObject('property.interlink');
 			$start_date	= $this->bocommon->date_to_timestamp($start_date);
 			$end_date	= $this->bocommon->date_to_timestamp($end_date);
 
 			$tickets = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
-											'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' => $this->district_id,
+											'status_id' => $this->status_id,'cat_id' => $this->cat_id,'district_id' => $this->district_id,
 											'start_date'=>$start_date,'end_date'=>$end_date,
-											'allrows'=>$this->allrows,'user_filter' => $this->user_filter,'external'=>$external));
+											'allrows'=>$this->allrows,'user_id' => $this->user_id,'external'=>$external, 'dry_run' => $dry_run));
 			$this->total_records = $this->so->total_records;
 			if(!$external)
 			{
-				$entity	= $this->so->get_origin_entity_type();
-				$this->uicols=$this->so->uicols;
+				$entity	= $this->get_origin_entity_type();
+//				$this->uicols_related = $this->so->uicols_related;
 			}
 			else
 			{
 				$entity[0]['type']='.project';
-				$this->uicols[]	= lang('project');
+				$this->uicols_related	= array('project');
 			}
 
 			foreach ($tickets as & $ticket)
 			{
 				if(!$ticket['subject'])
 				{
+					if(!isset($category_name[$ticket['cat_id']]))
+					{
 					$ticket['subject']= $this->get_category_name($ticket['cat_id']);
+						$category_name[$ticket['cat_id']] = $ticket['subject'];
+					}
+					else
+					{
+						$ticket['subject'] = $category_name[$ticket['cat_id']];
+					}
 				}
 
+				if(!isset($account[$ticket['user_id']]))
+				{
 				$ticket['user'] = $GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+					$account[$ticket['user_id']] = $ticket['user'];
+				}
+				else
+				{
+					$ticket['user'] = $account[$ticket['user_id']];
+				}
 
 				if($ticket['assignedto'])
 				{
+					if(!isset($account[$ticket['assignedto']]))
+					{
 					$ticket['assignedto'] = $GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']);
+						$account[$ticket['assignedto']] = $ticket['assignedto'];
 				}
 				else
 				{
+						$ticket['assignedto'] = $account[$ticket['assignedto']];
+					}
+				}
+				else
+				{
+					if(!isset($account[$ticket['group_id']]))
+					{
 					$ticket['assignedto'] = $GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
+						$account[$ticket['group_id']] = $ticket['assignedto'];
+					}
+					else
+					{
+						 $ticket['assignedto'] = $account[$ticket['group_id']];
+					}
 				}
 
-				$ticket['timestampopened'] = $GLOBALS['phpgw']->common->show_date($ticket['entry_date'],$this->dateformat);
+				$ticket['entry_date'] = $GLOBALS['phpgw']->common->show_date($ticket['entry_date'],$this->dateformat);
 
 				if($ticket['finnish_date2'])
 				{
-					$ticket['delay']=($ticket['finnish_date2']-$ticket['finnish_date'])/(24*3600);
+					$ticket['delay'] = round(($ticket['finnish_date2']-$ticket['finnish_date'])/(24*3600));
 					$ticket['finnish_date']=$ticket['finnish_date2'];
 				}
 				$ticket['finnish_date'] = (isset($ticket['finnish_date']) && $ticket['finnish_date'] ? $GLOBALS['phpgw']->common->show_date($ticket['finnish_date'],$this->dateformat):'');
@@ -348,9 +364,9 @@
 					$history_values = $this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$ticket['id']);
 					$ticket['timestampclosed'] = $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
 				}
-				if (isset($ticket['new_ticket']))
+				if ($ticket['new_ticket'])
 				{
-					$ticket['new_ticket'] = lang('New');
+					$ticket['new_ticket'] = '*';
 				}
 
 				if(isset($entity) && is_array($entity))
@@ -358,10 +374,14 @@
 					for ($j=0;$j<count($entity);$j++)
 					{
 						$ticket['child_date'][$j] = $interlink->get_child_date('property', '.ticket', $entity[$j]['type'], $ticket['id'], isset($entity[$j]['entity_id'])?$entity[$j]['entity_id']:'',isset($entity[$j]['cat_id'])?$entity[$j]['cat_id']:'');
+						if($ticket['child_date'][$j]['date_info'] && !$download)
+						{
+							$ticket['child_date'][$j]['statustext'] = $interlink->get_relation_info(array('location' => $entity[$j]['type']), $ticket['child_date'][$j]['date_info'][0]['target_id']);
 					}
 				}
 			}
-//_debug_array($tickets);
+			}
+
 			return $tickets;
 		}
 
@@ -424,7 +444,8 @@
 
 
 			$history_values = $this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
-			$ticket['timestampopened'] = $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+			$ticket['timestamp'] = $history_values[0]['datetime'];
+			$ticket['entry_date'] = $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
 			// Figure out when it was opened and last closed
 
 			$history_values = $this->historylog->return_array(array(),array('O'),'history_timestamp','ASC',$id);
@@ -437,9 +458,9 @@
 				$ticket['timestampclosed']= $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
 			}
 
-			$status_text = $this->_get_status_text();
+			$status_text = $this->get_status_text();
 
-			$ticket['status_name'] = lang($status_text[$ticket['status']]);
+			$ticket['status_name'] = $status_text[$ticket['status']];
 			$ticket['user_lid']=$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
 			$ticket['category_name']=ucfirst($this->get_category_name($ticket['cat_id']));
 
@@ -467,8 +488,9 @@
 
 		function read_additional_notes($id)
 		{
+			$additional_notes = array();
 			$history_array = $this->historylog->return_array(array(),array('C'),'','',$id);
-			$i=1;
+			$i=2;
 			while (is_array($history_array) && list(,$value) = each($history_array))
 			{
 				$additional_notes[] = array
@@ -480,20 +502,18 @@
 					);
 				$i++;
 			}
-
-			if(isset ($additional_notes))
-			{
 				return $additional_notes;
 			}
-		}
 
 
 		function read_record_history($id)
 		{
 			$history_array = $this->historylog->return_array(array('C','O'),array(),'','',$id);
-			$status_text = $this->_get_status_text();
+
+			$status_text = $this->get_status_text();
 			$record_history = array();
 			$i=0;
+
 			if (is_array($history_array))
 			{
 				foreach ($history_array as $value)
@@ -512,25 +532,35 @@
 						case 'T': $type = lang('Category changed'); break;
 						case 'S': $type = lang('Subject changed'); break;
 						case 'H': $type = lang('Billable hours changed'); break;
-						case 'B': $type = lang('Billable rate changed'); break;
+						case 'B': $type = lang('Budget changed'); break;
+	//					case 'B': $type = lang('Billable rate changed'); break;
 						case 'F': $type = lang('finnish date changed'); break;
 						case 'IF': $type = lang('Initial finnish date'); break;
+						case 'L': $type = lang('Location changed'); break;
+						case 'M':
+							$type = lang('Sendt by email to');
+							$this->order_sent_adress = $value['new_value']; // in case we want to resend the order as an reminder
+							break;
 						default: break;
 					}
 
-					switch ($value['new_value'])
+					if ( $value['status'] == 'X' || $value['status'] == 'R' || (strlen($value['status']) == 2 && substr($value['new_value'], 0, 1) == 'C') ) // if custom status
 					{
-						case 'O': $value['new_value']=lang('Opened'); break;
-						case 'X': $value['new_value']=lang('Closed'); break;
-						case 'I': $value['new_value']=lang('In Progress'); break; //initiated
-						case 'C': $value['new_value']=lang('custom'); break; // FIXME: make configurable
-						default: break;
+						switch ($value['status'])
+						{
+							case 'R': 
+								$type = lang('Re-opened');
+								break;
+							case 'X':
+								$type = lang('Closed');
+								break;
+							default:
+								$type = lang('Status changed')
+								;break;
 					}
 
-					if(strlen($value['new_value']) == 2 && substr($value['new_value'], 0, 1) == 'C') // if custom status
-					{
-						$type = lang('Status changed');
 						$value['new_value'] = $status_text[$value['new_value']];
+						$value['old_value'] = $status_text[$value['old_value']];
 					}
 
 					$record_history[$i]['value_action']	= $type?$type:'';
@@ -540,15 +570,18 @@
 						if ((int)$value['new_value']>0)
 						{
 							$record_history[$i]['value_new_value']	= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+							$record_history[$i]['value_old_value'] = $value['old_value'] ? $GLOBALS['phpgw']->accounts->id2name($value['old_value']) : '';
 						}
 						else
 						{
 							$record_history[$i]['value_new_value']	= lang('None');
+							$record_history[$i]['value_old_value']	= lang('None');
 						}
 					}
 					else if ($value['status'] == 'T')
 					{
 						$record_history[$i]['value_new_value']	= $this->get_category_name($value['new_value']);
+						$record_history[$i]['value_old_value']	= $this->get_category_name($value['old_value']);
 					}
 					else if (($value['status'] == 'F') || ($value['status'] =='IF'))
 					{
@@ -557,15 +590,18 @@
 					else if ($value['status'] != 'O' && $value['new_value'])
 					{
 						$record_history[$i]['value_new_value']	= $value['new_value'];
+						$record_history[$i]['value_old_value']	= $value['old_value'];
 					}
 					else
 					{
 						$record_history[$i]['value_new_value']	= '';
+
 					}
 
 					$i++;
 				}
 			}
+
 			return $record_history;
 		}
 
@@ -588,11 +624,11 @@
 
 			$receipt = $this->so->add($ticket);
 
-			$this->config->read_repository();
+			$this->config->read();
 
 			if (isset($this->config->config_data['mailnotification']) && $this->config->config_data['mailnotification'] && isset($ticket['send_mail']) && $ticket['send_mail'])
 			{
-				$receipt = $this->mail_ticket($receipt['id'],$fields_updated,$receipt,$ticket['location_code']);
+				$receipt_mail = $this->mail_ticket($receipt['id'],$fields_updated,$receipt,$ticket['location_code']);
 			}
 
 			$criteria = array
@@ -612,50 +648,72 @@
 					continue;
 				}
 
-				$file = PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+				$file = PHPGW_SERVER_ROOT . "/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
 				if ( $entry['active'] && is_file($file) )
 				{
-					require_once PHPGW_APP_INC . "/custom/{$entry['file_name']}";
+					require_once $file;
 				}
 			}
 
+			if(isset($receipt_mail) && is_array($receipt_mail))
+			{
+				$receipt = array_merge($receipt, $receipt_mail);
+			}
 			return $receipt;
 		}
 
 
-		function mail_ticket($id,$fields_updated,$receipt=0,$location_code='')
+		function get_address_element($location_code = '')
 		{
-			$this->send			= CreateObject('phpgwapi.send');
-
-			$members = array();
-
-			$ticket	= $this->so->read_single($id);
-
-			if($ticket['location_code'])
+			$address_element = array();
+			if($location_code)
 			{
 				$solocation 		= CreateObject('property.solocation');
 				$custom = createObject('property.custom_fields');
-				$location_data 		= $solocation->read_single($ticket['location_code']);
+				$location_data 		= $solocation->read_single($location_code);
 
-				$type_id=count(explode('-',$ticket['location_code']));
+				$location_types = execMethod('property.soadmin_location.select_location_type');
+				$type_id=count(explode('-',$location_code));
+
+				for ($i=1; $i<$type_id+1; $i++)
+				{
+					$address_element[] = array
+					(
+						'text' => $location_types[($i-1)]['name'],
+						'value'=> $location_data["loc{$i}"] . '  ' . $location_data["loc{$i}_name"]
+					);
+				}
+
 				$fm_location_cols = $custom->find('property','.location.' . $type_id, 0, '', 'ASC', 'attrib_sort', true, true);
 				$i=0;
-				if (isset($fm_location_cols) AND is_array($fm_location_cols))
-				{
 					foreach($fm_location_cols as $location_entry)
 					{
 						if($location_entry['lookup_form'])
 						{
-							$address_element[$i]['text']=$location_entry['input_text'];
-							$address_element[$i]['value']=$location_data[$location_entry['column_name']];
+						$address_element[] = array
+						(
+							'text' => $location_entry['input_text'],
+							'value'=> $location_data[$location_entry['column_name']]
+						);
 						}
 						$i++;
 					}
 				}
+			return $address_element;
 			}
 
+		function mail_ticket($id, $fields_updated, $receipt = array(),$location_code='')
+		{
+			$this->send			= CreateObject('phpgwapi.send');
+
+			$members = array();
+
+			$ticket	= $this->so->read_single($id);
+
+			$address_element = $this->get_address_element($ticket['location_code']);
+
 			$history_values = $this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
-			$timestampopened = $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+			$entry_date = $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
 
 			if($ticket['status']=='X')
 			{
@@ -667,7 +725,7 @@
 			$m=count($history_2)-1;
 			$ticket['status']=$history_2[$m]['status'];
 
-		//	$status = $this->_get_status_text();
+		//	$status = $this->get_status_text();
 
 			$group_name= $GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
 
@@ -704,8 +762,8 @@
 		// build body
 			$body  = '';
 	//		$body .= lang('Ticket').' #'.$id."\n";
-			$body .= '<a href ="http://' . $GLOBALS['phpgw_info']['server']['hostname'] . $GLOBALS['phpgw']->link('/index.php','menuaction='.'property.uitts.view&id=' . $id).'">' . lang('Ticket').' #' .$id .'</a>'."\n";
-			$body .= lang('Date Opened').': '.$timestampopened."\n";
+			$body .= '<a href ="http://' . $GLOBALS['phpgw_info']['server']['hostname'] . $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uitts.view', 'id' => $id)).'">' . lang('Ticket').' #' .$id .'</a>'."\n";
+			$body .= lang('Date Opened').': '.$entry_date."\n";
 			$body .= lang('Category').': '. $this->get_category_name($ticket['cat_id']) ."\n";
 //			$body .= lang('Subject').': '. $ticket['subject'] ."\n";
 			$body .= lang('Location').': '. $ticket['location_code'] ."\n";
@@ -837,7 +895,7 @@
 				$receipt['error'][] = array('msg'=> 'group: '.$group_name);
 				$receipt['error'][] = array('msg'=> 'err_code: '.$this->send->err['code']);
 				$receipt['error'][] = array('msg'=> 'err_msg: '. htmlspecialchars($this->send->err['msg']));
-				$receipt['error'][] = array('msg'=> 'err_desc: '. $GLOBALS['phpgw']->err['desc']);
+				$receipt['error'][] = array('msg'=> 'err_desc: '. $this->send->err['desc']);
 			}
 
 //_debug_array($receipt);
@@ -860,4 +918,17 @@
 			return $this->so->get_custom_status();
 		}
 
+		public function update_status($data, $id = 0)
+		{
+			$receipt 	= $this->so->update_status($data, $id);
+			$this->fields_updated = $this->so->fields_updated;
+			return $receipt;
+		}
+
+		public function update_ticket($data, $id)
+		{
+			$receipt 	= $this->so->update_ticket($data, $id);
+			$this->fields_updated = $this->so->fields_updated;		
+			return $receipt;
+		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.bowo_hour.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.bowo_hour.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.bowo_hour.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -325,8 +325,11 @@
 
 //_debug_array($values);
 
+			if ($values['select']) 
+			{
 			foreach($values['select'] as $n)
 			{
+													
 				if(!$values['quantity'][$n])
 				{
 					$values['quantity'][$n]=1;
@@ -361,6 +364,7 @@
 				);
 
 			}
+			}
 //_debug_array($hour);
 
 			if($hour)

Modified: people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -40,6 +40,7 @@
 		var $sort;
 		var $order;
 		var $cat_id;
+		var $order_sent_adress; // in case we want to resend the order as an reminder
 
 		var $public_functions = array
 		(
@@ -58,7 +59,7 @@
 			$this->cats					= CreateObject('phpgwapi.categories');
 			$this->cats->app_name		= 'property.project';
 			$this->cats->supress_info	= true;
-
+			$this->interlink 	= & $this->so->interlink;
 			if ($session)
 			{
 				$this->read_sessiondata();
@@ -72,20 +73,25 @@
 			$filter	= phpgw::get_var('filter', 'int');
 			$cat_id	= phpgw::get_var('cat_id', 'int');
 			$status_id	= phpgw::get_var('status_id');
-			$search_vendor	= phpgw::get_var('search_vendor');
 			$wo_hour_cat_id	= phpgw::get_var('wo_hour_cat_id', 'int');
 			$start_date	= phpgw::get_var('start_date');
 			$end_date	= phpgw::get_var('end_date');
 			$b_group	= phpgw::get_var('b_group');
 			$paid	= phpgw::get_var('paid', 'bool');
+			$b_account		= phpgw::get_var('b_account');
+			$district_id	= phpgw::get_var('district_id', 'int');
+			$criteria_id	= phpgw::get_var('criteria_id', 'int');
 
-			if ($start)
+			$this->start			= $start ? $start : 0;
+			$this->criteria_id		= isset($criteria_id) && $criteria_id ? $criteria_id : '';
+
+			if(array_key_exists('b_account',$_POST) || array_key_exists('b_account',$_GET) )
 			{
-				$this->start=$start;
+				$this->b_account = $b_account;
 			}
-			else
+			if(array_key_exists('district_id',$_POST) || array_key_exists('district_id',$_GET) )
 			{
-				$this->start=0;
+				$this->district_id = $district_id;
 			}
 
 			if(isset($paid))
@@ -112,27 +118,23 @@
 			{
 				$this->order = $order;
 			}
-			if(array_key_exists('cat_id',$_POST))
+			if(array_key_exists('cat_id',$_POST) || array_key_exists('cat_id',$_GET))
 			{
 				$this->cat_id = $cat_id;
 			}
-			if(array_key_exists('status_id',$_POST))
+			if(array_key_exists('status_id',$_POST)  || array_key_exists('status_id',$_GET))
 			{
 				$this->status_id = $status_id;
 			}
-			if(array_key_exists('search_vendor',$_POST))
+			if(array_key_exists('wo_hour_cat_id',$_POST)  || array_key_exists('wo_hour_cat_id',$_GET))
 			{
-				$this->search_vendor = $search_vendor;
-			}
-			if(array_key_exists('wo_hour_cat_id',$_POST))
-			{
 				$this->wo_hour_cat_id = $wo_hour_cat_id;
 			}
-			if(array_key_exists('start_date',$_POST))
+			if(array_key_exists('start_date',$_POST) || array_key_exists('start_date',$_GET))
 			{
 				$this->start_date = $start_date;
 			}
-			if(array_key_exists('end_date',$_POST))
+			if(array_key_exists('end_date',$_POST) || array_key_exists('end_date',$_GET))
 			{
 				$this->end_date = $end_date;
 			}
@@ -148,13 +150,15 @@
 			$this->sort				= isset($data['sort']) ? $data['sort']: '';
 			$this->order			= isset($data['order']) ? $data['order']: '';
 			$this->cat_id			= isset($data['cat_id']) ? $data['cat_id']: '';
-			$this->search_vendor	= isset($data['search_vendor']) ? $data['search_vendor']: '';
 			$this->status_id		= isset($data['status_id']) ? $data['status_id']: '';
 			$this->wo_hour_cat_id	= isset($data['wo_hour_cat_id']) ? $data['wo_hour_cat_id']: '';
 			$this->start_date		= isset($data['start_date']) ? $data['start_date']: '';
 			$this->end_date			= isset($data['end_date']) ? $data['end_date']: '';
 			$this->b_group			= isset($data['b_group']) ? $data['b_group']: '';
 			$this->paid				= isset($data['paid']) ? $data['paid']: '';
+			$this->b_account		= isset($data['b_account']) ? $data['b_account']: '';
+			$this->district_id		= isset($data['district_id']) ? $data['district_id']: '';
+			$this->criteria_id		= isset($data['criteria_id'])?$data['criteria_id']:'';
 		}
 
 		function save_sessiondata($data)
@@ -223,16 +227,148 @@
 			return $this->bocommon->select_list($selected,$key_location_entries);
 		}
 
-		function read($start_date='',$end_date='',$allrows='')
+		function get_criteria_list($selected='')
 		{
-			$start_date	= $this->bocommon->date_to_timestamp($start_date);
-			$end_date	= $this->bocommon->date_to_timestamp($end_date);
+			$criteria = array
+			(
+				array
+				(
+					'id'	=> '1',
+					'name'	=> lang('project group')
+				),
+				array
+				(
+					'id'	=> '2',
+					'name'	=> lang('project id')
+				),
+				array
+				(
+					'id'	=> '3',
+					'name'	=> lang('workorder id')
+				),
+				array
+				(
+					'id'	=> '4',
+					'name'	=> lang('address')
+				),
 
+				array
+				(
+					'id'	=> '5',
+					'name'	=> lang('location code')
+				),
+				array
+				(
+					'id'	=> '6',
+					'name'	=> lang('title')
+				),
+				array
+				(
+					'id'	=> '7',
+					'name'	=> lang('vendor')
+				),
+				array
+				(
+					'id'	=> '8',
+					'name'	=> lang('vendor id')
+				),
+			);
+			return $this->bocommon->select_list($selected,$criteria);
+		}
+
+
+		function get_criteria($id='')
+		{
+			$criteria = array();
+			$criteria[1] = array
+			(
+				'field'		=> 'project_group',
+				'type'		=> 'int',
+				'matchtype' => 'exact',
+				'front' => '',
+				'back' => ''
+			);
+			$criteria[2] = array
+			(
+				'field'		=> 'fm_project.id',
+				'type'		=> 'int',
+				'matchtype' => 'exact',
+				'front' => '',
+				'back' => ''
+			);
+			$criteria[3] = array
+			(
+				'field'		=> 'fm_workorder.id',
+				'type'		=> 'int',
+				'matchtype' => 'exact',
+				'front' => '',
+				'back' => ''
+			);
+			$criteria[4] = array
+			(
+				'field'	=> 'fm_project.address',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'%",
+				'back' => "%'",
+			);
+			$criteria[5] = array
+			(
+				'field'	=> 'fm_project.location_code',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'",
+				'back' => "%'"
+			);
+			$criteria[6] = array
+			(
+				'field'	=> 'fm_workorder.title',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'%",
+				'back' => "%'"
+			);
+			$criteria[7] = array
+			(
+				'field'	=> 'fm_vendor.org_name',
+				'type'	=> 'varchar',
+				'matchtype' => 'like',
+				'front' => "'%",
+				'back' => "%'"
+			);
+			$criteria[8] = array
+			(
+				'field'	=> 'fm_vendor.id',
+				'type'	=> 'int',
+				'matchtype' => 'exact',
+				'front' => '',
+				'back' => ''
+			);
+
+			if($id)
+			{
+				return array($criteria[$id]);
+			}
+			else
+			{
+				return $criteria;
+			}			
+		}
+
+
+		function read($data = array())
+		{
+			$start_date	= $this->bocommon->date_to_timestamp($data['start_date']);
+			$end_date	= $this->bocommon->date_to_timestamp($data['end_date']);
+
+
 			$workorder = $this->so->read(array('start' => $this->start,'query' => $this->query,'sort' => $this->sort,'order' => $this->order,
 											'filter' => $this->filter,'cat_id' => $this->cat_id,'status_id' => $this->status_id,
-											'search_vendor' => $this->search_vendor,'wo_hour_cat_id' => $this->wo_hour_cat_id,
-											'start_date'=>$start_date,'end_date'=>$end_date,'allrows'=>$allrows,
-											'b_group'=>$this->b_group,'paid'=>$this->paid));
+											'wo_hour_cat_id' => $this->wo_hour_cat_id,
+											'start_date'=>$start_date,'end_date'=>$end_date,'allrows'=>$data['allrows'],
+											'b_group'=>$this->b_group,'paid'=>$this->paid,'b_account' => $this->b_account,
+											'district_id' => $this->district_id,'dry_run'=>$data['dry_run'], 'criteria' => $this->get_criteria($this->criteria_id)));
+			
 			$this->total_records = $this->so->total_records;
 
 			$dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
@@ -276,11 +412,11 @@
 
 			$workorder['b_account_name']	= $this->so->get_b_account_name($workorder['b_account_id']);
 
-			$config				= CreateObject('phpgwapi.config');
-			$config->read_repository();
+			$config				= CreateObject('phpgwapi.config','property');
+			$config->read();
 			$tax = 1+($config->config_data['fm_tax'])/100;
-			$workorder['calculation']	=number_format($workorder['calculation']*$tax, 2, ',', '');
-			$workorder['actual_cost']	=number_format(($workorder['act_mtrl_cost']+$workorder['act_vendor_cost']), 2, ',', '');
+			$workorder['calculation']	= $workorder['calculation'] * $tax;
+			$workorder['actual_cost']	= $workorder['act_mtrl_cost'] + $workorder['act_vendor_cost'];
 
 			$vfs = CreateObject('phpgwapi.vfs');
 			$vfs->override_acl = 1;
@@ -303,6 +439,52 @@
 				unset($workorder['files']);
 			}
 
+			$workorder['origin'] = $this->interlink->get_relation('property', '.project.workorder', $workorder_id, 'origin');
+			$workorder['target'] = $this->interlink->get_relation('property', '.project.workorder', $workorder_id, 'target');
+
+			if($workorder['location_code'])
+			{
+				$solocation 	= CreateObject('property.solocation', $this->bocommon);
+				$workorder['location_data'] = $solocation->read_single($workorder['location_code']);
+			}
+
+			if($workorder['tenant_id']>0)
+			{
+				$tenant_data=$this->bocommon->read_single_tenant($workorder['tenant_id']);
+				$workorder['location_data']['tenant_id']= $workorder['tenant_id'];
+				$workorder['location_data']['contact_phone']= $tenant_data['contact_phone'];
+				$workorder['location_data']['last_name']	= $tenant_data['last_name'];
+				$workorder['location_data']['first_name']	= $tenant_data['first_name'];
+			}
+			else
+			{
+				unset($workorder['location_data']['tenant_id']);
+				unset($workorder['location_data']['contact_phone']);
+				unset($workorder['location_data']['last_name']);
+				unset($workorder['location_data']['first_name']);
+			}
+
+			if($workorder['p_num'])
+			{
+				$soadmin_entity	= CreateObject('property.soadmin_entity');
+				$category = $soadmin_entity->read_single_category($workorder['p_entity_id'],$workorder['p_cat_id']);
+
+				$workorder['p'][$workorder['p_entity_id']]['p_num']=$workorder['p_num'];
+				$workorder['p'][$workorder['p_entity_id']]['p_entity_id']=$workorder['p_entity_id'];
+				$workorder['p'][$workorder['p_entity_id']]['p_cat_id']=$workorder['p_cat_id'];
+				$workorder['p'][$workorder['p_entity_id']]['p_cat_name'] = $category['name'];
+			}
+
+			$event_criteria = array
+			(
+				'appname'		=> 'property',
+				'location'		=> '.project.workorder',
+				'location_item_id'	=> $workorder_id
+			);
+
+			$events = execMethod('property.soevent.read', $event_criteria);
+			$workorder['event_id'] = $events ? $events[0]['id'] : '';
+
 			return $workorder;
 		}
 
@@ -310,8 +492,9 @@
 		{
 			$historylog	= CreateObject('property.historylog','workorder');
 			$history_array = $historylog->return_array(array('O'),array(),'','',$id);
+
 			$i=0;
-			while (is_array($history_array) && list(,$value) = each($history_array))
+			foreach ($history_array as $value) 
 			{
 
 				$record_history[$i]['value_date']	= $GLOBALS['phpgw']->common->show_date($value['datetime']);
@@ -325,7 +508,10 @@
 					case 'O': $type = lang('Opened');    break;
 					case 'A': $type = lang('Re-assigned'); break;
 					case 'P': $type = lang('Priority changed'); break;
-					case 'M': $type = lang('Sendt by email to'); break;
+					case 'M':
+						$type = lang('Sendt by email to');
+						$this->order_sent_adress = $value['new_value']; // in case we want to resend the order as an reminder
+						break;
 					case 'B': $type = lang('Budget changed'); break;
 					case 'CO': $type = lang('Initial Coordinator'); break;
 					case 'C': $type = lang('Coordinator changed'); break;
@@ -354,23 +540,46 @@
 					{
 						$record_history[$i]['value_new_value']	= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
 					}
+					if (! $value['old_value'])
+					{
+						$record_history[$i]['value_old_value']	= '';
+					}
+					else
+					{
+						$record_history[$i]['value_old_value']	= $GLOBALS['phpgw']->accounts->id2name($value['old_value']);
+					}
 				}
 				else if ($value['status'] == 'C' || $value['status'] == 'CO')
 				{
 					$record_history[$i]['value_new_value']	= $GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+					if (! $value['old_value'])
+					{
+						$record_history[$i]['value_old_value']	= '';
+					}
+					else
+					{
+						$record_history[$i]['value_old_value']	= $GLOBALS['phpgw']->accounts->id2name($value['old_value']);
+					}
 				}
 				else if ($value['status'] == 'T' || $value['status'] == 'TO')
 				{
 					$category 								= $this->cats->return_single($value['new_value']);
 					$record_history[$i]['value_new_value']	= $category[0]['name'];
+					if($value['old_value'])
+					{
+						$category 								= $this->cats->return_single($value['old_value']);
+						$record_history[$i]['value_old_value']	= $category[0]['name'];
+					}
 				}
 				else if ($value['status'] != 'O' && $value['new_value'])
 				{
 					$record_history[$i]['value_new_value']	= $value['new_value'];
+					$record_history[$i]['value_old_value']	= $value['old_value'];
 				}
 				else if ($value['status'] != 'B' && $value['new_value'])
 				{
-					$record_history[$i]['value_new_value']	= $value['new_value'];
+					$record_history[$i]['value_new_value']	=number_format($value['new_value'], 0, ',', ' ');
+					$record_history[$i]['value_old_value']	=number_format($value['old_value'], 0, ',', ' ');
 				}
 				else
 				{
@@ -387,6 +596,7 @@
 		{
 			$workorder['start_date']	= $this->bocommon->date_to_timestamp($workorder['start_date']);
 			$workorder['end_date']	= $this->bocommon->date_to_timestamp($workorder['end_date']);
+			$workorder['location_code'] = isset($workorder['location']) && $workorder['location'] ? implode('-',$workorder['location']) : '';
 
 			if ($action=='edit')
 			{
@@ -403,5 +613,5 @@
 		{
 			$this->so->delete($workorder_id);
 		}
+
 	}
-

Modified: people/sigurdne/modules/property/trunk/inc/class.custom_fields.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.custom_fields.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.custom_fields.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -5,17 +5,17 @@
 	 * @author Sigurd Nes <[email protected]>
 	 * @author Dave Hall dave.hall at skwashd.com
 	 * @copyright Copyright (C) 2003-2006 Free Software Foundation http://www.fsf.org/
-	 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3 or later
+	 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License v2 or later
 	 * @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	 * @package phpgroupware
 	 * @subpackage phpgwapi
-	 * @version $Id: class.custom_fields.inc.php 1114 2008-06-02 18:15:22Z sigurd $
+	 * @version $Id: class.custom_fields.inc.php 2642 2009-04-28 14:29:39Z sigurd $
 	 */
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -40,6 +40,7 @@
 	 */
 	class property_custom_fields extends phpgwapi_custom_fields
 	{
+
 		/**
 		 * Constructor
 		 *
@@ -61,10 +62,6 @@
 		 * @param ????  $view_only ????
 		 *
 		 * @return array values and definitions of custom attributes prepared for ui
-		 *
-		 * @internal this is a UI related method - WTF was it doing in an API logic class?
-		 * this is property specific code and so has been moved there!
-		 * this code needs some serious attention
 		 */
 		public function prepare($values, $appname, $location, $view_only='')
 		{
@@ -112,8 +109,10 @@
 				{
 					if($attributes['value'])
 					{
-						$contact_data				= $contacts->read_single_entry($attributes['value'],array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-						$attributes['contact_name']	= $contact_data[0]['n_family'] . ', ' . $contact_data[0]['n_given'];
+						$contact_data					= $contacts->read_single_entry($attributes['value'],array('fn','tel_work','email'));
+						$attributes['contact_name']		= $contact_data[0]['fn'];
+						$attributes['contact_email']	= $contact_data[0]['email'];
+						$attributes['contact_tel']		= $contact_data[0]['tel_work'];
 					}
 
 					$insert_record_values[]			= $attributes['name'];
@@ -198,6 +197,50 @@
 						}
 					}
 				}
+				else if($attributes['datatype'] == 'event')
+				{
+					// If the record is not saved - issue a warning
+					if(isset($values['id']) || $values['id'])
+					{
+						$attributes['item_id'] = $values['id'];
+					}
+					else if(isset($values['location_code']) || $values['location_code'])
+					{
+						$attributes['item_id'] = execMethod('property.solocation.get_item_id', $values['location_code']);
+					}
+					else
+					{
+						$attributes['warning']			= lang('Warning: the record has to be saved in order to plan an event');
+					}
+
+					if(isset($attributes['value']) && $attributes['value'])
+					{
+						$event = execMethod('property.soevent.read_single', $attributes['value']);
+						$attributes['descr']			= $event['descr'];
+						$attributes['enabled']			= $event['enabled'] ? lang('yes') : lang('no');
+						$attributes['lang_enabled']		= lang('enabled');
+
+						$id = "property{$location}::{$values['id']}::{$attributes['id']}";
+						$job = execMethod('phpgwapi.asyncservice.read', $id);
+
+						$attributes['next']				= $GLOBALS['phpgw']->common->show_date($job[$id]['next'],$dateformat);
+						$attributes['lang_next_run']	= lang('next run');
+						unset($event);
+						unset($id);
+						unset($job);
+					}
+					$insert_record_values[]			= $attributes['name'];
+					$lookup_link					= $GLOBALS['phpgw']->link('/index.php',array(
+						'menuaction'	=> $this->_appname.'.uievent.edit',
+						'location'		=> $location,
+						'attrib_id'		=> $attributes['id'],
+						'item_id'		=> isset($attributes['item_id']) ? $attributes['item_id'] : '',
+						'id'			=> isset($attributes['value']) && $attributes['value'] ? $attributes['value'] : ''));
+
+					$lookup_functions[$m]['name']	= 'lookup_'. $attributes['name'] .'()';
+					$lookup_functions[$m]['action']	= 'Window1=window.open('."'" . $lookup_link ."'" .',"Search","width=800,height=500,toolbar=no,scrollbars=yes,resizable=yes");';
+					$m++;
+				}
 				else if (isset($entity['attributes'][$i]) && $entity['attributes'][$i]['datatype']!='I' && $entity['attributes'][$i]['value'])
 				{
 					$entity['attributes'][$i]['value'] = stripslashes($entity['attributes'][$i]['value']);
@@ -226,4 +269,164 @@
 
 			return $values;
 		}
+
+		function prepare_for_db($table, $values_attribute, $id = 0)
+		{	
+			$id = (int)$id;
+			$data = array();
+			if (isset($values_attribute) AND is_array($values_attribute))
+			{
+				foreach($values_attribute as $entry)
+				{
+					if($entry['datatype']!='AB' && $entry['datatype']!='VENDOR' && $entry['datatype']!='event')
+					{
+						if($entry['datatype'] == 'C' || $entry['datatype'] == 'T' || $entry['datatype'] == 'V' || $entry['datatype'] == 'link')
+						{
+							$entry['value'] = $this->_db->db_addslashes($entry['value']);
+						}
+
+						if($entry['datatype'] == 'pwd' && $entry['value'] && $entry['value2'])
+						{
+							if($entry['value'] || $entry['value2'])
+							{
+								if($entry['value'] == $entry['value2'])
+								{
+									$data['value_set'][$entry['name']]	= md5($entry['value']);
+								}
+								else
+								{
+									$data['receipt']['error'][]=array('msg'=>lang('Passwords do not match!'));
+								}
+							}
+						}
+						else
+						{
+							$data['value_set'][$entry['name']]	= isset($entry['value'])?$entry['value']:'';
+						}
+					}
+
+					if($entry['history'] == 1)
+					{
+						if($id)
+						{
+							$this->_db->query("SELECT {$entry['name']} FROM $table WHERE id = {$id}",__LINE__,__FILE__);
+							$this->_db->next_record();
+							$old_value = $this->_db->f($entry['name']);
+							if($entry['value'] != $old_value)
+							{
+								$data['history_set'][$entry['attrib_id']] = array
+								('
+									value'	=> $entry['value'],
+									'date'	=> phpgwapi_datetime::date_to_timestamp($entry['date'])
+								);
+							}
+						}
+						else
+						{
+								$data['history_set'][$entry['attrib_id']] = $entry['value'];
+						}
+					}
+				}
+			}
+			return $data;
+		}
+
+		function translate_value($values, $location_id, $location_count = 0)
+		{
+			$choice_table = 'phpgw_cust_choice';
+			$attribute_table = 'phpgw_cust_attribute';
+			$attribute_filter = " location_id = {$location_id}";
+			$contacts = CreateObject('phpgwapi.contacts');
+//_debug_array($values);
+			$location = array();
+			$ret = array();
+			$j=0;
+			foreach ($values as $row)
+			{
+				foreach ($row as $field => $data)
+				{
+					if($field == 'location_code')
+					{
+						$location = split('-',$data['value']);
+					}
+
+					if(($data['datatype']=='R' || $data['datatype']=='LB') && $data['value'])
+					{
+						$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$data['attrib_id']. "  AND id=" . $data['value'];
+						$this->_db->query($sql);
+						$this->_db->next_record();
+						$ret[$j][$field] =  $this->_db->f('value');
+					}
+					else if($data['datatype']=='AB' && $data['value'])
+					{
+						$contact_data	= $contacts->read_single_entry($data['value'],array('fn'));
+						$ret[$j][$field] =  $contact_data[0]['fn'];
+					}
+					else if($data['datatype']=='VENDOR' && $data['value'])
+					{
+						$sql="SELECT org_name FROM fm_vendor where id={$data['value']}";
+						$this->_db->query($sql);
+						$this->_db->next_record();
+						$ret[$j][$field] =  $this->_db->f('org_name',true);
+					}
+					else if($data['datatype']=='CH' && $data['value'])
+					{
+						$ch= unserialize($data['value']);
+						if (isset($ch) AND is_array($ch))
+						{
+							for ($k=0;$k<count($ch);$k++)
+							{
+								$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id= {$data['attrib_id']} AND id=" . $ch[$k];
+								$this->_db->query($sql);
+								while ($this->_db->next_record())
+								{
+									$ch_value[]=$this->_db->f('value');
+								}
+							}
+							$ret[$j][$field] =  @implode(",", $ch_value);
+							unset($ch_value);
+						}
+					}
+					else if($data['datatype']=='D' && $data['value'])
+					{
+						$ret[$j][$field] =  date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($data['value']));
+					}
+					else if($data['datatype']=='timestamp' && $data['value'])
+					{
+						$ret[$j][$field] =  date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],$data['value']);
+					}
+					else if($data['datatype']=='link' && $data['value'])
+					{
+						$ret[$j][$field] =  phpgw::safe_redirect($data['value']);
+					}
+					else if($data['datatype']=='user' && $data['value'])
+					{
+						$ret[$j][$field] =   $GLOBALS['phpgw']->accounts->get($data['value'])->__toString();
+					}
+					else if($data['datatype']=='pwd' && $data['value'])
+					{
+						$ret[$j][$field] =   lang('yes');
+					}
+					else
+					{
+						$ret[$j][$field] =  stripslashes($data['value']);
+					}
+
+					if($location)
+					{
+						if(!$location_count)
+						{
+							$location_count = count($location);
+						}
+						for ($m=0;$m < $location_count ; $m++)
+						{
+							$ret[$j]['loc' . ($m+1)] = $location[$m];
+							$ret[$j]['query_location']['loc' . ($m+1)]=implode('-', array_slice($location, 0, ($m + 1)));
+						}
+					}
+				}
+				$j++;
+			}
+			return $ret;
+		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.custom_functions.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.custom_functions.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.custom_functions.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -40,7 +40,7 @@
 			'index' => true
 		);
 
-		function property_custom_functions()
+		function __construct()
 		{
 			$GLOBALS['phpgw_info']['flags']['noheader'] = true;
 			$GLOBALS['phpgw_info']['flags']['nonavbar'] = true;
@@ -65,7 +65,8 @@
 			}
 			else
 			{
-				$data = unserialize(urldecode($_GET['data']));
+				$data = unserialize(urldecode(phpgw::get_var('data')));
+
 				$data = phpgw::clean_value($data);
 				if(!isset($data['function']))
 				{
@@ -82,7 +83,7 @@
 				return;
 			}
 
-			$file = PHPGW_SERVER_ROOT . "/property/inc/cron/{$function}.php";
+			$file = PHPGW_SERVER_ROOT . "/property/inc/cron/{$GLOBALS['phpgw_info']['user']['domain']}/{$function}.php";
 
 			if (is_file($file))
 			{
@@ -90,5 +91,9 @@
 				$custom = new $function;
 				$custom->pre_run($data);
 			}
+			else
+			{
+				echo "no such file: path_to_phpgw_server_root/property/inc/cron/{$GLOBALS['phpgw_info']['user']['domain']}/{$function}.php";
+			}
 		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.excel.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.excel.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.excel.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -26,6 +26,6 @@
  	* @version $Id$
 	*/
 
-	require_once(PHPGW_APP_INC . '/excel/Worksheet.php');
-	require_once(PHPGW_APP_INC . '/excel/Workbook.php');
+	require_once PHPGW_SERVER_ROOT . '/property/inc/excel/Worksheet.php';
+	require_once PHPGW_SERVER_ROOT . '/property/inc/excel/Workbook.php';
 

Modified: people/sigurdne/modules/property/trunk/inc/class.historylog.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.historylog.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.historylog.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -135,10 +135,11 @@
 			}
 
 			$this->db->query("insert into $this->table (history_record_id,"
-				. "history_appname,history_owner,history_status,history_new_value,history_timestamp $attrib_id_field $detail_id_field) "
+				. "history_appname,history_owner,history_status,history_new_value, history_old_value, history_timestamp $attrib_id_field $detail_id_field) "
 				. "values ('$record_id','" . $this->appname . "','"
 				. $this->account . "','$status','"
-				. $this->db->db_addslashes($new_value) . "','" . $timestamp
+				. $this->db->db_addslashes($new_value) . "','"
+				. $this->db->db_addslashes($old_value) . "','" . $timestamp
 				. "' $attrib_id_value $detail_id_value)",__LINE__,__FILE__);
 		}
 
@@ -191,22 +192,21 @@
 				. $this->appname . "' and history_record_id='$record_id' $filter $only_show_filter "
 				. "$orderby",__LINE__,__FILE__);
 
+			$return_values = array();
 			while ($this->db->next_record())
 			{
-				$return_values[] = array(
+				$return_values[] = array
+				(
 					'id'         => $this->db->f('history_id'),
 					'record_id'  => $this->db->f('history_record_id'),
 					'owner'      => $GLOBALS['phpgw']->accounts->id2name($this->db->f('history_owner')),
 //					'status'     => lang($this->types[$this->db->f('history_status')]),
 					'status'     => preg_replace('/ /','',$this->db->f('history_status')),
-					'new_value'  => $this->db->f('history_new_value'),
+					'new_value'  => htmlspecialchars_decode($this->db->f('history_new_value',true)),
+					'old_value'  => htmlspecialchars_decode($this->db->f('history_old_value',true)),
 					'datetime'   => strtotime($this->db->f('history_timestamp'))
 				);
 			}
-
-			if(isset ($return_values))
-			{
 				return $return_values;
 			}
 		}
-	}

Added: people/sigurdne/modules/property/trunk/inc/class.html2pdf.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.html2pdf.inc.php	                        (rev 0)
+++ people/sigurdne/modules/property/trunk/inc/class.html2pdf.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -0,0 +1,41 @@
+<?php
+	/**
+	 * phpGroupWare
+	 *
+	 * @author Sigurd Nes <[email protected]>
+	 * @copyright Copyright (C) 2007,2008 Free Software Foundation, Inc. http://www.fsf.org/
+	 * @license http://www.fsf.org/licenses/gpl.html GNU General Public License
+	 * @package phpgroupware
+	 * @subpackage property
+	 * @category utilities
+ 	 * @version $Id$
+	 */
+
+	/*
+	   This program 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.
+
+	   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+	 */
+
+	/**
+	* Document me!
+	*
+	* @package property
+	* @subpackage utilities
+	*/
+
+	/**
+	* Include the html2pdf class
+	* @see html2pdf
+	*/
+	require_once PHPGW_SERVER_ROOT . '/property/inc/html2pdf/html2pdf.class.php';
+


Property changes on: people/sigurdne/modules/property/trunk/inc/class.html2pdf.inc.php
___________________________________________________________________
Added: svn:keywords
   + Id Revision
Added: svn:eol-style
   + native

Modified: people/sigurdne/modules/property/trunk/inc/class.import.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.import.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.import.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -24,7 +24,7 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage agreement
- 	* @version $Id: class.import.inc.php 1043 2008-05-26 17:19:31Z sigurd $
+ 	* @version $Id: class.import.inc.php 2129 2009-01-18 20:19:40Z sigurd $
 	*/
 
 	/**
@@ -38,7 +38,7 @@
 		(
 		);
 
-		function property_import()
+		function __construct()
 		{
 			$GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
 			$this->bocommon		= CreateObject('property.bocommon');

Modified: people/sigurdne/modules/property/trunk/inc/class.interlink.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.interlink.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.interlink.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -9,13 +9,13 @@
 	* @package phpgroupware
 	* @subpackage property
 	* @category core
- 	* @version $Id: class.interlink.inc.php 732 2008-02-10 16:21:14Z sigurd $
+ 	* @version $Id: class.interlink.inc.php 3537 2009-09-09 09:33:24Z sigurd $
 	*/
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -52,10 +52,14 @@
 //			$this->_account			=& $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->_db 				=& $GLOBALS['phpgw']->db;
 			$this->boadmin_entity	= CreateObject('property.boadmin_entity');
+			$this->soadmin_entity				= & $this->boadmin_entity->so;
+			$this->soadmin_entity->type			= & $this->boadmin_entity->type;
+			$this->soadmin_entity->type_app		= & $this->boadmin_entity->type_app;
 
-//			$this->_like 			=& $this->db->like;
-//			$this->_join 			=& $this->db->join;
-//			$this->_left_join		=& $this->db->left_join;
+
+//			$this->_like 			=& $this->_db->like;
+			$this->_join 			=& $this->_db->join;
+//			$this->_left_join		=& $this->_db->left_join;
 		}
 
 		/**
@@ -110,6 +114,7 @@
 				foreach ($entry['data'] as &$data)
 				{
 					$data['link'] = $this->get_relation_link($linkend_location, $data['id']);
+					$data['statustext'] = $this->get_relation_info($linkend_location, $data['id']);
 				}
 			}
 			return $relation;
@@ -163,19 +168,22 @@
 
 		public function get_location_name($location)
 		{
-			if(substr($location,1,6)=='entity')
-			{
-				$type		= explode(".",$location);
-				$entity_id	= $type[2];
-				$cat_id		= $type[3];
 
-				$entity_category = $this->boadmin_entity->read_single_category($entity_id,$cat_id);
-				return $entity_category['name'];
-			}
-			else
+			$location = ltrim($location, '.');
+			$parts = explode('.', $location);
+//			list($type, $entity_id, $cat_id) = split('[.]', $location);
+			$this->boadmin_entity->type = $parts[0];
+			switch( $parts[0] )
 			{
-				return lang($location);
+				case 'entity':
+				case 'catch':
+					$entity_category = $this->boadmin_entity->read_single_category($parts[1],$parts[2]);
+					$location_name =  $entity_category['name'];					
+					break;
+				default:
+					$location_name = lang($location);
 			}
+			return $location_name;
 		}
 		/**
 		* Get relation of the interlink
@@ -186,25 +194,34 @@
 		* @return string the linkt to the the related item
 		*/
 
-		public function get_relation_link($linkend_location, $id)
+		public function get_relation_link($linkend_location, $id, $function = 'edit')
 		{
 			$link = array();
+
+			if(is_array($linkend_location))
+			{
 			$type = $linkend_location['location'];
+			}
+			else
+			{
+				$type = $linkend_location;
+			}
+
 			if($type == '.ticket')
 			{
 				$link = array('menuaction' => 'property.uitts.view', 'id' => $id);
 			}
 			else if($type == '.project.workorder')
 			{
-				$link = array('menuaction' => 'property.uiworkorder.view', 'id' => $id);
+				$link = array('menuaction' => "property.uiworkorder.{$function}", 'id' => $id);
 			}
 			else if($type == '.project.request')
 			{
-				$link = array('menuaction' => 'property.uirequest.view', 'id' => $id);
+				$link = array('menuaction' => "property.uirequest.{$function}", 'id' => $id);
 			}
 			else if($type == '.project')
 			{
-				$link = array('menuaction' => 'property.uiproject.view', 'id' => $id);
+				$link = array('menuaction' => "property.uiproject.{$function}", 'id' => $id);
 			}
 			else if( substr($type, 1, 6) == 'entity' )
 			{
@@ -213,16 +230,106 @@
 				$cat_id		= $type[3];
 				$link =	array
 				(
-					'menuaction'	=> 'property.uientity.view',
+					'menuaction'	=> "property.uientity.{$function}",
 					'entity_id'		=> $entity_id,
 					'cat_id'		=> $cat_id,
 					'id'			=> $id
 				);
 			}
+			else if( substr($type, 1, 5) == 'catch' )
+			{
+				$type		= explode('.',$type);
+				$entity_id	= $type[2];
+				$cat_id		= $type[3];
+				$link =	array
+				(
+					'menuaction'	=> "property.uientity.{$function}",
+					'type'			=> 'catch',
+					'entity_id'		=> $entity_id,
+					'cat_id'		=> $cat_id,
+					'id'			=> $id
+				);
+			}
 			return $GLOBALS['phpgw']->link('/index.php',$link);	
 		}
 
 		/**
+		* Get additional info of the linked item
+		*
+		* @param array   $linkend_location the location
+		* @param integer $id			   the id of the referenced item
+		*
+		* @return string info of the linked item
+		*/
+
+		public function get_relation_info($linkend_location, $id)
+		{
+			$id = (int)$id;
+			$type = $linkend_location['location'];
+			if($type == '.ticket')
+			{
+				$this->_db->query("SELECT status FROM fm_tts_tickets WHERE id = {$id}",__LINE__,__FILE__);
+				$this->_db->next_record();
+				$status_code = $this->_db->f('status');
+
+				static $status_text;
+				if(!$status_text)
+				{
+					$status_text = execMethod('property.botts.get_status_text');
+				}
+				return $status_text[$status_code];
+			}
+			else if($type == '.project.workorder')
+			{
+				$this->_db->query("SELECT fm_workorder_status.descr as status FROM fm_workorder {$this->_join} fm_workorder_status ON fm_workorder.status = fm_workorder_status.id WHERE fm_workorder.id = {$id}",__LINE__,__FILE__);
+				$this->_db->next_record();
+				return $this->_db->f('status');
+			}
+			else if($type == '.project.request')
+			{
+				$this->_db->query("SELECT fm_request_status.descr as status FROM fm_request {$this->_join} fm_request_status ON fm_request.status = fm_request_status.id WHERE fm_request.id = {$id}",__LINE__,__FILE__);				
+				$this->_db->next_record();
+				return $this->_db->f('status');
+			}
+			else if($type == '.project')
+			{		
+				$this->_db->query("SELECT fm_project_status.descr as status FROM fm_project {$this->_join} fm_project_status ON fm_project.status = fm_project_status.id WHERE fm_project.id = {$id}",__LINE__,__FILE__);
+				$this->_db->next_record();
+				return $this->_db->f('status');
+			}
+			else if( substr($type, 1, 6) == 'entity' )
+			{
+				$type		= explode('.',$type);
+				$entity_id	= $type[2];
+				$cat_id		= $type[3];
+				$metadata = $this->_db->metadata("fm_entity_{$entity_id}_{$cat_id}");
+				if(isset($metadata['status']))
+				{
+					$sql = "SELECT status FROM fm_entity_{$entity_id}_{$cat_id} WHERE id = {$id}";
+					$this->_db->query($sql,__LINE__,__FILE__);
+					$this->_db->next_record();
+					$status_id = (int)$this->_db->f('status');
+					$location_id	= $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}");
+
+					$sql = "SELECT phpgw_cust_choice.value as status FROM phpgw_cust_attribute"
+					. " {$this->_join} phpgw_cust_choice ON phpgw_cust_attribute.location_id = phpgw_cust_choice.location_id "
+					. " AND phpgw_cust_attribute.id = phpgw_cust_choice.attrib_id WHERE phpgw_cust_attribute.column_name = 'status'"
+					. " AND phpgw_cust_choice.id = {$status_id} AND phpgw_cust_attribute.location_id = {$location_id}";
+					$this->_db->query($sql,__LINE__,__FILE__);
+					$this->_db->next_record();
+					return $this->_db->f('status');
+				}
+			}
+			else if( substr($type, 1, 5) == 'catch' )
+			{
+				$type		= explode('.',$type);
+				$entity_id	= $type[2];
+				$cat_id		= $type[3];
+// Not set
+			}
+		}
+
+		/**
 		* Get entry date of the related item
 		*
 		* @param string  $appname  		  the application name for the location
@@ -238,10 +345,6 @@
 		public function get_child_date($appname, $origin_location, $target_location, $id, $entity_id = '', $cat_id = '')
 		{
 			$dateformat 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-			if($cat_id)
-			{
-				$soadmin_entity	= CreateObject('property.soadmin_entity');
-			}
 
 			$location1_id	= $GLOBALS['phpgw']->locations->get_id($appname, $origin_location);
 			$location2_id	= $GLOBALS['phpgw']->locations->get_id($appname, $target_location);
@@ -265,7 +368,7 @@
 				$entry['link']=$this->get_relation_link(array('location'=>$target_location), $entry['target_id']);
 				if($cat_id)
 				{
-					$entry['descr']=$soadmin_entity->read_category_name($entity_id,$cat_id);
+					$entry['descr']=$this->soadmin_entity->read_category_name($entity_id,$cat_id);
 				}
 				else
 				{

Modified: people/sigurdne/modules/property/trunk/inc/class.menu.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.menu.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.menu.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -13,7 +13,7 @@
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -38,7 +38,7 @@
 		 *
 		 * @return array available menus for the current user
 		 */
-		public function get_menu()
+		public function get_menu($type='')
 		{
 			$incoming_app = $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$GLOBALS['phpgw_info']['flags']['currentapp'] = 'property';
@@ -103,7 +103,7 @@
 					'tenant_cats'	=> array
 					(
 						'text'	=> lang('Tenant Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tenant', 'menu_selection' => 'admin::property::tenant::tenant_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tenant') )
 					),
 					'tenant_global_cats'	=> array
 					(
@@ -118,7 +118,7 @@
 					'claims_cats'	=> array
 					(
 						'text'	=> lang('Tenant Claim Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tenant_claim', 'menu_selection' => 'admin::property::tenant::claims_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tenant_claim') )
 					)
 				);
 
@@ -127,7 +127,7 @@
 					'vendor_cats'	=> array
 					(
 						'text'	=> lang('Vendor Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'vendor', 'menu_selection' => 'admin::property::vendor::vendor_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'vendor') )
 					),
 					'vendor_global_cats'	=> array
 					(
@@ -145,7 +145,7 @@
 					'owner_cats'	=> array
 					(
 						'text'	=> lang('Owner Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'owner', 'menu_selection' => 'admin::property::owner::owner_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'owner') )
 					),
 					'owner_attribs'	=> array
 					(
@@ -159,32 +159,37 @@
 					'accounting_cats'	=> array
 					(
 						'text'	=> lang('Accounting Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'b_account', 'menu_selection' => 'admin::property::accounting::accounting_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'b_account') )
 					),
-					'accounting_dim_b'	=> array
+					'accounting_dimb'	=> array
 					(
 						'text'	=> lang('Accounting dim b'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'dim_b', 'menu_selection' => 'admin::property::accounting::accounting_dim_b') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'dimb') )
 					),
-					'accounting_dim_d'	=> array
+					'dimb_roles'	=> array
 					(
+						'text'	=> lang('dimb roles'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uicategories.index', 'appname' => 'property.invoice.dimb', 'global_cats' => 'true', 'menu_selection' => 'admin::property::accounting::dimb_roles') )
+					),
+					'accounting_dimd'	=> array
+					(
 						'text'	=> lang('Accounting dim d'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'dim_d', 'menu_selection' => 'admin::property::accounting::accounting_dim_d') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'dimd') )
 					),
 					'accounting_tax'	=> array
 					(
 						'text'	=> lang('Accounting tax'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tax', 'menu_selection' => 'admin::property::accounting::accounting_tax') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tax') )
 					),
 					'voucher_cats'	=> array
 					(
 						'text'	=> lang('Accounting voucher category'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'voucher_cat', 'menu_selection' => 'admin::property::accounting::voucher_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'voucher_cat') )
 					),
 					'voucher_type'	=> array
 					(
 						'text'	=> lang('Accounting voucher type'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'voucher_type', 'menu_selection' => 'admin::property::accounting::voucher_type') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'voucher_type') )
 					)
 				);
 
@@ -193,7 +198,7 @@
 					'agreement_status'	=> array
 					(
 						'text'	=> lang('Agreement status'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'agreement_status', 'menu_selection' => 'admin::property::agreement::agreement_status') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'agreement_status') )
 					),
 					'agreement_attribs'	=> array
 					(
@@ -203,7 +208,7 @@
 					'service_agree_cats'	=> array
 					(
 						'text'	=> lang('service agreement categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 's_agreement', 'menu_selection' => 'admin::property::agreement::service_agree_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 's_agreement') )
 					),
 					'service_agree_attribs'	=> array
 					(
@@ -218,7 +223,7 @@
 					'rental_agree_cats'	=> array
 					(
 						'text'	=> lang('rental agreement categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'r_agreement', 'menu_selection' => 'admin::property::agreement::rental_agree_cats') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'r_agreement') )
 					),
 					'rental_agree_attribs'	=> array
 					(
@@ -242,7 +247,7 @@
 					);
 					$admin_children_location_children["category_{$location['id']}"] = array
 					(
-						'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uicategory.index', 'type' => 'location', 'type_id' => $location['id'], 'menu_selection' => "admin::property::location::location::category_{$location['id']}") ),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uicategory.index', 'type' => 'location', 'type_id' => $location['id']) ),
 						'text'	=> $location['name'] . ' ' . lang('categories'),
 					);
 				}
@@ -252,12 +257,12 @@
 					'street'	=> array
 					(
 						'text'	=> lang('Street'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'street', 'menu_selection' => 'admin::property::location::street') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'street') )
 					),
 					'district'	=> array
 					(
 						'text'	=> lang('District'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'district', 'menu_selection' => 'admin::property::location::district') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'district') )
 					),
 					'town'	=> array
 					(
@@ -274,6 +279,11 @@
 					(
 						'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.config') ),
 						'text'	=> lang('Config')
+					),
+					'update_location' => array
+					(
+						'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uilocation.update_location') ),
+						'text'	=> lang('update location')
 					)
 				);
 
@@ -311,13 +321,18 @@
 					'workorder_detail'	=> array
 					(
 						'text'	=> lang('Workorder Detail Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'wo_hours', 'menu_selection' => 'admin::property::workorder_detail') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'wo_hours') )
 					),
 					'ticket_cats'	=> array
 					(
 						'text'	=> lang('Ticket Categories'),
 						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uicategories.index', 'appname' => 'property.ticket', 'global_cats' => 'true', 'menu_selection' => 'admin::property::ticket_cats') )
 					),
+					'ticket_status'	=> array
+					(
+						'text'	=> lang('Ticket status'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'ticket_status') )
+					),
 					'tenant'	=> array
 					(
 						'text'	=> lang('Tenant'),
@@ -339,18 +354,18 @@
 					),
 					'doc_cats'	=> array
 					(
-						'text'	=> lang('Document Categories'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'document', 'menu_selection' => 'admin::property::doc_cats') )
+						'text'	=> lang('document categories'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'admin.uicategories.index', 'appname' => 'property.document', 'global_cats' => 'true') )
 					),
 					'building_part'	=> array
 					(
 						'text'	=> lang('Building Part'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'building_part') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'building_part') )
 					),
 					'tender'	=> array
 					(
 						'text'	=> lang('Tender chapter'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tender_chapter', 'menu_selection' => 'admin::property::tender') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'tender_chapter') )
 					),
 					'id_control'	=> array
 					(
@@ -370,44 +385,54 @@
 					'request_status'	=> array
 					(
 						'text'	=> lang('Request status'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'request_status') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'request_status') )
 					),
 					'request_condition'	=> array
 					(
 						'text'	=> lang('Request condition_type'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'r_condition_type', 'menu_selection' => 'admin::property::request_condition') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'r_condition_type') )
 					),
 					'workorder_status'	=> array
 					(
 						'text'	=> lang('Workorders status'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'workorder_status') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'workorder_status') )
 					),
+					'project_status'	=> array
+					(
+						'text'	=> lang('project status'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'project_status') )
+					),
+					'project_group'	=> array
+					(
+						'text'	=> lang('project group'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'project_group') )
+					),
 					'agreement'	=> array
 					(
 						'text'	=> lang('Agreement'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'agreement_status') ),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'agreement_status') ),
 						'image'		=> array( 'property', 'agreement' ),
 						'children'	=> $admin_children_agreement
 					),
 					'document_status'	=> array
 					(
 						'text'	=> lang('Document Status'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'document_status', 'menu_selection' => 'admin::property::document_status') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'document_status') )
 					),
 					'unit'	=> array
 					(
 						'text'	=> lang('Unit'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_2.index', 'type' => 'unit', 'menu_selection' => 'admin::property::unit') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'unit') )
 					),
 					'key_location'	=> array
 					(
 						'text'	=> lang('Key location'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_3.index', 'type' => 'key_location') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'key_location') )
 					),
 					'branch'	=> array
 					(
 						'text'	=> lang('Branch'),
-						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uistandard_3.index', 'type' => 'branch') )
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'branch') )
 					),
 					'accounting'	=> array
 					(
@@ -425,6 +450,11 @@
 						'text'	=> lang('Async services'),
 						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiasync.index') )
 					),
+					'event_action'	=> array
+					(
+						'text'	=> lang('event action'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'event_action') )
+					),
 					'list_functions'	=> array
 					(
 						'text'	=> lang('Admin custom functions'),
@@ -439,6 +469,11 @@
 					(
 						'text'		=> lang('responsible matrix'),
 						'url'		=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uiresponsible.index') ),
+					),
+					'pending_action_type'	=> array
+					(
+						'text'		=> lang('pending action type'),
+						'url'	=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'property.uicategory.index', 'type' => 'pending_action_type') )
 					)
 				);
 			}
@@ -468,6 +503,8 @@
 			}
 
 			$menus['navigation'] = array();
+
+//			$acl->set_account_id($GLOBALS['phpgw_info']['user']['account_id'], true);
 			if ( $acl->check('.location', PHPGW_ACL_READ, 'property') )
 			{
 				$children = array();
@@ -587,12 +624,6 @@
 							'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uitemplate.index')),
 							'text'	=> lang('template'),
 							'image'		=> array('property', 'project_template')
-						),
-						'claim'		=> array
-						(
-							'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uitenant_claim.index')),
-							'text'	=> lang('Tenant claim'),
-							'image'		=> array('property', 'project_tenant_claim')
 						)
 					)
 				);
@@ -663,6 +694,12 @@
 						(
 							'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiactor.index', 'role'=> 'tenant')),
 							'text'	=> lang('Tenant')
+						),
+						'claim'		=> array
+						(
+							'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uitenant_claim.index')),
+							'text'	=> lang('Tenant claim'),
+							'image'		=> array('property', 'project_tenant_claim')
 						)
 					), $children)
 				);
@@ -677,11 +714,6 @@
 					'image'		=> array('property', 'budget'),
 					'children'	=> array
 					(
-						'basis'		=> array
-						(
-							'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uibudget.basis')),
-							'text'	=> lang('basis')
-						),
 						'budget'	=> array
 						(
 							'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uibudget.index')),
@@ -694,6 +726,15 @@
 						)
 					)
 				);
+
+				if ( $acl->check('.budget.basis', PHPGW_ACL_READ, 'property') )
+				{
+					$menus['navigation']['budget']['children']['basis'] = array
+					(
+						'url'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uibudget.basis')),
+						'text'	=> lang('basis')
+					);
+				}
 			}
 
 			if ( $acl->check('.agreement', PHPGW_ACL_READ, 'property') )
@@ -816,8 +857,9 @@
 						);
 					}
 
+					if ($type != 'horisontal')
+					{
 					$cat_list = $entity->read_category(array('allrows'=>true,'entity_id'=>$entry['id']));
-
 					foreach($cat_list as $category)
 					{
 						if ( $acl->check(".entity.{$entry['id']}.{$category['id']}", PHPGW_ACL_READ, 'property') )
@@ -831,6 +873,7 @@
 					}
 				}
 			}
+			}
 			unset($entity_list);
 			unset($entity);
 			$GLOBALS['phpgw_info']['flags']['currentapp'] = $incoming_app;

Modified: people/sigurdne/modules/property/trunk/inc/class.ods.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.ods.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.ods.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -8,13 +8,13 @@
 	 * @package phpgroupware
 	 * @subpackage property
 	 * @category utilities
- 	 * @version $Id: $
+ 	 * @version $Id: class.ods.inc.php 2588 2009-04-14 11:00:02Z sigurd $
 	 */
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,

Modified: people/sigurdne/modules/property/trunk/inc/class.soXport.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soXport.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soXport.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -39,19 +39,15 @@
 		var $total_records = 0;
 		var $bilagsnr;
 
-		function property_soXport($useacl=true)
+		function __construct()
 		{
-
 			$GLOBALS['phpgw_info']['flags']['currentapp']	=	'property';
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
-			$this->bocommon		= CreateObject('property.bocommon');
 			$this->soinvoice	= CreateObject('property.soinvoice',true);
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->join		= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->datetimeformat	= $this->bocommon->datetimeformat;
-			$this->like		= $this->bocommon->like;
+			$this->db 			= & $GLOBALS['phpgw']->db;
+			$this->like 		= & $this->db->like;
+			$this->join 		= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->datetimeformat	= $this->db->datetime_format();
 			$this->account_id 	= $GLOBALS['phpgw_info']['user']['account_id'];
 		}
 
@@ -62,7 +58,7 @@
 			{
 				return;
 			}
-			$sql = "select mva as tax_code from fm_location1 where loc1=" . substr($dima,0,4);
+			$sql = "select mva as tax_code from fm_location1 where loc1='" . substr($dima,0,4) . "'";
 			$this->db->query($sql);
 			$this->db->next_record();
 
@@ -117,7 +113,7 @@
 			{
 				return;
 			}
-			$sql = "select kostra_id from fm_location1 where loc1=" . substr($dima,0,4);
+			$sql = "select kostra_id from fm_location1 where loc1='" . substr($dima,0,4) . "'";
 			$this->db->query($sql);
 			$this->db->next_record();
 
@@ -190,9 +186,12 @@
 
 		function get_project($id)
 		{
-			$this->db->query("select project_id from fm_workorder where id='$id'");
+			$id = (int) $id;
+			$sql = "SELECT project_group FROM fm_workorder"
+			. " $this->join fm_project ON fm_workorder.project_id = fm_project.id WHERE fm_workorder.id={$id}";
+			$this->db->query($sql, __LINE__, __FILE__);
 			$this->db->next_record();
-			return $this->db->f('project_id');
+			return $this->db->f('project_group');
 		}
 
 		function check_spbudact_code($id)
@@ -249,18 +248,19 @@
 						false,
 						false,
 						$fields['item_type'],
-						$fields['item_id']
+						$fields['item_id'],
+						$fields['external_ref']
 						);
 
 					$bilagsnr	= $fields['bilagsnr'];
 
-					$values	= $this->bocommon->validate_db_insert($values);
+					$values	= $this->db->validate_insert($values);
 
 					$sql= "INSERT INTO fm_ecobilag (project_id,kostra_id,pmwrkord_code,bilagsnr,splitt,kildeid,kidnr,typeid,fakturadato,"
 					. " forfallsdato,regtid,artid,spvend_code,dimb,oppsynsmannid,saksbehandlerid,budsjettansvarligid,"
 					. " fakturanr,spbudact_code,loc1,dima,dimd,mvakode,periode,merknad,oppsynsigndato,saksigndato,"
-					. " budsjettsigndato,utbetalingsigndato,item_type,item_id,belop,godkjentbelop)"
-					. " VALUES ($values," . $this->bocommon->moneyformat($fields['belop']) . "," . $this->bocommon->moneyformat($fields['godkjentbelop']) . ")";
+					. " budsjettsigndato,utbetalingsigndato,item_type,item_id,external_ref, belop,godkjentbelop)"
+					. " VALUES ($values," . $this->db->money_format($fields['belop']) . "," . $this->db->money_format($fields['godkjentbelop']) . ")";
 
 					$this->db->query($sql,__LINE__,__FILE__);
 
@@ -310,22 +310,23 @@
 				$data['utbetalingid'],
 				$data['utbetalingsigndato'],
 				$data['filnavn'],
-				date("Y-m-d G:i:s"),
+				date($this->db->datetime_format()),
 				$data['item_type'],
 				$data['item_id'],
+				$data['external_ref']
 				);
 
-			$values	= $this->bocommon->validate_db_insert($values);
+			$values	= $this->db->validate_insert($values);
 
 			$sql="INSERT INTO fm_ecobilagoverf (id,bilagsnr,kidnr,typeid,kildeid,project_id,kostra_id,pmwrkord_code,fakturadato,"
 				. " periode,forfallsdato,fakturanr,spbudact_code,regtid,artid,spvend_code,dima,loc1,"
 				. " dimb,mvakode,dimd,oppsynsmannid,saksbehandlerid,budsjettansvarligid,oppsynsigndato,saksigndato,"
-				. " budsjettsigndato,merknad,splitt,utbetalingid,utbetalingsigndato,filnavn,overftid,item_type,item_id,"
+				. " budsjettsigndato,merknad,splitt,utbetalingid,utbetalingsigndato,filnavn,overftid,item_type,item_id,external_ref,"
 				. " belop,godkjentbelop,ordrebelop)"
 				. "values ($values, "
-				. $this->bocommon->moneyformat($data['belop']) . ","
-				. $this->bocommon->moneyformat($data['godkjentbelop']) . ","
-				. $this->bocommon->moneyformat($data['ordrebelop']) . ")";
+				. $this->db->money_format($data['belop']) . ","
+				. $this->db->money_format($data['godkjentbelop']) . ","
+				. $this->db->money_format($data['ordrebelop']) . ")";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 //echo 'sql ' . $sql.'<br>';

Modified: people/sigurdne/modules/property/trunk/inc/class.soactor.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soactor.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soactor.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -24,7 +24,7 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage admin
- 	* @version $Id$
+ 	* @version $Id$
 	*/
 
 	/**
@@ -38,29 +38,29 @@
 
 		function property_soactor()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db			= $this->bocommon->new_db();
-			$this->db2			= $this->bocommon->new_db($this->db);
+			$this->custom 		= createObject('property.custom_fields');
+			$this->db           = & $GLOBALS['phpgw']->db;
 
-			$this->join			= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like			= $this->bocommon->like;
+			$this->join			= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				$start	= (isset($data['start'])?$data['start']:0);
-				$filter	= (isset($data['filter'])?$data['filter']:'none');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$cat_id = (isset($data['cat_id'])?$data['cat_id']:'');
-				$allrows 	= (isset($data['allrows'])?$data['allrows']:'');
-				$member_id 	= (isset($data['member_id'])?$data['member_id']:0);
+				$start		= isset($data['start'])?$data['start']:0;
+				$filter		= isset($data['filter']) && $data['filter'] ?$data['filter']:'none';
+				$query		= isset($data['query'])?$data['query']:'';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order		= isset($data['order'])?$data['order']:'';
+				$cat_id		= isset($data['cat_id'])?$data['cat_id']:'';
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
+				$member_id 	= isset($data['member_id']) && $data['member_id'] ? $data['member_id']:0;
+				$dry_run	= isset($data['dry_run']) ? $data['dry_run'] : '';
 			}
 
 			$sql = $this->bocommon->fm_cache('sql_actor_' . $this->role);
@@ -74,6 +74,8 @@
 
 			if(!$sql)
 			{
+				$cols_return = array();
+				$uicols = array();
 				$cols = $entity_table . ".*,$category_table.descr as category";
 
 				$cols_return[] 				= 'id';
@@ -81,24 +83,32 @@
 				$uicols['name'][]			= 'id';
 				$uicols['descr'][]			= lang('ID');
 				$uicols['statustext'][]		= lang('ID');
+				$uicols['datatype'][]		= false;
+				$uicols['attib_id'][]		= false;
 
 				$cols_return[] 				= 'id';
 				$uicols['input_type'][]		= 'hidden';
 				$uicols['name'][]			= 'id';
 				$uicols['descr'][]			= false;
 				$uicols['statustext'][]		= false;
+				$uicols['datatype'][]		= false;
+				$uicols['attib_id'][]		= false;
 
 				$cols_return[] 				= 'category';
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]			= 'category';
 				$uicols['descr'][]			= lang('category');
 				$uicols['statustext'][]		= lang('category');
+				$uicols['datatype'][]		= false;
+				$uicols['attib_id'][]		= false;
 
 				$cols_return[] 				= 'entry_date';
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]			= 'entry_date';
 				$uicols['descr'][]			= lang('entry date');
 				$uicols['statustext'][]		= lang('entry date');
+				$uicols['datatype'][]		= false;
+				$uicols['attib_id'][]		= false;
 
 				$paranthesis .='(';
 
@@ -119,8 +129,6 @@
 				$cols_return					= $this->bocommon->fm_cache('cols_return_actor_' . $this->role);
 			}
 
-			$i	= count($uicols['name']);
-
 			$user_columns=isset($GLOBALS['phpgw_info']['user']['preferences']['property']['actor_columns_' . $this->role])?$GLOBALS['phpgw_info']['user']['preferences']['property']['actor_columns_' . $this->role]:'';
 			$user_column_filter = '';
 			if (isset($user_columns) AND is_array($user_columns) AND $user_columns[0])
@@ -130,26 +138,18 @@
 
 			$this->db->query("SELECT * FROM $attribute_table WHERE list=1 AND $attribute_filter $user_column_filter ORDER BY attrib_sort ASC");
 
-
 			while ($this->db->next_record())
 			{
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]			= $this->db->f('column_name');
 				$uicols['descr'][]			= $this->db->f('input_text');
 				$uicols['statustext'][]		= $this->db->f('statustext');
-				$uicols['datatype'][$i]		= $this->db->f('datatype');
-				$cols_return_extra[]= array(
-					'name'	=> $this->db->f('column_name'),
-					'datatype'	=> $this->db->f('datatype'),
-					'attrib_id'	=> $this->db->f('id')
-				);
-
-				$i++;
+				$uicols['datatype'][]		= $this->db->f('datatype');
+				$uicols['attib_id'][]		= $this->db->f('id');
 			}
 
 			$this->uicols	= $uicols;
 
-//_debug_array($cols_return_extra);
 			if ($order)
 			{
 				$ordermethod = " order by $entity_table.$order $sort";
@@ -205,10 +205,13 @@
 			$_querymethod = array();
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
+				$query = $this->db->db_addslashes($query);
 
-			//	$filtermethod .= " $where $entity_table.id ='" . (int)$query . "'";
+				if(ctype_digit($query))
+				{
+					$_querymethod[]= "$entity_table.id =" . (int)$query;
+				}
+
 				$where= 'AND';
 
 				$this->db->query("SELECT * FROM $attribute_table WHERE $attribute_filter AND search='1'");
@@ -223,7 +226,7 @@
 					{
 						if(ctype_digit($query))
 						{
-							$_querymethod[]= "$entity_table." . $this->db->f('column_name') . " = " . intval($query);
+							$_querymethod[]= "$entity_table." . $this->db->f('column_name') . '=' . (int)$query;
 						}
 					}
 					else:
@@ -241,9 +244,13 @@
 
 			$sql .= " $filtermethod $querymethod";
 //echo $sql;
+			$values = array();
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			if(!$dry_run)
+			{
+				$this->db->query('SELECT count(*)' . substr($sql,strripos($sql,'from')),__LINE__,__FILE__);
+				$this->db->next_record();
+				$this->total_records = $this->db->f(0);
 			if(!$allrows)
 			{
 				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@@ -253,88 +260,29 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
+				$cols_return = $uicols['name'];
 			$j=0;
-			$n=count($cols_return);
-//_debug_array($cols_return);
-			$contacts			= CreateObject('phpgwapi.contacts');
 
+				$dataset = array();
 			while ($this->db->next_record())
 			{
-				for ($i=0;$i<$n;$i++)
+					foreach($cols_return as $key => $field)
 				{
-					$actor_list[$j][$cols_return[$i]] = $this->db->f($cols_return[$i]);
-					$actor_list[$j]['grants'] = (int)$grants[$this->db->f('owner_id')];
+						$dataset[$j][$field] = array
+						(
+							'value'		=> $this->db->f($field),
+							'datatype'	=> $uicols['datatype'][$key],
+							'attrib_id'	=> $uicols['attib_id'][$key]
+						);
 				}
-
-				for ($i=0;$i<count($cols_return_extra);$i++)
-				{
-					$value='';
-					$value=$this->db->f($cols_return_extra[$i]['name']);
-
-					if(($cols_return_extra[$i]['datatype']=='R' || $cols_return_extra[$i]['datatype']=='LB') && $value)
-					{
-						$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $value;
-						$this->db2->query($sql);
-						$this->db2->next_record();
-						$actor_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('value');
+					$j++;				
 					}
-					else if($cols_return_extra[$i]['datatype']=='AB' && $value)
-					{
-						$contact_data	= $contacts->read_single_entry($value,array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-						$actor_list[$j][$cols_return_extra[$i]['name']]	= $contact_data[0]['n_family'] . ', ' . $contact_data[0]['n_given'];
 
-/*						$sql="SELECT org_name FROM phpgw_addressbook where id=$value";
-						$this->db2->query($sql);
-						$this->db2->next_record();
-						$actor_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('org_name');
-*/
-					}
-					else if($cols_return_extra[$i]['datatype']=='VENDOR' && $value)
-					{
-						$sql="SELECT org_name FROM fm_vendor where id=$value";
-						$this->db2->query($sql);
-						$this->db2->next_record();
-						$actor_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('org_name');
-					}
-					else if($cols_return_extra[$i]['datatype']=='CH' && $value)
-					{
-						$ch= unserialize($value);
+				$values = $this->custom->translate_value($dataset, $location_id);
 
-						if (isset($ch) AND is_array($ch))
-						{
-							for ($k=0;$k<count($ch);$k++)
-							{
-								$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
-								$this->db2->query($sql);
-								while ($this->db2->next_record())
-								{
-									$ch_value[]=$this->db2->f('value');
-								}
-							}
-							$actor_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
-							unset($ch_value);
-						}
-					}
-					else if($cols_return_extra[$i]['datatype']=='D' && $value)
-					{
-						$actor_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($value));
-					}
-					else if($cols_return_extra[$i]['datatype']=='timestamp' && $value)
-					{
-						$actor_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],$value);
-					}
-					else if($cols_return_extra[$i]['datatype']=='link' && $value)
-					{
-						$actor_list[$j][$cols_return_extra[$i]['name']]= phpgw::safe_redirect($value);
-					}
-					else
-					{
-						$actor_list[$j][$cols_return_extra[$i]['name']]=$value;
-					}
-				}
-				$j++;
+				return $values;
 			}
-			return $actor_list;
+			return $values;
 		}
 
 		function read_single($actor_id, $values = array())

Modified: people/sigurdne/modules/property/trunk/inc/class.soadmin.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soadmin.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soadmin.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,15 +34,12 @@
 
 	class property_soadmin
 	{
-		function property_soadmin()
+		function __construct()
 		{
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-
-			$this->join		= $this->bocommon->join;
-			$this->like		= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function get_initials($id)

Modified: people/sigurdne/modules/property/trunk/inc/class.soadmin_entity.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soadmin_entity.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soadmin_entity.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,17 +35,27 @@
 	class property_soadmin_entity
 	{
 		var $grants;
+		var $type = 'entity';
+		var $type_app;
+		var $bocommon;
 
-		function property_soadmin_entity($entity_id='',$cat_id='')
+		function __construct($entity_id='', $cat_id='', $bocommon = '')
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
+
+			if(!$bocommon || !is_object($bocommon))
+			{
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			}
+			else
+			{
+				$this->bocommon = $bocommon;
+			}
 
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
+
 			if($entity_id && $cat_id)
 			{
 				$this->category_name	= $this->read_category_name($entity_id,$cat_id);
@@ -56,18 +66,12 @@
 		{
 			if(is_array($data))
 			{
-				if (isset($data['start']))
-				{
-					$start=$data['start'];
-				}
-				else
-				{
-					$start=0;
-				}
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$allrows = (isset($data['allrows'])?$data['allrows']:'');
+				$start		= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$query		= isset($data['query']) ? $data['query'] : '';
+				$sort		= isset($data['sort']) ? $data['sort'] : 'DESC';
+				$order		= isset($data['order']) ? $data['order'] : '';
+				$type		= isset($data['type']) && $data['type'] ? $data['type'] : $this->type;
+				$allrows	= isset($data['allrows']) ? $data['allrows'] : '';
 			}
 
 			if ($order)
@@ -80,21 +84,19 @@
 				$ordermethod = ' order by id asc';
 			}
 
-			$table = 'fm_entity';
+			$table = "fm_{$type}";
 
 			$querymethod = '';
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
+				$query = $this->db->db_addslashes($query);
 				$querymethod = " where name $this->like '%$query%' or descr $this->like '%$query%'";
 			}
 
 			$sql = "SELECT * FROM $table $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql, __LINE__, __FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -105,6 +107,8 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
+			$entity = array();
+
 			while ($this->db->next_record())
 			{
 				$entity[] = array
@@ -128,6 +132,7 @@
 				$order = (isset($data['order'])?$data['order']:'');
 				$allrows = (isset($data['allrows'])?$data['allrows']:'');
 				$entity_id = (isset($data['entity_id'])?$data['entity_id']:'');
+				$type		= isset($data['type']) && $data['type'] ? $data['type'] : $this->type;
 			}
 
 			if ($order)
@@ -140,7 +145,7 @@
 				$ordermethod = ' order by id asc';
 			}
 
-			$table = 'fm_entity_category';
+			$table = "fm_{$type}_category";
 
 			$querymethod = '';
 			if($query)
@@ -151,8 +156,8 @@
 
 			$sql = "SELECT * FROM $table WHERE entity_id=$entity_id $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -180,21 +185,23 @@
 		function read_single($id)
 		{
 
-			$sql = "SELECT * FROM fm_entity  where id='$id'";
+			$id = (int)$id;
+			$sql = "SELECT * FROM fm_{$this->type} WHERE id={$id}";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$entity = array();
 			if ($this->db->next_record())
 			{
 				$entity['id']				= $this->db->f('id');
-				$entity['name']				= $this->db->f('name');
-				$entity['descr']			= $this->db->f('descr');
+				$entity['name']				= $this->db->f('name',true);
+				$entity['descr']			= $this->db->f('descr',true);
 				$entity['location_form']	= $this->db->f('location_form');
 				$entity['lookup_entity']	= unserialize($this->db->f('lookup_entity'));
 				$entity['documentation']	= $this->db->f('documentation');
 			}
 
-			$sql = "SELECT location FROM fm_entity_lookup where entity_id=$id AND type='lookup'";
+			$sql = "SELECT location FROM fm_{$this->type}_lookup WHERE entity_id={$id} AND type='lookup'";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
@@ -203,7 +210,7 @@
 				$entity['include_entity_for'][] = $this->db->f('location');
 			}
 
-			$sql = "SELECT location FROM fm_entity_lookup where entity_id=$id AND type='start'";
+			$sql = "SELECT location FROM fm_{$this->type}_lookup WHERE entity_id={$id} AND type='start'";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
@@ -215,12 +222,13 @@
 			return $entity;
 		}
 
-		function read_single_category($entity_id,$cat_id)
+		function read_single_category($entity_id, $cat_id)
 		{
-			$sql = 'SELECT * FROM fm_entity_category where entity_id =' . (int)$entity_id . ' AND id = ' . (int)$cat_id;
+			$sql = "SELECT * FROM fm_{$this->type}_category WHERE entity_id =" . (int)$entity_id . ' AND id = ' . (int)$cat_id;
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$category = array();
 			if ($this->db->next_record())
 			{
 				$category['id']			= $this->db->f('id');
@@ -234,24 +242,26 @@
 				$category['loc_link']	= $this->db->f('loc_link');
 				$category['start_project']	= $this->db->f('start_project');
 				$category['start_ticket']	= $this->db->f('start_ticket');
-				return $category;
+				$category['jasperupload']	= $this->db->f('jasperupload');
 			}
+			return $category;
 		}
 
 		function read_category_name($entity_id,$cat_id)
 		{
-			$sql = 'SELECT * FROM fm_entity_category where entity_id =' . (int)$entity_id . ' AND id = ' . (int)$cat_id;
+			$sql = "SELECT * FROM fm_{$this->type}_category WHERE entity_id =" . (int)$entity_id . ' AND id = ' . (int)$cat_id;
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->db->next_record();
-			return $this->db->f('name');
+			return $this->db->f('name', true);
 		}
 
 		function add_entity($entity)
 		{
+			
 			$entity['name'] = $this->db->db_addslashes($entity['name']);
 			$entity['descr'] = $this->db->db_addslashes($entity['descr']);
 
-			$entity['id'] = $this->bocommon->next_id('fm_entity');
+			$entity['id'] = $this->bocommon->next_id("fm_{$this->type}");
 
 			$values= array(
 				$entity['id'],
@@ -261,12 +271,12 @@
 				$entity['documentation']
 				);
 
-			$values	= $this->bocommon->validate_db_insert($values);
+			$values	= $this->db->validate_insert($values);
 
-			$this->db->query("INSERT INTO fm_entity (id,name, descr,location_form,documentation) "
+			$this->db->query("INSERT INTO fm_{$this->type} (id,name, descr,location_form,documentation) "
 				. "VALUES ($values)",__LINE__,__FILE__);
 
-			$GLOBALS['phpgw']->locations->add('.entity.' . $entity['id'], $entity['name'], 'property', true);
+			$GLOBALS['phpgw']->locations->add(".{$this->type}." . $entity['id'], $entity['name'], $this->type_app[$this->type], true);
 
 			$receipt['id']= $entity['id'];
 
@@ -276,10 +286,10 @@
 
 		function get_default_column_def()
 		{
-
-			$fd=array();
+			$fd = array();
 			$fd['id'] = array('type' => 'int', 'precision' => 4, 'nullable' => false);
 			$fd['num'] = array('type' => 'varchar', 'precision' => 16, 'nullable' => false);
+
 			$fd['p_num'] = array('type' => 'varchar', 'precision' => 16, 'nullable' => true);
 			$fd['p_entity_id'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
 			$fd['p_cat_id'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
@@ -295,7 +305,8 @@
 			$fd['address'] = array('type' => 'varchar', 'precision' => 150, 'nullable' => true);
 			$fd['tenant_id'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
 			$fd['contact_phone'] = array('type' => 'varchar', 'precision' => 30, 'nullable' => true);
-			$fd['status'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
+	//		$fd['status'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
+
 			$fd['entry_date'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
 			$fd['user_id'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
 
@@ -309,7 +320,7 @@
 			$values['name'] = $this->db->db_addslashes($values['name']);
 			$values['descr'] = $this->db->db_addslashes($values['descr']);
 
-			$values['id'] = $this->bocommon->next_id('fm_entity_category',array('entity_id'=>$values['entity_id']));
+			$values['id'] = $this->bocommon->next_id("fm_{$this->type}_category", array('entity_id'=>$values['entity_id']));
 
 			$values_insert= array(
 				$values['entity_id'],
@@ -323,15 +334,16 @@
 				$values['fileupload'],
 				$values['loc_link'],
 				$values['start_project'],
-				$values['start_ticket']
+				$values['start_ticket'],
+				$values['jasperupload']
 				);
 
-			$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+			$values_insert	= $this->db->validate_insert($values_insert);
 
-			$this->db->query("INSERT INTO fm_entity_category (entity_id,id,name, descr,prefix,lookup_tenant,tracking,location_level,fileupload,loc_link,start_project,start_ticket) "
+			$this->db->query("INSERT INTO fm_{$this->type}_category (entity_id,id,name, descr,prefix,lookup_tenant,tracking,location_level,fileupload,loc_link,start_project,start_ticket,jasperupload) "
 				. "VALUES ($values_insert)",__LINE__,__FILE__);
 
-			$location_id = $GLOBALS['phpgw']->locations->add(".entity.{$values['entity_id']}.{$values['id']}", $values['name'], 'property', true, "fm_entity_{$values['entity_id']}_{$values['id']}");
+			$location_id = $GLOBALS['phpgw']->locations->add(".{$this->type}.{$values['entity_id']}.{$values['id']}", $values['name'],  $this->type_app[$this->type], true, "fm_{$this->type}_{$values['entity_id']}_{$values['id']}");
 
 			$receipt['id']= $values['id'];
 
@@ -340,12 +352,20 @@
 			$fd = $this->get_default_column_def();
 
 			$pk[]= 'id';
-			$table			= "fm_entity_{$values['entity_id']}_{$values['id']}";
 
-			if(($this->oProc->CreateTable($table,array('fd' => $fd,'pk' => $pk,'fk' => $fk,'ix' => array('location_code'),'uc' => array()))))
+			$ix = array();
+			
+			if( $this->type == 'entity' )
 			{
+				$ix =  array('location_code');
+			}
 
-				$values_insert= array(
+			$table			= "fm_{$this->type}_{$values['entity_id']}_{$values['id']}";
+
+			if(($this->oProc->CreateTable($table,array('fd' => $fd,'pk' => $pk,'fk' => $fk,'ix' => $ix,'uc' => array()))))
+			{
+
+	/*			$values_insert= array(
 					$location_id,
 					1,
 					'status',
@@ -356,12 +376,12 @@
 					'true'
 					);
 
-				$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+				$values_insert	= $this->db->validate_insert($values_insert);
 
 				$this->db->query("INSERT INTO phpgw_cust_attribute (location_id,id,column_name,input_text,statustext,datatype,attrib_sort,nullable) "
 					. "VALUES ($values_insert)",__LINE__,__FILE__);
+	*/
 
-
 				$receipt['message'][] = array('msg'	=> lang('table %1 has been saved',$table));
 				$this->db->transaction_commit();
 			}
@@ -374,7 +394,7 @@
 				}
 				else
 				{
-					$this->db->query("DELETE FROM fm_entity_category WHERE id=" . $values['id'] . " AND entity_id=" . $values['entity_id'],__LINE__,__FILE__);
+					$this->db->query("DELETE FROM fm_{$this->type}_category WHERE id=" . $values['id'] . " AND entity_id=" . $values['entity_id'],__LINE__,__FILE__);
 					unset($receipt['id']);
 				}
 			}
@@ -391,7 +411,7 @@
 
 			if (!$receipt['error'])
 			{
-				$table = 'fm_entity';
+				$table = "fm_{$this->type}";
 
 				$entity['name'] = $this->db->db_addslashes($entity['name']);
 				$entity['descr'] = $this->db->db_addslashes($entity['descr']);
@@ -409,31 +429,31 @@
 				'documentation'	=> $entity['documentation']
 				);
 
-				$value_set	= $this->bocommon->validate_db_update($value_set);
+				$value_set	= $this->db->validate_update($value_set);
 
 				$this->db->transaction_begin();
 
 				$this->db->query("UPDATE $table set $value_set WHERE id=" . $entity['id'],__LINE__,__FILE__);
 
-				$GLOBALS['phpgw']->locations->update_description(".entity.{$entity['id']}", $entity['name'], 'property');
+				$GLOBALS['phpgw']->locations->update_description(".{$this->type}.{$entity['id']}", $entity['name'],  $this->type_app[$this->type]);
 
-				$this->db->query("DELETE FROM fm_entity_lookup WHERE type='lookup' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
+				$this->db->query("DELETE FROM fm_{$this->type}_lookup WHERE type='lookup' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
 				if (isset($entity['include_entity_for']) AND is_array($entity['include_entity_for']))
 				{
 					foreach($entity['include_entity_for'] as $location)
 					{
-						$this->db->query("INSERT INTO fm_entity_lookup (entity_id,location,type)"
+						$this->db->query("INSERT INTO fm_{$this->type}_lookup (entity_id,location,type)"
 						. "VALUES (" .$entity['id'] . ",'$location','lookup' )",__LINE__,__FILE__);
 					}
 				}
 
-				$this->db->query("DELETE FROM fm_entity_lookup WHERE type='start' AND entity_id=" . $entity['id'],__LINE__,__FILE__);
+				$this->db->query("DELETE FROM fm_{$this->type}_lookup WHERE type='start' AND entity_id=" . (int)$entity['id'],__LINE__,__FILE__);
 
 				if (isset($entity['start_entity_from']) AND is_array($entity['start_entity_from']))
 				{
 					foreach($entity['start_entity_from'] as $location)
 					{
-						$this->db->query("INSERT INTO fm_entity_lookup (entity_id,location,type)"
+						$this->db->query("INSERT INTO fm_{$this->type}_lookup (entity_id,location,type)"
 						. "VALUES (" .$entity['id'] . ",'$location','start' )",__LINE__,__FILE__);
 					}
 				}
@@ -460,7 +480,7 @@
 
 			if (!isset($receipt['error']))
 			{
-				$table = 'fm_entity_category';
+				$table = "fm_{$this->type}_category";
 
 				$entity['name'] = $this->db->db_addslashes($entity['name']);
 				$entity['descr'] = $this->db->db_addslashes($entity['descr']);
@@ -475,14 +495,15 @@
 					'fileupload'	=> $entity['fileupload'],
 					'loc_link'		=> $entity['loc_link'],
 					'start_project'	=> $entity['start_project'],
-					'start_ticket'	=> $entity['start_ticket']
+					'start_ticket'	=> $entity['start_ticket'],
+					'jasperupload'	=> $entity['jasperupload']
 					);
 
-				$value_set	= $this->bocommon->validate_db_update($value_set);
+				$value_set	= $this->db->validate_update($value_set);
 
 				$this->db->query("UPDATE $table set $value_set WHERE entity_id=" . $entity['entity_id']. " AND id=" . $entity['id'],__LINE__,__FILE__);
 
-				$GLOBALS['phpgw']->locations->update_description(".entity.{$entity['entity_id']}.{$entity['id']}", $entity['name'], 'property');
+				$GLOBALS['phpgw']->locations->update_description(".{$this->type}.{$entity['entity_id']}.{$entity['id']}", $entity['name'],  $this->type_app[$this->type]);
 
 				$receipt['message'][] = array('msg'=> lang('entity has been edited'));
 			}
@@ -496,17 +517,18 @@
 
 		function delete_entity($id)
 		{
+			$id = (int) $id;
 			$category_list=$this->read_category(array('entity_id'=>$id));
 			$locations = array();
-			$locations[] = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$id}");
-			$subs = $GLOBALS['phpgw']->locations->get_subs('property', ".entity.{$id}");
+			$locations[] = $GLOBALS['phpgw']->locations->get_id( $this->type_app[$this->type], ".{$this->type}.{$id}");
+			$subs = $GLOBALS['phpgw']->locations->get_subs( $this->type_app[$this->type], ".{$this->type}.{$id}");
 			if (is_array($subs) && count($subs))
 			{
 				$locations = array_merge($locations, array_keys($subs));
 			}
 
-			$this->db->query("DELETE FROM fm_entity WHERE id={$id}",__LINE__,__FILE__);
-			$this->db->query("DELETE FROM fm_entity_category WHERE entity_id={$id}",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_{$this->type} WHERE id={$id}",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_{$this->type}_category WHERE entity_id={$id}",__LINE__,__FILE__);
 			$this->db->query('DELETE FROM phpgw_cust_attribute WHERE location_id IN (' . implode(',', $locations) . ')',__LINE__,__FILE__);
 			$this->db->query('DELETE FROM phpgw_locations WHERE location_id IN (' . implode(',', $locations) . ')',__LINE__,__FILE__);
 			$this->db->query('DELETE FROM phpgw_acl WHERE location_id IN (' . implode(',', $locations) . ')',__LINE__,__FILE__);
@@ -516,7 +538,7 @@
 
 				foreach($category_list as $entry)
 				{
-					$this->oProc->DropTable('fm_entity_' . $id . '_' . $entry['id']);
+					$this->oProc->DropTable("fm_{$this->type}_{$id}_{$entry['id']}");
 				}
 			}
 
@@ -528,23 +550,23 @@
 
 			$this->db->transaction_begin();	
 
-			$this->oProc->DropTable('fm_entity_' . $entity_id . '_' . $id);
+			$this->oProc->DropTable("fm_{$this->type}_{$entity_id}_{$id}");
 
-			$location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$id}");
+			$location_id = $GLOBALS['phpgw']->locations->get_id( $this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$id}");
 
-			$this->db->query("DELETE FROM fm_entity_category WHERE entity_id= $entity_id AND id= $id",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_{$this->type}_category WHERE entity_id= {$entity_id} AND id= {$id}",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM phpgw_cust_attribute WHERE location_id = {$location_id}",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM phpgw_locations WHERE location_id  = {$location_id}",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM phpgw_acl WHERE  location_id  = {$location_id}",__LINE__,__FILE__);
-			$this->db->query("DELETE FROM fm_entity_history WHERE history_appname = 'entity_{$entity_id}_{$id}'",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_{$this->type}_history WHERE history_appname = '{$this->type}_{$entity_id}_{$id}'",__LINE__,__FILE__);
 
 			$this->db->transaction_commit();
 		}
 
 		function get_table_def($entity_id,$cat_id)
 		{
-			$location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}");
-			$table = 'fm_entity_' . $entity_id . '_' . $cat_id;
+			$location_id = $GLOBALS['phpgw']->locations->get_id( $this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");
+			$table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
 			$metadata = $this->db->metadata($table);
 
 			if(isset($this->db->adodb))
@@ -600,7 +622,7 @@
 
 		function delete_history($entity_id, $cat_id, $attrib_id)
 		{
-			$this->db->query("DELETE FROM fm_entity_history WHERE history_appname = 'entity_" . $entity_id  . '_' . $cat_id . "' AND history_attrib_id = $attrib_id",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_{$this->type}_history WHERE history_appname = '{$this->type}_{$entity_id}_{$cat_id}' AND history_attrib_id = {$attrib_id}",__LINE__,__FILE__);
 		}
 
 		function init_process()

Modified: people/sigurdne/modules/property/trunk/inc/class.soadmin_location.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soadmin_location.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soadmin_location.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,14 +34,12 @@
 
 	class property_soadmin_location
 	{
-		function property_soadmin_location()
+		function __construct()
 		{
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-
-			$this->join		= $this->bocommon->join;
-			$this->like		= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function reset_fm_cache()
@@ -59,7 +57,6 @@
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
-
 			}
 			else
 			{
@@ -169,22 +166,26 @@
 		function read_single($id)
 		{
 
+			$id = (int) $id;
 			$table = 'fm_location_type';
 
-			$sql = "SELECT * FROM $table  where id='$id'";
+			$sql = "SELECT * FROM $table  where id={$id}";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$standard = array();
 			if ($this->db->next_record())
 			{
-				$standard['id']			= $this->db->f('id');
-				$standard['name']		= $this->db->f('name');
-				$standard['descr']		= $this->db->f('descr');
-				$standard['list_info']	= unserialize($this->db->f('list_info'));
-				$standard['list_address']	= $this->db->f('list_address');
-
-				return $standard;
+				$standard = array
+				(
+					'id'			=> $this->db->f('id'),
+					'name'			=> $this->db->f('name'),
+					'descr'			=> $this->db->f('descr'),
+					'list_info'		=> $this->db->f('list_info',true),
+					'list_address'	=> $this->db->f('list_address')
+				);
 			}
+			return $standard;
 		}
 
 		function add($standard)
@@ -193,7 +194,7 @@
 			$standard['name'] = $this->db->db_addslashes($standard['name']);
 			$standard['descr'] = $this->db->db_addslashes($standard['descr']);
 
-			$standard['id'] = $this->bocommon->next_id('fm_location_type');
+			$standard['id'] = $this->db->next_id('fm_location_type');
 
 			$receipt['id']= $standard['id'];
 
@@ -271,7 +272,7 @@
 			$default_attrib['column_name'][]= 'remark';
 			$default_attrib['type'][]='T';
 			$default_attrib['precision'][] = false;
-			$default_attrib['nullable'][] ='false';
+			$default_attrib['nullable'][] ='True';
 			$default_attrib['input_text'][] ='Remark';
 			$default_attrib['statustext'][] ='Remark';
 			$default_attrib['attrib_sort'][] =2;
@@ -288,6 +289,40 @@
 			$default_attrib['attrib_sort'][] ='';
 			$default_attrib['custom'][] ='';
 
+			$j++;
+			$default_attrib['id'][]= $j;
+			$default_attrib['column_name'][]= 'area_gross';
+			$default_attrib['type'][]='N';
+			$default_attrib['precision'][] = false;
+			$default_attrib['nullable'][] ='True';
+			$default_attrib['input_text'][] ='gross area';
+			$default_attrib['statustext'][] ='Sum of the areas included within the outside face of the exterior walls of a building.';
+			$default_attrib['attrib_sort'][] =3;
+			$default_attrib['custom'][] =1;
+
+			$j++;
+			$default_attrib['id'][]= $j;
+			$default_attrib['column_name'][]= 'area_net';
+			$default_attrib['type'][]='N';
+			$default_attrib['precision'][] = false;
+			$default_attrib['nullable'][] ='True';
+			$default_attrib['input_text'][] ='Net area';
+			$default_attrib['statustext'][] ='The wall-to-wall floor area of a room.';
+			$default_attrib['attrib_sort'][] =4;
+			$default_attrib['custom'][] =1;
+
+			$j++;
+			$default_attrib['id'][]= $j;
+			$default_attrib['column_name'][]= 'area_usable';
+			$default_attrib['type'][]='N';
+			$default_attrib['precision'][] = false;
+			$default_attrib['nullable'][] ='True';
+			$default_attrib['input_text'][] ='Usable area';
+			$default_attrib['statustext'][] ='Generally measured from "paint to paint" inside the permanent walls and to the middle of partitions separating rooms.';
+			$default_attrib['attrib_sort'][] =5;
+			$default_attrib['custom'][] =1;
+
+
 			$fd=array();
 			$fd['location_code'] = array('type' => 'varchar', 'precision' => 25, 'nullable' => false);
 
@@ -334,6 +369,9 @@
 			$fd['remark'] = array('type' => 'text', 'nullable' => true);
 			$fd['status'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
 			$fd['change_type'] = array('type' => 'int', 'precision' => 4, 'nullable' => true);
+			$fd['area_gross'] = array('type' => 'decimal','precision' => '20','scale' => '2','nullable' => True,'default' => '0.00');
+			$fd['area_net'] = array('type' => 'decimal','precision' => '20','scale' => '2','nullable' => True,'default' => '0.00');
+			$fd['area_usable'] = array('type' => 'decimal','precision' => '20','scale' => '2','nullable' => True,'default' => '0.00');
 
 			$ix = array('location_code');
 			$uc = array();
@@ -341,7 +379,7 @@
 			$fd_history = $fd;
 			$fd_history['exp_date'] = array('type' => 'timestamp','nullable' => true,'default' => 'current_timestamp');
 
-			$add_columns_in_tables=array('fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
+			$add_columns_in_tables = $this->get_tables_to_alter();
 
 			$this->db->transaction_begin();
 
@@ -364,6 +402,7 @@
 					$this->oProc->AddColumn($add_columns_in_tables[$i],'loc'. $standard['id'], array('type' => 'varchar', 'precision' => 4, 'nullable' => true));
 				}
 
+
 				$values_insert= array(
 					$standard['id'],
 					$standard['name'],
@@ -373,7 +412,7 @@
 				    $this->db->db_addslashes(implode(',',$uc)),
 					);
 
-				$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+				$values_insert	= $this->db->validate_insert($values_insert);
 
 				$this->db->query("INSERT INTO fm_location_type (id,name, descr,pk,ix,uc) "
 					. "VALUES ($values_insert)",__LINE__,__FILE__);
@@ -395,7 +434,7 @@
 						$default_attrib['nullable'][$i]
 						);
 
-					$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+					$values_insert	= $this->db->validate_insert($values_insert);
 
 					$this->db->query("INSERT INTO phpgw_cust_attribute (location_id,id,column_name,datatype,precision_,input_text,statustext,attrib_sort,custom,nullable) "
 						. "VALUES ($values_insert)",__LINE__,__FILE__);
@@ -433,6 +472,22 @@
 			return $receipt;
 		}
 
+		function get_tables_to_alter()
+		{
+			$tables = array('fm_project','fm_tts_tickets','fm_request','fm_document','fm_investment');
+			$entity			= CreateObject('property.soadmin_entity');
+			$entity_list 	= $entity->read(array('allrows' => true));
+			foreach($entity_list as $entry)
+			{
+				$cat_list = $entity->read_category(array('allrows'=>true,'entity_id'=>$entry['id']));
+				foreach($cat_list as $category)
+				{
+					$tables[] = "fm_entity_{$entry['id']}_{$category['id']}";
+				}
+			}
+			return $tables;
+		}
+
 		function edit($values)
 		{
 
@@ -445,7 +500,7 @@
 				'list_address'	=> (isset($values['list_address'])?$values['list_address']:''),
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->query("UPDATE $table SET $value_set WHERE id='" . $values['id']. "'",__LINE__,__FILE__);
 
@@ -457,8 +512,10 @@
 
 		function delete($id)
 		{
+			$tables_to_drop_from = $this->get_tables_to_alter();
+			
+			$receipt = array();
 			$this->init_process();
-			$this->oProc->m_odb->transaction_begin();
 			$this->db->transaction_begin();
 
 			$table 		= 'fm_location_type';
@@ -467,17 +524,19 @@
 			if($this->db->f('id') > $id)
 			{
 				$this->db->transaction_abort();
-				$this->oProc->m_odb->transaction_abort();
 				$receipt['error'][] = array('msg' => lang('please delete from the bottom'));
-				$GLOBALS['phpgw']->session->appsession('receipt','property',$receipt);
-
-				return;
+				return $receipt;
 			}
 
 			$this->oProc->DropTable('fm_location' . $id);
 			$this->oProc->DropTable('fm_location' . $id . '_category');
 			$this->oProc->DropTable('fm_location' . $id . '_history');
 
+			foreach($tables_to_drop_from as $entry)
+			{
+				$this->oProc->DropColumn($entry ,array(),"loc{$id}");
+			}
+
 			$attrib_table 	= 'phpgw_cust_attribute';
 			$choice_table 	= 'phpgw_cust_choice';
 			$location_id	= $GLOBALS['phpgw']->locations->get_id('property', ".location.{$id}");
@@ -486,16 +545,22 @@
 			$this->db->query("DELETE FROM {$choice_table} WHERE location_id = {$location_id}",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM {$table} WHERE id=" . (int)$id,__LINE__,__FILE__);
 
-			$this->db->transaction_commit();
-			$this->oProc->m_odb->transaction_commit();
+			if($this->db->transaction_commit())
+			{
+				$receipt['message'][] = array('msg' => lang('location at level %1 has been deleted', $id));
+			}
+			else
+			{
+				$receipt['error'][] = array('msg' => lang('the process failed'));			
+			}
+			return $receipt;
 		}
 
 
-
 		function init_process()
 		{
 			$this->oProc 				= CreateObject('phpgwapi.schema_proc',$GLOBALS['phpgw_info']['server']['db_type']);
-			$this->oProc->m_odb			= $this->db;
+			$this->oProc->m_odb			= & $this->db;
 			$this->oProc->m_odb->Halt_On_Error	= 'yes';
 		}
 
@@ -519,7 +584,7 @@
 //_debug_array($history_table_def);
 			if(!($location_type==$values[$column_name]))
 			{
-				$id = $this->bocommon->next_id('phpgw_cust_attribute',array('location_id' => $location_id));
+				$id = $this->db->next_id('phpgw_cust_attribute',array('location_id' => $location_id));
 
 				$this->init_process();
 
@@ -556,7 +621,7 @@
 						''
 					);
 
-					$values	= $this->bocommon->validate_db_insert($values);
+					$values	= $this->db->validate_insert($values);
 
 					$this->db->query("INSERT INTO phpgw_cust_attribute (location_id,id,column_name, input_text, statustext,datatype,precision_,scale,default_value,nullable,custom) "
 						. "VALUES ($values)",__LINE__,__FILE__);
@@ -585,6 +650,11 @@
 		}
 
 
+		function get_location_type()
+		{
+			return $this->select_location_type();
+		}
+
 		function select_location_type()
 		{
 			$this->db->query("SELECT * FROM fm_location_type ORDER BY id ");

Modified: people/sigurdne/modules/property/trunk/inc/class.soagreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soagreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soagreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -36,13 +36,12 @@
 	{
 		var $role;
 
-		function property_soagreement()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           = $this->bocommon->new_db();
-			$this->db2           = $this->bocommon->new_db($this->db);
+			$this->db           = clone($GLOBALS['phpgw']->db);
+			$this->db2          = clone($this->db);
 
 			$this->join			= $this->bocommon->join;
 			$this->left_join	= $this->bocommon->left_join;
@@ -255,9 +254,11 @@
 
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
+				$query = $this->db->db_addslashes($query);
 
+				$querymethod[]= "fm_branch.descr {$this->like} '%{$query}%'";
+				$querymethod[]= "{$entity_table}.name {$this->like} '%{$query}%'";
+
 				$this->db->query("SELECT * FROM $attribute_table WHERE search='1' AND $attribute_filter ");
 
 				while ($this->db->next_record())
@@ -280,7 +281,6 @@
 			}
 
 			$sql .= " $filtermethod $querymethod";
-//echo $sql;
 
 			$this->db2->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db2->num_rows();
@@ -391,6 +391,7 @@
 				$allrows		= (isset($data['allrows'])?$data['allrows']:'');
 				$agreement_id	= (isset($data['agreement_id'])?$data['agreement_id']:'');
 			}
+$allrows = true; // return all..
 
 			$entity_table = 'fm_activity_price_index';
 

Modified: people/sigurdne/modules/property/trunk/inc/class.soalarm.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soalarm.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soalarm.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,14 +34,12 @@
 
 	class property_soalarm
 	{
-		function property_soalarm()
+		function __construct()
 		{
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->socommon		= CreateObject('property.socommon');
-			$this->db           = $this->socommon->new_db();
-
-			$this->join			= $this->socommon->join;
-			$this->like			= $this->socommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function select_method_list()

Modified: people/sigurdne/modules/property/trunk/inc/class.soasync.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soasync.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soasync.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,43 +34,32 @@
 
 	class property_soasync
 	{
-		function property_soasync()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				if ($data['start'])
-				{
-					$start=$data['start'];
-				}
-				else
-				{
-					$start=0;
-				}
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
+				$start	= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$query	= isset($data['query']) ? $data['query'] : '';
+				$sort	= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
+				$order	= isset($data['order']) ? $data['order'] : '';
+				$allrows	= isset($data['allrows']) ? $data['allrows'] : '';
 			}
 
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
-
+				$ordermethod = " ORDER BY $order $sort";
 			}
 			else
 			{
-				$ordermethod = ' order by id asc';
+				$ordermethod = ' ORDER BY id asc';
 			}
 
 			$table='fm_async_method';
@@ -78,26 +67,33 @@
 			$querymethod = '';
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
-				$querymethod = " where id $this->like '%$query%' or descr $this->like '%$query%'";
+				$query = $this->db->db_addslashes($query);
+				$querymethod = " WHERE name $this->like '%$query%' OR data $this->like '%$query%' OR descr $this->like '%$query%'";
 			}
 
 			$sql = "SELECT * FROM $table $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
+
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+			}
 
+			$method = array();
 			while ($this->db->next_record())
 			{
 				$method[] = array
 				(
 					'id'	=> $this->db->f('id'),
-					'name'	=> $this->db->f('name'),
-					'data'	=> $this->db->f('data'),
-					'descr'	=> $this->db->f('descr')
+					'name'	=> $this->db->f('name',true),
+					'data'	=> $this->db->f('data',true),
+					'descr'	=> $this->db->f('descr',true)
 				);
 			}
 			return $method;
@@ -106,36 +102,43 @@
 
 		function read_single($id)
 		{
+			$id = (int) $id;
+
 			$table='fm_async_method';
 
-			$sql = "SELECT * FROM $table  where id='$id'";
+			$sql = "SELECT * FROM {$table} WHERE id={$id}";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$method = array();
 			if ($this->db->next_record())
 			{
 				$method['id']		= $this->db->f('id');
-				$method['name']		= $this->db->f('name');
-				$method['data']		= $this->db->f('data');
-				$method['descr']	= $this->db->f('descr');
-
-				return $method;
+				$method['name']		= $this->db->f('name', true);
+				$method['data']		= $this->db->f('data', true);
+				$method['descr']	= $this->db->f('descr', true);
 			}
+			return $method;
 		}
 
 		function add($method)
 		{
+			$receipt = array();
 			$table='fm_async_method';
 
-			$method['id'] = $this->bocommon->next_id($table);
+			$this->db->transaction_begin();
+			$method['id'] = $this->db->next_id($table);
 			$method['name'] = $this->db->db_addslashes($method['name']);
 			$method['descr'] = $this->db->db_addslashes($method['descr']);
 
 			$this->db->query("INSERT INTO $table (id, name,data, descr) "
 				. "VALUES ('" . $method['id'] . "','" . $method['name'] . "','" . $method['data'] . "','" . $method['descr']. "')",__LINE__,__FILE__);
 
+			if( $this->db->transaction_commit() )
+			{
 			$receipt['id'] = $method['id'];
 			$receipt['message'][] = array('msg' => lang('async method has been saved'));
+			}
 
 			return $receipt;
 		}

Modified: people/sigurdne/modules/property/trunk/inc/class.sob_account.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sob_account.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sob_account.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,32 +34,23 @@
 
 	class property_sob_account
 	{
-		function property_sob_account()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= 	$GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon	= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->like		= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				if ($data['start'])
-				{
-					$start=$data['start'];
-				}
-				else
-				{
-					$start=0;
-				}
-				$query		= (isset($data['query'])?$data['query']:'');
-				$sort		= (isset($data['sort'])?$data['sort']:'DESC');
-				$order		= (isset($data['order'])?$data['order']:'');
-				$allrows	= (isset($data['allrows'])?$data['allrows']:'');
+				$start		= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$query		= isset($data['query'])?$data['query']:'';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order		= isset($data['order'])?$data['order']:'';
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 			}
 
 			if ($order)
@@ -76,16 +67,14 @@
 
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
+				$query = $this->db->db_addslashes($query);
 				$querymethod = " where id $this->like '%$query%' or descr $this->like '%$query%'";
 			}
 
 			$sql = "SELECT * FROM $table $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{

Modified: people/sigurdne/modules/property/trunk/inc/class.sobudget.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sobudget.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sobudget.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,43 +34,70 @@
 
 	class property_sobudget
 	{
-		function property_sobudget()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
+			$this->cats					= CreateObject('phpgwapi.categories');
+			$this->cats->app_name		= 'property.project';
+			$this->cats->supress_info	= true;
+
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon	= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
+		}
 
-			$this->join		= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like		= $this->bocommon->like;
+
+		/**
+		 * Get a list of categories , included subs
+		 *
+		 * @param int $cat_id the parent doc-type
+		 * @return array parent and children
+		 */
+
+		function get_sub_cats($cat_id = 0)
+		{
+			$cat_ids = array();
+			if($cat_id)
+			{
+				$cat_ids[] = $cat_id;
+				$cat_sub = $this->cats->return_sorted_array($start = 0,$limit = false,$query = '',$sort = '',$order = '',$globals = False, $parent_id = $cat_id);
+				foreach ($cat_sub as $category)
+				{
+					$cat_ids[] = $category['id'];
+				}
+			}
+			return $cat_ids;
 		}
 
+
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				$start	= (isset($data['start'])?$data['start']:0);
-				$filter	= (isset($data['filter'])?$data['filter']:'none');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$allrows = (isset($data['allrows'])?$data['allrows']:'');
-				$district_id = (isset($data['district_id'])?$data['district_id']:'');
-				$year = (isset($data['year'])?$data['year']:'');
-				$grouping = (isset($data['grouping'])?$data['grouping']:'');
-				$revision = (isset($data['revision'])?$data['revision']:'');
+				$start			= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$filter			= isset($data['filter']) && $data['filter'] ? $data['filter'] : 'none';
+				$query			= isset($data['query']) ? $data['query'] : '';
+				$sort			= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
+				$order			= isset($data['order']) ? $data['order'] : '';
+				$allrows		= isset($data['allrows']) ? $data['allrows'] : '';
+				$district_id	= isset($data['district_id']) ? $data['district_id'] : '';
+				$year			= isset($data['year']) && $data['year'] ? (int) $data['year'] : 0;
+				$grouping		= isset($data['grouping']) ? $data['grouping'] : '';
+				$revision		= isset($data['revision']) ? $data['revision'] : '';
+				$cat_id			= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id']: 0;
+				$dimb_id			= isset($data['dimb_id']) && $data['dimb_id'] ? $data['dimb_id']: 0;
 			}
 
+			$cat_ids = $this->get_sub_cats($cat_id);
+
+
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
+				$ordermethod = " ORDER BY $order $sort";
 			}
 			else
 			{
-				$ordermethod = ' order by id DESC';
+				$ordermethod = ' ORDER BY id DESC';
 			}
 
 
@@ -90,7 +117,7 @@
 			}
 			if ($grouping > 0)
 			{
-				$filtermethod .= " $where category='$grouping' ";
+				$filtermethod .= " $where fm_b_account.category='$grouping' ";
 				$where = 'AND';
 
 			}
@@ -101,20 +128,30 @@
 
 			}
 
-			if($query)
+			if ($cat_ids && is_array($cat_ids))
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
+				$filtermethod .= " $where fm_budget.category IN (". implode(',', $cat_ids) . ')';
+				$where = 'AND';
+			}
 
-				$querymethod = " $where ( descr $this->like '%$query%')";
+			if ($dimb_id > 0)
+			{
+				$filtermethod .= " $where fm_budget.ecodimb={$dimb_id}";
+				$where = 'AND';
 			}
 
+			if($query)
+			{
+				$query = $this->db->db_addslashes($query);
+				$querymethod = " $where ( descr $this->like '%$query%') OR fm_budget.b_account_id='$query'";
+			}
 
-			$sql = "SELECT fm_budget.*, descr,category FROM fm_budget $this->join fm_b_account ON fm_budget.b_account_id = fm_b_account.id $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$sql = "SELECT fm_budget.*, fm_budget.category as cat_id, ecodimb, descr,fm_b_account.category as grouping FROM fm_budget $this->join fm_b_account ON fm_budget.b_account_id = fm_b_account.id $filtermethod $querymethod";
 
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
+
 			if(!$allrows)
 			{
 				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@@ -124,20 +161,23 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
+			$budget = array();
 			while ($this->db->next_record())
 			{
 				$budget[] = array
 				(
 					'budget_id'		=> $this->db->f('id'),
 					'year'			=> $this->db->f('year'),
-					'grouping'		=> $this->db->f('category'),
+					'grouping'			=> $this->db->f('grouping'),
 					'b_account_id'		=> $this->db->f('b_account_id'),
 					'b_account_name'	=> $this->db->f('descr'),
 					'district_id'		=> $this->db->f('district_id'),
 					'revision'		=> $this->db->f('revision'),
 					'budget_cost'		=> $this->db->f('budget_cost'),
 					'entry_date'		=> $this->db->f('entry_date'),
-					'user'			=> $GLOBALS['phpgw']->accounts->id2name($this->db->f('user_id'))
+					'ecodimb'			=> $this->db->f('ecodimb'),
+					'cat_id'			=> $this->db->f('cat_id'),
+		//			'user'				=> $GLOBALS['phpgw']->accounts->id2name($this->db->f('user_id'))
 				);
 			}
 			return $budget;
@@ -147,16 +187,16 @@
 		{
 			if(is_array($data))
 			{
-				$start	= (isset($data['start'])?$data['start']:0);
-				$filter	= (isset($data['filter'])?$data['filter']:'none');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$allrows = (isset($data['allrows'])?$data['allrows']:'');
-				$district_id = (isset($data['district_id'])?$data['district_id']:'');
-				$year = (isset($data['year'])?$data['year']:'');
-				$grouping = (isset($data['grouping'])?$data['grouping']:'');
-				$revision = (isset($data['revision'])?$data['revision']:'');
+				$start			= isset($data['start']) && $data['start'] ? $data['start']:0;
+				$filter			= isset($data['filter']) && $data['filter'] ?$data['filter']:'none';
+				$query			= isset($data['query'])?$data['query']:'';
+				$sort			= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order			= isset($data['order'])?$data['order']:'';
+				$allrows		= isset($data['allrows'])?$data['allrows']:'';
+				$district_id	= isset($data['district_id'])?$data['district_id']:'';
+				$year			= isset($data['year'])?$data['year']:'';
+				$grouping		= isset($data['grouping'])?$data['grouping']:'';
+				$revision		= isset($data['revision'])?$data['revision']:'';
 			}
 
 			if ($order)
@@ -198,17 +238,15 @@
 
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
+				$query = $this->db->db_addslashes($query);
 			//	$querymethod = " $where ( descr $this->like '%$query%')";
 			}
 
 
 			$sql = "SELECT * FROM fm_budget_basis $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -219,6 +257,7 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
+			$budget = array();
 			while ($this->db->next_record())
 			{
 				$budget[] = array
@@ -230,7 +269,9 @@
 					'revision'		=> $this->db->f('revision'),
 					'budget_cost'		=> $this->db->f('budget_cost'),
 					'entry_date'		=> $this->db->f('entry_date'),
-					'user'			=> $GLOBALS['phpgw']->accounts->id2name($this->db->f('user_id'))
+					'ecodimb'			=> $this->db->f('ecodimb'),
+					'cat_id'			=> $this->db->f('category'),
+			//		'user'			=> $GLOBALS['phpgw']->accounts->id2name($this->db->f('user_id'))
 				);
 			}
 			return $budget;
@@ -238,19 +279,26 @@
 
 		function read_single_basis($budget_id)
 		{
-			$this->db->query("select * from fm_budget_basis where id='$budget_id'",__LINE__,__FILE__);
+			$budget_id = (int) $budget_id;
+			$this->db->query("SELECT * FROM fm_budget_basis WHERE id = {$budget_id}",__LINE__,__FILE__);
 
+			$budget = array();
 			if ($this->db->next_record())
 			{
-				$budget['id']			= (int)$this->db->f('id');
-				$budget['year']			= $this->db->f('year');
-				$budget['district_id']		= $this->db->f('district_id');
-				$budget['revision']		= $this->db->f('revision');
-				$budget['b_group']		= $this->db->f('b_group');
-				$budget['remark']		= stripslashes($this->db->f('remark'));
-				$budget['budget_cost']		= $this->db->f('budget_cost');
-				$budget['entry_date']		= $this->db->f('entry_date');
-				$budget['distribute_year']	= unserialize($this->db->f('distribute_year'));
+				$budget = array
+				(
+					'id'				=> $budget_id,
+					'year'				=> $this->db->f('year'),
+					'district_id'		=> $this->db->f('district_id'),
+					'revision'			=> $this->db->f('revision'),
+					'b_group'			=> $this->db->f('b_group'),
+					'remark'			=> $this->db->f('remark',true),
+					'budget_cost'		=> $this->db->f('budget_cost'),
+					'entry_date'		=> $this->db->f('entry_date'),
+					'distribute_year'	=> unserialize($this->db->f('distribute_year')),
+					'ecodimb'			=> $this->db->f('ecodimb'),
+					'cat_id'			=> $this->db->f('category')
+				);
 			}
 
 			return $budget;
@@ -276,7 +324,7 @@
 
 			if(!$receipt['error'])
 			{
-				$id = $this->bocommon->next_id('fm_budget_basis');
+				$id = $this->db->next_id('fm_budget_basis');
 
 				$values= array(
 					$id,
@@ -288,13 +336,15 @@
 					$budget['district_id'],
 					$budget['b_group'],
 					$budget['budget_cost'],
-					serialize($budget['distribute_year'])
+					serialize($budget['distribute_year']),
+					$budget['ecodimb'],
+					$budget['cat_id']
 					);
 
-				$values	= $this->bocommon->validate_db_insert($values);
+				$values	= $this->db->validate_insert($values);
 
 
-				$this->db->query("INSERT INTO fm_budget_basis (id,entry_date,remark,user_id,year,revision,district_id,b_group,budget_cost,distribute_year)"
+				$this->db->query("INSERT INTO fm_budget_basis (id,entry_date,remark,user_id,year,revision,district_id,b_group,budget_cost,distribute_year,ecodimb,category)"
 					. "VALUES ($values)",__LINE__,__FILE__);
 
 				$receipt['budget_id']= $id;
@@ -311,14 +361,17 @@
 
 			$budget['remark'] = $this->db->db_addslashes($budget['remark']);
 
-			$value_set=array(
+			$value_set=array
+			(
 				'remark'	=> $budget['remark'],
 				'entry_date'	=> time(),
 				'budget_cost'	=> $budget['budget_cost'],
-				'distribute_year' => serialize($budget['distribute_year'])
+				'distribute_year'	=> serialize($budget['distribute_year']),
+				'ecodimb'			=> $budget['ecodimb'],
+				'category'			=> $budget['cat_id'],
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->transaction_begin();
 			$this->db->query("UPDATE fm_budget_basis set $value_set WHERE id=" . intval($budget['budget_id']),__LINE__,__FILE__);
@@ -339,16 +392,22 @@
 		{
 			$this->db->query("select * from fm_budget where id='$budget_id'",__LINE__,__FILE__);
 
+			$budget = array();
 			if ($this->db->next_record())
 			{
-				$budget['id']			= (int)$this->db->f('id');
-				$budget['year']			= $this->db->f('year');
-				$budget['district_id']		= $this->db->f('district_id');
-				$budget['revision']		= $this->db->f('revision');
-				$budget['b_account_id']		= $this->db->f('b_account_id');
-				$budget['remark']	= stripslashes($this->db->f('remark'));
-				$budget['budget_cost']	= $this->db->f('budget_cost');
-				$budget['entry_date']	= $this->db->f('entry_date');
+				$budget = array
+				(
+					'id'			=> (int)$this->db->f('id'),
+					'year'			=> $this->db->f('year'),
+					'district_id'	=> $this->db->f('district_id'),
+					'revision'		=> $this->db->f('revision'),
+					'b_account_id'	=> $this->db->f('b_account_id'),
+					'remark'		=> $this->db->f('remark', true),
+					'budget_cost'	=> $this->db->f('budget_cost'),
+					'entry_date'	=> $this->db->f('entry_date'),
+					'ecodimb'			=> $this->db->f('ecodimb'),
+					'cat_id'			=> $this->db->f('category')
+				);
 			}
 
 			return $budget;
@@ -356,11 +415,17 @@
 
 		function add($budget)
 		{
+			$receipt = array();
 			$budget['remark'] = $this->db->db_addslashes($budget['remark']);
 
 			$this->db->transaction_begin();
 
-			$sql = "SELECT id FROM fm_budget WHERE year ='" . $budget['year'] . "'  AND b_account_id ='" . $budget['b_account_id'] . "' AND revision = '" . $budget['revision'] . "' AND district_id='" . $budget['district_id'] . "'";
+			if($budget['district_id'])
+			{
+				$district_filter =  "AND district_id='{$budget['district_id']}";
+			}
+			$sql = "SELECT id FROM fm_budget WHERE year ='{$budget['year']}' AND b_account_id ='{$budget['b_account_id']}' AND revision = '{$budget['revision']}' {$district_filter}";
+
 			$this->db->query($sql,__LINE__,__FILE__);
 
 			if($this->db->next_record())
@@ -370,7 +435,7 @@
 
 			if(!$receipt['error'])
 			{
-				$id = $this->bocommon->next_id('fm_budget');
+				$id = $this->db->next_id('fm_budget');
 
 				$values= array(
 					$id,
@@ -382,11 +447,13 @@
 					$budget['district_id'],
 					$budget['b_account_id'],
 					$budget['budget_cost'],
+					$budget['ecodimb'],
+					$budget['cat_id']
 					);
 
-				$values	= $this->bocommon->validate_db_insert($values);
+				$values	= $this->db->validate_insert($values);
 
-				$this->db->query("INSERT INTO fm_budget (id,entry_date,remark,user_id,year,revision,district_id,b_account_id,budget_cost)"
+				$this->db->query("INSERT INTO fm_budget (id,entry_date,remark,user_id,year,revision,district_id,b_account_id,budget_cost,ecodimb,category)"
 					. "VALUES ($values)",__LINE__,__FILE__);
 
 				$receipt['budget_id']= $id;
@@ -400,20 +467,24 @@
 
 		function edit($budget)
 		{
+			$receipt = array();
 			$budget['remark'] = $this->db->db_addslashes($budget['remark']);
 
 			$this->db->transaction_begin();
 
-			$value_set=array(
+			$value_set = array
+			(
 				'remark'	=> $budget['remark'],
 				'entry_date'	=> time(),
 				'budget_cost'	=> $budget['budget_cost'],
 				'year'			=> $budget['year'],
 				'revision'		=> $budget['revision'],
 				'district_id'	=> $budget['district_id'],
+				'ecodimb'		=> $budget['ecodimb'],
+				'category'		=> $budget['cat_id']
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->query("UPDATE fm_budget set $value_set WHERE id=" . intval($budget['budget_id']),__LINE__,__FILE__);
 
@@ -424,29 +495,39 @@
 			return $receipt;
 		}
 
-
-
 		function read_obligations($data)
 		{
+//_debug_array($data);			
 			if(is_array($data))
 			{
-				$start	= (isset($data['start']) && $data['start'] ?$data['start']:0);
-				$filter	= (isset($data['filter'])?$data['filter']:'none');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$allrows = (isset($data['allrows'])?$data['allrows']:'');
-				$district_id = (isset($data['district_id'])?$data['district_id']:'');
-				$year = (isset($data['year'])?$data['year']:'');
-				$grouping = (isset($data['grouping'])?$data['grouping']:'');
-				$revision = (isset($data['revision'])?$data['revision']:'');
-				$year = (isset($data['year'])?$data['year']:'');
-				$cat_id = (isset($data['cat_id'])?$data['cat_id']:'');
+				$start			= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$filter			= isset($data['filter']) ? $data['filter'] : 'none';
+				$query			= isset($data['query']) ? $data['query'] : '';
+				$sort			= isset($data['sort']) ? $data['sort'] : 'DESC';
+				$order			= isset($data['order']) ? $data['order'] : '';
+				$allrows		= isset($data['allrows']) ? $data['allrows'] : '';
+				$district_id	= isset($data['district_id']) ? $data['district_id'] : '';
+				$year			= isset($data['year']) ? (int)$data['year'] : '';
+				$grouping		= isset($data['grouping']) ? $data['grouping'] : '';
+				$revision		= isset($data['revision']) ? $data['revision'] : 1;
+				$year			= isset($data['year']) ? $data['year'] : '';
+				$cat_id			= isset($data['cat_id']) ? $data['cat_id'] : '';
+				$details		= isset($data['details']) ? $data['details'] : '';
 			}
 
+			if(!$year)
+			{
+				return array();
+			}
+//_debug_array($allrows);
 			$ordermethod = '';
 			/* 0 => cancelled, 1 => obligation , 2 => paid */
-			$filtermethod = " WHERE fm_workorder.paid = 1 and fm_workorder.vendor_id > 0";
+			$filtermethod = "WHERE fm_workorder.paid = 1 and fm_workorder.vendor_id > 0";
+
+			$start_date = mktime(1, 1, 1, 1, 1, $year);
+			$end_date = mktime  (23, 59, 59, 12, 31, $year);
+			$filtermethod .= " AND fm_workorder.start_date >= $start_date AND fm_workorder.start_date <= $end_date";
+
 			$where = 'AND';
 
 			if ($cat_id > 0)
@@ -460,13 +541,7 @@
 				$filtermethod .= " $where district_id=" . (int)$district_id;
 				$where = 'AND';
 			}
-/*
-			if ($year > 0)
-			{
-				$filtermethod .= " $where year='$year' ";
-				$where = 'AND';
-			}
-*/
+
 			if ($grouping > 0)
 			{
 				$filtermethod .= " $where fm_b_account.category='$grouping' ";
@@ -474,39 +549,39 @@
 			}
 
 			$querymethod = '';
-			if($query)
+/*			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
-			//	$querymethod = " $where ( descr $this->like '%$query%')";
+				$query = $this->db->db_addslashes($query);
 			}
+*/
+			if( $details )
+			{
+				$b_account_field = 'id';
+			}
+			else
+			{
+				$b_account_field = 'category';
+			}
 
-
-			$sql = "SELECT sum(combined_cost) as combined_cost, count(fm_workorder.id) as hits, fm_b_account.category as b_group, district_id FROM"
-				. " fm_workorder $this->join fm_b_account ON fm_workorder.account_id =fm_b_account.id "
+			$sql = "SELECT sum(combined_cost) as combined_cost, count(fm_workorder.id) as hits, fm_b_account.{$b_account_field} as {$b_account_field}, district_id"
+				. " FROM fm_workorder"
+				. " $this->join fm_b_account ON fm_workorder.account_id =fm_b_account.id "
 				. " $this->join fm_project ON  fm_workorder.project_id =fm_project.id "
 				. " $this->join fm_location1 ON fm_project.loc1 = fm_location1.loc1 "
-				. " $this->join fm_part_of_town ON fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id $filtermethod $querymethod GROUP BY fm_b_account.category,district_id ";
+				. " $this->join fm_part_of_town ON fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id $filtermethod $querymethod GROUP BY fm_b_account.{$b_account_field},district_id ";
 
 			$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
-			$this->total_records = $this->db->num_rows();
-//_debug_array($sql);
-			if(!$year)
-			{
-				$year = date("Y");
-			}
 
 			while ($this->db->next_record())
 			{
-				$obligations[$this->db->f('b_group')][$this->db->f('district_id')] = round($this->db->f('combined_cost'));
-				$hits[$this->db->f('b_group')][$this->db->f('district_id')] = $this->db->f('hits');
-				$group_info[$this->db->f('b_group')] = true;
+				$obligations[$this->db->f($b_account_field)][$this->db->f('district_id')] = round($this->db->f('combined_cost'));
+				$hits[$this->db->f($b_account_field)][$this->db->f('district_id')] = $this->db->f('hits');
+				$accout_info[$this->db->f($b_account_field)] = true;
 				$district[$this->db->f('district_id')] = true;
 			}
 
 //_debug_array($obligations);
-			$this->db->query("select max(revision) as revision from fm_budget_basis where year='$year'",__LINE__,__FILE__);
+			$this->db->query("select max(revision) as revision from fm_budget where year={$year}",__LINE__,__FILE__);
 			$this->db->next_record();
 			$revision = (int)$this->db->f('revision');
 
@@ -515,9 +590,19 @@
 			$where = 'AND';
 			if ($grouping > 0)
 			{
+				$filtermethod = " $where fm_b_account.category='$grouping' ";
+/*
+				if (!$details)
+				{
 				$filtermethod = " $where b_group='$grouping' ";
 				$where = 'AND';
 			}
+				else
+				{
+					$filtermethod = " $where fm_b_account.category='$grouping' ";
+				}
+*/
+			}
 
 			if ($district_id > 0)
 			{
@@ -525,14 +610,24 @@
 				$where = 'AND';
 			}
 
-			$sql = "select budget_cost,b_group,district_id from fm_budget_basis where year='$year' AND revision = '$revision' $filtermethod GROUP BY budget_cost,b_group,district_id";
+			if( $details )
+			{
+				$sql = "SELECT budget_cost,b_account_id as b_account_field,district_id FROM fm_budget"
+				 . " $this->join fm_b_account ON fm_budget.b_account_id =fm_b_account.id WHERE year={$year} AND revision = '$revision' $filtermethod GROUP BY budget_cost,b_account_id,district_id";
+			}
+			else
+			{
+				$sql = "SELECT sum(budget_cost) as budget_cost ,fm_b_account.category as b_account_field,district_id FROM fm_budget"
+				 . " $this->join fm_b_account ON fm_budget.b_account_id =fm_b_account.id WHERE year={$year} AND revision = '$revision' $filtermethod GROUP BY fm_b_account.category,district_id";
+			}
+//_debug_array($sql);
 			$this->db->query($sql,__LINE__,__FILE__);
 
 			$budget_cost = array();
 			while ($this->db->next_record())
 			{
-				$budget_cost[$this->db->f('b_group')][$this->db->f('district_id')] = round($this->db->f('budget_cost'));
-				$group_info[$this->db->f('b_group')] = true;
+				$budget_cost[$this->db->f('b_account_field')][$this->db->f('district_id')] = round($this->db->f('budget_cost'));
+				$accout_info[$this->db->f('b_account_field')] = true;
 				$district[$this->db->f('district_id')] = true;
 			}
 
@@ -560,85 +655,109 @@
 			}
 
 
-			$start_date1 = date($this->bocommon->dateformat,mktime(2,0,0,3,1,$year));
-			$start_date2 = date($this->bocommon->dateformat,mktime(2,0,0,1,1,$year));
-			$end_date = date($this->bocommon->dateformat,mktime(2,0,0,12,31,$year));
+			$start_date1 = date($this->db->date_format(),mktime(2,0,0,3,1,$year));
+			$start_date2 = date($this->db->date_format(),mktime(2,0,0,1,1,$year));
+			$end_date = date($this->db->date_format(),mktime(2,0,0,12,31,$year));
 
-			$sql = "SELECT fm_b_account.category as b_group, district_id, sum(godkjentbelop) as actual_cost FROM fm_ecobilagoverf"
-				. " $this->join fm_project ON fm_ecobilagoverf.project_id =fm_project.id"
+			$sql = "SELECT fm_b_account.{$b_account_field} as $b_account_field, district_id, sum(godkjentbelop) as actual_cost FROM fm_ecobilagoverf"
 				. " $this->join fm_b_account ON fm_ecobilagoverf.spbudact_code =fm_b_account.id"
 				. " $this->join fm_location1 ON fm_ecobilagoverf.loc1 = fm_location1.loc1"
 				. " $this->join fm_part_of_town ON fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id"
 				. " WHERE (fakturadato > '$start_date1' AND fakturadato < '$end_date' $filtermethod)"
 				. " OR (fakturadato > '$start_date2' AND fakturadato < '$end_date' AND periode < 3 $filtermethod)"
-				. " GROUP BY b_group, district_id";
+				. " GROUP BY fm_b_account.{$b_account_field}, district_id";
 
 //_debug_array($sql);
 			$this->db->query($sql,__LINE__,__FILE__);
 
 			while ($this->db->next_record())
 			{
-				$actual_cost[$this->db->f('b_group')][$this->db->f('district_id')] = round($this->db->f('actual_cost'));
-				$group_info[$this->db->f('b_group')] = true;
+				$actual_cost[$this->db->f($b_account_field)][$this->db->f('district_id')] = round($this->db->f('actual_cost'));
+				$accout_info[$this->db->f($b_account_field)] = true;
 				$district[$this->db->f('district_id')] = true;
 			}
 
+			$result = array();
 
-			if (is_array($group_info))
+			if (is_array($accout_info))
 			{
-				if ($order == 'b_group')
+				if ($order == 'b_account')
 				{
 					switch ($sort)
 					{
 						case 'ASC':
-							ksort($group_info);
+							ksort($accout_info);
 							break;
 						case 'DESC':
-							krsort($group_info);
+							krsort($accout_info);
 							break;
 						default:
-							ksort($group_info);
+							ksort($accout_info);
 					}
 				}
 				else
 				{
-					ksort($group_info);
+					ksort($accout_info);
 				}
 
 				ksort($district);
-				$group_info = array_keys($group_info);
+				$accout_info = array_keys($accout_info);
 				$district = array_keys($district);
 
-				foreach($group_info as $b_group)
+				$result = array();
+				foreach($accout_info as $b_account)
 				{
 					foreach($district as $district_id)
 					{
-						if( (isset($actual_cost[$b_group][$district_id]) && $actual_cost[$b_group][$district_id])
-						 || (isset($budget_cost[$b_group][$district_id]) && $budget_cost[$b_group][$district_id])
-						 || (isset($obligations[$b_group][$district_id]) && $obligations[$b_group][$district_id]))
+						if( (isset($actual_cost[$b_account][$district_id]) && $actual_cost[$b_account][$district_id])
+						 || (isset($budget_cost[$b_account][$district_id]) && $budget_cost[$b_account][$district_id])
+						 || (isset($obligations[$b_account][$district_id]) && $obligations[$b_account][$district_id]))
 						{
 							$result[] = array(
-								'grouping'		=> $b_group,
+								'grouping'		=> $details ? '' : $b_account, 
+								'b_account'		=> $b_account,
 								'district_id'	=> $district_id,
-								'actual_cost'	=> isset($actual_cost[$b_group][$district_id]) && $actual_cost[$b_group][$district_id] ? round($actual_cost[$b_group][$district_id]) : 0,
-								'budget_cost'	=> isset($budget_cost[$b_group][$district_id]) && $budget_cost[$b_group][$district_id] ? round($budget_cost[$b_group][$district_id]) : 0,
-								'obligation'	=> isset($obligations[$b_group][$district_id]) && $obligations[$b_group][$district_id] ? round($obligations[$b_group][$district_id]) : 0,
-								'hits'			=> isset($hits[$b_group][$district_id])?$hits[$b_group][$district_id]:0,
+								'actual_cost'	=> isset($actual_cost[$b_account][$district_id]) && $actual_cost[$b_account][$district_id] ? round($actual_cost[$b_account][$district_id]) : 0,
+								'budget_cost'	=> isset($budget_cost[$b_account][$district_id]) && $budget_cost[$b_account][$district_id] ? round($budget_cost[$b_account][$district_id]) : 0,
+								'obligation'	=> isset($obligations[$b_account][$district_id]) && $obligations[$b_account][$district_id] ? round($obligations[$b_account][$district_id]) : 0,
+								'hits'			=> isset($hits[$b_account][$district_id])?$hits[$b_account][$district_id]:0,
 							);
 						}
 					}
 				}
 			}
 
-//_debug_array($result);
+			$this->total_records = count($result);
+			
+			//cramirez
+			if($this->total_records == 0)
+			{
+				return $result;				
+			}
+
+			if(!$allrows)
+			{
+				$num_rows = isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'])?intval($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']):15;
+
+//_debug_array(array($start,$this->total_records,$this->total_records,$num_rows));				
+				$page = ceil( ( $start / $this->total_records ) * ($this->total_records/ $num_rows) );
+
+				$out = array_chunk($result, $num_rows);
+
+				return $out[$page];
+			}
+			else
+			{
 			return $result;
 		}
+		}
 
 		function get_b_group_list()
 		{
-			$sql = "SELECT id FROM fm_b_account_category order by id asc";
+			$sql = "SELECT DISTINCT fm_b_account.category as id FROM fm_budget $this->join fm_b_account ON (fm_budget.b_account_id = fm_b_account.id) ORDER BY id asc";
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$group_list = array();
 			while ($this->db->next_record())
 			{
 				$group_list[] = array
@@ -654,6 +773,7 @@
 		function get_revision_list($year='',$basis = '')
 		{
 			$table = $basis?'fm_budget_basis':'fm_budget';
+			$revision_list = array();
 
 			if(!$year)
 			{
@@ -689,6 +809,7 @@
 			$sql = "SELECT year FROM $table group by year ORDER BY year ASC";
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$year_list = array();
 			while ($this->db->next_record())
 			{
 				$year_list[] = array
@@ -715,6 +836,7 @@
 			$sql = "SELECT revision FROM $table WHERE year =". (int)$year . "  group by revision";
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$revision_list = array();
 			while ($this->db->next_record())
 			{
 				$revision_list[] = array
@@ -734,11 +856,12 @@
 			}
 			else
 			{
-				$sql = "SELECT category as grouping FROM fm_budget $this->join fm_b_account ON fm_budget.b_account_id = fm_b_account.id WHERE year =". (int)$year . "  group by category";
+				$sql = "SELECT fm_b_account.category as grouping FROM fm_budget $this->join fm_b_account ON fm_budget.b_account_id = fm_b_account.id WHERE year =". (int)$year . "  group by fm_b_account.category";
 			}
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$grouping_list = array();
 			while ($this->db->next_record())
 			{
 				$grouping_list[] = array
@@ -756,6 +879,7 @@
 			$sql = "SELECT year FROM $table group by year order by year asc";
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$year_list = array();
 			while ($this->db->next_record())
 			{
 				$year_list[] = array
@@ -800,7 +924,7 @@
 			$this->db->transaction_commit();
 		}
 
-		function distribute($values,$receipt='')
+		function distribute($values,$receipt = array())
 		{
 			$year_condition = 'year in (' . implode(",",$values['distribute_year']). ')';
 
@@ -859,7 +983,7 @@
 						{
 
 							$this->db->query("INSERT INTO fm_budget (id, year, b_account_id, district_id,revision,user_id,entry_date,budget_cost) VALUES ("
-							. $this->bocommon->next_id('fm_budget') . ","
+							. $this->db->next_id('fm_budget') . ","
 							. $basis['year'] . ",'"
 							. $entry['b_account_id']. "',"
 							. $basis['district_id'] . ","

Modified: people/sigurdne/modules/property/trunk/inc/class.socategory.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.socategory.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.socategory.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -3,7 +3,7 @@
 	* phpGroupWare - property: a Facilities Management System.
 	*
 	* @author Sigurd Nes <[email protected]>
-	* @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software Foundation, Inc. http://www.fsf.org/
+	* @copyright Copyright (C) 2003,2004,2005,2006,2007,2008,2009 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
@@ -34,233 +34,1231 @@
 
 	class property_socategory
 	{
-		function property_socategory()
+		var $location_info = array();
+
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->custom 	= createObject('property.custom_fields');
+			$this->_db		= & $GLOBALS['phpgw']->db;
+			$this->_like	= & $this->_db->like;
+			$this->_join	= & $this->_db->join;
 		}
 
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				if ($data['start'])
-				{
-					$start=$data['start'];
+				$start		= isset($data['start']) && $data['start'] ? $data['start']:0;
+				$query		= isset($data['query'])?$data['query']:'';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order		= isset($data['order'])?$data['order']:'';
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 				}
-				else
+
+			$values = array();
+			if (!isset($this->location_info['table']) || !$table = $this->location_info['table'])
 				{
-					$start=0;
+				return $values;
 				}
-				$query		= (isset($data['query'])?$data['query']:'');
-				$sort		= (isset($data['sort'])?$data['sort']:'DESC');
-				$order		= (isset($data['order'])?$data['order']:'');
-				$type		= (isset($data['type'])?$data['type']:'');
-				$type_id		= (isset($data['type_id'])?$data['type_id']:'');
-				$allrows	= (isset($data['allrows'])?$data['allrows']:'');
+
+			$uicols = array();
+			$uicols['input_type'][]		= 'text';
+			$uicols['name'][]			= $this->location_info['id']['name'];
+			$uicols['descr'][]			= lang('id');
+			$uicols['datatype'][]		= $this->location_info['id']['type'] == 'varchar' ? 'V' : 'I';
+
+			foreach($this->location_info['fields'] as $field)
+			{
+				$uicols['input_type'][]		= 'text';
+				$uicols['name'][]			= $field['name'];
+				$uicols['descr'][]			= $field['descr'];
+				$uicols['datatype'][]		= 'V';
 			}
 
-			if(!$type)
+			if($GLOBALS['phpgw']->locations->get_attrib_table('property', $this->location_info['acl_location']))
 			{
-				return;
+
+				$choice_table = 'phpgw_cust_choice';
+				$attribute_table = 'phpgw_cust_attribute';
+				$location_id = $GLOBALS['phpgw']->locations->get_id('property', $this->location_info['acl_location']);
+				$attribute_filter = " location_id = {$location_id}";
+
+				$this->_db->query("SELECT * FROM $attribute_table WHERE list=1 AND $attribute_filter ORDER BY attrib_sort ASC");
+
+				$i	= count($uicols['name']);
+				while ($this->_db->next_record())
+			{
+					$uicols['input_type'][]		= 'text';
+					$uicols['name'][]			= $this->_db->f('column_name');
+					$uicols['descr'][]			= $this->_db->f('input_text');
+					$uicols['statustext'][]		= $this->_db->f('statustext');
+					$uicols['datatype'][$i]		= $this->_db->f('datatype');
+					$uicols['attib_id'][$i]		= $this->_db->f('id');
+					$cols_return_extra[]= array(
+						'name'	=> $this->_db->f('column_name'),
+						'datatype'	=> $this->_db->f('datatype'),
+						'attrib_id'	=> $this->_db->f('id')
+					);
+
+					$i++;
+				}
 			}
+
+			$this->uicols = $uicols;
+
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
-
+				$ordermethod = " ORDER BY $order $sort";
 			}
 			else
 			{
-				$ordermethod = ' order by id asc';
+				$ordermethod = ' ORDER BY id ASC';
 			}
 
-			$table = $this->select_table($type,$type_id);
-
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
+				if($this->location_info['id']['type']=='auto' || $this->location_info['id']['type']=='int')
+				{
+					$id_query = (int) $query;
+				}
+				else
+				{
+					$id_query = "'{$query}'";
+				}
 
-				$querymethod = " where id $this->like '%$query%' or descr $this->like '%$query%'";
+				$query = $this->_db->db_addslashes($query);
+				$querymethod = " WHERE {$table}.{$this->location_info['id']['name']} = {$id_query}";
+				foreach($this->location_info['fields'] as $field)
+				{
+					if($field['type'] == 'varchar')
+					{
+						$querymethod .= " OR {$table}.{$field['name']} $this->_like '%$query%'";
+					}
+				}
 			}
 
 			$sql = "SELECT * FROM $table $querymethod";
+			$this->_db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->_db->num_rows();
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
-
 			if(!$allrows)
 			{
-				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+				$this->_db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
 			}
 			else
 			{
-				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+				$this->_db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
-			while ($this->db->next_record())
+			$cols_return = $uicols['name'];
+			$j=0;
+//			$n=count($cols_return);
+
+			$dataset = array();
+			while ($this->_db->next_record())
 			{
-				$category[] = array
+				foreach($cols_return as $key => $field)
+				{
+					$dataset[$j][$field] = array
 				(
-					'id'	=> $this->db->f('id'),
-					'descr'	=> stripslashes($this->db->f('descr'))
+						'value'		=> $this->_db->f($field),
+						'datatype'	=> $uicols['datatype'][$key],
+						'attrib_id'	=> $uicols['attib_id'][$key]
 				);
 			}
-			return $category;
+				$j++;
 		}
 
+			$values = $this->custom->translate_value($dataset, $location_id);
 
-		function select_table($type,$type_id)
+			return $values;
+		}
+
+
+		function get_location_info($type,$type_id)
 		{
-
+			$type_id = (int)$type_id;
+			$info = array();
 			switch($type)
 			{
-				case 'dim_b':
-					$table='fm_ecodimb';
+//-------- ID type integer
+				case 'project_group':
+					$info = array
+					(
+						'table' => 'fm_project_group',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::project_group'
+					);
 					break;
-				case 'dim_d':
-					$table='fm_ecodimd';
+				case 'dimb':
+					$info = array
+					(
+						'table' => 'fm_ecodimb',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('dimb'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::accounting::accounting_dimb'
+					);
 					break;
+				case 'dimd':
+					$info = array
+					(
+						'table' => 'fm_ecodimd',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('dimd'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::accounting::accounting_dimd'
+					);
+					break;
 				case 'tax':
-					$table='fm_ecomva';
+					$info = array
+					(
+						'table' => 'fm_ecomva',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::accounting::accounting_tax'
+					);
 					break;
 				case 'voucher_cat':
-					$table='fm_ecobilag_category';
+					$info = array
+					(
+						'table' => 'fm_ecobilag_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::accounting::voucher_cats'
+					);
 					break;
 				case 'voucher_type':
-					$table='fm_ecoart';
+					$info = array
+					(
+						'table' => 'fm_ecoart',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::accounting::voucher_type'
+					);
 					break;
 				case 'tender_chapter':
-					$table='fm_chapter';
+					$info = array
+					(
+						'table' => 'fm_chapter',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::tender'
+					);
 					break;
 				case 'location':
-					$table='fm_location' . $type_id . '_category';
+
+					$this->_db->query("SELECT id FROM fm_location_type WHERE id ={$type_id}",__LINE__,__FILE__);
+
+					if($this->_db->next_record())
+					{
+						$info = array
+						(
+							'table' => "fm_location{$type_id}_category",
+							'id'				=> array('name' => 'id', 'type' => 'int'),
+							'fields'			=> array
+							(
+								array
+								(
+									'name' => 'descr',
+										'descr' => lang('descr'),
+								'type' => 'varchar'
+								)
+							),
+							'edit_msg'	=> lang('edit'),
+							'add_msg'	=> lang('add'),
+							'name'		=> '',
+							'acl_location' => '.admin',
+							'menu_selection' => "admin::property::location::location::category_{$type_id}"
+						);
+					}
+					else
+					{
+						throw new Exception(lang('ERROR: illegal type %1', $type_id));
+					}
 					break;
-				case 'meter':
-					$table='fm_meter_category';
-					break;
-				case 'document':
-					$table='fm_document_category';
-					break;
 				case 'owner':
-					$table='fm_owner_category';
+					$info = array
+					(
+						'table' => 'fm_owner_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::owner::owner_cats'
+					);
 					break;
 				case 'tenant':
-					$table='fm_tenant_category';
+					$info = array
+					(
+						'table' => 'fm_tenant_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('tenant category'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::tenant::tenant_cats'
+					);
 					break;
 				case 'vendor':
-					$table='fm_vendor_category';
+					$info = array
+					(
+						'table' => 'fm_vendor_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('vendor category'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::vendor::vendor_cats'
+					);
 					break;
 				case 'district':
-					$table='fm_district';
+					$info = array
+					(
+						'table' => 'fm_district',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('district'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::location::district'
+					);
 					break;
 				case 'street':
-					$table='fm_streetaddress';
+					$info = array
+					(
+						'table' => 'fm_streetaddress',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('streetaddress'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::location::street'
+					);
 					break;
 				case 's_agreement':
-					$table='fm_s_agreement_category';
+					$info = array
+					(
+						'table' => 'fm_s_agreement_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::agreement::service_agree_cats'
+					);
 					break;
 				case 'tenant_claim':
-					$table='fm_tenant_claim_category';
+					$info = array
+					(
+						'table' => 'fm_tenant_claim_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::tenant::claims_cats'
+					);
 					break;
 				case 'wo_hours':
-					$table='fm_wo_hours_category';
+					$info = array
+					(
+						'table' => 'fm_wo_hours_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::workorder_detail'
+					);
 					break;
 				case 'r_condition_type':
-					$table='fm_request_condition_type';
+					$info = array
+					(
+						'table' => 'fm_request_condition_type',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::request_condition'
+					);
 					break;
 				case 'r_agreement':
-					$table='fm_r_agreement_category';
+					$info = array
+					(
+						'table' => 'fm_r_agreement_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> '',
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::agreement::rental_agree_cats'
+					);
 					break;
 				case 'b_account':
-					$table='fm_b_account_category';
+					$info = array
+					(
+						'table' => 'fm_b_account_category',
+						'id'				=> array('name' => 'id', 'type' => 'int'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'	=> lang('edit'),
+						'add_msg'	=> lang('add'),
+						'name'		=> lang('budget account'),
+						'acl_location' => '.admin',
+						'menu_selection' => 'admin::property::accounting::accounting_cats'
+					);
 					break;
+//-------- ID type varchar
+				case 'project_status':
+					$info = array
+					(
+						'table' 			=> 'fm_project_status',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'approved',
+								'descr' => lang('approved'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'closed',
+								'descr' => lang('closed'),
+								'type' => 'checkbox'
+							)
+						),
+						'edit_msg'			=> lang('edit status'),
+						'add_msg'			=> lang('add status'),
+						'name'				=> lang('project status'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::project_status'
+					);
+					break;
+				case 'workorder_status':
+					$info = array
+					(
+						'table' 			=> 'fm_workorder_status',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'approved',
+								'descr' => lang('approved'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'in_progress',
+								'descr' => lang('In progress'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'delivered',
+								'descr' => lang('delivered'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'closed',
+								'descr' => lang('closed'),
+								'type' => 'checkbox'
+							)
+						),
+						'edit_msg'			=> lang('edit status'),
+						'add_msg'			=> lang('add status'),
+						'name'				=> lang('workorder status'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::workorder_status'
+					);
+					break;
+				case 'request_status':
+					$info = array
+					(
+						'table' 			=> 'fm_request_status',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'			=> lang('edit status'),
+						'add_msg'			=> lang('add status'),
+						'name'				=> lang('request status'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::request_status'
+					);
+					break;
+				case 'agreement_status':
+					$info = array
+					(
+						'table' 			=> 'fm_agreement_status',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'			=> lang('edit status'),
+						'add_msg'			=> lang('add status'),
+						'name'				=> lang('agreement status'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::agreement::agreement_status'
+					);
+					break;
+				case 'building_part':
+					$info = array
+					(
+						'table' 			=> 'fm_building_part',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('building part'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::building_part'
+					);
+					break;
+				case 'document_status':
+					$info = array
+					(
+						'table' 			=> 'fm_document_status',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'			=> lang('edit status'),
+						'add_msg'			=> lang('add status'),
+						'name'				=> lang('document status'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::document_status'
+					);
+					break;
+				case 'unit':
+					$info = array
+					(
+						'table' 			=> 'fm_standard_unit',
+						'id'				=> array('name' => 'id', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'			=> lang('edit unit'),
+						'add_msg'			=> lang('add unit'),
+						'name'				=> lang('unit'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::unit'
+					);
+					break;
+//-------- ID type auto
 				case 'branch':
-					$table='fm_branch';
+					$info = array
+					(
+						'table' 			=> 'fm_branch',
+						'id'				=> array('name' => 'id', 'type' => 'auto'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'num',
+								'descr' => lang('name'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'varchar'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('branch'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::branch'
+					);
+
 					break;
+				case 'key_location':
+					$info = array
+					(
+						'table' 			=> 'fm_key_loc',
+						'id'				=> array('name' => 'id', 'type' => 'auto'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'num',
+								'descr' => lang('name'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('key location'),
+								'type' => 'text'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('branch'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::key_location'
+					);
 
+					break;
+
+				case 'async':
+					$info = array
+					(
+						'table' 			=> 'fm_async_method',
+						'id'				=> array('name' => 'id', 'type' => 'auto'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'name',
+								'descr' => lang('name'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'data',
+								'descr' => lang('data'),
+								'type' => 'text'
+							),
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'text'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('Async services'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::async'
+					);
+					break;
+
+				case 'event_action':
+
+					$info = array
+					(
+						'table' 			=> 'fm_event_action',
+						'id'				=> array('name' => 'id', 'type' => 'auto'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'name',
+								'descr' => lang('name'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'action',
+								'descr' => lang('action'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'data',
+								'descr' => lang('data'),
+								'type' => 'text'
+							),
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'text'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('event action'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::event_action',
+						'default'			=> array
+						(
+							'user_id' 		=> array('add'	=> '$this->account'),
+							'entry_date'	=> array('add'	=> 'time()'),
+							'modified_date'	=> array('edit'	=> 'time()'),
+						)
+					);
+
+					break;
+
+				case 'ticket_status':
+
+					$info = array
+					(
+						'table' 			=> 'fm_tts_status',
+						'id'				=> array('name' => 'id', 'type' => 'auto'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'name',
+								'descr' => lang('name'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'color',
+								'descr' => lang('color'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'approved',
+								'descr' => lang('approved'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'in_progress',
+								'descr' => lang('In progress'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'delivered',
+								'descr' => lang('delivered'),
+								'type' => 'checkbox'
+							),
+							array
+							(
+								'name' => 'closed',
+								'descr' => lang('closed'),
+								'type' => 'checkbox'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('event action'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::ticket_status'
+					);
+					break;
+				case 'pending_action_type':
+					$info = array
+					(
+						'table' 			=> 'fm_action_pending_category',
+						'id'				=> array('name' => 'num', 'type' => 'varchar'),
+						'fields'			=> array
+						(
+							array
+							(
+								'name' => 'name',
+								'descr' => lang('name'),
+								'type' => 'varchar'
+							),
+							array
+							(
+								'name' => 'descr',
+								'descr' => lang('descr'),
+								'type' => 'text'
+							)
+						),
+						'edit_msg'			=> lang('edit'),
+						'add_msg'			=> lang('add'),
+						'name'				=> lang('Pending action type'),
+						'acl_location' 		=> '.admin',
+						'menu_selection'	=> 'admin::property::action_type'
+					);
+
+					break;
+
+				default:
+					$receipt = array();
+					$receipt['error'][]=array('msg'=>lang('ERROR: illegal type %1', $type));
+					phpgwapi_cache::session_set('phpgwapi', 'phpgw_messages', $receipt);
+				//	throw new Exception(lang('ERROR: illegal type %1', $type));
 			}
 
-			return $table;
+			$this->location_info = $info;
+			return $info;
 		}
 
+		function read_single($data,$values = array())
+		{
+			if (!isset($this->location_info['table']) || !$table = $this->location_info['table'])
+			{
+				return $values;
+			}
 
-		function read_single($id,$type,$type_id)
+			if($this->location_info['id']['type']=='auto' || $this->location_info['id']['type']=='int')
+			{
+				$id = (int) $data['id'];
+			}
+			else
 		{
+				$id = "'{$data['id']}'";
+			}
 
-			$table = $this->select_table($type,$type_id);
+			$sql = "SELECT * FROM $table WHERE {$this->location_info['id']['name']} = {$id}";
 
-			$sql = "SELECT * FROM $table  where id='$id'";
+			$this->_db->query($sql,__LINE__,__FILE__);
 
-			$this->db->query($sql,__LINE__,__FILE__);
+			if ($this->_db->next_record())
+			{
+				$values['id'] = $this->_db->f($this->location_info['id']['name']);
 
-			if ($this->db->next_record())
+				// FIXME - add field to $values['attributes']
+				foreach($this->location_info['fields'] as $field)
 			{
-				$category['id']		= $this->db->f('id');
-				$category['descr']	= stripslashes($this->db->f('descr'));
+					$values[$field['name']] = $this->_db->f($field['name'], true);
+				}
 
-				return $category;
+				if ( isset($values['attributes']) && is_array($values['attributes']) )
+				{
+					foreach ( $values['attributes'] as &$attr )
+					{
+						$attr['value'] 	= $this->_db->f($attr['column_name']);
 			}
 		}
+			}
+			return $values;
+		}
 
 
 		function select_category_list($data)
 		{
-			$table = $this->select_table($data['type'],$data['type_id']);
+			$values = array();
+
+			$this->get_location_info($data['type'], $data['type_id']);
+
+			if (!isset($this->location_info['table']) || !$table = $this->location_info['table'])
+			{
+				return $values;
+			}
 			$order		= isset($data['order']) && $data['order'] == 'id' ? 'id' :'descr';
 
-			$this->db->query("SELECT id, descr FROM $table ORDER BY $order");
+			$this->_db->query("SELECT id, descr FROM $table ORDER BY $order");
 
-			while ($this->db->next_record())
+			while ($this->_db->next_record())
 			{
-				$categories[] = array(
-					'id'	=> $this->db->f('id'),
-					'name'	=> stripslashes($this->db->f('descr'))
+				$values[] = array
+				(
+					'id'	=> $this->_db->f('id'),
+					'name'	=> $this->_db->f('descr', true)
 					);
 			}
-			return (isset($categories)?$categories:false);
+			return $values;
 		}
 
 
-		function add($category,$type,$type_id)
+		function add($data,$values_attribute)
 		{
-			$table = $this->select_table($type,$type_id);
+			$receipt = array();
 
-			$category['descr'] = $this->db->db_addslashes($category['descr']);
+			if (!isset($this->location_info['table']) || !$table = $this->location_info['table'])
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
 
-			$this->db->query("INSERT INTO $table (id, descr) "
-				. "VALUES ('" . $category['id'] . "','" . $category['descr']. "')",__LINE__,__FILE__);
+			if(isset($data['save']))
+			{
+				unset($data['save']);
+			}
+			if(isset($data['apply']))
+			{
+				unset($data['apply']);
+		}
+			$cols = array();
+			$vals = array();
 
-			$receipt['message'][]=array('msg'=>lang('category has been saved'));
-			return $receipt;
+			$data['descr'] = $this->_db->db_addslashes($data['descr']);
+
+			if(isset($data['extra']))
+		{
+				foreach ($data['extra'] as $input_name => $value)
+				{
+					if(isset($value) && $value)
+					{
+						$cols[] = $input_name;
+						$vals[] = $value;
+					}
+				}
+			}
+			unset($data['extra']);
+
+			foreach ($data as $input_name => $value)
+			{
+				if(isset($value) && $value)
+				{
+					$cols[] = $input_name;
+					$vals[] = $this->_db->db_addslashes($value);
+				}
+			}
+
+			$data_attribute = $this->custom->prepare_for_db($table, $values_attribute);
+			if(isset($data_attribute['value_set']))
+			{
+				foreach($data_attribute['value_set'] as $input_name => $value)
+				{
+					if(isset($value) && $value)
+					{
+						$cols[] = $input_name;
+						$vals[] = $value;
+					}
+				}
+			}
+
+
+			if(isset($this->location_info['default']) && is_array($this->location_info['default']))
+			{
+				foreach ($this->location_info['default'] as $field => $default)
+				{
+					if(isset($default['add']))
+					{
+						$cols[] = $field;
+						eval('$vals[] = ' . $default['add'] .';');
 		}
+				}
+			}
 
-		function edit($category,$type,$type_id)
+			$this->_db->transaction_begin();
+
+			if($this->location_info['id']['type']!='auto')
+			{
+				$this->_db->query("SELECT id FROM {$table} WHERE {$this->location_info['id']['name']} = '{$data['id']}'",__LINE__,__FILE__);
+				if($this->_db->next_record())
+				{
+					$receipt['error'][]=array('msg'=>lang('duplicate key value'));
+					$receipt['error'][]=array('msg'=>lang('record has not been saved'));
+					return $receipt;
+				}
+				$id = $data['id'];
+			}
+			else
 		{
+				$id = $this->_db->next_id($table);
+				$cols[] = 'id';
+				$vals[] = $id;
+			}
 
-			$table = $this->select_table($type,$type_id);
+			$cols	= implode(",", $cols);
+			$vals	= $this->_db->validate_insert($vals);
 
-			$category['descr'] = $this->db->db_addslashes($category['descr']);
+			$this->_db->query("INSERT INTO {$table} ({$cols}) VALUES ({$vals})",__LINE__,__FILE__);
 
-			$this->db->query("UPDATE $table set descr='" . $category['descr']
-							. "' WHERE id='" . $category['id']. "'",__LINE__,__FILE__);
+/*			if($this->location_info['id']['type']=='auto')
+			{
+				if(!$data['id'] = $this->_db->get_last_insert_id($table, 'id'))
+				{
+					$this->_db->transaction_abort();
+					$receipt['error'][]=array('msg'=>lang('record has not been saved'));
+				}
+			}
+*/
+			$this->_db->transaction_commit();
+			$receipt['id'] = $id;
+			$receipt['message'][]=array('msg'=>lang('record has been saved'));
+			return $receipt;
+		}
 
+		function edit($data,$values_attribute)
+		{
+			$receipt = array();
 
-			$receipt['message'][]=array('msg'=>lang('category has been edited'));
+			if (!isset($this->location_info['table']) || !$table = $this->location_info['table'])
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
 			return $receipt;
 		}
 
-		function delete($id,$type,$type_id)
+			$value_set = array();
+
+			if(isset($data['extra']))
+			{
+				foreach ($data['extra'] as $input_name => $value)
+				{
+					$value_set[$input_name] = $value;
+				}
+				unset($data['extra']);
+			}
+
+			$data_attribute = $this->custom->prepare_for_db($table, $values_attribute, $data['id']);
+
+			if(isset($data_attribute['value_set']))
+			{
+				$value_set = array_merge($value_set, $data_attribute['value_set']);
+			}
+			foreach($this->location_info['fields'] as $field)
 		{
-			$table = $this->select_table($type,$type_id);
+				$value_set[$field['name']] = $this->_db->db_addslashes($data[$field['name']]);
+			}
 
-			$this->db->query("DELETE FROM $table WHERE id='" . $id . "'",__LINE__,__FILE__);
+			if(isset($this->location_info['default']) && is_array($this->location_info['default']))
+			{
+				foreach ($this->location_info['default'] as $field => $default)
+				{
+					if(isset($default['edit']))
+					{
+						eval('$value_set[$field] = ' . $default['edit'] .';');
+					}
+				}
+			}
+
+			$value_set	= $this->_db->validate_update($value_set);
+			$this->_db->transaction_begin();
+			$this->_db->query("UPDATE $table SET {$value_set} WHERE {$this->location_info['id']['name']}='" . $data['id']. "'",__LINE__,__FILE__);
+
+/*			//FIXME
+			if (isset($data_attribute['history_set']) && is_array($data_attribute['history_set']))
+			{
+				$historylog	= CreateObject('phpgwapi.historylog','property', $this->location_info['acl_location']);
+				foreach ($data_attribute['history_set'] as $attrib_id => $history)
+				{
+					$historylog->add('SO',$data['id'],$history['value'],false, $attrib_id,$history['date']);
+				}
+			}
+*/
+			$this->_db->transaction_commit();
+
+			$receipt['id'] = $data['id'];
+
+			$receipt['message'][]=array('msg'=>lang('record has been edited'));
+			return $receipt;
 		}
+
+		function delete($id)
+		{
+			if (!isset($this->location_info['table']) || !$table = $this->location_info['table'])
+			{
+				return false;
+			}
+			$this->_db->query("DELETE FROM $table WHERE {$this->location_info['id']['name']}='{$id}'",__LINE__,__FILE__);
+		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.socommon.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.socommon.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.socommon.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -32,6 +32,8 @@
 	 * @package property
 	 */
 
+	phpgw::import_class('phpgwapi.datetime');
+
 	class property_socommon
 	{
 		/**
@@ -45,12 +47,13 @@
 		 var $like = 'LIKE';
 
 
-		function property_socommon()
+		function __construct()
 		{
 
 			if(is_object($GLOBALS['phpgw']->db))
 			{
-				$this->db = CreateObject('phpgwapi.db');
+				$this->db = & $GLOBALS['phpgw']->db;
+				//$this->db = CreateObject('phpgwapi.db');
 			}
 			else // for setup
 			{
@@ -114,8 +117,18 @@
 					$value = $GLOBALS['phpgw']->db->db_addslashes($value);
 				}
 
+				$this->db->query("SELECT value FROM fm_cache WHERE name='{$name}'");
+
+				if($this->db->next_record())
+				{
+					$this->db->query("UPDATE fm_cache SET value = '{$value}' WHERE name='{$name}'",__LINE__,__FILE__);
+				}
+				else
+				{
 				$this->db->query("INSERT INTO fm_cache (name,value)VALUES ('$name','$value')",__LINE__,__FILE__);
 			}
+
+			}
 			else
 			{
 				$this->db->query("SELECT value FROM fm_cache where name='$name'");
@@ -298,11 +311,15 @@
 
 		function increment_id($name)
 		{
-			$this->db->query("SELECT value FROM fm_idgenerator WHERE name='$name'");
+			if($name == 'order') // FIXME: temporary hack
+			{
+				$name = 'workorder';
+			}
+			$this->db->query("SELECT value FROM fm_idgenerator WHERE name='{$name}'");
 			$this->db->next_record();
-			$next_id=$this->db->f('value') +1;
+			$next_id = $this->db->f('value') +1;
 
-			$this->db->query("update fm_idgenerator set value = $next_id WHERE name = 'workorder'");
+			$this->db->query("UPDATE fm_idgenerator SET value = $next_id WHERE name = '{$name}'");
 			return $next_id;
 		}
 
@@ -312,6 +329,10 @@
 			{
 				$db = clone($db);
 			}
+			else if( is_object($GLOBALS['phpgw']->db) )
+			{
+				$db = & $GLOBALS['phpgw']->db;
+			}
 			else
 			{
 				$db = CreateObject('phpgwapi.db');

Modified: people/sigurdne/modules/property/trunk/inc/class.socustom.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.socustom.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.socustom.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,17 +34,12 @@
 
 	class property_socustom
 	{
-		function property_socustom()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read($data)
@@ -80,16 +75,14 @@
 
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
+				$query = $this->db->db_addslashes($query);
 				$querymethod = " $where name $this->like '%$query%'";
 			}
 
 			$sql = "SELECT * FROM fm_custom $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -115,15 +108,20 @@
 
 		function read_single($custom_id)
 		{
-			$this->db->query("select * from fm_custom where id='$custom_id'",__LINE__,__FILE__);
+			$custom_id = (int) $custom_id;
+			$this->db->query("SELECT * from fm_custom where id={$custom_id}",__LINE__,__FILE__);
 
+			$custom = array();
 			if ($this->db->next_record())
 			{
-				$custom['id']			= (int)$this->db->f('id');
-				$custom['name']			= stripslashes($this->db->f('name'));
-				$custom['sql_text']			= stripslashes($this->db->f('sql_text'));
-				$custom['entry_date']	= $this->db->f('entry_date');
-				$custom['cols'] 		= $this->read_cols($custom_id);
+				$custom = array
+				(
+					'id'			=> (int)$this->db->f('id'),
+					'name'			=> $this->db->f('name', true),
+					'sql_text'		=> $this->db->f('sql_text', true),
+					'entry_date'	=> $this->db->f('entry_date'),
+					'cols'			=> $this->read_cols($custom_id)
+				);
 			}
 
 			return $custom;
@@ -131,43 +129,41 @@
 
 		function read_cols($custom_id)
 		{
-			$sql = "SELECT * FROM fm_custom_cols WHERE custom_id=$custom_id ORDER by sorting";
+			$custom_id = (int) $custom_id;
+			$sql = "SELECT * FROM fm_custom_cols WHERE custom_id={$custom_id} ORDER by sorting";
 			$this->db->query($sql);
 
+			$cols = array();
 			while ($this->db->next_record())
 			{
-				$choice[] = array
+				$cols[] = array
 				(
 					'id'	=> $this->db->f('id'),
 					'name'	=> $this->db->f('name'),
-					'descr'	=> $this->db->f('descr'),
+					'descr'	=> $this->db->f('descr', true),
 					'sorting'=> $this->db->f('sorting')
 				);
 
 			}
-			return $choice;
+			return $cols;
 		}
 
 		function read_custom_name($custom_id)
 		{
-			$this->db->query("select name from fm_custom where id='$custom_id'",__LINE__,__FILE__);
-
-			if ($this->db->next_record())
-			{
-				$name			= stripslashes($this->db->f('name'));
-			}
-
-			return $name;
+			$custom_id = (int) $custom_id;
+			$this->db->query("SELECT name FROM fm_custom where id={$custom_id}",__LINE__,__FILE__);
+			$this->db->next_record();
+			return $this->db->f('name', true);
 		}
 
 		function add($custom)
 		{
 			$custom['name'] = $this->db->db_addslashes($custom['name']);
-			$custom['sql_text'] = $this->db->db_addslashes($custom['sql_text']);
+			$custom['sql_text'] = $this->db->db_addslashes(htmlspecialchars_decode($custom['sql_text']));
 
 			$this->db->transaction_begin();
 
-			$id = $this->bocommon->next_id('fm_custom');
+			$id = $this->db->next_id('fm_custom');
 
 			$this->db->query("INSERT INTO fm_custom (id,entry_date,sql_text,name,user_id) "
 				. "VALUES ($id,'" . time() . "','" . $custom['sql_text'] . "','" . $custom['name'] . "'," . $this->account . ")",__LINE__,__FILE__);
@@ -184,20 +180,19 @@
 		function edit($custom)
 		{
 			$custom['name'] = $this->db->db_addslashes($custom['name']);
-			$custom['sql_text'] = $this->db->db_addslashes($custom['sql_text']);
+			$custom['sql_text'] = $this->db->db_addslashes(htmlspecialchars_decode($custom['sql_text']));
 
-			$this->db->query("UPDATE fm_custom set sql_text='" . $custom['sql_text'] . "', entry_date='" . time() . "', name='" . $custom['name'] . "' WHERE id=" . intval($custom['custom_id']),__LINE__,__FILE__);
+			$this->db->query("UPDATE fm_custom set sql_text='" . $custom['sql_text'] . "', entry_date='" . time() . "', name='" . $custom['name'] . "' WHERE id=" . (int) $custom['custom_id'],__LINE__,__FILE__);
 
 			if($custom['new_name'])
 			{
-				$column_id = $this->bocommon->next_id('fm_custom_cols' ,array('custom_id'=>$custom['custom_id']));
+				$column_id = $this->db->next_id('fm_custom_cols', array('custom_id'=>$custom['custom_id']));
 
 				$sql = "SELECT max(sorting) as max_sort FROM fm_custom_cols WHERE custom_id=" . $custom['custom_id'];
 				$this->db->query($sql);
 				$this->db->next_record();
 				$sorting	= $this->db->f('max_sort')+1;
 
-
 				$values= array(
 					$custom['custom_id'],
 					$column_id,
@@ -206,7 +201,7 @@
 					$sorting
 					);
 
-				$values	= $this->bocommon->validate_db_insert($values);
+				$values	= $this->db->validate_insert($values);
 
 				$this->db->query("INSERT INTO fm_custom_cols (custom_id,id,name,descr,sorting) "
 				. "VALUES ($values)");
@@ -291,25 +286,27 @@
 		{
 			if(is_array($data))
 			{
-				$start	= (isset($data['start'])?$data['start']:0);
-				$filter	= (isset($data['filter'])?$data['filter']:'none');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$cat_id = (isset($data['cat_id'])?$data['cat_id']:0);
-				$allrows 		= (isset($data['allrows'])?$data['allrows']:'');
-				$custom_id 		= (isset($data['custom_id'])?$data['custom_id']:'');
+				$start		= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$filter		= isset($data['filter']) && $data['filter'] ? $data['filter'] : 'none';
+				$query		= isset($data['query']) ? $data['query'] : '';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
+				$order		= isset($data['order']) ? $data['order'] : '';
+				$allrows 	= isset($data['allrows']) ? $data['allrows'] : '';
+				$custom_id 	= isset($data['custom_id']) && $data['custom_id'] ? (int)$data['custom_id'] : 0;
 			}
 
-			$this->db->query("select sql_text from fm_custom where id='$custom_id'",__LINE__,__FILE__);
+			$this->db->query("SELECT sql_text FROM fm_custom where id={$custom_id}",__LINE__,__FILE__);
 			$this->db->next_record();
-			$sql = stripslashes($this->db->f('sql_text'));
+			$sql = $this->db->f('sql_text', true);
 
 			$uicols = $this->read_cols($custom_id);
 			$this->uicols = $uicols;
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			//FIXME:
+			$ordermethod = '';
+			
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -338,8 +335,9 @@
 
 		function delete($custom_id)
 		{
-			$this->db->query('DELETE FROM fm_custom WHERE id=' . intval($custom_id),__LINE__,__FILE__);
-			$this->db->query('DELETE FROM fm_custom_cols WHERE custom_id=' . intval($custom_id),__LINE__,__FILE__);
+			$custom_id = (int) $custom_id;
+			$this->db->query("DELETE FROM fm_custom WHERE id={$custom_id}",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_custom_cols WHERE custom_id={$custom_id}",__LINE__,__FILE__);
 		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.sodocument.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sodocument.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sodocument.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,57 +35,55 @@
 	class property_sodocument
 	{
 
-		function property_sodocument()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           = $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
 			$this->historylog	= CreateObject('property.historylog','document');
 			$this->vfs 			= CreateObject('phpgwapi.vfs');
-			$this->rootdir 		= $this->vfs->basedir;
+			$this->vfs->fakebase 		= '/property';
 			$this->fakebase 	= $this->vfs->fakebase;
-			$this->socommon		= CreateObject('property.socommon');
+			$this->cats					= CreateObject('phpgwapi.categories');
+			$this->cats->app_name		= 'property.document';
+			$this->cats->supress_info	= true;
 
-			$this->join			= $this->socommon->join;
-			$this->like			= $this->socommon->like;
+
+			$this->db           	= & $GLOBALS['phpgw']->db;
+			$this->join				= & $this->db->join;
+			$this->like				= & $this->db->like;
 		}
 
 
-		function read_single_category($id='')
-		{
-			$this->db->query("SELECT descr FROM fm_document_category where id='$id' ");
-			$this->db->next_record();
-			return $this->db->f('descr');
-		}
-
 		function select_status_list()
 		{
+			$status = array();
 			$this->db->query("SELECT id, descr FROM fm_document_status ORDER BY id ");
 
-			$i = 0;
 			while ($this->db->next_record())
 			{
-				$status_entries[$i]['id']				= $this->db->f('id');
-				$status_entries[$i]['name']				= stripslashes($this->db->f('descr'));
-				$i++;
+				$status[] = array
+				(
+					'id'	=> $this->db->f('id'),
+					'name'	=> $this->db->f('descr',true)
+				);
 			}
-			return $status_entries;
+			return $status;
 		}
 
 		function select_branch_list()
 		{
+			$branch = array();
 			$this->db->query("SELECT id, descr FROM fm_branch ORDER BY id ");
 
-			$i = 0;
 			while ($this->db->next_record())
 			{
-				$branch_entries[$i]['id']				= $this->db->f('id');
-				$branch_entries[$i]['name']				= stripslashes($this->db->f('descr'));
-				$i++;
+				$branch[] = array
+				(
+					'id'	=> $this->db->f('id'),
+					'name'	=> $this->db->f('descr',true)
+				);
 			}
-			return $branch_entries;
+			return $branch;
 		}
 
 		function read($data)
@@ -99,9 +97,11 @@
 				$order		= isset($data['order'])?$data['order']:'';
 				$cat_id		= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id']:0;
 				$entity_id	= isset($data['entity_id'])?$data['entity_id']:'';
-				$doc_type	= isset($data['doc_type']) && $data['doc_type'] ? $data['doc_type']:0;
+				$doc_type		= isset($data['doc_type']) && $data['doc_type'] ? $data['doc_type']: 0;
 			}
 
+			$doc_types = $this->get_sub_doc_types($doc_type);
+
 			$sql = $this->bocommon->fm_cache('sql_document_' . $entity_id);
 
 			if(!$sql)
@@ -174,7 +174,7 @@
 				$this->cols_extra	= $this->bocommon->fm_cache('cols_extra_document_' . $entity_id);
 			}
 
-			$groupmethod= " GROUP BY fm_document.location_code,fm_document.address,fm_document.document_name";
+			$groupmethod= " GROUP BY fm_document.location_code,fm_document.address";
 
 			if ($entity_id)
 			{
@@ -195,7 +195,7 @@
 
 			$filtermethod = '';
 
-			$GLOBALS['phpgw']->config->read_repository();
+			$GLOBALS['phpgw']->config->read();
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
 			{
 				$access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
@@ -215,10 +215,10 @@
 				$where= 'AND';
 			}
 
-			if ($doc_type > 0)
+			if ($doc_types && is_array($doc_types))
 			{
-				$filtermethod .= " $where fm_document.category='$doc_type' ";
-				$where= 'AND';
+				$filtermethod .= " $where fm_document.category IN (". implode(',', $doc_types) . ')';
+				$where = 'AND';
 			}
 
 			if ($filter!='all' && $filter)
@@ -237,8 +237,8 @@
 
 //echo $sql;
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
 
 			$document_list = array();
@@ -270,24 +270,20 @@
 		{
 			if(is_array($data))
 			{
-				if ($data['start'])
-				{
-					$start=$data['start'];
-				}
-				else
-				{
-					$start=0;
-				}
-				$filter	= (isset($data['filter'])?$data['filter']:'');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$entity_id = (isset($data['entity_id'])?$data['entity_id']:0);
-				$cat_id = (isset($data['cat_id'])?$data['cat_id']:0);
-				$doc_type = (isset($data['doc_type'])?$data['doc_type']:0);
-				$location_code = (isset($data['location_code'])?$data['location_code']:'');
+				$start			= isset($data['start']) && $data['start'] ? $data['start']:0;
+				$query			= isset($data['query'])?$data['query']:'';
+				$sort			= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order			= isset($data['order'])?$data['order']:'';
+				$filter			= isset($data['filter']) && $data['filter'] ? (int) $data['filter']: 0;
+				$entity_id		= isset($data['entity_id']) && $data['entity_id'] ? (int)$data['entity_id']:0;
+				$cat_id			= isset($data['cat_id']) && $data['cat_id'] ? (int)$data['cat_id']: 0;
+				$doc_type		= isset($data['doc_type']) && $data['doc_type'] ? $data['doc_type']: 0;
+				$allrows		= isset($data['allrows'])?$data['allrows']:'';
+				$location_code	= isset($data['location_code'])?$data['location_code']:'';
 			}
 
+			$doc_types = $this->get_sub_doc_types($doc_type);
+
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
@@ -297,38 +293,55 @@
 				$ordermethod = ' order by location_code ASC';
 			}
 
-			$filtermethod = " fm_document.location_code $this->like '$location_code%'";
+			$where = 'WHERE';
+			$filtermethod = '';
+			if($location_code)
+			{
+				$filtermethod = " $where fm_document.location_code $this->like '$location_code%'";
+				$where = 'AND';
+			}
 
-			if ($doc_type > 0)
+			if ($doc_types && is_array($doc_types))
 			{
-				$filtermethod .= " AND fm_document.category='$doc_type' ";
+				$filtermethod .= " $where fm_document.category IN (". implode(',', $doc_types) . ')';
+				$where = 'AND';
 			}
 			if ($cat_id > 0)
 			{
-				$filtermethod .= " AND fm_document.p_cat_id=$cat_id AND fm_document.p_entity_id=$entity_id ";
+				$filtermethod .= " $where fm_document.p_cat_id={$cat_id} AND fm_document.p_entity_id={$entity_id} ";
+				$where = 'AND';
 			}
 
-
-			if ($filter)
+			if ($filter > 0)
 			{
-				$filtermethod .= " AND fm_document.user_id='$filter' ";
+				$filtermethod .= "  $where fm_document.user_id='$filter' ";
+				$where = 'AND';
 			}
 
 			if($query)
 			{
 				$query = $this->db->db_addslashes($query);
-				$querymethod = " AND fm_document.title $this->like '%$query%' OR fm_document.document_name"
-				. " $this->like '%$query%' OR fm_document.location_code $this->like '$location_code%'";
+				$querymethod = " $where (fm_document.title $this->like '%$query%' OR fm_document.document_name"
+				. " $this->like '%$query%')";
 			}
 
-			$sql = "SELECT fm_document.*, fm_document_category.descr as category FROM fm_document"
-			. " $this->join fm_document_category on fm_document.category = fm_document_category.id"
-			. " WHERE  $filtermethod $querymethod";
+			$sql = "SELECT fm_document.*, phpgw_categories.cat_name as category FROM fm_document"
+			. " $this->join phpgw_categories on fm_document.category = phpgw_categories.cat_id"
+			. " $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
+
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+			}
 
+			$document_list = array();
 			while ($this->db->next_record())
 			{
 				$document_list[] = array
@@ -341,7 +354,7 @@
 					'user_id'			=> $this->db->f('user_id')
 					);
 			}
-//_debug_array($document_list);
+
 			return $document_list;
 		}
 
@@ -439,7 +452,7 @@
 				$document['vendor_id'],
 				$this->account);
 
-			$values	= $this->bocommon->validate_db_insert($values);
+			$values	= $this->db->validate_insert($values);
 
 			$this->db->query("INSERT INTO fm_document (document_name,link,title,access,category,entry_date,document_date,version,coordinator,status,"
 				. "descr,location_code,address,branch_id,vendor_id,user_id $cols) "
@@ -468,6 +481,7 @@
 
 		function edit($document)
 		{
+			$receipt = array();
 			while (is_array($document['location']) && list($input_name,$value) = each($document['location']))
 			{
 				$vals[]	= "$input_name = '$value'";
@@ -495,28 +509,43 @@
 				$address = $this->db->db_addslashes($document['location_name']);
 			}
 
-			$this->db->query("SELECT status,category,coordinator,document_name,loc1,link,p_num FROM fm_document where id='" .$document['document_id']."'",__LINE__,__FILE__);
+			$this->db->query("SELECT status,category,coordinator,document_name,location_code,link,p_entity_id,p_cat_id,p_num FROM fm_document where id='" .$document['document_id']."'",__LINE__,__FILE__);
 			$this->db->next_record();
 
 			$old_status = $this->db->f('status');
 			$old_doc_type = $this->db->f('category');
 			$old_coordinator = $this->db->f('coordinator');
 			$old_document_name = $this->db->f('document_name');
-			$old_loc1 = $this->db->f('loc1');
 			$old_link = $this->db->f('link');
+			$old_location_code	= $this->db->f('location_code');
+			$old_p_entity_id	= $this->db->f('p_entity_id');
+			$old_p_cat_id		= $this->db->f('p_cat_id');
 			$old_p_num = $this->db->f('p_num');
 
+			$move_file = false;
+
+			if($old_location_code != $document['location_code'])
+			{
+				$move_file = true;			
+			}
+
+			if("{$old_p_entity_id}_{$old_p_cat_id}" != "{$document['extra']['p_entity_id']}_{$document['extra']['p_cat_id']}")
+			{
+				$move_file = true;			
+			}
+
 			if ($old_status != $document['status'])
 			{
-				$this->historylog->add('S',$document['document_id'],$document['status']);
+				$this->historylog->add('S',$document['document_id'],$document['status'],$old_status);
 			}
 			if ($old_doc_type != $document['doc_type'])
 			{
-				$this->historylog->add('T',$document['document_id'],$document['doc_type']);
+				$this->historylog->add('T',$document['document_id'],$document['doc_type'],$old_doc_type);
+				$move_file = true;
 			}
 			if ((int)$old_coordinator != (int)$document['coordinator'])
 			{
-				$this->historylog->add('C',$document['document_id'],$document['coordinator']);
+				$this->historylog->add('C',$document['document_id'],$document['coordinator'],$old_coordinator);
 			}
 
 			if($document['document_name_orig'] && !$document['document_name'] )
@@ -526,32 +555,34 @@
 
 			if($old_link !=$document['link'] )
 			{
-					$this->historylog->add('L',$document['document_id'],$document['link']);
+					$this->historylog->add('L',$document['document_id'],$document['link'],$old_link);
 					$alter_link=true;
 			}
 
-//_debug_array($document);
-			if ($old_document_name && ($old_document_name != $document['document_name']))
+
+			if ($old_document_name && ($old_document_name != $document['document_name'] || $move_file = true))
 			{
 				if($document['link'] && !$alter_link)
 				{
-					$this->historylog->add('L',$document['document_id'],$document['link']);
+					$this->historylog->add('L',$document['document_id'],$document['link'],$old_document_name);
 				}
 				else
 				{
-					$this->historylog->add('F',$document['document_id'],$document['document_name']);
+					$this->historylog->add('F',$document['document_id'],$document['document_name'],$old_document_name);
 				}
 
-				if($old_p_num)
+				// file is already moved
+			/*	if($old_p_entity_id)
 				{
-					$file = $this->fakebase. '/' . 'document' . '/' . $old_loc1 . '/' . $document['entity_name'] . '/' . $document['category_name'] . '/' . $p_num . '/' . $old_document_name;
+					$file = "{$this->fakebase}/document/entity_{$old_p_entity_id}_{$old_p_cat_id}/{$old_p_num}/{$old_doc_type}/$old_document_name";
 				}
 				else
 				{
-					$file = $this->fakebase. '/' . 'document' . '/' . $old_loc1 . '/' . $old_document_name;
+					$file = "{$this->fakebase}/document/{$old_location_code}/{$old_doc_type}/{$old_document_name}";
 				}
 
 				$receipt= $this->delete_file($file);
+			*/
 			}
 
 			if($document['link'])
@@ -579,18 +610,122 @@
 				'address'		=>$address
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->query("UPDATE fm_document set $value_set $vals WHERE id= '" . $document['document_id'] ."'",__LINE__,__FILE__);
 
 			$receipt['document_id'] = $document['document_id'];
 			$receipt['message'][] = array('msg'=>lang('document %1 has been edited',"'".$document['title']."'"));
 			return $receipt;
+		}
 
+		/**
+		 * Get a list of doc-types , included subtypes
+		 *
+		 * @param int $doc_type the parent doc-type
+		 * @return array parent and children
+		 */
+
+		function get_sub_doc_types($doc_type = 0)
+		{
+			$doc_types = array();
+			if($doc_type)
+			{
+				$doc_types[] = $doc_type;
+				$cat_sub = $this->cats->return_sorted_array($start = 0,$limit = false,$query = '',$sort = '',$order = '',$globals = False, $parent_id = $doc_type);
+				foreach ($cat_sub as $doc_type)
+				{
+					$doc_types[] = $doc_type['id'];
+				}
+			}
+			return $doc_types;
 		}
 
+
+		/**
+		 * Get a hierarchical array of doc-types with number of hits for each level at locatin and link to list.
+		 * Basis for the folder-menu
+		 *
+		 * @param string $location_code location_code in the (physical) location-hierarchy
+		 * @return array parent and children
+		 */
+
+		function get_files_at_location($location_code)
+		{
+			$documents = array();
+			$sql = "SELECT count(*) as hits FROM fm_document WHERE location_code $this->like '$location_code%'";
+			$this->db->query($sql,__LINE__,__FILE__);
+			if($this->db->next_record())
+			{
+				$hits = (int) $this->db->f('hits');
+
+				$x = 0; // within level
+				$y = 0; //level
+				$cache_x_at_y[$y] = $x;
+				$documents[$x] = array
+				(
+					'link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uidocument.list_doc','location_code'=> $location_code)),
+					'text'		=> lang('documents') . ' [' . $hits . ']:',
+					'descr'		=> lang('Documentation'),
+					'level'		=> 0
+				);
+			}
+			else
+			{
+				return $documents;
+			}
+
+			$categories = $this->cats->return_sorted_array(0, false);
+
+			foreach ($categories as $category)
+			{			
+				$doc_types = $this->get_sub_doc_types($category['id']);
+
+				$sql = "SELECT count(*) as hits FROM fm_document WHERE location_code $this->like '$location_code%' AND category IN (". implode(',', $doc_types) . ')';
+				$this->db->query($sql,__LINE__,__FILE__);
+				$this->db->next_record();
+				$hits = (int) $this->db->f('hits');
+
+				$level = $category['level']+1;
+				if($level == $y)
+				{
+					$x++;
+				}
+				else if($level < $y )
+				{
+					$x = $cache_x_at_y[$level]+1;
+				}
+				else if($level > $y )
+				{
+					$x = 0;
+				}
+				$y = $level;
+
+					$map = '$documents'; 
+					for ($i = 0; $i < $level ; $i++)
+					{
+						
+						$map .= '[' . $cache_x_at_y[$i] ."]['children']"; 
+					}
+
+					$map .= '[]'; 
+
+					eval($map . ' =array('
+					.	"'link'	=> '" . $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uidocument.list_doc','location_code'=> $location_code, 'doc_type'=> $category['id'])) . "',\n"
+					.	"'text'			=> '" . $category['name'] . ' [' . $hits . ']' . "',\n"
+					.	"'descr'		=> '" . lang('Documentation') . "',\n"
+					.	"'level'		=> "  . ($category['level']+1) . "\n"
+					 . ');');
+
+				$cache_x_at_y[$y] = $x;
+			}
+
+			return $documents;
+		}
+
 		function delete_file($file)
 		{
+			$receipt = array();
 			if($this->vfs->file_exists(array(
 					'string' => $file,
 					'relatives' => Array(RELATIVE_NONE)
@@ -605,52 +740,51 @@
 				     )
 				)))
 				{
-					$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'. $this->fakebase. '/' . 'document'. '/' . $document_name);
+					$receipt['error'][]=array('msg'=>lang('failed to delete file') . ' :'. $file);
 				}
 				else
 				{
-					$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. $this->fakebase. '/' . 'document'. '/' . $document_name);
+					$receipt['message'][]=array('msg'=>lang('file deleted') . ' :'. $file);
 				}
 				$this->vfs->override_acl = 0;
 			}
-
+			return $receipt;
 		}
 
-		function delete($document_id )
+		function delete($document_id)
 		{
-			$this->db->query("SELECT document_name,location_code,p_num,p_entity_id,p_cat_id FROM fm_document where id='$document_id'",__LINE__,__FILE__);
+			$receipt = array();
+			$document_id = (int) $document_id;
+			$this->db->query("SELECT document_name,location_code,p_num,p_entity_id,p_cat_id,category FROM fm_document where id='$document_id'",__LINE__,__FILE__);
 			$this->db->next_record();
 			$document_name	= $this->db->f('document_name');
 			$location_code	= $this->db->f('location_code');
-			$p_num			= $this->db->f('p_num');
 			$p_entity_id	= $this->db->f('p_entity_id');
 			$p_cat_id		= $this->db->f('p_cat_id');
+			$p_num		= $this->db->f('p_num');
+			$category	= $this->db->f('category');
 
-			$location		= split("-", $location_code);
-			$loc1	= $location[0];
-			if($p_cat_id)
-			{
-				$boadmin_entity		= CreateObject('property.boadmin_entity');
-				$entity = $boadmin_entity->read_single($p_entity_id,false);
-				$category = $boadmin_entity->read_single_category($p_entity_id,$p_cat_id);
-			}
-
 			if($document_name)
 			{
-				if($p_num)
+				if($p_cat_id > 0)
 				{
-					$file = $this->fakebase. '/' . 'document' . '/' . $loc1 . '/' . $entity['name'] . '/' . $category['name'] . '/' . $p_num . '/' . $document_name;
+					$file = "{$this->fakebase}/document/entity_{$p_entity_id}_{$p_cat_id}/{$p_num}/{$category}/$document_name";
 				}
 				else
 				{
-					$file = $this->fakebase. '/' . 'document' . '/' . $loc1 . '/' . $document_name;
+					$file = "{$this->fakebase}/document/{$location_code}/{$category}/{$document_name}";
 				}
 
 				$receipt= $this->delete_file($file);
 			}
-
-			$this->db->query("DELETE FROM fm_document WHERE id='$document_id'",__LINE__,__FILE__);
-			$this->db->query("DELETE FROM fm_document_history  WHERE  history_record_id='$document_id'",__LINE__,__FILE__);
+			if(!isset($receipt['error']))
+			{
+				$this->db->transaction_begin();
+				$this->db->query("DELETE FROM fm_document WHERE id={$document_id}",__LINE__,__FILE__);
+				$this->db->query("DELETE FROM fm_document_history  WHERE  history_record_id={$document_id}",__LINE__,__FILE__);
+				$this->db->transaction_commit();
+			}
+			return $receipt;
 		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.soentity.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soentity.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soentity.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -40,18 +40,19 @@
 		var $uicols;
 		var $cols_extra;
 		var $cols_return_lookup;
+		var $type = 'entity';
+		var $type_app;
 
-		function property_soentity($entity_id='',$cat_id='')
+		function __construct($entity_id='',$cat_id='')
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           = $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
+			$this->custom 		= createObject('property.custom_fields');
+			$this->db           = & $GLOBALS['phpgw']->db;
 
-			$this->join			= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like			= $this->bocommon->like;
+			$this->join			= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
 			$this->entity_id	= $entity_id;
 			$this->cat_id		= $cat_id;
 		}
@@ -63,7 +64,7 @@
 				return;
 			}
 
-			$location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}");
+			$location_id = $GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");
 
 			$sql= "SELECT phpgw_cust_choice.id, phpgw_cust_choice.value FROM phpgw_cust_attribute"
 			. " $this->join phpgw_cust_choice ON"
@@ -105,6 +106,9 @@
 				$status			= isset($data['status']) ? $data['status'] : '';
 				$start_date		= isset($data['start_date']) ? $data['start_date'] : '';
 				$end_date		= isset($data['end_date']) ? $data['end_date'] : '';
+				$dry_run		= isset($data['dry_run']) ? $data['dry_run'] : '';
+				$this->type		= isset($data['type']) && $data['type'] ? $data['type'] : $this->type;
+				$location_code	= isset($data['location_code']) ? $data['location_code'] : '';
 			}
 
 			if(!$entity_id || !$cat_id)
@@ -112,66 +116,99 @@
 				return;
 			}
 
-			$grants 	= $GLOBALS['phpgw']->session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,'property');
+			$grants 	= $GLOBALS['phpgw']->session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,$this->type_app[$this->type]);
 
 			if(!$grants)
 			{
 				$this->acl 	= & $GLOBALS['phpgw']->acl;
-				$grants		= $this->acl->get_grants('property','.entity.' . $entity_id . '.' . $cat_id);
-				$GLOBALS['phpgw']->session->appsession('grants_entity_'.$entity_id.'_'.$cat_id,'property',$grants);
+				$grants		= $this->acl->get_grants($this->type_app[$this->type],".{$this->type}.{$entity_id}.{$cat_id}");
+				$GLOBALS['phpgw']->session->appsession('grants_entity_'.$entity_id.'_'.$cat_id, $this->type_app[$this->type], $grants);
 			}
 
-			$sql = $this->bocommon->fm_cache('sql_entity_' . $entity_id . '_' . $cat_id . '_' . $lookup);
+			$sql = $this->bocommon->fm_cache("sql_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}");
 
 			$admin_entity	= CreateObject('property.soadmin_entity');
+			$admin_entity->type = $this->type;
+
 			$category = $admin_entity->read_single_category($entity_id,$cat_id);
 
-			$entity_table = 'fm_entity_' . $entity_id . '_' . $cat_id;
+			$entity_table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
 			$choice_table = 'phpgw_cust_choice';
 			$attribute_table = 'phpgw_cust_attribute';
-			$location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}");
+			$location_id = $GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");
 			$attribute_filter = " location_id = {$location_id}";
 
 			if(!$sql)
 			{
+				$cols_return_extra	= array();
+				$cols_return		= array();
+				$uicols				= array();
 				$cols = $entity_table . '.*';
+
 				$cols_return[] = 'location_code';
+				$uicols['input_type'][]		= 'hidden';
+				$uicols['name'][]			= 'location_code';
+				$uicols['descr'][]			= 'dummy';
+				$uicols['statustext'][]		= 'dummy';
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
 
 				$cols_return[] 			= 'num';
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]		= 'num';
 				$uicols['descr'][]		= lang('ID');
 				$uicols['statustext'][]		= lang('ID');
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
 
 				$cols_return[] 			= 'id';
 				$uicols['input_type'][]		= 'hidden';
 				$uicols['name'][]		= 'id';
 				$uicols['descr'][]		= false;
 				$uicols['statustext'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+
 				if($lookup)
 				{
 					$cols .= ',num as entity_num_' . $entity_id;
 					$cols_return[] = 'entity_num_' . $entity_id;
+					$uicols['input_type'][]		= 'hidden';
+					$uicols['name'][]			= 'entity_num_' . $entity_id;
+					$uicols['descr'][]			= 'dummy';
+					$uicols['statustext'][]		= 'dummy';
+					$uicols['align'][] 			= '';
+					$uicols['datatype'][]		= '';
 				}
 
-				$cols .= ',account_lid';
-				$cols_return[] 				= 'account_lid';
+				$cols .= ", {$entity_table}.user_id";
+				$cols_return[] 				= 'user_id';
 				$uicols['input_type'][]		= 'text';
-				$uicols['name'][]			= 'account_lid';
+				$uicols['name'][]			= 'user_id';
 				$uicols['descr'][]			= lang('User');
 				$uicols['statustext'][]		= lang('User');
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= 'user';
 
-				$joinmethod = " $this->join phpgw_accounts ON ($entity_table.user_id = phpgw_accounts.account_id))";
-				$paranthesis ='(';
+				$cols_return_extra[]= array
+								(
+									'name'		=> 'user_id',
+									'datatype'	=> 'user'
+								);
 
+				// Don't work with LDAP - where phpgw_accounts is empty
+	//			$joinmethod = " $this->join phpgw_accounts ON ($entity_table.user_id = phpgw_accounts.account_id))";
+	//			$paranthesis ='(';
+
 				$sql = $this->bocommon->generate_sql(array('entity_table'=>$entity_table,'cols_return'=>$cols_return,'cols'=>$cols,
 								'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query,'lookup'=>$lookup,'location_level'=>$category['location_level']));
 
-				$this->bocommon->fm_cache('sql_entity_' . $entity_id . '_' . $cat_id . '_' . $lookup,$sql);
-				$this->bocommon->fm_cache('uicols_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->uicols);
-				$this->bocommon->fm_cache('cols_return_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->cols_return);
-				$this->bocommon->fm_cache('cols_return_lookup_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->cols_return_lookup);
-				$this->bocommon->fm_cache('cols_extra_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup,$this->bocommon->cols_extra);
+				$this->bocommon->fm_cache("sql_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}", $sql);
+				$this->bocommon->fm_cache("uicols_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}", $this->bocommon->uicols);
+				$this->bocommon->fm_cache("cols_return_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}", $this->bocommon->cols_return);
+				$this->bocommon->fm_cache("cols_return_lookup_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}", $this->bocommon->cols_return_lookup);
+				$this->bocommon->fm_cache("cols_extra_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}", $this->bocommon->cols_extra);
+				$this->bocommon->fm_cache("cols_extra_return_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}", $cols_return_extra);
 
 				$uicols				= $this->bocommon->uicols;
 				$cols_return			= $this->bocommon->cols_return;
@@ -180,24 +217,25 @@
 			}
 			else
 			{
-				$uicols 			= $this->bocommon->fm_cache('uicols_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup);
-				$cols_return			= $this->bocommon->fm_cache('cols_return_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup);
-				$this->cols_return_lookup 	= $this->bocommon->fm_cache('cols_return_lookup_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup);
-				$this->cols_extra		= $this->bocommon->fm_cache('cols_extra_entityt_' . $entity_id . '_' . $cat_id . '_' . $lookup);
+				$uicols 					= $this->bocommon->fm_cache("uicols_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}");
+				$cols_return				= $this->bocommon->fm_cache("cols_return_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}");
+				$this->cols_return_lookup 	= $this->bocommon->fm_cache("cols_return_lookup_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}");
+				$this->cols_extra			= $this->bocommon->fm_cache("cols_extra_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}");
+				$cols_return_extra			= $this->bocommon->fm_cache("cols_extra_return_{$this->type}_{$entity_id}_{$cat_id}_{$lookup}");
 			}
 
 			if ($cat_id > 0)
 			{
 //-------------------
 
-				$user_columns = isset($GLOBALS['phpgw_info']['user']['preferences']['property']['entity_columns_'.$entity_id.'_'.$cat_id])?$GLOBALS['phpgw_info']['user']['preferences']['property']['entity_columns_'.$entity_id.'_'.$cat_id]:'';
+				$user_columns = isset($GLOBALS['phpgw_info']['user']['preferences'][$this->type_app[$this->type]]['entity_columns_'.$entity_id.'_'.$cat_id])?$GLOBALS['phpgw_info']['user']['preferences'][$this->type_app[$this->type]]['entity_columns_'.$entity_id.'_'.$cat_id]:'';
 				$user_column_filter = '';
 				if (isset($user_columns) AND is_array($user_columns) AND $user_columns[0])
 				{
 					$user_column_filter = " OR ($attribute_filter AND id IN (" . implode(',',$user_columns) .'))';
 				}
 
-				$this->db->query("SELECT * FROM $attribute_table WHERE list=1 AND $attribute_filter $user_column_filter ORDER BY attrib_sort ASC");
+				$this->db->query("SELECT * FROM $attribute_table WHERE list=1 AND $attribute_filter $user_column_filter ORDER BY group_id, attrib_sort ASC");
 
 				$i	= count($uicols['name']);
 				while ($this->db->next_record())
@@ -207,6 +245,14 @@
 					$uicols['descr'][]			= $this->db->f('input_text');
 					$uicols['statustext'][]		= $this->db->f('statustext');
 					$uicols['datatype'][$i]		= $this->db->f('datatype');
+					$uicols['cols_return_extra'][$i] = array
+					(
+						'name'	=> $this->db->f('column_name'),
+						'datatype'	=> $this->db->f('datatype'),
+						'attrib_id'	=> $this->db->f('id')					
+					);
+					
+					
 					$cols_return_extra[]= array(
 						'name'	=> $this->db->f('column_name'),
 						'datatype'	=> $this->db->f('datatype'),
@@ -220,7 +266,14 @@
 				$uicols['name'][]			= 'entry_date';
 				$uicols['descr'][]			= lang('entry date');
 				$uicols['statustext'][]		= lang('entry date' );
-				$uicols['datatype'][$i]		= 'timestamp';
+				$uicols['datatype'][]		= 'timestamp';
+				$uicols['cols_return_extra'][$i] = array
+				(
+					'name'		=> 'entry_date',
+					'datatype'	=> 'timestamp',
+				);
+
+
 				$cols_return_extra[]= array(
 					'name'	=> 'entry_date',
 					'datatype'	=> 'timestamp',
@@ -236,7 +289,14 @@
 //_debug_array($cols_return_extra);
 			if ($order)
 			{
-				$ordermethod = " order by $entity_table.$order $sort";
+				switch($order)
+				{
+					case 'user_id':
+		//				$ordermethod = " ORDER BY phpgw_accounts.account_lastname {$sort}";  // Don't work with LDAP. 
+						break;
+					default:
+						$ordermethod = " ORDER BY $entity_table.$order $sort";	
+				}
 			}
 			else
 			{
@@ -246,7 +306,7 @@
 			$where= 'WHERE';
 			$filtermethod = '';
 
-			$GLOBALS['phpgw']->config->read_repository();
+			$GLOBALS['phpgw']->config->read();
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location'])
 				&& $GLOBALS['phpgw']->config->config_data['acl_at_location']
 				&& $category['location_level'] > 0)
@@ -284,7 +344,7 @@
 
 			if ($district_id > 0)
 			{
-				$filtermethod .= " $where  district_id='$district_id' ";
+				$filtermethod .= " $where  fm_part_of_town.district_id='$district_id' ";
 				$where = 'AND';
 			}
 
@@ -294,6 +354,12 @@
 				$where= 'AND';
 			}
 
+			if ($location_code)
+			{
+				$filtermethod .= " $where $entity_table.location_code $this->like '$location_code%'";
+				$where= 'AND';			
+			}
+
 			$querymethod = '';
 			if($query)
 			{
@@ -341,11 +407,17 @@
 
 			$sql .= " $filtermethod $querymethod";
 
-//echo $sql;
+//_debug_array($sql);
 			$this->db->query('SELECT count(*)' . substr($sql,strripos($sql,'from')),__LINE__,__FILE__);
 			$this->db->next_record();
 			$this->total_records = $this->db->f(0);
 
+			if($dry_run)
+			{
+				return array();
+			}
+			else
+			{
 			if(!$allrows)
 			{
 				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@@ -354,102 +426,49 @@
 			{
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
+			}
 
 			$j=0;
-			$n=count($cols_return);
-//_debug_array($cols_return);
-			$contacts			= CreateObject('phpgwapi.contacts');
-
-			$entity_list = array();
+			$cols_return = $uicols['name'];
+			$dataset = array();
 			while ($this->db->next_record())
 			{
-				for ($i=0;$i<$n;$i++)
-				{
-					$entity_list[$j][$cols_return[$i]] = $this->db->f($cols_return[$i]);
-					$entity_list[$j]['grants'] = (int)$grants[$this->db->f('user_id')];
-					if($lookup)
-					{
-						$entity_list[$j]['entity_cat_name_' . $entity_id] = $category['name'];
-						$entity_list[$j]['entity_id_' . $entity_id] = $entity_id;
-						$entity_list[$j]['cat_id_' . $entity_id] = $cat_id;
-					}
-				}
-
-				if(isset($cols_return_extra) && is_array($cols_return_extra))
-				{
-					for ($i=0;$i<count($cols_return_extra);$i++)
-					{
-						$value = $this->db->f($cols_return_extra[$i]['name'], true);
-
-						if(($cols_return_extra[$i]['datatype']=='R' || $cols_return_extra[$i]['datatype']=='LB') && $value)
-						{
-							$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $value;
-							$this->db2->query($sql);
-							$this->db2->next_record();
-							$entity_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('value');
-						}
-						else if($cols_return_extra[$i]['datatype']=='AB' && $value)
-						{
-							$contact_data	= $contacts->read_single_entry($value,array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-							$entity_list[$j][$cols_return_extra[$i]['name']]	= $contact_data[0]['n_family'] . ', ' . $contact_data[0]['n_given'];
-						}
-						else if($cols_return_extra[$i]['datatype']=='VENDOR' && $value)
-						{
-							$sql="SELECT org_name FROM fm_vendor where id=$value";
-							$this->db2->query($sql);
-							$this->db2->next_record();
-							$entity_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('org_name');
-						}
-						else if($cols_return_extra[$i]['datatype']=='CH' && $value)
-						{
-							$ch= unserialize($value);
-
-							if (isset($ch) AND is_array($ch))
+				foreach($cols_return as $key => $field)
 							{
-								for ($k=0;$k<count($ch);$k++)
-								{
-									$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
-									$this->db2->query($sql);
-									while ($this->db2->next_record())
-									{
-										$ch_value[]=$this->db2->f('value');
-									}
-								}
-								$entity_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
-								unset($ch_value);
-							}
+					$dataset[$j][$field] = array
+					(
+						'value'		=> $this->db->f($field),
+						'datatype'	=> $uicols['datatype'][$key],
+						'attrib_id'	=> $uicols['cols_return_extra'][$key]['attrib_id']
+					);
 						}
-						else if($cols_return_extra[$i]['datatype']=='D' && $value)
+				if($lookup)
 						{
-							$entity_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($value));
-						}
-						else if($cols_return_extra[$i]['datatype']=='timestamp' && $value)
-						{
-							$entity_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],$value);
-						}
-						else if($cols_return_extra[$i]['datatype']=='link' && $value)
-						{
-							$entity_list[$j][$cols_return_extra[$i]['name']]= phpgw::safe_redirect($value);
-						}
-						else
-						{
-							$entity_list[$j][$cols_return_extra[$i]['name']] = $value;
-						}
+					$dataset[$j]["entity_cat_name_{$entity_id}"] = array
+					(
+						'value'		=> $category['name'],
+						'datatype'	=> false,
+						'attrib_id'	=> false
+					);
+					$dataset[$j]["entity_id_{$entity_id}"] = array
+					(
+						'value'		=> $entity_id,
+						'datatype'	=> false,
+						'attrib_id'	=> false
+					);
+					$dataset[$j]["cat_id_{$entity_id}"] = array
+					(
+						'value'		=> $cat_id,
+						'datatype'	=> false,
+						'attrib_id'	=> false
+					);
 					}
+				$j++;				
 				}
 
-				$location_code=	$this->db->f('location_code');
-				$location = split('-',$location_code);
-				for ($m=0;$m<count($location);$m++)
-				{
-					$entity_list[$j]['loc' . ($m+1)] = $location[$m];
-					$entity_list[$j]['query_location']['loc' . ($m+1)]=implode("-", array_slice($location, 0, ($m+1)));
-				}
+			$values = $this->custom->translate_value($dataset, $location_id);
 
-				$j++;
-			}
-//_debug_array($entity_list);
-			return $entity_list;
+			return $values;
 		}
 
 		function read_single($data,$values = array())
@@ -457,7 +476,7 @@
 			$entity_id =$data['entity_id'];
 			$cat_id =$data['cat_id'];
 			$id =$data['id'];
-			$table='fm_entity_' . $entity_id .'_' . $cat_id;
+			$table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
 
 				$this->db->query("SELECT * FROM $table WHERE id =$id");
 
@@ -489,7 +508,7 @@
 
 		function check_entity($entity_id,$cat_id,$num)
 		{
-			$table='fm_entity_' . $entity_id .'_' . $cat_id;
+			$table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
 			$this->db->query("SELECT count(*) FROM $table where num='$num'");
 
 			$this->db->next_record();
@@ -502,7 +521,7 @@
 
 		function generate_id($data)
 		{
-			$table='fm_entity_' . $data['entity_id'] .'_' . $data['cat_id'];
+			$table = "fm_{$this->type}_{$data['entity_id']}_{$data['cat_id']}";
 			$this->db->query("select max(id) as id from $table");
 			$this->db->next_record();
 			$id = $this->db->f('id')+1;
@@ -512,7 +531,7 @@
 
 		function generate_num($entity_id,$cat_id,$id)
 		{
-			$this->db->query("select prefix from fm_entity_category WHERE entity_id=$entity_id AND id=$cat_id ");
+			$this->db->query("select prefix from fm_{$this->type}_category WHERE entity_id=$entity_id AND id=$cat_id ");
 			$this->db->next_record();
 			$prefix = $this->db->f('prefix');
 
@@ -533,6 +552,9 @@
 
 		function add($values,$values_attribute,$entity_id,$cat_id)
 		{
+			$cols = array();
+			$vals = array();
+
 			if(isset($values['street_name']) && $values['street_name'])
 			{
 				$address[]= $values['street_name'];
@@ -542,9 +564,21 @@
 
 			if(!isset($address) || !$address)
 			{
-				$address = $this->db->db_addslashes($values['location_name']);
+				$address = isset($values['location_name']) ? $this->db->db_addslashes($values['location_name']) : '';
 			}
 
+			if(isset($address) && $address)
+			{
+				$cols[] = 'address';
+				$vals[] = $address;
+			}
+
+			if (isset($values['location_code']) && $values['location_code'])
+			{
+				$cols[] = 'location_code';
+				$vals[] = $values['location_code'];			
+			}
+
 			if(isset($values['location']) && is_array($values['location']))
 			{
 				foreach ($values['location'] as $input_name => $value)
@@ -596,17 +630,21 @@
 				$cols	= "," . implode(",", $cols);
 				$vals	= "," . $this->bocommon->validate_db_insert($vals);
 			}
+			else
+			{
+				$cols = '';
+				$vals = '';
+			}
 
-			$table='fm_entity_' . $entity_id .'_' . $cat_id;
+			$table = "fm_{$this->type}_{$entity_id}_$cat_id";
+			$this->db->transaction_begin();
+			$values['id'] = $this->generate_id(array('entity_id'=>$entity_id,'cat_id'=>$cat_id));
 			$num=$this->generate_num($entity_id,$cat_id,$values['id']);
-			$this->db->transaction_begin();
 
-			$this->db->query("INSERT INTO $table (id,num,address,location_code,entry_date,user_id $cols) "
+			$this->db->query("INSERT INTO $table (id,num,entry_date,user_id $cols) "
 				. "VALUES ("
 				. $values['id']. ",'"
-				. $num . "','"
-				. $address. "','"
-				. $values['location_code']. "',"
+				. $num . "',"
 				. time() . ","
 				. $this->account. " $vals)",__LINE__,__FILE__);
 
@@ -618,7 +656,7 @@
 					(
 						'location1_id'		=> $GLOBALS['phpgw']->locations->get_id('property', $values['origin'][0]['location']),
 						'location1_item_id' => $values['origin'][0]['data'][0]['id'],
-						'location2_id'		=> $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}"),
+						'location2_id'		=> $GLOBALS['phpgw']->locations->get_id('property', ".{$this->type}.{$entity_id}.{$cat_id}"),
 						'location2_item_id' => $values['id'],
 						'account_id'		=> $this->account
 					);
@@ -630,7 +668,7 @@
 
 			if (isset($history_set) AND is_array($history_set))
 			{
-				$historylog	= CreateObject('property.historylog','entity_' . $entity_id .'_' . $cat_id);
+				$historylog	= CreateObject('property.historylog',"{$this->type}_{$entity_id}_{$cat_id}");
 				foreach ($history_set as $attrib_id => $new_value)
 				{
 					$historylog->add('SO',$values['id'],$new_value,false, $attrib_id);
@@ -639,37 +677,51 @@
 
 			$this->db->transaction_commit();
 
+			$receipt = array();
+			$receipt['id'] = $values['id'];
 			$receipt['message'][] = array('msg'=>lang('Entity %1 has been saved',$values['id']));
 			return $receipt;
 		}
 
 		function edit($values,$values_attribute,$entity_id,$cat_id)
 		{
+			$receipt	= array();
+			$value_set	= array();
+			$table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
+
 			if(isset($values['street_name']) && $values['street_name'])
 			{
 				$address[]= $values['street_name'];
 				$address[]= $values['street_number'];
-				$address	= implode(" ", $address);
+				$value_set['address'] = $this->db->db_addslashes(implode(" ", $address));
 			}
 
 			if(!isset($address) || !$address)
 			{
-				$address = $values['location_name'];
+				$address = isset($values['location_name']) ? $this->db->db_addslashes($values['location_name']) : '';
+				if($address)
+				{
+					$value_set['address'] = $address;
+				}
 			}
 
-			$value_set=array(
-				'location_code'	=> $values['location_code'],
-				'address'	=> $this->db->db_addslashes($address)
-				);
+			if (isset($values['location_code']) && $values['location_code'])
+			{
+					$value_set['location_code'] = $values['location_code'];
+			}
 
 			$admin_location	= CreateObject('property.soadmin_location');
 			$admin_location->read(false);
 
 			// Delete old values for location - in case of moving up in the hierarchy
+			$metadata = $this->db->metadata($table);
 			for ($i = 1;$i < $admin_location->total_records + 1; $i++)
 			{
+				if(isset($metadata["loc{$i}"]))
+				{
 				$value_set["loc{$i}"]	= false;
 			}
+			}
 
 			if(isset($values['location']) && is_array($values['location']))
 			{
@@ -687,14 +739,11 @@
 				}
 			}
 
-//_debug_array($values_attribute);
-			$table = 'fm_entity_' . $entity_id .'_' . $cat_id;
-
 			if (isset($values_attribute) AND is_array($values_attribute))
 			{
 				foreach($values_attribute as $entry)
 				{
-					if($entry['datatype']!='AB' && $entry['datatype']!='VENDOR')
+					if($entry['datatype']!='AB' && $entry['datatype']!='VENDOR' && $entry['datatype']!='user' && $entry['datatype']!='event')
 					{
 						if($entry['datatype'] == 'C' || $entry['datatype'] == 'T' || $entry['datatype'] == 'V' || $entry['datatype'] == 'link')
 						{
@@ -736,7 +785,7 @@
 			}
 
 //_debug_array($history_set);
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->transaction_begin();
 
@@ -744,7 +793,7 @@
 
 			if (isset($history_set) AND is_array($history_set))
 			{
-				$historylog	= CreateObject('property.historylog','entity_' . $entity_id .'_' . $cat_id);
+				$historylog	= CreateObject('property.historylog',"{$this->type}_{$entity_id}_{$cat_id}");
 				foreach ($history_set as $attrib_id => $history)
 				{
 					$historylog->add('SO',$values['id'],$history['value'],false, $attrib_id,$history['date']);
@@ -753,14 +802,15 @@
 
 			$this->db->transaction_commit();
 
+			$receipt['id'] = $values['id'];
 			$receipt['message'][] = array('msg'=>lang('entity %1 has been edited',$values['num']));
 			return $receipt;
 		}
 
 		function delete($entity_id,$cat_id,$id )
 		{
-			$location2_id	= $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}");			
-			$table='fm_entity_' . $entity_id .'_' . $cat_id;
+			$location2_id	= $GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");			
+			$table = "fm_{$this->type}_{$entity_id}_{$cat_id}";
 			$this->db->transaction_begin();
 			$this->db->query("DELETE FROM $table WHERE id=$id",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM phpgw_interlink WHERE location2_id ={$location2_id} AND location2_item_id = {$id}",__LINE__,__FILE__);
@@ -778,7 +828,7 @@
 				return;
 			}
 
-			$location_id = $GLOBALS['phpgw']->locations->get_id('property', ".entity.{$entity_id}.{$cat_id}");
+			$location_id = $GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}");
 
 			$this->db->query("SELECT helpmsg FROM fphpgw_cust_attribute WHERE location_id = {$location_id} AND id =" . (int)$attrib_id );
 

Added: people/sigurdne/modules/property/trunk/inc/class.soevent.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soevent.inc.php	                        (rev 0)
+++ people/sigurdne/modules/property/trunk/inc/class.soevent.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -0,0 +1,507 @@
+<?php
+	/**
+	* phpGroupWare - property: a Facilities Management System.
+	*
+	* @author Sigurd Nes <[email protected]>
+	* @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software Foundation, Inc. http://www.fsf.org/
+	* This file is part of phpGroupWare.
+	*
+	* phpGroupWare is free software; you can redistribute it and/or modify
+	* it under the terms of the GNU General Public License as published by
+	* the Free Software Foundation; either version 2 of the License, or
+	* (at your option) any later version.
+	*
+	* phpGroupWare is distributed in the hope that it will be useful,
+	* but WITHOUT ANY WARRANTY; without even the implied warranty of
+	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	* GNU General Public License for more details.
+	*
+	* You should have received a copy of the GNU General Public License
+	* along with phpGroupWare; if not, write to the Free Software
+	* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+	*
+	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
+	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
+	* @package property
+	* @subpackage admin
+ 	* @version $Id$
+	*/
+
+	/*
+	 * Import the datetime class for date processing
+	 */
+	phpgw::import_class('phpgwapi.datetime');
+
+	/**
+	 * Description
+	 * @package property
+	 */
+
+	class property_soevent
+	{
+
+		function __construct()
+		{
+			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
+			$this->_db 			= & $GLOBALS['phpgw']->db;
+			$this->_join		= & $this->_db->loin;
+			$this->_like		= & $this->_db->like;
+		}
+
+		function read($data)
+		{
+			if(!isset($data['location_id']) || !$data['location_id'])
+			{
+				if(!isset($data['appname']) || !$data['appname'] || !isset($data['location']) || !$data['location'])
+				{
+					throw new Exception("property_soevent::read - Missing location info in input");
+				}
+				$location_id = $GLOBALS['phpgw']->locations->get_id($data['appname'], $data['location']);
+			}
+			else
+			{
+				$location_id = (int) $data['location_id'];
+			}
+
+			$location_item_id 	= isset($data['location_item_id']) && $data['location_item_id'] ? (int)$data['location_item_id'] : '';
+			$start				= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+			$query				= isset($data['query']) ? $data['query'] : '';
+			$sort				= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+			$order				= isset($data['order']) ? $data['order'] : '';
+			$allrows			= isset($data['allrows']) ? $data['allrows'] : '';
+
+			if(!isset($data['location_item_id']) || !$data['location_item_id'])
+			{
+				throw new Exception("property_soevent::read - Missing location_item_id in input");
+			}
+
+			$location_item_id	= $data['location_item_id'];
+
+			$events = array();
+
+			$table = 'fm_event';
+
+			$filtermethod = "WHERE location_id = {$location_id}";
+			
+			if($location_item_id)
+			{
+				$filtermethod .= " AND location_item_id = {$location_item_id}";
+			}
+			
+			if($query)
+			{
+				$query = $this->_db->db_addslashes($query);
+
+				$querymethod = " AND id $this->_like '%$query%' OR descr $this->_like '%$query%'";
+			}
+
+			$sql = "SELECT * FROM {$table} {$filtermethod} {$querymethod}";
+
+			$this->_db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->_db->num_rows();
+
+			if(!$allrows)
+			{
+				$this->_db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->_db->query($sql . $ordermethod,__LINE__,__FILE__);
+			}
+
+			while ($this->_db->next_record())
+			{
+				$events[] = array
+				(
+					'id'	=> $this->_db->f('id'),
+					'descr'	=> $this->_db->f('descr')
+				);
+			}
+			return $events;
+		}
+
+		function read_single($id)
+		{
+			$values = array();
+
+			$table = 'fm_event';
+
+			$sql = "SELECT * FROM $table WHERE id='{$id}'";
+
+			$this->_db->query($sql,__LINE__,__FILE__);
+
+			if ($this->_db->next_record())
+			{
+				$start_date		= $this->_db->f('start_date');
+				$end_date		= $this->_db->f('end_date');				
+				$values = array
+				(
+					'id'				=> $this->_db->f('id'),
+					'descr'				=> $this->_db->f('descr', true),
+					'start_date'		=> $start_date,
+					'responsible'		=> $this->_db->f('responsible_id'),
+					'action'			=> $this->_db->f('action_id'),
+					'end_date'			=> $end_date,
+					'repeat_type'		=> $this->_db->f('repeat_type'),
+					'rpt_day'			=> (int)$this->_db->f('repeat_day'),
+					'repeat_interval'	=> $this->_db->f('repeat_interval'),
+					'enabled'			=> $this->_db->f('enabled'),
+					'user_id'			=> $this->_db->f('user_id'),
+					'entry_date'		=> $this->_db->f('entry_date'),
+					'modified_date'		=> $this->_db->f('modified_date'),
+					'location_id'		=> $this->_db->f('location_id'),
+					'location_item_id'	=> $this->_db->f('location_item_id'),
+					'attrib_id'			=> $this->_db->f('attrib_id')
+				);
+
+				$values['start']['month']	= date('m',$start_date);
+				$values['start']['mday']	= date('d',$start_date);
+				$values['start']['year']	= date('Y',$start_date);
+				$values['start']['hour']	= date('G',$start_date);
+				$values['start']['min']		= date('i',$start_date);
+				$values['start']['sec']		= date('s',$start_date);
+
+				$values['end']['month']	= $end_date ? date('m',$end_date) : 0;
+				$values['end']['mday']	= $end_date ? date('d',$end_date) : 0;
+				$values['end']['year']	= $end_date ? date('Y',$end_date) : 0;
+				$values['end']['hour']	= $end_date ? date('G',$end_date) : 0;
+				$values['end']['min']	= $end_date ? date('i',$end_date) : 0;
+				$values['end']['sec']	= $end_date ? date('s',$end_date) : 0;
+
+				$sql = "SELECT * FROM fm_event_exception WHERE event_id ='{$id}'";
+
+				$this->_db->query($sql,__LINE__,__FILE__);
+				while ($this->_db->next_record())
+				{
+					$values['repeat_exception'][] = $this->_db->f('exception_time');
+				}
+			}
+
+			return $values;
+		}
+
+		function add($data)
+		{
+			$receipt = array();
+			$table = 'fm_event';
+
+			$data['descr'] = $this->_db->db_addslashes($data['descr']);
+
+			$cols = array
+			(
+				'location_id',
+				'location_item_id',
+				'attrib_id',
+				'descr',
+				'start_date',
+				'responsible_id',
+				'action_id',
+				'end_date',
+				'repeat_type',
+				'repeat_day',
+				'repeat_interval',
+				'enabled',
+				'user_id',
+				'entry_date'
+			);
+
+			$repeat_day = 0;
+			if(isset($data['repeat_day']) && is_array($data['repeat_day']))
+			{
+				foreach ($data['repeat_day'] as $day)
+				{
+					$repeat_day |= $day;
+				}
+			}
+
+			$vals = array
+			(
+				$data['location_id'],
+				$data['item_id'],
+				$data['attrib_id'],
+				$data['descr'],				
+				$data['start_date'],
+				$data['responsible'],
+				$data['action'],
+				$data['end_date'],
+				$data['repeat_type'],				
+				$repeat_day,
+				$data['repeat_interval'],
+				$data['enabled'],
+				$this->account,
+				time()
+			);
+
+			$this->_db->transaction_begin();
+
+			$id = $this->_db->next_id($table);
+			$cols[] = 'id';
+			$vals[] = $id;
+
+			$cols	= implode(",", $cols);
+			$vals	= $this->_db->validate_insert($vals);
+
+			$this->_db->query("INSERT INTO {$table} ({$cols}) VALUES ({$vals})",__LINE__,__FILE__);
+
+			if($this->_db->transaction_commit())
+			{
+				$receipt['id'] = $id;
+				$receipt['message'][] = array('msg' => lang('event has been saved'));
+			}
+			else
+			{
+				$receipt['error'][] = array('msg' => lang('event has not been saved'));
+			}
+			return $receipt;
+		}
+
+		function edit($data)
+		{
+			$receipt = array();
+			$table = 'fm_event';
+
+			$repeat_day = 0;
+			if(isset($data['repeat_day']) && is_array($data['repeat_day']))
+			{
+				foreach ($data['repeat_day'] as $day)
+				{
+					$repeat_day |= $day;
+				}
+			}
+
+			$value_set = array
+			(
+				'descr' 			=> $this->_db->db_addslashes($data['descr']),
+				'start_date'		=> $data['start_date'],
+				'responsible_id'	=> $data['responsible'],
+				'action_id'			=> $data['action'],
+				'end_date'			=> $data['end_date'],
+				'repeat_type'		=> $data['repeat_type'],
+				'repeat_day'		=> $repeat_day,
+				'repeat_interval'	=> $data['repeat_interval'],
+				'enabled'			=> $data['enabled'],
+				'modified_date'		=> time()
+			);
+
+			
+			$value_set	= $this->_db->validate_update($value_set);
+
+			$this->_db->transaction_begin();
+			$this->_db->query("UPDATE $table SET {$value_set} WHERE id='" . $data['id']. "'",__LINE__,__FILE__);
+
+			$receipt['id'] = $data['id'];
+			if($this->_db->transaction_commit())
+			{
+				$receipt['message'][] = array('msg' => lang('event has been updated'));
+			}
+			else
+			{
+				$receipt['error'][] = array('msg' => lang('event has not been updated'));
+			}
+			return $receipt;
+		}
+
+		function check_event_exception($event_id, $time)
+		{
+			$event_id = (int) $event_id;
+			$time = (int) $time;
+			$sql = "SELECT event_id FROM fm_event_exception WHERE event_id = {$event_id} AND exception_time = {$time}";
+			$this->_db->query($sql,__LINE__,__FILE__);
+			$this->_db->next_record();
+			return !!$this->_db->f('id');
+		}
+
+		function cron_log($data)
+		{
+			$insert_values= array(
+				!!$data['cron'], // or manual...
+				date($this->_db->datetime_format()),
+				$data['action'],
+				$data['message']
+				);
+
+			$insert_values	= $this->_db->validate_insert($insert_values);
+
+			$sql = "INSERT INTO fm_cron_log (cron,cron_date,process,message) "
+					. "VALUES ($insert_values)";
+			$this->_db->query($sql,__LINE__,__FILE__);
+		}
+
+		function delete($id)
+		{
+			$receipt = array();
+			$table = 'fm_event';
+			$this->_db->transaction_begin();
+			$ret = !!$this->_db->query("DELETE FROM $table WHERE id='{$id}'",__LINE__,__FILE__);
+			if($this->_db->transaction_commit())
+			{
+				return $ret;
+			}
+			return false;
+		}
+
+		//FIXME adapt from calendar	
+		function list_events($data = array())
+		{
+			$startYear			= $data['syear'];
+			$startMonth			= $data['smonth'];
+			$startDay			= $data['sday'];
+			$endYear			= $data['eyear'] ? $data['eyear'] : 0;
+			$endMonth			= $data['emonth'] ? $data['emonth'] : 0;
+			$endDay				= $data['eday'] ? $data['eday'] : 0;
+			$extra				= $data['extra'] ? $data['extra'] : '';
+			$tz_offset			= $data['tz_offset'] ? $data['tz_offset'] : 0;
+			$owner_id			= $data['owner_id'] ? $data['owner_id'] : 0;
+			$location_id		= (int) $data['location_id'];
+			$location_item_id	= (int) $data['location_item_id'];
+
+			if(!$startYear || !$startMonth || !$startDay || !$location_id || !$location_item_id)
+			{
+				throw new Exception("property_soevent::list_events - Missing start date info");
+			}
+
+//			$datetime = mktime(0,0,0,$startMonth,$startDay,$startYear) - $tz_offset;
+			$datetime = mktime(13,0,0,$startMonth,$startDay,$startYear);		
+			$sql = ' WHERE (fm_event.user_id in (';
+			if($owner_id)
+			{
+				$sql .= implode(',',$owner_id);
+			}
+			else
+			{
+				$sql .= $this->account;
+			}
+			$member_groups = $GLOBALS['phpgw']->accounts->membership($this->account);
+			@reset($member_groups);
+			foreach ($member_groups as $key => $group_info)
+			{
+				$member[] = $group_info->id;		
+			}
+
+			@reset($member);
+	//		$sql .= ','.implode(',',$member);
+			$sql .= ')) ';
+
+			$sql .= 'AND ( ( (fm_event.start_date >= '.$datetime.') ';
+
+			if($endYear != 0 && $endMonth != 0 && $endDay != 0)
+			{
+//				$edatetime = mktime(23,59,59,intval($endMonth),intval($endDay),intval($endYear)) - $tz_offset;
+				$edatetime = mktime(13,0,0,intval($endMonth),intval($endDay),intval($endYear));
+				$sql .= 'AND (fm_event.end_date <= '.$edatetime.') ) '
+					. 'OR ( (fm_event.start_date <= '.$datetime.') '
+					. 'AND (fm_event.end_date >= '.$edatetime.') ) '
+					. 'OR ( (fm_event.start_date >= '.$datetime.') '
+					. 'AND (fm_event.start_date <= '.$edatetime.') '
+					. 'AND (fm_event.end_date >= '.$edatetime.') ) '
+					. 'OR ( (fm_event.start_date <= '.$datetime.') '
+					. 'AND (fm_event.end_date >= '.$datetime.') '
+					. 'AND (fm_event.end_date <= '.$edatetime.') ';
+			}
+			$sql .= ") ) AND location_id = {$location_id} AND location_item_id = {$location_item_id}";
+
+			$order_by = ' ORDER BY fm_event.start_date ASC, fm_event.end_date ASC';
+
+			return $this->get_event_ids(False,$sql.$extra.$order_by);
+		}
+
+		function list_repeated_events($data = array())
+		{
+			$syear				= $data['syear'];
+			$smonth				= $data['smonth'];
+			$sday				= $data['sday'];
+			$eyear				= $data['eyear'];
+			$emonth				= $data['emonth'];
+			$eday				= $data['eday'];
+			$owner_id			= $data['owner_id'] ? $data['owner_id'] : 0;
+			$location_id		= (int) $data['location_id'];
+			$location_item_id	= (int) $data['location_item_id'];
+			if(!$syear || !$smonth || !$sday || !$eyear || !$emonth || !$eday || !$location_id || !$location_item_id)
+			{
+				throw new Exception("property_soevent::list_repeated_events - Missing date info");
+			}
+
+			$user_timezone = phpgwapi_datetime::user_timezone();
+
+			$starttime = mktime(0,0,0,$smonth,$sday,$syear) - $user_timezone;
+			$endtime = mktime(23,59,59,$emonth,$eday,$eyear) - $user_timezone;
+			$sql = "(fm_event.location_id = {$location_id} AND fm_event.location_item_id = {$location_item_id})"
+				. ' AND ((fm_event.end_date >= '.$starttime.') OR (fm_event.end_date=0))'
+				. ' ORDER BY fm_event.start_date ASC, fm_event.end_date ASC';
+
+			return $this->get_event_ids(true, $sql);
+		}
+
+		function get_event_ids($search_repeats = false, $extra = '')
+		{
+	//		$where = 'WHERE';
+			$repeat = '';
+			if($search_repeats)
+			{
+				$repeat = 'WHERE (fm_event.repeat_type > 0) ';
+				$where = 'AND';
+			}
+
+			$sql = 'SELECT DISTINCT fm_event.id,'
+					. ' fm_event.start_date,fm_event.end_date'
+					. " FROM fm_event {$repeat} {$where} {$extra}";
+
+			$this->_db->query($sql,__LINE__,__FILE__);
+
+			$retval = array();
+			if($this->_db->num_rows() == 0)
+			{
+				return $retval;
+			}
+	
+			while($this->_db->next_record())
+			{
+				$retval[] = intval($this->_db->f('id'));
+			}
+			if($this->debug)
+			{
+				echo "Records found!<br />\n";
+			}
+			return $retval;
+		}
+
+		public function set_exceptions($data = array())
+		{
+			if(!isset($data['event_id']) || !$data['event_id'])
+			{
+					throw new Exception("property_soevent::set_exceptions - Missing event_id in input");
+			}
+
+			foreach ($data['alarm'] as $exception_id)
+			{
+				$exception_time = mktime(13,0,0,intval(substr($exception_id,4,2)),intval(substr($exception_id,6,2)),intval(substr($exception_id,0,4)));
+				if($data['exception'])
+				{
+					$sql = "SELECT * FROM fm_event_exception WHERE event_id ='{$data['event_id']}' AND exception_time = {$exception_time}";
+					$this->_db->query($sql,__LINE__,__FILE__);
+					if ($this->_db->next_record())
+					{
+						continue;
+					}
+					else
+					{
+						$vals = array
+						(
+							$data['event_id'],
+							$exception_time,
+							$this->account,
+							phpgwapi_datetime::user_localtime(),
+						);						
+  						$vals	= $this->_db->validate_insert($vals);
+						$this->_db->query("INSERT INTO fm_event_exception (event_id, exception_time, user_id, entry_date) VALUES ({$vals})",__LINE__,__FILE__);
+					}
+				
+				}
+				else
+				{
+					$sql = "DELETE FROM fm_event_exception WHERE event_id ='{$data['event_id']}' AND exception_time = {$exception_time}";
+					$this->_db->query($sql,__LINE__,__FILE__);
+				}
+			}
+		}
+	}


Property changes on: people/sigurdne/modules/property/trunk/inc/class.soevent.inc.php
___________________________________________________________________
Added: svn:keywords
   + Id Revision

Modified: people/sigurdne/modules/property/trunk/inc/class.sogab.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sogab.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sogab.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -37,17 +37,18 @@
 		var $gab_insert_level;
 		var $payment_date;
 
-		function property_sogab($gab_insert_level)
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->db2          = clone($this->db);
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 
-			$this->gab_insert_level = $gab_insert_level;
+			$this->config		= CreateObject('phpgwapi.config','property');
+			$this->config->read();
+			$this->gab_insert_level = isset($this->config->config_data['gab_insert_level']) && $this->config->config_data['gab_insert_level'] ? $this->config->config_data['gab_insert_level'] : 3;
 		}
 
 		function read($data)
@@ -59,7 +60,7 @@
 				$sort			= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
 				$order			= isset($data['order']) ? $data['order'] : '';
 				$cat_id 		= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id'] : 0;
-				$loc1 			= isset($data['loc1']) ? $data['loc1'] : '';
+				$location_code 	= isset($data['location_code']) ? $data['location_code'] : '';
 				$gaards_nr		= isset($data['gaards_nr'])? (int)$data['gaards_nr'] : '';
 				$bruksnr		= isset($data['bruksnr']) ? (int)$data['bruksnr'] : '';
 				$feste_nr		= isset($data['feste_nr']) ? (int)$data['feste_nr'] : '';
@@ -92,9 +93,9 @@
 				$filtermethod .= " $where fm_gab_location.address $this->like '%$address%' ";
 				$where = 'AND';
 			}
-			if ($loc1)
+			if ($location_code)
 			{
-				$filtermethod .= " $where fm_gab_location.loc1='$loc1' ";
+				$filtermethod .= " $where fm_gab_location.location_code $this->like '$location_code%' ";
 				$where = 'AND';
 			}
 
@@ -140,11 +141,11 @@
 
 			if($check_payments)
 			{
-				$sql = "SELECT gab_id,count(gab_id) as hits, loc" . $j . "_name as address ,fm_gab_location.loc1 as location_code, fm_gab_location.owner as owner FROM fm_gab_location $joinmethod $filtermethod GROUP BY gab_id,fm_gab_location.loc1,loc" . $j . "_name,owner ";
+				$sql = "SELECT gab_id,count(gab_id) as hits, address ,fm_gab_location.loc1 as location_code, fm_gab_location.owner as owner FROM fm_gab_location $joinmethod $filtermethod GROUP BY gab_id,fm_gab_location.loc1,address,owner ";
 			}
 			else
 			{
-				$sql = "SELECT gab_id,count(gab_id) as hits, loc" . $j . "_name as address ,fm_gab_location.location_code, fm_gab_location.owner as owner FROM fm_gab_location $joinmethod $filtermethod GROUP BY gab_id,fm_gab_location.location_code,loc" . $j . "_name,owner ";
+				$sql = "SELECT gab_id,count(gab_id) as hits, address ,fm_gab_location.location_code, fm_gab_location.owner as owner FROM fm_gab_location $joinmethod $filtermethod GROUP BY gab_id,fm_gab_location.location_code,address,owner ";
 			}
 
 			$this->db->query($sql,__LINE__,__FILE__);

Modified: people/sigurdne/modules/property/trunk/inc/class.soinvestment.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soinvestment.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soinvestment.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -38,16 +38,15 @@
 		{
 		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function get_type_list()
 		{
 			$this->db->query("SELECT entity_type FROM fm_investment GROUP BY entity_type ");
+			$type_list = array();
 			while ($this->db->next_record())
 			{
 				$type_list[] = Array(
@@ -142,8 +141,8 @@
 			}
 			if($sql)
 			{
-				$this->db2->query($sql,__LINE__,__FILE__);
-				$this->total_records = $this->db2->num_rows();
+				$this->db->query($sql,__LINE__,__FILE__);
+				$this->total_records = $this->db->num_rows();
 
 				if(!$allrows)
 				{
@@ -156,6 +155,7 @@
 			}
 
 
+			$investment = array();
 			$i=0;
 			while ($this->db->next_record())
 			{
@@ -192,6 +192,7 @@
 		{
 //_debug_array($values);
 
+			$receipt = array();
 			while (is_array($values['location']) && list($input_name,$value) = each($values['location']))
 			{
 				if($value)
@@ -263,7 +264,9 @@
 
 		function update_investment($values)
 		{
-			if (isSet($values) AND is_array($values))
+			$receipt = array();
+
+			if ($values)
 			{
 				$this->db->transaction_begin();
 				foreach($values as $entry)
@@ -286,13 +289,16 @@
 						1
 						);
 
-					$insert	= $this->bocommon->validate_db_insert($insert);
+					$insert	= $this->db->validate_insert($insert);
 
 
 					$this->db->query("insert into fm_investment_value (entity_id, invest_id, index_count, this_index, value,initial_value, index_date,current_index) "
 					. " values ($insert)");
+
+					$receipt['message'][]=array('msg'=>lang('investment %1 is updated at entity %2', $entry['invest_id'], $entry['entity_id']));
 				}
 				$this->db->transaction_commit();
+				return $receipt;
 			}
 		}
 
@@ -307,8 +313,8 @@
 			$sql = "SELECT index_count, this_index,current_index,value, initial_value, index_date  "
 			. " FROM fm_investment_value Where entity_id= '$entity_id' and invest_id= '$investment_id' order by index_count";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -319,6 +325,7 @@
 				$this->db->query($sql,__LINE__,__FILE__);
 			}
 
+			$investment = array();
 			$i=0;
 			while ($this->db->next_record())
 			{
@@ -341,6 +348,7 @@
 		{
 			$this->db->query("SELECT writeoff_year FROM fm_investment GROUP BY writeoff_year ",__LINE__,__FILE__);
 
+			$period_list = array();
 			while ($this->db->next_record())
 			{
 				$period_list[] = Array(

Modified: people/sigurdne/modules/property/trunk/inc/class.soinvoice.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soinvoice.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soinvoice.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,33 +35,39 @@
 	class property_soinvoice
 	{
 		var $total_records = 0;
+		var $role = array();
 
 		function property_soinvoice()
 		{
-			$this->bocommon		= CreateObject('property.bocommon');
 			$this->account_id 	= $GLOBALS['phpgw_info']['user']['account_id'];
-
 			$this->acl 			= & $GLOBALS['phpgw']->acl;
-
-			$this->join			= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like			= $this->bocommon->like;
-			$this->db          	= $this->bocommon->new_db();
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read_invoice($data)
 		{
+
+			$valid_order = array
+			(
+				'bilagsnr'		=> true,
+				'spvend_code'	=> true,
+				'fakturadato'	=> true
+			);
+
 			if(is_array($data))
 			{
 				$start			= isset($data['start']) && $data['start'] ? $data['start'] : 0;
 				$query 			= isset($data['query'])?$data['query']:'';
 				$sort 			= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
-				$order 			= isset($data['order'])?$data['order']:'';
+				$order 			= isset($data['order']) && $valid_order[$data['order']] ? $data['order']:'';
 				$cat_id 		= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id']:0;
 				$user_lid 		= isset($data['user_lid']) && $data['user_lid']?$data['user_lid']:'none';
 				$paid 			= isset($data['paid'])?$data['paid']:'';
-				$start_date 	= isset($data['start_date'])?$data['start_date']:'';
-				$end_date 		= isset($data['end_date'])?$data['end_date']:'';
+				$start_date 	= isset($data['start_date']) && $data['start_date'] ? date($this->db->datetime_format(), $data['start_date']) : '';
+				$end_date 		= isset($data['end_date']) && $data['end_date'] ? date($this->db->datetime_format(), $data['end_date']) : '';
 				$vendor_id 		= isset($data['vendor_id'])?$data['vendor_id']:'';
 				$loc1 			= isset($data['loc1'])?$data['loc1']:'';
 				$workorder_id 	= isset($data['workorder_id'])?$data['workorder_id']:'';
@@ -75,6 +81,13 @@
 			$querymethod	= '';
 //_debug_array($data);
 
+			$this->db->query("SELECT * FROM fm_ecoart");
+			$art_list = array();
+			while ($this->db->next_record())
+			{
+				$art_list[$this->db->f('id')] = $this->db->f('descr',true);
+			}
+
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
@@ -103,7 +116,7 @@
 				$where= 'AND';
 			}
 
-			if ($district_id > 0)
+			if ($district_id > 0 && $paid)
 			{
 				$filtermethod .= " $where  district_id='$district_id' ";
 				$join_tables = " $this->join fm_location1 ON fm_ecobilagoverf.loc1 = fm_location1.loc1"
@@ -130,7 +143,7 @@
 
 			if ($voucher_id)
 			{
-				$filtermethod .= " $where  bilagsnr $this->like '%$voucher_id%' ";
+				$filtermethod .= " $where  bilagsnr = " . (int)$voucher_id;
 				$where= 'AND';
 			}
 
@@ -146,48 +159,9 @@
 					$join_tables .= " $this->join fm_b_account ON fm_ecobilagoverf.spbudact_code = fm_b_account.id";
 				}
 
-				if (!$workorder_id && !$voucher_id)
-				{
-					$dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-					$dateformat = str_replace(".","",$dateformat);
-					$dateformat = str_replace("-","",$dateformat);
-					$dateformat = str_replace("/","",$dateformat);
-					$y=strpos($dateformat,'y');
-					$d=strpos($dateformat,'d');
-					$m=strpos($dateformat,'m');
-
-	 				$dateparts = explode('/', $start_date);
-	 				$sday = $dateparts[$d];
-	 				$smonth = $dateparts[$m];
-	 				$syear = $dateparts[$y];
-
-		 			$dateparts = explode('/', $end_date);
-	 				$eday = $dateparts[$d];
-	 				$emonth = $dateparts[$m];
-	 				$eyear = $dateparts[$y];
-
-					$start_date = date($this->bocommon->dateformat,mktime(2,0,0,$smonth,$sday,$syear));
-					if ($syear == $eyear)
+				if (!$workorder_id && !$voucher_id  && $start_date)
 					{
-						$end_date = date($this->bocommon->dateformat,mktime(2,0,0,12,31,$eyear));
-						$filtermethod .= " $where (fakturadato >'$start_date' AND fakturadato < '$end_date'"
-								. " AND periode >" . ($smonth -1) . " AND periode <" . ($emonth+1) . ')';
-					}
-
-					$end_date = date($this->bocommon->dateformat,mktime(2,0,0,$emonth,$eday,$eyear));
-
-
-		/*			$filtermethod .= " $where (fakturadato >'$start_date' AND fakturadato < '$end_date'";
-
-					if($smonth < 3)
-					{
-						$filtermethod .= " AND periode = 1)";
-					}
-					else
-					{
-						$filtermethod .= ")";
-					}
-		*/
+					$filtermethod .= " $where (fakturadato >'$start_date' AND fakturadato < '$end_date')";
 				}
 			}
 			else
@@ -201,10 +175,9 @@
 				$querymethod = " $where ( spvend_code = {$query} OR bilagsnr = {$query})";
 			}
 
-			$sql = "SELECT bilagsnr, count(bilagsnr) as invoice_count, sum(belop) as belop,spvend_code,fakturadato FROM  $table $join_tables $filtermethod $querymethod group by bilagsnr,spvend_code,fakturadato ";
+			$sql = "SELECT bilagsnr, count(bilagsnr) as invoice_count, sum(belop) as belop,spvend_code,fakturadato FROM  $table $join_tables $filtermethod $querymethod GROUP BY bilagsnr,spvend_code,fakturadato ";
 			$sql2 = "SELECT DISTINCT bilagsnr FROM  $table $join_tables $filtermethod $querymethod";
 
-//echo $sql;
 			$this->db->query($sql2,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
 
@@ -217,6 +190,7 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
+			$temp = array();
 			while ($this->db->next_record())
 			{
 				$temp[] = array
@@ -228,13 +202,13 @@
 			}
 
 			$invoice = array();
-			if (isset($temp) && $temp)
+			if ($temp)
 			{
 				$role= $this->check_role();
 				$i = 0;
 				foreach($temp as $invoice_temp)
 				{
-					$voucher_id=$invoice_temp['voucher_id'];
+					$voucher_id = $invoice_temp['voucher_id'];
 
 					$sql = "SELECT spvend_code,oppsynsmannid,saksbehandlerid,budsjettansvarligid,"
 					. " utbetalingid,oppsynsigndato,saksigndato,budsjettsigndato,utbetalingsigndato,fakturadato,org_name,"
@@ -253,8 +227,6 @@
 
 					if($this->db->f('oppsynsmannid') && $this->db->f('oppsynsigndato'))
 					{
-//						$timestamp_jan_date			= mktime(0,0,0,date(m,strtotime($this->db->f('oppsynsigndato'))),date(d,strtotime($this->db->f('oppsynsigndato'))),date(y,strtotime($this->db->f('oppsynsigndato'))));
-//						$invoice[$i]['jan_date']	= $GLOBALS['phpgw']->common->show_date($timestamp_jan_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
 						$invoice[$i]['jan_date']=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($this->db->f('oppsynsigndato')));
 					}
 					else
@@ -263,8 +235,6 @@
 					}
 					if($this->db->f('saksbehandlerid') && $this->db->f('saksigndato'))
 					{
-//						$timestamp_super_date		= mktime(0,0,0,date(m,strtotime($this->db->f('saksigndato'))),date(d,strtotime($this->db->f('saksigndato'))),date(y,strtotime($this->db->f('saksigndato'))));
-//						$invoice[$i]['super_date']	= $GLOBALS['phpgw']->common->show_date($timestamp_super_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
 						$invoice[$i]['super_date']=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($this->db->f('saksigndato')));
 					}
 					else
@@ -274,8 +244,6 @@
 
 					if($this->db->f('budsjettansvarligid') && $this->db->f('budsjettsigndato'))
 					{
-//							$timestamp_budget_date		= mktime(0,0,0,date(m,strtotime($this->db->f('budsjettsigndato'))),date(d,strtotime($this->db->f('budsjettsigndato'))),date(y,strtotime($this->db->f('budsjettsigndato'))));
-//							$invoice[$i]['budget_date']	= $GLOBALS['phpgw']->common->show_date($timestamp_budget_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
 							$invoice[$i]['budget_date']=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($this->db->f('budsjettsigndato')));
 					}
 					else
@@ -285,8 +253,6 @@
 
 					if($this->db->f('utbetalingid') && $this->db->f('utbetalingsigndato'))
 					{
-//						$timestamp_transfer_date= mktime(0,0,0,date(m,strtotime($this->db->f('utbetalingsigndato'))),date(d,strtotime($this->db->f('utbetalingsigndato'))),date(y,strtotime($this->db->f('utbetalingsigndato'))));
-//						$invoice[$i]['transfer_date']			= $GLOBALS['phpgw']->common->show_date($timestamp_transfer_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
 						$invoice[$i]['transfer_date']=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($this->db->f('utbetalingsigndato')));
 					}
 					else
@@ -312,7 +278,7 @@
 					$invoice[$i]['voucher_date'] 			= $GLOBALS['phpgw']->common->show_date($timestamp_voucher_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
 					$invoice[$i]['payment_date'] 			= $GLOBALS['phpgw']->common->show_date($timestamp_payment_date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
 					$invoice[$i]['period']					= $this->db->f('periode');
-					$invoice[$i]['type']					= $this->db->f('artid');
+					$invoice[$i]['type']					= $art_list[$this->db->f('artid')];
 					$invoice[$i]['kidnr']					= $this->db->f('kidnr');
 					$invoice[$i]['kreditnota']				= $this->db->f('kreditnota');
 					$invoice[$i]['amount']					= $invoice_temp['amount'];
@@ -373,7 +339,7 @@
 			}
 			else
 			{
-				$ordermethod = ' order by bilagsnr DESC';
+				$ordermethod = ' order by id DESC';
 			}
 
 			if ($voucher_id)
@@ -381,42 +347,44 @@
 				$filtermethod = " WHERE ( bilagsnr= '$voucher_id')";
 			}
 
-			$sql = "SELECT $table.*,fm_workorder.status,fm_workorder.charge_tenant,org_name,fm_workorder.claim_issued FROM $table "
-			. " $this->left_join fm_workorder on fm_workorder.id = $table.pmwrkord_code  "
+			$sql = "SELECT $table.*,fm_workorder.status,fm_workorder.charge_tenant,org_name,fm_workorder.claim_issued, fm_workorder.paid_percent, project_group FROM $table"
+			. " $this->left_join fm_workorder ON fm_workorder.id = $table.pmwrkord_code"
+			. " $this->left_join fm_project ON fm_workorder.project_id = fm_project.id"
 			. " $this->join fm_vendor ON $table.spvend_code = fm_vendor.id $filtermethod";
 
-			$this->db->query($sql,__LINE__,__FILE__);
+			$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
-			$this->db->query($sql . $ordermethod,$start,__LINE__,__FILE__);
 
 			$i = 0;
 
+			$invoice = array();
 			while ($this->db->next_record())
 			{
-				$invoice[$i]['counter']					= $i;
-				$invoice[$i]['claim_issued']			= $this->db->f('claim_issued');
-				$invoice[$i]['project_id']				= $this->db->f('project_id');
-				$invoice[$i]['workorder_id']			= $this->db->f('pmwrkord_code');
-				$invoice[$i]['status']					= $this->db->f('status');
-				if ($this->db->f('status')=='closed')
-				{
-					$invoice[$i]['closed']				= true;
-				}
-				$invoice[$i]['voucher_id']				= $voucher_id;
-				$invoice[$i]['id']						= $this->db->f('id');
-				$invoice[$i]['invoice_id']				= $this->db->f('fakturanr');
-				$invoice[$i]['budget_account']			= $this->db->f('spbudact_code');
-				$invoice[$i]['dima']					= $this->db->f('dima');
-				$invoice[$i]['dimb']					= $this->db->f('dimb');
-				$invoice[$i]['dimd']					= $this->db->f('dimd');
-				if ($this->db->f('merknad'))
-				{
-					$invoice[$i]['remark']				= true;
-				}
-				$invoice[$i]['tax_code']				= $this->db->f('mvakode');
-				$invoice[$i]['amount']					= $this->db->f('belop');
-				$invoice[$i]['charge_tenant']			= $this->db->f('charge_tenant');
-				$invoice[$i]['vendor']					= $this->db->f('org_name');
+				$invoice[] = array
+				(
+					'counter'				=> $i,
+					'claim_issued'			=> $this->db->f('claim_issued'),
+					'project_id'			=> $this->db->f('project_id'),
+					'workorder_id'			=> $this->db->f('pmwrkord_code'),
+					'status'				=> $this->db->f('status'),
+					'closed'				=> $this->db->f('status') == 'closed',
+					'voucher_id'			=> $voucher_id,
+					'id'					=> $this->db->f('id'),
+					'invoice_id'			=> $this->db->f('fakturanr'),
+					'budget_account'		=> $this->db->f('spbudact_code'),
+					'dima'					=> $this->db->f('dima'),
+					'dimb'					=> $this->db->f('dimb'),
+					'dimd'					=> $this->db->f('dimd'),
+					'remark' 				=> !!$this->db->f('merknad'),
+					'tax_code'				=> $this->db->f('mvakode'),
+					'amount'				=> $this->db->f('belop'),
+					'charge_tenant'			=> $this->db->f('charge_tenant'),
+					'vendor'				=> $this->db->f('org_name'),
+					'paid_percent'			=> $this->db->f('paid_percent'),
+					'project_group'			=> $this->db->f('project_group'),
+					'external_ref'			=> $this->db->f('external_ref')
+				);
+
 				$i++;
 			}
 
@@ -434,37 +402,17 @@
 				$sort 			= isset($data['sort'])?$data['sort']:'DESC';
 				$order 			= isset($data['order'])?$data['order']:'';
 				$cat_id 		= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id']:0;
-				$start_date 	= isset($data['start_date'])?$data['start_date']:'';
-				$end_date 		= isset($data['end_date'])?$data['end_date']:'';
+				$start_date 	= isset($data['start_date']) && $data['start_date'] ? date($this->db->datetime_format(), $data['start_date']) : '';
+				$end_date 		= isset($data['end_date']) && $data['end_date'] ? date($this->db->datetime_format(), $data['end_date']) : '';
 				$vendor_id 		= isset($data['vendor_id'])?$data['vendor_id']:'';
 				$loc1 			= isset($data['loc1'])?$data['loc1']:'';
 				$district_id 	= isset($data['district_id'])?$data['district_id']:'';
 				$workorder_id 	= isset($data['workorder_id']) && $data['workorder_id'] ? $data['workorder_id']:0;
 				$b_account_class = isset($data['b_account_class'])?$data['b_account_class']:'';
+				$b_account		= isset($data['b_account']) ? $data['b_account'] : '';
 			}
 //_debug_array($data);
 
-			$dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-			$dateformat = str_replace(".","",$dateformat);
-			$dateformat = str_replace("-","",$dateformat);
-			$dateformat = str_replace("/","",$dateformat);
-			$y=strpos($dateformat,'y');
-			$d=strpos($dateformat,'d');
-			$m=strpos($dateformat,'m');
- 			$dateparts = explode('/', $start_date);
- 			$sday = $dateparts[$d];
- 			$smonth = $dateparts[$m];
- 			$syear = $dateparts[$y];
-
- 			$dateparts = explode('/', $end_date);
- 			$eday = $dateparts[$d];
- 			$emonth = $dateparts[$m];
- 			$eyear = $dateparts[$y];
-
-			$start_date = date($this->bocommon->dateformat,mktime(2,0,0,$smonth,$sday,$syear));
-			$end_date = date($this->bocommon->dateformat,mktime(2,0,0,$emonth,$eday,$eyear));
-
-
 			$where = 'AND';
 
 			if($b_account_class)
@@ -478,6 +426,16 @@
 				$group_account_class=', spbudact_code,fm_b_account.category';
 			}
 
+			if ($b_account)
+			{
+				$filtermethod .= " {$where} fm_b_account.id = '{$b_account}'";
+				$where= 'AND';
+				$select_account_class=',fm_b_account.id as b_account_class';
+				$group_account_class=', spbudact_code,fm_b_account.id';
+
+			}
+
+
 			if ($vendor_id)
 			{
 				$filtermethod .= " $where (spvend_code = $vendor_id)";
@@ -510,49 +468,31 @@
 				$where= 'AND';
 			}
 
-
-			$year = date("Y",strtotime($start_date));
-			$month = date("m",strtotime($start_date));
-			if($month < 3)
-			{
-				$start_date = date($this->bocommon->dateformat,mktime(2,0,0,3,1,$year));
-			}
-
-			$start_date2 = date($this->bocommon->dateformat,mktime(2,0,0,1,1,$year));
-
 			$sql = "SELECT district_id,periode,sum(godkjentbelop) as consume $select_account_class "
 				. " FROM  fm_ecobilagoverf $this->join fm_location1 ON (fm_ecobilagoverf.loc1 = fm_location1.loc1) "
 				. " $this->join fm_part_of_town ON (fm_location1.part_of_town_id = fm_part_of_town.part_of_town_id) "
 				. " $this->join fm_b_account ON (fm_ecobilagoverf.spbudact_code = fm_b_account.id) "
 		        	. " WHERE (fakturadato >'$start_date' AND fakturadato < '$end_date' $filtermethod )"
-		        	. " OR (fakturadato >'$start_date2' AND fakturadato < '$end_date'  AND periode < 3  $filtermethod) "
 		        	. " GROUP BY district_id,periode $group_account_class"
 		        	. " ORDER BY periode";
 //echo $sql;
 
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
-			$this->db->query($sql . $ordermethod,$start,__LINE__,__FILE__);
 
-			$i = 0;
+			$consume = array();
 
 			while ($this->db->next_record())
 			{
-				$consume[$i]['consume']				= round($this->db->f('consume'));
-				$consume[$i]['period']					= $this->db->f('periode');
-				$consume[$i]['district_id']				= $this->db->f('district_id');
-				if(!$b_account_class)
-				{
-					$consume[$i]['account_class']			= $this->db->f('b_account_class');
+				$consume[] = array
+				(
+					'consume'		=> round($this->db->f('consume')),
+					'period'		=> $this->db->f('periode'),
+					'district_id'	=> $this->db->f('district_id'),
+					'account_class'	=> $b_account_class ? $b_account_class : $this->db->f('b_account_class')
+				);	
 				}
-				else
-				{
-					$consume[$i]['account_class']			= $b_account_class;
-				}
 
-				$i++;
-			}
-//_debug_array($consume);
 			return $consume;
 		}
 
@@ -595,7 +535,7 @@
 
 		function update_invoice_sub($values)
 		{
-
+			$receipt = array();
 			$GLOBALS['phpgw']->db->transaction_begin();
 
 			while($entry=each($values['counter']))
@@ -607,12 +547,11 @@
 
 //_debug_array($entry);
 
-
 				if ($values['budget_account'][$n])
 				{
 					$budget_account=$values['budget_account'][$n];
 
-					$GLOBALS['phpgw']->db->query("select count(*) from fm_b_account  where id =$budget_account");
+					$GLOBALS['phpgw']->db->query("select count(*) from fm_b_account  where id ='{$budget_account}'");
 					$GLOBALS['phpgw']->db->next_record();
 					if ($GLOBALS['phpgw']->db->f(0) == 0)
 					{
@@ -690,6 +629,11 @@
 						$update_status[$workorder_id]='R';
 					}
 
+					if(isset($values['paid_percent'][$n]) && $values['paid_percent'][$n])
+					{
+						$update_paid_percent[$workorder_id] = $values['paid_percent'][$n];
+					}
+
 					$GLOBALS['phpgw']->db->query("UPDATE fm_ecobilag set $dima_field ,$kostra_field,$dimd_field, mvakode = '$tax_code',spbudact_code = '$budget_account',dimb = $dimb where id='$id'");
 
 					$receipt['message'][] = array('msg'=>lang('Voucher is updated '));
@@ -705,12 +649,40 @@
 
 				while (list($id,$entry) = each($update_status))
 				{
+					$this->db->query("SELECT type FROM fm_orders WHERE id={$id}",__LINE__,__FILE__);
+					$this->db->next_record();
+					switch ( $this->db->f('type') )
+					{
+						case 'workorder':
 					$historylog_workorder->add($entry,$id,$status_code[$entry]);
 					$GLOBALS['phpgw']->db->query("UPDATE fm_workorder set status=" . "'$status_code[$entry]'" . "where id=$id");
 					$receipt['message'][] = array('msg'=>lang('Workorder %1 is %2',$id, $status_code[$entry]));
 				}
 			}
+			}
 
+			if (isset($update_paid_percent) AND is_array($update_paid_percent))
+			{
+				$workorder = CreateObject('property.soworkorder');
+				foreach ($update_paid_percent as $workorder_id => $paid_percent)
+				{
+					$paid_percent = (int) $paid_percent;
+					$GLOBALS['phpgw']->db->query("UPDATE fm_workorder set paid_percent={$paid_percent} WHERE id= $workorder_id");				
+	
+					$this->db->query("SELECT type FROM fm_orders WHERE id={$workorder_id}",__LINE__,__FILE__);
+					$this->db->next_record();
+					switch ( $this->db->f('type') )
+					{
+						case 'workorder':
+							$this->db->query("SELECT project_id FROM fm_workorder WHERE id={$workorder_id}",__LINE__,__FILE__);
+							$this->db->next_record();
+							$project_id = $this->db->f('project_id');
+							$workorder->update_planned_cost($project_id);
+							break;
+					}
+				}
+			}
+
 			$GLOBALS['phpgw']->db->transaction_commit();
 
 			return $receipt;
@@ -768,6 +740,7 @@
 
 		function update_period($voucher_id='',$period='')
 		{
+			$receipt = array();
 			$this->db->transaction_begin();
 
 			$this->db->query("UPDATE fm_ecobilag set periode='$period' where bilagsnr='$voucher_id'");
@@ -812,6 +785,7 @@
 		function tax_code_list($selected='')
 		{
 			$this->db->query("SELECT * FROM fm_ecomva order by id asc ");
+			$tax_code_list = array();
 			while ($this->db->next_record())
 			{
 				$tax_code_list[] = Array(
@@ -826,6 +800,7 @@
 		function get_lisfm_ecoart()
 		{
 			$this->db->query("SELECT * FROM fm_ecoart order by id asc ");
+			$art_list = array();
 			while ($this->db->next_record())
 			{
 				$art_list[] = Array(
@@ -842,20 +817,22 @@
 		function get_type_list()
 		{
 			$this->db->query("SELECT * FROM fm_ecobilag_category order by id asc ");
+			$category = array();
 			while ($this->db->next_record())
 			{
-				$art_list[] = Array(
+				$category[] = Array(
 					'id'        => $this->db->f('id'),
 					'name'       => $this->db->f('descr')
 				);
 			}
-			return $art_list;
+			return $category;
 		}
 
 	//----------
 		function select_dimb_list()
 		{
 			$this->db->query("SELECT * FROM fm_ecodimb order by id asc ");
+			$dimb_list = array();
 			while ($this->db->next_record())
 			{
 				$dimb_list[] = Array(
@@ -870,6 +847,7 @@
 		function select_dimd_list()
 		{
 			$this->db->query("SELECT * FROM fm_ecodimd order by id asc ");
+			$dimd_list = array();
 			while ($this->db->next_record())
 			{
 				$dimd_list[] = Array(
@@ -884,6 +862,7 @@
 		function select_tax_code_list()
 		{
 			$this->db->query("SELECT * FROM fm_ecomva order by id asc ");
+			$tax_code_list = array();
 			while ($this->db->next_record())
 			{
 				$tax_code_list[] = Array(
@@ -899,6 +878,7 @@
 			$sql = "SELECT id from fm_b_account_category order by id";
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$class = array();
 			while ($this->db->next_record())
 			{
 				$class[] = Array(
@@ -919,6 +899,7 @@
 			$sql = "SELECT * from fm_ecobilag WHERE bilagsnr ='$bilagsnr'";
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$values = array();
 			while ($this->db->next_record())
 			{
 				$values[] = Array(
@@ -1034,63 +1015,63 @@
 							$sign_field = 'oppsynsmannid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'oppsynsigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_janitor' && $values['sign_orig'][$n]=='sign_supervisor'):
 							$blank_date = 'saksigndato= NULL';
 							$sign_field = 'oppsynsmannid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'oppsynsigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_janitor' && $values['sign_orig'][$n]=='sign_budget_responsible'):
 							$blank_date = 'budsjettsigndato= NULL';
 							$sign_field = 'oppsynsmannid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'oppsynsigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_supervisor' && !$values['sign_orig'][$n]):
 							$blank_date = '';
 							$sign_field = 'saksbehandlerid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'saksigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_supervisor' && $values['sign_orig'][$n]=='sign_janitor'):
 							$blank_date = 'oppsynsigndato= NULL';
 							$sign_field = 'saksbehandlerid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'saksigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_supervisor' && $values['sign_orig'][$n]=='sign_budget_responsible'):
 							$blank_date = 'budsjettsigndato= NULL';
 							$sign_field = 'saksbehandlerid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'saksigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_budget_responsible' && $values['sign_orig'][$n]=='sign_janitor'):
 							$blank_date = 'oppsynsigndato= NULL';
 							$sign_field = 'budsjettansvarligid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'budsjettsigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_budget_responsible' && $values['sign_orig'][$n]=='sign_supervisor'):
 							$blank_date = 'saksigndato= NULL';
 							$sign_field = 'budsjettansvarligid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'budsjettsigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						elseif ($values['sign'][$n]=='sign_budget_responsible' && !$values['sign_orig'][$n]):
 							$blank_date = '';
 							$sign_field = 'budsjettansvarligid=';
 							$sign_id = "'$user_lid'";
 							$sign_date_field = 'budsjettsigndato=';
-							$sign_date="'" . date($this->bocommon->datetimeformat) . "'";
+							$sign_date="'" . date($this->db->datetime_format()) . "'";
 							$kommma=",";
 						endif;
 
@@ -1109,7 +1090,7 @@
 
 						if (!($values['num_days_orig'][$n]==$values['num_days'][$n]))
 						{
-							$payment_date = date($this->bocommon->dateformat,$values['timestamp_voucher_date'][$n]+(24*3600*$values['num_days'][$n]));
+							$payment_date = date($this->db->date_format(),$values['timestamp_voucher_date'][$n]+(24*3600*$values['num_days'][$n]));
 							$GLOBALS['phpgw']->db->query("UPDATE fm_ecobilag set forfallsdato= '$payment_date' where bilagsnr='$voucher_id'");
 						}
 
@@ -1121,7 +1102,7 @@
 							if ($this->check_for_transfer($voucher_id))
 							{
 								$transfer_id="'$user_lid',";
-								$transfer_date="'" . date($this->bocommon->datetimeformat) . "'";
+								$transfer_date="'" . date($this->db->datetime_format()) . "'";
 							}
 							else
 							{

Modified: people/sigurdne/modules/property/trunk/inc/class.solocation.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.solocation.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.solocation.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,41 +35,70 @@
 	class property_solocation
 	{
 
-		function property_solocation()
+		var $bocommon;
+		var $total_records;
+
+		function __construct($bocommon = '')
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
-
 			$this->account			= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->soadmin_location	= CreateObject('property.soadmin_location');
+			if(!$bocommon || !is_object($bocommon))
+			{
 			$this->bocommon			= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->socommon			= CreateObject('property.socommon');
+			}
+			else
+			{
+				$this->bocommon = $bocommon;
+			}
+			$this->custom 		= createObject('property.custom_fields');
 
-			$this->join			= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->socommon		= & $this->bocommon->socommon;
+
+			$this->join			= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read_entity_to_link($location_code)
 		{
+			$entity = array();
+
 			$sql = "SELECT * FROM fm_entity_category where loc_link=1";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$category = array();
 			while ($this->db->next_record())
 			{
-				$sql = "SELECT count(*) as hits FROM fm_entity_" . $this->db->f('entity_id') . "_" . $this->db->f('id') . " WHERE location_code $this->like '$location_code%'";
+				$category[] = array
+				(
+					'entity_id'	=> $this->db->f('entity_id'),
+					'cat_id'	=> $this->db->f('id'),
+					'name'		=> $this->db->f('name'),
+					'descr'		=> $this->db->f('descr')
+				);
+			}
+
+			foreach($category as $entry)
+			{
+				$sql = "SELECT count(*) as hits FROM fm_entity_{$entry['entity_id']}_{$entry['cat_id']} WHERE location_code $this->like '$location_code%'";
 				$this->db->query($sql,__LINE__,__FILE__);
 				$this->db->next_record();
 				if($this->db->f('hits'))
 				{
-					$entity[] = array
+					$entity['related'][] = array
 					(
-						'entity_id'	=> $this->db->f('entity_id'),
-						'cat_id'	=> $this->db->f('id'),
-						'name'		=> $this->db->f('name') . ' [' . $this->db->f('hits') . ']',
-						'descr'		=> $this->db->f('descr')
+						'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array
+														(
+															'menuaction'	=> 'property.uientity.index',
+															'entity_id'		=> $entry['entity_id'],
+															'cat_id'		=> $entry['cat_id'],
+															'location_code'	=> $location_code
+														)
+													),
+						'name'			=> $entry['name'] . ' [' . $this->db->f('hits') . ']',
+						'descr'			=> $entry['descr']
 					);
 				}
 			}
@@ -79,44 +108,58 @@
 			$this->db->next_record();
 			if($this->db->f('hits'))
 			{
-				$entity[] = array
+				$hits = $this->db->f('hits');
+				$entity['related'][] = array
 				(
 					'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uitts.index', 'query'=> $location_code)),
-					'name'		=> lang('Helpdesk') . ' [' . $this->db->f('hits') . ']',
+					'name'		=> lang('Helpdesk') . " [{$hits}]",
 					'descr'		=> lang('Helpdesk')
 				);
 			}
 
-			$sql = "SELECT count(*) as hits FROM fm_document WHERE location_code $this->like '$location_code%'";
+			$sql = "SELECT count(*) as hits FROM fm_request WHERE location_code $this->like '$location_code%'";
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->db->next_record();
 			if($this->db->f('hits'))
 			{
-				$entity[] = array
+				$hits = $this->db->f('hits');
+				$entity['related'][] = array
 				(
-					'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uidocument.index','query'=> $location_code)),
-					'name'		=> lang('Documentation') . ' [' . $this->db->f('hits') . ']',
-					'descr'		=> lang('Documentation')
+					'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uirequest.index','query'=> $location_code)),
+					'name'		=> lang('request') . " [{$hits}]",
+					'descr'		=> lang('request')
 				);
 			}
 
-			$sql = "SELECT count(*) as hits FROM fm_request WHERE location_code $this->like '$location_code%'";
+			$sql = "SELECT count(*) as hits FROM fm_project WHERE location_code $this->like '$location_code%'";
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->db->next_record();
 			if($this->db->f('hits'))
 			{
-				$entity[] = array
+				$hits = $this->db->f('hits');
+				$entity['related'][] = array
 				(
-					'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uirequest.index','query'=> $location_code)),
-					'name'		=> lang('request') . ' [' . $this->db->f('hits') . ']',
-					'descr'		=> lang('request')
+					'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uiproject.index','query'=> $location_code, 'criteria_id' => 4)), //criteria 4 is for location_code
+					'name'		=> lang('project') . " [{$hits}]",
+					'descr'		=> lang('project')
 				);
 			}
 
-			if (isset($entity))
+			$sql = "SELECT count(*) as hits FROM fm_gab_location WHERE location_code $this->like '$location_code%'";
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->db->next_record();
+			if($this->db->f('hits'))
 			{
-				return $entity;
+				$hits = $this->db->f('hits');
+				$entity['gab'][] = array
+				(
+					'entity_link'	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uigab.index','location_code'=> $location_code)),
+					'name'		=> lang('gabnr') . " [{$hits}]",
+					'descr'		=> lang('gab info')
+				);
 			}
+
+			return $entity;
 		}
 
 		function select_status_list($type_id)
@@ -206,6 +249,8 @@
 				$lookup				= isset($data['lookup']) ? $data['lookup'] : '';
 				$status				= isset($data['status']) ? $data['status'] : '';
 				$part_of_town_id	= isset($data['part_of_town_id']) ? $data['part_of_town_id'] : '';
+				$dry_run			= isset($data['dry_run']) ? $data['dry_run'] : '';
+				$location_code		= isset($data['location_code']) ? $data['location_code'] : '';
 			}
 
 			if (!$type_id)
@@ -215,10 +260,11 @@
 
 			$sql = $this->socommon->fm_cache('sql_'. $type_id . '_' . $lookup_tenant . '_' . $lookup);
 			$location_id = $GLOBALS['phpgw']->locations->get_id('property', ".location.{$type_id}");
-			$choice_table = 'phpgw_cust_choice';
+
+//			$choice_table = 'phpgw_cust_choice';
 			$attribute_table = 'phpgw_cust_attribute';
 			$attribute_filter = " custom = 1 AND location_id = {$location_id}";
-			$attribute_choice_filter = " location_id = {$location_id}";
+//			$attribute_choice_filter = " location_id = {$location_id}";
 
 			if(!$sql)
 			{
@@ -232,6 +278,7 @@
 				$uicols['statustext'][]		= 'dummy';
 				$uicols['exchange'][]		= false;
 				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
 
 				for ($i=0; $i<($type_id); $i++)
 				{
@@ -241,10 +288,13 @@
 					$uicols['statustext'][]		= $location_types[$i]['descr'];
 					$uicols['exchange'][]		= true;
 					$uicols['align'][] 			= 'center';
+					$uicols['datatype'][]		= 'link';
 					$cols 						.= ",fm_location" . ($type_id) .".loc" . $location_types[$i]['id'];
 					$cols_return[] 				= 'loc' . $location_types[$i]['id'];
 				}
 
+				$uicols['datatype'][$type_id] = 'I'; // correct the last one
+
 				$list_info = $location_types[($type_id-1)]['list_info'];
 
 				for ($i=1; $i<($type_id+1); $i++)
@@ -259,6 +309,7 @@
 						$uicols['statustext'][]		= $location_types[($i-1)]['name'] . ' ' . lang('name');
 						$uicols['exchange'][]		= true;
 						$uicols['align'][] 			= 'left';
+						$uicols['datatype'][]		= 'V';
 					}
 				}
 
@@ -296,33 +347,40 @@
 					$uicols['statustext'][]		= 'dummy';
 					$uicols['exchange'][]		= true;
 					$uicols['align'][] 			= '';
+					$uicols['datatype'][]		= '';
 
 					$cols.= ',fm_tenant.last_name';
 					$cols_return[] 				= 'last_name';
 					$uicols['input_type'][]		= 'text';
 					$uicols['name'][]			= 'last_name';
+					$uicols['datatype'][]		= 'V';
 					$uicols['descr'][]			= lang('last name');
 					$uicols['statustext'][]		= lang('last name');
 					$uicols['exchange'][]		= true;
 					$uicols['align'][] 			= 'left';
+					$uicols['datatype'][]		= 'V';
 
 					$cols.= ',fm_tenant.first_name';
 					$cols_return[] 				= 'first_name';
 					$uicols['input_type'][]		= 'text';
 					$uicols['name'][]			= 'first_name';
+					$uicols['datatype'][]		= 'V';
 					$uicols['descr'][]			= lang('first name');
 					$uicols['statustext'][]		= lang('first name');
 					$uicols['exchange'][]		= true;
 					$uicols['align'][] 			= 'left';
+					$uicols['datatype'][]		= 'V';
 
 					$cols.= ',fm_tenant.contact_phone';
 					$cols_return[] 				= 'contact_phone';
 					$uicols['input_type'][]		= 'text';
 					$uicols['name'][]			= 'contact_phone';
+					$uicols['datatype'][]		= 'V';
 					$uicols['descr'][]			= lang('contact phone');
 					$uicols['statustext'][]		= lang('contact phone');
 					$uicols['exchange'][]		= true;
 					$uicols['align'][] 			= 'left';
+					$uicols['datatype'][]		= 'V';
 
 					$sub_query_tenant=1;
 					$this->socommon->fm_cache('sub_query_tenant_'. $type_id  . '_' . $lookup_tenant . '_' . $lookup,$sub_query_tenant);
@@ -363,6 +421,7 @@
 								$uicols['statustext'][]		= lang('street name');
 								$uicols['exchange'][]		= true;
 								$uicols['align'][] 			= 'left';
+								$uicols['datatype'][]		= 'V';
 
 								$cols.= ',street_number';
 								$cols_return[] 				= 'street_number';
@@ -372,6 +431,7 @@
 								$uicols['statustext'][]		= lang('street number');
 								$uicols['exchange'][]		= true;
 								$uicols['align'][] 			= 'left';
+								$uicols['datatype'][]		= 'V';
 
 								$cols.= ',fm_location' . $config[$i]['location_type'] . '.' . $config[$i]['column_name'];
 								$cols_return[] 				= $config[$i]['column_name'];
@@ -381,6 +441,7 @@
 								$uicols['statustext'][]		= lang($config[$i]['input_text']);
 								$uicols['exchange'][]		= true;
 								$uicols['align'][] 			= '';
+								$uicols['datatype'][]		= '';
 							}
 						}
 						else
@@ -397,7 +458,7 @@
 					}
 				}
 
-				$this->db->query("SELECT * FROM $attribute_table WHERE list=1 AND $attribute_filter");
+				$this->db->query("SELECT * FROM $attribute_table WHERE (list=1 OR lookup_form=1) AND $attribute_filter");
 				while ($this->db->next_record())
 				{
 					$cols .= ",fm_location" . ($type_id) .'.' . $this->db->f('column_name');
@@ -430,17 +491,34 @@
 					$user_column_filter = " OR ($attribute_filter AND id IN (" . implode(',',$user_columns) .'))';
 				}
 
-				$this->db->query("SELECT * FROM $attribute_table WHERE list=1 AND $attribute_filter $user_column_filter ORDER BY attrib_sort ASC");
-
+				$this->db->query("SELECT DISTINCT * FROM $attribute_table WHERE (list=1 OR lookup_form=1) AND $attribute_filter $user_column_filter ORDER BY attrib_sort ASC");
 				$i	= count($uicols['name']);
 				while ($this->db->next_record())
 				{
-					$uicols['input_type'][]		= 'text';
+					$input_type = 'text';
+					if($this->db->f('lookup_form') == 1 && $this->db->f('list') != 1)
+					{
+						$input_type = 'hidden';
+						$exchange	= true;
+					}
+					else if($this->db->f('lookup_form') == 1)
+					{
+						$exchange	= true;
+					}
+					else
+					{
+						$input_type = 'text';
+						$exchange	= false;
+					}
+
+					$uicols['input_type'][]		= $input_type;
 					$uicols['name'][]			= $this->db->f('column_name');
 					$uicols['descr'][]			= $this->db->f('input_text');
 					$uicols['statustext'][]		= $this->db->f('statustext');
 					$uicols['datatype'][$i]		= $this->db->f('datatype');
-					$cols_return_extra[]= array(
+					$uicols['exchange'][]		= $exchange;
+					$uicols['cols_return_extra'][$i] = array
+					(
 						'name'	=> $this->db->f('column_name'),
 						'datatype'	=> $this->db->f('datatype'),
 						'attrib_id'	=> $this->db->f('id')
@@ -488,7 +566,7 @@
 			$where= 'WHERE';
 
 			$filtermethod = '';
-			$GLOBALS['phpgw']->config->read_repository();
+			$GLOBALS['phpgw']->config->read();
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
 			{
 				$access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
@@ -509,7 +587,9 @@
 
 			if ($filter > 0)
 			{
-				if($GLOBALS['phpgw_info']['user']['preferences']['property']['property_filter'] == 'owner')
+				//[email protected] 16/09/08 	validacion is added to avoid notice
+				if(isset($GLOBALS['phpgw_info']['user']['preferences']['property']['property_filter']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['property_filter'] == 'owner')
+				//if($GLOBALS['phpgw_info']['user']['preferences']['property']['property_filter'] == 'owner')
 				{
 					$filtermethod .= " $where fm_owner.id='$filter' ";
 				}
@@ -546,6 +626,12 @@
 				$where= 'AND';
 			}
 
+			if ($location_code)
+			{
+				$filtermethod .= "  {$where} fm_location{$type_id}.location_code $this->like '{$location_code}%'";
+				$where= 'AND';			
+			}
+
 			$querymethod = '';
 
 			if($query)
@@ -585,6 +671,10 @@
 			$sql .= "$filtermethod $querymethod";
 
 //echo $sql; die();
+			//[email protected] 23/07/08 avoid retrieve data in first time, only render definition for headers (var myColumnDefs)
+			$values = array();
+			if(!$dry_run)
+			{
 			$this->db->query('SELECT count(*)' . substr($sql,strripos($sql,'from')),__LINE__,__FILE__);
 			$this->db->next_record();
 			$this->total_records = $this->db->f(0);
@@ -599,98 +689,28 @@
 			}
 
 			$j=0;
-			$cols_return_count	= count($cols_return);
+
 			$location_count 	= $type_id-1;
-			$contacts		= CreateObject('phpgwapi.contacts');
-			$location_list		= array();
 
+				$cols_return = $uicols['name'];
+				$dataset = array();
 			while ($this->db->next_record())
 			{
-				for ($i=0;$i<$cols_return_count;$i++)
-				{
-					$location_list[$j][$cols_return[$i]] = stripslashes($this->db->f($cols_return[$i]));
-
-					$value = $this->db->f($cols_return[$i]);
-				}
-
-				if(isset($cols_return_extra) && is_array($cols_return_extra))
-				{
-					for ($i=0;$i<count($cols_return_extra);$i++)
-					{
-						$value = $this->db->f($cols_return_extra[$i]['name'], true);
-
-						if(($cols_return_extra[$i]['datatype']=='R' || $cols_return_extra[$i]['datatype']=='LB') && $value)
+					foreach($cols_return as $key => $field)
 						{
-					//		$sql="SELECT value FROM fm_location_choice where type_id=$type_id AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $value;
-							$sql="SELECT value FROM $choice_table WHERE $attribute_choice_filter AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $value;
-							$this->db2->query($sql);
-							$this->db2->next_record();
-							$location_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('value');
-						}
-						else if($cols_return_extra[$i]['datatype']=='AB' && $value)
-						{
-							$contact_data	= $contacts->read_single_entry($value,array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-							$location_list[$j][$cols_return_extra[$i]['name']]	= $contact_data[0]['n_family'] . ', ' . $contact_data[0]['n_given'];
-						}
-						else if($cols_return_extra[$i]['datatype']=='VENDOR' && $value)
-						{
-							$sql="SELECT org_name FROM fm_vendor where id=$value";
-							$this->db2->query($sql);
-							$this->db2->next_record();
-							$location_list[$j][$cols_return_extra[$i]['name']] = $this->db2->f('org_name');
-						}
-						else if($cols_return_extra[$i]['datatype']=='CH' && $value)
-						{
-							$ch= unserialize($value);
-
-							if (isset($ch) AND is_array($ch))
-							{
-								for ($k=0;$k<count($ch);$k++)
-								{
-			//						$sql="SELECT value FROM fm_location_choice where type_id=$type_id AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
-									$sql="SELECT value FROM $choice_table WHERE $attribute_choice_filter AND attrib_id=" .$cols_return_extra[$i]['attrib_id']. "  AND id=" . $ch[$k];
-									$this->db2->query($sql);
-									while ($this->db2->next_record())
-									{
-										$ch_value[]=$this->db2->f('value');
-									}
-								}
-								$location_list[$j][$cols_return_extra[$i]['name']] = @implode(",", $ch_value);
-								unset($ch_value);
-							}
-						}
-						else if($cols_return_extra[$i]['datatype']=='D' && $value)
-						{
-							$location_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($value));
-						}
-						else if($cols_return_extra[$i]['datatype']=='timestamp' && $value)
-						{
-							$location_list[$j][$cols_return_extra[$i]['name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],$value);
-						}
-						else if($cols_return_extra[$i]['datatype']=='link' && $value)
-						{
-							$location_list[$j][$cols_return_extra[$i]['name']]= phpgw::safe_redirect($value);
-						}
-						else
-						{
-							$location_list[$j][$cols_return_extra[$i]['name']] = $value;
-						}
-					}
-					unset($value);
+						$dataset[$j][$field] = array
+						(
+							'value'		=> $this->db->f($field),
+							'datatype'	=> $uicols['datatype'][$key],
+							'attrib_id'	=> isset($uicols['cols_return_extra'][$key]['attrib_id']) ? $uicols['cols_return_extra'][$key]['attrib_id']:''
+						);
 				}
-
-				$location_code=	$this->db->f('location_code');
-				$location = split('-',$location_code);
-				for ($m=0;$m<$location_count;$m++)
-				{
-					$location_list[$j]['loc' . ($m+1)] = $location[$m];
-					$location_list[$j]['query_location']['loc' . ($m+1)]=implode("-", array_slice($location, 0, ($m+1)));
-				}
-
 				$j++;
 			}
 
-			return $location_list;
+				$values = $this->custom->translate_value($dataset, $location_id, $location_count);
+			}
+			return $values;
 		}
 
 		function generate_sql($type_id='',$cols='',$cols_return='',$uicols='',$read_single='')
@@ -838,24 +858,29 @@
 			$fm_location_cols = $custom->find('property', '.location.' . $type_id, 0, '', '', '', true);
 //_debug_array($fm_location_cols);
 
-			$location_cols_count	= count($fm_location_cols);
-
 			if($read_single)
 			{
 				$cols .= ",fm_location{$type_id}.*";
+				foreach ($fm_location_cols as $location_col)
+				{
+					if($location_col['lookup_form'] == 1)
+					{
+						$cols_return[] 			= $location_col['column_name'];
+					}
+				}
 			}
 			else
 			{
-				for ($i=0;$i<$location_cols_count;$i++)
+				foreach ($fm_location_cols as $location_col)
 				{
-					if($fm_location_cols[$i]['list']==1)
+					if($location_col['list'] == 1)
 					{
-						$cols .= ",fm_location" . ($type_id) .".".$fm_location_cols[$i]['column_name'];
-						$cols_return[] 			= $fm_location_cols[$i]['column_name'];
+						$cols .= ",fm_location" . ($type_id) .".".$location_col['column_name'];
+						$cols_return[] 			= $location_col['column_name'];
 						$uicols['input_type'][]		= 'text';
-						$uicols['name'][]		= $fm_location_cols[$i]['column_name'];
-						$uicols['descr'][]		= $fm_location_cols[$i]['input_text'];
-						$uicols['statustext'][]		= $fm_location_cols[$i]['statustext'];
+						$uicols['name'][]		= $location_col['column_name'];
+						$uicols['descr'][]		= $location_col['input_text'];
+						$uicols['statustext'][]		= $location_col['statustext'];
 					}
 				}
 			}
@@ -932,12 +957,11 @@
 //echo $sql;
 			$cols_return	= $this->cols_return;
 
-			$cols_return_count	= count($cols_return);
+			$this->db->next_record();
 
-			$this->db->next_record();
-			for ($i=0;$i<$cols_return_count;$i++)
+			foreach ($cols_return as $col)
 			{
-				$values[$cols_return[$i]] = stripslashes($this->db->f($cols_return[$i]));
+				$values[$col] = $this->db->f($col,true);
 			}
 
 			if ( isset($values['attributes']) && is_array($values['attributes']) )
@@ -953,9 +977,9 @@
 			return $values;
 		}
 
-		function add($location='',$values_attribute='',$type_id='')
+		function add($location,$values_attribute = array(),$type_id='')
 		{
-			while (is_array($location) && list($input_name,$value) = each($location))
+			foreach ($location as $input_name => $value)
 			{
 				if($value)
 				{
@@ -999,6 +1023,18 @@
 
 			$this->db->transaction_commit();
 			$receipt['message'][] = array('msg'=>lang('Location %1 has been saved',$location['location_code']));
+
+			$GLOBALS['phpgw']->config->read();
+			// Keep it at level 1 for the moment
+			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'] && $type_id == 1)
+			{
+				$acl_location = ".location.{$type_id}." . str_replace("-",'.',$location['location_code']);
+				if(!$GLOBALS['phpgw']->locations->get_id('property', $acl_location))
+				{
+					$GLOBALS['phpgw']->locations->add($acl_location, $location["loc{$type_id}_name"], 'property');
+				}
+			}
+
 			return $receipt;
 		}
 
@@ -1168,6 +1204,108 @@
 			return $receipt;
 		}
 
+
+		function update_location()
+		{
+			$this->db->transaction_begin();
+
+			$this->db->query('SELECT max(id) as levels FROM fm_location_type');
+			$this->db->next_record();
+			$levels =  $this->db->f('levels');
+
+			//perform an update on all location_codes on all levels to make sure they are consistent and unique
+			$locations = array();
+			for ($level=1;$level<($levels+1);$level++)
+			{
+				$sql = "SELECT * from fm_location{$level}";
+				$this->db->query($sql,__LINE__,__FILE__);
+				$i = 0;
+				while($this->db->next_record())
+				{
+					$location_code = array();
+					$where = 'WHERE';
+					$locations[$level][$i]['condition'] = '';
+					for ($j=1;$j<($level+1);$j++)
+					{
+						$loc = $this->db->f("loc{$j}");
+						$location_code[] = $loc;
+						$locations[$level][$i]['condition'] .= "$where loc{$j}='{$loc}'";
+						$where = 'AND';
+					}
+					$locations[$level][$i]['new_values']['location_code'] = implode('-', $location_code);
+					$i++;
+				}
+
+			}
+
+			foreach($locations as $level => $location_at_leve)
+			{
+				foreach($location_at_leve as $location )
+				{
+					$sql = "UPDATE fm_location{$level} SET location_code = '{$location['new_values']['location_code']}' {$location['condition']}";
+					$this->db->query($sql,__LINE__,__FILE__);
+				}
+			}
+
+			$locations = array();
+			for ($i=1;$i<($levels+1);$i++)
+			{
+				$this->db->query("SELECT fm_location{$i}.location_code from fm_location{$i} $this->left_join fm_locations ON fm_location{$i}.location_code = fm_locations.location_code WHERE fm_locations.location_code IS NULL");
+				while($this->db->next_record())
+				{
+					$locations[] = array
+					(
+						'level' 		=> $i,
+						'location_code' => $this->db->f('location_code')
+					);
+				}
+			}
+
+			$receipt = array();
+			foreach ($locations as $location)
+			{
+				$this->db->query("INSERT INTO fm_locations (level, location_code) VALUES ({$location['level']}, '{$location['location_code']}')");
+
+				$receipt['message'][]=array('msg'=>lang('location %1 added at level %2', $location['location_code'], $location['level']));
+			}
+
+// Check ACL-location - currently only level 1
+			$GLOBALS['phpgw']->config->read();
+			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
+			{
+				$level = 1;
+				$acl_locations = array();
+				$this->db->query("SELECT location_code, loc{$level}_name FROM fm_location{$level}");
+				while($this->db->next_record())
+				{
+					$acl_locations[] = array
+					(
+						'id'	=> ".location.{$level}." . str_replace("-",'.',$this->db->f('location_code')),
+						'name'	=> $this->db->f("loc{$level}_name", true)
+					);
+				}
+
+				foreach($acl_locations as $acl_location)
+				{
+					if(!$GLOBALS['phpgw']->locations->get_id('property', $acl_location['id']))
+					{
+						$GLOBALS['phpgw']->locations->add($acl_location['id'], $acl_location['name'], 'property');
+						$receipt['message'][]=array('msg'=>lang('%1 added as ACL-location %2', $acl_location['name'], $acl_location['id']));
+					}
+				}
+			}
+
+			if( $this->db->transaction_commit() )
+			{
+				return $receipt;
+			}
+			else
+			{
+				return $receipt['error'][]=array('msg'=>lang('update failed'));
+			}
+		}
+
+
 		function read_summary($data='')
 		{
 			if(is_array($data))
@@ -1328,84 +1466,37 @@
 			$this->uicols['descr'][] = lang('exp date');
 
 
-			$attrib[] = array(
+			$attrib[] = array
+			(
 				'column_name' => 'exp_date',
 				'input_text' => 'exp date',
-				'datatype' => 'D'
+				'datatype'		=> 'D',
+				'attrib_id'		=> 0
 			);
 
 			$sql = "SELECT $table.*, $table_category.descr as category FROM $table $this->left_join $table_category ON $table.category =$table_category.id WHERE location_code='$location_code' ORDER BY exp_date DESC";
 			$this->db->query($sql,__LINE__,__FILE__);
 
 			$j=0;
+			$cols_return = $uicols['name'];
+			$dataset = array();
 			while ($this->db->next_record())
 			{
-				for ($i=0; $i<count($attrib); $i++)
-				{
-					$location[$j][$attrib[$i]['column_name']]=$this->db->f($attrib[$i]['column_name']);
-
-					$value = $this->db->f($attrib[$i]['column_name']);
-					if(($attrib[$i]['datatype']=='R' || $attrib[$i]['datatype']=='LB') && $value)
+				foreach($attrib as $key => $field)
 					{
-
-						$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$attrib[$i]['attrib_id']. "  AND id=" . $value;
-						$this->db2->query($sql);
-						$this->db2->next_record();
-						$location[$j][$attrib[$i]['column_name']] = $this->db2->f('value');
-					}
-					else if($attrib[$i]['datatype']=='AB' && $value)
-					{
-						$contact_data	= $contacts->read_single_entry($value,array('n_given'=>'n_given','n_family'=>'n_family','email'=>'email'));
-						$location[$j][$attrib[$i]['column_name']]	= $contact_data[0]['n_family'] . ', ' . $contact_data[0]['n_given'];
-					}
-					else if($attrib[$i]['datatype']=='VENDOR' && $value)
-					{
-						$sql="SELECT org_name FROM fm_vendor where id=$value";
-						$this->db2->query($sql);
-						$this->db2->next_record();
-						$location[$j][$attrib[$i]['column_name']] = $this->db2->f('org_name');
-					}
-					else if($attrib[$i]['datatype']=='CH' && $value)
-					{
-						$ch= unserialize($value);
-						if (isset($ch) AND is_array($ch))
-						{
-							for ($k=0;$k<count($ch);$k++)
-							{
-								$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id=" .$attrib[$i]['attrib_id']. "  AND id=" . $ch[$k];
-								$this->db2->query($sql);
-								while ($this->db2->next_record())
-								{
-									$ch_value[]=$this->db2->f('value');
-								}
-							}
-							$location[$j][$attrib[$i]['column_name']] = @implode(",", $ch_value);
-							unset($ch_value);
-						}
-					}
-					else if($attrib[$i]['datatype']=='D' && $value)
-					{
-						$location[$j][$attrib[$i]['column_name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],strtotime($value));
-					}
-					else if($cols_return_extra[$i]['datatype']=='link' && $value)
-					{
-						$location_list[$j][$cols_return_extra[$i]['name']]= phpgw::safe_redirect($value);
-					}
-					else if($attrib[$i]['column_name']=='entry_date' && $value)
-					{
-						$location[$j][$attrib[$i]['column_name']]=date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],$value);
-					}
-					else
-					{
-						$location_list[$j][$cols_return_extra[$i]['name']] = $value;
-					}
-
-					unset($value);
+					$dataset[$j][$field['column_name']] = array
+					(
+						'value'		=> $this->db->f($field['column_name']),
+						'datatype'	=> $field['datatype'],
+						'attrib_id'	=> $field['attib_id']
+					);
 				}
 				$j++;
 			}
 
-			return $location;
+			$values = $this->custom->translate_value($dataset, $location_id);
+
+			return $values;
 		}
 
 		function get_tenant_location($tenant_id='')
@@ -1429,5 +1520,10 @@
 			}
 		}
 
+		function get_item_id($location_code )
+		{
+			$this->db->query("SELECT id FROM fm_locations WHERE location_code='{$location_code}'",__LINE__,__FILE__);
+			$this->db->next_record();
+			return $this->db->f('id');
+		}
 	}
-

Modified: people/sigurdne/modules/property/trunk/inc/class.solookup.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.solookup.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.solookup.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -36,14 +36,12 @@
 	{
 		var $grants;
 
-		function property_solookup()
+		function __construct()
 		{
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read_addressbook($data)
@@ -56,9 +54,9 @@
 				$sort   = isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
 				$order  = isset($data['order'])?$data['order']:'';
 				$cat_id = isset($data['cat_id'])?$data['cat_id']:0;
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 			}
 
-
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
@@ -88,7 +86,15 @@
 
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
+
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);			
+			}
 
 			$contact = array();
 			while ($this->db->next_record())
@@ -111,18 +117,19 @@
 				$start		= isset($data['start']) && $data['start'] ? $data['start'] : 0;
 				$filter		= isset($data['filter'])?$data['filter']:'none';
 				$query		= isset($data['query'])?$data['query']:'';
-				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'ASC';
 				$order		= isset($data['order'])?$data['order']:'';
 				$cat_id		= isset($data['cat_id'])?$data['cat_id']:0;
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 			}
 
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
+				$ordermethod = " ORDER BY $order $sort";
 			}
 			else
 			{
-				$ordermethod = ' order by org_name DESC';
+				$ordermethod = ' ORDER BY org_name ASC';
 			}
 
 
@@ -145,7 +152,14 @@
 
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);			
+			}
 
 			$vendor = array();
 			while ($this->db->next_record())
@@ -172,6 +186,7 @@
 				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
 				$order		= isset($data['order'])?$data['order']:'';
 				$cat_id		= isset($data['cat_id'])?$data['cat_id']:0;
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 			}
 
 			if ($order)
@@ -194,7 +209,15 @@
 
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
+
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);			
+			}
 
 			$b_account = array();
 			while ($this->db->next_record())
@@ -220,6 +243,7 @@
 				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
 				$order		= isset($data['order'])?$data['order']:'';
 				$cat_id		= isset($data['cat_id'])?$data['cat_id']:0;
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 			}
 
 			if ($order)
@@ -242,7 +266,14 @@
 
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+			}
 
 			$street = array();
 			while ($this->db->next_record())
@@ -267,6 +298,7 @@
 				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
 				$order		= isset($data['order'])?$data['order']:'';
 				$cat_id		= isset($data['cat_id'])?$data['cat_id']:0;
+				$allrows	= isset($data['allrows'])?$data['allrows']:'';
 			}
 
 			if ($order)
@@ -289,7 +321,15 @@
 
 			$this->db->query($sql,__LINE__,__FILE__);
 			$this->total_records = $this->db->num_rows();
+
+			if(!$allrows)
+			{
 			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+			}
 
 			$tenant = array();
 			while ($this->db->next_record())

Modified: people/sigurdne/modules/property/trunk/inc/class.sop_of_town.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sop_of_town.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sop_of_town.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,16 +35,13 @@
 	class property_sop_of_town
 	{
 
-		function property_sop_of_town()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
 
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function read_district_name($id)
@@ -95,8 +92,8 @@
 
 			$sql = "SELECT fm_part_of_town.*, descr as category FROM fm_part_of_town $this->join fm_district on fm_part_of_town.district_id=fm_district.id $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{

Added: people/sigurdne/modules/property/trunk/inc/class.sopending_action.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sopending_action.inc.php	                        (rev 0)
+++ people/sigurdne/modules/property/trunk/inc/class.sopending_action.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -0,0 +1,332 @@
+<?php
+	/**
+	* phpGroupWare - property: a Facilities Management System.
+	*
+	* @author Sigurd Nes <[email protected]>
+	* @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software Foundation, Inc. http://www.fsf.org/
+	* This file is part of phpGroupWare.
+	*
+	* phpGroupWare is free software; you can redistribute it and/or modify
+	* it under the terms of the GNU General Public License as published by
+	* the Free Software Foundation; either version 2 of the License, or
+	* (at your option) any later version.
+	*
+	* phpGroupWare is distributed in the hope that it will be useful,
+	* but WITHOUT ANY WARRANTY; without even the implied warranty of
+	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	* GNU General Public License for more details.
+	*
+	* You should have received a copy of the GNU General Public License
+	* along with phpGroupWare; if not, write to the Free Software
+	* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+	*
+	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
+	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
+	* @package property
+	* @subpackage core
+ 	* @version $Id$
+	*/
+
+	/**
+	 * Description
+	 * @package property
+	 */
+
+	phpgw::import_class('phpgwapi.datetime');
+
+	class property_sopending_action
+	{
+		public $total_records;
+
+		/**
+		 * @var array valid responsible types
+		 */
+		protected $valid_responsible_types = array(
+								'user',
+								'vendor',
+								'tenant'
+							);
+
+		//To avoid conflicting transactions
+		protected $global_transaction  = false;
+
+		function __construct()
+		{
+			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->left_join 	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
+		}
+
+		/**
+		* Set pending action for items across the system.
+		*
+		* @param array   $data array containing string  'appname'			- the name of the module being looked up
+		*										string  'location'			- the location within the module to look up
+		* 										integer 'id'				- id of the referenced item - could possibly be a bigint
+		* 										integer 'responsible'		- the user_id asked for approval
+		* 										string  'responsible_type'  - what type of responsible is asked for action (user,vendor or tenant)
+		* 										string  'action'			- what type of action is pending
+		* 										string  'remark'			- a general remark - if any
+		* 										integer 'deadline'			- unix timestamp if any deadline is given.
+		*
+		* @return integer $reminder  number of request for this action
+		*/
+
+		public function set_pending_action($data = array())
+		{
+			$appname		= $data['appname'];
+			$location		= $data['location'];
+			$item_id		= $data['id']; //possible bigint
+			$responsible	= (int) $data['responsible'];
+			$action			= $this->db->db_addslashes($data['action']);
+			$remark			= $this->db->db_addslashes($data['remark']);
+			$deadline		= (int) $data['deadline'];
+
+			if( !$item_id)
+			{
+				throw new Exception("No item_id given");
+			}
+
+			$responsible_type = isset($data['responsible_type']) && $data['responsible_type'] ? $data['responsible_type'] : 'user';
+
+			if( !in_array($responsible_type, $this->valid_responsible_types))
+			{
+				throw new Exception("'{$responsible_type}' is not a valid responsible_type");
+			}
+
+			$sql = "SELECT id FROM fm_action_pending_category WHERE num = '{$action}'";
+			$this->db->query($sql, __LINE__,__FILE__);
+			$this->db->next_record();
+			$action_category = $this->db->f('id');
+			if ( !$action_category )
+			{
+				throw new Exception("'{$action}' is not a valid action_type");
+			}
+
+			$location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location);
+
+			if ( !$location_id )
+			{
+				throw new Exception("phpgwapi_locations::get_id ({$appname}, {$location}) returned 0");
+			}
+
+			$reminder = 1;
+
+			if( $this->db->Transaction )
+			{
+				$this->global_transaction = true;
+			}
+			else
+			{
+				$this->db->transaction_begin();
+			}
+
+			$condition = " WHERE location_id = {$location_id}"
+				. " AND item_id = {$item_id}"
+				. " AND responsible = {$responsible}"
+				. " AND action_category = {$action_category}"
+				. " AND action_performed IS NULL"
+				. " AND expired_on IS NULL";
+
+			$sql = "SELECT id, reminder FROM fm_action_pending {$condition}";
+
+			$this->db->query($sql, __LINE__,__FILE__);
+			$this->db->next_record();
+			if($this->db->f('reminder'))
+			{
+				$reminder	= $this->db->f('reminder') + 1;
+				$id			= $this->db->f('id');
+
+				$value_set = array
+				(
+					'expired_on' 		=> phpgwapi_datetime::user_localtime(),
+					'expired_by' 		=> $this->account,
+				);
+
+				if ( $deadline > 0 )
+				{
+					$value_set['deadline'] = $deadline;
+				}
+
+				if( isset($data['close']) && $data['close'] )
+				{
+					$value_set['action_performed'] = phpgwapi_datetime::user_localtime();
+				}
+
+				$value_set	= $this->db->validate_update($value_set);
+				$sql = "UPDATE fm_action_pending SET {$value_set} WHERE id = $id";
+				$ok = !!$this->db->query($sql, __LINE__,__FILE__);
+
+				if( isset($data['close']) && $data['close'] )
+				{
+					if( !$this->global_transaction )
+					{
+						$this->db->transaction_commit();
+					}
+					return $ok;
+				}
+			}
+
+			//if nothing found - and you want to close
+			if( isset($data['close']) && $data['close'] )
+			{
+				return 0;
+			}
+
+
+			$values= array
+			(
+				$item_id,								//item_id
+				$location_id,
+				$responsible,							// responsible
+				$responsible_type,						// responsible_type
+				$action_category, 						//action_category
+				phpgwapi_datetime::user_localtime(),	// action_requested
+				$reminder,
+				$deadline,								//action_deadline
+				phpgwapi_datetime::user_localtime(),	//created_on
+				$this->account,							//created_by
+				$remark									//remark
+			);
+
+			$values	= $this->db->validate_insert($values);
+			$sql = "INSERT INTO fm_action_pending ("
+				. "item_id, location_id, responsible, responsible_type,"
+				. "action_category, action_requested, reminder, action_deadline,"
+				. "created_on, created_by, remark) VALUES ( $values $vals)";
+			$this->db->query($sql, __LINE__,__FILE__);
+
+			if( !$this->global_transaction )
+			{
+				$this->db->transaction_commit();
+			}
+
+			return $reminder;
+		}
+
+		/**
+		* Get pending action for items across the system.
+		*
+		* @param array   $data array containing string  'appname'			- the name of the module being looked up
+		*										string  'location'			- the location within the module to look up
+		* 										integer 'id'				- id of the referenced item - could possibly be a bigint
+		* 										integer 'responsible'		- the user_id asked for approval
+		* 										string  'responsible_type'  - what type of responsible is asked for action (user,vendor or tenant)
+		* 										string  'action'			- what type of action is pending
+		* 										integer 'created_by'		- The user that owns the record
+		* 										integer 'deadline'			- unix timestamp if any deadline is given.
+		*
+		* @return array $ret  dataset also containing an url to the item in question
+		*/
+
+		public function get_pending_action($data = array())
+		{
+			$start				= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+			$appname			= isset($data['appname']) && $data['appname'] ? $data['appname'] : '';
+			$location			= isset($data['location']) && $data['location'] ? $data['location'] : '';
+			$item_id			= isset($data['id']) && $data['id'] ? $data['id'] : '';$data['id']; //possible bigint
+			$responsible		= (int) $data['responsible'];
+			$responsible_type	= isset($data['responsible_type']) && $data['responsible_type'] ? $data['responsible_type'] : 'user';
+			$action				= isset($data['action']) && $data['action'] ? $this->db->db_addslashes($data['action']) : '';
+			$deadline			= isset($data['deadline']) && $data['deadline'] ? (int) $data['deadline'] : 0;
+			$created_by			= isset($data['created_by']) && $data['created_by'] ? (int) $data['created_by'] : 0;
+			$sort				= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
+			$order				= isset($data['order']) ? $data['order'] : '';
+			$allrows			= isset($data['allrows']) ? $data['allrows'] : '';
+
+			if( !in_array($responsible_type, $this->valid_responsible_types))
+			{
+				throw new Exception("'{$responsible_type}' is not a valid responsible_type");
+			}
+
+			$location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location);
+
+			if ( !$location_id )
+			{
+				throw new Exception("phpgwapi_locations::get_id ({$appname}, {$location}) returned 0");
+			}
+
+			$ret = array();
+			$condition = " WHERE action_performed IS NULL AND expired_on IS NULL AND num = '{$action}' AND location_id = {$location_id}";
+
+			if( $responsible )
+			{
+				$condition .= " AND responsible = {$responsible}";
+			}
+
+			if( $item_id )
+			{
+				$condition .= " AND item_id = {$item_id}";
+			}
+
+			if( $deadline )
+			{
+				$condition .= " AND deadline < {$deadline}";
+			}
+
+			if( $created_by )
+			{
+				$condition .= " AND created_by = {$created_by}";
+			}
+
+			if ($order)
+			{
+				$ordermethod = " ORDER BY $order $sort";
+			}
+			else
+			{
+				$ordermethod = ' ORDER BY created_on DESC';
+			}
+
+			$sql = "SELECT fm_action_pending.* FROM fm_action_pending {$this->join} fm_action_pending_category"
+			. " ON fm_action_pending.action_category = fm_action_pending_category.id {$condition}";
+
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
+
+			if(!$allrows)
+			{
+				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			}
+			else
+			{
+				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+			}
+
+			$ret = $this->db->resultSet;
+
+			$interlink = CreateObject('property.interlink');
+
+			foreach ($ret as &$entry)
+			{
+				if( !$location )
+				{
+					$location = $GLOBALS['phpgw']->locations->get_name($entry['location_id']);
+				}
+				$entry['url'] = $interlink->get_relation_link($location, $entry['item_id'], 'edit');
+			}
+			return $ret;
+		}
+
+		/**
+		* Close pending action for items across the system.
+		*
+		* @param array   $data array containing string  'appname'			- the name of the module being looked up
+		*										string  'location'			- the location within the module to look up
+		* 										integer 'id'				- id of the referenced item - could possibly be a bigint
+		* 										integer 'responsible'		- the user_id asked for approval
+		* 										string  'responsible_type'  - what type of responsible is asked for action (user,vendor or tenant)
+		* 										string  'action'			- what type of action is pending
+		* 										string  'remark'			- a general remark - if any
+		* 										integer 'deadline'			- unix timestamp if any deadline is given.
+		*
+		* @return integer $reminder  number of request for this action
+		*/
+		public function close_pending_action($data = array())
+		{
+			$data['close'] = true;
+			return !!$this->set_pending_action($data);
+		}
+	}


Property changes on: people/sigurdne/modules/property/trunk/inc/class.sopending_action.inc.php
___________________________________________________________________
Added: svn:keywords
   + Id Revision
Added: svn:eol-style
   + native

Modified: people/sigurdne/modules/property/trunk/inc/class.sopricebook.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sopricebook.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sopricebook.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,16 +35,12 @@
 	class property_sopricebook
 	{
 
-		function property_sopricebook()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 		}
 
 		function add_activity_first_prize($m_cost,$w_cost,$total_cost,$activity_id,$agreement_id,$date)
@@ -251,8 +247,8 @@
 //echo $sql;
 
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -335,8 +331,8 @@
 
 			$sql = "SELECT * FROM  fm_agreement_group $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -417,8 +413,8 @@
 				. " FROM fm_activity_price_index $this->join fm_agreement on fm_activity_price_index.agreement_id = fm_agreement.id "
 				. " Where activity_id= '$activity_id' and fm_activity_price_index.agreement_id= '$agreement_id'";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -497,8 +493,8 @@
 				. " $filtermethod $querymethod ";
 
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -574,8 +570,8 @@
 				. " Where fm_activity_price_index.activity_id= '$activity_id' $querymethod group by fm_activities.id,fm_activities.num,"
 				. " fm_branch.descr,org_name , fm_agreement.id ";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -658,7 +654,7 @@
 				$values['base_descr']
 				);
 
-			$vals	= $this->bocommon->validate_db_insert($vals);
+			$vals	= $this->db->validate_insert($vals);
 
 			$this->db->transaction_begin();
 			$this->db->query("INSERT INTO fm_activities (id, num,unit,agreement_group_id,ns3420,dim_d,branch_id,descr,base_descr) "
@@ -686,7 +682,7 @@
 				'base_descr'			=> $values['base_descr']
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 			$this->db->transaction_begin();
 			$this->db->query("UPDATE fm_activities set $value_set WHERE id= '" . $values['activity_id'] . "'",__LINE__,__FILE__);
 			$this->db->transaction_commit();
@@ -707,7 +703,7 @@
 				$values['descr']
 				);
 
-			$vals	= $this->bocommon->validate_db_insert($vals);
+			$vals	= $this->db->validate_insert($vals);
 
 			$this->db->query("INSERT INTO fm_agreement_group (id,num,status,descr) "
 				. "VALUES ($vals)",__LINE__,__FILE__);
@@ -727,7 +723,7 @@
 				'descr'	=> $values['descr']
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 			$this->db->transaction_begin();
 
 			$this->db->query("UPDATE fm_agreement_group set $value_set WHERE id= '" . $values['agreement_group_id'] . "'",__LINE__,__FILE__);

Modified: people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,18 +34,19 @@
 
 	class property_soproject
 	{
+		var $total_records = 0;
 
-		function property_soproject()
+		function __construct()
 		{
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
 			$this->interlink 	= CreateObject('property.interlink');
+			$this->custom 		= createObject('property.custom_fields');
 
-			$this->like =& $this->db->like;
-			$this->join =& $this->db->join;
-			$this->left_join = " LEFT JOIN ";
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->left_join 	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
 
 			$this->acl 		= & $GLOBALS['phpgw']->acl;
 			$this->grants	= $this->acl->get_grants('property','.project');
@@ -53,7 +54,7 @@
 
 		function select_status_list()
 		{
-			$this->db->query("SELECT id, descr FROM fm_workorder_status ORDER BY id ");
+			$this->db->query("SELECT id, descr FROM fm_project_status ORDER BY id ");
 
 			$i = 0;
 			while ($this->db->next_record())
@@ -99,7 +100,7 @@
 			if(is_array($data))
 			{
 				$start	= isset($data['start']) && $data['start'] ? $data['start'] : 0;
-				$filter	= $data['filter']?$data['filter']:'all';
+				$filter	= $data['filter']?(int)$data['filter']:0;
 				$query = (isset($data['query'])?$data['query']:'');
 				$sort = (isset($data['sort'])?$data['sort']:'DESC');
 				$order = (isset($data['order'])?$data['order']:'');
@@ -109,6 +110,9 @@
 				$end_date = (isset($data['end_date'])?$data['end_date']:'');
 				$allrows = (isset($data['allrows'])?$data['allrows']:'');
 				$wo_hour_cat_id = (isset($data['wo_hour_cat_id'])?$data['wo_hour_cat_id']:'');
+				$district_id	= (isset($data['district_id'])?$data['district_id']:'');
+				$dry_run		= isset($data['dry_run']) ? $data['dry_run'] : '';
+				$criteria	= isset($data['criteria']) && $data['criteria'] ? $data['criteria'] : array();				
 			}
 
 			$sql = $this->bocommon->fm_cache('sql_project_' . !!$wo_hour_cat_id);
@@ -126,13 +130,47 @@
 				$uicols['name'][]			= 'project_id';
 				$uicols['descr'][]			= lang('Project');
 				$uicols['statustext'][]		= lang('Project ID');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
+				$cols .= ", project_group";
+				$cols_return[] 				= 'project_group';
+				$uicols['input_type'][]		= 'text';
+				$uicols['name'][]			= 'project_group';
+				$uicols['descr'][]			= lang('group');
+				$uicols['statustext'][]		= lang('Project group');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= 'rightClasss';
+
+				$cols .= ", fm_project_status.descr as status";
+				$cols_return[] 				= 'status';
+				$uicols['input_type'][]		= 'text';
+				$uicols['name'][]			= 'status';
+				$uicols['descr'][]			= lang('status');
+				$uicols['statustext'][]		= lang('status');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
+
 				$cols.= ",$entity_table.start_date";
 				$cols_return[] 				= 'start_date';
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]			= 'start_date';
 				$uicols['descr'][]			= lang('start date');
 				$uicols['statustext'][]		= lang('Project start date');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols.= ",$entity_table.name as name";
 				$cols_return[] 				= 'name';
@@ -140,13 +178,35 @@
 				$uicols['name'][]			= 'name';
 				$uicols['descr'][]			= lang('name');
 				$uicols['statustext'][]		= lang('Project name');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
+				$cols.= ",loc1_name";
+				$cols_return[] 				= 'loc1_name';
+				$uicols['input_type'][]		= 'hidden';
+				$uicols['name'][]			= 'loc1_name';
+				$uicols['descr'][]			= lang('loc1_name');
+				$uicols['statustext'][]		= lang('loc1_name');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
+
 				$cols.= ",account_lid as coordinator";
 				$cols_return[] 				= 'coordinator';
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]			= 'coordinator';
 				$uicols['descr'][]			= lang('Coordinator');
 				$uicols['statustext'][]		= lang('Project coordinator');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols.= ",(fm_project.budget + fm_project.reserve) as budget";
 				$cols_return[] 				= 'budget';
@@ -154,6 +214,11 @@
 				$uicols['name'][]			= 'budget';
 				$uicols['descr'][]			= lang('Project budget');
 				$uicols['statustext'][]		= lang('Project budget');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= 'myFormatCount2';
+				$uicols['classname'][]		= 'rightClasss';
 
 				$cols .= ',sum(fm_workorder.combined_cost) as combined_cost';
 				$cols_return[] = 'combined_cost';
@@ -161,6 +226,11 @@
 				$uicols['name'][]			= 'combined_cost';
 				$uicols['descr'][]			= lang('Sum	workorder');
 				$uicols['statustext'][]		= lang('Cost - either budget or calculation');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= 'myFormatCount2';
+				$uicols['classname'][]		= 'rightClasss';
 
 				$cols .= ',(sum(fm_workorder.act_mtrl_cost) + sum(fm_workorder.act_vendor_cost)) as actual_cost';
 				$cols_return[] = 'actual_cost';
@@ -168,13 +238,32 @@
 				$uicols['name'][]			= 'actual_cost';
 				$uicols['descr'][]			= lang('Actual cost');
 				$uicols['statustext'][]		= lang('Actual cost - paid so far');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= 'myFormatCount2';
+				$uicols['classname'][]		= 'rightClasss';
 
+				$cols .= ',planned_cost';
+				$cols_return[] = 'planned_cost';
+				$uicols['input_type'][]		= 'text';
+				$uicols['name'][]			= 'planned_cost';
+				$uicols['descr'][]			= lang('planned cost');
+				$uicols['statustext'][]		= lang('ordered minus paid');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+				$uicols['formatter'][]		= 'myFormatCount2';
+				$uicols['classname'][]		= 'rightClasss';
 
 				$cols.= ",$entity_table.user_id";
 
 				$joinmethod = " $this->join  phpgw_accounts ON ($entity_table.coordinator = phpgw_accounts.account_id))";
 				$paranthesis ='(';
 
+				$joinmethod .= " $this->join fm_project_status ON ($entity_table.status = fm_project_status.id))";
+				$paranthesis .='(';
+
 				$joinmethod .= " $this->left_join fm_workorder ON ($entity_table.id = fm_workorder.project_id))";
 				$paranthesis .='(';
 
@@ -215,6 +304,11 @@
 				$this->cols_extra	= $this->bocommon->fm_cache('cols_extra_project_' . !!$wo_hour_cat_id);
 			}
 
+			if($dry_run)
+			{
+				return array();
+			}
+
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
@@ -228,7 +322,7 @@
 
 			$filtermethod = '';
 
-			$GLOBALS['phpgw']->config->read_repository();
+			$GLOBALS['phpgw']->config->read();
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
 			{
 				$access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
@@ -254,10 +348,17 @@
 				$where= 'AND';
 			}
 
-			$group_method = ' GROUP BY fm_project.location_code,fm_project.id,fm_project.start_date,fm_project.name,phpgw_accounts.account_lid,fm_project.user_id,fm_project.address,fm_project.budget,fm_project.reserve';
+			if($district_id)
+			{
+				$filtermethod .= " {$where} fm_part_of_town.district_id = {$district_id}";
+				$where= 'AND';
+			}
 
-			if ($filter=='all')
-			{
+			$group_method = ' GROUP BY fm_project_status.descr,loc1_name,fm_project.location_code,fm_project.id,fm_project.start_date,'
+				. 'fm_project.name,phpgw_accounts.account_lid,fm_project.user_id,fm_project.address,'
+				. 'fm_project.budget,fm_project.reserve,planned_cost,project_group';
+
+
 				if (is_array($this->grants))
 				{
 					$grants = $this->grants;
@@ -266,14 +367,14 @@
 						$public_user_list[] = $user;
 					}
 					reset($public_user_list);
-					$filtermethod .= " $where (fm_project.user_id IN(" . implode(',',$public_user_list) . "))";
+				$filtermethod .= " $where (fm_project.user_id IN(" . implode(',',$public_user_list) . ")";
 
 					$where= 'AND';
 				}
-			}
-			else
+
+			if ($filter)
 			{
-				$filtermethod .= " $where fm_project.user_id=$filter ";
+				$filtermethod .= " $where fm_project.user_id={$filter}";
 				$where= 'AND';
 			}
 
@@ -283,7 +384,7 @@
 				$where= 'AND';
 			}
 
-
+			$querymethod = '';
 			if($query)
 			{
 				$query = $this->db->db_addslashes($query);
@@ -295,15 +396,53 @@
 				}
 				else
 				{
-					$querymethod = " $where (fm_project.name $this->like '%$query%' or fm_project.address $this->like '%$query%' or fm_project.location_code $this->like '%$query%' or fm_project.id =" . (int)$query .')';
+
+					$matchtypes = array
+					(
+						'exact' => '=',
+						'like'	=> $this->like						
+					);
+					
+					if(count($criteria) > 1)
+					{
+						$_querymethod = array();
+						foreach($criteria as $field_info)
+						{
+							if($field_info['type'] == int)
+							{
+								$_query = (int) $query;
+							}
+							else
+							{
+								$_query = $query;
+							}
+
+							$_querymethod[] = "{$field_info['field']} {$matchtypes[$field_info['matchtype']]} {$field_info['front']}{$_query}{$field_info['back']}";
 				}
+
+						$querymethod = $where . ' ' . implode(' OR ', $_querymethod);
+						unset($_querymethod);
 			}
 			else
 			{
-				$querymethod = '';
+						if($criteria[0]['type'] == int)
+						{
+							$_query = (int) $query;
+						}
+						else
+						{
+							$_query = $query;
+						}
+
+						$querymethod = "{$where} {$criteria[0]['field']} {$matchtypes[$criteria[0]['matchtype']]} {$criteria[0]['front']}{$_query}{$criteria[0]['back']}";
+					}
 			}
+			}
 
+			$querymethod .= ')';
+
 			$sql .= " $filtermethod $querymethod";
+
 //echo substr($sql,strripos($sql,'from'));
 			if($GLOBALS['phpgw_info']['server']['db_type']=='postgres')
 			{
@@ -359,46 +498,66 @@
 		function get_meter_table()
 		{
 			$config = CreateObject('phpgwapi.config','property');
-			$config->read_repository();
+			$config->read();
 			return isset($config->config_data['meter_table'])?$config->config_data['meter_table']:'';
 		}
 
-		function read_single($project_id)
+		function read_single($project_id, $values = array())
 		{
-			$sql = "SELECT * from fm_project where id='$project_id'";
+			$project_id = (int) $project_id;
+			$sql = "SELECT * from fm_project WHERE id={$project_id}";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+
 			if ($this->db->next_record())
 			{
-				$project['project_id']			= $this->db->f('id');
-				$project['title']			= $this->db->f('title');
-				$project['name']			= $this->db->f('name');
-				$project['location_code']		= $this->db->f('location_code');
-				$project['key_fetch']			= $this->db->f('key_fetch');
-				$project['key_deliver']			= $this->db->f('key_deliver');
-				$project['other_branch']		= $this->db->f('other_branch');
-				$project['key_responsible']		= $this->db->f('key_responsible');
-				$project['descr']			= stripslashes($this->db->f('descr'));
-				$project['status']			= $this->db->f('status');
-				$project['budget']			= (int)$this->db->f('budget');
-				$project['reserve']			= (int)$this->db->f('reserve');
-				$project['tenant_id']			= $this->db->f('tenant_id');
-				$project['user_id']			= $this->db->f('user_id');
-				$project['coordinator']			= $this->db->f('coordinator');
-				$project['access']			= $this->db->f('access');
-				$project['start_date']			= $this->db->f('start_date');
-				$project['end_date']			= $this->db->f('end_date');
-				$project['cat_id']			= $this->db->f('category');
-				$project['grants'] 			= (int)$this->grants[$this->db->f('user_id')];
-				$project['p_num']			= $this->db->f('p_num');
-				$project['p_entity_id']			= $this->db->f('p_entity_id');
-				$project['p_cat_id']			= $this->db->f('p_cat_id');
-				$project['contact_phone']		= $this->db->f('contact_phone');
+				$project = array
+				(
+					'project_id'			=> $this->db->f('id'),
+					'title'					=> $this->db->f('title'),
+					'name'					=> $this->db->f('name'),
+					'location_code'			=> $this->db->f('location_code'),
+					'key_fetch'				=> $this->db->f('key_fetch'),
+					'key_deliver'			=> $this->db->f('key_deliver'),
+					'other_branch'			=> $this->db->f('other_branch'),
+					'key_responsible'		=> $this->db->f('key_responsible'),
+					'descr'					=> $this->db->f('descr', true),
+					'status'				=> $this->db->f('status'),
+					'budget'				=> (int)$this->db->f('budget'),
+					'planned_cost'			=> (int)$this->db->f('planned_cost'),
+					'reserve'				=> (int)$this->db->f('reserve'),
+					'tenant_id'				=> $this->db->f('tenant_id'),
+					'user_id'				=> $this->db->f('user_id'),
+					'coordinator'			=> $this->db->f('coordinator'),
+					'access'				=> $this->db->f('access'),
+					'start_date'			=> $this->db->f('start_date'),
+					'end_date'				=> $this->db->f('end_date'),
+					'cat_id'				=> $this->db->f('category'),
+					'grants' 				=> (int)$this->grants[$this->db->f('user_id')],
+					'p_num'					=> $this->db->f('p_num'),
+					'p_entity_id'			=> $this->db->f('p_entity_id'),
+					'p_cat_id'				=> $this->db->f('p_cat_id'),
+					'contact_phone'			=> $this->db->f('contact_phone'),
+					'project_group'			=> $this->db->f('project_group'),
+					'ecodimb'				=> $this->db->f('ecodimb'),
+					'b_account_id'			=> $this->db->f('account_id'),
+					'contact_id'			=> $this->db->f('contact_id'),
+				);
 
-				$project['power_meter']	= $this->get_power_meter($this->db->f('location_code'));
+				if ( isset($values['attributes']) && is_array($values['attributes']) )
+				{
+					$project['attributes'] = $values['attributes'];
+					foreach ( $project['attributes'] as &$attr )
+					{
+						$attr['value'] 	= $this->db->f($attr['column_name']);
 			}
+				}
 
+
+				$location_code = $this->db->f('location_code');
+				$project['power_meter']		= $this->get_power_meter($location_code);
+			}
 //_debug_array($project);
 				return $project;
 		}
@@ -410,25 +569,26 @@
 				return false;
 			}
 
-			$this->db2->query("SELECT ext_meter_id as power_meter FROM $meter_table where location_code='$location_code' and category='1'",__LINE__,__FILE__);
+			$this->db->query("SELECT ext_meter_id as power_meter FROM $meter_table where location_code='$location_code' and category='1'",__LINE__,__FILE__);
 
-			$this->db2->next_record();
+			$this->db->next_record();
 
-			return $this->db2->f('power_meter');
+			return $this->db->f('power_meter');
 		}
 
 		function project_workorder_data($project_id = '')
 		{
+			$project_id = (int) $project_id;
 			$budget = array();
 			$this->db->query("SELECT act_mtrl_cost, act_vendor_cost, budget, fm_workorder.id as workorder_id, vendor_id, calculation,rig_addition,addition,deviation,charge_tenant,fm_workorder_status.descr as status"
-			." FROM fm_workorder $this->join fm_workorder_status ON fm_workorder.status = fm_workorder_status.id WHERE project_id='$project_id'");
+			." FROM fm_workorder $this->join fm_workorder_status ON fm_workorder.status = fm_workorder_status.id WHERE project_id={$project_id}");
 			while ($this->db->next_record())
 			{
 				$budget[] = array(
 					'workorder_id'		=> $this->db->f('workorder_id'),
-					'budget'			=> $this->db->f('budget'),
+					'budget'			=> (int)$this->db->f('budget'),
 					'deviation'			=> $this->db->f('deviation'),
-					'calculation'		=> ($this->db->f('calculation')*(1+$this->db->f('addition')/100))+$this->db->f('rig_addition'),
+					'calculation'		=> $this->db->f('calculation'),
 					'vendor_id'			=> $this->db->f('vendor_id'),
 					'act_mtrl_cost'		=> $this->db->f('act_mtrl_cost'),
 					'act_vendor_cost'	=> $this->db->f('act_vendor_cost'),
@@ -442,10 +602,10 @@
 		function branch_p_list($project_id = '')
 		{
 			$selected = array();
-			$this->db2->query("SELECT branch_id from fm_projectbranch WHERE project_id=" .  (int)$project_id ,__LINE__,__FILE__);
-			while ($this->db2->next_record())
+			$this->db->query("SELECT branch_id from fm_projectbranch WHERE project_id=" .  (int)$project_id ,__LINE__,__FILE__);
+			while ($this->db->next_record())
 			{
-				$selected[] = array('branch_id' => $this->db2->f('branch_id'));
+				$selected[] = array('branch_id' => $this->db->f('branch_id'));
 			}
 			return $selected;
 		}
@@ -463,8 +623,9 @@
 			return $project_id;
 		}
 
-		function add($project)
+		function add($project, $values_attribute = array())
 		{
+			$receipt = array();
 			$historylog	= CreateObject('property.historylog','project');
 
 			while (is_array($project['location']) && list($input_name,$value) = each($project['location']))
@@ -485,6 +646,19 @@
 				}
 			}
 
+			$data_attribute = $this->custom->prepare_for_db('fm_project', $values_attribute);
+			if(isset($data_attribute['value_set']))
+			{
+				foreach($data_attribute['value_set'] as $input_name => $value)
+				{
+					if(isset($value) && $value)
+					{
+						$cols[] = $input_name;
+						$vals[] = $value;
+					}
+				}
+			}
+
 			if($cols)
 			{
 				$cols	= "," . implode(",", $cols);
@@ -506,8 +680,12 @@
 			$project['descr'] = $this->db->db_addslashes($project['descr']);
 			$project['name'] = $this->db->db_addslashes($project['name']);
 
-			$values= array(
-				$project['project_id'],
+			$this->db->transaction_begin();
+			$id = $this->next_project_id();
+			$values= array
+			(
+				$id,
+				$project['project_group'],
 				$project['name'],
 				'public',
 				$project['cat_id'],
@@ -517,22 +695,24 @@
 				$project['coordinator'],
 				$project['status'],
 				$project['descr'],
-				$project['budget'],
-				$project['reserve'],
+				(int) $project['budget'],
+				(int) $project['reserve'],
 				$project['location_code'],
 				$address,
 				$project['key_deliver'],
 				$project['key_fetch'],
 				$project['other_branch'],
 				$project['key_responsible'],
-				$this->account);
+				$this->account,
+				$project['ecodimb'],
+				$project['b_account_id'],
+				$project['contact_id']
+			);
 
 			$values	= $this->bocommon->validate_db_insert($values);
 
-			$this->db->transaction_begin();
-
-			$this->db->query("INSERT INTO fm_project (id,name,access,category,entry_date,start_date,end_date,coordinator,status,"
-				. "descr,budget,reserve,location_code,address,key_deliver,key_fetch,other_branch,key_responsible,user_id $cols) "
+			$this->db->query("INSERT INTO fm_project (id,project_group,name,access,category,entry_date,start_date,end_date,coordinator,status,"
+				. "descr,budget,reserve,location_code,address,key_deliver,key_fetch,other_branch,key_responsible,user_id,ecodimb,account_id,contact_id $cols) "
 				. "VALUES ($values $vals )",__LINE__,__FILE__);
 
 			if($project['extra']['contact_phone'] && $project['extra']['tenant_id'])
@@ -549,7 +729,7 @@
 			{
 				while($branch=each($project['branch']))
 				{
-					$this->db->query("insert into fm_projectbranch (project_id,branch_id) values ('" . $project['project_id']. "','$branch[1]')",__LINE__,__FILE__);
+					$this->db->query("insert into fm_projectbranch (project_id,branch_id) values ({$id},{$branch[1]})",__LINE__,__FILE__);
 				}
 			}
 
@@ -562,7 +742,7 @@
 						'location1_id'		=> $GLOBALS['phpgw']->locations->get_id('property', $project['origin'][0]['location']),
 						'location1_item_id' => $project['origin'][0]['data'][0]['id'],
 						'location2_id'		=> $GLOBALS['phpgw']->locations->get_id('property', '.project'),			
-						'location2_item_id' => $project['project_id'],
+						'location2_item_id' => $id,
 						'account_id'		=> $this->account
 					);
 					
@@ -573,20 +753,22 @@
 			if($this->db->transaction_commit())
 			{
 				$this->increment_project_id();
-				$historylog->add('SO',$project['project_id'],$project['status']);
-				$historylog->add('TO',$project['project_id'],$project['cat_id']);
-				$historylog->add('CO',$project['project_id'],$project['coordinator']);
+				$historylog->add('SO', $id, $project['status']);
+				$historylog->add('TO', $id, $project['cat_id']);
+				$historylog->add('CO', $id, $project['coordinator']);
 				if ($project['remark'])
 				{
-					$historylog->add('RM',$project['project_id'],$project['remark']);
+					$historylog->add('RM', $id, $project['remark']);
 				}
 
-				$receipt['message'][] = array('msg'=>lang('project %1 has been saved',$project['project_id']));
+				$receipt['message'][] = array('msg'=>lang('project %1 has been saved',$id));
 			}
 			else
 			{
 				$receipt['error'][] = array('msg'=>lang('the project has not been saved'));
 			}
+			
+			$receipt['id'] = $id;
 			return $receipt;
 		}
 
@@ -657,25 +839,11 @@
 			return $meter_id;
 		}
 
-		function edit($project)
+		function edit($project, $values_attribute = array())
 		{
 			$historylog	= CreateObject('property.historylog','project');
+			$receipt = array();
 
-			while (is_array($project['location']) && list($input_name,$value) = each($project['location']))
-			{
-				$vals[]	= "$input_name = '$value'";
-			}
-
-			while (is_array($project['extra']) && list($input_name,$value) = each($project['extra']))
-			{
-				$vals[]	= "$input_name = '$value'";
-			}
-
-			if($vals)
-			{
-				$vals	= "," . implode(",",$vals);
-			}
-
 			if($project['street_name'])
 			{
 				$address[]= $project['street_name'];
@@ -692,6 +860,7 @@
 			$project['name'] = $this->db->db_addslashes($project['name']);
 
 			$value_set=array(
+				'project_group'		=> $project['project_group'],
 				'name'			=> $project['name'],
 				'status'		=> $project['status'],
 				'category'		=> $project['cat_id'],
@@ -706,24 +875,46 @@
 				'other_branch'		=> $project['other_branch'],
 				'key_responsible'	=> $project['key_responsible'],
 				'location_code'		=> $project['location_code'],
-				'address'		=> $address
+				'address'			=> $address,
+				'ecodimb'			=> $project['ecodimb'],
+				'account_id'		=> $project['b_account_id'],
+				'contact_id'		=> $project['contact_id']
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$data_attribute = $this->custom->prepare_for_db('fm_project', $values_attribute, $data['id']);
 
+			if(isset($data_attribute['value_set']))
+			{
+				$value_set = array_merge($value_set, $data_attribute['value_set']);
+			}
+
+			while (is_array($project['location']) && list($input_name,$value) = each($project['location']))
+			{
+				$value_set[$input_name] = $value;
+			}
+
+			while (is_array($project['extra']) && list($input_name,$value) = each($project['extra']))
+			{
+				$value_set[$input_name] = $value;
+			}
+
+			$value_set	= $this->db->validate_update($value_set);
+
 			$this->db->transaction_begin();
 
-			$this->db->query("SELECT status,category,coordinator FROM fm_project where id='" .$project['project_id']."'",__LINE__,__FILE__);
+			$this->db->query("SELECT status,category,coordinator,budget,reserve FROM fm_project WHERE id = {$project['id']}",__LINE__,__FILE__);
 			$this->db->next_record();
 			$old_status = $this->db->f('status');
 			$old_category = (int)$this->db->f('category');
 			$old_coordinator = (int)$this->db->f('coordinator');
+			$old_budget = (int)$this->db->f('budget');
+			$old_reserve = (int)$this->db->f('reserve');
 
-			$this->db->query("UPDATE fm_project set $value_set $vals WHERE id= '" . $project['project_id'] ."'",__LINE__,__FILE__);
+			$this->db->query("UPDATE fm_project SET $value_set WHERE id= {$project['id']}",__LINE__,__FILE__);
 
 			if($project['extra']['contact_phone'] && $project['extra']['tenant_id'])
 			{
-				$this->db->query("update fm_tenant set contact_phone='". $project['extra']['contact_phone']. "' where id='". $project['extra']['tenant_id']. "'",__LINE__,__FILE__);
+				$this->db->query("UPDATE fm_tenant SET contact_phone='". $project['extra']['contact_phone']. "' WHERE id='". $project['extra']['tenant_id']. "'",__LINE__,__FILE__);
 			}
 
 			if (isset($project['power_meter']) && $project['power_meter'])
@@ -731,92 +922,156 @@
 				$this->update_power_meter($project['power_meter'],$project['location_code'],$address);
 			}
 	// -----------------which branch is represented
-			$this->db->query("delete from fm_projectbranch where project_id='" . $project['project_id'] ."'",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_projectbranch WHERE project_id={$project['id']}",__LINE__,__FILE__);
 
 			if (count($project['branch']) != 0)
 			{
 				while($branch=each($project['branch']))
 				{
-					$this->db->query("insert into fm_projectbranch (project_id,branch_id) values ('" . $project['project_id']. "','$branch[1]')",__LINE__,__FILE__);
+					$this->db->query("INSERT INTO fm_projectbranch (project_id,branch_id) VALUES ({$project['id']}, {$branch[1]})",__LINE__,__FILE__);
 				}
 			}
 
 			if($project['delete_request'])
 			{
-				$receipt = $this->delete_request_from_project($project['delete_request'],$project['project_id']);
+				$receipt = $this->delete_request_from_project($project['delete_request'],$project['id']);
 
 			}
 
-			$this->update_request_status($project['project_id'],$project['status'],$project['cat_id'],$project['coordinator']);
+			$this->update_request_status($project['id'],$project['status'],$project['cat_id'],$project['coordinator']);
 
 			if (($old_status != $project['status']) || $project['confirm_status'])
 			{
-				$this->db->query("SELECT id from fm_workorder WHERE project_id=" .  (int)$project['project_id'] ,__LINE__,__FILE__);
+				$close_pending_action = false;
+				$close_workorders = false;
+				$this->db->query("SELECT * FROM fm_project_status WHERE id = '{$project['status']}'");
+				$this->db->next_record();
+				if ($this->db->f('closed') )
+				{
+					$close_workorders = true;
+				}
+
+
+				if ($this->db->f('approved') )
+				{
+					$close_pending_action = true;
+
+					$action_params = array
+					(
+						'appname'			=> 'property',
+						'location'			=> '.project',
+						'id'				=> (int)$project['id'],
+						'responsible'		=> $this->account,
+						'responsible_type'  => 'user',
+						'action'			=> 'approval',
+						'remark'			=> '',
+						'deadline'			=> ''
+					);
+
+					execMethod('property.sopending_action.close_pending_action', $action_params);
+					unset($action_params);
+				}
+ 
+				$this->db->query("SELECT id from fm_workorder WHERE project_id=" .  (int)$project['id'] ,__LINE__,__FILE__);
+				$workorder = array();
 				while ($this->db->next_record())
 				{
 					$workorder[] = $this->db->f('id');
 				}
 
-				if (isset($workorder) AND is_array($workorder))
+				if ($workorder)
 				{
 					$historylog_workorder	= CreateObject('property.historylog','workorder');
 				}
 
-				if($old_status != $project['status'])
+				if($old_status != $project['status'] && $close_workorders)
 				{
-					$historylog->add('S',$project['project_id'],$project['status']);
+					$historylog->add('S',$project['id'],$project['status'], $old_status);
 
-					$this->db->query("UPDATE fm_workorder set status='". $project['status'] . "' WHERE project_id= '" . $project['project_id'] ."'",__LINE__,__FILE__);
+					$this->db->query("UPDATE fm_workorder SET status='closed' WHERE project_id = {$project['id']}",__LINE__,__FILE__);
 
 					if (isset($workorder) AND is_array($workorder))
 					{
 						foreach($workorder as $workorder_id)
 						{
-							$historylog_workorder->add('S',$workorder_id,$project['status']);
+							$historylog_workorder->add('S',$workorder_id,'closed');
 						}
 					}
 					$receipt['notice_owner'][]=lang('Status changed') . ': ' . $project['status'];
 				}
 				elseif($project['confirm_status'])
 				{
-					$historylog->add('SC',$project['project_id'],$project['status']);
+					$historylog->add('SC',$project['id'],$project['status']);
 
-					if (isset($workorder) AND is_array($workorder))
+					if (isset($workorder) && is_array($workorder)  && $close_workorders)
 					{
 						foreach($workorder as $workorder_id)
 						{
-							$historylog_workorder->add('SC',$workorder_id,$project['status']);
+							$historylog_workorder->add('SC',$workorder_id,'closed');
 						}
 					}
 					$receipt['notice_owner'][]=lang('Status confirmed') . ': ' . $project['status'];
 				}
 
+				if($close_pending_action)
+				{
+					$action_params = array
+					(
+						'appname'			=> 'property',
+						'location'			=> '.project.workorder',
+						'id'				=> 0,
+						'responsible'		=> $this->account,
+						'responsible_type'  => 'user',
+						'action'			=> 'approval',
+						'remark'			=> '',
+						'deadline'			=> ''
+					);
+
+
+					foreach($workorder as $workorder_id)
+					{
+						$action_params['id'] =  $workorder_id;
+						execMethod('property.sopending_action.close_pending_action', $action_params);
+					}
+					unset($action_params);
+				}
 			}
 
 			if ($old_category != $project['cat_id'])
 			{
-				$historylog->add('T',$project['project_id'],$project['cat_id']);
+				$historylog->add('T',$project['id'],$project['cat_id'], $old_category);
 			}
 			if ($old_coordinator != $project['coordinator'])
 			{
-				$historylog->add('C',$project['project_id'],$project['coordinator']);
+				$historylog->add('C',$project['id'],$project['coordinator'], $old_coordinator);
 				$receipt['notice_owner'][]=lang('Coordinator changed') . ': ' . $GLOBALS['phpgw']->accounts->id2name($project['coordinator']);
 			}
 
+			if ($old_budget != (int)$project['budget'])
+			{
+				$historylog->add('B',$project['id'],$project['budget'], $old_budget);
+			}
+
+			if ($old_reserve != (int)$project['reserve'])
+			{
+				$historylog->add('BR',$project['id'],$project['reserve'], $old_reserve);
+			}
+
 			if ($project['remark'])
 			{
-				$historylog->add('RM',$project['project_id'],$project['remark']);
+				$historylog->add('RM',$project['id'],$project['remark']);
 			}
 
-			$receipt['message'][] = array('msg'=>lang('project %1 has been edited',$project['project_id']));
+ 			execMethod('property.soworkorder.update_planned_cost', $project['id']);
+ 			
+			$receipt['id'] = $project['id'];
+			$receipt['message'][] = array('msg'=>lang('project %1 has been edited', $project['id']));
 
 			$this->db->transaction_commit();
 
 			return $receipt;
-
 		}
 
-
 		function delete_request_from_project($request,$project_id)
 		{
 			foreach ($request as $request_id)
@@ -866,7 +1121,7 @@
 
 		function check_request($request_id)
 		{
-			$target = $this->interlink->get_specific_targets('property', '.project.request', '.project', $request_id);
+			$target = $this->interlink->get_specific_relation('property', '.project.request', '.project', $request_id);
 
 			if ( $target)
 			{
@@ -909,7 +1164,7 @@
 
 		function delete($project_id )
 		{
-			$request = $this->interlink->get_specific_targets('property', '.project.request', '.project', $project_id);
+			$request = $this->interlink->get_specific_relation('property', '.project.request', '.project', $project_id);
 
 			$sql = "SELECT id as workorder_id FROM fm_workorder WHERE project_id='$project_id'";
 			$this->db->query($sql,__LINE__,__FILE__);

Modified: people/sigurdne/modules/property/trunk/inc/class.sor_agreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sor_agreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sor_agreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -36,17 +36,15 @@
 	{
 		var $role;
 
-		function property_sor_agreement()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->db2          = clone($this->db);
 
-			$this->join			= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like			= $this->bocommon->like;
+			$this->join			= $this->db->join;
+			$this->left_join	= $this->db->left_join;
+			$this->like			= $this->db->like;
 		}
 
 		function select_vendor_list()
@@ -679,7 +677,7 @@
 
 
 			$this->db->transaction_begin();
-			$id = $this->bocommon->next_id('fm_r_agreement');
+			$id = $this->db->next_id('fm_r_agreement');
 
 			$vals[]	= $id;
 			$vals[]	= $r_agreement['name'];
@@ -724,7 +722,7 @@
 				$cols	= "," . implode(",", $cols);
 			}
 
-			$vals	= $this->bocommon->validate_db_insert($vals);
+			$vals	= $this->db->validate_insert($vals);
 
 			$this->db->query("INSERT INTO $table (id,name,descr,entry_date,category,member_of,start_date,end_date,termination_date,customer_id,customer_name,account_id,user_id $cols) "
 				. "VALUES ($vals)",__LINE__,__FILE__);
@@ -802,11 +800,11 @@
 			if($cols)
 			{
 				$cols	= "," . implode(",", $cols);
-				$vals	= "," . $this->bocommon->validate_db_insert($vals);
+				$vals	= "," . $this->db->validate_insert($vals);
 			}
 
 			$this->db->transaction_begin();
-			$id = $this->bocommon->next_id($table,array('agreement_id'=>$values['r_agreement_id']));
+			$id = $this->db->next_id($table,array('agreement_id'=>$values['r_agreement_id']));
 
 			$this->db->query("INSERT INTO $table (id,agreement_id,entry_date,user_id $cols) "
 				. "VALUES ($id," . $values['r_agreement_id'] ."," . time()
@@ -893,7 +891,7 @@
 			$value_set['customer_name']= $values['customer_name'];
 			if($value_set)
 			{
-				$value_set	= ',' . $this->bocommon->validate_db_update($value_set);
+				$value_set	= ',' . $this->db->validate_update($value_set);
 			}
 
 			$this->db->query("UPDATE $table set entry_date='" . time() . "', category='"
@@ -955,7 +953,7 @@
 
 			if($value_set)
 			{
-				$value_set	= ',' . $this->bocommon->validate_db_update($value_set);
+				$value_set	= ',' . $this->db->validate_update($value_set);
 			}
 
 			$this->db->query("UPDATE $table set entry_date=" . time() . "$value_set WHERE agreement_id=" . intval($values['r_agreement_id']) . ' AND id=' . intval($values['id']));
@@ -1091,10 +1089,10 @@
 			$vals[] = $this->db->db_addslashes($values['remark']);
 
 			$cols	= "," . implode(",", $cols);
-			$vals	= "," . $this->bocommon->validate_db_insert($vals);
+			$vals	= "," . $this->db->validate_insert($vals);
 
 			$this->db->transaction_begin();
-			$c_id = $this->bocommon->next_id($table,array('agreement_id'=>$values['r_agreement_id']));
+			$c_id = $this->db->next_id($table,array('agreement_id'=>$values['r_agreement_id']));
 
 			$this->db->query("INSERT INTO $table (id,agreement_id,entry_date,user_id $cols) "
 				. "VALUES ($c_id," . $values['r_agreement_id'] ."," . time()
@@ -1143,7 +1141,7 @@
 			$table = 'fm_r_agreement_c_history';
 
 			$this->db->transaction_begin();
-			$id = $this->bocommon->next_id($table,array('agreement_id'=>$values['r_agreement_id'],'c_id' =>$values['c_id']));
+			$id = $this->db->next_id($table,array('agreement_id'=>$values['r_agreement_id'],'c_id' =>$values['c_id']));
 
 			$this->db->query("SELECT from_date, to_date FROM $table WHERE agreement_id=" . $values['r_agreement_id'] . " AND c_id=" . $values['c_id'] . " AND id =" .($id-1),__LINE__,__FILE__);
 			$this->db->next_record();

Modified: people/sigurdne/modules/property/trunk/inc/class.sorequest.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sorequest.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sorequest.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -36,15 +36,13 @@
 	{
 		function property_sorequest()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->soproject	= CreateObject('property.soproject');
 			$this->historylog	= CreateObject('property.historylog','request');
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 			$this->interlink 	= CreateObject('property.interlink');
 		}
 
@@ -177,9 +175,9 @@
 				$cat_id			= isset($data['cat_id'])?$data['cat_id']:0;
 				$status_id		= isset($data['status_id']) && $data['status_id'] ? $data['status_id']:0;
 				$project_id		= isset($data['project_id'])?$data['project_id']:'';
-				$project_id		= isset($data['project_id'])?$data['project_id']:'';
 				$allrows		= isset($data['allrows'])?$data['allrows']:'';
 				$list_descr		= isset($data['list_descr'])?$data['list_descr']:'';
+				$dry_run		= isset($data['dry_run']) ? $data['dry_run'] : '';
 			}
 
 			$entity_table = 'fm_request';
@@ -256,7 +254,7 @@
 			$where = 'WHERE';
 			$filtermethod = '';
 
-			$GLOBALS['phpgw']->config->read_repository();
+			$GLOBALS['phpgw']->config->read();
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
 			{
 				$access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
@@ -301,9 +299,19 @@
 			$type_id		= $this->bocommon->type_id;
 			$this->cols_extra	= $this->bocommon->cols_extra;
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->fetchmode = 'ASSOC';
+			$sql2 = 'SELECT count(*) as cnt ' . substr($sql,strripos($sql,'from'));
+			$this->db->query($sql2,__LINE__,__FILE__);
+			$this->db->next_record();
+			$this->total_records = $this->db->f('cnt');
 
+			//[email protected] 23/10/08 avoid retrieve data in first time, only render definition for headers (var myColumnDefs)
+			if($dry_run)
+			{
+				return array();
+			}
+			else
+			{
 			if(!$allrows)
 			{
 				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@@ -312,13 +320,15 @@
 			{
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
+			}
 
 			$j=0;
+			$request_list = array();
 			while ($this->db->next_record())
 			{
 				for ($i=0;$i<count($cols_return);$i++)
 				{
-					$request_list[$j][$cols_return[$i]] = stripslashes($this->db->f($cols_return[$i]));
+					$request_list[$j][$cols_return[$i]] = $this->db->f($cols_return[$i], true);
 				}
 
 				$location_code=	$this->db->f('location_code');
@@ -337,34 +347,40 @@
 
 		function read_single($request_id)
 		{
-			$sql = "SELECT * from fm_request where id='$request_id'";
+			$request_id = (int) $request_id;
+			$sql = "SELECT * FROM fm_request WHERE id={$request_id}";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$request = array();
 			if ($this->db->next_record())
 			{
-				$request['request_id']			= $this->db->f('id');
-				$request['title']			= $this->db->f('title');
-				$request['location_code']		= $this->db->f('location_code');
-				$request['descr']			= $this->db->f('descr');
-				$request['status']			= $this->db->f('status');
-				$request['budget']			= (int)$this->db->f('budget');
-				$request['tenant_id']			= $this->db->f('tenant_id');
-				$request['owner']			= $this->db->f('owner');
-				$request['coordinator']			= $this->db->f('coordinator');
-				$request['access']			= $this->db->f('access');
-				$request['start_date']			= $this->db->f('start_date');
-				$request['end_date']			= $this->db->f('end_date');
-				$request['cat_id']			= $this->db->f('category');
-				$request['branch_id']			= $this->db->f('branch_id');
-				$request['authorities_demands']		= $this->db->f('authorities_demands');
-				$request['score']			= $this->db->f('score');
-				$request['p_num']			= $this->db->f('p_num');
-				$request['p_entity_id']			= $this->db->f('p_entity_id');
-				$request['p_cat_id']			= $this->db->f('p_cat_id');
-				$request['contact_phone']		= $this->db->f('contact_phone');
-
-				$request['power_meter']	= $this->soproject->get_power_meter($this->db->f('location_code'));
+				$request = array
+				(
+					'id'					=> $this->db->f('id'),
+					'request_id'			=> $this->db->f('id'), // FIXME
+					'title'					=> $this->db->f('title', true),
+					'location_code'			=> $this->db->f('location_code'),
+					'descr'					=> $this->db->f('descr', true),
+					'status'				=> $this->db->f('status'),
+					'budget'				=> (int)$this->db->f('budget'),
+					'tenant_id'				=> $this->db->f('tenant_id'),
+					'owner'					=> $this->db->f('owner'),
+					'coordinator'			=> $this->db->f('coordinator'),
+					'access'				=> $this->db->f('access'),
+					'start_date'			=> $this->db->f('start_date'),
+					'end_date'				=> $this->db->f('end_date'),
+					'cat_id'				=> $this->db->f('category'),
+					'branch_id'				=> $this->db->f('branch_id'),
+					'authorities_demands'	=> $this->db->f('authorities_demands'),
+					'score'					=> $this->db->f('score'),
+					'p_num'					=> $this->db->f('p_num'),
+					'p_entity_id'			=> $this->db->f('p_entity_id'),
+					'p_cat_id'				=> $this->db->f('p_cat_id'),
+					'contact_phone'			=> $this->db->f('contact_phone', true)
+				);
+				$location_code = $this->db->f('location_code');
+				$request['power_meter']		= $this->soproject->get_power_meter($location_code);
 			}
 
 			return $request;
@@ -372,6 +388,7 @@
 
 		function request_workorder_data($request_id = '')
 		{
+			$request_id = (int)$request_id;
 			$this->db->query("select budget, id as workorder_id, vendor_id from fm_workorder where request_id='$request_id'");
 			while ($this->db->next_record())
 			{
@@ -401,6 +418,7 @@
 		function add($request)
 		{
 //_debug_array($request);
+			$receipt = array();
 			while (is_array($request['location']) && list($input_name,$value) = each($request['location']))
 			{
 				if($value)
@@ -441,8 +459,10 @@
 			$request['name'] = $this->db->db_addslashes($request['name']);
 			$request['title'] = $this->db->db_addslashes($request['title']);
 
+			$this->db->transaction_begin();
+			$id = $this->next_id();
 			$values= array(
-				$request['request_id'],
+				$id,
 				$request['title'],
 				$this->account,
 				$request['cat_id'],
@@ -458,8 +478,6 @@
 
 			$values	= $this->bocommon->validate_db_insert($values);
 
-			$this->db->transaction_begin();
-
 			$this->db->query("insert into fm_request (id,title,owner,category,descr,location_code,"
 				. "address,entry_date,budget,status,branch_id,coordinator,"
 				. "authorities_demands  $cols) "
@@ -469,7 +487,7 @@
 			{
 				$this->db->query("INSERT INTO fm_request_condition (request_id,condition_type,degree,probability,consequence,user_id,entry_date) "
 					. "VALUES ('"
-					. $request['request_id']. "','"
+					. $id. "','"
 					. $condition_type . "',"
 					. $value_type['degree']. ","
 					. $value_type['probability']. ","
@@ -478,7 +496,7 @@
 					. time() . ")",__LINE__,__FILE__);
 			}
 
-			$this->update_score($request['request_id']);
+			$this->update_score($id);
 
 
 			if($request['extra']['contact_phone'] && $request['extra']['tenant_id'])
@@ -498,7 +516,7 @@
 					'location1_id'		=> $GLOBALS['phpgw']->locations->get_id('property', $request['origin'][0]['location']),
 					'location1_item_id' => $request['origin'][0]['data'][0]['id'],
 					'location2_id'		=> $GLOBALS['phpgw']->locations->get_id('property', '.project.request'),			
-					'location2_item_id' => $request['request_id'],
+					'location2_item_id' => $id,
 					'account_id'		=> $this->account
 				);
 					
@@ -508,35 +526,23 @@
 			if($this->db->transaction_commit())
 			{
 				$this->increment_request_id();
-				$this->historylog->add('SO',$request['request_id'],$request['status']);
-				$this->historylog->add('TO',$request['request_id'],$request['cat_id']);
-				$this->historylog->add('CO',$request['request_id'],$request['coordinator']);
-				$receipt['message'][] = array('msg'=>lang('request %1 has been saved',$request['request_id']));
+				$this->historylog->add('SO',$id,$request['status']);
+				$this->historylog->add('TO',$id,$request['cat_id']);
+				$this->historylog->add('CO',$id,$request['coordinator']);
+				$receipt['message'][] = array('msg'=>lang('request %1 has been saved',$id));
 			}
 			else
 			{
-				$receipt['error'][] = array('msg'=>lang('request %1 has not been saved',$request['request_id']));
+				$receipt['error'][] = array('msg'=>lang('request %1 has not been saved',$id));
 			}
+			$receipt['id'] = $id;
 			return $receipt;
 		}
 
 		function edit($request)
 		{
-			while (is_array($request['location']) && list($input_name,$value) = each($request['location']))
-			{
-				$vals[]	= "$input_name = '$value'";
-			}
+			$receipt = array();
 
-			while (is_array($request['extra']) && list($input_name,$value) = each($request['extra']))
-			{
-				$vals[]	= "$input_name = '$value'";
-			}
-
-			if($vals)
-			{
-				$vals	= "," . implode(",",$vals);
-			}
-
 			if($request['street_name'])
 			{
 				$address[]= $request['street_name'];
@@ -549,11 +555,9 @@
 				$address = $this->db->db_addslashes($request['location_name']);
 			}
 
-
 			$request['descr'] = $this->db->db_addslashes($request['descr']);
 			$request['name'] = $this->db->db_addslashes($request['name']);
 			$request['title'] = $this->db->db_addslashes($request['title']);
-//_debug_array($request);
 
 			$value_set=array(
 				'status'		=> $request['status'],
@@ -568,25 +572,35 @@
 				'authorities_demands' => $request['authorities_demands']
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			while (is_array($request['location']) && list($input_name,$value) = each($request['location']))
+			{
+				$value_set[$input_name] = $value;
+			}
 
+			while (is_array($request['extra']) && list($input_name,$value) = each($request['extra']))
+			{
+				$value_set[$input_name] = $value;
+			}
+
+			$value_set	= $this->db->validate_update($value_set);
+
 			$this->db->transaction_begin();
 
-			$this->db->query("SELECT status,category,coordinator FROM fm_request where id='" .$request['request_id']."'",__LINE__,__FILE__);
+			$this->db->query("SELECT status,category,coordinator FROM fm_request where id='" .$request['id']."'",__LINE__,__FILE__);
 			$this->db->next_record();
 
 			$old_status = $this->db->f('status');
 			$old_category = $this->db->f('category');
 			$old_coordinator = $this->db->f('coordinator');
 
-			$this->db->query("UPDATE fm_request set $value_set $vals WHERE id= '" . $request['request_id'] ."'",__LINE__,__FILE__);
+			$this->db->query("UPDATE fm_request set $value_set WHERE id= '" . $request['id'] ."'",__LINE__,__FILE__);
 
-			$this->db->query("DELETE FROM fm_request_condition WHERE request_id='" . $request['request_id'] . "'",__LINE__,__FILE__);
+			$this->db->query("DELETE FROM fm_request_condition WHERE request_id='" . $request['id'] . "'",__LINE__,__FILE__);
 			while (is_array($request['condition']) && list($condition_type,$value_type) = each($request['condition']))
 			{
 				$this->db->query("INSERT INTO fm_request_condition (request_id,condition_type,degree,probability,consequence,user_id,entry_date) "
 					. "VALUES ('"
-					. $request['request_id']. "','"
+					. $request['id']. "','"
 					. $condition_type . "',"
 					. $value_type['degree']. ","
 					. $value_type['probability']. ","
@@ -595,7 +609,7 @@
 					. time() . ")",__LINE__,__FILE__);
 			}
 
-			$this->update_score($request['request_id']);
+			$this->update_score($request['id']);
 
 			if($request['extra']['contact_phone'] && $request['extra']['tenant_id'])
 			{
@@ -611,25 +625,26 @@
 			{
 				if ($old_status != $request['status'])
 				{
-					$this->historylog->add('S',$request['request_id'],$request['status']);
+					$this->historylog->add('S',$request['id'],$request['status']);
 				}
 				if ($old_category != $request['cat_id'])
 				{
-					$this->historylog->add('T',$request['request_id'],$request['cat_id']);
+					$this->historylog->add('T',$request['id'],$request['cat_id']);
 				}
 				if ($old_coordinator != $request['coordinator'])
 				{
-					$this->historylog->add('C',$request['request_id'],$request['coordinator']);
+					$this->historylog->add('C',$request['id'],$request['coordinator']);
 				}
 
-				$receipt['message'][] = array('msg'=>lang('request %1 has been edited',$request['request_id']));
+				$receipt['message'][] = array('msg'=>lang('request %1 has been edited',$request['id']));
 			}
 			else
 			{
-				$receipt['message'][] = array('msg'=>lang('request %1 has not been edited',$request['request_id']));
+				$receipt['message'][] = array('msg'=>lang('request %1 has not been edited',$request['id']));
 			}
+
+			$receipt['id'] = $request['id'];
 			return $receipt;
-
 		}
 
 		function delete($request_id )

Modified: people/sigurdne/modules/property/trunk/inc/class.soresponsible.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soresponsible.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soresponsible.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -9,13 +9,13 @@
 	* @package phpgroupware
 	* @subpackage property
 	* @category core
- 	* @version $Id: class.uiresponsible.inc.php 732 2008-02-10 16:21:14Z sigurd $
+ 	* @version $Id: class.soresponsible.inc.php 3386 2009-08-20 13:29:37Z sigurd $
 	*/
 
 	/*
 	   This program 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 3 of the License, or
+	   the Free Software Foundation, either version 2 of the License, or
 	   (at your option) any later version.
 
 	   This program is distributed in the hope that it will be useful,
@@ -41,6 +41,7 @@
 		var $db;
 		var $account;
 		var $acl_location;
+		var $appname = 'property';
 
 		/**
 		* @var the total number of records for a search
@@ -86,7 +87,7 @@
 
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
+				$ordermethod = " order by fm_responsibility.$order $sort";
 			}
 			else
 			{
@@ -96,18 +97,26 @@
 			$where= 'WHERE';
 			$filtermethod = '';
 
+/*
 			if(is_array($filter) && $location)
 			{
 				$filtermethod .= " $where cat_id IN (" . implode(',', $filter) . ')';
 				$where = 'AND';
 			}
+*/
+			if($location)
+			{
+				$filtermethod .= " $where fm_responsibility.location_id =" . $GLOBALS['phpgw']->locations->get_id($this->appname, $location);
+				$where = 'AND';
+			}
+
 			$querymethod = '';
 			if($query)
 			{
-				$querymethod = "$where (name $this->like '%$query%' OR descr $this->like '%$query%')";
+				$querymethod = "$where (fm_responsibility.name $this->like '%$query%' OR fm_responsibility.descr $this->like '%$query%')";
 			}
 
-			$sql = "SELECT * FROM fm_responsibility $filtermethod $querymethod";
+			$sql = "SELECT fm_responsibility.*, phpgw_locations.name as location FROM fm_responsibility $this->join phpgw_locations ON fm_responsibility.location_id = phpgw_locations.location_id $filtermethod $querymethod";
 
 			$this->db->query($sql, __LINE__, __FILE__);
 			$this->total_records = $this->db->num_rows();
@@ -131,6 +140,7 @@
 					'name'			=> $this->db->f('name', true),
 					'descr'			=> $this->db->f('descr', true),
 					'active'		=> $this->db->f('active'),
+					'location'		=> $this->db->f('location'),
 					'cat_id'		=> $this->db->f('cat_id'),
 					'created_by'	=> $this->db->f('created_by'),
 					'created_on'	=> $this->db->f('created_on'),
@@ -158,6 +168,7 @@
 			(
 				$values['name'],
 				$values['descr'],
+				$GLOBALS['phpgw']->locations->get_id($this->appname, $values['location']),
 				(int) $values['cat_id'],
 				isset($values['active']) ? !!$values['active'] : '',
 				$this->account,
@@ -168,7 +179,7 @@
 
 			$this->db->transaction_begin();
 
-			$this->db->query("INSERT INTO fm_responsibility (name, descr, cat_id, active, created_by, created_on) "
+			$this->db->query("INSERT INTO fm_responsibility (name, descr,location_id, cat_id, active, created_by, created_on) "
 				. "VALUES ($insert_values)", __LINE__, __FILE__);
 
 			if($this->db->transaction_commit())
@@ -342,6 +353,7 @@
 					'p_num'				=> $this->db->f('p_num', true),
 					'p_entity_id'		=> $this->db->f('p_entity_id'),
 					'p_cat_id'			=> $this->db->f('p_cat_id'),
+					'ecodimb'			=> $this->db->f('ecodimb'),
 					'remark'			=> $this->db->f('remark', true),
 				);
 			}
@@ -367,12 +379,13 @@
 			(
 				(int) $values['responsibility_id'],
 				(int) $values['contact_id'],
-				implode('-', $values['location']),
+				@implode('-', $values['location']),
 				$values['active_from'],
 				$values['active_to'],
 				isset($values['extra']['p_num']) ? $values['extra']['p_num'] : '',
 				isset($values['extra']['p_entity_id']) ? $values['extra']['p_entity_id'] : '',
 				isset($values['extra']['p_cat_id']) ? $values['extra']['p_cat_id'] : '',
+				$values['ecodimb'],
 				$values['remark'],
 				$this->account,
 				time()
@@ -383,7 +396,7 @@
 			$this->db->transaction_begin();
 
 			$this->db->query("INSERT INTO fm_responsibility_contact (responsibility_id, contact_id,"
-				." location_code, active_from, active_to, p_num, p_entity_id, p_cat_id, remark, created_by, created_on)"
+				." location_code, active_from, active_to, p_num, p_entity_id, p_cat_id, ecodimb, remark, created_by, created_on)"
 				." VALUES ($insert_values)", __LINE__, __FILE__);
 
 			if($this->db->transaction_commit())
@@ -413,11 +426,12 @@
 
 			$orig = $this->read_single_contact($values['id']);
 
-			if(implode('-', $values['location']) != $orig['location_code']
+			if(isset($values['location']) &&(@implode('-', $values['location']) != $orig['location_code'])
 				|| $values['active_from'] != $orig['active_from']
 				|| $values['active_to'] != $orig['active_to']
 				|| $values['extra']['p_num'] != $orig['p_num']
-				|| $values['remark'] != $orig['remark'])
+				|| $values['remark'] != $orig['remark']
+				|| $values['ecodimb'] != $orig['ecodimb'])
 			{
 				$receipt = $this->add_contact($values);
 				
@@ -427,6 +441,7 @@
 
 					$value_set['expired_by']	= $this->account;
 					$value_set['expired_on']	= time();
+					$value_set['ecodimb']		= $values['ecodimb'];
 				}
 
 				$value_set	= $this->db->validate_update($value_set);
@@ -494,6 +509,7 @@
 				'expired_by'		=> $this->db->f('expired_by'),
 				'expired_on'		=> $this->db->f('expired_on'),
 				'priority'			=> $this->db->f('priority'), // FIXME - evaluate the need for this one
+				'ecodimb'			=> $this->db->f('ecodimb')
 			);
 
 			return $values;
@@ -525,45 +541,56 @@
 		{
 			$location_filter = array();
 
-			if(!isset($values['location']) || !is_array($values['location']))
+			$todo = false;
+			$item_filter = '';
+			
+			if(isset($values['ecodimb']) && $values['ecodimb'])
 			{
-				return 0;
+				$item_filter =   " AND ecodimb = '{$values['ecodimb']}'";
+				$location_filter[] = '';
+				$todo = true;
 			}
-			
-			$item_filter = '';
-			if(isset($values['extra']) && is_array($values['extra']))
+			elseif(isset($values['extra']['p_entity_id']) && $values['extra']['p_entity_id'])
 			{
 				$location_code = implode('-', $values['location']);
 
-				$item_filter =   " WHERE p_num = '{$values['extra']['p_num']}'"
+				$item_filter =   " AND p_num = '{$values['extra']['p_num']}'"
 								.' AND p_entity_id =' . (int) $values['extra']['p_entity_id']
 								.' AND p_cat_id =' . (int) $values['extra']['p_cat_id'];
 
 				$location_filter[] = " AND location_code = '{$location_code}'";
 				$ordermethod = '';
+				$todo = true;
 			}
-			else
+			else if(isset($values['location']) && $values['location'])
 			{
+				$location_filter[] = ''; // when the responsibility is generic - not located to any location
 				$location_code = '';
 				$location_array = array();
-				$where = ' WHERE';
 				foreach ($values['location'] as $location)
 				{
 					$location_array[]	= $location;
 					$location_code		= implode('-', $location_array);
-					$location_filter[]	= "{$where} location_code $this->like '$location_code%'";
-					$location_filter	= array_reverse($location_filter);
-					$where = ' AND';
+					$location_filter[]	= "AND location_code $this->like '$location_code%'";
 				}
 				
+				// Start at the bottom level
+				$location_filter	= array_reverse($location_filter);				
+
 				$ordermethod = ' ORDER by location_code.id ASC';
+				$todo = true;
 			}
 
+			if( !$todo )
+			{
+				return 0;
+			}
+
 			$sql = "SELECT contact_id FROM fm_responsibility_contact"
 			 . " $this->join fm_responsibility ON fm_responsibility_contact.responsibility_id = fm_responsibility.id"
-			 . " {$item_filter}"
-			 . ' AND cat_id =' . (int) $values['cat_id']
-			 . ' AND active = 1 AND active_from < ' . time() . ' AND active_to > ' . time() . ' AND expired_on IS NULL';
+			 . ' WHERE cat_id =' . (int) $values['cat_id']
+			 . ' AND active = 1 AND active_from < ' . time() . ' AND (active_to > ' . time() . ' OR active_to = 0) AND expired_on IS NULL'
+ 			 . " {$item_filter}";
 
 			foreach ($location_filter as $filter_at_location)
 			{
@@ -588,9 +615,32 @@
 
 		public function get_contact_user_id($person_id)
 		{
-			$sql = 'SELECT account_id FROM phpgw_accounts WHERE person_id =' . (int) $person_id;
+			$person_id = (int) $person_id;
+			$sql = "SELECT account_id FROM phpgw_accounts WHERE person_id ={$person_id} AND person_id > 0";
 			$this->db->query($sql, __LINE__, __FILE__);
 			$this->db->next_record();
 			return $this->db->f('account_id');
 		}
+
+		/**
+		* Get the user_id for a particular responsibility
+		*
+		* @param integer $person_id the ID of the given contact
+		*
+		* @return user_id
+		*/
+
+		public function get_responsible_user_id($responsibility_id)
+		{
+			$responsibility_id = (int)$responsibility_id;
+			$now = time();
+			$sql = "SELECT contact_id FROM fm_responsibility_contact"
+			 . " $this->join fm_responsibility ON fm_responsibility_contact.responsibility_id = fm_responsibility.id"
+			 . " AND active = 1 AND active_from < {$now} AND active_to > {$now} AND expired_on IS NULL";
+
+			$this->db->query($sql, __LINE__, __FILE__);
+			$this->db->next_record(); 
+			$contact_id = $this->db->f('contact_id');
+			return $this->get_contact_user_id($contact_id);
+		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.sos_agreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sos_agreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sos_agreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -27,6 +27,8 @@
  	* @version $Id$
 	*/
 
+	phpgw::import_class('phpgwapi.datetime');
+
 	/**
 	 * Description
 	 * @package property
@@ -35,18 +37,18 @@
 	class property_sos_agreement
 	{
 		var $role;
+		var $uicols = array();
 
-		function property_sos_agreement()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
+			$this->socommon		= CreateObject('property.socommon');
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->db2          = clone($this->db);
 
-			$this->join			= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like			= $this->bocommon->like;
+			$this->join			= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->like			= & $this->db->like;
 		}
 
 		function select_vendor_list()
@@ -565,11 +567,12 @@
 		{
 			$table = 'fm_s_agreement';
 
-			$this->db->query("SELECT * from $table where id='$s_agreement_id'");
+			$sql = "SELECT fm_s_agreement.* FROM $table WHERE id='$s_agreement_id'";
+			$this->db->query($sql);
 
 			if($this->db->next_record())
 			{
-				$values['id']				= (int)$this->db->f('id');
+				$values['id']				= $this->db->f('id');
 				$values['entry_date']		= $this->db->f('entry_date');
 				$values['cat_id']			= $this->db->f('category');
 				$values['member_of']		= explode(',',$this->db->f('member_of'));
@@ -590,7 +593,20 @@
 						$attr['value'] 	= $this->db->f($attr['column_name']);
 					}
 				}
+
+				$sql = "SELECT fm_s_agreement_budget.category as order_category, year, ecodimb,budget_account,budget"
+					. " FROM fm_s_agreement_budget WHERE agreement_id='$s_agreement_id' AND fm_s_agreement_budget.year =" . date('Y');
+				$this->db->query($sql);
+				$this->db->next_record();
+
+				$values['order_category']	= $this->db->f('order_category');
+				$values['year']				= $this->db->f('year');
+				$values['ecodimb']			= $this->db->f('ecodimb');
+				$values['b_account_id']		= $this->db->f('budget_account');
+				$values['budget']			= (int)$this->db->f('budget');
+				$values['year']				= $this->db->f('year');
 			}
+
 			return $values;
 		}
 
@@ -605,7 +621,7 @@
 
 			if($this->db->next_record())
 			{
-				$values['agreement_id']		= (int)$this->db->f('agreement_id');
+				$values['agreement_id']		= $this->db->f('agreement_id');
 				$values['id']				= (int)$this->db->f('id');
 				$values['entry_date']		= $this->db->f('entry_date');
 				$values['location_code']	= $this->db->f('location_code');
@@ -624,38 +640,38 @@
 			return $values;
 		}
 
-		function add($s_agreement,$values_attribute='')
+		function add($values,$values_attribute='')
 		{
-//_debug_array($s_agreement);
+//_debug_array($values);
 			$table = 'fm_s_agreement';
-			$s_agreement['name'] = $this->db->db_addslashes($s_agreement['name']);
-			$s_agreement['descr'] = $this->db->db_addslashes($s_agreement['descr']);
+			$values['name'] = $this->db->db_addslashes($values['name']);
+			$values['descr'] = $this->db->db_addslashes($values['descr']);
 
-			if($s_agreement['member_of'])
+			if($values['member_of'])
 			{
-				$s_agreement['member_of']=',' . implode(',',$s_agreement['member_of']) . ',';
+				$values['member_of']=',' . implode(',',$values['member_of']) . ',';
 			}
 
 
 			$this->db->transaction_begin();
-			$id = $this->bocommon->increment_id('workorder');
+			$id = $this->socommon->increment_id('workorder');
 
 			$vals[]	= $id;
-			$vals[]	= $s_agreement['name'];
-			$vals[]	= $s_agreement['descr'];
+			$vals[]	= $values['name'];
+			$vals[]	= $values['descr'];
 			$vals[]	= time();
-			$vals[]	= $s_agreement['cat_id'];
-			$vals[]	= $s_agreement['member_of'];
-			$vals[]	= $s_agreement['start_date'];
-			$vals[]	= $s_agreement['end_date'];
-			$vals[]	= $s_agreement['termination_date'];
-			$vals[]	= $s_agreement['vendor_id'];
-			$vals[]	= $s_agreement['b_account_id'];
+			$vals[]	= $values['cat_id'];
+			$vals[]	= $values['member_of'];
+			$vals[]	= $values['start_date'];
+			$vals[]	= $values['end_date'];
+			$vals[]	= $values['termination_date'];
+			$vals[]	= $values['vendor_id'];
+			$vals[]	= $values['b_account_id'];
 			$vals[]	= $this->account;
 
-			if(isset($s_agreement['extra']) && is_array($s_agreement['extra']))
+			if(isset($values['extra']) && is_array($values['extra']))
 			{
-				foreach ($s_agreement['extra'] as $input_name => $value)
+				foreach ($values['extra'] as $input_name => $value)
 				{
 					if(isset($value) && $value)
 					{
@@ -682,8 +698,23 @@
 				$cols	= "," . implode(",", $cols);
 			}
 
-			$vals	= $this->bocommon->validate_db_insert($vals);
+			$vals	= $this->db->validate_insert($vals);
 
+			if(isset($values['budget']) && $values['budget'])
+			{
+				$_budget = array
+				(
+					'agreement_id'		=> $values['s_agreement_id'],
+					'category'			=> $values['order_category'],
+					'year'				=> (int)$values['year'],
+					'ecodimb'			=> (int)$values['ecodimb'],
+					'budget_account'	=> $values['b_account_id'],
+					'budget'			=> $values['budget'],				
+				);
+
+				$this->update_budget($_budget);
+			}
+
 			$this->db->query("INSERT INTO $table (id,name,descr,entry_date,category,member_of,start_date,end_date,termination_date,vendor_id,account_id,user_id $cols) "
 				. "VALUES ($vals)",__LINE__,__FILE__);
 
@@ -768,12 +799,12 @@
 			if($cols)
 			{
 				$cols	= "," . implode(",", $cols);
-				$vals	= "," . $this->bocommon->validate_db_insert($vals);
+				$vals	= "," . $this->db->validate_insert($vals);
 			}
 
 			$this->db->transaction_begin();
 
-			$id = $this->bocommon->next_id($table,array('agreement_id'=>$values['s_agreement_id']));
+			$id = $this->db->next_id($table,array('agreement_id'=>$values['s_agreement_id']));
 
 			$this->db->query("INSERT INTO $table (id,agreement_id,entry_date,user_id $cols) "
 				. "VALUES ($id," . $values['s_agreement_id'] ."," . time()
@@ -811,12 +842,51 @@
 			return $receipt;
 		}
 
-		function edit($values,$values_attribute='')
+		function update_budget($data)
 		{
+			$sql = "SELECT * FROM fm_s_agreement_budget WHERE agreement_id = {$data['agreement_id']} AND year = {$data['year']}";
+			$this->db->query($sql,__LINE__,__FILE__);
+
+			if($this->db->next_record())
+			{
+				$old_category	= $this->db->f('category');
+				$old_ecodimb		= $this->db->f('ecodimb');
+				$old_budget_account	= $this->db->f('budget_account');
+				$old_budget			= $this->db->f('budget');
+				$sql = "UPDATE fm_s_agreement_budget SET"
+				 . " category = {$data['category']},"
+				 . " ecodimb = {$data['ecodimb']},"
+				 . " budget_account = '{$data['budget_account']}',"
+				 . " budget = {$data['budget']},"
+				 . ' modified_date=' . time()
+				 . " WHERE agreement_id = {$data['agreement_id']} AND year = {$data['year']}";
+				 				
+			}
+			else
+			{
+				$sql = "INSERT INTO fm_s_agreement_budget (agreement_id,year,category,ecodimb,budget_account,budget,user_id,entry_date) VALUES("
+				 . "{$data['agreement_id']},"
+				 . "{$data['year']},"
+				 . "{$data['category']},"
+				 . "{$data['ecodimb']},"
+				 . "'{$data['budget_account']}',"
+				 . "{$data['budget']},"
+				 . "{$this->account},"
+				 . time() . ')';
+			}
+
+			$this->db->query($sql,__LINE__,__FILE__);
+		
+		}
+
+		function edit($values,$values_attribute = array())
+		{
 //_debug_array($values);
 //_debug_array($values_attribute);
+
 			$table = 'fm_s_agreement';
 
+			$values['s_agreement_id'] = $this->db->db_addslashes($values['s_agreement_id']); // bigint
 			$values['name'] = $this->db->db_addslashes($values['name']);
 
 			if($values['member_of'])
@@ -854,14 +924,30 @@
 			$value_set['descr']	= $values['descr'];
 			if($value_set)
 			{
-				$value_set	= ',' . $this->bocommon->validate_db_update($value_set);
+				$value_set	= ',' . $this->db->validate_update($value_set);
 			}
 
+			$this->db->transaction_begin();
+			if(isset($values['budget']) && $values['budget'])
+			{
+				$_budget = array
+				(
+					'agreement_id'		=> $values['s_agreement_id'],
+					'category'			=> $values['order_category'],
+					'year'				=> (int)$values['year'],
+					'ecodimb'			=> (int)$values['ecodimb'],
+					'budget_account'	=> $values['b_account_id'],
+					'budget'			=> $values['budget'],				
+				);
+
+				$this->update_budget($_budget);
+			}
 			$this->db->query("UPDATE $table set entry_date='" . time() . "', category='"
-							. $values['cat_id'] . "', member_of='" . $values['member_of'] . "', start_date=" . intval($values['start_date']) . ", end_date=" . intval($values['end_date']) . ", termination_date=" . intval($values['termination_date']) . ", account_id=" . intval($values['b_account_id']) . "$value_set WHERE id=" . intval($values['s_agreement_id']));
+							. $values['cat_id'] . "', member_of='" . $values['member_of'] . "', start_date=" . intval($values['start_date']) . ", end_date=" . intval($values['end_date']) . ", termination_date=" . intval($values['termination_date']) . ", account_id=" . intval($values['b_account_id']) . "$value_set WHERE id='{$values['s_agreement_id']}'");
 
-			$this->db->query("UPDATE fm_s_agreement_pricing set index_date=" . intval($values['start_date']) . " WHERE id=1 AND agreement_id= " . intval($values['s_agreement_id']));
+			$this->db->query("UPDATE fm_s_agreement_pricing set index_date=" . intval($values['start_date']) . " WHERE id=1 AND agreement_id= '{$values['s_agreement_id']}'");
 
+			$this->db->transaction_commit();
 			$receipt['s_agreement_id']= $values['s_agreement_id'];
 			$receipt['message'][] = array('msg'=>lang('s_agreement %1 has been edited',$values['s_agreement_id']));
 			return $receipt;
@@ -902,7 +988,7 @@
 						if($entry['value'] != $old_value)
 						{
 							$history_set[$entry['attrib_id']] = array('value' => $entry['value'],
-												'date'  => $this->bocommon->date_to_timestamp($entry['date']));
+												'date'  => phpgwapi_datetime::date_to_timestamp($entry['date']));
 						}
 					}
 				}
@@ -926,12 +1012,12 @@
 
 			if($value_set)
 			{
-				$value_set	= ',' . $this->bocommon->validate_db_update($value_set);
+				$value_set	= ',' . $this->db->validate_update($value_set);
 			}
 
-			$this->db->query("UPDATE $table set entry_date=" . time() . "$value_set WHERE agreement_id=" . intval($values['s_agreement_id']) . ' AND id=' . intval($values['id']));
+			$this->db->query("UPDATE $table set entry_date=" . time() . "$value_set WHERE agreement_id=" . ($values['s_agreement_id']) . ' AND id=' . intval($values['id']));
 
-			$this->db->query("UPDATE fm_s_agreement_pricing set cost = this_index *" . $this->floatval($values['cost']) . " WHERE agreement_id=" . intval($values['s_agreement_id']) . ' AND item_id=' . intval($values['id']));
+			$this->db->query("UPDATE fm_s_agreement_pricing set cost = this_index *" . $this->floatval($values['cost']) . " WHERE agreement_id=" . $values['s_agreement_id'] . ' AND item_id=' . intval($values['id']));
 
 			if (isset($history_set) AND is_array($history_set))
 			{
@@ -952,19 +1038,18 @@
 
 		function update($values)
 		{
-//_debug_array($values);
 			$values['new_index']=$this->floatval($values['new_index']);
 			$this->db->transaction_begin();
 
-			while (is_array($values['select']) && list($item_id,$value) = each($values['select']))
+			if(isset($values['select']) && is_array($values['select']))
 			{
-
-				$this->db->query("UPDATE fm_s_agreement_pricing set current_index = NULL WHERE agreement_id=" . intval($values['agreement_id']) . ' AND item_id=' . intval($item_id));
-
+				foreach ($values['select'] as $item_id => $value)
+				{
+					$this->db->query("UPDATE fm_s_agreement_pricing SET current_index = NULL WHERE agreement_id=" . $values['agreement_id'] . ' AND item_id=' . (int)$item_id);
 				$this->db->query("INSERT INTO fm_s_agreement_pricing (agreement_id,item_id,id,current_index,this_index,cost,index_date,entry_date,user_id)"
 					. "VALUES (" . $values['agreement_id'] . "," . $item_id ."," . ($values['id'][$item_id]+1) .",1,'" . $values['new_index'] . "','" . ($value * $values['new_index'])  . "'," . (int)$values['date'] . "," . time()
 					. "," . $this->account . ")");
-
+				}
 			}
 
 			$this->db->transaction_commit();
@@ -1013,10 +1098,10 @@
 		{
 			$table = 'fm_s_agreement';
 			$this->db->transaction_begin();
-			$this->db->query("DELETE FROM $table WHERE id=" . intval($s_agreement_id));
-			$this->db->query("DELETE FROM fm_s_agreement_detail WHERE agreement_id=" . intval($s_agreement_id));
-			$this->db->query("DELETE FROM fm_s_agreement_pricing WHERE agreement_id=" . intval($s_agreement_id));
-			$this->db->query("DELETE FROM fm_orders WHERE id=" . intval($s_agreement_id));
+			$this->db->query("DELETE FROM $table WHERE id=" . $s_agreement_id);
+			$this->db->query("DELETE FROM fm_s_agreement_detail WHERE agreement_id=" . $s_agreement_id);
+			$this->db->query("DELETE FROM fm_s_agreement_pricing WHERE agreement_id=" . $s_agreement_id);
+			$this->db->query("DELETE FROM fm_orders WHERE id=" . $s_agreement_id);
 			$this->db->transaction_commit();
 		}
 
@@ -1040,5 +1125,50 @@
 			$next_id= $this->db->f('id')+1;
 			return $next_id;
 		}
+
+		function get_year_filter_list($agreement_id = 0)
+		{
+			$table = 'fm_s_agreement_budget';
+			$sql = "SELECT year FROM $table WHERE agreement_id = {$agreement_id} group by year ORDER BY year ASC";
+			$this->db->query($sql,__LINE__,__FILE__);
+
+			$values = array();
+
+			while ($this->db->next_record())
+			{
+				$values[]	= $this->db->f('year');
 	}
 
+			return $values;
+		}
+
+		function get_budget($agreement_id = 0)
+		{
+			$values = array();
+
+			$sql = "SELECT * FROM fm_s_agreement_budget WHERE agreement_id = {$agreement_id} ORDER BY year ASC";
+			$this->db->query($sql,__LINE__,__FILE__);
+
+			while($this->db->next_record())
+			{
+				$values[] = array
+				(
+					'agreement_id'		=> $agreement_id,
+					'year'				=> $this->db->f('year'),
+					'cat_id'			=> $this->db->f('category'),
+					'ecodimb'			=> $this->db->f('ecodimb'),
+					'budget_account'	=> $this->db->f('budget_account'),
+					'budget'			=> $this->db->f('budget'),
+					'actual_cost'		=> $this->db->f('actual_cost')
+				);
+			}
+			
+			return $values;
+		}
+
+		function delete_year_from_budget($data,$agreement_id)
+		{
+			$sql = "DELETE FROM fm_s_agreement_budget WHERE agreement_id = {$agreement_id} AND year IN(" . implode(',', $data) . ')';
+			$this->db->query($sql,__LINE__,__FILE__);
+		}
+	}

Modified: people/sigurdne/modules/property/trunk/inc/class.sostandard_2.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sostandard_2.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sostandard_2.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,77 +35,67 @@
 	class property_sostandard_2
 	{
 
-		function property_sostandard_2()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-
-			$this->join		= $this->bocommon->join;
-			$this->like		= $this->bocommon->like;
+			$this->_db 			= & $GLOBALS['phpgw']->db;
+			$this->_like		= & $this->_db->like;
 		}
 
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				if ($data['start'])
-				{
-					$start=$data['start'];
+				$start		= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$query		= isset($data['query']) ? $data['query'] : '';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order		= isset($data['order']) ? $data['order'] : '';
+				$type		= isset($data['type']) ? $data['type'] : '';
+				$allrows	= isset($data['allrows']) ? $data['allrows'] : '';
 				}
-				else
+
+			$standard = array();
+			if (!$table = $this->select_table($type))
 				{
-					$start=0;
-				}
-				$query		= (isset($data['query'])?$data['query']:'');
-				$sort		= (isset($data['sort'])?$data['sort']:'DESC');
-				$order		= (isset($data['order'])?$data['order']:'');
-				$type		= (isset($data['type'])?$data['type']:0);
-				$allrows	= (isset($data['allrows'])?$data['allrows']:'');
+				return $standard;
 			}
 
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
-
+				$ordermethod = " ORDER BY $order $sort";
 			}
 			else
 			{
-				$ordermethod = ' order by id asc';
+				$ordermethod = ' ORDER BY id ASC';
 			}
 
-			$table = $this->select_table($type);
-
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
+				$query = $this->_db->db_addslashes($query);
 
-				$querymethod = " where id $this->like '%$query%' or descr $this->like '%$query%'";
+				$querymethod = " WHERE id $this->_like '%$query%' OR descr $this->_like '%$query%'";
 			}
 
 			$sql = "SELECT * FROM $table $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->_db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->_db->num_rows();
 
 			if(!$allrows)
 			{
-				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+				$this->_db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
 			}
 			else
 			{
-				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
+				$this->_db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
-			while ($this->db->next_record())
+			while ($this->_db->next_record())
 			{
 				$standard[] = array
 				(
-					'id'	=> $this->db->f('id'),
-					'descr'	=> $this->db->f('descr')
+					'id'	=> $this->_db->f('id'),
+					'descr'	=> $this->_db->f('descr')
 				);
 			}
 			return $standard;
@@ -143,61 +133,82 @@
 
 		function read_single($id,$type)
 		{
+			$standard = array();
 
-			$table = $this->select_table($type);
+			if (!$table = $this->select_table($type))
+			{
+				return $standard;
+			}
 
-			$sql = "SELECT * FROM $table  where id='$id'";
+			$sql = "SELECT * FROM $table WHERE id='{$id}'";
 
-			$this->db->query($sql,__LINE__,__FILE__);
+			$this->_db->query($sql,__LINE__,__FILE__);
 
-			if ($this->db->next_record())
+			if ($this->_db->next_record())
 			{
-				$standard['id']			= $this->db->f('id');
-				$standard['descr']		= $this->db->f('descr');
-
-				return $standard;
+				$standard = array
+				(
+					'id'		=> $this->_db->f('id'),
+					'descr'		=> $this->_db->f('descr', true)
+				);
 			}
+			return $standard;
 		}
 
 		function add($standard,$type)
 		{
-			$table = $this->select_table($type);
+			$receipt = array();
+			if (!$table = $this->select_table($type))
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
 
-			$standard['descr'] = $this->db->db_addslashes($standard['descr']);
+			$standard['descr'] = $this->_db->db_addslashes($standard['descr']);
 
-			$this->db->transaction_begin();
+			$this->_db->transaction_begin();
 
-			$this->db->query("INSERT INTO $table (id, descr) "
+			$this->_db->query("INSERT INTO $table (id, descr) "
 				. "VALUES ('" . $standard['id'] . "','" . $standard['descr']. "')",__LINE__,__FILE__);
 
-			$this->db->transaction_commit();
+			$this->_db->transaction_commit();
 			$receipt['message'][] = array('msg' => lang('standard has been saved'));
 			return $receipt;
 		}
 
 		function edit($standard,$type)
 		{
+			$receipt = array();
+			if (!$table = $this->select_table($type))
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
 
-			$table = $this->select_table($type);
+			$standard['descr'] = $this->_db->db_addslashes($standard['descr']);
 
-			$standard['descr'] = $this->db->db_addslashes($standard['descr']);
+			$this->_db->transaction_begin();
 
-			$this->db->transaction_begin();
-
-			$this->db->query("UPDATE $table set descr='" . $standard['descr']
+			$this->_db->query("UPDATE $table set descr='" . $standard['descr']
 							. "' WHERE id='" . $standard['id']. "'",__LINE__,__FILE__);
 
-			$this->db->transaction_commit();
+			$this->_db->transaction_commit();
 			$receipt['message'][] = array('msg' => lang('standard has been edited'));
 			return $receipt;
 		}
 
 		function delete($id,$type)
 		{
-			$table = $this->select_table($type);
-			$this->db->transaction_begin();
-			$this->db->query("DELETE FROM $table WHERE id=" . (int)$id,__LINE__,__FILE__);
-			$this->db->transaction_commit();
+			$receipt = array();
+			if (!$table = $this->select_table($type))
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
+
+			$this->_db->transaction_begin();
+			$this->_db->query("DELETE FROM $table WHERE id='{$id}'",__LINE__,__FILE__);
+			$this->_db->transaction_commit();
 		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.sostandard_3.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sostandard_3.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sostandard_3.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,71 +34,63 @@
 
 	class property_sostandard_3
 	{
-
-		function property_sostandard_3()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
 			$this->socommon		= CreateObject('property.socommon');
+			$this->_db 			= & $GLOBALS['phpgw']->db;
 
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->_join		= & $this->_db->join;
+			$this->_like		= & $this->_db->like;
 		}
 
 		function read($data)
 		{
 			if(is_array($data))
 			{
-				if ($data['start'])
-				{
-					$start=$data['start'];
+				$start		= isset($data['start']) && $data['start'] ? $data['start']:0;
+				$query		= isset($data['query'])?$data['query']:'';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
+				$order		= isset($data['order'])?$data['order']:'';
+				$type		= isset($data['type']) ?$data['type']: '';
 				}
-				else
+
+			$standard = array();
+			if (!$table = $this->select_table($type))
 				{
-					$start=0;
-				}
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$type = (isset($data['type'])?$data['type']:0);
+				return $standard;
 			}
 
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
-
 			}
 			else
 			{
 				$ordermethod = ' order by id asc';
 			}
 
-			$table = $this->select_table($type);
-
 			if($query)
 			{
-				$query = preg_replace("/'/",'',$query);
-				$query = preg_replace('/"/','',$query);
-
-				$querymethod = " where id $this->like '%$query%' or descr $this->like '%$query%'";
+				$query = $this->_db->db_addslashes($query);
+				// FIXME: change fm_async_method.name to fm_async_method.num
+				//$querymethod = " WHERE num $this->_like '%$query%' or descr $this->_like '%$query%'";
+				$querymethod = " WHERE descr $this->_like '%$query%'";
 			}
 
 			$sql = "SELECT * FROM $table $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
-			$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
+			$this->_db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->_db->num_rows();
+			$this->_db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
 
-			while ($this->db->next_record())
+			while ($this->_db->next_record())
 			{
 				$standard[] = array
 				(
-					'id'	=> $this->db->f('id'),
-					'num'	=> $this->db->f('num'),
-					'descr'	=> $this->db->f('descr')
+					'id'	=> $this->_db->f('id'),
+					'num'	=> $this->_db->f('num', true),
+					'descr'	=> $this->_db->f('descr',true)
 				);
 			}
 			return $standard;
@@ -106,6 +98,7 @@
 
 		function select_table($type)
 		{
+			$table = '';
 			switch($type)
 			{
 				case 'branch':
@@ -121,38 +114,50 @@
 			return $table;
 		}
 
-		function read_single($id,$type)
+		function read_single($id, $type)
 		{
+			$id = (int) $id;
+			$standard = array();
 
-			$table = $this->select_table($type);
+			if (!$table = $this->select_table($type))
+			{
+				return $standard;
+			}
 
-			$sql = "SELECT * FROM $table  where id='$id'";
+			$sql = "SELECT * FROM $table WHERE id={$id}";
 
-			$this->db->query($sql,__LINE__,__FILE__);
+			$this->_db->query($sql,__LINE__,__FILE__);
 
-			if ($this->db->next_record())
+			if ($this->_db->next_record())
 			{
-				$standard['id']			= $this->db->f('id');
-				$standard['num']		= $this->db->f('num');
-				$standard['descr']		= $this->db->f('descr');
-
-				return $standard;
+				$standard = array
+				(
+					'id'		=> $this->_db->f('id'),
+					'num'		=> $this->_db->f('num', true),
+					'descr'		=> $this->_db->f('descr', true)
+				);
 			}
+			return $standard;
 		}
 
 		function add($standard,$type)
 		{
-			$table = $this->select_table($type);
+			$receipt = array();
+			if (!$table = $this->select_table($type))
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
 
+			$standard['num'] = $this->_db->db_addslashes($standard['num']);
+			$standard['descr'] = $this->_db->db_addslashes($standard['descr']);
+
+			$this->_db->transaction_begin();
 			$standard['id'] = $this->socommon->next_id($table);
-			$standard['num'] = $this->db->db_addslashes($standard['num']);
-			$standard['descr'] = $this->db->db_addslashes($standard['descr']);
-
-			$this->db->transaction_begin();
-			$this->db->query("INSERT INTO $table (id, num, descr) "
+			$this->_db->query("INSERT INTO $table (id, num, descr) "
 				. "VALUES ('" . $standard['id'] . "','" . $standard['num'] . "','" . $standard['descr']. "')",__LINE__,__FILE__);
 
-			$this->db->transaction_commit();
+			$this->_db->transaction_commit();
 			$receipt['id'] = $standard['id'];
 			$receipt['message'][] = array('msg' => lang('standard has been saved'));
 
@@ -161,16 +166,21 @@
 
 		function edit($standard,$type)
 		{
-			$table = $this->select_table($type);
+			$receipt = array();
+			if (!$table = $this->select_table($type))
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
 
-			$standard['num'] = $this->db->db_addslashes($standard['num']);
-			$standard['descr'] = $this->db->db_addslashes($standard['descr']);
+			$standard['num'] = $this->_db->db_addslashes($standard['num']);
+			$standard['descr'] = $this->_db->db_addslashes($standard['descr']);
 
-			$this->db->transaction_begin();
-			$this->db->query("UPDATE $table set descr='" . $standard['descr'] . "', num='". $standard['num']
+			$this->_db->transaction_begin();
+			$this->_db->query("UPDATE $table set descr='" . $standard['descr'] . "', num='". $standard['num']
 							. "' WHERE id='" . $standard['id']. "'",__LINE__,__FILE__);
 
-			$this->db->transaction_commit();
+			$this->_db->transaction_commit();
 
 			$receipt['id'] = $standard['id'];
 			$receipt['message'][] = array('msg' =>lang('standard has been edited'));
@@ -179,10 +189,16 @@
 
 		function delete($id,$type)
 		{
-			$table = $this->select_table($type);
-			$this->db->transaction_begin();
-			$this->db->query("DELETE FROM $table WHERE id=" . (int)$id ,__LINE__,__FILE__);
-			$this->db->transaction_commit();
+			$receipt = array();
+			if (!$table = $this->select_table($type))
+			{
+				$receipt['error'][] = array('msg' => lang('not a valid type'));
+				return $receipt;
+			}
+
+			$this->_db->transaction_begin();
+			$this->_db->query("DELETE FROM $table WHERE id=" . (int)$id ,__LINE__,__FILE__);
+			$this->_db->transaction_commit();
 		}
 	}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.sotemplate.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sotemplate.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sotemplate.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -39,8 +39,7 @@
 		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
+			$this->db           = & $GLOBALS['phpgw']->db;
 
 			$this->join			= $this->bocommon->join;
 			$this->left_join	= $this->bocommon->left_join;
@@ -92,15 +91,15 @@
 				$query = preg_replace("/'/",'',$query);
 				$query = preg_replace('/"/','',$query);
 
-				$querymethod = " $where (fm_template.descr $this->like '%$query%')";
+				$querymethod = " $where (fm_template.name $this->like '%$query%' OR fm_template.descr $this->like '%$query%')";
 			}
 
 			$sql = "SELECT fm_template.id,fm_template.descr,fm_template.name,fm_template.owner,fm_template.entry_date,"
 			 . " fm_chapter.descr as chapter FROM fm_template $this->left_join fm_chapter  on fm_template.chapter_id=fm_chapter.id"
 			 . " $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{
@@ -170,8 +169,8 @@
 
 			$sql = "SELECT fm_template_hours.*, chapter_id from fm_template_hours  $this->join fm_template on fm_template.id=fm_template_hours.template_id $filtermethod $querymethod";
 
-			$this->db2->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db2->num_rows();
+			$this->db->query($sql,__LINE__,__FILE__);
+			$this->total_records = $this->db->num_rows();
 
 			if(!$allrows)
 			{

Modified: people/sigurdne/modules/property/trunk/inc/class.sotenant_claim.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sotenant_claim.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sotenant_claim.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -37,11 +37,9 @@
 		function property_sotenant_claim()
 		{
 			$this->account	= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
+			$this->db           = & $GLOBALS['phpgw']->db;
+			$this->join			= & $this->db->join;
+			$this->like			= & $this->db->like;
 			$this->interlink 	= CreateObject('property.interlink');
 		}
 
@@ -49,20 +47,29 @@
 		{
 			if(is_array($data))
 			{
-				$start	= (isset($data['start'])?$data['start']:0);
-				$filter	= (isset($data['filter'])?$data['filter']:'none');
-				$status	= (isset($data['status'])?$data['status']:'open');
-				$query = (isset($data['query'])?$data['query']:'');
-				$sort = (isset($data['sort'])?$data['sort']:'DESC');
-				$order = (isset($data['order'])?$data['order']:'');
-				$cat_id = (isset($data['cat_id'])?$data['cat_id']:0);
-				$allrows 	= (isset($data['allrows'])?$data['allrows']:'');
-				$project_id 	= (isset($data['project_id'])?$data['project_id']:'');
+				$start		= isset($data['start']) && $data['start'] ? $data['start'] : 0;
+				$filter		= isset($data['filter']) && $data['filter'] ? $data['filter'] : 'none';
+				$status		= isset($data['status']) && $data['status'] ? $data['status'] : 'open';
+				$query		= isset($data['query']) ? $data['query'] : '';
+				$sort		= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
+				$order		= isset($data['order']) ? $data['order'] : '';
+				$cat_id		= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id'] : 0;
+				$allrows	= isset($data['allrows']) ? $data['allrows'] : '';
+				$project_id	= isset($data['project_id']) ? $data['project_id'] : '';
 
 			}
 
 			if ($order)
 			{
+				switch($order)
+				{
+					case 'claim_id':
+						$order = 'fm_tenant_claim.id';
+						break;
+					case 'name':
+						$order = 'last_name';
+						break;
+				}
 				$ordermethod = " order by $order $sort";
 			}
 			else
@@ -84,17 +91,11 @@
 				$where = 'AND';
 			}
 
-			if ($status == 'closed'):
+			if ($status && $status != 'all')
 			{
-				$filtermethod .= " $where fm_tenant_claim.status='closed'";
+				$filtermethod .= " $where fm_tenant_claim.status='{$status}'";
 				$where = 'AND';
 			}
-			elseif($status == ''):
-			{
-				$filtermethod .= " $where fm_tenant_claim.status='open'";
-				$where = 'AND';
-			}
-			endif;
 
 			if($query)
 			{
@@ -103,7 +104,7 @@
 				$querymethod = " $where ( first_name $this->like '%$query%' OR last_name $this->like '%$query%')";
 			}
 
-			$sql = "SELECT fm_tenant_claim.*, descr as category FROM fm_tenant_claim "
+			$sql = "SELECT fm_tenant_claim.*, descr as category, fm_tenant.last_name, fm_tenant.first_name FROM fm_tenant_claim "
 			 . " $this->join fm_tenant_claim_category on fm_tenant_claim.category=fm_tenant_claim_category.id"
 			 . " $this->join fm_tenant ON fm_tenant_claim.tenant_id = fm_tenant.id"
 			 . " $filtermethod $querymethod";
@@ -120,6 +121,7 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
+			$claims = array();
 			while ($this->db->next_record())
 			{
 				$claims[] = array
@@ -127,6 +129,7 @@
 					'claim_id'		=> $this->db->f('id'),
 					'project_id'	=> $this->db->f('project_id'),
 					'tenant_id'		=> $this->db->f('tenant_id'),
+					'name'			=> $this->db->f('last_name') . ', ' . $this->db->f('first_name'),
 					'remark'		=> $this->db->f('remark',true),
 					'entry_date'	=> $this->db->f('entry_date'),
 					'category'		=> $this->db->f('category'),
@@ -220,7 +223,7 @@
 				$claim['status']
 				);
 
-			$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+			$values_insert	= $this->db->validate_insert($values_insert);
 
 
 			$this->db->query("INSERT INTO fm_tenant_claim (project_id,tenant_id,amount,b_account_id,category,remark,user_id,entry_date,status) "
@@ -269,7 +272,7 @@
 				'remark'			=> $this->db->db_addslashes($claim['remark'])
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->query("UPDATE fm_tenant_claim set $value_set  WHERE id=" . (int)$claim['claim_id'],__LINE__,__FILE__);
 

Modified: people/sigurdne/modules/property/trunk/inc/class.sotts.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sotts.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sotts.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -27,6 +27,8 @@
  	* @version $Id$
 	*/
 
+	phpgw::import_class('phpgwapi.datetime');
+
 	/**
 	 * Description
 	 * @package property
@@ -34,16 +36,21 @@
 
 	class property_sotts
 	{
-		function property_sotts()
+		var $uicols_related = array();
+		var $acl_location = '.ticket';
+
+		var $soap_enabled = array
+		(
+			'read'	=> true
+		);
+
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->historylog	= CreateObject('property.historylog','tts');
-			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           = $this->bocommon->new_db();
-			$this->join			= $this->bocommon->join;
-			$this->like			= $this->bocommon->like;
-			$this->soadmin_entity	= CreateObject('property.soadmin_entity');
+			$this->db 			= & $GLOBALS['phpgw']->db;
+			$this->like 		= & $this->db->like;
+			$this->join 		= & $this->db->join;
 			$this->dateformat 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
 		}
 
@@ -56,11 +63,10 @@
 
 		function read($data)
 		{
-			if(is_array($data))
-			{
 				$start			= isset($data['start']) && $data['start'] ? $data['start']:0;
-				$filter			= isset($data['filter']) && $data['filter'] ? $data['filter']:'O'; //O='Open'
-				$user_filter	= isset($data['user_filter'])?$data['user_filter']:'';
+			$status_id		= isset($data['status_id']) && $data['status_id'] ? $data['status_id']:'O'; //O='Open'
+			$user_id		= isset($data['user_id'])?$data['user_id']:'';
+			$owner_id		= isset($data['owner_id'])?$data['owner_id']:'';
 				$query			= isset($data['query'])?$data['query']:'';
 				$sort			= isset($data['sort']) && $data['sort'] ? $data['sort']:'DESC';
 				$order			= isset($data['order'])?$data['order']:'';
@@ -70,35 +76,53 @@
 				$start_date		= isset($data['start_date'])?$data['start_date']:'';
 				$end_date		= isset($data['end_date'])?$data['end_date']:'';
 				$external		= isset($data['external'])?$data['external']:'';
-			}
+			$dry_run		= isset($data['dry_run']) ? $data['dry_run'] : '';
 
 			$this->grants 	= $GLOBALS['phpgw']->session->appsession('grants_ticket','property');
 
 			if(!$this->grants)
 			{
-				$this->grants	= $GLOBALS['phpgw']->acl->get_grants('property','.ticket');
+//				$this->grants	= $GLOBALS['phpgw']->acl->get_grants('property','.ticket');
 				$GLOBALS['phpgw']->session->appsession('grants_ticket','property',$this->grants);
 			}
 
 			if ($order)
 			{
-				$ordermethod = " order by $order $sort";
+				if( $order == 'assignedto' )
+				{
+					$order_join = "$this->join phpgw_accounts ON fm_tts_tickets.assignedto=phpgw_accounts.account_id";
+					$order = 'account_lastname';
+				}
+				else if( $order == 'user' )
+				{
+					$order_join = "$this->join phpgw_accounts ON fm_tts_tickets.user_id=phpgw_accounts.account_id";
+					$order = 'account_lastname';
+				}
+				else
+				{
+					$order_join = '';
+				}
+				
+				$ordermethod = " ORDER BY $order $sort";
 			}
 			else
 			{
-				$ordermethod = ' order by fm_tts_tickets.id DESC';
+				$ordermethod = ' ORDER BY fm_tts_tickets.id DESC';
 			}
 
 			$where= 'WHERE';
 
 			$filtermethod = '';
-			$GLOBALS['phpgw']->config->read_repository();
+			$GLOBALS['phpgw']->config->read();
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
 			{
-				$access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
+				$access_location = execMethod('property.socommon.get_location_list', PHPGW_ACL_READ);
+				if($access_location)
+				{
 				$filtermethod = " WHERE fm_tts_tickets.loc1 in ('" . implode("','", $access_location) . "')";
 				$where= 'AND';
 			}
+			}
 
 			if (is_array($this->grants))
 			{
@@ -115,25 +139,53 @@
 			if($tenant_id = $GLOBALS['phpgw']->session->appsession('tenant_id','property'))
 			{
 				$filtermethod .= $where . ' fm_tts_tickets.tenant_id=' . $tenant_id;
+				$where = 'AND';
 			}
 
-			if ($filter == 'X')
+			if ($status_id == 'X')
 			{
 				$filtermethod .= " $where fm_tts_tickets.status='X'";
 				$where = 'AND';
 			}
-			else if($filter == 'O')
+			else if($status_id == 'O')
 			{
-				$filtermethod .= " $where (fm_tts_tickets.status='O' OR fm_tts_tickets.status $this->like 'C%')";
+				$open = '';
+				$this->db->query('SELECT * from fm_tts_status',__LINE__,__FILE__);
+
+				while ($this->db->next_record())
+			{
+					if( ! $this->db->f('closed'))
+					{
+						$open .= " OR fm_tts_tickets.status = 'C" . $this->db->f('id') . "'";
+					}
+				}
+
+				$filtermethod .= " $where (fm_tts_tickets.status='O'{$open})";
 				$where = 'AND';
 			}
-			else if($filter == 'all')
+			else if($status_id == 'all')
 			{
 				//nothing
 			}
+			else if(is_array($status_id) && count($status_id))
+			{
+				$or = '';
+				$filtermethod .= "{$where} (";
+				
+				foreach ($status_id as $value)
+				{
+					$value = trim($value,'C');
+					$filtermethod .= "{$or} fm_tts_tickets.status = '{$value}'";					
+					$or = ' OR';
+				}
+
+				$filtermethod .= ')';
+
+				$where = 'AND';
+			}
 			else
 			{
-				$filtermethod .= " $where fm_tts_tickets.status='{$filter}'";
+				$filtermethod .= " $where fm_tts_tickets.status='{$status_id}'";
 				$where = 'AND';
 			}
 
@@ -143,15 +195,21 @@
 				$where = 'AND';
 			}
 
-			if ($user_filter > 0)
+			if ($user_id > 0)
 			{
-				$filtermethod .= " $where assignedto=$user_filter";
+				$filtermethod .= " $where assignedto=" . (int)$user_id;
 				$where = 'AND';
 			}
 
+			if ($owner_id > 0)
+			{
+				$filtermethod .= " $where fm_tts_tickets.user_id=" . (int)$owner_id;
+				$where = 'AND';
+			}
+
 			if ($district_id > 0)
 			{
-				$filtermethod .= " $where  district_id='$district_id' ";
+				$filtermethod .= " $where  district_id=" .(int)$district_id;
 				$where = 'AND';
 			}
 
@@ -177,14 +235,18 @@
 				}
 			}
 
-			$sql = "SELECT fm_tts_tickets.* FROM fm_tts_tickets"
-			. " $this->join fm_location1 on fm_tts_tickets.loc1=fm_location1.loc1"
-			. " $this->join fm_part_of_town on fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id $filtermethod $querymethod";
+			$sql = "SELECT fm_tts_tickets.* ,fm_location1.loc1_name FROM fm_tts_tickets"
+			. " $this->join fm_location1 ON fm_tts_tickets.loc1=fm_location1.loc1"
+			. " $this->join fm_part_of_town ON fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id"
+			. " $order_join"
+			. " $filtermethod $querymethod";
 
-//echo $sql;
-			$this->db->query($sql,__LINE__,__FILE__);
-			$this->total_records = $this->db->num_rows();
-
+			if(!$dry_run)
+			{
+				$this->db->query('SELECT count(*) as hits ' . substr($sql,strripos($sql,'from')),__LINE__,__FILE__);
+				$this->db->next_record();
+				$this->total_records = $this->db->f('hits');
+				$this->db->fetchmode = 'ASSOC';
 			if(!$allrows)
 			{
 				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@@ -194,36 +256,42 @@
 				$this->db->query($sql . $ordermethod,__LINE__,__FILE__);
 			}
 
-			$db2           	= $this->bocommon->new_db($this->db);
+			}
 
 			$tickets = array();
-			$i = 0;
+
 			while ($this->db->next_record())
 			{
-				$tickets[$i]['id']				= $this->db->f('id');
-				$tickets[$i]['subject']			= $this->db->f('subject',true);
-				$tickets[$i]['location_code']	= $this->db->f('location_code');
-				$tickets[$i]['user_id']			= $this->db->f('user_id');
-				$tickets[$i]['address']			= $this->db->f('address',true);
-				$tickets[$i]['assignedto']		= $this->db->f('assignedto');
-				$tickets[$i]['status']			= $this->db->f('status');
-				$tickets[$i]['priority']		= $this->db->f('priority');
-				$tickets[$i]['cat_id']			= $this->db->f('cat_id');
-				$tickets[$i]['group_id']		= $this->db->f('group_id');
-				$tickets[$i]['entry_date']		= $this->db->f('entry_date');
-				$tickets[$i]['finnish_date']	= $this->db->f('finnish_date');
-				$tickets[$i]['finnish_date2']	= $this->db->f('finnish_date2');
+				$tickets[]= array
+				(
+					'id'				=> (int) $this->db->f('id'),
+					'subject'			=> $this->db->f('subject',true),
+					'loc1_name'			=> $this->db->f('loc1_name',true),
+					'location_code'		=> $this->db->f('location_code'),
+					'user_id'			=> $this->db->f('user_id'),
+					'address'			=> $this->db->f('address',true),
+					'assignedto'		=> $this->db->f('assignedto'),
+					'status'			=> $this->db->f('status'),
+					'priority'			=> $this->db->f('priority'),
+					'cat_id'			=> $this->db->f('cat_id'),
+					'group_id'			=> $this->db->f('group_id'),
+					'entry_date'		=> $this->db->f('entry_date'),
+					'finnish_date'		=> $this->db->f('finnish_date'),
+					'finnish_date2'		=> $this->db->f('finnish_date2'),
+					'new_ticket'		=> ''
+				);
+			}
 
-				$db2->query("select count(*) from fm_tts_views where id='" . (int)$this->db->f('id')
-					. "' and account_id='" . $GLOBALS['phpgw_info']['user']['account_id'] . "'",__LINE__,__FILE__);
-				$db2->next_record();
+			foreach ($tickets as &$ticket)
+				{
+				$this->db->query("SELECT count(*) as hits FROM fm_tts_views where id={$ticket['id']}"
+					. " AND account_id='{$this->account}'",__LINE__,__FILE__);
+				$this->db->next_record();
 
-				if (!$db2->f(0))
+				if(! $this->db->f('hits'))
 				{
-					$tickets[$i]['new_ticket'] = true;
+					$ticket['new_ticket'] = true;
 				}
-
-				$i++;
 			}
 			return $tickets;
 		}
@@ -248,9 +316,9 @@
 			}
 
 			$entity[$i]['type']='.project';
-			$uicols[]	= lang('project');
+			$uicols[]	= 'project';
 
-			$this->uicols	= $uicols;
+			$this->uicols_related	= $uicols;
 			return $entity;
 		}
 
@@ -267,18 +335,27 @@
 				$ticket['group_id']			= $this->db->f('group_id');
 				$ticket['status']			= $this->db->f('status');
 				$ticket['cat_id']			= $this->db->f('cat_id');
-				$ticket['subject']			= stripslashes($this->db->f('subject'));
+				$ticket['subject']			= $this->db->f('subject', true);
 				$ticket['priority']			= $this->db->f('priority');
-				$ticket['details']			= stripslashes($this->db->f('details'));
+				$ticket['details']			= $this->db->f('details', true);
 				$ticket['location_code']	= $this->db->f('location_code');
 				$ticket['contact_phone']	= $this->db->f('contact_phone');
-				$ticket['address']			= stripslashes($this->db->f('address'));
+				$ticket['contact_email']	= $this->db->f('contact_email',true);
+				$ticket['address']			= $this->db->f('address', true);
 				$ticket['tenant_id']		= $this->db->f('tenant_id');
 				$ticket['p_num']			= $this->db->f('p_num');
 				$ticket['p_entity_id']		= $this->db->f('p_entity_id');
 				$ticket['p_cat_id']			= $this->db->f('p_cat_id');
 				$ticket['finnish_date']		= $this->db->f('finnish_date');
 				$ticket['finnish_date2']	= $this->db->f('finnish_date2');
+				$ticket['contact_id']		= $this->db->f('contact_id');
+				$ticket['order_id']			= $this->db->f('order_id');
+				$ticket['vendor_id']		= $this->db->f('vendor_id');
+				$ticket['b_account_id']		= $this->db->f('b_account_id');
+				$ticket['order_descr']		= $this->db->f('order_descr', true);
+				$ticket['ecodimb']			= $this->db->f('ecodimb');
+				$ticket['budget']			= $this->db->f('budget');
+				$ticket['actual_cost']		= $this->db->f('actual_cost');
 
 				$user_id=(int)$this->db->f('user_id');
 				$this->db->query("SELECT account_firstname,account_lastname FROM phpgw_accounts WHERE account_id='$user_id' ");
@@ -300,14 +377,15 @@
 		function update_view($id='')
 		{
 			// Have they viewed this ticket before ?
-			$this->db->query("select count(*) from fm_tts_views where id='$id' "
-					. "and account_id='" . $GLOBALS['phpgw_info']['user']['account_id'] . "'",__LINE__,__FILE__);
+			$id = (int) $id;
+			$this->db->query("SELECT count(*) FROM fm_tts_views where id={$id}"
+					. " AND account_id='" . $GLOBALS['phpgw_info']['user']['account_id'] . "'",__LINE__,__FILE__);
 			$this->db->next_record();
 
 			if (! $this->db->f(0))
 			{
-				$this->db->query("insert into fm_tts_views (id,account_id,time) values ('$id','"
-					. $GLOBALS['phpgw_info']['user']['account_id'] . "','" . time() . "')",__LINE__,__FILE__);
+				$this->db->query("INSERT INTO fm_tts_views (id,account_id,time) values ({$id},'"
+					. $GLOBALS['phpgw_info']['user']['account_id'] . "','" . phpgwapi_datetime::user_localtime() . "')",__LINE__,__FILE__);
 			}
 		}
 
@@ -356,8 +434,9 @@
 				$address = $this->db->db_addslashes($ticket['location_name']);
 			}
 
-			$values= array(
-				$ticket['priority'],
+			$values= array
+			(
+				isset($ticket['priority'])?$ticket['priority']:0,
 				$GLOBALS['phpgw_info']['user']['account_id'],
 				$ticket['assignedto'],
 				$ticket['group_id'],
@@ -367,15 +446,17 @@
 				$this->db->db_addslashes($ticket['details']),
 				$ticket['location_code'],
 				$address,
-				time(),
-				$ticket['finnish_date']);
+				phpgwapi_datetime::user_localtime(),
+				$ticket['finnish_date'],
+				$ticket['contact_id']
+			);
 
-			$values	= $this->bocommon->validate_db_insert($values);
+			$values	= $this->db->validate_insert($values);
 			$this->db->transaction_begin();
 
 			$this->db->query("insert into fm_tts_tickets (priority,user_id,"
 				. "assignedto,group_id,subject,cat_id,status,details,location_code,"
-				. "address,entry_date,finnish_date $cols)"
+				. "address,entry_date,finnish_date,contact_id $cols)"
 				. "VALUES ($values $vals )",__LINE__,__FILE__);
 
 			$id = $this->db->get_last_insert_id('fm_tts_tickets','id');
@@ -393,7 +474,7 @@
 						'location1_id'		=> $GLOBALS['phpgw']->locations->get_id('property', $ticket['origin'][0]['location']),
 						'location1_item_id' => $ticket['origin'][0]['data'][0]['id'],
 						'location2_id'		=> $GLOBALS['phpgw']->locations->get_id('property', '.ticket'),			
-						'location2_item_id' => $ticket['project_id'],
+						'location2_item_id' => $id,
 						'account_id'		=> $this->account
 					);
 					
@@ -404,7 +485,7 @@
 
 			if($this->db->transaction_commit())
 			{
-				$this->historylog->add('O',$id,mktime(),'');
+				$this->historylog->add('O',$id, phpgwapi_datetime::user_localtime(),'');
 				if($ticket['finnish_date'])
 				{
 					$this->historylog->add('IF',$id,$ticket['finnish_date'],'');
@@ -439,4 +520,423 @@
 			}
 			return $status;
 		}
+		function update_status($ticket,$id = 0)
+		{
+			$id = (int) $id;
+			$receipt = array();
+			// DB Content is fresher than http posted value.
+			$this->db->query("select * from fm_tts_tickets where id='$id'",__LINE__,__FILE__);
+			$this->db->next_record();
+			$old_status  		= $this->db->f('status');
+
+			$this->db->transaction_begin();
+
+			/*
+			** phpgw_fm_tts_append.append_type - Defs
+			** R - Reopen ticket
+			** X - Ticket closed
+			** O - Ticket opened
+			** C - Comment appended
+			** A - Ticket assignment
+			** G - Ticket group assignment
+			** P - Priority change
+			** T - Category change
+			** S - Subject change
+			** B - Budget
+			** H - Billing hours
+			** F - finnish date
+			** C% - Status changed
+			** L - Location changed
+			** M - Mail sent to vendor
+			*/
+
+			if ($old_status != $ticket['status'])
+			{
+				$check_old_custom = (int) trim($old_status,'C');
+				$this->db->query("SELECT * from fm_tts_status WHERE id = {$check_old_custom}",__LINE__,__FILE__);
+				$this->db->next_record();
+				$this->fields_updated = true;
+				if($old_status=='X' || $this->db->f('closed'))
+				{
+					$new_status = $ticket['status'];
+					$this->historylog->add('R',$id,$ticket['status'],$old_status);
+
+					$this->db->query("UPDATE fm_tts_tickets SET status='{$new_status}' WHERE id= {$id}",__LINE__,__FILE__);
+				}
+				else
+				{
+					$this->historylog->add($ticket['status'],$id,$ticket['status'],$old_status);
+					$this->db->query("UPDATE fm_tts_tickets SET status='{$ticket['status']}' WHERE id={$id}",__LINE__,__FILE__);
+				}
+				$this->check_pending_action($ticket, $id);
+			}
+
+			$this->db->transaction_commit();
+
+			if ($this->fields_updated)
+			{
+				$receipt['message'][]= array('msg' => lang('Ticket %1 has been updated',$id));
+			}
+
+			return $receipt;
+
+		}
+
+		function update_ticket($ticket,$id = 0)
+		{
+			$id = (int) $id;
+			$receipt = array();
+			// DB Content is fresher than http posted value.
+			$this->db->query("select * from fm_tts_tickets where id='$id'",__LINE__,__FILE__);
+			$this->db->next_record();
+
+
+			$location_code 	= $this->db->f('location_code');
+			$oldlocation_code 	= $this->db->f('location_code');
+			$oldfinnish_date 	= $this->db->f('finnish_date');
+			$oldfinnish_date2 	= $this->db->f('finnish_date2');
+			$oldassigned 		= $this->db->f('assignedto');
+			$oldgroup_id 		= $this->db->f('group_id');
+			$oldpriority 		= $this->db->f('priority');
+			$oldcat_id 			= $this->db->f('cat_id');
+			$old_status  		= $this->db->f('status');
+			$old_budget  		= $this->db->f('budget');
+		//	$old_billable_hours	= $this->db->f('billable_hours');
+		//	$old_billable_rate	= $this->db->f('billable_rate');
+			$old_subject		= $this->db->f('subject');
+			$old_contact_id		= $this->db->f('contact_id');
+			if($oldcat_id ==0){$oldcat_id ='';}
+			if($oldassigned ==0){$oldassigned ='';}
+			if($oldgroup_id ==0){$oldgroup_id ='';}
+
+			// Figure out and last note
+
+			$history_values = $this->historylog->return_array(array(),array('C'),'history_timestamp','DESC',$id);
+			$old_note = $history_values[0]['new_value'];
+
+			if(!$old_note)
+			{
+				$old_note = $this->db->f('details');
+			}
+
+
+			$this->db->transaction_begin();
+
+			/*
+			** phpgw_fm_tts_append.append_type - Defs
+			** R - Reopen ticket
+			** X - Ticket closed
+			** O - Ticket opened
+			** C - Comment appended
+			** A - Ticket assignment
+			** G - Ticket group assignment
+			** P - Priority change
+			** T - Category change
+			** S - Subject change
+			** B - Budget change
+			** H - Billing hours
+			** F - finnish date
+			** C% - Status change
+			** L - Location changed
+			** M - Mail sent to vendor
+			*/
+
+			$finnish_date	= (isset($ticket['finnish_date']) ? phpgwapi_datetime::date_to_timestamp($ticket['finnish_date']):'');
+
+			if ($oldfinnish_date && isset($ticket['finnish_date']) && $ticket['finnish_date']):
+			{
+				$this->db->query("update fm_tts_tickets set finnish_date2='" . $finnish_date
+					. "' where id='$id'",__LINE__,__FILE__);
+			}
+			elseif(!$oldfinnish_date && isset($ticket['finnish_date']) && $ticket['finnish_date']):
+			{
+				$this->db->query("update fm_tts_tickets set finnish_date='" . $finnish_date
+					. "' where id='$id'",__LINE__,__FILE__);
+			}
+			endif;
+
+			if($oldfinnish_date2>0)
+			{
+				$oldfinnish_date = $oldfinnish_date2;
+			}
+			if(isset($ticket['finnish_date']) && $ticket['finnish_date'])
+			{
+				if ($oldfinnish_date != $finnish_date)
+				{
+					$this->fields_updated = true;
+					$this->historylog->add('F',$id,$finnish_date,$oldfinnish_date);
+				}
+			}
+
+			if (isset($ticket['status']) && ($old_status != $ticket['status']))
+			{
+				$check_old_custom = (int) trim($old_status,'C');
+				$this->db->query("SELECT * from fm_tts_status WHERE id = {$check_old_custom}",__LINE__,__FILE__);
+				$this->db->next_record();
+				$this->fields_updated = true;
+				if($old_status=='X' || $this->db->f('closed'))
+				{
+					$new_status = $ticket['status'];
+					$this->historylog->add('R',$id,$ticket['status'],$old_status);
+
+					$this->db->query("UPDATE fm_tts_tickets SET status='{$new_status}' WHERE id= {$id}",__LINE__,__FILE__);
+				}
+				else
+				{
+					$this->historylog->add($ticket['status'],$id,$ticket['status'],$old_status);
+					$this->db->query("UPDATE fm_tts_tickets SET status='{$ticket['status']}' WHERE id={$id}",__LINE__,__FILE__);
+				}
+				$this->check_pending_action($ticket, $id);
+			}
+
+			if (($oldassigned != $ticket['assignedto']) && $ticket['assignedto'] != 'ignore')
+			{
+				$this->fields_updated = true;
+
+				$value_set=array('assignedto'	=> $ticket['assignedto']);
+				$value_set	= $this->db->validate_update($value_set);
+
+				$this->db->query("update fm_tts_tickets set $value_set where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('A',$id,$ticket['assignedto'],$oldassigned);
+			}
+
+			if (($oldgroup_id != $ticket['group_id']) && $ticket['group_id'] != 'ignore')
+			{
+				$this->fields_updated = true;
+
+				$value_set=array('group_id'	=> $ticket['group_id']);
+				$value_set	= $this->db->validate_update($value_set);
+
+				$this->db->query("update fm_tts_tickets set $value_set where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('G',$id,$ticket['group_id'],$oldgroup_id);
+			}
+
+			if ($oldpriority != $ticket['priority'])
+			{
+				$this->fields_updated = true;
+				$this->db->query("update fm_tts_tickets set priority='" . $ticket['priority']
+					. "' where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('P',$id,$ticket['priority'],$oldpriority);
+			}
+
+			if ($old_contact_id != $ticket['contact_id'])
+			{
+				$contact_id  = (int) $ticket['contact_id'];
+				$this->fields_updated = true;
+				$this->db->query("update fm_tts_tickets set contact_id={$contact_id} WHERE id=$id",__LINE__,__FILE__);
+			}
+
+			if (($oldcat_id != $ticket['cat_id']) && $ticket['cat_id'] != 'ignore')
+			{
+				$this->fields_updated = true;
+				$this->db->query("update fm_tts_tickets set cat_id='" . $ticket['cat_id']
+					. "' where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('T',$id,$ticket['cat_id'],$oldcat_id);
+			}
+
+			if ($old_budget != $ticket['budget'])
+			{
+				$this->fields_updated = true;
+				$this->db->query("UPDATE fm_tts_tickets set budget='" . (int)$ticket['budget']
+					. "' where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('B',$id,$ticket['budget'],$old_budget);
+			}
+	/*
+			if ($old_billable_rate != $ticket['billable_rate'])
+			{
+				$this->fields_updated = true;
+				$this->db->query("update fm_tts_tickets set billable_rate='" . $ticket['billable_rate']
+					. "' where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('B',$id,$ticket['billable_rate'],$old_billable_rate);
+			}
+	*/
+			if ($old_subject != $ticket['subject'])
+			{
+				$this->db->query("update fm_tts_tickets set subject='" . $ticket['subject']
+					. "' where id='$id'",__LINE__,__FILE__);
+				$this->historylog->add('S',$id,$ticket['subject'],$old_subject);
+				$receipt['message'][]= array('msg' => lang('Subject has been updated'));
+			}
+
+			if (($old_note != $ticket['note']) && $ticket['note'])
+			{
+				$this->fields_updated = true;
+				$this->historylog->add('C',$id,$ticket['note'],$old_note);
+			}
+
+			if(isset($ticket['location']) && $ticket['location'])
+			{
+				$ticket['location_code'] = implode('-', $ticket['location']);
+			}
+
+			if (isset($ticket['location_code']) && $ticket['location_code'] && ($oldlocation_code != $ticket['location_code']))
+			{
+				$interlink 	= CreateObject('property.interlink');
+				if( $interlink->get_relation('property', '.ticket', $id, 'origin') || $interlink->get_relation('property', '.ticket', $id, 'target'))
+				{
+					$receipt['message'][]= array('msg' => lang('location could not be changed'));
+				}
+				else
+				{
+					$value_set	= array();
+
+					if(isset($ticket['street_name']) && $ticket['street_name'])
+					{
+						$address[]= $ticket['street_name'];
+						$address[]= $ticket['street_number'];
+						$value_set['address'] = $this->db->db_addslashes(implode(" ", $address));
+					}
+
+					if(!isset($address) || !$address)
+					{
+						$address = isset($ticket['location_name']) ? $this->db->db_addslashes($ticket['location_name']) : '';
+						if($address)
+						{
+							$value_set['address'] = $address;
+						}
+					}
+
+					if (isset($ticket['location_code']) && $ticket['location_code'])
+					{
+						$value_set['location_code'] = $ticket['location_code'];
+					}
+
+					$admin_location	= CreateObject('property.soadmin_location');
+					$admin_location->read(false);
+
+				// Delete old values for location - in case of moving up in the hierarchy
+					$metadata = $this->db->metadata('fm_tts_tickets');
+					for ($i = 1;$i < $admin_location->total_records + 1; $i++)
+					{
+						if(isset($metadata["loc{$i}"]))
+						{
+							$value_set["loc{$i}"]	= false;
+						}
+					}
+
+					if(isset($ticket['location']) && is_array($ticket['location']))
+					{
+						foreach ($ticket['location'] as $column => $value)
+						{
+							$value_set[$column]	= $value;
+						}
+					}
+
+					if(isset($ticket['extra']) && is_array($ticket['extra']))
+					{
+						foreach ($ticket['extra'] as $column => $value)
+						{
+							$value_set[$column]	= $value;
+						}
+					}
+
+					$value_set	= $this->db->validate_update($value_set);
+
+					$this->db->query("UPDATE fm_tts_tickets SET $value_set WHERE id={$id}",__LINE__,__FILE__);
+
+					$this->historylog->add('L',$id,$ticket['location_code'],$oldlocation_code);
+					$receipt['message'][]= array('msg' => lang('Location has been updated'));
+				}
+				unset($interlink);
+			}
+
+
+			if(isset($ticket['make_order']) && $ticket['make_order'])
+			{
+				$order_id = execMethod('property.socommon.increment_id', 'order');
+				if($order_id)
+				{
+					$this->db->query("UPDATE fm_tts_tickets SET order_id = {$order_id} WHERE id={$id}",__LINE__,__FILE__);
+				}
+			}
+
+			$value_set					= array();
+			$value_set['vendor_id']		= $ticket['vendor_id'];
+			$value_set['b_account_id']	= $ticket['b_account_id'];
+			$value_set['order_descr']	= $this->db->db_addslashes($ticket['order_descr']);
+			$value_set['ecodimb']		= $ticket['ecodimb'];
+			$value_set['budget']		= $ticket['budget'];
+			$value_set					= $this->db->validate_update($value_set);
+			$this->db->query("UPDATE fm_tts_tickets SET $value_set WHERE id={$id}",__LINE__,__FILE__);
+
+			$this->db->transaction_commit();
+
+			if (isset($this->fields_updated))
+			{
+				$receipt['message'][]= array('msg' => lang('Ticket has been updated'));
+
+				$criteria = array
+				(
+					'appname'	=> 'property',
+					'location'	=> $this->acl_location,
+					'allrows'	=> true
+				);
+
+				$custom_functions = $GLOBALS['phpgw']->custom_functions->find($criteria);
+
+				foreach ( $custom_functions as $entry )
+				{
+					// prevent path traversal
+					if ( preg_match('/\.\./', $entry['file_name']) )
+					{
+						continue;
+					}
+
+					$file = PHPGW_SERVER_ROOT . "/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+					if ( $entry['active'] && is_file($file) )
+					{
+						require_once $file;
+					}
+				}
+			}
+			return $receipt;
+		}
+
+		function check_pending_action($ticket,$id)
+		{
+			$status = (int)trim($ticket['status'], 'C');
+			$this->db->query("SELECT * FROM fm_tts_status WHERE id = '{$status}'");
+
+			$this->db->next_record();
+
+			if ($this->db->f('approved') )
+			{
+				$action_params = array
+				(
+					'appname'			=> 'property',
+					'location'			=> '.ticket',
+					'id'				=> $id,
+					'responsible'		=> $this->account,
+					'responsible_type'  => 'user',
+					'action'			=> 'approval',
+					'remark'			=> '',
+					'deadline'			=> ''
+				);
+
+				execMethod('property.sopending_action.close_pending_action', $action_params);
+				unset($action_params);
+			}
+			if ($this->db->f('in_progress') )
+			{
+				$action_params = array
+				(
+					'appname'			=> 'property',
+					'location'			=> '.ticket',
+					'id'				=> $id,
+					'responsible'		=> $ticket['vendor_id'],
+					'responsible_type'  => 'vendor',
+					'action'			=> 'remind',
+					'remark'			=> '',
+					'deadline'			=> ''
+				);
+
+				execMethod('property.sopending_action.close_pending_action', $action_params);
+				unset($action_params);
+			}
+
+			if ($this->db->f('delivered') )
+			{
+				//close
+			}
+		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.sowo_hour.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.sowo_hour.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.sowo_hour.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -34,23 +34,22 @@
 
 	class property_sowo_hour
 	{
-		function property_sowo_hour()
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
-			$this->bocommon	= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
 
-			$this->join		= $this->bocommon->join;
-			$this->left_join	= $this->bocommon->left_join;
-			$this->like		= $this->bocommon->like;
+			$this->db 			= & $GLOBALS['phpgw']->db;
+			$this->db2			= clone($this->db);
+			$this->like 		= & $this->db->like;
+			$this->join 		= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
 		}
 
 		function get_chapter_list()
 		{
 			$this->db->query("SELECT id, descr FROM fm_chapter ORDER BY id ");
 
+			$chapter_entries = array();
 			$i = 0;
 			while ($this->db->next_record())
 			{
@@ -234,7 +233,7 @@
 				time()
 				);
 
-			$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+			$values_insert	= $this->db->validate_insert($values_insert);
 
 			$this->db->query("INSERT INTO fm_wo_h_deviation (workorder_id,hour_id,id,amount,descr,entry_date) VALUES ($values_insert)",__LINE__,__FILE__);
 
@@ -253,7 +252,7 @@
 				'descr'			=> $this->db->db_addslashes($values['descr'])
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->query("UPDATE fm_wo_h_deviation set $value_set WHERE workorder_id=" . $values['workorder_id'] . " AND hour_id=" . $values['hour_id'] . " AND id=" . $values['id'],__LINE__,__FILE__);
 
@@ -299,7 +298,7 @@
 				time()
 				 );
 
-			$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+			$values_insert	= $this->db->validate_insert($values_insert);
 
 			$this->db->query("insert into fm_template (owner,name,descr,chapter_id,entry_date) "
 				. " values ($values_insert)",__LINE__,__FILE__);
@@ -333,7 +332,7 @@
 					$record,
 					$template_id );
 
-				$values_insert	= $this->bocommon->validate_db_insert($values_insert);
+				$values_insert	= $this->db->validate_insert($values_insert);
 
 				$this->db->query("insert into fm_template_hours (activity_id,activity_num,owner,hours_descr,unit,"
 				. "cost,quantity,billperae,ns3420_id,dim_d,grouping_id,grouping_descr,remark,tolerance,building_part,record,template_id) "
@@ -362,7 +361,7 @@
 					$hour[$i]['hours_descr'],
 					$hour[$i]['unit'],
 					$hour[$i]['cost'],
-					$hour[$i]['quantity'],
+					(int)$hour[$i]['quantity'],
 					$hour[$i]['billperae'],
 					$hour[$i]['ns3420_id'],
 					$hour[$i]['dim_d'],
@@ -373,7 +372,7 @@
 					$hour[$i]['cat_per_cent']
 					);
 
-				$values	= $this->bocommon->validate_db_insert($values);
+				$values	= $this->db->validate_insert($values);
 
 				$this->db->query("insert into fm_wo_hours (activity_id,activity_num,owner,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,record,entry_date,workorder_id,category,cat_per_cent) "
 				. " values ($values)",__LINE__,__FILE__);
@@ -443,7 +442,7 @@
 					$hour[$i]['cat_per_cent']
 					);
 
-				$values	= $this->bocommon->validate_db_insert($values);
+				$values	= $this->db->validate_insert($values);
 
 				$this->db->query("insert into fm_wo_hours (owner,activity_id,activity_num,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,"
 				. " grouping_id,grouping_descr,record,building_part,tolerance,remark,entry_date,workorder_id,category,cat_per_cent) "
@@ -520,7 +519,7 @@
 					$hour['cat_per_cent']
 					);
 
-			$values	= $this->bocommon->validate_db_insert($values);
+			$values	= $this->db->validate_insert($values);
 
 			$this->db->query("insert into fm_wo_hours (owner,hours_descr,unit,cost,quantity,billperae,ns3420_id,dim_d,"
 				. " grouping_id,grouping_descr,record,building_part,tolerance,remark,entry_date,workorder_id,category,cat_per_cent) "
@@ -661,7 +660,7 @@
 				'cat_per_cent'		=> $hour['cat_per_cent']
 				);
 
-			$value_set	= $this->bocommon->validate_db_update($value_set);
+			$value_set	= $this->db->validate_update($value_set);
 
 			$this->db->query("UPDATE fm_wo_hours set $value_set WHERE id= '" . $hour['hour_id'] ."'",__LINE__,__FILE__);
 
@@ -680,11 +679,12 @@
 			$this->db->query("UPDATE fm_vendor set email ='$to_email' where  id= '$vendor_id'",__LINE__,__FILE__);
 		}
 
-		function get_email($vendor_id)
+		function get_email($vendor_id = 0)
 		{
 			$vendor_id=(int)$vendor_id;
 			$location_id = $GLOBALS['phpgw']->locations->get_id('property', '.vendor');
 			$this->db->query("select column_name from phpgw_cust_attribute WHERE location_id = {$location_id} AND datatype='email'",__LINE__,__FILE__);
+			$email_list = array();
 			while ($this->db->next_record())
 			{
 				$this->db2->query("select " . $this->db->f('column_name') . " from fm_vendor where id=$vendor_id",__LINE__,__FILE__);
@@ -742,8 +742,8 @@
 
 			if($calculation > 0)
 			{
-				$config		= CreateObject('phpgwapi.config');
-				$config->read_repository();
+				$config		= CreateObject('phpgwapi.config','property');
+				$config->read();
 				$tax = 1+(($config->config_data['fm_tax'])/100);
 				$calculation = $calculation * $tax;
 

Modified: people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -35,19 +35,18 @@
 	class property_soworkorder
 	{
 
-		function property_soworkorder()
+		var $total_records = 0;
+
+		function __construct()
 		{
-		//	$this->currentapp	= $GLOBALS['phpgw_info']['flags']['currentapp'];
 			$this->account		= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bocommon		= CreateObject('property.bocommon');
-			$this->db           	= $this->bocommon->new_db();
-			$this->db2           	= $this->bocommon->new_db($this->db);
-			$this->join			= $this->bocommon->join;
-
-			$this->left_join	= $this->bocommon->left_join;
-
-			$this->like			= $this->bocommon->like;
-
+			$this->db 			= & $GLOBALS['phpgw']->db;
+			$this->db2			= clone($this->db);
+			$this->like 		= & $this->db->like;
+			$this->join 		= & $this->db->join;
+			$this->left_join	= & $this->db->left_join;
+			$this->interlink 	= CreateObject('property.interlink');
 		//	$this->grants 		= $GLOBALS['phpgw']->session->appsession('grants_project','property');
 		//	if(!$this->grants)
 			{
@@ -128,37 +127,39 @@
 			if(is_array($data))
 			{
 				$start			= isset($data['start']) && $data['start'] ? $data['start'] : 0;
-				$filter			= $data['filter'] ? $data['filter'] : 'all';
+				$filter			= $data['filter'] ? (int)$data['filter'] : 0;
 				$query			= isset($data['query']) ? $data['query'] : '';
 				$sort			= isset($data['sort']) && $data['sort'] ? $data['sort'] : 'DESC';
 				$order			= isset($data['order']) ? $data['order'] : '';
 				$cat_id			= isset($data['cat_id']) && $data['cat_id'] ? $data['cat_id'] : 0;
 				$status_id		= isset($data['status_id']) && $data['status_id'] ? $data['status_id'] : 0;
-				$search_vendor	= isset($data['search_vendor']) ? $data['search_vendor'] : '';
 				$start_date		= isset($data['start_date']) ? $data['start_date'] : '';
 				$end_date		= isset($data['end_date']) ? $data['end_date'] : '';
 				$allrows		= isset($data['allrows']) ? $data['allrows'] : '';
 				$wo_hour_cat_id	= isset($data['wo_hour_cat_id']) ? $data['wo_hour_cat_id'] : '';
 				$b_group		= isset($data['b_group']) ? $data['b_group'] : '';
 				$paid			= isset($data['paid']) ? $data['paid'] : '';
+				$b_account		= isset($data['b_account']) ? $data['b_account'] : '';
+				$district_id	= isset($data['district_id']) ? $data['district_id'] : '';
+				$dry_run		= isset($data['dry_run']) ? $data['dry_run'] : '';
+				$criteria		= isset($data['criteria']) && $data['criteria'] ? $data['criteria'] : array();
 			}
 
-
+			$GLOBALS['phpgw']->config->read();
 			$sql = $this->bocommon->fm_cache('sql_workorder'.!!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group);
 //echo $sql;
 			if(!$sql)
 			{
 				$entity_table = 'fm_project';
 
-				$cols .= $entity_table . '.location_code';
-				$cols_return[] = 'location_code';
-
-				$cols .= ",$entity_table.id as project_id";
+				$cols = "$entity_table.id as project_id";
 				$cols_return[] 				= 'project_id';
 				$uicols['input_type'][]		= 'text';
 				$uicols['name'][]			= 'project_id';
 				$uicols['descr'][]			= lang('Project');
 				$uicols['statustext'][]		= lang('Project ID');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ",fm_workorder.id as workorder_id";
 				$cols_return[] 				= 'workorder_id';
@@ -166,6 +167,8 @@
 				$uicols['name'][]			= 'workorder_id';
 				$uicols['descr'][]			= lang('Workorder');
 				$uicols['statustext'][]		= lang('Workorder ID');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ",fm_workorder.title as title";
 				$cols_return[] 				= 'title';
@@ -173,6 +176,8 @@
 				$uicols['name'][]			= 'title';
 				$uicols['descr'][]			= lang('Title');
 				$uicols['statustext'][]		= lang('Workorder title');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ",fm_workorder.status as status";
 				$cols_return[] 				= 'status';
@@ -180,6 +185,8 @@
 				$uicols['name'][]			= 'status';
 				$uicols['descr'][]			= lang('Status');
 				$uicols['statustext'][]		= lang('Workorder status');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ",fm_workorder.entry_date as entry_date";
 				$cols_return[] 				= 'entry_date';
@@ -187,6 +194,8 @@
 				$uicols['name'][]			= 'entry_date';
 				$uicols['descr'][]			= lang('Entry date');
 				$uicols['statustext'][]		= lang('Workorder entry date');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ",phpgw_accounts.account_lid as user_lid";
 				$cols_return[] 				= 'user_lid';
@@ -194,6 +203,8 @@
 				$uicols['name'][]			= 'user_lid';
 				$uicols['descr'][]			= lang('User');
 				$uicols['statustext'][]		= lang('Workorder User');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ',fm_workorder.vendor_id';
 				$cols_return[] = 'vendor_id';
@@ -201,7 +212,19 @@
 				$uicols['name'][]			= 'vendor_id';
 				$uicols['descr'][]			= lang('Vendor ID');
 				$uicols['statustext'][]		= lang('Vendor ID');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
+				$cols.= ",loc1_name";
+				$cols_return[] 				= 'loc1_name';
+				$uicols['input_type'][]		= 'hidden';
+				$uicols['name'][]			= 'loc1_name';
+				$uicols['descr'][]			= '';
+				$uicols['statustext'][]		= '';
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
+
+
 				$cols .= ",fm_project.user_id as project_owner";
 
 				$joinmethod .= " $this->join  fm_workorder ON ($entity_table.id = fm_workorder.project_id) $this->join  phpgw_accounts ON (fm_workorder.user_id = phpgw_accounts.account_id))";
@@ -213,6 +236,8 @@
 				$uicols['name'][]			= 'org_name';
 				$uicols['descr'][]			= lang('Vendor name');
 				$uicols['statustext'][]		= lang('Vendor name');
+				$uicols['formatter'][]		= '';
+				$uicols['classname'][]		= '';
 
 				$cols .= ',fm_workorder.combined_cost';
 				$cols_return[] = 'combined_cost';
@@ -220,6 +245,8 @@
 				$uicols['name'][]			= 'combined_cost';
 				$uicols['descr'][]			= lang('Cost');
 				$uicols['statustext'][]		= lang('Cost - either budget or calculation');
+				$uicols['formatter'][]		= 'myFormatCount2';
+				$uicols['classname'][]		= 'rightClasss';
 
 				$cols .= ',fm_workorder.act_mtrl_cost + fm_workorder.act_vendor_cost as actual_cost';
 				$cols_return[] = 'actual_cost';
@@ -227,6 +254,8 @@
 				$uicols['name'][]			= 'actual_cost';
 				$uicols['descr'][]			= lang('Actual cost');
 				$uicols['statustext'][]		= lang('Actual cost - paid so far');
+				$uicols['formatter'][]		= 'myFormatCount2';
+				$uicols['classname'][]		= 'rightClasss';
 
 				$joinmethod .= " $this->left_join  fm_vendor ON (fm_workorder.vendor_id = fm_vendor.id))";
 				$paranthesis .='(';
@@ -256,8 +285,30 @@
 				//----- b_group
 
 
+			$cols_return[] = 'location_code';
+			$no_address = false;
+			if(isset($GLOBALS['phpgw']->config->config_data['location_at_workorder']) && $GLOBALS['phpgw']->config->config_data['location_at_workorder'])
+			{
+				$no_address = true;
+				$cols .= ',fm_workorder.location_code';
+				$cols .= ',fm_workorder.address';
+				$cols_return[] 				= 'address';
+				$uicols['input_type'][]		= 'text';
+				$uicols['name'][]			= 'address';
+				$uicols['descr'][]			= lang('address');
+				$uicols['statustext'][]		= lang('address');
+				$uicols['exchange'][]		= false;
+				$uicols['align'][] 			= '';
+				$uicols['datatype'][]		= '';
+			}
+			else
+			{
+				$cols .= ",{$entity_table}.location_code";
+			}
+
 				$sql	= $this->bocommon->generate_sql(array('entity_table'=>$entity_table,'cols'=>$cols,'cols_return'=>$cols_return,
-									'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query,'force_location'=>true));
+									'uicols'=>$uicols,'joinmethod'=>$joinmethod,'paranthesis'=>$paranthesis,'query'=>$query,
+									'force_location'=>true, 'no_address' => $no_address));
 
 				$this->bocommon->fm_cache('sql_workorder'.!!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group,$sql);
 
@@ -280,6 +331,17 @@
 //				$this->cols_extra	= $this->bocommon->fm_cache('cols_extra_workorder'.!!$search_vendor . '_' . !!$wo_hour_cat_id . '_' . !!$b_group);
 			}
 
+			if($dry_run)
+			{
+				return array();
+			}
+
+			$location_table = 'fm_project';
+			if(isset($GLOBALS['phpgw']->config->config_data['location_at_workorder']) && $GLOBALS['phpgw']->config->config_data['location_at_workorder'])
+			{
+				$location_table = 'fm_workorder';
+			}
+
 			if ($order)
 			{
 				$ordermethod = " order by $order $sort";
@@ -293,7 +355,7 @@
 
 			$filtermethod = '';
 
-			$GLOBALS['phpgw']->config->read_repository();
+
 			if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && $GLOBALS['phpgw']->config->config_data['acl_at_location'])
 			{
 				$access_location = $this->bocommon->get_location_list(PHPGW_ACL_READ);
@@ -318,7 +380,7 @@
 			{
 				$filtermethod .= " $where fm_wo_hours_category.id=$wo_hour_cat_id ";
 				$where= 'AND';
-				$group_method = " group by fm_project.id,fm_project.location_code,fm_workorder.id,workorder_id,title,fm_workorder.status,fm_workorder.entry_date,user_lid,fm_workorder.vendor_id,project_owner,fm_project.address,fm_vendor.org_name,fm_workorder.combined_cost,fm_workorder.act_mtrl_cost,fm_workorder.act_vendor_cost";
+				$group_method = " group by fm_project.id,{$location_table}.location_code,fm_workorder.id,workorder_id,title,fm_workorder.status,fm_workorder.entry_date,user_lid,fm_workorder.vendor_id,project_owner,{$location_table}.address,fm_vendor.org_name,fm_workorder.combined_cost,fm_workorder.act_mtrl_cost,fm_workorder.act_vendor_cost";
 			}
 
 			if ($b_group)
@@ -334,8 +396,18 @@
 				$where= 'AND';
 			}
 
-			if ($filter=='all')
+			if ($b_account)
 			{
+				$filtermethod .= " {$where} fm_workorder.account_id = '{$b_account}'";
+				$where= 'AND';
+			}
+
+			if ($district_id)
+			{
+				$filtermethod .= " {$where} district_id = {$district_id}";
+				$where= 'AND';
+			}
+
 				if (is_array($this->grants))
 				{
 					$grants = $this->grants;
@@ -344,13 +416,13 @@
 						$public_user_list[] = $user;
 					}
 					reset($public_user_list);
-					$filtermethod .= " $where (fm_project.access='public' AND fm_project.user_id IN(" . implode(',',$public_user_list) . "))";
+				$filtermethod .= " $where (fm_project.access='public' AND fm_project.user_id IN(" . implode(',',$public_user_list) . ")";
 					$where= 'AND';
 				}
-			}
-			else
+
+			if ($filter)
 			{
-				$filtermethod .= " $where fm_workorder.user_id=$filter ";
+				$filtermethod .= " $where fm_workorder.user_id={$filter}";
 				$where= 'AND';
 			}
 
@@ -368,37 +440,64 @@
 				if(stristr($query, '.'))
 				{
 					$query=explode(".",$query);
-					$querymethod = " $where (fm_project.loc1='" . $query[0] . "' AND fm_project.loc".$type_id."='" . $query[1] . "')";
+					$querymethod = " $where ({$location_table}.location_code $this->like '{$query[0]}%' AND {$location_table}.location_code $this->like '%{$query[1]}')";
 				}
 				else
 				{
-					$querymethod = " $where (fm_workorder.title $this->like '%$query%' or fm_workorder.descr $this->like '%$query%' or fm_project.address $this->like '%$query%' or fm_project.location_code $this->like '%$query%' or fm_workorder.id =" . (int)$query . ')';
+					$matchtypes = array
+					(
+						'exact' => '=',
+						'like'	=> $this->like
+					);
+
+					if(count($criteria) > 1)
+					{
+						$_querymethod = array();
+						foreach($criteria as $field_info)
+						{
+							if($field_info['type'] == int)
+							{
+								$_query = (int) $query;
 				}
-				$where= 'AND';
+							else
+							{
+								$_query = $query;
+							}
+
+							$_querymethod[] = "{$field_info['field']} {$matchtypes[$field_info['matchtype']]} {$field_info['front']}{$_query}{$field_info['back']}";
 			}
 
-			$querymethod_vendor = '';
-			if($search_vendor)
+						$querymethod = $where . ' ' . implode(' OR ', $_querymethod);
+						unset($_querymethod);
+					}
+					else
 			{
-				if((int)$search_vendor>0)
+						if($criteria[0]['type'] == int)
 				{
-					$querymethod_vendor = " $where fm_workorder.vendor_id=" .(int)$search_vendor ;
+							$_query = (int) $query;
 				}
 				else
 				{
-					$querymethod_vendor = " $where  fm_vendor.org_name $this->like '%$search_vendor%'";
+							$_query = $query;
 				}
+
+						$querymethod = "{$where} {$criteria[0]['field']} {$matchtypes[$criteria[0]['matchtype']]} {$criteria[0]['front']}{$_query}{$criteria[0]['back']}";
 			}
 
-			$sql .= " $filtermethod $querymethod $querymethod_vendor";
-//echo $sql;
+				}
+				$where= 'AND';
+			}
+			$querymethod .= ')';
 
+			$sql .= " $filtermethod $querymethod";
+
+//_debug_array($sql);
 			if($GLOBALS['phpgw_info']['server']['db_type']=='postgres')
 			{
 				$sql2 = 'SELECT count(*) FROM (SELECT fm_workorder.id ' . substr($sql,strripos($sql,'from'))  . ') as cnt';
 				$this->db->query($sql2,__LINE__,__FILE__);
 				$this->db->next_record();
-				$this->total_records = $this->db->f(0);
+				$this->total_records = $this->db->f('count');//$this->db->f('0');
 			}
 			else
 			{
@@ -409,6 +508,8 @@
 
 			$sql .= " $group_method";
 
+			//[email protected] 23/10/08 avoid retrieve data in first time, only render definition for headers (var myColumnDefs)
+
 			if(!$allrows)
 			{
 				$this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__);
@@ -444,43 +545,59 @@
 			return $workorder_list;
 		}
 
-		function read_single($workorder_id)
+		function read_single($workorder_id = 0)
 		{
+		//	$this->update_actual_cost_global();
+		//	$this->update_planned_cost_global();
+
 			$sql = "SELECT fm_workorder.*, fm_chapter.descr as chapter ,fm_project.user_id from fm_workorder $this->join fm_project on fm_workorder.project_id=fm_project.id  $this->left_join fm_chapter on "
-				. " fm_workorder.chapter_id = fm_chapter.id where fm_workorder.id=$workorder_id";
+				. " fm_workorder.chapter_id = fm_chapter.id where fm_workorder.id={$workorder_id}";
 
 			$this->db->query($sql,__LINE__,__FILE__);
 
+			$workorder = array();
 			if ($this->db->next_record())
 			{
-				$workorder['workorder_id']		= $this->db->f('id');
-				$workorder['project_id']		= $this->db->f('project_id');
-				$workorder['title']				= $this->db->f('title');
-				$workorder['name']				= $this->db->f('name');
-				$workorder['key_fetch']			= $this->db->f('key_fetch');
-				$workorder['key_deliver']		= $this->db->f('key_deliver');
-				$workorder['key_responsible']	= $this->db->f('key_responsible');
-				$workorder['charge_tenant']		= $this->db->f('charge_tenant');
-				$workorder['descr']				= stripslashes($this->db->f('descr'));
-				$workorder['status']			= $this->db->f('status');
-				$workorder['budget']			= (int)$this->db->f('budget');
-				$workorder['calculation']			= $this->db->f('calculation')>0?($this->db->f('calculation')*(1+$this->db->f('addition')/100))+$this->db->f('rig_addition'):0;
-				$workorder['b_account_id']			= (int)$this->db->f('account_id');
-				$workorder['addition_percentage']	= (int)$this->db->f('addition');
-				$workorder['addition_rs']			= (int)$this->db->f('rig_addition');
-				$workorder['act_mtrl_cost']			= $this->db->f('act_mtrl_cost');
-				$workorder['act_vendor_cost']		= $this->db->f('act_vendor_cost');
-				$workorder['user_id']				= $this->db->f('user_id');
-				$workorder['vendor_id']			= $this->db->f('vendor_id');
-				$workorder['coordinator']		= $this->db->f('coordinator');
-				$workorder['access']			= $this->db->f('access');
-				$workorder['start_date']		= $this->db->f('start_date');
-				$workorder['end_date']			= $this->db->f('end_date');
-				$workorder['cat_id']			= $this->db->f('category');
-				$workorder['chapter_id']		= $this->db->f('chapter_id');
-				$workorder['chapter']			= $this->db->f('chapter');
-				$workorder['deviation']			= $this->db->f('deviation');
-				$workorder['grants'] 				= (int)$this->grants[$this->db->f('user_id')];
+				$workorder = array
+				(
+					'id'					=> $this->db->f('id'),
+					'workorder_id'			=> $this->db->f('id'), // FIXME
+					'project_id'			=> $this->db->f('project_id'),
+					'title'					=> $this->db->f('title'),
+					'name'					=> $this->db->f('name'),
+					'key_fetch'				=> $this->db->f('key_fetch'),
+					'key_deliver'			=> $this->db->f('key_deliver'),
+					'key_responsible'		=> $this->db->f('key_responsible'),
+					'charge_tenant'			=> $this->db->f('charge_tenant'),
+					'descr'					=> stripslashes($this->db->f('descr')),
+					'status'				=> $this->db->f('status'),
+					'budget'				=> (int)$this->db->f('budget'),
+					'calculation'			=> $this->db->f('calculation'),
+					'b_account_id'			=> (int)$this->db->f('account_id'),
+					'addition_percentage'	=> (int)$this->db->f('addition'),
+					'addition_rs'			=> (int)$this->db->f('rig_addition'),
+					'act_mtrl_cost'			=> $this->db->f('act_mtrl_cost'),
+					'act_vendor_cost'		=> $this->db->f('act_vendor_cost'),
+					'user_id'				=> $this->db->f('user_id'),
+					'vendor_id'				=> $this->db->f('vendor_id'),
+					'coordinator'			=> $this->db->f('coordinator'),
+					'access'				=> $this->db->f('access'),
+					'start_date'			=> $this->db->f('start_date'),
+					'end_date'				=> $this->db->f('end_date'),
+					'cat_id'				=> $this->db->f('category'),
+					'chapter_id'			=> $this->db->f('chapter_id'),
+					'chapter'				=> $this->db->f('chapter'),
+					'deviation'				=> $this->db->f('deviation'),
+					'ecodimb'				=> $this->db->f('ecodimb'),
+					'location_code'			=> $this->db->f('location_code'),
+					'p_num'					=> $this->db->f('p_num'),
+					'p_entity_id'			=> $this->db->f('p_entity_id'),
+					'p_cat_id'				=> $this->db->f('p_cat_id'),
+					'contact_phone'			=> $this->db->f('contact_phone'),
+					'tenant_id'				=> $this->db->f('tenant_id'),
+					'cat_id'				=> $this->db->f('category'),
+					'grants'				=> (int)$this->grants[$this->db->f('user_id')]
+				);
 			}
 
 //_debug_array($workorder);
@@ -490,7 +607,9 @@
 
 		function project_budget_from_workorder($project_id = '')
 		{
-			$this->db->query("select budget, id as workorder_id from fm_workorder where project_id='$project_id'");
+			$project_id = (int) $project_id;
+			$this->db->query("select budget, id as workorder_id from fm_workorder WHERE project_id={$project_id}");
+			$budget = array();
 			while ($this->db->next_record())
 			{
 				$budget[] = array(
@@ -501,10 +620,133 @@
 			return $budget;
 		}
 
+		/**
+		* planned cost start out as the project budget - and reflect the amount yet to be spent on the project
+		* When an order is placed  - the "planned cost" is reduced with expected cost for that order.
+		* When an invoice is paid -  the "planned cost" is reduced with actual cost for that order (replace the expected cost).
+		*
+		* @param integer $project_id the project in question
+		*
+		* @return void
+		*/
+
+		function update_planned_cost($project_id)
+		{
+			$this->db->query("SELECT paid, paid_percent, act_mtrl_cost, act_vendor_cost, combined_cost, budget FROM fm_workorder WHERE project_id={$project_id}");
+			$workorders = array();
+			while ($this->db->next_record())
+			{
+				$workorders[] = array
+				(
+					'paid'			=> $this->db->f('paid'), //0-cancelled /1-invoice received but not paid / 2 - paid
+					'paid_percent'	=> $this->db->f('paid_percent')/100,
+					'actual_cost'	=> $this->db->f('act_mtrl_cost') + $this->db->f('act_vendor_cost'),
+					'cost'			=> abs($this->db->f('combined_cost')) > 0 ? $this->db->f('combined_cost') : $this->db->f('budget'),
+				);
+			}
+
+			$orded_or_paid = 0;
+
+			foreach($workorders as $workorder)
+			{
+				if($workorder['paid'] == 0 || $workorder['paid'] == 1)
+				{
+					$orded_or_paid = $orded_or_paid + $workorder['cost'];
+				}
+				else
+				{
+					if(!$workorder['paid_percent'])
+					{
+						$workorder['paid_percent'] = 1;
+					}
+					$orded_or_paid = $orded_or_paid + ($workorder['actual_cost']/$workorder['paid_percent']);
+				}
+			}
+
+            $this->db->query("SELECT budget, reserve FROM fm_project WHERE id={$project_id}"); 
+            $this->db->next_record(); 
+            $project_sum = $this->db->f('budget') + $this->db->f('reserve'); 
+
+			$project_planned_cost = round($project_sum - $orded_or_paid);
+
+			if($project_planned_cost < 0)
+			{
+				$project_planned_cost = 0;
+			}
+
+//_debug_array("UPDATE fm_project SET planned_cost = {$project_planned_cost} WHERE id = {$project_id}");
+			$this->db->query("UPDATE fm_project SET planned_cost = {$project_planned_cost} WHERE id = {$project_id}");
+		}
+
+		function update_actual_cost_global()
+		{
+			set_time_limit(1800);
+			$this->db->query("SELECT id FROM fm_workorder ORDER BY id ASC",__LINE__,__FILE__);
+			$workorders = array();
+			while ($this->db->next_record())
+			{
+				$workorders[] = $this->db->f('id');
+			}
+//_debug_array($workorders);die();
+
+			foreach ($workorders as $workorder_id)
+			{
+				$this->update_actual_cost($workorder_id);
+			}
+		}
+
+		function update_planned_cost_global()
+		{
+			set_time_limit(3600);
+			$this->db->query("SELECT id FROM fm_project ORDER BY id ASC",__LINE__,__FILE__);
+			$projects = array();
+			while ($this->db->next_record())
+			{
+				$projects[] = $this->db->f('id');
+			}
+//_debug_array($projects);die();
+
+			foreach ($projects as $project_id)
+		{
+				$this->update_planned_cost($project_id);
+			}
+		}
+
+		function update_actual_cost($workorder_id)
+		{
+			$this->db->query("SELECT godkjentbelop, dimd FROM fm_ecobilagoverf WHERE pmwrkord_code = {$workorder_id}",__LINE__,__FILE__);
+			$cost = array();
+			while ($this->db->next_record())
+			{
+				$cost[] = array
+				(
+					'godkjentbelop' => $this->db->f('godkjentbelop'),
+					'dimd' => $this->db->f('dimd'),
+				);
+			}
+			$act_mtrl_cost = 0;
+			$act_vendor_cost = 0;
+			foreach ($cost as $entry)
+			{
+				if($entry['dimd'] % 2 == 0)
+				{
+					$act_mtrl_cost = $act_mtrl_cost + $entry['godkjentbelop'];
+				}
+				else
+				{
+					$act_vendor_cost = $act_vendor_cost + $entry['godkjentbelop'];
+				}
+			}
+//_debug_array("UPDATE fm_workorder SET act_mtrl_cost = {$act_mtrl_cost}, act_vendor_cost = {$act_vendor_cost}  WHERE id = {$workorder_id}");
+			$this->db->query("UPDATE fm_workorder SET act_mtrl_cost = {$act_mtrl_cost}, act_vendor_cost = {$act_vendor_cost}  WHERE id = {$workorder_id}");
+
+		}
+
 		function branch_p_list($project_id = '')
 		{
-
-			$this->db2->query("SELECT branch_id from fm_projectbranch WHERE project_id='$project_id' ",__LINE__,__FILE__);
+			$project_id = (int) $project_id;
+			$this->db2->query("SELECT branch_id from fm_projectbranch WHERE project_id={$project_id}",__LINE__,__FILE__);
+			$selected = array();
 			while ($this->db2->next_record())
 			{
 				$selected[] = array('branch_id' => $this->db2->f('branch_id'));
@@ -520,17 +762,67 @@
 
 		function add($workorder)
 		{
+			$receipt = array();
 			$historylog	= CreateObject('property.historylog','workorder');
 			$workorder['descr'] = $this->db->db_addslashes($workorder['descr']);
 			$workorder['title'] = $this->db->db_addslashes($workorder['title']);
 
+			$cols = array();
+			$vals = array();
+
+			if (isset($workorder['extra']) && is_array($workorder['extra']))
+			{
+				foreach ($workorder['extra'] as $input_name => $value)
+				{
+					if($value)
+					{
+						$cols[] = $input_name;
+						$vals[] = $value;
+					}
+				}
+			}
+
+			if ($workorder['location_code'])
+			{
+				$cols[] = 'location_code';
+				$vals[] = $workorder['location_code'];
+
+				if($workorder['street_name'])
+				{
+					$address[]= $workorder['street_name'];
+					$address[]= $workorder['street_number'];
+					$address = $this->db->db_addslashes(implode(" ", $address));
+				}
+
+				if(!$address)
+				{
+					$address = $this->db->db_addslashes($workorder['location_name']);
+				}
+				$cols[] = 'address';
+				$vals[] = $address;
+			}
+
+			if($cols)
+			{
+				$cols	= "," . implode(",", $cols);
+				$vals	= ",'" . implode("','", $vals) . "'";
+			}
+			else
+			{
+				$cols = '';
+				$vals = '';
+			}
+
+			$this->db->transaction_begin();
+			$id = $this->next_id();
 			if(!$workorder['workorder_num'])
 			{
-				$workorder['workorder_num'] = $workorder['workorder_id'];
+				$workorder['workorder_num'] = $id;
 			}
 
-			$values= array(
-				$workorder['workorder_id'],
+			$values= array
+			(
+				$id,
 				$workorder['workorder_num'],
 				$workorder['project_id'],
 				$workorder['title'],
@@ -540,8 +832,8 @@
 				$workorder['end_date'],
 				$workorder['status'],
 				$workorder['descr'],
-				$workorder['budget'],
-				$workorder['budget'],
+				(int) $workorder['budget'],
+				(int) $workorder['budget'],
 				$workorder['b_account_id'],
 				$workorder['addition_rs'],
 				$workorder['addition_percentage'],
@@ -549,17 +841,18 @@
 				$workorder['key_fetch'],
 				$workorder['vendor_id'],
 				$workorder['charge_tenant'],
-				$this->account);
+				$this->account,
+				$workorder['ecodimb'],
+				$workorder['cat_id']
+			);
 
 			$values	= $this->bocommon->validate_db_insert($values);
 
-			$this->db->transaction_begin();
-
 			$this->db->query("INSERT INTO fm_workorder (id,num,project_id,title,access,entry_date,start_date,end_date,status,"
-				. "descr,budget,combined_cost,account_id,rig_addition,addition,key_deliver,key_fetch,vendor_id,charge_tenant,user_id) "
-				. "VALUES ( $values )",__LINE__,__FILE__);
+				. "descr,budget,combined_cost,account_id,rig_addition,addition,key_deliver,key_fetch,vendor_id,charge_tenant,user_id,ecodimb,category $cols) "
+				. "VALUES ( $values $vals)",__LINE__,__FILE__);
 
-			$this->db->query("INSERT INTO fm_orders (id,type) VALUES (" . $workorder['workorder_id'] . ",'workorder')");
+			$this->db->query("INSERT INTO fm_orders (id,type) VALUES ({$id},'workorder')");
 
 /*
 			if($workorder['charge_tenant'])
@@ -567,21 +860,41 @@
 				$this->db->query("UPDATE fm_project set charge_tenant = 1 WHERE id =" . $workorder['project_id']);
 			}
 */
+
+			if(is_array($workorder['origin']))
+			{
+				if($workorder['origin'][0]['data'][0]['id'])
+				{
+					$interlink_data = array
+					(
+						'location1_id'		=> $GLOBALS['phpgw']->locations->get_id('property', $workorder['origin'][0]['location']),
+						'location1_item_id' => $workorder['origin'][0]['data'][0]['id'],
+						'location2_id'		=> $GLOBALS['phpgw']->locations->get_id('property', '.project.workorder'),
+						'location2_item_id' => $id,
+						'account_id'		=> $this->account
+					);
+
+					$this->interlink->add($interlink_data,$this->db);
+				}
+			}
+
+
 			if($this->db->transaction_commit())
 			{
 				$this->increment_workorder_id();
-				$historylog->add('SO',$workorder['workorder_id'],$workorder['status']);
+				$historylog->add('SO', $id, $workorder['status']);
 				if ($workorder['remark'])
 				{
-					$historylog->add('RM',$workorder['workorder_id'],$workorder['remark']);
+					$historylog->add('RM', $id, $workorder['remark']);
 				}
 
-				$receipt['message'][] = array('msg'=>lang('workorder %1 has been saved',$workorder['workorder_id']));
+				$receipt['message'][] = array('msg'=>lang('workorder %1 has been saved', $id));
 			}
 			else
 			{
 				$receipt['error'][] = array('msg'=>lang('the workorder has not been saved'));
 			}
+			$receipt['id'] = $id;
 			return $receipt;
 		}
 
@@ -591,25 +904,26 @@
 			$workorder['descr'] = $this->db->db_addslashes($workorder['descr']);
 			$workorder['title'] = $this->db->db_addslashes($workorder['title']);
 
-			$this->db->query("SELECT status,budget,calculation FROM fm_workorder where id='" .$workorder['workorder_id']."'",__LINE__,__FILE__);
+			$this->db->query("SELECT status,budget,calculation FROM fm_workorder WHERE id = {$workorder['id']}",__LINE__,__FILE__);
 			$this->db->next_record();
 
+			$old_status = $this->db->f('status');
+			$old_budget = $this->db->f('budget');
+
 			if ($this->db->f('calculation') > 0)
 			{
-				$config	= CreateObject('phpgwapi.config');
+				$calculation = $this->db->f('calculation');
+				$config	= CreateObject('phpgwapi.config','property');
 				$config->read_repository();
 				$tax = 1+(($config->config_data['fm_tax'])/100);
-				$combined_cost = $this->db->f('calculation')* $tax;
+				$combined_cost = $calculation * $tax;
 			}
 			else
 			{
 				$combined_cost = $workorder['budget'];
 			}
 
-			$old_status = $this->db->f('status');
-			$old_budget = $this->db->f('budget');
-
-			$this->db->query("SELECT bilagsnr FROM fm_ecobilag where pmwrkord_code ='" .$workorder['workorder_id']."'",__LINE__,__FILE__);
+			$this->db->query("SELECT bilagsnr FROM fm_ecobilag WHERE pmwrkord_code ={$workorder['id']}",__LINE__,__FILE__);
 			$this->db->next_record();
 
 			if($this->db->f('bilagsnr'))
@@ -617,7 +931,7 @@
 				$paid = 1;
 			}
 
-			$this->db->query("SELECT bilagsnr FROM fm_ecobilagoverf where pmwrkord_code ='" .$workorder['workorder_id']."'",__LINE__,__FILE__);
+			$this->db->query("SELECT bilagsnr FROM fm_ecobilagoverf where pmwrkord_code = {$workorder['id']}",__LINE__,__FILE__);
 			$this->db->next_record();
 			if($this->db->f('bilagsnr'))
 			{
@@ -625,7 +939,8 @@
 			}
 
 
-			$value_set=array(
+			$value_set=array
+			(
 				'title'			=> $workorder['title'],
 				'status'		=> $workorder['status'],
 				'start_date'		=> $workorder['start_date'],
@@ -639,61 +954,145 @@
 				'rig_addition'		=> $workorder['addition_rs'],
 				'addition'		=> $workorder['addition_percentage'],
 				'charge_tenant'		=> $workorder['charge_tenant'],
-				'vendor_id'		=> $workorder['vendor_id']
+				'vendor_id'		=> $workorder['vendor_id'],
+				'ecodimb'		=> $workorder['ecodimb'],
+				'category'		=> $workorder['cat_id']
 				);
 
 			if($workorder['status'] == 'closed')
 			{
 				$value_set['paid'] = $paid = (isset($paid)?$paid:0);
+				$value_set['paid_percent'] = 100;
 			}
 
+			if (isset($workorder['extra']) && is_array($workorder['extra']))
+			{
+				foreach ($workorder['extra'] as $input_name => $value)
+				{
+					$value_set[$input_name] = $value;
+				}
+			}
+
+			if ($workorder['location_code'])
+			{
+				$value_set['location_code'] = $workorder['location_code'];
+
+				if($workorder['street_name'])
+				{
+					$address[]= $workorder['street_name'];
+					$address[]= $workorder['street_number'];
+					$address = $this->db->db_addslashes(implode(" ", $address));
+				}
+
+				if(!isset($address) || !$address)
+				{
+					$address = $this->db->db_addslashes($workorder['location_name']);
+				}
+
+				$value_set['address'] = $address;
+			}
+
 			$value_set	= $this->bocommon->validate_db_update($value_set);
 
 			$this->db->transaction_begin();
 
-			$this->db->query("UPDATE fm_workorder set $value_set WHERE id=" . $workorder['workorder_id'] ,__LINE__,__FILE__);
+			$this->db->query("UPDATE fm_workorder set $value_set WHERE id= {$workorder['id']}" ,__LINE__,__FILE__);
 
 /*			if($workorder['charge_tenant'])
 			{
 				$this->db->query("UPDATE fm_project set charge_tenant = 1 WHERE id =" . $workorder['project_id']);
 			}
 */
-			if($this->db->transaction_commit())
-			{
+			$this->update_planned_cost($workorder['project_id']); // at project
+
+			$check_pending_action = false;
 				if ($old_status != $workorder['status'])
 				{
-					$historylog->add('S',$workorder['workorder_id'],$workorder['status']);
+					$historylog->add('S',$workorder['id'],$workorder['status'], $old_status);
 					$receipt['notice_owner'][]=lang('Status changed') . ': ' . $workorder['status'];
+					$check_pending_action = true;
 				}
 				elseif($workorder['confirm_status'])
 				{
-					$historylog->add('SC',$workorder['workorder_id'],$workorder['status']);
+					$check_pending_action = true;
+					$historylog->add('SC',$workorder['id'],$workorder['status'], $old_status);
 					$receipt['notice_owner'][]=lang('Status confirmed') . ': ' . $workorder['status'];
 				}
 
+				if( $check_pending_action )
+				{
+					$this->db->query("SELECT * FROM fm_workorder_status WHERE id = '{$workorder['status']}'");
+
+					$this->db->next_record();
+
+ 					if ($this->db->f('approved') )
+ 					{
+ 						$action_params = array
+						(
+							'appname'			=> 'property',
+							'location'			=> '.project.workorder',
+							'id'				=> $workorder['id'],
+							'responsible'		=> $this->account,
+							'responsible_type'  => 'user',
+							'action'			=> 'approval',
+							'remark'			=> '',
+							'deadline'			=> ''
+						);
+
+						execMethod('property.sopending_action.close_pending_action', $action_params);
+						unset($action_params);
+ 					}
+ 					if ($this->db->f('in_progress') )
+ 					{
+ 						$action_params = array
+						(
+							'appname'			=> 'property',
+							'location'			=> '.project.workorder',
+							'id'				=> $workorder['id'],
+							'responsible'		=> $workorder['vendor_id'],
+							'responsible_type'  => 'vendor',
+							'action'			=> 'remind',
+							'remark'			=> '',
+							'deadline'			=> ''
+						);
+
+						execMethod('property.sopending_action.close_pending_action', $action_params);
+						unset($action_params);
+
+ 					}
+ 					if ($this->db->f('delivered') )
+ 					{
+ 						//close
+ 					}
+				}
+
 				if ($old_budget != $workorder['budget'])
 				{
-					$historylog->add('B',$workorder['workorder_id'],$workorder['budget']);
+					$historylog->add('B', $workorder['id'], $workorder['budget'], $old_budget);
 				}
 
 				if ($workorder['remark'])
 				{
-					$historylog->add('RM',$workorder['workorder_id'],$workorder['remark']);
+					$historylog->add('RM', $workorder['id'], $workorder['remark']);
 				}
+			if($this->db->transaction_commit())
+			{
 
-				$receipt['message'][] = array('msg'=>lang('workorder %1 has been edited',$workorder['workorder_id']));
+				$receipt['message'][] = array('msg'=>lang('workorder %1 has been edited', $workorder['id']));
 			}
 			else
 			{
-				$receipt['error'][] = array('msg'=>lang('workorder %1 has not been edited',$workorder['workorder_id']));
+				$receipt['error'][] = array('msg'=>lang('workorder %1 has not been edited', $workorder['id']));
 			}
 
+			$receipt['id'] = $workorder['id'];
 			return $receipt;
 		}
 
 		function delete($workorder_id )
 		{
 			$this->db->transaction_begin();
+			$this->interlink->delete_at_target('property', '.project.workorder', $workorder_id, $this->db);
 			$this->db->query("DELETE FROM fm_workorder WHERE id='" . $workorder_id . "'",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM fm_workorder_history  WHERE  history_record_id='" . $workorder_id   . "'",__LINE__,__FILE__);
 			$this->db->query("DELETE FROM fm_wo_hours WHERE workorder_id='" . $workorder_id   . "'",__LINE__,__FILE__);
@@ -702,4 +1101,3 @@
 
 		}
 	}
-

Added: people/sigurdne/modules/property/trunk/inc/class.test.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.test.inc.php	                        (rev 0)
+++ people/sigurdne/modules/property/trunk/inc/class.test.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -0,0 +1,83 @@
+<?php
+	/**
+	* phpGroupWare - property: a Facilities Management System.
+	*
+	* @author Sigurd Nes <[email protected]>
+	* @copyright Copyright (C) 2009 Free Software Foundation, Inc. http://www.fsf.org/
+	* This file is part of phpGroupWare.
+	*
+	* phpGroupWare is free software; you can redistribute it and/or modify
+	* it under the terms of the GNU General Public License as published by
+	* the Free Software Foundation; either version 2 of the License, or
+	* (at your option) any later version.
+	*
+	* phpGroupWare is distributed in the hope that it will be useful,
+	* but WITHOUT ANY WARRANTY; without even the implied warranty of
+	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	* GNU General Public License for more details.
+	*
+	* You should have received a copy of the GNU General Public License
+	* along with phpGroupWare; if not, write to the Free Software
+	* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+	*
+	* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
+	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
+	* @package property
+	* @subpackage test
+ 	* @version $Id$
+	*/
+
+
+	/**
+	 * Description
+	 * @package property
+	 */
+
+	class property_test
+	{
+		var $public_functions = array
+		(
+			'date' => true
+		);
+
+		function __construct()
+		{
+		  	$GLOBALS['phpgw']->css->add_external_file('rental/templates/base/css/base.css');
+		}
+
+		function date()
+		{
+			$date1 = date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+
+			$start_field = $GLOBALS['phpgw']->yuical->add_listener('start_date', $date1);
+			$end_field = $GLOBALS['phpgw']->yuical->add_listener('end_date');
+
+			//Only if not xslt_app
+			$GLOBALS['phpgw']->common->phpgw_header(true);
+
+			$html = <<<HTML
+			<div class="yui-content">
+				<div class="details">
+					<form action="#" method="post">
+						<dl class="proplist-col">
+							<dt>
+								<label for="name">Gjelder fra</label>
+							</dt>
+							<dd>
+								{$start_field}
+							</dd>
+							<dt>
+								<label for="name">Gjelder til</label>
+							</dt>
+							<dd>
+								{$end_field}
+							</dd>
+					</form>
+				</div>
+			</div>
+HTML;
+
+			echo $html;
+//			$GLOBALS['phpgw']->common->phpgw_exit();
+		}
+	}


Property changes on: people/sigurdne/modules/property/trunk/inc/class.test.inc.php
___________________________________________________________________
Added: svn:keywords
   + Id Revision

Modified: people/sigurdne/modules/property/trunk/inc/class.uiXport.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiXport.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.uiXport.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -252,6 +252,7 @@
 					}
 					else
 					{
+						$GLOBALS['phpgw_info']['flags']['noframework'] = true;
 						$this->debug_import($buffer,$invoice_common);
 						return;
 					}
@@ -455,7 +456,7 @@
 
 			);
 
-			$vendor	= $this->contacts->read_single($table[0]['spvend_code'], array('attributes'=>array(array('column_name' => 'org_name'))));
+			$vendor	= $this->contacts->read_single($invoice_common['vendor_id'], array('attributes'=>array(array('column_name' => 'org_name'))));
 
 			foreach($vendor['attributes'] as $attribute)
 			{
@@ -468,24 +469,23 @@
 
 			$data = array
 			(
-				'artid'							=> $table[0]['artid'],
+				'artid'							=> $invoice_common['art'],
 				'lang_type'						=> lang('Type'),
-				'artid'							=> $table[0]['artid'],
 				'lang_bilagsnr'					=> lang('bilagsnr'),
-				'bilagsnr'						=> $table[0]['bilagsnr'],
+				'bilagsnr'						=> $invoice_common['bilagsnr'],
 				'lang_vendor'					=> lang('Vendor'),
 				'vendor_name'					=> $vendor_name,
-				'spvend_code'					=> $table[0]['spvend_code'],
+				'spvend_code'					=> $invoice_common['vendor_id'],
 				'lang_fakturadato'				=> lang('invoice date'),
-				'fakturadato'					=> $table[0]['fakturadato'],
+				'fakturadato'					=> $invoice_common['invoice_date'],
 				'lang_forfallsdato'				=> lang('Payment date'),
 				'forfallsdato'					=> $table[0]['forfallsdato'],
 				'lang_janitor'					=> lang('Janitor'),
-				'oppsynsmannid'					=> $table[0]['oppsynsmannid'],
+				'oppsynsmannid'					=> $invoice_common['janitor'],
 				'lang_supervisor'				=> lang('Supervisor'),
-				'saksbehandlerid'				=> $table[0]['saksbehandlerid'],
+				'saksbehandlerid'				=> $invoice_common['supervisor'],
 				'lang_budget_responsible'		=> lang('Budget Responsible'),
-				'budsjettansvarligid'			=> $table[0]['budsjettansvarligid'],
+				'budsjettansvarligid'			=> $invoice_common['budget_responsible'],
 				'lang_sum'						=> lang('Sum'),
 				'sum'							=> number_format($sum, 2, ',', ''),
 				'table_header'					=> $table_header,

Modified: people/sigurdne/modules/property/trunk/inc/class.uiactor.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiactor.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.uiactor.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -24,9 +24,11 @@
 	* @internal Development of this application was funded by http://www.bergen.kommune.no/bbb_/ekstern/
 	* @package property
 	* @subpackage admin
- 	* @version $Id$
+ 	* @version $Id$
 	*/
 
+	phpgw::import_class('phpgwapi.yui');
+
 	/**
 	 * uiactor class
 	 *
@@ -58,13 +60,13 @@
 
 		function property_uiactor()
 		{
+			$GLOBALS['phpgw_info']['flags']['nonavbar'] = true; // menus added where needed via bocommon::get_menu
 			$GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
 
-			$this->nextmatchs		= CreateObject('phpgwapi.nextmatchs');
 			$this->account			= $GLOBALS['phpgw_info']['user']['account_id'];
 
 			$this->bo				= CreateObject('property.boactor',true);
-			$this->bocommon			= CreateObject('property.bocommon');
+			$this->bocommon 		= & $this->bo->bocommon;
 
 			$this->role				= $this->bo->role;
 
@@ -127,6 +129,10 @@
 
 		function columns()
 		{
+
+			//cramirez: necesary for windows.open . Avoid error JS
+   			phpgwapi_yui::load_widget('tabview');
+
 			$GLOBALS['phpgw']->xslttpl->add_file(array('columns'));
 			$GLOBALS['phpgw_info']['flags']['noframework'] = true;
 			$values	= phpgw::get_var('values');
@@ -134,7 +140,7 @@
 			if ($values['save'])
 			{
 				$GLOBALS['phpgw']->preferences->account_id=$this->account;
-				$GLOBALS['phpgw']->preferences->read_repository();
+				$GLOBALS['phpgw']->preferences->read();
 				$GLOBALS['phpgw']->preferences->add('property','actor_columns_' .$this->role,$values['columns'],'user');
 				$GLOBALS['phpgw']->preferences->save_repository();
 
@@ -183,190 +189,447 @@
 				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=>1, 'acl_location'=> $this->acl_location));
 			}
 
-			$GLOBALS['phpgw']->xslttpl->add_file(array('actor',
-										'receipt',
-										'search_field',
-										'nextmatchs',
-										'filter_member_of'));
+			$dry_run=false;
+			$lookup = ''; //Fix this
+
+			$datatable = array();
+			$values_combo_box = array();
 
 			$receipt = $GLOBALS['phpgw']->session->appsession('session_data','actor_receipt_' . $this->role);
 			$GLOBALS['phpgw']->session->appsession('session_data','actor_receipt_' . $this->role,'');
 
-			$list = $this->bo->read();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			 {
+
+				if(!$lookup)
+				{
+					$datatable['menu']	= $this->bocommon->get_menu();
+				}
+
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    				(
+	    							'menuaction'=> 'property.uiactor.index',
+									'lookup'    => $lookup,
+									'cat_id'	=>$this->cat_id,
+									'query'		=>$this->query,
+									'role'		=> $this->role,
+									'member_id'	=> $this->member_id
+
+	    				));
+	    		$datatable['config']['allow_allrows'] = true;
+
+				$datatable['config']['base_java_url'] = "menuaction:'property.uiactor.index',"
+
+	    											."lookup:'{$lookup}',"
+	    											."query:'{$this->query}',"
+													."cat_id:'{$this->cat_id}',"
+						 	                        ."role:'{$this->role}',"
+						 	                        ."member_id:'{$this->member_id}'";
+                //die(_debug_array($datatable));
+
+				$values_combo_box[0]  = $this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' => true));
+				$default_value = array ('cat_id'=>'','name'=>lang('no member'));
+				array_unshift ($values_combo_box[0]['cat_list'],$default_value);
+
+				$values_combo_box[1] = $this->bocommon->select_category_list(array('format'=>'filter','selected' => $this->cat_id,'type' => $this->role,'order'=>'descr'));
+				$default_value = array ('id'=>'','name'=> lang('no category'));
+				array_unshift ($values_combo_box[1],$default_value);
+
+				$datatable['actions']['form'] = array(
+					array(
+						'action'	=> $GLOBALS['phpgw']->link('/index.php',
+								array(
+									'menuaction' 		=> 'property.uiactor.index',
+									'lookup'        		=> $lookup,
+									'cat_id'	=> $this->cat_id,
+									'query'		=> $this->query,
+									'role'		=> $this->role,
+									'member_id'	=> $this->member_id
+								)
+							),
+						'fields'	=> array(
+                                    	'field' => array(
+			                                        array(
+			                                            'id' => 'btn_member_id',
+			                                            'name' => 'member_id',
+			                                            'value'	=> lang('Member'),
+			                                            'type' => 'button',
+			                                            'style' => 'filter',
+			                                            'tab_index' => 1
+			                                        ),
+			                                        array(
+			                                            'id' => 'btn_cat_id',
+			                                            'name' => 'cat_id',
+			                                            'value'	=> lang('Category'),
+			                                            'type' => 'button',
+			                                            'style' => 'filter',
+			                                            'tab_index' => 2
+			                                        ),
+													array(
+										                'type'=> 'link',
+										                'id'  => 'btn_columns',
+										                'url' => "Javascript:window.open('".$GLOBALS['phpgw']->link('/index.php',
+										                       array(
+										                           'menuaction' => 'property.uiactor.columns',
+										                           'role'		=> $this->role
+										                           ))."','','width=350,height=370')",
+										                 'value' => lang('columns'),
+										                 'tab_index' => 6
+										            ),
+													array(
+						                                'type'	=> 'button',
+						                            	'id'	=> 'btn_new',
+						                                'value'	=> lang('add'),
+						                                'tab_index' => 5
+						                            ),
+			                                        array( //boton     SEARCH
+			                                            'id' => 'btn_search',
+			                                            'name' => 'search',
+			                                            'value'    => lang('search'),
+			                                            'type' => 'button',
+			                                            'tab_index' => 4
+			                                        ),
+			   										array( // TEXT IMPUT
+			                                            'name'     => 'query',
+			                                            'id'     => 'txt_query',
+			                                            'value'    => '',//$query,
+			                                            'type' => 'text',
+			                                            'onkeypress' => 'return pulsar(event)',
+			                                            'size'    => 28,
+			                                            'tab_index' => 3
+			                                        )
+		                           				),
+		                       		'hidden_value' => array(
+					                                        array( //div values  combo_box_0
+							                                            'id' => 'values_combo_box_0',
+							                                            'value'	=> $this->bocommon->select2String($values_combo_box[0]['cat_list'], 'cat_id') //i.e.  id,value/id,vale/
+							                                      ),
+							                                array( //div values  combo_box_1
+							                                            'id' => 'values_combo_box_1',
+							                                            'value'	=> $this->bocommon->select2String($values_combo_box[1])
+							                                      )
+		                       								)
+												)
+										  )
+				);
+
+				if($this->role == 'tenant')
+				{
+					unset($datatable['actions']['form'][0]['fields']['field'][0]);
+				}
+
+				if(!$this->acl_add)
+				{
+					unset($datatable['actions']['form'][0]['fields']['field'][3]);
+				}
+				$dry_run=true;
+			}
+
+			$actor_list = array();
+			$actor_list = $this->bo->read($dry_run);
+
+			//echo $dry_run; count($actor_list); die(_debug_array($actor_list));
 
 			$uicols	= $this->bo->uicols;
 
 			$j=0;
-
-			if (isset($list) AND is_array($list))
+			if (isset($actor_list) && is_array($actor_list))
 			{
-				foreach($list as $entry)
+				foreach($actor_list as $actor)
 				{
 					for ($i=0;$i<count($uicols['name']);$i++)
 					{
 						if($uicols['input_type'][$i]!='hidden')
 						{
-							$content[$j]['row'][$i]['value'] = $entry[$uicols['name'][$i]];
-							$content[$j]['row'][$i]['name'] = $uicols['name'][$i];
-						}
-					}
-
-					if($this->acl_read)
+							if(isset($actor['query_location'][$uicols['name'][$i]]))
 					{
-						$content[$j]['row'][$i]['statustext']	= lang('view the entity');
-						$content[$j]['row'][$i]['text']		= lang('view');
-						$content[$j]['row'][$i++]['link']	= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiactor.view', 'actor_id'=> $entry['id'], 'role'=> $this->role));
+								$datatable['rows']['row'][$j]['column'][$i]['name'] 			= $uicols['name'][$i];
+								$datatable['rows']['row'][$j]['column'][$i]['statustext']		= lang('search');
+								$datatable['rows']['row'][$j]['column'][$i]['value']			= $actor[$uicols['name'][$i]];
+								$datatable['rows']['row'][$j]['column'][$i]['format'] 			= 'link';
+								$datatable['rows']['row'][$j]['column'][$i]['java_link']		= true;
+								$datatable['rows']['row'][$j]['column'][$i]['link']				= $actor['query_location'][$uicols['name'][$i]];
 					}
-					if($this->acl_edit)
+							else
 					{
-						$content[$j]['row'][$i]['statustext']	= lang('edit the actor');
-						$content[$j]['row'][$i]['text']		= lang('edit');
-						$content[$j]['row'][$i++]['link']	= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiactor.edit', 'actor_id'=> $entry['id'], 'role'=> $this->role));
+								$datatable['rows']['row'][$j]['column'][$i]['value'] 			= $actor[$uicols['name'][$i]];
+								$datatable['rows']['row'][$j]['column'][$i]['name'] 			= $uicols['name'][$i];
+								$datatable['rows']['row'][$j]['column'][$i]['lookup'] 			= $lookup;
+								$datatable['rows']['row'][$j]['column'][$i]['align'] 			= (isset($uicols['align'][$i])?$uicols['align'][$i]:'center');
+
+								if(isset($uicols['datatype']) && isset($uicols['datatype'][$i]) && $uicols['datatype'][$i]=='link' && $actor[$uicols['name'][$i]])
+								{
+									$datatable['rows']['row'][$j]['column'][$i]['value']		= lang('link');
+									$datatable['rows']['row'][$j]['column'][$i]['link']		= $actor[$uicols['name'][$i]];
+									$datatable['rows']['row'][$j]['column'][$i]['target']	= '_blank';
 					}
-					if($this->acl_delete)
+							}
+						}
+						else
 					{
-						$content[$j]['row'][$i]['statustext']	= lang('delete the actor');
-						$content[$j]['row'][$i]['text']		= lang('delete');
-						$content[$j]['row'][$i++]['link']	= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiactor.delete', 'actor_id'=> $entry['id'], 'role'=> $this->role));
+								$datatable['rows']['row'][$j]['column'][$i]['name'] 			= $uicols['name'][$i];
+								$datatable['rows']['row'][$j]['column'][$i]['value']			= $actor[$uicols['name'][$i]];
+						}
+
+						$datatable['rows']['row'][$j]['hidden'][$i]['value'] 			= $actor[$uicols['name'][$i]];
+						$datatable['rows']['row'][$j]['hidden'][$i]['name'] 			= $uicols['name'][$i];
 					}
 
 					$j++;
 				}
 			}
 
-//html_print_r($content);
-			for ($i=0;$i<count($uicols['descr']);$i++)
-			{
-				if($uicols['input_type'][$i]!='hidden')
-				{
-					$table_header[$i]['header'] 	= $uicols['descr'][$i];
-					$table_header[$i]['width'] 		= '5%';
-					$table_header[$i]['align'] 		= 'center';
-					if(isset($uicols['datatype'][$i]) && $uicols['datatype'][$i]!='T' && $uicols['datatype'][$i]!='CH')
+			// NO pop-up
+			$datatable['rowactions']['action'] = array();
+			if(!$lookup)
 					{
-						$table_header[$i]['sort_link']	=true;
-						$table_header[$i]['sort'] 		= $this->nextmatchs->show_sort_order(array
+				$parameters = array
 							(
-								'sort'	=> $this->sort,
-								'var'	=> $uicols['name'][$i],
-								'order'	=> $this->order,
-								'extra'	=> array('menuaction'	=> 'property.uiactor.index',
-													'query'		=> $this->query,
-													'role'		=> $this->role,
-													'member_id'	=> $this->member_id
+					'parameter' => array
+					(
+						array
+						(
+							'name'		=> 'actor_id',
+							'source'	=> 'id'
 												)
-							));
-					}
-				}
-			}
+					)
+				);
 
 			if($this->acl_read)
 			{
-				$table_header[$i]['width'] 	= '5%';
-				$table_header[$i]['align'] 	= 'center';
-				$table_header[$i]['header']	= lang('view');
-				$i++;
+					$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'view',
+						'text' 			=> lang('view'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+										(
+											'menuaction'	=> 'property.uiactor.view',
+											'role'	=> $this->role
+										)),
+						'parameters'	=> $parameters
+					);
+					$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'view',
+						'text' 			=> lang('open view in new window'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+										(
+											'menuaction'	=> 'property.uiactor.view',
+											'role'			=> $this->role,
+											'target'		=> '_blank'
+										)),
+						'parameters'	=> $parameters
+					);
 			}
 			if($this->acl_edit)
 			{
-				$table_header[$i]['width'] 	= '5%';
-				$table_header[$i]['align'] 	= 'center';
-				$table_header[$i]['header']	= lang('edit');
-				$i++;
+					$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'edit',
+						'text' 			=> lang('edit'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+										(
+											'menuaction'	=> 'property.uiactor.edit',
+											'role'	=> $this->role
+										)),
+						'parameters'	=> $parameters
+					);
+					$datatable['rowactions']['action'][] = array(
+						'my_name' 		=> 'edit',
+						'text' 			=> lang('open edit in new window'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+										(
+											'menuaction'	=> 'property.uiactor.edit',
+											'role'			=> $this->role,
+											'target'		=> '_blank'
+										)),
+						'parameters'	=> $parameters
+					);
 			}
 			if($this->acl_delete)
 			{
-				$table_header[$i]['width'] 	= '5%';
-				$table_header[$i]['align'] 	= 'center';
-				$table_header[$i]['header']	= lang('delete');
-				$i++;
+					$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'delete',
+						'text' 			=> lang('delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+										(
+											'menuaction'	=> 'property.uiactor.delete',
+											'role'	=> $this->role
+										)),
+						'parameters'	=> $parameters
+					);
 			}
-
 			if($this->acl_add)
 			{
-				$table_add = array
+					$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'text' 			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
 				(
-					'lang_add'		=> lang('add'),
-					'lang_add_statustext'	=> lang('add an actor'),
-					'add_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiactor.edit', 'role'=> $this->role))
+												'menuaction'	=> 'property.uiactor.edit',
+												'role'	=> $this->role
+											))
 				);
 			}
+				unset($parameters);
+			}
 
-			$link_data = array
-			(
-				'menuaction'	=> 'property.uiactor.index',
-				'sort'		=>$this->sort,
-				'order'		=>$this->order,
-				'cat_id'	=>$this->cat_id,
-				'filter'	=>$this->filter,
-				'query'		=>$this->query,
-				'role'		=> $this->role,
-				'member_id'	=> $this->member_id
-			);
+			$uicols_count	= count($uicols['descr']);
 
-			if(!$this->allrows)
+			for ($i=0;$i<$uicols_count;$i++)
 			{
-				$record_limit	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+
+				//all colums should be have formatter
+				$datatable['headers']['header'][$i]['formatter'] = ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['format'] 			= $this->bocommon->translate_datatype_format($uicols['datatype'][$i]);
+					$datatable['headers']['header'][$i]['sortable']			= false;
+
+					if(isset($uicols['datatype'][$i]) && $uicols['datatype'][$i]!='T' && $uicols['datatype'][$i]!='CH')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= $uicols['name'][$i];
+					}
 			}
 			else
 			{
-				$record_limit	= $this->bo->total_records;
+					$datatable['headers']['header'][$i]['name'] 			= 'id2';
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= false;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					$datatable['headers']['header'][$i]['format'] 			= 'hidden';
+				}
 			}
 
-			$msgbox_data = $this->bocommon->msgbox_data($receipt);
+			// path for property.js
+			$datatable['property_js'] =  $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned'] = count($actor_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
 
-			$link_columns = array
+			//$datatable['sorting']['order'] 	= phpgw::get_var('order', 'string'); // Column
+			//$datatable['sorting']['sort'] 	= phpgw::get_var('sort', 'string'); // ASC / DESC
+
+			if($this->role == 'tenant')
+			{
+				if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+				{
+					$datatable['sorting']['order'] 			= 'first_name'; // name key Column in myColumnDef
+					$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+				}
+				else
+				{
+					$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+					$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+				}
+			}
+			else
+			{
+				if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+				{
+					$datatable['sorting']['order'] 			= 'org_name'; // name key Column in myColumnDef
+					$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+				}
+				else
+				{
+					$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+					$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+				}
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	//// cramirez: necesary for include a partucular js
+		  	phpgwapi_yui::load_widget('loader');
+		  	//cramirez: necesary for use opener . Avoid error JS
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			//FIXME this one is only needed when $lookup==true - so there is probably an error
+			phpgwapi_yui::load_widget('animation');
+
+//-- BEGIN----------------------------- JSON CODE ------------------------------
+
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
 			(
-				'menuaction' 	=> 'property.uiactor.columns',
-				'role'		=> $this->role
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
 			);
 
-			$member_of_data	= $this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' => true, 'link_data' =>$link_data));
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  $json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			 $json['records'][] = $json_row;
+	    			}
+	    		}
 
-			$GLOBALS['phpgw']->js->validate_file('overlib','overlib','property');
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
 
-			$data = array
-			(
-				'menu'							=> $this->bocommon->get_menu(),
-				'lang_columns'						=> lang('columns'),
-				'link_columns'						=> $GLOBALS['phpgw']->link('/index.php',$link_columns),
-				'lang_columns_help'					=> lang('Choose columns'),
-				'msgbox_data'						=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
-				'links'								=> $links,
- 				'allow_allrows'						=> false,
-				'allrows'							=> $this->allrows,
-				'start_record'						=> $this->start,
-				'record_limit'						=> $record_limit,
-				'num_records'						=> count($list),
- 				'all_records'						=> $this->bo->total_records,
-				'link_url'							=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'img_path'							=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
-				'lang_no_cat'						=> lang('no category'),
-				'lang_cat_statustext'				=> lang('Select the category the actor belongs to. To do not use a category select NO CATEGORY'),
-				'select_name'						=> 'cat_id',
-				'cat_list'							=> $this->bocommon->select_category_list(array('format'=>'filter','selected' => $this->cat_id,'type' => $this->role,'order'=>'descr')),
+	    		return $json;
+			}
+//-------------------- JSON CODE ----------------------
 
-				'select_action'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
 
-				'lang_no_member'					=> lang('no member'),
-				'member_of_name'					=> 'member_id',
-				'member_of_list'					=> $member_of_data['cat_list'],
+			// Prepare template variables and process XSLT
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
 
-				'filter_list'						=> $this->nextmatchs->xslt_filter(array('filter' => $this->filter)),
-				'lang_filter_statustext'			=> lang('Select the filter. To show all entries select SHOW ALL'),
-				'lang_searchfield_statustext'		=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
-				'lang_searchbutton_statustext'		=> lang('Submit the search string'),
-				'query'								=> $this->query,
-				'lang_search'						=> lang('search'),
-				'table_header'						=> $table_header,
-				'values'							=> $content,
-				'table_add'							=> $table_add
-			);
-			$this->save_sessiondata();
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+			// Prepare CSS Style
+		  	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+
+			//Title of Page
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('actor') . ': ' . lang('list ' . $this->role);
 
-			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
+	  		// Prepare YUI Library
+  			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'actor.index', 'property' );
+
+			//$this->save_sessiondata();
 		}
 
 		function edit()
@@ -411,6 +674,11 @@
 				if ((isset($values['save']) && $values['save']) || (isset($values['apply']) && $values['apply']))
 				{
 
+					if($GLOBALS['phpgw']->session->is_repost())
+					{
+						$receipt['error'][]=array('msg'=>lang('Hmm... looks like a repost!'));
+					}
+
 					if(!isset($values['cat_id']) || !$values['cat_id'])
 					{
 						$receipt['error'][]=array('msg'=>lang('Please select a category !'));
@@ -453,18 +721,18 @@
 			}
 
 
-			$actor = $this->bo->read_single(array('actor_id'=>$actor_id));
+			$values = $this->bo->read_single(array('actor_id'=>$actor_id));
 
 			/* Preserve attribute values from post */
 			if(isset($receipt['error']) && (isset( $values_attribute) && is_array( $values_attribute)))
 			{
-				$actor = $this->bo->preserve_attribute_values($actor,$values_attribute);
+				$values = $this->bo->preserve_attribute_values($values,$values_attribute);
 			}
 
 			if ($actor_id)
 			{
-				$this->cat_id = ($actor['cat_id']?$actor['cat_id']:$this->cat_id);
-				$this->member_id = ($actor['member_of']?$actor['member_of']:$this->member_id);
+				$this->cat_id = ($values['cat_id']?$values['cat_id']:$this->cat_id);
+				$this->member_id = ($values['member_of']?$values['member_of']:$this->member_id);
 			}
 
 			$link_data = array
@@ -474,41 +742,52 @@
 				'role'		=> $this->role
 			);
 
-			$dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-			$sep = '/';
-			$dlarr[strpos($dateformat,'y')] = 'yyyy';
-			$dlarr[strpos($dateformat,'m')] = 'MM';
-			$dlarr[strpos($dateformat,'d')] = 'DD';
-			ksort($dlarr);
 
-			$dateformat= (implode($sep,$dlarr));
+			$msgbox_data = $this->bocommon->msgbox_data($receipt);
+
+			$member_of_data	= $this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' => true, 'link_data' =>array()));
+
+			$tabs = array();
 
-			switch(substr($dateformat,0,1))
+			if (isset($values['attributes']) && is_array($values['attributes']))
+			{
+				foreach ($values['attributes'] as & $attribute)
 			{
-				case 'M':
-					$dateformat_validate= "javascript:vDateType='1'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'1')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'1')";
-					break;
-				case 'y':
-					$dateformat_validate="javascript:vDateType='2'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'2')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'2')";
-					break;
-				case 'D':
-					$dateformat_validate="javascript:vDateType='3'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'3')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'3')";
-					break;
+					if($attribute['history'] == true)
+					{
+						$link_history_data = array
+						(
+							'menuaction'	=> 'property.uiactor.attrib_history',
+							'attrib_id'	=> $attribute['id'],
+							'actor_id'	=> $actor_id,
+							'role'		=> $this->role,
+							'edit'		=> true
+						);
+
+						$attribute['link_history'] = $GLOBALS['phpgw']->link('/index.php',$link_history_data);
+					}
 			}
 
-			$msgbox_data = $this->bocommon->msgbox_data($receipt);
+				phpgwapi_yui::tabview_setup('actor_edit_tabview');
+				$tabs['general']	= array('label' => lang('general'), 'link' => '#general');
 
-			$member_of_data	= $this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' => true, 'link_data' =>array()));
+				$location = $this->acl_location;
+				$attributes_groups = $this->bo->get_attribute_groups($location, $values['attributes']);
 
-			$GLOBALS['phpgw']->js->validate_file('dateformat','dateformat','property');
+				$attributes = array();
+				foreach ($attributes_groups as $group)
+				{
+					if(isset($group['attributes']))
+					{
+						$tabs[str_replace(' ', '_', $group['name'])] = array('label' => $group['name'], 'link' => '#' . str_replace(' ', '_', $group['name']));
+						$group['link'] = str_replace(' ', '_', $group['name']);
+						$attributes[] = $group;
+					}
+				}
+				unset($attributes_groups);
+				unset($values['attributes']);
+			}
 
-//_debug_array($member_of_data);
 			$data = array
 			(
 				'msgbox_data'					=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
@@ -519,7 +798,7 @@
 				'lang_save'						=> lang('save'),
 				'lang_cancel'					=> lang('cancel'),
 				'lang_apply'					=> lang('apply'),
-	//			'value_cat'						=> $actor['cat'],
+	//			'value_cat'						=> $values['cat'],
 				'lang_id_statustext'			=> lang('Choose an ID'),
 				'lang_apply_statustext'			=> lang('Apply the values'),
 				'lang_cancel_statustext'		=> lang('Leave the actor untouched and return back to the list'),
@@ -533,35 +812,39 @@
 				'member_of_name'				=> 'member_id',
 				'member_of_list'				=> $member_of_data['cat_list'],
 
-				'lang_dateformat' 				=> lang(strtolower($dateformat)),
-				'dateformat_validate'			=> $dateformat_validate,
-				'onKeyUp'						=> $onKeyUp,
-				'onBlur'						=> $onBlur,
 				'lang_attributes'				=> lang('Attributes'),
-		//		'attributes_header'				=> $attributes_header,
-				'attributes_values'				=> $actor['attributes'],
-				'lookup_functions'				=> isset($actor['lookup_functions'])?$actor['lookup_functions']:'',
+				'attributes_group'				=> $attributes,
+				'lookup_functions'				=> isset($values['lookup_functions'])?$values['lookup_functions']:'',
 				'dateformat'					=> $dateformat,
 				'lang_edit'						=> lang('edit'),
 				'lang_add'						=> lang('add'),
 				'textareacols'				=> isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] : 40,
-				'textarearows'				=> isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] : 6
+				'textarearows'				=> isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] : 6,
+				'tabs'							=> phpgwapi_yui::tabview_generate($tabs, 'general')
 			);
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('actor') . ': ' . ($actor_id?lang('edit') . ' ' . lang($this->role):lang('add') . ' ' . lang($this->role));
 
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
 
 
 		function delete()
 		{
+
+			$actor_id	= phpgw::get_var('actor_id', 'int');
+
+			//cramirez add JsonCod for Delete
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+				$this->bo->delete($actor_id);
+				return "actor_id ".$actor_id." ".lang("has been deleted");
+			}
+
 			if(!$this->acl_delete)
 			{
 				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=>8, 'acl_location'=> $this->acl_location));
 			}
 
-			$actor_id	= phpgw::get_var('actor_id', 'int');
 			$confirm	= phpgw::get_var('confirm', 'bool', 'POST');
 
 			$link_data = array

Modified: people/sigurdne/modules/property/trunk/inc/class.uiadmin.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiadmin.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.uiadmin.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -337,6 +337,7 @@
 				$receipt	= $this->bo->set_permission($values,$r_processed,false,$initials);
 			}
 
+			$num_records = 0;
 			if ($this->location)
 			{
 				if($this->cat_id=='accounts')
@@ -346,6 +347,7 @@
 
 				if (isSet($user_list) AND is_array($user_list))
 				{
+					$num_records = count($user_list);
 					foreach($user_list as $user)
 					{
 						$processed[] = $user['account_id'];
@@ -403,6 +405,7 @@
 
 				if (isSet($group_list) AND is_array($group_list))
 				{
+					$num_records = count($group_list);
 					foreach($group_list as $group)
 					{
 						$processed[] = $group['account_id'];
@@ -541,8 +544,8 @@
 				'processed'						=> (isset($processed)?$processed:''),
 				'location'						=> $this->location,
 
-				'num_records'					=> (isset($user_list)?count($user_list):''),
-				'all_records'					=> (isset($this->bo->total_records)?$this->bo->total_records:''),
+				'num_records'					=> $num_records,
+				'all_records'					=> isset($this->bo->total_records) && $this->bo->total_records ? $this->bo->total_records : 0,
 				'link_url'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
 				'img_path'						=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
 
@@ -663,15 +666,15 @@
 				return;
 			}
 
+			$user_id	= phpgw::get_var('user_id', 'int');
+
 			$GLOBALS['phpgw']->xslttpl->add_file(array('admin'));
 
 			$values		= phpgw::get_var('values');
 
 			if ($values['save'])
 			{
-				// this should use the contacts backend in the API - each account is already linked to a contact
-				$GLOBALS['phpgw']->preferences->account_id=$this->filter;
-				$GLOBALS['phpgw']->preferences->read_repository();
+				$GLOBALS['phpgw']->preferences->set_account_id($user_id, true);
 
 				if ($values['old_email'] != $values['email'])
 				{
@@ -711,9 +714,9 @@
 				$GLOBALS['phpgw']->preferences->save_repository();
 			}
 
-			if($this->filter)
+			if($user_id)
 			{
-				$prefs = $this->bocommon->create_preferences('property',$this->filter);
+				$prefs = $this->bocommon->create_preferences('property',$user_id);
 			}
 
 			$cats		= CreateObject('phpgwapi.categories');
@@ -797,10 +800,10 @@
 
 
 				'lang_user_statustext'			=> lang('Select the user to edit email'),
-				'select_user_name'				=> 'filter',
+				'select_user_name'				=> 'user_id',
 				'lang_no_user'					=> lang('No user'),
-				'value_user_id'					=> $this->filter,
-				'user_list'						=> $this->bocommon->get_user_list('filter',$this->filter,$extra=false,$default=false,$start=-1,$sort='ASC',$order='account_lastname',$query='',$offset=-1),
+				'value_user_id'					=> $user_id,
+				'user_list'						=> $this->bocommon->get_user_list('filter',$user_id,$extra=false,$default=false,$start=-1,$sort='ASC',$order='account_lastname',$query='',$offset=-1, true),
 				'group_list_tts'				=> $groups_tts,
 				'account_list_tts'				=> $accounts_tts,
 				'lang_group_select'				=> lang('Default group TTS'),

Modified: people/sigurdne/modules/property/trunk/inc/class.uiadmin_entity.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiadmin_entity.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.uiadmin_entity.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -28,6 +28,7 @@
 	* @subpackage admin
  	* @version $Id$
 	*/
+	phpgw::import_class('phpgwapi.yui');
 
 	/**
 	 * Description
@@ -52,30 +53,21 @@
 			'edit_category'		=> true,
 			'view'   		=> true,
 			'delete' 		=> true,
+			'list_attribute_group'	=> true,
 			'list_attribute'	=> true,
+			'edit_attrib_group'		=> true,
 			'edit_attrib' 		=> true,
-			'list_custom_function'	=>true,
+			'list_custom_function'	=> true,
 			'edit_custom_function'	=> true
 		);
 
 		function property_uiadmin_entity()
 		{
 			$GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
-			$GLOBALS['phpgw_info']['flags']['menu_selection'] = 'admin::property::entity';
-		//	$this->currentapp			= $GLOBALS['phpgw_info']['flags']['currentapp'];
-			$this->nextmatchs			= CreateObject('phpgwapi.nextmatchs');
 			$this->account				= $GLOBALS['phpgw_info']['user']['account_id'];
 			$this->bo					= CreateObject('property.boadmin_entity',true);
-			$this->bocommon				= CreateObject('property.bocommon');
+			$this->bocommon				= & $this->bo->bocommon;
 
-			$this->acl 				= & $GLOBALS['phpgw']->acl;
-			$this->acl_location			= '.admin.entity';
-			$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');
-
 			$this->start				= $this->bo->start;
 			$this->query				= $this->bo->query;
 			$this->sort					= $this->bo->sort;
@@ -83,7 +75,17 @@
 			$this->entity_id			= $this->bo->entity_id;
 			$this->cat_id				= $this->bo->cat_id;
 			$this->allrows				= $this->bo->allrows;
+			$this->type					= $this->bo->type;
+			$this->type_app				= $this->bo->type_app;
+			$this->acl 					= & $GLOBALS['phpgw']->acl;
+			$this->acl_location			= '.admin.entity';
+			$this->acl_read 			= $this->acl->check($this->acl_location, PHPGW_ACL_READ, $this->type_app[$this->type]);
+			$this->acl_add 				= $this->acl->check($this->acl_location, PHPGW_ACL_ADD, $this->type_app[$this->type]);
+			$this->acl_edit 			= $this->acl->check($this->acl_location, PHPGW_ACL_EDIT, $this->type_app[$this->type]);
+			$this->acl_delete 			= $this->acl->check($this->acl_location, PHPGW_ACL_DELETE, $this->type_app[$this->type]);
+			$this->acl_manage 			= $this->acl->check($this->acl_location, 16, $this->type_app[$this->type]);
 
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] = "admin::{$this->type_app[$this->type]}::entity";
 		}
 
 		function save_sessiondata()
@@ -109,260 +111,707 @@
 			}
 
 			$this->bocommon->reset_fm_cache();
-			$GLOBALS['phpgw']->xslttpl->add_file(array(
-								'admin_entity',
-								'nextmatchs',
-								'search_field'));
 
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+			(
+	    			'menuaction'	=> 'property.uiadmin_entity.index',
+					'sort'		=>$this->sort,
+					'order'		=>$this->order,
+					'query'		=>$this->query,
+					'type'		=> $this->type
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_entity.index',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."type:'{$this->type}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+			$link_data = array
+			(
+				'menuaction'	=> 'property.uiadmin_entity.index',
+				'sort'		=>$this->sort,
+				'order'		=>$this->order,
+					'query'		=>$this->query,
+					'type'		=> $this->type
+			);
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_entity.index',
+								'sort'		=>$this->sort,
+								'order'		=>$this->order,
+								'query'		=>$this->query,
+								'type'		=> $this->type
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+			);
+
+				$dry_run = true;
+		}
+
 			$entity_list = $this->bo->read();
+			$uicols['name'][0]	= 'id';
+			$uicols['descr'][0]	= lang('Entity ID');
+			$uicols['name'][1]	= 'name';
+			$uicols['descr'][1]	= lang('Name');
+			$uicols['name'][2]	= 'descr';
+			$uicols['descr'][2]	= lang('Descr');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
 
-			if (isSet($entity_list) AND is_array($entity_list))
+			if (isset($entity_list) AND is_array($entity_list))
+		{
+				foreach($entity_list as $entity_entry)
 			{
-				foreach($entity_list as $entry)
+					for ($k=0;$k<$count_uicols_name;$k++)
+			{
+						if($uicols['input_type'][$k]!='hidden')
 				{
-					$content[] = array
-					(
-						'id'				=> $entry['id'],
-						'name'				=> $entry['name'],
-						'descr'				=> $entry['descr'],
-						'link_categories'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category',' entity_id'=> $entry['id'])),
-						'link_edit'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit', 'id'=> $entry['id'])),
-						'link_delete'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.delete',' entity_id'=> $entry['id'])),
-						'lang_view_standardtext'	=> lang('view the standard'),
-						'lang_category_text'		=> lang('categories for the entity type'),
-						'lang_edit_standardtext'	=> lang('edit the entity'),
-						'lang_delete_standardtext'	=> lang('delete the entity'),
-						'text_categories'		=> lang('Categories'),
-						'text_edit'			=> lang('edit'),
-						'text_delete'			=> lang('delete')
-					);
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']				= $entity_entry[$uicols['name'][$k]];
+						}
+					}
+					$j++;
 				}
 			}
 
-//_debug_array($content);
+			$datatable['rowactions']['action'] = array();
 
-			$table_header[] = array
+			$parameters = array
 			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
+			);
 
-				'lang_descr'		=> lang('Descr'),
-				'lang_categories'	=> lang('Categories'),
-				'lang_edit'		=> lang('edit'),
-				'lang_delete'		=> lang('delete'),
-				'sort_id'		=> $this->nextmatchs->show_sort_order(array
+			$parameters2 = array
 										(
-											'sort'	=> $this->sort,
-											'var'	=> 'id',
-											'order'	=> $this->order,
-											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.index',
-																'allrows'=> $this->allrows)
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'entity_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'categories',
+						'statustext' 	=> lang('categories'),
+						'text'			=> lang('Categories'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_entity.category',
+									'type'			=> $this->type
 										)),
-				'lang_id'		=> lang('entity id'),
-				'sort_name'		=> $this->nextmatchs->show_sort_order(array
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('edit'),
+						'text'			=> lang('edit'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
 										(
-											'sort'	=> $this->sort,
-											'var'	=> 'name',
-											'order'	=> $this->order,
-											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.index',
-																'allrows'=> $this->allrows)
+									'menuaction'	=> 'property.uiadmin_entity.edit',
+									'type'			=> $this->type
 										)),
-				'lang_name'		=> lang('Name'),
+					'parameters'	=> $parameters
 			);
 
-			$table_add[] = array
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('delete'),
+						'text'			=> lang('delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
 			(
-				'lang_add'		=> lang('add'),
-				'lang_add_standardtext'	=> lang('add a standard'),
-				'add_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit')),
-				'lang_done'		=> lang('done'),
-				'lang_done_standardtext'=> lang('back to admin'),
-				'done_action'		=> $GLOBALS['phpgw']->link('/admin/index.php')
+									'menuaction'	=> 'property.uiadmin_entity.delete',
+									'type'			=> $this->type
+								)),
+					'parameters'	=> $parameters2
 			);
 
-			if(!$this->allrows)
+
+			$datatable['rowactions']['action'][] = array(
+					'my_name' 		=> 'add',
+					'text' 			=> lang('add'),
+					'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+					(
+						'menuaction'	=> 'property.uiadmin_entity.edit',
+						'type'			=> $this->type
+					)));
+
+			unset($parameters);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
 			{
-				$record_limit	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'id';
 			}
-			else
+					if($uicols['name'][$i]=='name')
 			{
-				$record_limit	= $this->bo->total_records;
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'name';
+					}
+				}
 			}
 
-			$link_data = array
-			(
-				'menuaction'	=> 'property.uiadmin_entity.index',
-				'sort'		=>$this->sort,
-				'order'		=>$this->order,
-				'query'		=>$this->query
-			);
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
 
-			$data = array
-			(
-				'allow_allrows'				=> true,
-				'allrows'				=> $this->allrows,
-				'start_record'				=> $this->start,
-				'record_limit'				=> $record_limit,
-				'num_records'				=> count($entity_list),
-				'all_records'				=> $this->bo->total_records,
-				'link_url'				=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'img_path'				=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
-				'lang_searchfield_standardtext'		=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
-				'lang_searchbutton_standardtext'	=> lang('Submit the search string'),
-				'query'					=> $this->query,
-				'lang_search'				=> lang('search'),
-				'table_header'				=> $table_header,
-				'values'				=> $content,
-				'table_add'				=> $table_add
-			);
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($entity_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
 
 			$appname	= lang('entity');
 			$function_msg	= lang('list entity type');
 
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+		{
+				$datatable['sorting']['order'] 			= 'id'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
+			else
+			{
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+				{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+				{
+		    					$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+				{
+		    				  $json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+					{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+					}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+					{
+					$json ['rights'] = $datatable['rowactions']['action'];
+					}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+					{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+					}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
-			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
-			$this->save_sessiondata();
-		}
 
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_entity.index', 'property' );
+				}
 
 		function category()
-		{
+				{
 			if(!$this->acl_read)
 			{
 				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
-			}
+				}
 
 			$entity_id	= phpgw::get_var('entity_id', 'int');
 			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::entity_{$entity_id}";
 
-			$GLOBALS['phpgw']->xslttpl->add_file(array(
-								'admin_entity',
-								'nextmatchs',
-								'search_field'));
+			$entity = $this->bo->read_single($entity_id);
 
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'	=> 'property.uiadmin_entity.category',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'type'		=> $this->type
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_entity.category',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."entity_id:'{$this->entity_id}',"
+						 	                        ."type:'{$this->type}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+			$link_data = array
+			(
+					'menuaction'	=> 'property.uiadmin_entity.category',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'type'		=> $this->type
+			);
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_entity.category',
+								'sort'		=> $this->sort,
+								'order'		=> $this->order,
+								'query'		=> $this->query,
+								'entity_id'	=> $entity_id,
+								'type'		=> $this->type
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        ),
+				                                        array(
+				                                            'id' => 'txtcategory',
+				                                            'name' => 'search',
+				                                            'value'    => 'Entity: '.$entity['name'],
+				                                            'type' => 'label',
+				                                            'style' => 'filter'
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
 			$category_list = $this->bo->read_category($entity_id);
+			$uicols['name'][0]	= 'id';
+			$uicols['descr'][0]	= lang('category ID');
+			$uicols['name'][1]	= 'name';
+			$uicols['descr'][1]	= lang('Name');
+			$uicols['name'][2]	= 'descr';
+			$uicols['descr'][2]	= lang('Descr');
+			$uicols['name'][3]	= 'prefix';
+			$uicols['descr'][3]	= lang('Prefix');
+			$uicols['name'][4]	= 'entity_id';
+			$uicols['descr'][4]	= lang('id');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
 
-			if (isSet($category_list) AND is_array($category_list))
+			if (isset($category_list) AND is_array($category_list))
 			{
-				foreach($category_list as $entry)
+				foreach($category_list as $category_entry)
 				{
-					$content[] = array
-					(
-						'id'					=> $entry['id'],
-						'name'					=> $entry['name'],
-						'prefix'				=> $entry['prefix'],
-						'descr'					=> $entry['descr'],
-//						'link_status'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_status', 'cat_id'=> $entry['id'], 'entity_id'=> $entity_id)),
-						'link_custom_function'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'cat_id'=> $entry['id'], 'entity_id'=> $entity_id)),
-						'link_attribute'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'cat_id'=> $entry['id'], 'entity_id'=> $entity_id)),
-						'link_edit'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_category','id'=> $entry['id'], 'entity_id'=> $entity_id)),
-						'link_delete'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.delete', 'cat_id'=> $entry['id'], 'entity_id'=> $entity_id)),
-						'lang_view_standardtext'		=> lang('view the category'),
-						'lang_status_standardtext'		=> lang('Status for the entity category'),
-						'lang_attribute_standardtext'		=> lang('attributes for the entity category'),
-						'lang_custom_function_standardtext'	=> lang('custom functions for the entity category'),
-						'lang_edit_standardtext'		=> lang('edit the standard'),
-						'lang_delete_standardtext'		=> lang('delete the standard'),
-						'text_status'				=> lang('Status'),
-						'text_attribute'			=> lang('Attributes'),
-						'text_custom_function'			=> lang('Custom functions'),
-						'text_edit'				=> lang('edit'),
-						'text_delete'				=> lang('delete')
-					);
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+						if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']			= $category_entry[$uicols['name'][$k]];
+							if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'entity_id')
+							{
+								$datatable['rows']['row'][$j]['column'][$k]['value']		= $entity_id;
+							}
+						}
+					}
+					$j++;
 				}
 			}
 
-//_debug_array($content);
+			$datatable['rowactions']['action'] = array();
 
-			$table_header[] = array
+			$parameters = array
 			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+					array
+					(
+						'name'		=> 'entity_id',
+						'source'	=> 'entity_id'
+					)
+				)
+			);
 
-				'lang_descr'		=> lang('Descr'),
-				'lang_prefix'		=> lang('prefix'),
-//				'lang_status'		=> lang('Status'),
-				'lang_attribute'	=> lang('Attributes'),
-				'lang_custom_function'	=> lang('custom functions'),
-				'lang_edit'		=> lang('edit'),
-				'lang_delete'		=> lang('delete'),
-				'sort_id'		=> $this->nextmatchs->show_sort_order(array
-										(
-											'sort'	=> $this->sort,
-											'var'	=> 'id',
-											'order'	=> $this->order,
-											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.category',
-																'entity_id' =>$entity_id,
-																'allrows'=>$this->allrows)
-										)),
-				'lang_id'		=> lang('category id'),
-				'sort_name'		=> $this->nextmatchs->show_sort_order(array
-										(
-											'sort'	=> $this->sort,
-											'var'	=> 'name',
-											'order'	=> $this->order,
-											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.category',
-																'entity_id' =>$entity_id,
-																'allrows'=>$this->allrows)
-										)),
-				'lang_name'		=> lang('Name'),
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'cat_id',
+						'source'	=> 'id'
+					),
+					array
+					(
+						'name'		=> 'entity_id',
+						'source'	=> 'entity_id'
+					)
+				)
 			);
 
-			$table_add[] = array
+			$parameters3 = array
 			(
-				'lang_add'			=> lang('add'),
-				'lang_add_standardtext'		=> lang('add a category'),
-				'add_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_category', 'entity_id'=> $entity_id)),
-				'lang_done'			=> lang('done'),
-				'lang_done_standardtext'	=> lang('back to entity'),
-				'done_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.index'))
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'entity_id',
+						'source'	=> 'entity_id'
+					)
+				)
 			);
 
-			$entity = $this->bo->read_single($entity_id,false);
+			//_debug_array($parameters2);die;
 
-			if(!$this->allrows)
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'attribute_groups',
+						'statustext' 	=> lang('attribute groups'),
+						'text'			=> lang('attribute groups'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_entity.list_attribute_group',
+									'type'			=> $this->type
+								)),
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'attributes',
+						'statustext' 	=> lang('attributes'),
+						'text'			=> lang('Attributes'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_entity.list_attribute',
+									'type'			=> $this->type
+								)),
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'custom functions',
+						'statustext' 	=> lang('custom functions'),
+						'text'			=> lang('Custom functions'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_entity.list_custom_function',
+									'type'			=> $this->type
+								)),
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('edit'),
+						'text'			=> lang('edit'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_entity.edit_category',
+									'type'			=> $this->type
+								)),
+					'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('delete'),
+						'text'			=> lang('delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_entity.delete',
+									'type'			=> $this->type
+								)),
+					'parameters'	=> $parameters2
+					);
+
+
+			$datatable['rowactions']['action'][] = array(
+					'my_name' 		=> 'add',
+					'text' 			=> lang('add'),
+					'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+						(
+							'menuaction'	=> 'property.uiadmin_entity.edit_category',
+							'entity_id'		=> $entity_id,
+							'type'			=> $this->type
+						)),
+					'parameters'	=> $parameters3
+					);
+
+			unset($parameters);
+			unset($parameters2);
+			unset($parameters3);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
 			{
-				$record_limit	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'id';
+					}
+					if($uicols['name'][$i]=='name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'name';
+					}
+					if($uicols['name'][$i]=='entity_id')
+					{
+						$datatable['headers']['header'][$i]['visible'] 		= false;
+					}
+				}
 			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($category_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
+			$appname	= lang('entity');
+			$function_msg	= lang('list entity type');
+
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'id'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
 			else
 			{
-				$record_limit	= $this->bo->total_records;
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
 			}
 
-			$link_data = array
-			(
-				'menuaction'	=> 'property.uiadmin_entity.category',
-				'sort'		=> $this->sort,
-				'order'		=> $this->order,
-				'query'		=> $this->query,
-				'entity_id'	=> $entity_id
-			);
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
 
-			$data = array
-			(
-				'lang_entity'					=> lang('entity'),
-				'entity_name'					=> $entity['name'],
-				'allow_allrows'					=> true,
-				'allrows'					=> $this->allrows,
-				'start_record'					=> $this->start,
-				'record_limit'					=> $record_limit,
-				'num_records'					=> count($category_list),
-				'all_records'					=> $this->bo->total_records,
-				'link_url'					=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'img_path'					=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
-				'lang_searchfield_standardtext'			=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
-				'lang_searchbutton_standardtext'		=> lang('Submit the search string'),
-				'query'						=> $this->query,
-				'lang_search'					=> lang('search'),
-				'table_header_category'				=> $table_header,
-				'values_category'				=> $content,
-				'table_add'					=> $table_add
-			);
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
 
-			$appname	= lang('entity');
-			$function_msg	= lang('list entity type');
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  $json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
 
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
-			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list_category' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
-			$this->save_sessiondata();
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_entity.category', 'property' );
 		}
 
 		function edit()
@@ -374,7 +823,7 @@
 
 			$id	= phpgw::get_var('id', 'int');
 			$values			= phpgw::get_var('values');
-			$config = CreateObject('phpgwapi.config','property');
+			$config = CreateObject('phpgwapi.config', $this->type_app[$this->type]);
 
 			$GLOBALS['phpgw']->xslttpl->add_file(array('admin_entity'));
 
@@ -399,7 +848,7 @@
 					{
 						$id=$receipt['id'];
 					}
-					$config->read_repository();
+					$config->read();
 
 					if(!is_array($config->config_data['location_form']))
 					{
@@ -446,7 +895,8 @@
 			$link_data = array
 			(
 				'menuaction'	=> 'property.uiadmin_entity.edit',
-				'id'		=> $id
+				'id'		=> $id,
+				'type'		=> $this->type
 			);
 //_debug_array($include_list);
 
@@ -457,7 +907,7 @@
 				'msgbox_data'					=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
 				'lang_name_standardtext'			=> lang('Enter a name of the standard'),
 				'form_action'					=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'done_action'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.index')),
+				'done_action'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.index', 'type' => $this->type)),
 				'lang_id'					=> lang('standard ID'),
 				'lang_name'					=> lang('Name'),
 				'lang_descr'					=> lang('Descr'),
@@ -491,7 +941,7 @@
 
 			$appname	= lang('entity');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
@@ -559,8 +1009,9 @@
 			$link_data = array
 			(
 				'menuaction'	=> 'property.uiadmin_entity.edit_category',
-				'entity_id'	=>$entity_id,
-				'id'		=> $id
+				'entity_id'		=> $entity_id,
+				'id'			=> $id,
+				'type'			=> $this->type
 			);
 //_debug_array($link_data);
 
@@ -577,7 +1028,7 @@
 				'lang_name_standardtext'			=> lang('Enter a name of the standard'),
 
 				'form_action'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'done_action'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category', 'entity_id'=> $entity_id)),
+				'done_action'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category', 'entity_id'=> $entity_id,'type' => $this->type)),
 				'lang_id'							=> lang('Category'),
 				'lang_name'							=> lang('Name'),
 				'lang_descr'						=> lang('Descr'),
@@ -605,7 +1056,7 @@
 				'lang_tracking_statustext'			=> lang('If this entity type is to be tracket in ticket list'),
 				'lang_fileupload'					=> lang('Enable file upload'),
 				'value_fileupload'					=> $values['fileupload'],
-				'lang_fileupload_statustext'		=> lang('If files can be uploaded for this category'),
+				'value_jasperupload'				=> $values['jasperupload'],
 				'lang_loc_link'						=> lang('Link from location'),
 				'value_loc_link'					=> $values['loc_link'],
 				'lang_loc_link_statustext'			=> lang('Enable link from location detail'),
@@ -614,12 +1065,13 @@
 				'lang_start_project_statustext'		=> lang('Enable start project from this category'),
 				'lang_start_ticket'					=> lang('Start ticket'),
 				'value_start_ticket'				=> $values['start_ticket'],
-				'lang_start_ticket_statustext'		=> lang('Enable start ticket from this category')
+				'lang_start_ticket_statustext'		=> lang('Enable start ticket from this category'),
+				'jasperupload'						=> true
 			);
 
 			$appname = lang('entity');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
@@ -634,23 +1086,34 @@
 			$entity_id		= phpgw::get_var('entity_id', 'int');
 			$cat_id			= phpgw::get_var('cat_id', 'int');
 			$attrib_id		= phpgw::get_var('attrib_id', 'int');
+			$group_id		= phpgw::get_var('group_id', 'int');
 			$acl_location		= phpgw::get_var('acl_location');
 			$custom_function_id	= phpgw::get_var('custom_function_id', 'int');
 			$confirm		= phpgw::get_var('confirm', 'bool', 'POST');
 
-			if($attrib_id):
+			// JSON code delete
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
 			{
+				$this->bo->delete($cat_id,$entity_id,$attrib_id,$acl_location,$custom_function_id,$group_id);
+				return lang("this record has been deleted");
+			}
+
+			if($group_id)
+			{
+				$function='list_attribute_group';
+			}
+			else if($attrib_id)
+			{
 				$function='list_attribute';
 			}
-			elseif($custom_function_id):
+			else if($custom_function_id)
 			{
 				$function='list_custom_function';
 			}
-			endif;
 
 			if (!$acl_location && $entity_id && $cat_id)
 			{
-				$acl_location = '.entity.' . $entity_id . '.' . $cat_id;
+				$acl_location = ".{$this->type}.{$entity_id}.{$cat_id}";
 			}
 
 			if(!$function)
@@ -671,7 +1134,8 @@
 				'menuaction'	=> 'property.uiadmin_entity.'.$function,
 				'cat_id' 	=> $cat_id,
 				'entity_id'	=> $entity_id,
-				'attrib_id'	=> $attrib_id
+				'attrib_id'	=> $attrib_id,
+				'type'		=> $this->type
 			);
 
 			$delete_data = array
@@ -679,17 +1143,13 @@
 				'menuaction'	=> 'property.uiadmin_entity.delete',
 				'cat_id'	=> $cat_id,
 				'entity_id'	=> $entity_id,
+				'group_id'	=> $group_id,
 				'attrib_id'	=> $attrib_id,
 				'acl_location'	=> $acl_location,
-				'custom_function_id' => $custom_function_id
+				'custom_function_id' => $custom_function_id,
+				'type'				=> $this->type
 			);
 
-			if (phpgw::get_var('confirm', 'bool', 'POST'))
-			{
-				$this->bo->delete($cat_id,$entity_id,$attrib_id,$acl_location,$custom_function_id);
-				$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
-			}
-
 			$GLOBALS['phpgw']->xslttpl->add_file(array('app_delete'));
 
 			$data = array
@@ -706,13 +1166,12 @@
 			$appname		= lang('entity');
 			$function_msg		= lang('delete entity type');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('delete' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
 
-
-		function list_attribute()
+		function list_attribute_group()
 		{
 			if(!$this->acl_read)
 			{
@@ -727,6 +1186,374 @@
 			$id	= phpgw::get_var('id', 'int');
 			$resort	= phpgw::get_var('resort');
 
+			if($resort)
+			{
+				$this->bo->resort_attrib_group($id,$resort);
+			}
+
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+				{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'	=> 'property.uiadmin_entity.list_attribute_group',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'cat_id'	=> $cat_id,
+					'type'		=> $this->type
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_entity.list_attribute_group',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."entity_id:'{$this->entity_id}',"
+						 	                        ."cat_id:'{$this->cat_id}',"
+						 	                        ."type:'{$this->type}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
+					(
+					'menuaction'	=> 'property.uiadmin_entity.list_attribute',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'cat_id'	=> $cat_id,
+					'type'		=> $this->type
+				);
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_entity.list_attribute_group',
+								'sort'		=> $this->sort,
+								'order'		=> $this->order,
+								'query'		=> $this->query,
+								'entity_id'	=> $entity_id,
+								'cat_id'	=> $cat_id,
+								'type'		=> $this->type
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
+			$attrib_list = $this->bo->read_attrib_group($entity_id,$cat_id);
+			$uicols['name'][0]	= 'name';
+			$uicols['descr'][0]	= lang('Name');
+			$uicols['name'][1]	= 'descr';
+			$uicols['descr'][1]	= lang('Descr');
+			$uicols['name'][2]	= 'group_sort';
+			$uicols['descr'][2]	= lang('sorting');
+			$uicols['name'][3]	= 'up';
+			$uicols['descr'][3]	= lang('up');
+			$uicols['name'][4]	= 'down';
+			$uicols['descr'][4]	= lang('down');
+			$uicols['name'][5]	= 'id';
+			$uicols['descr'][5]	= lang('id');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
+			if (isset($attrib_list) AND is_array($attrib_list))
+			{
+				foreach($attrib_list as $attrib_entry)
+				{
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+						if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']			= $attrib_entry[$uicols['name'][$k]];
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'up')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'up';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute_group', 'resort'=> 'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'down')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'down';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute_group', 'resort'=> 'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+					}
+					$j++;
+				}
+			}
+
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'group_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('Edit'),
+						'text'			=> lang('Edit'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_entity.edit_attrib_group',
+								'entity_id'			=> $entity_id,
+								'cat_id'			=> $cat_id,
+								'type' 				=> $this->type
+							)
+						),
+						'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('Delete'),
+						'text'			=> lang('Delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_entity.delete',
+								'entity_id'			=> $entity_id,
+								'cat_id'			=> $cat_id,
+								'type' 				=> $this->type
+							)
+						),
+						'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'statustext' 	=> lang('add'),
+							'text'			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiadmin_entity.edit_attrib_group',
+										'entity_id'			=> $entity_id,
+										'cat_id'			=> $cat_id,
+										'type' 				=> $this->type
+									))
+						);
+
+			unset($parameters);
+			unset($parameters2);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
+			{
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['visible'] 			= false;
+					}
+
+					if($uicols['name'][$i]=='name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'name';
+					}
+				}
+			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($attrib_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
+			$appname	= lang('attribute');
+			$function_msg	= lang('list entity attribute');
+
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'name'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
+			else
+			{
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					//$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  //$json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				  $json_row[$column['name']] = "<a href='#' onclick='".$column['link']."'>" .$column['value']."</a>";
+		    				  //$json_row[$column['name']] = '<a href="#" onclick="delete_record("/index.php?menuaction=property.uiasync.delete")">' .$column['value'].'</a>';
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+				// query parameters
+				if(isset($current_Consult) && is_array($current_Consult))
+				{
+					$json ['current_consult'] = $current_Consult;
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_entity.attribute_group', 'property' );
+
+			/*if(!$this->acl_read)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
+			}
+
+			$entity_id	= $this->entity_id;
+			$cat_id	= $this->cat_id;
+
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::entity_{$entity_id}::entity_{$entity_id}_{$cat_id}";
+
+			$id	= phpgw::get_var('id', 'int');
+			$resort	= phpgw::get_var('resort');
+
 			$GLOBALS['phpgw']->xslttpl->add_file(array(
 								'admin_entity',
 								'nextmatchs',
@@ -734,9 +1561,9 @@
 
 			if($resort)
 			{
-				$this->bo->resort_attrib($id,$resort);
+				$this->bo->resort_attrib_group($id,$resort);
 			}
-			$attrib_list = $this->bo->read_attrib($entity_id,$cat_id);
+			$attrib_list = $this->bo->read_attrib_group($entity_id,$cat_id);
 
 			if (isset($attrib_list) AND is_array($attrib_list))
 			{
@@ -745,16 +1572,13 @@
 
 					$content[] = array
 					(
-						'name'				=> $entry['name'],
-						'datatype'			=> $entry['trans_datatype'],
-						'column_name'			=> $entry['column_name'],
-						'input_text'			=> $entry['input_text'],
-						'sorting'			=> $entry['attrib_sort'],
-						'search'			=> $entry['search'],
-						'link_up'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'resort'=> 'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows)),
-						'link_down'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'resort'=> 'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows)),
-						'link_edit'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_attrib', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'])),
-						'link_delete'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.delete', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'attrib_id'=> $entry['id'])),
+						'name'					=> $entry['name'],
+						'descr'					=> $entry['descr'],
+						'sorting'				=> $entry['group_sort'],
+						'link_up'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute_group', 'resort'=> 'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)),
+						'link_down'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute_group', 'resort'=> 'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)),
+						'link_edit'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_attrib_group', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'type' => $this->type)),
+						'link_delete'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.delete', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'group_id'=> $entry['id'], 'type' => $this->type)),
 						'lang_up_text'			=> lang('shift up'),
 						'lang_down_text'		=> lang('shift down'),
 						'lang_edit_text'		=> lang('edit the attrib'),
@@ -773,9 +1597,7 @@
 			$table_header[] = array
 			(
 				'lang_descr'		=> lang('Descr'),
-				'lang_datatype'		=> lang('Datatype'),
 				'lang_sorting'		=> lang('sorting'),
-				'lang_search'		=> lang('search'),
 				'lang_edit'		=> lang('edit'),
 				'lang_delete'		=> lang('delete'),
 				'sort_name'		=> $this->nextmatchs->show_sort_order(array
@@ -786,7 +1608,8 @@
 											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.list_attribute',
 																'entity_id'	=>$entity_id,
 																'cat_id'	=>$cat_id,
-																'allrows'=>$this->allrows)
+																'allrows'=>$this->allrows,
+																'type'	=> $this->type)
 										)),
 				'sort_sorting'		=> $this->nextmatchs->show_sort_order(array
 										(
@@ -796,7 +1619,8 @@
 											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.list_attribute',
 																'entity_id'	=>$entity_id,
 																'cat_id'	=>$cat_id,
-																'allrows'=>$this->allrows)
+																'allrows'=>$this->allrows,
+																'type'	=> $this->type)
 										)),
 				'lang_name'		=> lang('Name'),
 			);
@@ -805,10 +1629,10 @@
 			(
 				'lang_add'		=> lang('add'),
 				'lang_add_attribtext'	=> lang('add an attrib'),
-				'add_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_attrib', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id)),
+				'add_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_attrib_group', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id,'type' => $this->type)),
 				'lang_done'		=> lang('done'),
 				'lang_done_attribtext'	=> lang('back to admin'),
-				'done_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category', 'entity_id'=> $entity_id)),
+				'done_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category', 'entity_id'=> $entity_id, 'type' => $this->type)),
 			);
 
 			if(!$this->allrows)
@@ -827,7 +1651,8 @@
 				'order'		=> $this->order,
 				'query'		=> $this->query,
 				'entity_id'	=> $entity_id,
-				'cat_id'	=> $cat_id
+				'cat_id'	=> $cat_id,
+				'type'		=> $this->type
 			);
 
 			$entity = $this->bo->read_single($entity_id,false);
@@ -835,35 +1660,574 @@
 
 			$data = array
 			(
+				'lang_entity'						=> lang('entity'),
+				'entity_name'						=> $entity['name'],
+				'lang_category'						=> lang('category'),
+				'category_name'						=> $category['name'],
+				'allow_allrows'						=> true,
+				'allrows'							=> $this->allrows,
+				'start_record'						=> $this->start,
+				'record_limit'						=> $record_limit,
+				'start_record'						=> $this->start,
+				'num_records'						=> count($attrib_list),
+				'all_records'						=> $this->bo->total_records,
+				'link_url'							=> $GLOBALS['phpgw']->link('/index.php',$link_data),
+				'img_path'							=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
+				'lang_searchfield_attribtext'		=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
+				'lang_searchbutton_attribtext'		=> lang('Submit the search string'),
+				'query'								=> $this->query,
+				'lang_search'						=> lang('search'),
+				'table_header_attrib_group'			=> $table_header,
+				'values_attrib_group'				=> $content,
+				'table_add'							=> $table_add
+			);
+
+			$appname	= lang('attribute');
+			$function_msg	= lang('list entity attribute group');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list_attribute_group' => $data));
+			$this->save_sessiondata();*/
+		}
+
+		function list_attribute()
+		{
+			if(!$this->acl_read)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
+			}
+
+			$entity_id	= $this->entity_id;
+			$cat_id	= $this->cat_id;
+
+			$entity = $this->bo->read_single($entity_id);
+			$category = $this->bo->read_single_category($entity_id,$cat_id);
+
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::entity_{$entity_id}::entity_{$entity_id}_{$cat_id}";
+
+			$id	= phpgw::get_var('id');
+			$resort	= phpgw::get_var('resort');
+
+			if($resort && phpgw::get_var('phpgw_return_as') == 'json')
+			{
+				$this->bo->resort_attrib($id,$resort);
+			}
+
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'	=> 'property.uiadmin_entity.list_attribute',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'cat_id'	=> $cat_id,
+					'type'		=> $this->type
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_entity.list_attribute',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."entity_id:'{$this->entity_id}',"
+						 	                        ."cat_id:'{$this->cat_id}',"
+						 	                        ."type:'{$this->type}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
+				(
+					'menuaction'	=> 'property.uiadmin_entity.list_attribute',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'cat_id'	=> $cat_id,
+					'type'		=> $this->type
+				);
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_entity.list_attribute',
+								'sort'		=> $this->sort,
+								'order'		=> $this->order,
+								'query'		=> $this->query,
+								'entity_id'	=> $entity_id,
+								'cat_id'	=> $cat_id,
+								'type'		=> $this->type
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array( // mensaje
+															'type'	=> 'label',
+															'id'	=> 'msg_header',
+															'value'	=> '',
+															'style' => 'filter'
+														),
+														array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        ),
+														array( //container of  control's Form
+															'type'	=> 'label',
+															'id'	=> 'controlsForm_container',
+															'value'	=> ''
+														)
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
+			$attrib_list = $this->bo->read_attrib($entity_id,$cat_id);
+			$uicols['name'][0]	= 'column_name';
+			$uicols['descr'][0]	= lang('Name');
+			$uicols['name'][1]	= 'input_text';
+			$uicols['descr'][1]	= lang('Descr');
+			$uicols['name'][2]	= 'trans_datatype';
+			$uicols['descr'][2]	= lang('Datatype');
+			$uicols['name'][3]	= 'group_id';
+			$uicols['descr'][3]	= lang('group');
+			$uicols['name'][4]	= 'attrib_sort';
+			$uicols['descr'][4]	= lang('sorting');
+			$uicols['name'][5]	= 'up';
+			$uicols['descr'][5]	= lang('up');
+			$uicols['name'][6]	= 'down';
+			$uicols['descr'][6]	= lang('down');
+			$uicols['name'][7]	= 'search';
+			$uicols['descr'][7]	= lang('Search');
+			$uicols['name'][8]	= 'id';
+			$uicols['descr'][8]	= lang('id');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
+			if (isset($attrib_list) AND is_array($attrib_list))
+			{
+				foreach($attrib_list as $attrib_entry)
+				{
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+						if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']			= $attrib_entry[$uicols['name'][$k]];
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'up')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'up';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'resort'=> 'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'down')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'down';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'resort'=> 'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+					}
+					$j++;
+				}
+			}
+
+			$current_Consult = array ();
+			for($i=0;$i<2;$i++)
+			{
+				if($i==0)
+				{
+					$current_Consult[] = array('entity',$entity['name']);
+				}
+				if($i==1)
+				{
+					$current_Consult[] = array('Category',$category['name']);
+				}
+			}
+
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'attrib_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('Edit'),
+						'text'			=> lang('Edit'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_entity.edit_attrib',
+								'entity_id'			=> $entity_id,
+								'cat_id'			=> $cat_id,
+								'type' 				=> $this->type
+							)
+						),
+						'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('Delete'),
+						'text'			=> lang('Delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_entity.delete',
+								'entity_id'			=> $entity_id,
+								'cat_id'			=> $cat_id,
+								'type' 				=> $this->type
+							)
+						),
+						'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'statustext' 	=> lang('add'),
+							'text'			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiadmin_entity.edit_attrib',
+										'entity_id'			=> $entity_id,
+										'cat_id'			=> $cat_id,
+										'type' 				=> $this->type
+									))
+						);
+
+			unset($parameters);
+			unset($parameters2);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
+			{
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='column_name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'column_name';
+					}
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['visible'] 			= false;
+					}
+					if($uicols['name'][$i]=='attrib_sort')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'attrib_sort';
+					}
+				}
+			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($attrib_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
+			$appname	= lang('attribute');
+			$function_msg	= lang('list entity attribute');
+
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'column_name'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
+			else
+			{
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					//$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  //$json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				  $json_row[$column['name']] = "<a href='#' onclick='".$column['link']."'>" .$column['value']."</a>";
+		    				  //$json_row[$column['name']] = '<a href="#" onclick="delete_record("/index.php?menuaction=property.uiasync.delete")">' .$column['value'].'</a>';
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+				if(isset($current_Consult) && is_array($current_Consult))
+				{
+					$json ['current_consult'] = $current_Consult;
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_entity.attribute', 'property' );
+		}
+
+		function edit_attrib_group()
+		{
+			if(!$this->acl_add)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 2, 'acl_location'=> $this->acl_location));
+			}
+
+			$entity_id	= phpgw::get_var('entity_id', 'int');
+			$cat_id		= phpgw::get_var('cat_id', 'int');
+			$id			= phpgw::get_var('id', 'int');
+			$values		= phpgw::get_var('values');
+
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::entity_{$entity_id}::entity_{$entity_id}_{$cat_id}";
+
+			if(!$values)
+			{
+				$values=array();
+			}
+
+			$GLOBALS['phpgw']->xslttpl->add_file(array('admin_entity'));
+
+			if (isset($values['save']) && $values['save'])
+			{
+				if($id)
+				{
+					$values['id']=$id;
+					$action='edit';
+				}
+
+				$values['entity_id']=$entity_id;
+				$values['cat_id']=$cat_id;
+
+				if (!$values['group_name'])
+				{
+					$receipt['error'][] = array('msg'=>lang('group name not entered!'));
+				}
+
+				if (!$values['descr'])
+				{
+					$receipt['error'][] = array('msg'=>lang('description not entered!'));
+				}
+
+				if (!$values['entity_id'])
+				{
+					$receipt['error'][] = array('msg'=>lang('entity type not chosen!'));
+				}
+
+
+				if (!isset($receipt['error']))
+				{
+					$receipt = $this->bo->save_attrib_group($values,$action);
+
+					if(!$id)
+					{
+						$id=$receipt['id'];
+					}
+				}
+				else
+				{
+					$receipt['error'][] = array('msg' => lang('Attribute group has NOT been saved'));
+				}
+			}
+
+			if ($id)
+			{
+				$values = $this->bo->read_single_attrib_group($entity_id,$cat_id,$id);
+				$type_name=$values['type_name'];
+				$function_msg = lang('edit attribute group'). ' ' . lang($type_name);
+				$action='edit';
+			}
+			else
+			{
+				$function_msg = lang('add attribute group');
+				$action='add';
+			}
+
+			$link_data = array
+			(
+				'menuaction'	=> 'property.uiadmin_entity.edit_attrib_group',
+				'entity_id'	=> $entity_id,
+				'cat_id'	=> $cat_id,
+				'id'		=> $id,
+				'type'		=> $this->type
+			);
+
+
+			$entity = $this->bo->read_single($entity_id,false);
+			$category = $this->bo->read_single_category($entity_id,$cat_id);
+
+			$msgbox_data = (isset($receipt)?$this->bocommon->msgbox_data($receipt):'');
+
+			$data = array
+			(
 				'lang_entity'					=> lang('entity'),
 				'entity_name'					=> $entity['name'],
 				'lang_category'					=> lang('category'),
 				'category_name'					=> $category['name'],
-				'allow_allrows'					=> true,
-				'allrows'					=> $this->allrows,
-				'start_record'					=> $this->start,
-				'record_limit'					=> $record_limit,
-				'start_record'					=> $this->start,
-				'num_records'					=> count($attrib_list),
-				'all_records'					=> $this->bo->total_records,
-				'link_url'					=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'img_path'					=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
-				'lang_searchfield_attribtext'			=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
-				'lang_searchbutton_attribtext'			=> lang('Submit the search string'),
-				'query'						=> $this->query,
-				'lang_search'					=> lang('search'),
-				'table_header_attrib'				=> $table_header,
-				'values_attrib'					=> $content,
-				'table_add'					=> $table_add
+
+				'msgbox_data'						=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
+				'form_action'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
+				'done_action'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute_group', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'type' => $this->type)),
+				'lang_id'							=> lang('Attribute group ID'),
+				'lang_entity_type'					=> lang('Entity type'),
+				'lang_no_entity_type'				=> lang('No entity type'),
+				'lang_save'							=> lang('save'),
+				'lang_done'							=> lang('done'),
+				'value_id'							=> $id,
+
+				'lang_group_name'					=> lang('group name'),
+				'value_group_name'					=> $values['group_name'],
+				'lang_group_name_statustext'		=> lang('enter the name for the group'),
+
+				'lang_descr'						=> lang('descr'),
+				'value_descr'						=> $values['descr'],
+				'lang_descr_statustext'				=> lang('enter the input text for records'),
+
+				'lang_remark'						=> lang('remark'),
+				'lang_remark_statustext'			=> lang('Enter a remark for the group'),
+				'value_remark'						=> $values['remark'],
+
+				'lang_done_attribtext'				=> lang('Back to the list'),
+				'lang_save_attribtext'				=> lang('Save the attribute')
 			);
+//_debug_array($values);
 
-			$appname	= lang('attribute');
-			$function_msg	= lang('list entity attribute');
+			$appname = lang('entity');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
-			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list_attribute' => $data));
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit_attrib_group' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
-			$this->save_sessiondata();
 		}
 
 		function edit_attrib()
@@ -877,6 +2241,9 @@
 			$cat_id		= phpgw::get_var('cat_id', 'int');
 			$id		= phpgw::get_var('id', 'int');
 			$values		= phpgw::get_var('values');
+
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::entity_{$entity_id}::entity_{$entity_id}_{$cat_id}";
+
 			if(!$values)
 			{
 				$values=array();
@@ -976,7 +2343,8 @@
 				'menuaction'	=> 'property.uiadmin_entity.edit_attrib',
 				'entity_id'	=> $entity_id,
 				'cat_id'	=> $cat_id,
-				'id'		=> $id
+				'id'		=> $id,
+				'type'		=> $this->type
 			);
 
 			if($values['column_info']['type']=='R' || $values['column_info']['type']=='CH' || $values['column_info']['type']=='LB')
@@ -1007,7 +2375,7 @@
 
 				'msgbox_data'						=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
 				'form_action'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'done_action'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id)),
+				'done_action'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_attribute', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'type' => $this->type)),
 				'lang_id'							=> lang('Attribute ID'),
 				'lang_entity_type'					=> lang('Entity type'),
 				'lang_no_entity_type'				=> lang('No entity type'),
@@ -1038,6 +2406,11 @@
 				'lang_no_datatype'					=> lang('No datatype'),
 				'datatype_list'						=> $this->bocommon->select_datatype($values['column_info']['type']),
 
+				'lang_group'						=> lang('group'),
+				'lang_group_statustext'				=> lang('Select a group'),
+				'lang_no_group'					=> lang('no group'),
+				'attrib_group_list'					=> $this->bo->get_attrib_group_list($entity_id,$cat_id, $values['group_id']),
+
 				'lang_precision'					=> lang('Precision'),
 				'lang_precision_statustext'			=> lang('enter the record length'),
 				'value_precision'					=> $values['column_info']['precision'],
@@ -1080,7 +2453,7 @@
 
 			$appname = lang('entity');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit_attrib' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
@@ -1097,6 +2470,374 @@
 			$id		= phpgw::get_var('id', 'int');
 			$resort		= phpgw::get_var('resort');
 
+			if($resort)
+			{
+				$this->bo->resort_custom_function($id,$resort);
+			}
+
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'	=> 'property.uiadmin_entity.list_custom_function',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'cat_id'	=> $cat_id,
+					'type'		=> $this->type
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_entity.list_custom_function',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."entity_id:'{$this->entity_id}',"
+						 	                        ."cat_id:'{$this->cat_id}',"
+						 	                        ."type:'{$this->type}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
+				(
+					'menuaction'	=> 'property.uiadmin_entity.list_custom_function',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'entity_id'	=> $entity_id,
+					'cat_id'	=> $cat_id,
+					'type'		=> $this->type
+				);
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_entity.list_custom_function',
+								'sort'		=> $this->sort,
+								'order'		=> $this->order,
+								'query'		=> $this->query,
+								'entity_id'	=> $entity_id,
+								'cat_id'	=> $cat_id,
+								'type'		=> $this->type
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
+			$custom_function_list = $this->bo->read_custom_function($entity_id,$cat_id);
+			$uicols['name'][0]	= 'name';
+			$uicols['descr'][0]	= '';//FIXME
+			$uicols['name'][1]	= 'id';
+			$uicols['descr'][1]	= lang('id');
+			$uicols['name'][2]	= 'descr';
+			$uicols['descr'][2]	= lang('Descr');
+			$uicols['name'][3]	= 'active';
+			$uicols['descr'][3]	= lang('Active');
+			$uicols['name'][4]	= 'sorting';
+			$uicols['descr'][4]	= lang('sorting');
+			$uicols['name'][5]	= 'up';
+			$uicols['descr'][5]	= lang('up');
+			$uicols['name'][6]	= 'down';
+			$uicols['descr'][6]	= lang('down');
+			$uicols['name'][7]	= 'file_name';
+			$uicols['descr'][7]	= lang('Name');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
+			if (isset($custom_function_list) AND is_array($custom_function_list))
+			{
+				foreach($custom_function_list as $custom_entry)
+				{
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+						if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']			= $custom_entry[$uicols['name'][$k]];
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'up')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'resort'=> 'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $custom_entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'down')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'resort'=> 'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $custom_entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+					}
+					$j++;
+				}
+			}
+
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'custom_function_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('Edit'),
+						'text'			=> lang('Edit'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_entity.edit_custom_function',
+								'entity_id'			=> $entity_id,
+								'cat_id'			=> $cat_id,
+								'type' 				=> $this->type
+							)
+						),
+						'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('Delete'),
+						'text'			=> lang('Delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_entity.delete',
+								'entity_id'			=> $entity_id,
+								'cat_id'			=> $cat_id,
+								'type' 				=> $this->type,
+								'acl_location'		=> ".{$this->type}.{$entity_id}.{$cat_id}"
+							)
+						),
+						'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'statustext' 	=> lang('add'),
+							'text'			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiadmin_entity.edit_custom_function',
+										'entity_id'			=> $entity_id,
+										'cat_id'			=> $cat_id,
+										'type' 				=> $this->type
+									))
+						);
+
+			unset($parameters);
+			unset($parameters2);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
+			{
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					/*if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['visible'] 			= false;
+					}
+
+					if($uicols['name'][$i]=='name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'name';
+					}*/
+				}
+			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($custom_function_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
+			$appname	= lang('custom function');
+			$function_msg	= lang('list entity custom function');
+
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'name'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
+			else
+			{
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					//$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  $json_row[$column['name']] = "<a href='#' onclick='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+				// query parameters
+				if(isset($current_Consult) && is_array($current_Consult))
+				{
+					$json ['current_consult'] = $current_Consult;
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_entity.function_group', 'property' );
+
+			/*if(!$this->acl_read)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
+			}
+
+			$entity_id	= $this->entity_id;
+			$cat_id		= $this->cat_id;
+			$id		= phpgw::get_var('id', 'int');
+			$resort		= phpgw::get_var('resort');
+
 			$GLOBALS['phpgw']->xslttpl->add_file(array(
 								'admin_entity',
 								'nextmatchs',
@@ -1119,10 +2860,10 @@
 						'descr'					=> $entry['descr'],
 						'sorting'				=> $entry['sorting'],
 						'active'				=> $entry['active']?'X':'',
-						'link_up'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'resort'=>'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows)),
-						'link_down'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'resort'=>'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows)),
-						'link_edit'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_custom_function', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'])),
-						'link_delete'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.delete', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'custom_function_id'=> $entry['id'])),
+						'link_up'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'resort'=>'up', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)),
+						'link_down'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'resort'=>'down', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'allrows'=> $this->allrows, 'type' => $this->type)),
+						'link_edit'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_custom_function', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'id'=> $entry['id'], 'type' => $this->type)),
+						'link_delete'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.delete', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'custom_function_id'=> $entry['id'], 'type' => $this->type)),
 						'lang_up_text'				=> lang('shift up'),
 						'lang_down_text'			=> lang('shift down'),
 						'lang_edit_text'			=> lang('edit the custom_function'),
@@ -1152,7 +2893,8 @@
 											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.list_custom_function',
 																'entity_id'	=> $entity_id,
 																'cat_id'	=> $cat_id,
-																'allrows'	=> $this->allrows)
+																'allrows'	=> $this->allrows,
+																'type'		=> $this->type)
 										)),
 				'sort_sorting'		=> $this->nextmatchs->show_sort_order(array
 										(
@@ -1162,7 +2904,8 @@
 											'extra'	=> array('menuaction'	=> 'property.uiadmin_entity.list_custom_function',
 																'entity_id'	=>$entity_id,
 																'cat_id'	=>$cat_id,
-																'allrows'	=>$this->allrows)
+																'allrows'	=>$this->allrows,
+																'type'		=> $this->type)
 										)),
 				'lang_name'		=> lang('Name'),
 			);
@@ -1171,10 +2914,10 @@
 			(
 				'lang_add'			=> lang('add'),
 				'lang_add_custom_functiontext'	=> lang('add a custom_function'),
-				'add_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_custom_function', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id)),
+				'add_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.edit_custom_function', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id,'type' => $this->type)),
 				'lang_done'			=> lang('done'),
 				'lang_done_custom_functiontext'	=> lang('back to admin'),
-				'done_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category', 'entity_id'=> $entity_id)),
+				'done_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.category', 'entity_id'=> $entity_id,'type' => $this->type)),
 			);
 
 			if(!$this->allrows)
@@ -1193,7 +2936,8 @@
 				'order'		=> $this->order,
 				'query'		=> $this->query,
 				'entity_id'	=> $entity_id,
-				'cat_id'	=> $cat_id
+				'cat_id'	=> $cat_id,
+				'type'		=> $this->type
 			);
 
 			$entity = $this->bo->read_single($entity_id,false);
@@ -1226,10 +2970,10 @@
 			$appname	= lang('custom function');
 			$function_msg	= lang('list entity custom function');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list_custom_function' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
-			$this->save_sessiondata();
+			$this->save_sessiondata();*/
 		}
 
 		function edit_custom_function()
@@ -1304,7 +3048,8 @@
 				'menuaction'	=> 'property.uiadmin_entity.edit_custom_function',
 				'entity_id'	=> $entity_id,
 				'cat_id'	=> $cat_id,
-				'id'		=> $id
+				'id'		=> $id,
+				'type'		=> $this->type
 			);
 
 
@@ -1324,7 +3069,7 @@
 
 				'msgbox_data'					=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
 				'form_action'					=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'done_action'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id)),
+				'done_action'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_entity.list_custom_function', 'entity_id'=> $entity_id, 'cat_id'=> $cat_id, 'type' => $this->type)),
 				'lang_id'					=> lang('Custom function ID'),
 				'lang_entity_type'				=> lang('Entity type'),
 				'lang_no_entity_type'				=> lang('No entity type'),
@@ -1351,7 +3096,7 @@
 
 			$appname = lang('entity');
 
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang($this->type_app[$this->type]) . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit_custom_function' => $data));
 		}
 	}

Modified: people/sigurdne/modules/property/trunk/inc/class.uiadmin_location.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiadmin_location.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.uiadmin_location.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -26,6 +26,7 @@
 	* @subpackage admin
  	* @version $Id$
 	*/
+	phpgw::import_class('phpgwapi.yui');
 
 	/**
 	 * Description
@@ -50,8 +51,10 @@
 			'view'   		=> true,
 			'edit'   		=> true,
 			'delete' 		=> true,
-			'list_attribute'=> true,
+			'list_attribute'		=> true,
 			'edit_attrib' 	=> true,
+			'list_attribute_group'	=> true,
+			'edit_attrib_group'		=> true,
 		);
 
 		function property_uiadmin_location()
@@ -102,6 +105,325 @@
 			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= '::location';
 
 			$this->bocommon->reset_fm_cache();
+
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'	=> 'property.uiadmin_location.index'
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_location.index'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
+				(
+					'menuaction'	=> 'property.uiadmin_location.index'
+				);
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_location.index'
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
+			$standard_list = $this->bo->read();
+			$uicols['name'][0]	= 'id';
+			$uicols['descr'][0]	= lang('standard id');
+			$uicols['name'][1]	= 'name';
+			$uicols['descr'][1]	= lang('Name');
+			$uicols['name'][2]	= 'descr';
+			$uicols['descr'][2]	= lang('Descr');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
+			if (isset($standard_list) AND is_array($standard_list))
+			{
+				foreach($standard_list as $standard_entry)
+				{
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+						if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']				= $standard_entry[$uicols['name'][$k]];
+						}
+					}
+					$j++;
+				}
+			}
+
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'type_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'categories',
+						'statustext' 	=> lang('categories'),
+						'text'			=> lang('Categories'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uicategory.index',
+									'type'			=> 'location'
+
+								)),
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'attribute_groups',
+						'statustext' 	=> lang('attribute groups'),
+						'text'			=> lang('attribute groups'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_location.list_attribute_group'
+								)),
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'attributes',
+						'statustext' 	=> lang('attributes'),
+						'text'			=> lang('Attributes'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_location.list_attribute'
+
+								)),
+					'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('edit'),
+						'text'			=> lang('edit'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_location.edit'
+								)),
+					'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('delete'),
+						'text'			=> lang('delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+								(
+									'menuaction'	=> 'property.uiadmin_location.delete'
+								)),
+					'parameters'	=> $parameters
+					);
+
+
+			$datatable['rowactions']['action'][] = array(
+					'my_name' 		=> 'add',
+					'text' 			=> lang('add'),
+					'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+					(
+						'menuaction'	=> 'property.uiadmin_location.edit'
+					)));
+
+			unset($parameters);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
+			{
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'id';
+					}
+					if($uicols['name'][$i]=='name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'name';
+					}
+				}
+			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($standard_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
+			$appname		= lang('entity');
+			$function_msg	= lang('list entity type');
+
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'id'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
+			else
+			{
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  $json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_location.index', 'property' );
+			/*if(!$this->acl_read)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=>1, 'acl_location'=> $this->acl_location));
+			}
+
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= '::location';
+
+			$this->bocommon->reset_fm_cache();
 			$GLOBALS['phpgw']->xslttpl->add_file(array(
 								'admin_location',
 								'nextmatchs',
@@ -118,6 +440,7 @@
 					'first'							=> $standard['descr'],
 					'link_categories'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uicategory.index', 'type'=>'location', 'type_id'=> $standard['id'])),
 					'link_attribute'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute', 'type_id'=> $standard['id'])),
+					'link_attribute_group'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute_group', 'type_id'=> $standard['id'])),
 					'link_edit'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.edit' ,'id'=> $standard['id'])),
 					'link_delete'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.delete' ,'id'=> $standard['id'])),
 					'lang_view_standardtext'		=> lang('view the standard'),
@@ -127,6 +450,7 @@
 					'lang_delete_standardtext'		=> lang('delete the standard'),
 					'text_categories'				=> lang('Categories'),
 					'text_attribute'				=> lang('Attributes'),
+					'text_attribute_group'			=> lang('attribute groups'),
 					'text_edit'						=> lang('edit'),
 					'text_delete'					=> lang('delete')
 				);
@@ -199,7 +523,7 @@
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list' => $data));
 		//	$GLOBALS['phpgw']->xslttpl->pp();
-			$this->save_sessiondata();
+			$this->save_sessiondata();*/
 		}
 
 		function edit()
@@ -302,11 +626,27 @@
 				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 8, 'acl_location'=> $this->acl_location));
 			}
 
+			$group_id   = phpgw::get_var('group_id', 'int');
 			$attrib		= phpgw::get_var('attrib');
 			$type_id	= phpgw::get_var('type_id', 'int');
 			$id			= phpgw::get_var('id', 'int');
 			$confirm	= phpgw::get_var('confirm', 'bool', 'POST');
 
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+				$receipt =  $this->bo->delete($type_id,$id,$attrib,$group_id);
+
+				//FIXME
+				if(isset($receipt['message']))
+				{
+					return $receipt['message'][0]['msg'];
+				}
+				else
+				{
+					return $receipt['error'][0]['msg'];
+				}
+			}
+			
 			if($attrib)
 			{
 				$function='list_attribute';
@@ -321,12 +661,6 @@
 				'type_id' => $type_id
 			);
 
-			if ($confirm)
-			{
-				$this->bo->delete($type_id,$id,$attrib);
-				$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
-			}
-
 			$GLOBALS['phpgw']->xslttpl->add_file(array('app_delete'));
 
 			$data = array
@@ -348,8 +682,7 @@
 		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
 
-
-		function list_attribute()
+		function list_attribute_group()
 		{
 			if(!$this->acl_read)
 			{
@@ -357,100 +690,517 @@
 			}
 
 			$type_id	= phpgw::get_var('type_id', 'int');
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::location::attribute_loc_{$type_id}";
+
+			$location	= ".location.{$type_id}";
 			$id	= phpgw::get_var('id', 'int');
 			$resort	= phpgw::get_var('resort');
-			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::location::attribute_loc_{$type_id}";
 
-			$GLOBALS['phpgw']->xslttpl->add_file(array(
-								'admin_location',
-								'nextmatchs',
-								'search_field'));
-
 			if($resort)
 			{
-				$this->bo->resort_attrib(array('resort'=>$resort,'type_id' => $type_id,'id'=>$id));
+				$this->bo->resort_attrib_group($location, $id, $resort);
 			}
 
-			$type = $this->bo->read_single($type_id);
+			$datatable = array();
 
-			$attrib_list = $this->bo->read_attrib($type_id);
-
-			while (is_array($attrib_list) && list(,$attrib) = each($attrib_list))
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
 			{
-				$content[] = array
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
 				(
-					'datatype'					=> $attrib['trans_datatype'],
-					'column_name'				=> $attrib['column_name'],
-					'input_text'				=> $attrib['input_text'],
-					'sorting'					=> $attrib['attrib_sort'],
-					'link_up'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute', 'resort'=> 'up', 'id'=> $attrib['id'], 'type_id'=> $type_id, 'allrows'=> $this->allrows)),
-					'link_down'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute', 'resort'=> 'down', 'id'=> $attrib['id'], 'type_id'=> $type_id, 'allrows'=> $this->allrows)),
-					'link_edit'					=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.edit_attrib', 'id'=> $attrib['id'], 'type_id'=> $type_id)),
-					'link_delete'				=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.delete', 'id'=> $attrib['id'], 'type_id'=> $type_id, 'attrib'=>true)),
-					'lang_view_attribtext'		=> lang('view the attrib'),
-					'lang_attribute_attribtext'	=> lang('attributes for the attrib'). ' ' . lang('location'),
-					'lang_edit_attribtext'		=> lang('edit the attrib'),
-					'lang_delete_attribtext'	=> lang('delete the attrib'),
-					'text_attribute'			=> lang('Attributes'),
-					'text_up'					=> lang('up'),
-					'text_down'					=> lang('down'),
-					'text_edit'					=> lang('edit'),
-					'text_delete'				=> lang('delete')
-				);
-			}
+	    			'menuaction'	=> 'property.uiadmin_location.list_attribute',
+					'sort'		=> $this->sort,
+					'order'		=> $this->order,
+					'query'		=> $this->query,
+					'type_id'	=> $type_id
+   				));
 
-//_debug_array($content);
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_location.list_attribute_group',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."type_id:'{$type_id}'";
 
-			$table_header[] = array
-			(
-				'lang_descr'		=> lang('Descr'),
-				'lang_datatype'		=> lang('Datatype'),
-				'lang_sorting'		=> lang('sorting'),
-				'lang_edit'			=> lang('edit'),
-				'lang_delete'		=> lang('delete'),
-				'sort_sorting'		=> $this->nextmatchs->show_sort_order(array
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
 										(
+					'menuaction'	=> 'property.uiadmin_location.list_attribute',
 											'sort'	=> $this->sort,
-											'var'	=> 'attrib_sort',
 											'order'	=> $this->order,
-											'extra'	=> array('menuaction'	=> 'property.uiadmin_location.list_attribute',
+					'query'		=> $this->query,
 															'type_id'	=> $type_id,
-															'allrows'	=> $this->allrows)
-										)),
+				);
 
-				'sort_name'			=> $this->nextmatchs->show_sort_order(array
-										(
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_location.list_attribute',
 											'sort'	=> $this->sort,
-											'var'	=> 'column_name',
 											'order'	=> $this->order,
-											'extra' => array('menuaction'	=> 'property.uiadmin_location.list_attribute',
-																'type_id'	=>$type_id,
-																'allrows'	=>$this->allrows)
-										)),
-				'lang_name'			=> lang('Name'),
+								'query'		=> $this->query,
+								'type_id'	=> $type_id
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
 			);
 
-			$table_add[] = array
+				$dry_run = true;
+			}
+
+			$attrib_list = $this->bo->read_attrib_group($location);
+			$uicols['name'][0]	= 'name';
+			$uicols['descr'][0]	= lang('Name');
+			$uicols['name'][1]	= 'descr';
+			$uicols['descr'][1]	= lang('Descr');
+			$uicols['name'][2]	= 'group_sort';
+			$uicols['descr'][2]	= lang('sorting');
+			$uicols['name'][3]	= 'up';
+			$uicols['descr'][3]	= lang('up');
+			$uicols['name'][4]	= 'down';
+			$uicols['descr'][4]	= lang('down');
+			$uicols['name'][5]	= 'id';
+			$uicols['descr'][5]	= lang('id');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
+			if (isset($attrib_list) AND is_array($attrib_list))
+			{
+				foreach($attrib_list as $attrib_entry)
+				{
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+						if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']			= $attrib_entry[$uicols['name'][$k]];
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'up')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'up';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute_group', 'resort'=> 'up', 'type_id'=> $type_id, 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+
+						if($datatable['rows']['row'][$j]['column'][$k]['name'] == 'down')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'down';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute_group', 'resort'=> 'down', 'type_id'=> $type_id, 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.')';
+						}
+					}
+					$j++;
+				}
+			}
+
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
 			(
-				'lang_add'				=> lang('add'),
-				'lang_add_attribtext'	=> lang('add an attrib'),
-				'add_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.edit_attrib', 'type_id'=> $type_id)),
-				'lang_done'				=> lang('done'),
-				'lang_done_attribtext'	=> lang('back to admin'),
-				'done_action'			=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.index')),
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
 			);
 
-			if(!$this->allrows)
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'group_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('Edit'),
+						'text'			=> lang('Edit'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_location.edit_attrib_group',
+								'type_id'			=> $type_id
+							)
+						),
+						'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('Delete'),
+						'text'			=> lang('Delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_location.delete',
+								'type_id'			=> $type_id
+							)
+						),
+						'parameters'	=> $parameters2
+					);
+
+			$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'statustext' 	=> lang('add'),
+							'text'			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiadmin_location.edit_attrib_group',
+										'type_id' 				=> $type_id
+									))
+						);
+
+			unset($parameters);
+			unset($parameters2);
+
+
+			for ($i=0;$i<$count_uicols_name;$i++)
 			{
-				$record_limit	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['visible'] 			= false;
+					}
+
+					if($uicols['name'][$i]=='name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'name';
+					}
+				}
 			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($attrib_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
+			$appname	= lang('attribute');
+			$function_msg	= lang('list entity attribute');
+
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'name'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
 			else
 			{
-				$record_limit	= $this->bo->total_records;
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
 			}
 
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  $json_row[$column['name']] = "<a href='#' onclick='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+				// query parameters
+				if(isset($current_Consult) && is_array($current_Consult))
+				{
+					$json ['current_consult'] = $current_Consult;
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_location.attribute_group', 'property' );
+		}
+
+		function edit_attrib_group()
+		{
+			if(!$this->acl_add)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 2, 'acl_location'=> $this->acl_location));
+			}
+
+			$type_id	= phpgw::get_var('type_id', 'int');
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::location::attribute_loc_{$type_id}";
+			$location	= ".location.{$type_id}";
+			$id			= phpgw::get_var('id', 'int');
+			$values		= phpgw::get_var('values');
+			if(!$values)
+			{
+				$values=array();
+			}
+
+			$GLOBALS['phpgw']->xslttpl->add_file(array('admin_entity'));
+
+			if (isset($values['save']) && $values['save'])
+			{
+				if($id)
+				{
+					$values['id']=$id;
+					$action='edit';
+				}
+
+				$values['location'] = $location;
+
+				if (!$values['group_name'])
+				{
+					$receipt['error'][] = array('msg'=>lang('group name not entered!'));
+				}
+
+				if (!$values['descr'])
+				{
+					$receipt['error'][] = array('msg'=>lang('description not entered!'));
+				}
+
+				if (!$location)
+				{
+					$receipt['error'][] = array('msg'=>lang('location not chosen!'));
+				}
+
+
+				if (!isset($receipt['error']))
+				{
+					$receipt = $this->bo->save_attrib_group($values,$action);
+
+					if(!$id)
+					{
+						$id=$receipt['id'];
+					}
+				}
+				else
+				{
+					$receipt['error'][] = array('msg' => lang('Attribute group has NOT been saved'));
+				}
+			}
+
+			if ($id)
+			{
+				$values = $this->bo->read_single_attrib_group($location,$id);
+				$type_name=$values['type_name'];
+				$function_msg = lang('edit attribute group'). ' ' . lang($type_name);
+				$action='edit';
+			}
+			else
+			{
+				$function_msg = lang('add attribute group');
+				$action='add';
+			}
+
 			$link_data = array
 			(
+				'menuaction'	=> 'property.uiadmin_location.edit_attrib_group',
+				'type_id'	=> $type_id,
+				'id'		=> $id
+			);
+
+
+			$type = $this->bo->read_single( $type_id,false);
+
+			$msgbox_data = (isset($receipt)?$this->bocommon->msgbox_data($receipt):'');
+
+			$data = array
+			(
+				'lang_entity'						=> lang('location'),
+				'entity_name'						=> $type['name'],
+
+				'msgbox_data'						=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
+				'form_action'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
+				'done_action'						=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute_group', 'type_id'=> $type_id)),
+				'lang_id'							=> lang('Attribute group ID'),
+				'lang_entity_type'					=> lang('Entity type'),
+				'lang_no_entity_type'				=> lang('No entity type'),
+				'lang_save'							=> lang('save'),
+				'lang_done'							=> lang('done'),
+				'value_id'							=> $id,
+
+				'lang_group_name'					=> lang('group name'),
+				'value_group_name'					=> $values['group_name'],
+				'lang_group_name_statustext'		=> lang('enter the name for the group'),
+
+				'lang_descr'						=> lang('descr'),
+				'value_descr'						=> $values['descr'],
+				'lang_descr_statustext'				=> lang('enter the input text for records'),
+
+				'lang_remark'						=> lang('remark'),
+				'lang_remark_statustext'			=> lang('Enter a remark for the group'),
+				'value_remark'						=> $values['remark'],
+
+				'lang_done_attribtext'				=> lang('Back to the list'),
+				'lang_save_attribtext'				=> lang('Save the attribute')
+			);
+
+			$appname = lang('location');
+
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
+			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit_attrib_group' => $data));
+		}
+
+
+		function list_attribute()
+		{
+			if(!$this->acl_read)
+			{
+				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
+			}
+
+			$type_id	= phpgw::get_var('type_id', 'int');
+			$id	= phpgw::get_var('id', 'int');
+			$resort	= phpgw::get_var('resort');
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] .= "::location::attribute_loc_{$type_id}";
+
+			if($resort)
+			{
+				$this->bo->resort_attrib(array('resort'=>$resort,'type_id' => $type_id,'id'=>$id));
+			}
+
+			$type = $this->bo->read_single($type_id);
+
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'	=> 'property.uiadmin_location.list_attribute',
+					'sort'			=> $this->sort,
+					'order'			=> $this->order,
+					'query'			=> $this->query,
+					'type_id'		=> $type_id,
+					'allrows'		=> $this->allrows
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiadmin_location.list_attribute',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+						 	                        ."query:'{$this->query}',"
+						 	                        ."type_id:'{$type_id}',"
+						 	                        ."allrows:'{$this->allrows}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
+				(
 				'menuaction'	=> 'property.uiadmin_location.list_attribute',
 				'sort'			=> $this->sort,
 				'order'			=> $this->order,
@@ -458,34 +1208,310 @@
 				'type_id'		=> $type_id
 			);
 
-			$data = array
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction'	=> 'property.uiadmin_location.list_attribute',
+								'sort'			=> $this->sort,
+								'order'			=> $this->order,
+				'query'							=> $this->query,
+								'type_id'		=> $type_id
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_done',
+							                                'value'	=> lang('done'),
+							                                'tab_index' => 1
+							                            ),
+							                            array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 2
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 3
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 4
+				                                        ),
+				                                        array(
+				                                            'id' => 'txtcategory',
+				                                            'name' => 'search',
+				                                            'value'    => 'Location type: '.$type['name'],
+				                                            'type' => 'label',
+				                                            'style' => 'filter'
+				                                        )
+			                           				),
+			                       		'hidden_value' => array(
+
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
+			$attrib_list = $this->bo->read_attrib($type_id);
+			$uicols['name'][0]	= 'column_name';
+			$uicols['descr'][0]	= lang('Name');
+			$uicols['name'][1]	= 'input_text';
+			$uicols['descr'][1]	= lang('Descr');
+			$uicols['name'][2]	= 'trans_datatype';
+			$uicols['descr'][2]	= lang('Datatype');
+			$uicols['name'][3]	= 'group_id';
+			$uicols['descr'][3]	= lang('group');
+			$uicols['name'][4]	= 'attrib_sort';
+			$uicols['descr'][4]	= lang('sorting');
+			$uicols['name'][5]	= 'up';
+			$uicols['descr'][5]	= lang('up');
+			$uicols['name'][6]	= 'down';
+			$uicols['descr'][6]	= lang('down');
+			$uicols['name'][7]	= 'id';
+			$uicols['descr'][7]	= lang('id');
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
+			if (isset($attrib_list) AND is_array($attrib_list))
+			{
+				foreach($attrib_list as $attrib_entry)
+				{
+					for ($k=0;$k<$count_uicols_name;$k++)
+					{
+			//			if($uicols['input_type'][$k]!='hidden')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']			= isset($attrib_entry[$uicols['name'][$k]]) ? $attrib_entry[$uicols['name'][$k]] : '';
+						}
+
+						if(isset($datatable['rows']['row'][$j]['column'][$k]['name']) && $datatable['rows']['row'][$j]['column'][$k]['name'] == 'up')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'up';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute', 'resort'=> 'up', 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows, 'type_id' => $type_id)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.',"' . $this->allrows . '")';
+						}
+
+						if(isset($datatable['rows']['row'][$j]['column'][$k]['name']) && $datatable['rows']['row'][$j]['column'][$k]['name'] == 'down')
+						{
+							$datatable['rows']['row'][$j]['column'][$k]['format'] 			= 'link';
+							$datatable['rows']['row'][$j]['column'][$k]['value']		= 'down';//$uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['target']	= '_blank';
+							$url = '"'.$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiadmin_location.list_attribute', 'resort'=> 'down', 'id'=> $attrib_entry['id'], 'allrows'=> $this->allrows, 'type_id' => $type_id)).'"';
+							$datatable['rows']['row'][$j]['column'][$k]['link']			= 'move_record('.$url.',"' . $this->allrows . '")';
+						}
+					}
+					$j++;
+				}
+			}
+
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
 			(
-				'value_type_name'				=> $type['name'],
-				'lang_type'						=> lang('Location type'),
-				'allow_allrows'					=> true,
-				'allrows'						=> $this->allrows,
-				'start_record'					=> $this->start,
-				'record_limit'					=> $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'],
-				'num_records'					=> count($attrib_list),
-				'all_records'					=> $this->bo->total_records,
-				'link_url'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'img_path'						=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
-				'lang_searchfield_attribtext'	=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
-				'lang_searchbutton_attribtext'	=> lang('Submit the search string'),
-				'query'							=> $this->query,
-				'lang_search'					=> lang('search'),
-				'table_header_attrib'			=> $table_header,
-				'values_attrib'					=> $content,
-				'table_add'						=> $table_add
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
 			);
 
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'edit',
+						'statustext' 	=> lang('Edit'),
+						'text'			=> lang('Edit'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_location.edit_attrib',
+								'type_id' 				=> $type_id
+							)
+						),
+						'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array
+					(
+						'my_name' 			=> 'delete',
+						'statustext' 	=> lang('Delete'),
+						'text'			=> lang('Delete'),
+						'confirm_msg'	=> lang('do you really want to delete this entry'),
+						'action'		=> $GLOBALS['phpgw']->link
+						(
+							'/index.php',array
+							(
+								'menuaction'		=> 'property.uiadmin_location.delete',
+								'type_id'			=> $type_id,
+								'attrib' 				=> true
+							)
+						),
+						'parameters'	=> $parameters
+					);
+
+			$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'statustext' 	=> lang('add'),
+							'text'			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiadmin_location.edit_attrib',
+										'type_id'			=> $type_id,
+									))
+			);
+
+			unset($parameters);
+
+
+			for ($i=0;$i<$count_uicols_name;$i++)
+			{
+//				if($uicols['input_type'][$i]!='hidden')
+				{
+					$datatable['headers']['header'][$i]['formatter'] 		= (!isset($uicols['formatter'][$i]) || !$uicols['formatter'][$i]?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='column_name')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'column_name';
+					}
+					if($uicols['name'][$i]=='id')
+					{
+						$datatable['headers']['header'][$i]['visible'] 			= false;
+					}
+					if($uicols['name'][$i]=='attrib_sort')
+					{
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'attrib_sort';
+					}
+				}
+			}
+
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($attrib_list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
+
 			$appname	= lang('attribute');
-			$function_msg	= lang('list location attribute');
+			$function_msg	= lang('list entity attribute');
 
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
+			{
+				$datatable['sorting']['order'] 			= 'attrib_sort'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'asc'; // ASC / DESC
+			}
+			else
+			{
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
+			}
+
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
+
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
+	    		(
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
+	    		);
+
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && isset($column['java_link']) && $column['java_link']==true)
+		    				{
+		    					//$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  //$json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				  $json_row[$column['name']] = "<a href='#' onclick='".$column['link']."'>" .$column['value']."</a>";
+		    				  //$json_row[$column['name']] = '<a href="#" onclick="delete_record("/index.php?menuaction=property.uiasync.delete")">' .$column['value'].'</a>';
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
+
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
+
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
+
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
+
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
+
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
-			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list_attribute' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
-			$this->save_sessiondata();
+
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'admin_location.attribute', 'property' );
+
+//			$this->save_sessiondata();
 		}
 
 		function edit_attrib()
@@ -657,6 +1683,11 @@
 				'lang_no_datatype'				=> lang('No datatype'),
 				'datatype_list'					=> $this->bocommon->select_datatype($values['column_info']['type']),
 
+				'lang_group'					=> lang('group'),
+				'lang_group_statustext'			=> lang('Select a group'),
+				'lang_no_group'					=> lang('no group'),
+				'attrib_group_list'				=> $this->bo->get_attrib_group_list($type_id, $values['group_id']),
+
 				'lang_precision'				=> lang('Precision'),
 				'lang_precision_statustext'		=> lang('enter the record length'),
 				'value_precision'				=> $values['column_info']['precision'],

Modified: people/sigurdne/modules/property/trunk/inc/class.uiagreement.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiagreement.inc.php	2009-11-20 10:28:44 UTC (rev 20847)
+++ people/sigurdne/modules/property/trunk/inc/class.uiagreement.inc.php	2009-11-20 10:29:01 UTC (rev 20848)
@@ -31,7 +31,7 @@
 	 * Description
 	 * @package property
 	 */
-
+	phpgw::import_class('phpgwapi.yui');
 	class property_uiagreement
 	{
 		var $grants;
@@ -110,7 +110,7 @@
 
 		function columns()
 		{
-
+			phpgwapi_yui::load_widget('tabview');
 			$GLOBALS['phpgw']->xslttpl->add_file(array('columns'));
 
 			$GLOBALS['phpgw_info']['flags']['noframework'] = true;
@@ -122,7 +122,7 @@
 			{
 
 				$GLOBALS['phpgw']->preferences->account_id=$this->account;
-				$GLOBALS['phpgw']->preferences->read_repository();
+				$GLOBALS['phpgw']->preferences->read();
 				$GLOBALS['phpgw']->preferences->add('property','agreement_columns',$values['columns'],'user');
 				$GLOBALS['phpgw']->preferences->save_repository();
 
@@ -174,195 +174,394 @@
 				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=>1, 'acl_location'=> $this->acl_location));
 			}
 
-			$GLOBALS['phpgw_info']['flags']['menu_selection'] = 'property::agreement::pricebook::agreement';
-			$GLOBALS['phpgw']->xslttpl->add_file(array('agreement',
-										'receipt',
-										'search_field',
-										'nextmatchs',
-										'filter_member_of'));
-
 			$receipt = $GLOBALS['phpgw']->session->appsession('session_data','agreement_receipt');
 			$GLOBALS['phpgw']->session->appsession('session_data','agreement_receipt','');
 
+			$GLOBALS['phpgw_info']['flags']['menu_selection'] = 'property::agreement::pricebook::agreement';
+
+			$datatable = array();
+
+			if( phpgw::get_var('phpgw_return_as') != 'json' )
+			{
+				$datatable['menu']					= $this->bocommon->get_menu();
+	    		$datatable['config']['base_url'] = $GLOBALS['phpgw']->link('/index.php', array
+	    		(
+	    			'menuaction'			=> 'property.uiagreement.index',
+	    			'sort'		=>$this->sort,
+					'order'		=>$this->order,
+					'cat_id'	=>$this->cat_id,
+					'filter'	=>$this->filter,
+					'query'		=>$this->query,
+					'role'		=> $this->role,
+					'member_id'	=> $this->member_id
+   				));
+
+   				$datatable['config']['base_java_url'] = "menuaction:'property.uiagreement.index',"
+	    											."sort:'{$this->sort}',"
+	    											."order:'{$this->order}',"
+ 	                        						."cat_id: '{$this->cat_id}',"
+ 	                        						."filter:'{$this->filter}',"
+						 	                        ."query:'{$this->query}',"
+ 	                        						."role:'{$this->role}',"
+						 	                        ."member_id:'{$this->member_id}'";
+
+				$datatable['config']['allow_allrows'] = true;
+
+				$link_data = array
+				(
+					'menuaction'	=> 'property.uiagreement.index',
+					'sort'		=>$this->sort,
+					'order'		=>$this->order,
+					'cat_id'	=>$this->cat_id,
+					'filter'	=>$this->filter,
+					'query'		=>$this->query,
+					'role'		=> $this->role,
+					'member_id'	=> $this->member_id
+				);
+
+				$values_combo_box[0] = $this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' => true,'link_data' =>$link_data));
+				$default_value = array ('cat_id'=>'','name'=> lang('no member'));
+				array_unshift ($values_combo_box[0]['cat_list'],$default_value);
+
+				$values_combo_box[1]  = $this->bocommon->select_category_list(array('format'=>'filter','selected' => $this->cat_id,'type' =>'branch','order'=>'descr'));
+				$default_value = array ('id'=>'','name'=>lang('no category'));
+				array_unshift ($values_combo_box[1],$default_value);
+
+				$values_combo_box[2]  = $this->bo->select_vendor_list('filter',$this->vendor_id);
+				$default_value = array ('id'=>'','name'=>lang('no vendor'));
+				array_unshift ($values_combo_box[2],$default_value);
+
+				//_debug_array($values_combo_box[0]);die;
+
+				$datatable['actions']['form'] = array(
+				array(
+					'action'	=> $GLOBALS['phpgw']->link('/index.php',
+							array(
+								'menuaction' 		=> 'property.uiagreement.index',
+								'sort'		=>$this->sort,
+								'order'		=>$this->order,
+								'cat_id'	=>$this->cat_id,
+								'filter'	=>$this->filter,
+								'query'		=>$this->query,
+								'role'		=> $this->role,
+								'member_id'	=> $this->member_id
+							)
+						),
+					'fields'	=> array(
+	                                    'field' => array(
+				                                        array( //boton 	CATEGORY
+				                                            'id' => 'btn_member_id',
+				                                            'name' => 'member_id',
+				                                            'value'	=> lang('Member'),
+				                                            'type' => 'button',
+				                                            'style' => 'filter',
+				                                            'tab_index' => 1
+				                                        ),
+				                                        array( //boton 	STATUS
+				                                            'id' => 'btn_cat_id',
+				                                            'name' => 'category_id',
+				                                            'value'	=> lang('Category'),
+				                                            'type' => 'button',
+				                                            'style' => 'filter',
+				                                            'tab_index' => 2
+				                                        ),
+				                                        array( //boton 	HOUR CATEGORY
+				                                            'id' => 'btn_vendor_id',
+				                                            'name' => 'vendor_id',
+				                                            'value'	=> lang('Vendor'),
+				                                            'type' => 'button',
+				                                            'style' => 'filter',
+				                                            'tab_index' => 3
+				                                        ),
+														array(
+							                                'type'	=> 'button',
+							                            	'id'	=> 'btn_new',
+							                                'value'	=> lang('add'),
+							                                'tab_index' => 8
+							                            ),
+				                                        array( //boton     SEARCH
+				                                            'id' => 'btn_search',
+				                                            'name' => 'search',
+				                                            'value'    => lang('search'),
+				                                            'type' => 'button',
+				                                            'tab_index' => 7
+				                                        ),
+				   										array( // TEXT INPUT
+				                                            'name'     => 'query',
+				                                            'id'     => 'txt_query',
+				                                            'value'    => '',//$query,
+				                                            'type' => 'text',
+				                                            'onkeypress' => 'return pulsar(event)',
+				                                            'size'    => 28,
+				                                            'tab_index' => 6
+				                                        ),
+				                                        array(
+							                                'type' => 'link',
+							                                'id' => 'btn_columns',
+							                                'url' => "Javascript:window.open('".$GLOBALS['phpgw']->link('/index.php',
+																					           array
+																					              (
+																					               'menuaction' => 'property.uiagreement.columns',
+																								   'role'		=> $this->role
+																					              ))."','','width=300,height=600,scrollbars=1')",
+															'value' => lang('columns'),
+															'tab_index' => 9
+														)
+			                           				),
+			                       		'hidden_value' => array(
+						                                        array( //div values  combo_box_0
+								                                            'id' => 'values_combo_box_0',
+								                                            'value'	=> $this->bocommon->select2String($values_combo_box[0]['cat_list'], 'cat_id')
+								                                      ),
+								                                array( //div values  combo_box_1
+								                                            'id' => 'values_combo_box_1',
+								                                            'value'	=> $this->bocommon->select2String($values_combo_box[1])
+								                                      ),
+																 array( //div values  combo_box_2
+								                                            'id' => 'values_combo_box_2',
+								                                            'value'	=> $this->bocommon->select2String($values_combo_box[2])
+								                                      )
+			                       								)
+										)
+					 )
+				);
+
+				$dry_run = true;
+			}
+
 			$list = $this->bo->read();
 
 			$uicols		= $this->bo->uicols;
-			$content = array();
-			$j=0;
+			$j = 0;
+			$count_uicols_name = count($uicols['name']);
+
 			if (isset($list) AND is_array($list))
 			{
-				foreach($list as $entry)
+				foreach($list as $list_entry)
 				{
-					for ($i=0;$i<count($uicols['name']);$i++)
+					for ($k=0;$k<$count_uicols_name;$k++)
 					{
-						if($uicols['input_type'][$i]!='hidden')
+						if($uicols['input_type'][$k]!='hidden')
 						{
-							$content[$j]['row'][$i]['value'] 	= $entry[$uicols['name'][$i]];
-							$content[$j]['row'][$i]['name'] 	= $uicols['name'][$i];
+							$datatable['rows']['row'][$j]['column'][$k]['name'] 			= $uicols['name'][$k];
+							$datatable['rows']['row'][$j]['column'][$k]['value']				= $list_entry[$uicols['name'][$k]];
 						}
 					}
+					$j++;
+						}
+					}
 
+			$datatable['rowactions']['action'] = array();
+
+			$parameters = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
+			$parameters2 = array
+			(
+				'parameter' => array
+				(
+					array
+					(
+						'name'		=> 'agreement_id',
+						'source'	=> 'id'
+					),
+				)
+			);
+
 					if($this->acl_read)
 					{
-						$content[$j]['row'][$i]['statustext']		= lang('view the entity');
-						$content[$j]['row'][$i]['text']			= lang('view');
-						$content[$j]['row'][$i++]['link']		= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiagreement.view','id'=> $entry['id'], 'role'=> $this->role));
+				$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'view',
+							'statustext' 	=> lang('view this entity'),
+							'text'			=> lang('view'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiagreement.view',
+										'role'			=> $this->role
+									)),
+						'parameters'	=> $parameters
+						);
 					}
+
 					if($this->acl_edit)
 					{
-						$content[$j]['row'][$i]['statustext']		= lang('edit the agreement');
-						$content[$j]['row'][$i]['text']			= lang('edit');
-						$content[$j]['row'][$i++]['link']		= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiagreement.edit','id'=> $entry['id'], 'role'=> $this->role));
+				$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'edit',
+							'statustext' 	=> lang('edit this entity'),
+							'text'			=> lang('edit'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiagreement.edit',
+										'role'			=> $this->role
+									)),
+						'parameters'	=> $parameters
+						);
 					}
+
 					if($this->acl_delete)
 					{
-						$content[$j]['row'][$i]['statustext']		= lang('delete the agreement');
-						$content[$j]['row'][$i]['text']			= lang('delete');
-						$content[$j]['row'][$i++]['link']		= $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiagreement.delete', 'agreement_id'=> $entry['id'], 'role'=> $this->role));
+				$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'delete',
+							'statustext' 	=> lang('delete this entity'),
+							'text'			=> lang('delete'),
+							'confirm_msg'	=> lang('do you really want to delete this entry'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiagreement.delete',
+										'role'			=> $this->role
+									)),
+						'parameters'	=> $parameters2
+						);
 					}
 
-					$j++;
-				}
+			if($this->acl_add)
+			{
+				$datatable['rowactions']['action'][] = array(
+							'my_name' 			=> 'add',
+							'statustext' 	=> lang('add an entity'),
+							'text'			=> lang('add'),
+							'action'		=> $GLOBALS['phpgw']->link('/index.php',array
+									(
+										'menuaction'	=> 'property.uiagreement.edit',
+										'role'			=> $this->role
+									))
+						);
 			}
 
-//_debug_array($content);
-			for ($i=0;$i<count($uicols['descr']);$i++)
+			unset($parameters);
+			unset($parameters2);
+
+			for ($i=0;$i<$count_uicols_name;$i++)
 			{
 				if($uicols['input_type'][$i]!='hidden')
 				{
-					$table_header[$i]['header'] 	= $uicols['descr'][$i];
-					$table_header[$i]['width'] 		= '5%';
-					$table_header[$i]['align'] 		= 'center';
-					if($uicols['datatype'][$i]!='T' && $uicols['datatype'][$i]!='CH')
+					$datatable['headers']['header'][$i]['formatter'] 		= ($uicols['formatter'][$i]==''?  '""' : $uicols['formatter'][$i]);
+					$datatable['headers']['header'][$i]['name'] 			= $uicols['name'][$i];
+					$datatable['headers']['header'][$i]['text'] 			= $uicols['descr'][$i];
+					$datatable['headers']['header'][$i]['visible'] 			= true;
+					$datatable['headers']['header'][$i]['sortable']			= false;
+					if($uicols['name'][$i]=='id' || $uicols['name'][$i]=='name' || $uicols['name'][$i]=='org_name' || $uicols['name'][$i]=='category' || $uicols['name'][$i]=='start_date' || $uicols['name'][$i]=='end_date' || $uicols['name'][$i]=='status')
 					{
-						$table_header[$i]['sort_link']	=true;
-						$table_header[$i]['sort'] 		= $this->nextmatchs->show_sort_order(array
-							(
-								'sort'	=> $this->sort,
-								'var'	=> $uicols['name'][$i],
-								'order'	=> $this->order,
-								'extra'	=> array('menuaction'	=> 'property.uiagreement.index',
-													'query'		=> $this->query,
-													'role'		=> $this->role,
-													'member_id'	=> $this->member_id,
-													'allrows'	=> $this->allrows
-													)
-							));
-					}
-				}
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= $uicols['name'][$i];
 			}
 
-			if($this->acl_read)
+					if($uicols['name'][$i]=='category')
 			{
-				$table_header[$i]['width'] 			= '5%';
-				$table_header[$i]['align'] 			= 'center';
-				$table_header[$i]['header']			= lang('view');
-				$i++;
+						$datatable['headers']['header'][$i]['sortable']		= true;
+						$datatable['headers']['header'][$i]['sort_field']	= 'org_name';
 			}
-			if($this->acl_edit)
-			{
-				$table_header[$i]['width'] 			= '5%';
-				$table_header[$i]['align'] 			= 'center';
-				$table_header[$i]['header']			= lang('edit');
-				$i++;
 			}
-			if($this->acl_delete)
-			{
-				$table_header[$i]['width'] 			= '5%';
-				$table_header[$i]['align'] 			= 'center';
-				$table_header[$i]['header']			= lang('delete');
-				$i++;
 			}
 
+			//path for property.js
+			$datatable['property_js'] = $GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
 
-			if($this->acl_add)
-			{
-				$table_add = array
-				(
-					'lang_add'		=> lang('add'),
-					'lang_add_statustext'	=> lang('add an agreement'),
-					'add_action'		=> $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'role'=> $this->role))
-				);
-			}
+			// Pagination and sort values
+			$datatable['pagination']['records_start'] 	= (int)$this->bo->start;
+			$datatable['pagination']['records_limit'] 	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+			$datatable['pagination']['records_returned']= count($list);
+			$datatable['pagination']['records_total'] 	= $this->bo->total_records;
 
-			$link_data = array
-			(
-				'menuaction'	=> 'property.uiagreement.index',
-				'sort'		=>$this->sort,
-				'order'		=>$this->order,
-				'cat_id'	=>$this->cat_id,
-				'filter'	=>$this->filter,
-				'query'		=>$this->query,
-				'role'		=> $this->role,
-				'member_id'	=> $this->member_id
-			);
+			$appname					= lang('agreement');
+			$function_msg		= lang('List') . ' ' . lang($this->role);
 
-			if(!$this->allrows)
+			if ( (phpgw::get_var("start")== "") && (phpgw::get_var("order",'string')== ""))
 			{
-				$record_limit	= $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+				$datatable['sorting']['order'] 			= 'id'; // name key Column in myColumnDef
+				$datatable['sorting']['sort'] 			= 'desc'; // ASC / DESC
 			}
 			else
 			{
-				$record_limit	= $this->bo->total_records;
+				$datatable['sorting']['order']			= phpgw::get_var('order', 'string'); // name of column of Database
+				$datatable['sorting']['sort'] 			= phpgw::get_var('sort', 'string'); // ASC / DESC
 			}
 
-			$msgbox_data = $this->bocommon->msgbox_data($receipt);
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
 
-			$link_columns = array
+			//-- BEGIN----------------------------- JSON CODE ------------------------------
+			if( phpgw::get_var('phpgw_return_as') == 'json' )
+			{
+    		//values for Pagination
+	    		$json = array
 			(
-				'menuaction' 	=> 'property.uiagreement.columns',
-				'role'		=> $this->role
+	    			'recordsReturned' 	=> $datatable['pagination']['records_returned'],
+    				'totalRecords' 		=> (int)$datatable['pagination']['records_total'],
+	    			'startIndex' 		=> $datatable['pagination']['records_start'],
+					'sort'				=> $datatable['sorting']['order'],
+	    			'dir'				=> $datatable['sorting']['sort'],
+					'records'			=> array()
 			);
 
-			$member_of_data	= $this->cats->formatted_xslt_list(array('selected' => $this->member_id,'globals' => true,'link_data' =>$link_data));
+				// values for datatable
+	    		if(isset($datatable['rows']['row']) && is_array($datatable['rows']['row'])){
+	    			foreach( $datatable['rows']['row'] as $row )
+	    			{
+		    			$json_row = array();
+		    			foreach( $row['column'] as $column)
+		    			{
+		    				if(isset($column['format']) && $column['format']== "link" && $column['java_link']==true)
+		    				{
+		    					$json_row[$column['name']] = "<a href='#' id='".$column['link']."' onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+		    				}
+		    				elseif(isset($column['format']) && $column['format']== "link")
+		    				{
+		    				  $json_row[$column['name']] = "<a href='".$column['link']."'>" .$column['value']."</a>";
+		    				}else
+		    				{
+		    				  $json_row[$column['name']] = $column['value'];
+		    				}
+		    			}
+		    			$json['records'][] = $json_row;
+	    			}
+	    		}
 
-			$GLOBALS['phpgw']->js->validate_file('overlib','overlib','property');
+				// right in datatable
+				if(isset($datatable['rowactions']['action']) && is_array($datatable['rowactions']['action']))
+				{
+					$json ['rights'] = $datatable['rowactions']['action'];
+				}
 
-			$data = array
-			(
-				'menu'							=> $this->bocommon->get_menu(),
-				'lang_columns'					=> lang('columns'),
-				'link_columns'					=> $GLOBALS['phpgw']->link('/index.php',$link_columns),
-				'lang_columns_help'				=> lang('Choose columns'),
-				'msgbox_data'					=> $GLOBALS['phpgw']->common->msgbox($msgbox_data),
- 				'allow_allrows'					=> true,
-				'allrows'						=> $this->allrows,
-				'start_record'					=> $this->start,
-				'record_limit'					=> $record_limit,
-				'num_records'					=> count($list),
- 				'all_records'					=> $this->bo->total_records,
-				'link_url'						=> $GLOBALS['phpgw']->link('/index.php',$link_data),
-				'img_path'						=> $GLOBALS['phpgw']->common->get_image_path('phpgwapi','default'),
-				'lang_no_cat'					=> lang('no category'),
-				'lang_cat_statustext'			=> lang('Select the category the agreement belongs to. To do not use a category select NO CATEGORY'),
-				'select_name'					=> 'cat_id',
-				'cat_list'						=> $this->bocommon->select_category_list(array('format'=>'filter','selected' => $this->cat_id,'type' =>'branch','order'=>'descr')),
+	    		return $json;
+			}
+			//-------------------- JSON CODE ----------------------
 
-				'select_action'					=> $GLOBALS['phpgw']->link('/index.php',$link_data),
+			$template_vars = array();
+			$template_vars['datatable'] = $datatable;
+			$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+	      	$GLOBALS['phpgw']->xslttpl->set_var('phpgw', $template_vars);
 
-				'lang_no_vendor'				=> lang('no vendor'),
-				'lang_vendor_statustext'		=> lang('Select the vendor the agreement belongs to.'),
-				'vendor_list'					=> $this->bo->select_vendor_list('filter',$this->vendor_id),
+	      	if ( !isset($GLOBALS['phpgw']->css) || !is_object($GLOBALS['phpgw']->css) )
+	      	{
+	        	$GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+	      	}
 
-				'lang_no_member'				=> lang('no member'),
-				'member_of_name'				=> 'member_id',
-				'member_of_list'				=> $member_of_data['cat_list'],
+	      	$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
 
-				'filter_list'					=> $this->nextmatchs->xslt_filter(array('filter' => $this->filter)),
-				'lang_filter_statustext'		=> lang('Select the filter. To show all entries select SHOW ALL'),
-				'lang_searchfield_statustext'	=> lang('Enter the search string. To show all entries, empty this field and press the SUBMIT button again'),
-				'lang_searchbutton_statustext'	=> lang('Submit the search string'),
-				'query'							=> $this->query,
-				'lang_search'					=> lang('search'),
-				'table_header'					=> $table_header,
-				'values'						=> $content,
-				'table_add'						=> $table_add
-			);
-			$this->save_sessiondata();
-			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('agreement') . ': ' . lang('list ' . $this->role);
+			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('property') . ' - ' . $appname . ': ' . $function_msg;
 
-			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('list' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'agreement.index', 'property' );
 		}
 
 		function list_content($list,$uicols,$edit_item='',$view_only='')
@@ -480,12 +679,12 @@
 					if ($values['save'])
 					{
 						$GLOBALS['phpgw']->session->appsession('session_data','agreement_receipt',$receipt);
-						$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id));
+						$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id, 'tab' => 'items'));
 					}
 				}
 				else
 				{
-					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id));
+					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id, 'tab' => 'items'));
 
 				}
 			}
@@ -539,31 +738,31 @@
 
 		function edit()
 		{
+
 			if(!$this->acl_add)
 			{
 				$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uilocation.stop', 'perm'=>2, 'acl_location'=> $this->acl_location));
 			}
-
-
 			$id	= phpgw::get_var('id', 'int');
 			$values		= phpgw::get_var('values');
+//return _debug_array($values);
 			$delete_item	= phpgw::get_var('delete_item', 'bool');
 			$activity_id	= phpgw::get_var('activity_id', 'int');
+			$active_tab		= phpgw::get_var('tab', 'string', 'REQUEST', 'general');
 
 			$config		= CreateObject('phpgwapi.config','property');
 			$boalarm	= CreateObject('property.boalarm');
 			$receipt 	= array();
+			$get_items 		= false;
 
 			if($delete_item && $id && $activity_id)
 			{
 				$this->bo->delete_item($id,$activity_id);
+				$get_items = true;
 			}
-
 			$values_attribute  = phpgw::get_var('values_attribute');
-
 			$insert_record_agreement = $GLOBALS['phpgw']->session->appsession('insert_record_values.agreement','property');
 
-//_debug_array($insert_record_agreement);
 			if(isset($insert_record_agreement) && is_array($insert_record_agreement))
 			{
 				for ($j=0;$j<count($insert_record_agreement);$j++)
@@ -679,6 +878,7 @@
 					if(!$receipt['error'])
 					{
 						$receipt = $this->bo->update($values);
+						$get_items = true;
 					}
 
 				}
@@ -697,6 +897,7 @@
 					if(!isset($receipt['error']) || !$receipt['error'])
 					{
 						$receipt = $boalarm->enable_alarm('agreement',$values['alarm'],isset($values['enable_alarm'])?$values['enable_alarm']:'');
+
 					}
 
 				}
@@ -869,34 +1070,6 @@
 						'account_id'=> isset($account_id)?$account_id:''
 						));
 
-			$dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-			$sep = '/';
-			$dlarr[strpos($dateformat,'y')] = 'yyyy';
-			$dlarr[strpos($dateformat,'m')] = 'MM';
-			$dlarr[strpos($dateformat,'d')] = 'DD';
-			ksort($dlarr);
-
-			$dateformat= (implode($sep,$dlarr));
-
-			switch(substr($dateformat,0,1))
-			{
-				case 'M':
-					$dateformat_validate= "javascript:vDateType='1'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'1')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'1')";
-					break;
-				case 'y':
-					$dateformat_validate="javascript:vDateType='2'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'2')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'2')";
-					break;
-				case 'D':
-					$dateformat_validate="javascript:vDateType='3'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'3')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'3')";
-					break;
-			}
-
 			$msgbox_data = $this->bocommon->msgbox_data($receipt);
 
 			$table_add[] = array
@@ -941,10 +1114,257 @@
 
 			$GLOBALS['phpgw']->js->validate_file('overlib','overlib','property');
 			$GLOBALS['phpgw']->js->validate_file('core','check','property');
-			$GLOBALS['phpgw']->js->validate_file('dateformat','dateformat','property');
 
+			if (isset($agreement['attributes']) && is_array($agreement['attributes']))
+			{
+
+		/*		foreach ($values['attributes'] as & $attribute)
+				{
+					if($attribute['history'] == true)
+					{
+						$link_history_data = array
+						(
+							'menuaction'	=> 'property.uis_agreement.attrib_history',
+							'attrib_id'	=> $attribute['id'],
+							'id'		=> $id,
+							'edit'		=> true
+						);
+
+						$attribute['link_history'] = $GLOBALS['phpgw']->link('/index.php',$link_history_data);
+					}
+				}
+		*/
+
+				phpgwapi_yui::tabview_setup('edit_tabview');
+				$tabs['general']	= array('label' => lang('general'), 'link' => '#general');
+
+				$location = $this->acl_location;
+				$attributes_groups = $this->bo->get_attribute_groups($location, $agreement['attributes']);
+
+				$attributes = array();
+				foreach ($attributes_groups as $group)
+				{
+					if(isset($group['attributes']))
+					{
+						$attributes[] = $group;
+					}
+				}
+				unset($attributes_groups);
+				unset($agreement['attributes']);
+
+				$tabs['items']	= array('label' => lang('items'), 'link' => '#items');
+			}
+
+//------JSON code-------------------
+
+			//---GET ITEMS
+			if( phpgw::get_var('phpgw_return_as') == 'json' &&  $get_items )
+			{
+				if(count($content))
+				{
+					return json_encode($content);
+				}
+				else
+				{
+					return "";
+				}
+			}
+
+			//-- ALARMS ---
+			else if( phpgw::get_var('phpgw_return_as') == 'json' && !$get_items )
+			{
+				$alarm_data=$this->bocommon->initiate_ui_alarm(array(
+						'acl_location'=>$this->acl_location,
+						'alarm_type'=> 'agreement',
+						'type'		=> 'form',
+						'text'		=> 'Email notification',
+						'times'		=> isset($times)?$times:'',
+						'id'		=> $id,
+						'method'	=> isset($method)?$method:'',
+						'data'		=> isset($data)?$data:'',
+						'account_id'=> isset($account_id)?$account_id:''
+						));
+				//$alarm_data['values'] = array();
+				if(count($alarm_data['values']))
+				{
+					return json_encode($alarm_data['values']);
+				}
+				else
+				{
+					return "";
+				}
+			}
+
+			//---datatable0 settings---------------------------------------------------
+
+
+			$datavalues[0] = array
+			(
+				'name'			=> "0",
+				'values' 		=> json_encode($alarm_data['values']),
+				'total_records'	=> count($alarm_data['values']),
+				'permission'   	=> "''",
+				'is_paginator'	=> 0,
+				'footer'		=> 0
+			);
+       		$myColumnDefs[0] = array
+       		(
+       			'name'			=> "0",
+       			'values'		=>	json_encode(array(	array(key => time,	label=>$alarm_data['header'][0]['lang_time'],	sortable=>true,resizeable=>true,width=>140),
+									       				array(key => text,	label=>$alarm_data['header'][0]['lang_text'],	sortable=>true,resizeable=>true,width=>340),
+									       				array(key => user,	label=>$alarm_data['header'][0]['lang_user'],	sortable=>true,resizeable=>true,width=>200),
+		       				       						array(key => enabled,label=>$alarm_data['header'][0]['lang_enabled'],sortable=>true,resizeable=>true,formatter=>FormatterCenter,width=>60),
+		       				       						array(key => alarm_id,label=>"dummy",sortable=>true,resizeable=>true,hidden=>true),
+		       				       						array(key => select,label=>$alarm_data['header'][0]['lang_select'],	sortable=>false,resizeable=>false,formatter=>myFormatterCheck,width=>60)))
+			);
+
+       		$myButtons[0] = array
+       		(
+       			'name'			=> "0",
+       			'values'		=>	json_encode(array(	array(id =>'values[enable_alarm]',type=>buttons,	value=>Enable,	label=>$alarm_data[alter_alarm][0][lang_enable],	funct=> onActionsClick , classname=> actionButton, value_hidden=>""),
+       													array(id =>'values[disable_alarm]',type=>buttons,	value=>Disable,	label=>$alarm_data[alter_alarm][0][lang_disable],	funct=> onActionsClick , classname=> actionButton, value_hidden=>""),
+       													array(id =>'values[delete_alarm]',type=>buttons,	value=>Delete,	label=>$alarm_data[alter_alarm][0][lang_delete],	funct=> onActionsClick , classname=> actionButton, value_hidden=>""),
+       													))
+			);
+       		$myButtons[1] = array
+       		(
+       			'name'			=> "1",
+       			'values'		=>	json_encode(array(	array(id =>'values[time][days]',	type=>menu,		value=>$this->bocommon->make_menu_date($alarm_data['add_alarm']['day_list'],"1_0",'values[time][days]' ),	label=>"0", classname=> actionsFilter, value_hidden=>"0"),
+       													array(id =>'values[time][hours]',	type=>menu,		value=>$this->bocommon->make_menu_date($alarm_data['add_alarm']['hour_list'],"1_1",'values[time][hours]'),	label=>"0", classname=> actionsFilter, value_hidden=>"0"),
+       													array(id =>'values[time][mins]',	type=>menu,		value=>$this->bocommon->make_menu_date($alarm_data['add_alarm']['minute_list'],"1_2",'values[time][mins]'), label=>"0", classname=> actionsFilter, value_hidden=>"0"),
+       													array(id =>'values[user_id]',		type=>menu,		value=>$this->bocommon->make_menu_user($alarm_data['add_alarm']['user_list'],"1_3",'values[user_id]'),	label=>$this->bocommon->choose_select($alarm_data['add_alarm']['user_list'],"name"),classname=> actionsFilter, value_hidden=>$this->bocommon->choose_select($alarm_data['add_alarm']['user_list'],"id")),
+
+       													array(id =>'values[add_alarm]',		type=>buttons,	value=>Add,		label=>$alarm_data[add_alarm][lang_add],			funct=> onAddClick , classname=> actionButton, value_hidden=>"")
+       													))
+			);
+//_debug_array($alarm_data['add_alarm']['user_list']);die;
+
+//---datatable1 settings---------------------------------------------------
+			$parameters['view'] = array('parameter' => array(
+					array('name'  => 'agreement_id','source' => 'agreement_id'),
+					array('name'  => 'id',			'source' => 'id')));
+
+			$parameters['edit'] = array('parameter' => array(
+					array('name'  => 'agreement_id','source' => 'agreement_id'),
+					array('name'  => 'id',			'source' => 'id')));
+
+			$parameters['delete'] = array('parameter' => array(
+					array('name'  => 'delete_item',	'source' => 1,	'ready'  => 1),
+					array('name'  => 'id',			'source' => 'agreement_id'),
+					array('name'  => 'activity_id',	'source' => 'activity_id')));
+
+			$permission_update = false;
+			if($this->acl_read && (!isset($edit_item) || !$edit_item) && (!isset($view_only) || !$view_only))
+			{
+				$permissions['rowactions'][] = array(
+					'text'    => lang('view'),
+					'action'  => $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uiagreement.view_item')),
+					'parameters' => $parameters['view']
+			   	);
+			}
+			if($this->acl_edit && (!isset($edit_item) || !$edit_item) && (!isset($view_only) || !$view_only))
+			{
+				$permissions['rowactions'][] = array(
+					'text'    => lang('edit'),
+					'action'  => $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uiagreement.edit_item')),
+					'parameters' => $parameters['edit']
+			   	);
+			}
+			if($this->acl_delete && (!isset($edit_item) || !$edit_item) && (!isset($view_only) || !$view_only))
+			{
+				$permissions['rowactions'][] = array(
+					'text'    	=> lang('delete'),
+					'action'  	=> $GLOBALS['phpgw']->link('/index.php',array('menuaction' => 'property.uiagreement.edit' )),
+					'confirm_msg'=> lang('do you really want to delete this entry'),
+					'parameters'=> $parameters['delete']
+			   	);
+			}
+			if($this->acl_manage && (!isset($edit_item) || !$edit_item) && (!isset($view_only) || !$view_only))
+			{
+				$permission_update = true;
+			}
+
+			$datavalues[1] = array
+			(
+				'name'			=> "1",
+				'values' 		=> json_encode($content),
+				'total_records'	=> count($content),
+				'permission'   	=> json_encode($permissions['rowactions']),
+				'is_paginator'	=> 0,
+				'footer'		=> 1
+			);
+
+
+
+	       $myColumnDefs[1] = array
+	       (
+	       'name'			=> "1",
+	       'values'		=>	json_encode(array(	array(key => id,			label=>$table_header[0]['header'],	sortable=>true,resizeable=>true),
+										       	array(key => num,			label=>$table_header[1]['header'],	sortable=>true,resizeable=>true),
+										       	array(key => descr,			label=>$table_header[2]['header'],	sortable=>true,resizeable=>true),
+										       	array(key => unit,			label=>$table_header[3]['header'],	sortable=>true,resizeable=>true, formatter=>FormatterCenter),
+										       	array(key => m_cost,		label=>$table_header[4]['header'],	sortable=>true,resizeable=>true, formatter=>FormatterRight),
+										       	array(key => w_cost,		label=>$table_header[5]['header'],	sortable=>true,resizeable=>true, formatter=>FormatterRight),
+										       	array(key => total_cost,	label=>$table_header[6]['header'],	sortable=>true,resizeable=>true, formatter=>FormatterRight),
+										       	array(key => this_index,	label=>$table_header[7]['header'],	sortable=>true,resizeable=>true),
+										       	array(key => index_count,	label=>$table_header[8]['header'],	sortable=>true,resizeable=>true, formatter=>FormatterCenter),
+										       	array(key => index_date,	label=>$table_header[9]['header'],	sortable=>true,resizeable=>true),
+										       	$permission_update?array(key => select,		label=>$table_header[13]['header'],	sortable=>false,resizeable=>false,formatter=>FormatterCheckItems):"",
+										       	array(key => activity_id,	hidden=>true),
+										       	array(key => agreement_id,	hidden=>true)
+	       )));
+
+
+
+
+
+
+			$myButtons[2] = array
+       		(
+       			'name'			=> "2",
+       			'values'		=>	json_encode(array(	array(type=>text, label=>' New index:', classname=> 'index-opt'),
+       													array(id =>'values[new_index]', type=>inputText, size=>12, classname=> 'mybottonsUpdates'),
+       													array(id =>'values[update]',	type=>buttons,		value=>Update,	label=>lang('update'),	funct=> onUpdateClick , classname=> '')
+       													)));
+
+
+			$link_view_file = $GLOBALS['phpgw']->link('/index.php',$link_file_data);
+
+			for($z=0; $z<count($agreement['files']); $z++)
+			{
+				$content_files[$z]['file_name'] = '<a href="'.$link_view_file.'&amp;file_name='.$agreement['files'][$z]['file_name'].'" target="_blank" title="'.lang('click to view file').'" style="cursor:help">'.$agreement['files'][$z]['name'].'</a>';
+				$content_files[$z]['delete_file'] = '<input type="checkbox" name="values[file_action][]" value="'.$agreement['files'][$z]['name'].'" title="'.lang('Check to delete file').'" style="cursor:help">';
+			}
+
+			$datavalues[2] = array
+			(
+					'name'					=> "2",
+					'values' 				=> json_encode($content_files),
+					'total_records'			=> count($content_files),
+					'permission'   			=> "''",
+					'is_paginator'			=> 0,
+					'footer'				=> 0
+			);
+
+			$myColumnDefs[2] = array
+       		(
+       			'name'		=> "2",
+       			'values'	=>	json_encode(array(	array(key => file_name,label=>lang('Filename'),sortable=>false,resizeable=>true),
+									       			array(key => delete_file,label=>lang('Delete file'),sortable=>false,resizeable=>true,formatter=>FormatterCenter)))
+			);
+
+
+			//----------------------------------------------datatable settings--------
+
 			$data = array
 			(
+ 				'property_js'							=> json_encode($GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property2.js"),
+				'base_java_url'							=> json_encode(array(menuaction => "property.uiagreement.edit",id=>$id)),
+				'datatable'								=> $datavalues,
+				'myColumnDefs'							=> $myColumnDefs,
+				'myButtons'								=> $myButtons,
+
+				'img_cal'								=> $GLOBALS['phpgw']->common->image('phpgwapi','cal'),
  				'allow_allrows'							=> true,
 				'allrows'								=> $this->allrows,
 				'start_record'							=> $this->start,
@@ -993,16 +1413,10 @@
 				'member_of_name'						=> 'member_id',
 				'member_of_list'						=> $member_of_data['cat_list'],
 
-				'lang_dateformat' 						=> lang(strtolower($dateformat)),
-				'dateformat_validate'					=> $dateformat_validate,
-				'onKeyUp'								=> $onKeyUp,
-				'onBlur'								=> $onBlur,
-				'lang_attributes'						=> lang('Attributes'),
-				'attributes_values'						=> $agreement['attributes'],
+				'attributes_group'						=> $attributes,
 				'lookup_functions'						=> isset($agreement['lookup_functions'])?$agreement['lookup_functions']:'',
 				'dateformat'							=> $dateformat,
 
-				'img_cal'								=> $GLOBALS['phpgw']->common->image('phpgwapi','cal'),
 				'lang_datetitle'						=> lang('Select date'),
 
 				'lang_start_date_statustext'			=> lang('Select the estimated end date for the agreement'),
@@ -1042,13 +1456,31 @@
 				'status_name'							=> 'values[status]',
 				'lang_no_status'						=> lang('Select status'),
 				'textareacols'							=> isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textareacols'] : 40,
-				'textarearows'							=> isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] : 6
+				'textarearows'							=> isset($GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] ? $GLOBALS['phpgw_info']['user']['preferences']['property']['textarearows'] : 6,
+				'tabs'									=> phpgwapi_yui::tabview_generate($tabs, $active_tab)
 			);
+//_debug_array($data);die;
+			//---datatable settings--------------------
+			phpgwapi_yui::load_widget('dragdrop');
+		  	phpgwapi_yui::load_widget('datatable');
+		  	phpgwapi_yui::load_widget('menu');
+		  	phpgwapi_yui::load_widget('connection');
+		  	phpgwapi_yui::load_widget('loader');
+			phpgwapi_yui::load_widget('tabview');
+			phpgwapi_yui::load_widget('paginator');
+			phpgwapi_yui::load_widget('animation');
 
+			$GLOBALS['phpgw']->css->validate_file('datatable');
+		  	$GLOBALS['phpgw']->css->validate_file('property');
+		  	$GLOBALS['phpgw']->css->add_external_file('property/templates/base/css/property.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+			$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+			$GLOBALS['phpgw']->js->validate_file( 'yahoo', 'agreement.edit', 'property' );
+			//-----------------------datatable settings---
+
 			$GLOBALS['phpgw_info']['flags']['app_header'] = lang('agreement') . ': ' . ($id?lang('edit') . ' ' . lang($this->role):lang('add') . ' ' . lang($this->role));
-
 			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('edit' => $data));
-		//	$GLOBALS['phpgw']->xslttpl->pp();
 		}
 
 		function download()
@@ -1098,7 +1530,7 @@
 						if ($values['save'])
 						{
 							$GLOBALS['phpgw']->session->appsession('session_data','agreement_receipt',$receipt);
-							$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id));
+							$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id, 'tab' => 'items'));
 						}
 					}
 				}
@@ -1121,7 +1553,7 @@
 				}
 				elseif (!$values['save'] && !$values['apply'] && !$values['update']):
 				{
-					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id));
+					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiagreement.edit', 'id'=> $agreement_id, 'tab' => 'items'));
 				}
 				endif;
 			}
@@ -1138,34 +1570,6 @@
 			);
 
 
-			$dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
-			$sep = '/';
-			$dlarr[strpos($dateformat,'y')] = 'yyyy';
-			$dlarr[strpos($dateformat,'m')] = 'MM';
-			$dlarr[strpos($dateformat,'d')] = 'DD';
-			ksort($dlarr);
-
-			$dateformat= (implode($sep,$dlarr));
-
-			switch(substr($dateformat,0,1))
-			{
-				case 'M':
-					$dateformat_validate= "javascript:vDateType='1'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'1')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'1')";
-					break;
-				case 'y':
-					$dateformat_validate="javascript:vDateType='2'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'2')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'2')";
-					break;
-				case 'D':
-					$dateformat_validate="javascript:vDateType='3'";
-					$onKeyUp	= "DateFormat(this,this.value,event,false,'3')";
-					$onBlur		= "DateFormat(this,this.value,event,true,'3')";
-					break;
-			}
-
 			$jscal = CreateObject('phpgwapi.jscalendar');
 			$jscal->add_listener('values_date');
 
@@ -1207,11 +1611,108 @@
 				'lang_update_statustext'	=> lang('update selected investments')
 			);
 
+			if( phpgw::get_var('phpgw_return_as') == 'json')
+			{
+
+				$content_values = array();
+
+	  			$hidden = '';
+				for($y=0;$y<count($content);$y++)
+				{
+					for($z=0;$z<=count($content[$y]['row']);$z++)
+					{
+						if($content[$y]['row'][$z]['name']!='')
+						{
+							$content_values[$y][$content[$y]['row'][$z]['name']] = $content[$y]['row'][$z]['value'];
+						}
+					}
+				}
+
+				$hidden .= " <input name='values[select][0]' type='hidden' value='".$content_values[$y - 1]['activity_id']."'/>";
+				$hidden .= " <input name='values[total_cost][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['total_cost']."'/>";
+				$hidden .= " <input name='values[w_cost][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['w_cost']."'/>";
+				$hidden .= " <input name='values[m_cost][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['m_cost']."'/>";
+				$hidden .= " <input name='values[id][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['index_count']."'/>";
+
+				$content_values[$y - 1]['index_date'] .= $hidden;
+
+				if(count($content_values))
+				{
+					return json_encode($content_values);
+				}
+				else
+				{
+					return "";
+				}
+			}
+
+  			$hidden = '';
+			for($y=0;$y<count($content);$y++)
+			{
+				for($z=0;$z<=count($content[$y]['row']);$z++)
+				{
+					if($content[$y]['row'][$z]['name']!='')
+					{
+						$content_values[$y][$content[$y]['row'][$z]['name']] = $content[$y]['row'][$z]['value'];
+					}
+				}
+			}
+
+			$hidden .= " <input name='values[select][0]'  type='hidden' value='".$content_values[$y - 1]['activity_id']."'/>";
+			$hidden .= " <input name='values[total_cost][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['total_cost']."'/>";
+			$hidden .= " <input name='values[w_cost][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['w_cost']."'/>";
+			$hidden .= " <input name='values[m_cost][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['m_cost']."'/>";
+			$hidden .= " <input name='values[id][".$content_values[$y - 1]['activity_id']."]'  type='hidden' value='".$content_values[$y - 1]['index_count']."'/>";
+
+			$content_values[$y - 1]['index_date'] .= $hidden;
+
+			$datavalues[0] = array
+			(
+					'name'					=> "0",
+					'values' 				=> json_encode($content_values),
+					'total_records'			=> count($content_values),
+					'is_paginator'			=> 0,
+					'permission'			=> '""',
+					'footer'				=> 0
+			);
+
+       		$myColumnDefs[0] = array
+       		(
+       			'name'		=> "0",
+       			'values'	=>	json_encode(array(	array(key => activity_id,label=>lang('Activity ID'),sortable=>false,resizeable=>true),
+									       			array(key => m_cost,label=>lang('m_cost'),sortable=>false,resizeable=>true),
+									       			array(key => w_cost,label=>lang('w_cost'),sortable=>false,resizeable=>true),
+									       			array(key => total_cost,label=>lang('Total Cost'),sortable=>false,resizeable=>true),
+									       			array(key => this_index,label=>lang('index'),sortable=>false,resizeable=>true),
+									       			array(key => index_count,label=>lang('index_count'),sortable=>false,resizeable=>true),
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.