[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [12927] Merge from stavanger branch
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [12927] Merge from stavanger branch |
Date: |
Tue, 31 Mar 2015 11:17:46 +0000 |
Revision: 12927
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=12927
Author: sigurdne
Date: 2015-03-31 11:17:44 +0000 (Tue, 31 Mar 2015)
Log Message:
-----------
Merge from stavanger branch
Modified Paths:
--------------
trunk/booking/inc/class.async_task_send_reminder.inc.php
trunk/booking/inc/class.boallocation.inc.php
trunk/booking/inc/class.boapplication.inc.php
trunk/booking/inc/class.bobooking.inc.php
trunk/booking/inc/class.bocommon.inc.php
trunk/booking/inc/class.bodocument_view.inc.php
trunk/booking/inc/class.boevent.inc.php
trunk/booking/inc/class.boorganization.inc.php
trunk/booking/inc/class.customer_identifier.inc.php
trunk/booking/inc/class.menu.inc.php
trunk/booking/inc/class.soallocation.inc.php
trunk/booking/inc/class.soapplication.inc.php
trunk/booking/inc/class.sobooking.inc.php
trunk/booking/inc/class.sobuilding.inc.php
trunk/booking/inc/class.socommon.inc.php
trunk/booking/inc/class.socompleted_reservation_export.inc.php
trunk/booking/inc/class.socompleted_reservation_export_file.inc.php
trunk/booking/inc/class.soevent.inc.php
trunk/booking/inc/class.sogroup.inc.php
trunk/booking/inc/class.soorganization.inc.php
trunk/booking/inc/class.soresource.inc.php
trunk/booking/inc/class.uiaccount_code_set.inc.php
trunk/booking/inc/class.uiallocation.inc.php
trunk/booking/inc/class.uiapplication.inc.php
trunk/booking/inc/class.uibooking.inc.php
trunk/booking/inc/class.uibuilding.inc.php
trunk/booking/inc/class.uicommon.inc.php
trunk/booking/inc/class.uicompleted_reservation.inc.php
trunk/booking/inc/class.uicompleted_reservation_export.inc.php
trunk/booking/inc/class.uicompleted_reservation_export_file.inc.php
trunk/booking/inc/class.uievent.inc.php
trunk/booking/inc/class.uigroup.inc.php
trunk/booking/inc/class.uiorganization.inc.php
trunk/booking/inc/class.uiresource.inc.php
trunk/booking/inc/class.uiseason.inc.php
trunk/booking/jasper/templates/logo.png
trunk/booking/js/booking/application.js
trunk/booking/js/booking/common.js
trunk/booking/js/booking/schedule.js
trunk/booking/setup/default_records.inc.php
trunk/booking/setup/phpgw_no.lang
trunk/booking/setup/setup.inc.php
trunk/booking/setup/tables_current.inc.php
trunk/booking/setup/tables_update.inc.php
trunk/booking/templates/base/account_code_dimension.xsl
trunk/booking/templates/base/account_code_set.xsl
trunk/booking/templates/base/account_code_set_form.xsl
trunk/booking/templates/base/allocation_delete_preview.xsl
trunk/booking/templates/base/application.xsl
trunk/booking/templates/base/application_edit.xsl
trunk/booking/templates/base/application_new.xsl
trunk/booking/templates/base/booking_delete.xsl
trunk/booking/templates/base/building.xsl
trunk/booking/templates/base/building_form.xsl
trunk/booking/templates/base/css/base.css
trunk/booking/templates/base/organization_edit.xsl
trunk/booking/templates/base/resource_form.xsl
trunk/booking/templates/base/settings.xsl
trunk/bookingfrontend/inc/class.bosearch.inc.php
trunk/bookingfrontend/inc/class.bouser.inc.php
trunk/bookingfrontend/inc/class.menu.inc.php
trunk/bookingfrontend/inc/class.uiallocation.inc.php
trunk/bookingfrontend/inc/class.uiapplication.inc.php
trunk/bookingfrontend/inc/class.uibooking.inc.php
trunk/bookingfrontend/inc/class.uibuilding.inc.php
trunk/bookingfrontend/inc/class.uievent.inc.php
trunk/bookingfrontend/inc/class.uiorganization.inc.php
trunk/bookingfrontend/inc/class.uiresource.inc.php
trunk/bookingfrontend/inc/class.uisearch.inc.php
trunk/bookingfrontend/setup/phpgw_no.lang
trunk/bookingfrontend/setup/setup.inc.php
trunk/bookingfrontend/templates/base/config.tpl
trunk/bookingfrontend/templates/base/search.xsl
trunk/phpgwapi/templates/bkbooking/head.inc.php
trunk/phpgwapi/templates/bkbooking/head.tpl
Added Paths:
-----------
trunk/booking/inc/class.sopermission_event.inc.php
trunk/booking/inc/class.uiapplication_settings.inc.php
trunk/booking/inc/class.uievent_mail_settings.inc.php
trunk/booking/inc/class.uimail_settings.inc.php
trunk/booking/inc/class.uimetasettings.inc.php
trunk/booking/jasper/templates/logo.jpg
trunk/booking/templates/base/application_settings.xsl
trunk/booking/templates/base/event_mail_settings.xsl
trunk/booking/templates/base/mail_settings.xsl
trunk/booking/templates/base/metasettings.xsl
trunk/bookingfrontend/change.php
trunk/bookingfrontend/inc/custom/default/MinId.php
trunk/bookingfrontend/templates/fjell/
trunk/bookingfrontend/templates/stavanger/
Property Changed:
----------------
trunk/
trunk/booking/
trunk/bookingfrontend/
Property changes on: trunk
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/stavangerkommune:12743-12875
Property changes on: trunk/booking
___________________________________________________________________
Added: svn:mergeinfo
+ /branches/stavangerkommune/booking:9468-12740,12743-12875
Modified: trunk/booking/inc/class.async_task_send_reminder.inc.php
===================================================================
--- trunk/booking/inc/class.async_task_send_reminder.inc.php 2015-03-30
23:28:08 UTC (rev 12926)
+++ trunk/booking/inc/class.async_task_send_reminder.inc.php 2015-03-31
11:17:44 UTC (rev 12927)
@@ -111,14 +111,23 @@
private function create_body_text($from, $to, $where, $who,
$id, $secret, $type, $external_site_address)
{
- $body = "Informasjon om kommende arrangement:\n";
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $body = "Informasjon om kommende arrangement:\n";
$body .= "Hvor: %WHERE%\n";
$body .= "Når: %WHEN%\n";
if (strlen($who) > 0)
{
$body .= "Hvem: %WHO%\n";
}
- $body .= "\nBergen kommune fører statistikk på bruk av
lokaler og ber derfor om at dere \n";
+ if ($config->config_data['metatag_author'] != '') {
+ $body .= "\n".$config->config_data['metatag_author'];
+ } else {
+ $body .= "\nAktivby ";
+ }
+
+ $body .= " fører statistikk på bruk av lokaler og ber
derfor om at dere \n";
$body .= "\netter arrangementet melder inn korrekt
deltakertall til oss.\n";
$body .= "Du kan gjøre dette ved å klikke på linken
nedenfor.\n\n%URL%";
Modified: trunk/booking/inc/class.boallocation.inc.php
===================================================================
--- trunk/booking/inc/class.boallocation.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.boallocation.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -10,6 +10,162 @@
}
/**
+ * @ Send message about cancelation to users of building.
+ */
+ function send_notification($allocation, $maildata,
$mailadresses)
+ {
+ if
(!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+ if($maildata['outseason'] != 'on' && $maildata['recurring'] !=
'on')
+ {
+ $res_names = '';
+ foreach ($allocation['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ $info_deleted = $info_deleted."".$res_names." -
";
+ $info_deleted .= pretty_timestamp($allocation['from_'])." - ";
+ $info_deleted .= pretty_timestamp($allocation['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$allocation['building_id'].'&building_name='.urlencode($allocation['building_name']).'&from_[]=';
+ $link .=
urlencode($allocation['from_']).'&to_[]='.urlencode($allocation['to_']).'&resource='.$allocation['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+
+ $subject =
$config->config_data['allocation_canceled_mail_subject'];
+ $body = "<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$allocation['organization_name'].' har
avbestilt tid i '.$allocation['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ } else {
+ $res_names = '';
+ foreach ($allocation['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($maildata['delete'] as $valid_date) {
+ $info_deleted =
$info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($valid_date['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$allocation['building_id'].'&building_name='.urlencode($allocation['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$allocation['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+
+ $subject =
$config->config_data['allocation_canceled_mail_subject'];
+ $body = "<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$allocation['organization_name'].' har
avbestilt tid i '.$allocation['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ }
+
+
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
+
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body,
'', '', '', $from, '', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+
+ }
+
+ function send_admin_notification($allocation, $maildata,
$system_message)
+ {
+ if (!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $mailadresses = $config->config_data['emails'];
+ $mailadresses = explode("\n",$mailadresses);
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+ $subject = $system_message['title'];
+ $body = '<b>Beksjed fra '.$system_message['name'].'</b><br
/>'.$system_message['message'].'<br /><br /><b>Epost som er sendt til brukere
av Hallen:</b><br />';
+
+
+ if ($config->config_data['user_can_delete_allocations'] == 'yes') {
+ if($maildata['outseason'] != 'on' && $maildata['recurring'] !=
'on')
+ {
+ $res_names = '';
+ foreach ($allocation['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ $info_deleted = $info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($allocation['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($allocation['to_']);
+ $link =
$external_site_address.'/?menuaction=booking.uiapplication.add&building_id=';
+ $link .=
$allocation['building_id'].'&building_name='.urlencode($allocation['building_name']).'&from_[]=';
+ $link .=
urlencode($allocation['from_']).'&to_[]='.urlencode($allocation['to_']).'&resource='.$allocation['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+
+ $body .=
"<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$allocation['organization_name'].' har
avbestilt tid i '.$allocation['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ } else {
+ $res_names = '';
+ foreach ($allocation['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($maildata['delete'] as $valid_date) {
+ $info_deleted = $info_deleted."".$res_names." - ";
+ $info_deleted .=
pretty_timestamp($valid_date['from_'])." - ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/?menuaction=booking.uiapplication.add&building_id=';
+ $link .=
$allocation['building_id'].'&building_name='.urlencode($allocation['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$allocation['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply
for time').'</a><br />';
+ }
+
+ $body .=
"<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$allocation['organization_name'].' har
avbestilt tid i '.$allocation['building_name'];
+ $body .= $info_deleted.'</p>';
+ }
+ } else {
+ $body .= "<p>Det er ikke sendt noen beskjed til brukere.</p>";
+ }
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
+
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body, '', '', '',
$from, '', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+
+ }
+
+
+ /**
* @see bocommon_authorized
*/
protected function include_subject_parent_roles(array
$for_object = null)
Modified: trunk/booking/inc/class.boapplication.inc.php
===================================================================
--- trunk/booking/inc/class.boapplication.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.boapplication.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -1,15 +1,17 @@
<?php
phpgw::import_class('booking.bocommon');
-
+
class booking_boapplication extends booking_bocommon
{
function __construct()
{
parent::__construct();
+ $this->activity_bo = CreateObject('booking.boactivity');
+ $this->organization_bo = CreateObject('booking.boorganization');
$this->so = CreateObject('booking.soapplication');
}
- function send_notification($application, $created=false)
+ function send_notification($application, $created=false,
$assocciated=false)
{
if
(!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
return;
@@ -20,34 +22,82 @@
$from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
$external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+ $subject =
$config->config_data['application_mail_subject'];
- $subject = 'Melding fra Bergen kommune - AktivBy';
$link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.show&id='.$application['id'].'&secret='.$application['secret'];
if ($created) {
- $body = '<p>Din søknad om leie/lån er
mottatt.</p>';
- $body .= '<p>Praktisk informasjon finner du i
dokumenter knyttet til bygget, ref. juridiske betingelser pk.8 i søknad.</p>';
- $body .= '<p>Klikk på linken under for å se på,
redigere eller ha dialog med saksbehandler om din søknad.</p>';
- $body .= '<p><a href="'.$link.'">Link til
AktivBy: søknad #'.$application['id'].'</a></p>';
+ $body =
"<pre>".$config->config_data['application_mail_created']."</pre>";
+ $body .= '<p><a href="'.$link.'">Link til
'.$config->config_data['application_mail_systemname'].': søknad
#'.$application['id'].'</a></p>';
} elseif ($application['status'] == 'PENDING') {
- $body = '<p>Din søknad i AktivBy? om leie/lån
er '.lang($application['status']).'.<br />Saksbehandler trenger ytterligere
informasjon, ber om at du klikker på linken under og gir nødvendig
tilbakemeldinger slik at saken kan ferdigbehandles.</p>';
- $body .= '<p><a href="'.$link.'">Link til
AktivBy: søknad #'.$application['id'].'</a></p>';
+ $body = "<p>Din søknad i
".$config->config_data['application_mail_systemname']." om leie/lån er
".lang($application['status']);
+ $body .=
"</p><pre>".$config->config_data['application_mail_pending']."</pre>";
+ $body .= '<p><a href="'.$link.'">Link til
'.$config->config_data['application_mail_systemname'].': søknad
#'.$application['id'].'</a></p>';
if ($application['comment'] != '') {
$body .= '<p>Kommentar fra
saksbehandler:<br />'.$application['comment'].'</p>';
}
} elseif ($application['status'] == 'ACCEPTED') {
- $body = '<p>Din søknad i AktivBy om leie/lån er
'.lang($application['status']).'.<br /> For å skrive ut en bekreftelse eller ha
dialog med saksbehandler bruk <a href="'.$link.'">Link til AktivBy: søknad
#'.$application['id'].'</a></p>';
+ $accepted =
$this->so->get_accepted($application['id']);
+ $adates = "";
+ foreach ($accepted as $key => $date) {
+ if($key === 0)
+ $adates .= implode(" -
",$date)."\n";
+ else
+ $adates .=
"\t".implode(" - ",$date)."\n";
+ }
+ $rejected =
$this->so->get_rejected($application['id']);
+ $rdates = "";
+ foreach ($rejected as $key => $date) {
+ if($key === 0)
+ $rdates .= implode(" -
",$date)."\n";
+ else
+ $rdates .=
"\t".implode(" - ",$date)."\n";
+ }
+
+ $body = "<p>Din søknad i
".$config->config_data['application_mail_systemname']." om leie/lån er
".lang($application['status']);
+ $body .=
'</p><pre>'.$config->config_data['application_mail_accepted'].'<br /><a
href="'.$link.'">Link til
'.$config->config_data['application_mail_systemname'].': søknad
#'.$application['id'].'</a></pre>';
+ $body .= "<pre>Godkjent: ".$adates."</pre>";
+ $body .= "<pre>Avvist: ".$rdates."</pre>";
+
if ($application['comment'] != '') {
- $body .= '<p>Kommentar fra
saksbehandler:<br />'.$application['comment'].'</p>';
+ $body .= "<p>Kommentar fra
saksbehandler:<br />".$application['comment']."</p>";
}
+
+ $buildingemail =
$this->get_tilsyn_email($application['building_name']);
+ if ($buildingemail['email1'] != '' ||
$buildingemail['email2'] != '' || $buildingemail['email3'] != '') {
+ $resourcename =
implode(",",$this->get_resource_name($application['resources']));
+ $bsubject =
$config->config_data['application_mail_subject'].": En søknad om leie/lån av
".$resourcename." på ".$application['building_name']." er godkjent";
+ $bbody =
"<p>".$application['contact_name']." sin søknad om leie/lån av
".$resourcename." på ".$application['building_name']."</p>";
+ $bbody .= "<p>Den ".$adates."er
Godkjent</p>";
+ $bbody .= "<p><b>Ekstra informasjon fra søker:</b><br
/>".$application['equipment']."</p>";
+
+ foreach ($buildingemail as $bemail)
+ {
+ try
+ {
+ $send->msg('email',
$bemail, $bsubject, $bbody, '', '', '', $from, '', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if
something goes wrong
+ }
+
+ }
+ }
} elseif ($application['status'] == 'REJECTED') {
- $body = '<p>Din søknad i AktivBy om leie/lån er
'.lang($application['status']).'.<br />For ytterligere informasjon se <a
href="'.$link.'">Link til AktivBy: søknad #'.$application['id'].'</a></p>';
+ $body = "<p>Din søknad i
".$config->config_data['application_mail_systemname']." om leie/lån er
".lang($application['status']);
+ $body .=
'</p><pre>'.$config->config_data['application_mail_rejected'].' <a
href="'.$link.'">Link til
'.$config->config_data['application_mail_systemname'].': søknad
#'.$application['id'].'</a></pre>';
if ($application['comment'] != '') {
$body .= '<p>Kommentar fra
saksbehandler:<br />'.$application['comment'].'</p>';
}
- }
- $body .= '<p>Med vennlig hilsen AktivBy - Bergen
Kommune</p>';
+ } else {
+ $subject =
$config->config_data['application_comment_mail_subject'];
+ $body =
"<pre><p>".$config->config_data['application_comment_added_mail']."</p>";
+ $body .= '<p>Kommentar fra saksbehandler:<br
/>'.$application['comment'].'</p></pre>';
+ $body .= '<p><a href="'.$link.'">Link til
'.$config->config_data['application_mail_systemname'].': søknad
#'.$application['id'].'</a></p>';
+ }
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
try
{
@@ -58,8 +108,65 @@
// TODO: Inform user if something goes wrong
}
}
-
- /**
+
+ /**
+ * @ Send message about comment on application to case officer.
+ */
+ function send_admin_notification($application, $message = null)
+ {
+ if (!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config', 'booking');
+ $config->read();
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+ $subject =
$config->config_data['application_comment_mail_subject_caseofficer'];
+
+ $mailadresses = $config->config_data['emails'];
+ $mailadresses = explode("\n", $mailadresses);
+
+ if ($GLOBALS['phpgw_info']['server']['webserver_url'] != '' &&
isset($config->config_data['external_site_address']))
+ $link = $external_site_address .
$GLOBALS['phpgw_info']['server']['webserver_url'] .
'/index.php?menuaction=booking.uiapplication.show&id=' . $application['id'];
+ else
+ $link = $external_site_address .
'/index.php?menuaction=booking.uiapplication.show&id=' . $application['id'];
+
+ $activity =
$this->activity_bo->read_single($application['activity_id']);
+
+ if (strlen($application['customer_organization_number']) == 9) {
+ $orgid =
$this->organization_bo->so->get_orgid($application['customer_organization_number']);
+ $organization = $this->organization_bo->read_single($orgid);
+ $body = '<b>Kommentar fra ' . $organization['name'] . '</b><br
/>' . $message . '<br /><br/>';
+ } else {
+ $body = '<b>Kommentar fra
'.$application['contact_name'].'</b><br />'.$message.'<br /><br/>';
+ }
+
+ $body .= '<b>Bygg: </b>'.$application['building_name'].'<br />';
+ $body .= '<b>Aktivitet: </b>'.$activity['name'].'<br /><br />';
+ $body .= '<b>Kontaktperson:</b>
'.$application['contact_name'].'<br />';
+ $body .= '<b>Epost:</b> '.$application['contact_email'].'<br />';
+ $body .= '<b>Telefon:</b> '.$application['contact_phone'].'<br
/><br />';
+ $body .= '<a href="'.$link.'">Lenke til søknad</a><br /><br />';
+
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body, '', '', '',
$from, '', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+ }
+
+
+ /**
* Returns an array of application ids from applications
assocciated with buildings
* which the given user has access to
*
@@ -70,6 +177,11 @@
$applications = array();
$this->db = & $GLOBALS['phpgw']->db;
+# $sql = "select distinct ap.id
+# from bb_application ap
+# inner join bb_application_resource ar
on ar.application_id = ap.id
+# inner join bb_resource re on re.id =
ar.resource_id
+# inner join bb_building bu on bu.id =
re.building_id";
$sql = "select distinct ap.id
from bb_application ap
inner join bb_application_resource ar
on ar.application_id = ap.id
@@ -93,20 +205,19 @@
if (!isset($params['filters'])) $params['filters'] =
array();
$where_clauses = !isset($params['filters']['where']) ?
array() : (array)$params['filters']['where'];
-
+
if (!is_null($for_case_officer_id[0])) {
$where_clauses[] =
"(%%table%%.display_in_dashboard = 1 AND %%table%%.case_officer_id =
".intval($for_case_officer_id[1]).')';
} else {
$where_clauses[] = "(%%table%%.case_officer_id
= ".intval($for_case_officer_id[1]).')';
}
-
if ($building_id = phpgw::get_var('filter_building_id',
'int', 'GET', false)) {
$where_clauses[] = "(%%table%%.id IN (SELECT
DISTINCT a.id FROM bb_application a, bb_application_resource ar, bb_resource r
WHERE ar.application_id = a.id AND ar.resource_id = r.id AND r.building_id =
".intval($building_id)."))";
}
-
+
if ( $status = phpgw::get_var('status') != '') {
- $params['filters']['status'] = phpgw::get_var('status');
+ $params['filters']['status'] = phpgw::get_var('status');
}
$params['filters']['where'] = $where_clauses;
@@ -123,4 +234,4 @@
parent::__construct();
$this->so = new booking_soapplication_association();
}
- }
+ }
\ No newline at end of file
Modified: trunk/booking/inc/class.bobooking.inc.php
===================================================================
--- trunk/booking/inc/class.bobooking.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.bobooking.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -29,8 +29,251 @@
$this->event_so = CreateObject('booking.soevent');
$this->season_bo = CreateObject('booking.boseason');
}
-
+
/**
+ * @ Send message about cancelation to users of building.
+ */
+ function send_notification($booking, $allocation, $maildata,
$mailadresses, $valid_dates=null)
+ {
+ if
(!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+
+ if(($maildata['outseason'] != 'on' && $maildata['recurring'] !=
'on' && $maildata['delete_allocation'] != 'on') ||
+ ($maildata['outseason'] != 'on' && $maildata['recurring'] !=
'on' && $maildata['delete_allocation'] == 'on' &&
+ $maildata['allocation'] == 0))
+ {
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($booking['from_']).'&to_[]='.urlencode($booking['to_']).'&resource='.$booking['resources'][0];
+
+ $subject =
$config->config_data['booking_canceled_mail_subject'];
+
+ $body = "<p>".$config->config_data['booking_canceled_mail'];
+ $body .= '</p><p>'.$booking['group_name'].' har avbestilt tid
i '.$booking['building_name'].':<br />';
+ $body .= $this->so->get_resource($booking['resources'][0]).'
den '.pretty_timestamp($booking['from_']);
+ $body .=' til '.pretty_timestamp($booking['to_']);
+ $body .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a></p>';
+
+ } elseif (($maildata['outseason'] == 'on' ||
$maildata['recurring'] == 'on') && $maildata['delete_allocation'] != 'on') {
+ $res_names = '';
+ foreach ($booking['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($valid_dates as $valid_date) {
+ $info_deleted = $info_deleted."".$res_names." -
";
+ $info_deleted .= pretty_timestamp($valid_date['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']);
+ $link .=
'&from_[]='.urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+
+ $subject =
$config->config_data['booking_canceled_mail_subject'];
+
+ $body = "<p>".$config->config_data['booking_canceled_mail'];
+ $body .= '<br />'.$booking['group_name'].' har avbestilt tid i
'.$booking['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ } elseif (($maildata['outseason'] == 'on' ||
$maildata['recurring'] == 'on') && $maildata['delete_allocation'] == 'on') {
+ $res_names = '';
+ foreach ($booking['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($valid_dates as $valid_date) {
+ if (!in_array($valid_date,$maildata['delete'])) {
+ $info_deleted =
$info_deleted."".$res_names." - ";
+ $info_deleted .=
pretty_timestamp($valid_date['from_'])." - ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply
for time').'</a><br />';
+ }
+ }
+ foreach ($maildata['delete'] as $valid_date) {
+ $info_deleted =
$info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($valid_date['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+
+
+ $subject =
$config->config_data['allocation_canceled_mail_subject'];
+ $body = "<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$booking['group_name'].' har avbestilt tid i
'.$booking['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ } else {
+ $res_names = '';
+ foreach ($booking['resources'] as $res) {
+ $res_names =
$res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($maildata['delete'] as $valid_date) {
+ $info_deleted =
$info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($allocation['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($allocation['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+ $subject =
$config->config_data['allocation_canceled_mail_subject'];
+ $body = "<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$booking['group_name'].' har avbestilt tid i
'.$booking['building_name'];
+ $body .= $info_deleted.'</p>';
+ }
+
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
+
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body,
'', '', '', $from, '', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+ }
+
+ function send_admin_notification($booking, $maildata, $system_message,
$allocation, $valid_dates=null)
+ {
+ if (!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+ $subject = $system_message['title'];
+ $body = '<b>Beksjed fra '.$system_message['name'].'</b><br
/>'.$system_message['message'].'<br /><br /><b>Epost som er sendt til brukere
av Hallen:</b><br />';
+ $mailadresses = $config->config_data['emails'];
+ $mailadresses = explode("\n",$mailadresses);
+
+ if(($maildata['outseason'] != 'on' && $maildata['recurring'] !=
'on' && $maildata['delete_allocation'] != 'on') ||
+ ($maildata['outseason'] != 'on' && $maildata['recurring'] !=
'on' && $maildata['delete_allocation'] == 'on' &&
+ $maildata['allocation'] == 0))
+ {
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($booking['from_']).'&to_[]='.urlencode($booking['to_']).'&resource='.$booking['resources'][0];
+
+ $body .= "<p>".$config->config_data['booking_canceled_mail'];
+ $body .= '</p><p>'.$booking['group_name'].' har avbestilt tid
i '.$booking['building_name'].':<br />';
+ $body .= $this->so->get_resource($booking['resources'][0]).'
den '.pretty_timestamp($booking['from_']);
+ $body .=' til '.pretty_timestamp($booking['to_']);
+ $body .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a></p>';
+
+ } elseif (($maildata['outseason'] == 'on' ||
$maildata['recurring'] == 'on') && $maildata['delete_allocation'] != 'on') {
+ $res_names = '';
+ foreach ($booking['resources'] as $res) {
+ $res_names = $res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($valid_dates as $valid_date) {
+ $info_deleted = $info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($valid_date['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']);
+ $link .=
'&from_[]='.urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+
+ $body .= "<p>".$config->config_data['booking_canceled_mail'];
+ $body .= '<br />'.$booking['group_name'].' har avbestilt tid i
'.$booking['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ } elseif (($maildata['outseason'] == 'on' ||
$maildata['recurring'] == 'on') && $maildata['delete_allocation'] == 'on') {
+ $res_names = '';
+ foreach ($booking['resources'] as $res) {
+ $res_names = $res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($valid_dates as $valid_date) {
+ if (!in_array($valid_date,$maildata['delete'])) {
+ $info_deleted = $info_deleted."".$res_names." - ";
+ $info_deleted .=
pretty_timestamp($valid_date['from_'])." - ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply
for time').'</a><br />';
+ }
+ }
+ foreach ($maildata['delete'] as $valid_date) {
+ $info_deleted = $info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($valid_date['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($valid_date['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']).'&from_[]=';
+ $link .=
urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+
+
+ $body .=
"<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$booking['group_name'].' har avbestilt tid i
'.$booking['building_name'];
+ $body .= $info_deleted.'</p>';
+
+ } else {
+ $res_names = '';
+ foreach ($booking['resources'] as $res) {
+ $res_names = $res_names.$this->so->get_resource($res)." ";
+ }
+ $info_deleted = ':<p>';
+ foreach ($maildata['delete'] as $valid_date) {
+ $info_deleted = $info_deleted."".$res_names." - ";
+ $info_deleted .= pretty_timestamp($allocation['from_'])."
- ";
+ $info_deleted .= pretty_timestamp($allocation['to_']);
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+ $link .=
$booking['building_id'].'&building_name='.urlencode($booking['building_name']);
+ $link .=
'&from_[]='.urlencode($valid_date['from_']).'&to_[]='.urlencode($valid_date['to_']).'&resource='.$booking['resources'][0];
+ $info_deleted .= ' - <a href="'.$link.'">'.lang('Apply for
time').'</a><br />';
+ }
+ $body .=
"<p>".$config->config_data['allocation_canceled_mail'];
+ $body .= '<br />'.$booking['group_name'].' har avbestilt tid i
'.$booking['building_name'];
+ $body .= $info_deleted.'</p>';
+ }
+
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body, '', '', '',
$from, '', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+ }
+
+
+ /**
* @see bocommon_authorized
*/
protected function include_subject_parent_roles(array
$for_object = null)
@@ -176,11 +419,315 @@
*
* @return array containing values from $array for the keys in
$keys.
*/
- function building_schedule($building_id, $date)
+
+// todo: remove debug kode
+ function building_schedule($building_id, $date)
+ {
+// echo "debug:\n";
+ $from = clone $date;
+ $from->setTime(0, 0, 0);
+ // Make sure $from is a monday
+ if($from->format('w') != 1)
+ {
+ $from->modify('last monday');
+ }
+ $to = clone $from;
+ $to->modify('+7 days');
+ $allocation_ids =
$this->so->allocation_ids_for_building($building_id, $from, $to);
+ $allocations = $this->allocation_so->read(array('filters'=>
array('id' => $allocation_ids)));
+ $allocations = $allocations['results'];
+ foreach($allocations as &$allocation)
+ {
+ $allocation['name'] = $allocation['organization_name'];
+ $allocation['shortname'] =
$allocation['organization_shortname'];
+ $allocation['type'] = 'allocation';
+ }
+
+ $booking_ids = $this->so->booking_ids_for_building($building_id,
$from, $to);
+ $bookings = $this->so->read(array('filters'=> array('id' =>
$booking_ids)));
+ $bookings = $bookings['results'];
+ foreach($bookings as &$booking)
+ {
+ $booking['name'] = $booking['group_name'];
+ $booking['shortname'] = $booking['group_shortname'];
+ $booking['type'] = 'booking';
+ unset($booking['audience']);
+ unset($booking['agegroups']);
+ }
+
+ $allocations = $this->split_allocations($allocations, $bookings);
+
+ $event_ids = $this->so->event_ids_for_building($building_id,
$from, $to);
+ $events = $this->event_so->read(array('filters'=> array('id' =>
$event_ids)));
+ $events = $events['results'];
+ foreach($events as &$event)
+ {
+
+ $event['name'] = $event['description'];
+ $event['type'] = 'event';
+ unset($event['comments']);
+ unset($event['audience']);
+ unset($event['agegroups']);
+ unset($event['dates']);
+
+ }
+
+ $bookings = array_merge($allocations, $bookings);
+// echo "before rem\n";
+ $bookings = $this->_remove_event_conflicts($bookings, $events);
+// echo "after rem\n";
+
+ $bookings = array_merge($events, $bookings);
+
+ $resource_ids = $this->so->resource_ids_for_bookings($booking_ids);
+ $resource_ids = array_merge($resource_ids,
$this->so->resource_ids_for_allocations($allocation_ids));
+ $resource_ids = array_merge($resource_ids,
$this->so->resource_ids_for_events($event_ids));
+ $resources = $this->resource_so->read(array('filters' =>
array('id' => $resource_ids, 'active' => 1)));
+ $resources = $resources['results'];
+
+ foreach ($resources as $key => $row) {
+ $sort[$key] = $row['sort'];
+ }
+
+ // Sort the resources with sortkey ascending
+ // Add $resources as the last parameter, to sort by the common key
+ array_multisort($sort, SORT_ASC, $resources);
+ $bookings = $this->_split_multi_day_bookings($bookings, $from,
$to);
+ $results = build_schedule_table($bookings, $resources);
+// exit;
+ return array('total_records'=>count($results),
'results'=>$results);
+ }
+
+ function building_infoscreen_schedule($building_id, $date, $res
= False)
{
+ $from = clone $date;
+ $from->setTime(0, 0, 0);
+ // Make sure $from is a monday
+ if($from->format('w') != 1)
+ {
+ $from->modify('last monday');
+ }
+ $to = clone $from;
+ $to->modify('+7 days');
+ $to->modify('-1 minute');
+ if ($res != False){
+ $resources = $this->so->get_screen_resources($building_id,
$res);
+ if (count($resources) > 0)
+ $resources = "AND bb_resource.id IN (".implode(",",
$resources).")";
+ else
+ $resources = '';
+ }
+ $allocations = $this->so->get_screen_allocation($building_id,
$from, $to, $resources);
+ $bookings = $this->so->get_screen_booking($building_id, $from,
$to, $resources);
+ $events = $this->so->get_screen_event($building_id, $from, $to,
$resources);
- $from = clone $date;
+ $results = array();
+
+ foreach($allocations as &$allocation)
+ {
+ $allocation['name'] =
$allocation['organization_name'];
+ $allocation['shortname'] =
$allocation['organization_shortname'];
+ $allocation['type'] = 'allocation';
+
+ $datef = strtotime($allocation['from_']);
+ $allocation['weekday'] = date('D',$datef);
+ }
+
+ foreach($bookings as &$booking)
+ {
+ $booking['name'] = $booking['group_name'];
+ $booking['shortname'] =
$booking['group_shortname'];
+ $booking['type'] = 'booking';
+
+ $datef = strtotime($booking['from_']);
+ $booking['weekday'] = date('D',$datef);
+ }
+
+ foreach($events as &$event)
+ {
+ $event['name'] = substr($event['description'], 0, 34);
+ $event['shortname'] = substr($event['description'], 0, 12);
+ $event['type'] = 'event';
+ $datef = strtotime($event['from_']);
+ $event['weekday'] = date('D',$datef);
+ }
+
+ $allocations = $this->split_allocations2($allocations, $bookings);
+ $bookings = array_merge($allocations, $bookings);
+ $bookings = $this->_remove_event_conflicts2($bookings, $events);
+ $bookings = array_merge($bookings, $events);
+ $bookings = $this->_split_multi_day_bookings2($bookings, $from,
$to);
+
+ foreach($bookings as &$allocation)
+ {
+ $datef = strtotime($allocation['from_']);
+ $datet = strtotime($allocation['to_']);
+ $timef = date('H:i:s',$datef);
+ $timet = date('H:i:s',$datet);
+ $weekday = $allocation['weekday'];
+ $resname = $allocation['resource_name'];
+ $ft = $timef;
+ $from = explode(':',$timef);
+ $to = explode(':',$timet);
+ $from = $from[0]*60+$from[1];
+ $to = $to[0]*60+$to[1];
+ if ($to == 0)
+ $to = 24*60;
+ $colspan = ($to-$from)/30;
+
+ $allocation['colspan'] = $colspan;
+ $results[$weekday][$resname][$ft] = $allocation;
+ }
+
+ foreach ($results as &$day) {
+ foreach ($day as &$res) {
+ ksort($res);
+ }
+ }
+
+ return array('total_records'=>count($results),
'results'=>$results);
+ }
+
+ function split_allocations2($allocations, $all_bookings)
+ {
+ function get_from2($a) {return $a['from_'];};
+ function get_to2($a) {return $a['to_'];};
+ $new_allocations = array();
+ foreach($allocations as $allocation)
+ {
+ // $ Find all associated bookings
+ $bookings = array();
+
+ foreach($all_bookings as $b)
+ {
+ if($b['allocation_id'] == $allocation['id'])
+ $bookings[] = $b;
+ }
+ $times = array($allocation['from_'], $allocation['to_']);
+
+ $times = array_merge(array_map("get_from2", $bookings),
$times);
+ $times = array_merge(array_map("get_to2", $bookings), $times);
+ $times = array_unique($times);
+ sort($times);
+ while(count($times) >= 2)
+ {
+ $from_ = $times[0];
+ $to_ = $times[1];
+ $resources = array($allocation['resource_id']);
+ foreach($all_bookings as $b)
+ {
+
+ if(($b['from_'] >= $from_ && $b['from_'] < $to_) ||
($b['to_'] > $from_ && $b['to_'] <= $to_) || ($b['from_'] <= $from_ &&
$b['to_'] >= $to_))
+ $resources = array_minus($resources,
array($b['resource_id']));
+ }
+ if($resources)
+ {
+ $a = $allocation;
+ $a['from_'] = $times[0];
+ $a['to_'] = $times[1];
+ $new_allocations[] = $a;
+ }
+ array_shift($times);
+ }
+ }
+ return $new_allocations;
+ }
+
+ function _remove_event_conflicts2($bookings, &$events)
+ {
+ $new_bookings = array();
+ foreach($bookings as $b)
+ {
+ $keep = true;
+ foreach($events as &$e)
+ {
+ if((($b['from_'] >= $e['from_'] && $b['from_'] <
$e['to_']) ||
+ ($b['to_'] > $e['from_'] && $b['to_'] <=
$e['to_']) ||
+ ($b['from_'] <= $e['from_'] && $b['to_'] >=
$e['to_'])) && ( $b['resource_id'] == $e['resource_id']))
+ {
+ $keep = false;
+ break;
+ }
+ }
+ if($keep)
+ {
+ $new_bookings[] = $b;
+ }
+ }
+ return $new_bookings;
+ }
+
+ function _split_multi_day_bookings2($bookings, $t0, $t1)
+ {
+ if($t1->format('H:i') == '00:00')
+ $t1->modify('-1 day');
+ $new_bookings = array();
+ foreach($bookings as $booking)
+ {
+ $from = new DateTime($booking['from_']);
+ $to = new DateTime($booking['to_']);
+ // Basic one-day booking
+ if($from->format('Y-m-d') == $to->format('Y-m-d'))
+ {
+ $booking['date'] = $from->format('Y-m-d');
+ $booking['weekday'] =
date_format(date_create($booking['date']), 'D');
+ $booking['from_'] = $from->format('H:i');
+ $booking['to_'] = $to->format('H:i');
+ // We need to use 24:00 instead of 00:00 to sort correctly
+ $booking['to_'] = $booking['to_'] == '00:00' ? '24:00' :
$booking['to_'];
+ $new_bookings[] = $booking;
+ }
+ // Multi-day booking
+ else
+ {
+ $start = clone max($from, $t0);
+ $end = clone min($to, $t1);
+ $date = clone $start;
+ do
+ {
+ $new_booking = $booking;
+ $new_booking['date'] = $date->format('Y-m-d');
+ $new_booking['weekday'] = date_format($date, 'D');
+ $new_booking['from_'] = '00:00';
+ $new_booking['to_'] = '00:00';
+ if($new_booking['date'] == $from->format('Y-m-d'))
+ {
+ $new_booking['from_'] = $from->format('H:i');
+ }
+ else if($new_booking['date'] == $to->format('Y-m-d'))
+ {
+ $new_booking['to_'] = $to->format('H:i');
+ }
+ // We need to use 24:00 instead of 00:00 to sort
correctly
+ $new_booking['to_'] = $new_booking['to_'] == '00:00' ?
'24:00' : $new_booking['to_'];
+ $new_bookings[] = $new_booking;
+
+ if($date->format('Y-m-d') == $end->format('Y-m-d'))
+ {
+ break;
+ }
+
+ // if($date->getTimestamp() >
$end->getTimestamp()) // > php 5.3.0
+ if($date->format("U") > $end->format("U"))
+ {
+ throw new InvalidArgumentException('start time( '
. $date->format('Y-m-d') . ' ) later than end time( ' . $end->format('Y-m-d') .
" ) for {$booking['type']}#{$booking['id']}::{$booking['name']}");
+ }
+
+ $date->modify('+1 day');
+ }
+ while(true);
+ }
+ }
+ return $new_bookings;
+ }
+
+ function building_extraschedule($building_id, $date)
+ {
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $from = clone $date;
$from->setTime(0, 0, 0);
// Make sure $from is a monday
if($from->format('w') != 1)
@@ -190,7 +737,10 @@
$to = clone $from;
$to->modify('+7 days');
$allocation_ids =
$this->so->allocation_ids_for_building($building_id, $from, $to);
- $allocations =
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids)));
+
+ $orgids = explode(",", $config->config_data['extra_schedule_ids']);
+
+ $allocations =
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids,
'organization_id' => $orgids), 'sort'=>'from_'));
$allocations = $allocations['results'];
foreach($allocations as &$allocation)
{
@@ -200,7 +750,7 @@
}
$booking_ids =
$this->so->booking_ids_for_building($building_id, $from, $to);
- $bookings = $this->so->read(array('filters'=>
array('id' => $booking_ids)));
+ $bookings = $this->so->read(array('filters'=>
array('id' => $booking_ids), 'sort'=>'from_'));
$bookings = $bookings['results'];
foreach($bookings as &$booking)
{
@@ -214,7 +764,7 @@
$allocations = $this->split_allocations($allocations,
$bookings);
$event_ids =
$this->so->event_ids_for_building($building_id, $from, $to);
- $events = $this->event_so->read(array('filters'=>
array('id' => $event_ids)));
+ $events = $this->event_so->read(array('filters'=>
array('id' => $event_ids), 'sort'=>'from_'));
$events = $events['results'];
foreach($events as &$event)
{
@@ -228,7 +778,6 @@
$bookings = array_merge($allocations, $bookings);
$bookings = $this->_remove_event_conflicts($bookings,
$events);
- $bookings = array_merge($events, $bookings);
$resource_ids =
$this->so->resource_ids_for_bookings($booking_ids);
$resource_ids = array_merge($resource_ids,
$this->so->resource_ids_for_allocations($allocation_ids));
@@ -257,199 +806,324 @@
*
* @return array containg values from $array for the keys in
$keys.
*/
- function resource_schedule($resource_id, $date)
- {
- $from = clone $date;
- $from->setTime(0, 0, 0);
- // Make sure $from is a monday
- if($from->format('w') != 1)
- {
- $from->modify('last monday');
- }
- $to = clone $from;
- $to->modify('+7 days');
- $resource =
$this->resource_so->read_single($resource_id);
- $allocation_ids =
$this->so->allocation_ids_for_resource($resource_id, $from, $to);
- $allocations =
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids)));
- $allocations = $allocations['results'];
- foreach($allocations as &$allocation)
- {
- $allocation['name'] =
$allocation['organization_name'];
- $allocation['shortname'] =
$allocation['organization_shortname'];
- $allocation['type'] = 'allocation';
- }
- $booking_ids =
$this->so->booking_ids_for_resource($resource_id, $from, $to);
- $bookings = $this->so->read(array('filters'=>
array('id' => $booking_ids)));
- $bookings = $bookings['results'];
- foreach($bookings as &$booking)
- {
- $booking['name'] = $booking['group_name'];
- $booking['shortname'] =
$booking['group_shortname'];
- $booking['type'] = 'booking';
- }
- $allocations = $this->split_allocations($allocations,
$bookings);
+ function resource_schedule($resource_id, $date)
+ {
+ $from = clone $date;
+ $from->setTime(0, 0, 0);
+ // Make sure $from is a monday
+ if($from->format('w') != 1)
+ {
+ $from->modify('last monday');
+ }
+ $to = clone $from;
+ $to->modify('+7 days');
+ $resource = $this->resource_so->read_single($resource_id);
+ $allocation_ids =
$this->so->allocation_ids_for_resource($resource_id, $from, $to);
+ $allocations = $this->allocation_so->read(array('filters'=>
array('id' => $allocation_ids)));
+ $allocations = $allocations['results'];
+ foreach($allocations as &$allocation)
+ {
+ $allocation['name'] = $allocation['organization_name'];
+ $allocation['shortname'] =
$allocation['organization_shortname'];
+ $allocation['type'] = 'allocation';
+ }
+ $booking_ids = $this->so->booking_ids_for_resource($resource_id,
$from, $to);
+ $bookings = $this->so->read(array('filters'=> array('id' =>
$booking_ids)));
+ $bookings = $bookings['results'];
+ foreach($bookings as &$booking)
+ {
+ $booking['name'] = $booking['group_name'];
+ $booking['shortname'] = $booking['group_shortname'];
+ $booking['type'] = 'booking';
+ }
+ $allocations = $this->split_allocations($allocations, $bookings);
- $event_ids =
$this->so->event_ids_for_resource($resource_id, $from, $to);
- $events = $this->event_so->read(array('filters'=>
array('id' => $event_ids)));
- $events = $events['results'];
- foreach($events as &$event)
- {
- $event['name'] = $event['description'];
- $event['type'] = 'event';
- }
- $bookings = array_merge($allocations, $bookings);
- $bookings = $this->_remove_event_conflicts($bookings,
$events);
- $bookings = array_merge($events, $bookings);
-
- $bookings = $this->_split_multi_day_bookings($bookings,
$from, $to);
- $results = build_schedule_table($bookings,
array($resource));
- return array('total_records'=>count($results),
'results'=>$results);
- }
+ $event_ids = $this->so->event_ids_for_resource($resource_id,
$from, $to);
+ $events = $this->event_so->read(array('filters'=> array('id' =>
$event_ids)));
+ $events = $events['results'];
+ foreach($events as &$event)
+ {
+ $event['name'] = $event['description'];
+ $event['type'] = 'event';
+ }
+ $bookings = array_merge($allocations, $bookings);
+ $bookings = $this->_remove_event_conflicts($bookings, $events);
+ $bookings = array_merge($events, $bookings);
- /**
- * Split allocations overlapped by bookings into multiple
allocations
- * to avoid overlaps
- */
- function split_allocations($allocations, $all_bookings)
- {
- function get_from2($a) {return $a['from_'];};
- function get_to2($a) {return $a['to_'];};
- $new_allocations = array();
- foreach($allocations as $allocation)
- {
- // $ Find all associated bookings
- $bookings = array();
- foreach($all_bookings as $b)
- {
- if($b['allocation_id'] ==
$allocation['id'])
- $bookings[] = $b;
- }
- $times = array($allocation['from_'],
$allocation['to_']);
- $times = array_merge(array_map("get_from2",
$bookings), $times);
- $times = array_merge(array_map("get_to2",
$bookings), $times);
- $times = array_unique($times);
- sort($times);
- while(count($times) >= 2)
- {
- $from_ = $times[0];
- $to_ = $times[1];
- $resources = $allocation['resources'];
- $used = array();
- foreach($all_bookings as $b)
- {
-
- if(($b['from_'] >= $from_ &&
$b['from_'] < $to_) || ($b['to_'] > $from_ && $b['to_'] <= $to_) ||
($b['from_'] <= $from_ && $b['to_'] >= $to_))
- $resources =
array_minus($resources, $b['resources']);
- }
- if($resources)
- {
- $a = $allocation;
- $a['from_'] = $times[0];
- $a['to_'] = $times[1];
- $new_allocations[] = $a;
- }
- array_shift($times);
- }
- }
- return $new_allocations;
- }
+ $bookings = $this->_split_multi_day_bookings($bookings, $from,
$to);
+ $results = build_schedule_table($bookings, array($resource));
+ return array('total_records'=>count($results),
'results'=>$results);
+ }
- /**
- * Split Multi-day bookings into separate single-day bookings
- **/
- function _split_multi_day_bookings($bookings, $t0, $t1)
- {
- if($t1->format('H:i') == '00:00')
- $t1->modify('-1 day');
- $new_bookings = array();
- foreach($bookings as $booking)
- {
- $from = new DateTime($booking['from_']);
- $to = new DateTime($booking['to_']);
- // Basic one-day booking
- if($from->format('Y-m-d') ==
$to->format('Y-m-d'))
- {
- $booking['date'] =
$from->format('Y-m-d');
- $booking['wday'] =
date_format(date_create($booking['date']), 'D');
- $booking['from_'] =
$from->format('H:i');
- $booking['to_'] = $to->format('H:i');
- // We need to use 24:00 instead of
00:00 to sort correctly
- $booking['to_'] = $booking['to_'] ==
'00:00' ? '24:00' : $booking['to_'];
- $new_bookings[] = $booking;
- }
- // Multi-day booking
- else
- {
- $start = clone max($from, $t0);
- $end = clone min($to, $t1);
- $date = clone $start;
- do
- {
- $new_booking = $booking;
- $new_booking['date'] =
$date->format('Y-m-d');
- $new_booking['wday'] =
date_format($date, 'D');
- $new_booking['from_'] = '00:00';
- $new_booking['to_'] = '00:00';
- if($new_booking['date'] ==
$from->format('Y-m-d'))
- {
- $new_booking['from_'] =
$from->format('H:i');
- }
- else if($new_booking['date'] ==
$to->format('Y-m-d'))
- {
- $new_booking['to_'] =
$to->format('H:i');
- }
- // We need to use 24:00 instead
of 00:00 to sort correctly
- $new_booking['to_'] =
$new_booking['to_'] == '00:00' ? '24:00' : $new_booking['to_'];
- $new_bookings[] = $new_booking;
+ /**
+ * Split allocations overlapped by bookings into multiple allocations
+ * to avoid overlaps
+ */
+ function split_allocations($allocations, $all_bookings)
+ {
+ function get_from2($a) {return $a['from_'];};
+ function get_to2($a) {return $a['to_'];};
+ $new_allocations = array();
+ foreach($allocations as $allocation)
+ {
+ // $ Find all associated bookings
+ $bookings = array();
+ foreach($all_bookings as $b)
+ {
+ if($b['allocation_id'] == $allocation['id'])
+ $bookings[] = $b;
+ }
+ $times = array($allocation['from_'], $allocation['to_']);
+ $times = array_merge(array_map("get_from2", $bookings),
$times);
+ $times = array_merge(array_map("get_to2", $bookings), $times);
+ $times = array_unique($times);
+ sort($times);
+ while(count($times) >= 2)
+ {
+ $from_ = $times[0];
+ $to_ = $times[1];
+ $resources = $allocation['resources'];
+ $used = array();
+ foreach($all_bookings as $b)
+ {
- if($date->format('Y-m-d') ==
$end->format('Y-m-d'))
- {
- break;
- }
+ if(($b['from_'] >= $from_ && $b['from_'] < $to_) ||
($b['to_'] > $from_ && $b['to_'] <= $to_) || ($b['from_'] <= $from_ &&
$b['to_'] >= $to_))
+ $resources = array_minus($resources,
$b['resources']);
+ }
+ if($resources)
+ {
+ $a = $allocation;
+ $a['from_'] = $times[0];
+ $a['to_'] = $times[1];
+ $new_allocations[] = $a;
+ }
+ array_shift($times);
+ }
+ }
+ return $new_allocations;
+ }
- // if($date->getTimestamp() >
$end->getTimestamp()) // > php 5.3.0
- if($date->format("U") >
$end->format("U"))
- {
- throw new
InvalidArgumentException('start time( ' . $date->format('Y-m-d') . ' ) later
than end time( ' . $end->format('Y-m-d') . " ) for
{$booking['type']}#{$booking['id']}::{$booking['name']}");
- }
+ /**
+ * Split Multi-day bookings into separate single-day bookings
+ **/
+ function _split_multi_day_bookings($bookings, $t0, $t1)
+ {
+ if($t1->format('H:i') == '00:00')
+ $t1->modify('-1 day');
+ $new_bookings = array();
+ foreach($bookings as $booking)
+ {
+ $from = new DateTime($booking['from_']);
+ $to = new DateTime($booking['to_']);
+ // Basic one-day booking
+ if($from->format('Y-m-d') == $to->format('Y-m-d'))
+ {
+ $booking['date'] = $from->format('Y-m-d');
+ $booking['wday'] =
date_format(date_create($booking['date']), 'D');
+ $booking['from_'] = $from->format('H:i');
+ $booking['to_'] = $to->format('H:i');
+ // We need to use 24:00 instead of 00:00 to sort correctly
+ $booking['to_'] = $booking['to_'] == '00:00' ? '24:00' :
$booking['to_'];
+ $new_bookings[] = $booking;
+ }
+ // Multi-day booking
+ else
+ {
+ $start = clone max($from, $t0);
+ $end = clone min($to, $t1);
+ $date = clone $start;
+ do
+ {
+ $new_booking = $booking;
+ $new_booking['date'] = $date->format('Y-m-d');
+ $new_booking['wday'] = date_format($date, 'D');
+ $new_booking['from_'] = '00:00';
+ $new_booking['to_'] = '00:00';
+ if($new_booking['date'] == $from->format('Y-m-d'))
+ {
+ $new_booking['from_'] = $from->format('H:i');
+ }
+ else if($new_booking['date'] == $to->format('Y-m-d'))
+ {
+ $new_booking['to_'] = $to->format('H:i');
+ }
+ // We need to use 24:00 instead of 00:00 to sort
correctly
+ $new_booking['to_'] = $new_booking['to_'] == '00:00' ?
'24:00' : $new_booking['to_'];
+ $new_bookings[] = $new_booking;
- $date->modify('+1 day');
- }
- while(true);
- }
- }
- return $new_bookings;
- }
+ if($date->format('Y-m-d') == $end->format('Y-m-d'))
+ {
+ break;
+ }
- function _remove_event_conflicts($bookings, &$events)
- {
- foreach($events as &$e)
- {
- $e['conflicts'] = array();
- }
- $new_bookings = array();
- foreach($bookings as $b)
- {
- $keep = true;
- foreach($events as &$e)
- {
- if((($b['from_'] >= $e['from_'] &&
$b['from_'] < $e['to_']) ||
- ($b['to_'] > $e['from_'] &&
$b['to_'] <= $e['to_']) ||
- ($b['from_'] <= $e['from_'] &&
$b['to_'] >= $e['to_'])) && (array_intersect($b['resources'], $e['resources'])
!= array()))
- {
- $keep = false;
- $e['conflicts'][] = $b;
- break;
- }
- }
- if($keep)
- {
- $new_bookings[] = $b;
- }
- }
- return $new_bookings;
- }
-
+ // if($date->getTimestamp() >
$end->getTimestamp()) // > php 5.3.0
+ if($date->format("U") > $end->format("U"))
+ {
+ throw new InvalidArgumentException('start time( '
. $date->format('Y-m-d') . ' ) later than end time( ' . $end->format('Y-m-d') .
" ) for {$booking['type']}#{$booking['id']}::{$booking['name']}");
+ }
+
+ $date->modify('+1 day');
+ }
+ while(true);
+ }
+ }
+ return $new_bookings;
+ }
+
+ function _remove_event_conflicts($bookings, &$events)
+ {
+ foreach($events as &$e)
+ {
+ $e['conflicts'] = array();
+ }
+ $new_bookings = array();
+ $last = array();
+ foreach($bookings as $b)
+ {
+ if ($last) {
+ foreach ($last as $l) {
+// echo $l['id']."-".$l['from_']."-".$l['to_']."\n";
+ $new_bookings[] = $l;
+ }
+ $last = array();
+ }
+ $keep = true;
+// $i = 0;
+ foreach($events as &$e)
+ {
+
+// echo $b['id']."\tfrom: ".substr($b['from_'],11,19)." to:
".substr($b['to_'],11,19)."\n";
+// echo $e['id']."\tfrom: ".substr($e['from_'],11,19)." to:
".substr($e['to_'],11,19)." ".$e['name']."\n";
+
+ if((($b['from_'] >= $e['from_'] && $b['from_'] <
$e['to_']) ||
+ ($b['to_'] > $e['from_'] && $b['to_'] <=
$e['to_']) ||
+ ($b['from_'] <= $e['from_'] && $b['to_'] >=
$e['to_'])) && (array_intersect($b['resources'], $e['resources']) != array()))
+ {
+// echo "##$i\n";
+ $keep = false;
+ $e['conflicts'][] = $b;
+
+ $bf = $b['from_'];
+ $bt = $b['to_'];
+ $ef = $e['from_'];
+ $et = $e['to_'];
+ $tmp = $b;
+
+ if ($last) {
+ $ilast = $last;
+ $last = array();
+ foreach ($ilast as $l) {
+ $lf = $l['from_'];
+ $lt = $l['to_'];
+ $tmp = $l;
+ if ($ef <= $lf && $et >= $lt) {
+// echo "B0: break ef <= bf && et >=
bt\n\n";
+ $last[] = $l;
+ break;
+ } elseif (($ef >= $lf) && ($et > $lt)) {
+// echo "B1: (ef >= lf) && (et > lt)\n";
+ $tmp['from_'] = $lf;
+ $tmp['to_'] = $ef;
+ $last[] = $tmp;
+ } elseif (($ef <= $lf) && ($et < $lt)) {
+// echo "B2: (ef <= lf) && (et < lt)\n";
+ $tmp['from_'] = $et;
+ $tmp['to_'] = $lt;
+ $last[] = $tmp;
+ } elseif (($ef > $lf) && ($et < $lt)) {
+// echo "B3: (ef > lf) && (et < lt)\n";
+ $tmp['from_'] = $lf;
+ $tmp['to_'] = $ef;
+ $last[] = $tmp;
+ $tmp['from_'] = $et;
+ $tmp['to_'] = $lt;
+ $last[] = $tmp;
+ } else {
+// echo "B4: else break\n\n";
+ $last[] = $l;
+ break;
+ }
+ }
+ } else {
+ if ($ef <= $bf && $et >= $bt) {
+// echo "A0: break ef <= bf && et >= bt\n\n";
+ break;
+ } elseif (($ef >= $bf) && ($et > $bt)) {
+// echo "A1: (ef >= bf) && (et > bt)\n";
+ $tmp['from_'] = $bf;
+ $tmp['to_'] = $ef;
+ $last[] = $tmp;
+ } elseif (($ef <= $bf) && ($et < $bt)) {
+// echo "A2: (ef <= bf) && (et < bt)\n";
+ $tmp['from_'] = $et;
+ $tmp['to_'] = $bt;
+ $last[] = $tmp;
+ } elseif (($ef > $bf) && ($et < $bt)) {
+// echo "A3: (ef > bf) && (et < bt)\n";
+ $tmp['from_'] = $bf;
+ $tmp['to_'] = $ef;
+ $last[] = $tmp;
+ $tmp['from_'] = $et;
+ $tmp['to_'] = $bt;
+ $last[] = $tmp;
+ } else {
+// echo "A4: else break\n\n";
+ break;
+ }
+ }
+// print_r($last);
+ }
+// $i+=1;
+ }
+
+ if($last)
+ {
+ foreach ($last as $l) {
+// echo $l['id']."-".$l['from_']."-".$l['to_']."\n";
+ $new_bookings[] = $l;
+ }
+ $last = array();
+ }
+
+ if($keep)
+ {
+ $new_bookings[] = $b;
+ }
+ }
+// print_r($new_bookings);
+ return $new_bookings;
+// exit;
+ }
+
+ function _remove_event_conflicts_org($bookings, &$events)
+ {
+ foreach($events as &$e)
+ {
+ $e['conflicts'] = array();
+ }
+ $new_bookings = array();
+ foreach($bookings as $b)
+ {
+ $keep = true;
+ foreach($events as &$e)
+ {
+ if((($b['from_'] >= $e['from_'] && $b['from_'] < $e['to_'])
||
+ ($b['to_'] > $e['from_'] && $b['to_'] <= $e['to_'])
||
+ ($b['from_'] <= $e['from_'] && $b['to_'] >=
$e['to_'])) && (array_intersect($b['resources'], $e['resources']) != array()))
+ {
+ $keep = false;
+ $e['conflicts'][] = $b;
+ break;
+ }
+ }
+ if($keep)
+ {
+ $new_bookings[] = $b;
+ }
+ }
+ return $new_bookings;
+ }
+
public function complete_expired(&$bookings) {
$this->so->complete_expired($bookings);
}
Modified: trunk/booking/inc/class.bocommon.inc.php
===================================================================
--- trunk/booking/inc/class.bocommon.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.bocommon.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -71,7 +71,9 @@
}
if(!isset($_SESSION['showall'])) {
- $filters['active'] = "1";
+ if(!isset($filters['application_id'])) {
+ $filters['active'] = "1";
+ }
}
return array(
Modified: trunk/booking/inc/class.bodocument_view.inc.php
===================================================================
--- trunk/booking/inc/class.bodocument_view.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.bodocument_view.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -12,11 +12,10 @@
public function read_regulations() {
$params = $this->build_default_read_params();
!isset($params['filters']) AND $params['filters'] =
array();
-
- $params['filters']['category'] =
array(booking_sodocument::CATEGORY_REGULATION,
booking_sodocument::CATEGORY_HMS_DOCUMENT);
-
+ $params['filters']['category'] =
array(booking_sodocument::CATEGORY_REGULATION,
+ booking_sodocument::CATEGORY_HMS_DOCUMENT,
+ booking_sodocument::CATEGORY_PRICE_LIST);
$where_filter = array();
-
if ($owner_filters = phpgw::get_var('owner', 'string'))
{
foreach($owner_filters as $filter) {
list($owner_type, $owner_id) =
explode('::', $filter);
@@ -25,9 +24,7 @@
$where_filter[] =
"(%%table%%.type=$owner_type AND %%table%%.owner_id = $owner_id)";
}
}
-
$params['filters']['where'] =
array('('.join($where_filter, ' OR ').')');
-
return $this->so->read($params);
}
}
\ No newline at end of file
Modified: trunk/booking/inc/class.boevent.inc.php
===================================================================
--- trunk/booking/inc/class.boevent.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.boevent.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -1,19 +1,233 @@
<?php
- phpgw::import_class('booking.bocommon');
-
- class booking_boevent extends booking_bocommon
- {
- function __construct()
- {
- parent::__construct();
- $this->so = CreateObject('booking.soevent');
- }
-
- public function complete_expired(&$events) {
- $this->so->complete_expired($events);
- }
-
- public function find_expired() {
- return $this->so->find_expired();
- }
- }
+phpgw::import_class('booking.bocommon_authorized');
+
+class booking_boevent extends booking_bocommon_authorized
+{
+ const ROLE_ADMIN = 'organization_admin';
+
+ function __construct()
+ {
+ parent::__construct();
+ $this->so = CreateObject('booking.soevent');
+ }
+ /**
+ * @see booking_bocommon_authorized
+ */
+ protected function get_subject_roles($for_object = null,
$initial_roles=array())
+ {
+ if ($this->current_app() == 'bookingfrontend') {
+ $bouser = CreateObject('bookingfrontend.bouser');
+
+ if (is_array($for_object) &&
$for_object['customer_organization_number']) {
+ $org =
$this->so->get_org($for_object['customer_organization_number']);
+ $for_object['customer_organization_id'] = $org['id'];
+ $for_object['customer_organization_name'] = $org['name'];
+ }
+
+ $org_id = is_array($for_object) ?
$for_object['customer_organization_id'] : (!is_null($for_object) ? $for_object
: null);
+
+ if ($bouser->is_organization_admin($org_id)) {
+ $initial_roles[] = array('role' => self::ROLE_ADMIN);
+ }
+ }
+ return parent::get_subject_roles($for_object, $initial_roles);
+ }
+
+ /**
+ * @see bocommon_authorized
+ */
+ protected function get_object_role_permissions(array $forObject,
$defaultPermissions)
+ {
+ if ($this->current_app() == 'booking') {
+ $defaultPermissions[booking_sopermission::ROLE_DEFAULT] = array
+ (
+ 'read' => true,
+ 'delete' => true,
+ 'write' => true,
+ 'create' => true,
+ );
+ }
+
+ if ($this->current_app() == 'bookingfrontend') {
+ $defaultPermissions[self::ROLE_ADMIN] = array
+ (
+ 'write' =>
array_fill_keys(array('active','description','from_','to_','contact_name','contact_email',
+
'contact_phone','activity_name','audience','agegroups','is_public'), true),
+ );
+ }
+
+ return $defaultPermissions;
+ }
+
+ /**
+ * @see bocommon_authorized
+ */
+ protected function get_collection_role_permissions($defaultPermissions)
+ {
+ if ($this->current_app() == 'booking')
+ {
+ $defaultPermissions[booking_sopermission::ROLE_DEFAULT]['create']
= true;
+ $defaultPermissions[booking_sopermission::ROLE_DEFAULT]['write'] =
true;
+ }
+
+ return $defaultPermissions;
+ }
+
+ public function get_permissions(array $entity)
+ {
+ return parent::get_permissions($entity);
+ }
+
+ public function complete_expired(&$events) {
+ $this->so->complete_expired($events);
+ }
+
+ public function find_expired() {
+ return $this->so->find_expired();
+ }
+
+ /**
+ * @ Send message about cancelation/modification on event to users of
building.
+ */
+ function send_notification($type, $event, $mailadresses, $orgdate = null)
+ {
+ if (!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+// $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uiapplication.add&building_id=';
+// $link .=
$event['building_id'].'&building_name='.urlencode($event['building_name']).'&from_[]=';
+// $link .=
urlencode($event['from_']).'&to_[]='.urlencode($event['to_']).'&resource='.implode(",",$event['resources']);
+
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uibuilding.schedule&id=';
+ $link .= $event['building_id'].'&date='.substr($event['from_'], 0, 10);
+ $body = "";
+ $subject = "";
+ if (!$type) {
+ $subject .= $config->config_data['event_canceled_mail_subject'];
+ $body .= "<p>".$config->config_data['event_canceled_mail'];
+ } else {
+ $subject .= $config->config_data['event_edited_mail_subject'];
+ $body .= "<p>".$config->config_data['event_edited_mail'];
+ }
+
+ if ($_POST['org_from'] < $event['from_'] && $_POST['org_to'] ==
$event['to_']) {
+ $event['from_'] = $_POST['org_from'];
+ $event['to_'] = $event['from_'];
+ $freetime = pretty_timestamp($event['from_']).' til
'.pretty_timestamp($event['to_']);
+ }
+ elseif ($_POST['org_from'] == $event['from_'] && $_POST['org_to'] >
$event['to_']) {
+ $event['from_'] = $event['to_'];
+ $event['to_'] = $_POST['org_to'];
+ $freetime = pretty_timestamp($event['from_']).' til
'.pretty_timestamp($event['to_']);
+ }
+ elseif ($_POST['org_from'] < $event['from_'] && $_POST['org_to'] >
$event['to_']) {
+ $freetime = pretty_timestamp($_POST['org_from']).' til
'.pretty_timestamp($event['from_'])." og \n";
+ $freetime .= pretty_timestamp($event['to_']).' til
'.pretty_timestamp($_POST['org_to']);
+ } else {
+ $freetime = pretty_timestamp($event['from_']).' til
'.pretty_timestamp($event['to_'])."\n";
+ }
+
+ $body .= '</p><p>'.$event['customer_organization_name'].' har
avbestilt tid i '.$event['building_name'].':<br />';
+ $body .= implode(",
",$this->so->get_resources(implode(",",$event['resources']))).' den '.$freetime;
+ $body .= ' - <a href="'.$link.'">'.lang('Check calendar').'</a></p>';
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
+
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body, '', '', '', $from,
'', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+ }
+
+ /**
+ * @ Send message about cancelation/modification on event to admins of
building.
+ */
+ function send_admin_notification($type, $event, $message = null, $orgdate
= null)
+ {
+ if (!(isset($GLOBALS['phpgw_info']['server']['smtp_server']) &&
$GLOBALS['phpgw_info']['server']['smtp_server']))
+ return;
+ $send = CreateObject('phpgwapi.send');
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ $from = isset($config->config_data['email_sender']) &&
$config->config_data['email_sender'] ? $config->config_data['email_sender'] :
"noreply<address@hidden'phpgw_info']['server']['hostname']}>";
+
+ $external_site_address =
isset($config->config_data['external_site_address']) &&
$config->config_data['external_site_address'] ?
$config->config_data['external_site_address'] :
$GLOBALS['phpgw_info']['server']['webserver_url'];
+
+ if (!$type) {
+ $subject = $config->config_data['event_canceled_mail_subject'];
+ } else {
+ $subject = $config->config_data['event_edited_mail_subject'];
+ }
+
+ $body = '<b>Beksjed fra
'.$event['customer_organization_name'].'</b><br />'.$message.'<br /><br/>';
+ $body .= '<b>Kontaktperson:</b> '.$event['contact_name'].'<br />';
+ $body .= '<b>Epost:</b> '.$event['contact_email'].'<br />';
+ $body .= '<b>Telefon:</b> '.$event['contact_phone'].'<br /><br />';
+ $body .= '<br /><b>Epost som er sendt til brukere av Hallen:</b><br
/>';
+
+ $mailadresses = $config->config_data['emails'];
+ $mailadresses = explode("\n",$mailadresses);
+
+ $link =
$external_site_address.'/bookingfrontend/?menuaction=bookingfrontend.uibuilding.schedule&id=';
+ $link .= $event['building_id'].'&date='.substr($event['from_'], 0, 10);
+
+ if (!$type) {
+ $body .= $config->config_data['event_canceled_mail_subject'];
+ $body .= "<p>".$config->config_data['event_canceled_mail'];
+ } else {
+ $body .= $config->config_data['event_edited_mail_subject'];
+ $body .= "<p>".$config->config_data['event_edited_mail'];
+ }
+
+ if ($_POST['org_from'] < $event['from_'] && $_POST['org_to'] ==
$event['to_']) {
+ $event['from_'] = $_POST['org_from'];
+ $event['to_'] = $event['from_'];
+ $freetime = pretty_timestamp($event['from_']).' til
'.pretty_timestamp($event['to_']);
+ }
+ elseif ($_POST['org_from'] == $event['from_'] && $_POST['org_to'] >
$event['to_']) {
+ $event['from_'] = $event['to_'];
+ $event['to_'] = $_POST['org_to'];
+ $freetime = pretty_timestamp($event['from_']).' til
'.pretty_timestamp($event['to_']);
+ }
+ elseif ($_POST['org_from'] < $event['from_'] && $_POST['org_to'] >
$event['to_']) {
+ $freetime = pretty_timestamp($_POST['org_from']).' til
'.pretty_timestamp($event['from_'])." og \n";
+ $freetime .= pretty_timestamp($event['to_']).' til
'.pretty_timestamp($_POST['org_to']);
+ } else {
+ $freetime = pretty_timestamp($event['from_']).' til
'.pretty_timestamp($event['to_'])."\n";
+ }
+
+ $body .= '</p><p>'.$event['customer_organization_name'].' har
avbestilt tid i '.$event['building_name'].':<br />';
+ $body .= implode(",
",$this->so->get_resources(implode(",",$event['resources']))).' den '.$freetime;
+ $body .= ' - <a href="'.$link.'">'.lang('Check calendar').'</a></p>';
+ $body .=
"<p>".$config->config_data['application_mail_signature']."</p>";
+
+ foreach ($mailadresses as $adr)
+ {
+ try
+ {
+ $send->msg('email', $adr, $subject, $body, '', '', '', $from,
'', 'html');
+ }
+ catch (phpmailerException $e)
+ {
+ // TODO: Inform user if something goes wrong
+ }
+ }
+ }
+
+}
\ No newline at end of file
Modified: trunk/booking/inc/class.boorganization.inc.php
===================================================================
--- trunk/booking/inc/class.boorganization.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.boorganization.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -51,7 +51,7 @@
if ($this->current_app() == 'bookingfrontend') {
$defaultPermissions[self::ROLE_ADMIN] = array
(
- 'write' =>
array_fill_keys(array('name','homepage','phone','email','description','street','zip_code','district','city','active','organization_number'),
true),
+ 'write' =>
array_fill_keys(array('name','homepage','phone','email','description','street','zip_code','district','city','active','organization_number','contacts'),
true),
);
}
@@ -103,8 +103,8 @@
/**
* @see soorganization
*/
- function find_building_users($building_id)
+ function find_building_users($building_id, $split = false,
$activities = array())
{
- return $this->so->find_building_users($building_id,
$this->build_default_read_params());
+ return $this->so->find_building_users($building_id,
$this->build_default_read_params(), $split, $activities);
}
}
Modified: trunk/booking/inc/class.customer_identifier.inc.php
===================================================================
--- trunk/booking/inc/class.customer_identifier.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.customer_identifier.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -177,16 +177,16 @@
Event.addListener(select_input, 'change',
function(e) {
enableCustField(this[this.selectedIndex].value);
});
-
+
// Wouldn't work in IE6:
// Dom.batch(items, function(opt) {
- // Event.addListener(opt, 'click',
function(e) {
+ // Event.addListener(opt, 'click',
function(e) {
// enableCustField(this.value);
// })
// });
})();
JST;
-
+
if (is_array($entity)) {
$this->add_current_identifier_info($entity);
}
Modified: trunk/booking/inc/class.menu.inc.php
===================================================================
--- trunk/booking/inc/class.menu.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.menu.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -212,7 +212,13 @@
'text' => lang('Free time'),
'url' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction'=> 'booking.uireports.freetime') ),
'image' =>
array('property', 'report'),
- )
+ ),
+# 'free_time2' => array
+# (
+# 'text' => lang('Free time2'),
+# 'url' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction'=> 'booking.uireports.freetime2') ),
+# 'image' =>
array('property', 'report'),
+# )
)
),
);
@@ -265,6 +271,21 @@
'text' =>
lang('Documentation'),
'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'booking.uidocumentation.index', 'appname' => 'booking') )
),
+ 'mail_settings' => array
+ (
+ 'text' =>
lang('Mail Settings'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'booking.uimail_settings.index', 'appname' => 'booking') )
+ ),
+ 'event_mail_settings'
=> array
+ (
+ 'text' =>
lang('Event Mail Settings'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'booking.uievent_mail_settings.index', 'appname' => 'booking') )
+ ),
+ 'application_settings'
=> array
+ (
+ 'text' =>
lang('Application Settings'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'booking.uiapplication_settings.index', 'appname' => 'booking') )
+ ),
'office' => array
(
'text' =>
lang('office'),
Modified: trunk/booking/inc/class.soallocation.inc.php
===================================================================
--- trunk/booking/inc/class.soallocation.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.soallocation.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -239,7 +239,7 @@
$season_id = $allocation['season_id'];
$resources = implode(",", $allocation['resources']);
- $sql = "SELECT id FROM bb_allocation ba2 WHERE ba2.from_ = ($from)
AND ba2.to_ = ($to) AND ba2.organization_id = ($org_id) AND ba2.season_id =
($season_id) AND EXISTS ( SELECT 1 FROM bb_allocation a,bb_allocation_resource
b WHERE a.id = b.allocation_id AND b.resource_id IN ($resources))";
+ $sql = "SELECT id FROM bb_allocation ba2 JOIN
bb_allocation_resource bar2 ON (ba2.id = bar2.allocation_id) WHERE ba2.from_ =
($from) AND ba2.to_ = ($to) AND ba2.organization_id = ($org_id) AND
ba2.season_id = ($season_id) AND bar2.resource_id IN ($resources)";
$this->db->limit_query($sql, 0,__LINE__, __FILE__,1);
if(!$this->db->next_record())
@@ -271,6 +271,7 @@
$table_name = $this->table_name;
$sql = "DELETE FROM $table_name WHERE id = ($id)";
$db->query($sql, __LINE__, __FILE__);
+ return True;
}
public function update_id_string()
Modified: trunk/booking/inc/class.soapplication.inc.php
===================================================================
--- trunk/booking/inc/class.soapplication.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.soapplication.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -40,6 +40,7 @@
'column' =>
'name'
)),
'description' => array('type' =>
'string', 'query' => true, 'required' => true),
+ 'equipment' => array('type' => 'string', 'query' =>
true, 'required' => false),
'contact_name' => array('type' =>
'string', 'query' => true, 'required'=> true),
'contact_email' => array('type' =>
'string', 'required'=> true, 'sf_validator' =>
createObject('booking.sfValidatorEmail', array(), array('invalid' => '%field%
is invalid'))),
'contact_phone' => array('type' =>
'string'),
@@ -116,6 +117,74 @@
'name' => $this->db->f('name',
false));
}
+ function get_accepted($id)
+ {
+ $sql = "SELECT bad.from_, bad.to_
+ FROM bb_application ba,
bb_application_date bad, bb_event be
+ WHERE ba.id=($id)
+ AND ba.id=bad.application_id
+ AND ba.id=be.application_id
+ AND be.from_=bad.from_
+ AND be.to_=bad.to_";
+ $results = array();
+ $this->db->query($sql,__LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array('from_' =>
$this->db->f('from_', false),
+ 'to_' =>
$this->db->f('to_', false));
+ }
+ return $results;
+ }
+
+ function get_rejected($id)
+ {
+ $sql = "SELECT bad.from_, bad.to_ FROM bb_application
ba, bb_application_date bad
+ WHERE ba.id=($id)
+ AND ba.id=bad.application_id
+ AND bad.id NOT IN (SELECT bad.id
+ FROM bb_application ba,
bb_application_date bad, bb_event be
+ WHERE ba.id=($id)
+ AND ba.id=bad.application_id
+ AND ba.id=be.application_id
+ AND be.from_=bad.from_
+ AND be.to_=bad.to_)";
+ $results = array();
+ $this->db->query($sql,__LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array('from_' =>
$this->db->f('from_', false),
+ 'to_' =>
$this->db->f('to_', false));
+ }
+ return $results;
+ }
+
+ function get_tilsyn_email($id)
+ {
+ $sql = "SELECT tilsyn_email, tilsyn_email2, email FROM
bb_building where id=(select id from bb_building where name = '$id' AND active
= 1)";
+ $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return array('email1' => $this->db->f('tilsyn_email',
false),
+ 'email2' =>
$this->db->f('tilsyn_email2', false),
+ 'email3' => $this->db->f('email', false));
+
+ }
+
+ function get_resource_name($id)
+ {
+ $list = implode(",",$id);
+ $results = array();
+ $this->db->query("SELECT name FROM bb_resource where id
IN ($list)",__LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = $this->db->f('name', false);
+ }
+ return $results;
+
+ }
+
function get_building($id)
{
$this->db->limit_query("SELECT name FROM bb_building
where id=" . intval($id), 0, __LINE__, __FILE__, 1);
@@ -139,6 +208,38 @@
return $results;
}
+ function set_inactive($id,$type)
+ {
+ if ($type == 'event') {
+ $sql = "UPDATE bb_event SET active = 0 where id
= ($id)";
+ } elseif ($type == 'allocation') {
+ $sql = "UPDATE bb_allocation SET active = 0
where id = ($id)";
+ } elseif ($type == 'booking') {
+ $sql = "UPDATE bb_booking SET active = 0 where
id = ($id)";
+ } else {
+ throw new UnexpectedValueException('Encountered
an unexpected error');
+ }
+ $this->db->query($sql, __LINE__, __FILE__);
+ return;
+
+ }
+
+ function set_active($id,$type)
+ {
+ if ($type == 'event') {
+ $sql = "UPDATE bb_event SET active = 1 where id
= ($id)";
+ } elseif ($type == 'allocation') {
+ $sql = "UPDATE bb_allocation SET active = 1
where id = ($id)";
+ } elseif ($type == 'booking') {
+ $sql = "UPDATE bb_booking SET active = 1 where
id = ($id)";
+ } else {
+ throw new UnexpectedValueException('Encountered
an unexpected error');
+ }
+ $this->db->query($sql, __LINE__, __FILE__);
+ return;
+
+ }
+
function get_activities_main_level()
{
$results = array();
@@ -169,10 +270,37 @@
$sql = "UPDATE $table_name SET id_string = cast(id AS
varchar)";
$db->query($sql, __LINE__, __FILE__);
}
-
+ function check_collision($resources, $from_, $to_)
+ {
+ $rids = join(',', array_map("intval", $resources));
+ $sql = "SELECT ba.id
+ FROM bb_allocation ba, bb_allocation_resource bar
+ WHERE ba.id = bar.allocation_id
+ AND bar.resource_id in ($rids)
+ AND ((ba.from_ < '$from_' AND ba.to_ > '$from_')
+ OR (ba.from_ >= '$from_' AND ba.to_ <= '$to_')
+ OR (ba.from_ < '$to_' AND ba.to_ > '$to_'))
+ UNION
+ SELECT be.id
+ FROM bb_event be, bb_event_resource ber, bb_event_date
bed
+ WHERE be.id = ber.event_id
+ AND be.id = bed.event_id
+ AND ber.resource_id in ($rids)
+ AND ((bed.from_ < '$from_' AND bed.to_ > '$from_')
+ OR (bed.from_ >= '$from_' AND bed.to_ <= '$to_')
+ OR (bed.from_ < '$to_' AND bed.to_ > '$to_'))";
-
+ $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return True;
+
+ }
+
/**
* Check if a given timespan is available for bookings or
allocations
*
@@ -186,7 +314,7 @@
{
$rids = join(',', array_map("intval", $resources));
$nrids = count($resources);
- $this->db->query("SELECT id FROM bb_season
+ $this->db->query("SELECT id FROM bb_season
WHERE id IN (SELECT season_id
FROM
bb_season_resource
WHERE
resource_id IN ($rids,-1)
@@ -213,7 +341,8 @@
'id'
=> array('type' => 'int'),
'application_id' =>
array('type' => 'int'),
'type' => array('type' => 'string',
'required' => true),
- 'from_' => array('type' => 'timestamp'),
- 'to_' => array('type' =>
'timestamp')));
+ 'from_' => array('type' =>
'timestamp','query' => true),
+ 'to_' => array('type' => 'timestamp'),
+ 'active' => array('type' => 'int')));
}
}
Modified: trunk/booking/inc/class.sobooking.inc.php
===================================================================
--- trunk/booking/inc/class.sobooking.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.sobooking.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -255,7 +255,7 @@
$end = $end->format('Y-m-d H:i');
$building_id = intval($building_id);
$results = array();
- $this->db->query("SELECT bb_allocation.id AS id FROM
bb_allocation JOIN bb_season ON (bb_allocation.season_id=bb_season.id AND
bb_allocation.active=1) WHERE bb_season.building_id=$building_id AND
((bb_allocation.from_ >= '$start' AND bb_allocation.from_ < '$end') OR
(bb_allocation.to_ > '$start' AND bb_allocation.to_ <= '$end') OR
(bb_allocation.from_ < '$start' AND bb_allocation.to_ > '$end'))", __LINE__,
__FILE__);
+ $this->db->query("SELECT bb_allocation.id AS id FROM
bb_allocation JOIN bb_season ON (bb_allocation.season_id=bb_season.id AND
bb_allocation.active=1) WHERE bb_season.building_id=$building_id AND
bb_season.active=1 AND bb_season.status='PUBLISHED' AND ((bb_allocation.from_
>= '$start' AND bb_allocation.from_ < '$end') OR (bb_allocation.to_ > '$start'
AND bb_allocation.to_ <= '$end') OR (bb_allocation.from_ < '$start' AND
bb_allocation.to_ > '$end'))", __LINE__, __FILE__);
while ($this->db->next_record())
{
$results[] =
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -269,7 +269,7 @@
$end = $end->format('Y-m-d H:i');
$building_id = intval($building_id);
$results = array();
- $this->db->query("SELECT bb_booking.id AS id FROM
bb_booking JOIN bb_season ON (bb_booking.season_id=bb_season.id AND
bb_booking.active=1) WHERE bb_season.building_id=$building_id AND
((bb_booking.from_ >= '$start' AND bb_booking.from_ < '$end') OR
(bb_booking.to_ > '$start' AND bb_booking.to_ <= '$end') OR (bb_booking.from_ <
'$start' AND bb_booking.to_ > '$end'))", __LINE__, __FILE__);
+ $this->db->query("SELECT bb_booking.id AS id FROM
bb_booking JOIN bb_season ON (bb_booking.season_id=bb_season.id AND
bb_booking.active=1) WHERE bb_season.building_id=$building_id AND
bb_season.active=1 AND bb_season.status='PUBLISHED' AND ((bb_booking.from_ >=
'$start' AND bb_booking.from_ < '$end') OR (bb_booking.to_ > '$start' AND
bb_booking.to_ <= '$end') OR (bb_booking.from_ < '$start' AND bb_booking.to_ >
'$end'))", __LINE__, __FILE__);
while ($this->db->next_record())
{
$results[] =
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -297,7 +297,7 @@
$end = $end->format('Y-m-d H:i');
$resource_id = intval($resource_id);
$results = array();
- $this->db->query("SELECT id FROM bb_allocation JOIN
bb_allocation_resource ON (allocation_id=id AND resource_id=$resource_id) WHERE
active=1 AND ((from_ >= '$start' AND from_ < '$end') OR (to_ > '$start' AND to_
<= '$end') OR (from_ < '$start' AND to_ > '$end'))", __LINE__, __FILE__);
+ $this->db->query("SELECT bb_allocation.id AS id FROM
bb_allocation JOIN bb_allocation_resource ON (allocation_id=id AND
resource_id=$resource_id) JOIN bb_resource as res ON ( res.id=$resource_id)
JOIN bb_season ON (bb_allocation.season_id=bb_season.id AND
bb_allocation.active=1) WHERE bb_season.building_id=res.building_id AND
bb_season.active=1 AND bb_season.status='PUBLISHED' AND ((bb_allocation.from_
>= '$start'AND bb_allocation.from_ < '$end') OR (bb_allocation.to_ > '$start'
AND bb_allocation.to_ <= '$end') OR (bb_allocation.from_ < '$start' AND
bb_allocation.to_ > '$end'))", __LINE__, __FILE__);
while ($this->db->next_record())
{
$results[] =
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -311,7 +311,7 @@
$end = $end->format('Y-m-d H:i');
$resource_id = intval($resource_id);
$results = array();
- $this->db->query("SELECT id FROM bb_booking JOIN
bb_booking_resource ON (booking_id=id AND resource_id=$resource_id) WHERE
active=1 AND ((from_ >= '$start' AND from_ < '$end') OR (to_ > '$start' AND to_
<= '$end') OR (from_ < '$start' AND to_ > '$end'))", __LINE__, __FILE__);
+ $this->db->query("SELECT bb_booking.id AS id FROM
bb_booking JOIN bb_booking_resource ON (booking_id=id AND
resource_id=$resource_id) JOIN bb_resource as res ON ( res.id=$resource_id)
JOIN bb_season ON (bb_booking.season_id=bb_season.id AND bb_booking.active=1)
WHERE bb_season.building_id=res.building_id AND bb_season.active=1 AND
bb_season.status='PUBLISHED' AND ((bb_booking.from_ >= '$start' AND
bb_booking.from_ < '$end') OR (bb_booking.to_ > '$start' AND bb_booking.to_ <=
'$end') OR (bb_booking.from_ < '$start' AND bb_booking.to_ > '$end'))",
__LINE__, __FILE__);
while ($this->db->next_record())
{
$results[] =
$this->_unmarshal($this->db->f('id', false), 'int');
@@ -336,9 +336,6 @@
public function get_booking_id($booking)
{
- $table_name = $this->table_name;
- $db = $this->db;
-
$from = "'".$booking['from_']."'";
$to = "'".$booking['to_']."'";
$gid = $booking['group_id'];
@@ -357,9 +354,6 @@
public function check_allocation($id)
{
- $table_name = $this->table_name;
- $db = $this->db;
-
$sql = "SELECT allocation_id as aid FROM bb_booking WHERE
allocation_id = ( SELECT allocation_id FROM bb_booking WHERE id = ($id) ) GROUP
BY allocation_id HAVING count(id) < 2";
$this->db->limit_query($sql, 0,__LINE__, __FILE__,1);
@@ -444,6 +438,16 @@
return $this->db->f('name', false);
}
+ function get_groups_of_organization($grp_id)
+ {
+ $this->db->limit_query("select organization_id from
bb_group where id=($grp_id)", 0, __LINE__, __FILE__, 1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return $this->db->f('organization_id', false);
+ }
+
function get_resource($id)
{
$this->db->limit_query("SELECT name FROM bb_resource
where id=" . intval($id), 0, __LINE__, __FILE__, 1);
@@ -474,16 +478,32 @@
return $this->db->f('id', false);
}
- function get_group_of_organization($id)
+ public function get_group_contacts_of_organization($id)
{
$results = array();
- $this->db->query("SELECT id FROM bb_group WHERE active
= 1 and organization_id=". intval($id), __LINE__, __FILE__);
+ $sql = "SELECT
bb_group_contact.id,bb_group_contact.group_id,bb_group_contact.email FROM
bb_group,bb_group_contact WHERE bb_group.id=bb_group_contact.group_id AND
bb_group.active = 1 AND bb_group.organization_id=(".intval($id).")";
+ $this->db->query($sql, __LINE__, __FILE__);
while ($this->db->next_record())
{
- $results[] = $this->db->f('id', false);
+ $results[] = array('id' => $this->db->f('id',
false),
+ 'group_id' => $this->db->f('group_id',
false),
+ 'email' => $this->db->f('email', false));
}
return $results;
}
+ public function get_all_group_of_organization_from_groupid($id)
+ {
+ $results = array();
+ $sql = "SELECT
bb_group_contact.id,bb_group_contact.group_id,bb_group_contact.email FROM
bb_group,bb_group_contact WHERE bb_group.id=bb_group_contact.group_id AND
bb_group.active = 1 AND bb_group.organization_id=(select organization_id from
bb_group where id=(".intval($id)."))";
+ $this->db->query($sql, __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array('id' => $this->db->f('id',
false),
+ 'group_id' => $this->db->f('group_id',
false),
+ 'email' => $this->db->f('email', false));
+ }
+ return $results;
+ }
function get_organizations()
{
@@ -537,4 +557,183 @@
}
}
}
+
+
+ function get_screen_resources($building_id, $res = False){
+ $building_id = intval($building_id);
+ if (intval($res) == 1) {
+ $type = "AND ba.name IN ('Idrett','Friidrett','Svømming')";
+ } elseif (intval($res) == 2){
+ $type = "AND ba.name IN ('Barnehage','Styrkerom','Møterom')";
+ } else {
+ $type = '';
+ }
+ $results = array();
+ $sql = "SELECT br.id
+ FROM bb_resource br, bb_activity ba
+ WHERE ba.id = br.activity_id ".$type."
+ AND br.building_id = ".$building_id."
+ AND br.active = 1
+ ORDER by br.sort";
+
+ $this->db->query($sql, __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = $this->db->f('id', false);
+ }
+ return $results;
+ }
+
+ function get_screen_allocation($building_id, $start, $end, $resources
= False)
+ {
+ $start = $start->format('Y-m-d H:i');
+ $end = $end->format('Y-m-d H:i');
+ $building_id = intval($building_id);
+ $results = array();
+ $sql = "SELECT
+ bb_allocation.id AS id,
+ bb_allocation.building_name AS building_name,
+ bb_allocation.from_ AS from_,
+ bb_allocation.to_ AS to_,
+ bb_allocation.organization_id AS organization_id,
+ bb_resource.id AS resource_id,
+ bb_resource.name AS resource_name,
+ bb_resource.sort AS sort,
+ bb_resource.building_id AS building_id,
+ bb_organization.name AS organization_name,
+ bb_organization.shortname AS organization_shortname
+ FROM bb_allocation
+ INNER JOIN bb_allocation_resource ON (bb_allocation.id =
bb_allocation_resource.allocation_id)
+ INNER JOIN bb_resource ON
(bb_allocation_resource.resource_id = bb_resource.id)
+ INNER JOIN bb_organization ON (bb_organization.id =
bb_allocation.organization_id)
+ WHERE bb_allocation.from_ > '".$start."' AND
bb_allocation.to_ < '".$end."'
+ AND bb_resource.building_id = (".$building_id.")
+ ".$resources."
+ AND bb_allocation.active = 1
+ ORDER BY building_name, sort, from_;";
+ $this->db->query($sql, __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array(
+ 'id' => $this->db->f('id', false),
+ 'building_id' =>
$this->db->f('building_id', false),
+ 'resource_id' =>
$this->db->f('resource_id', false),
+ 'organization_id' =>
$this->db->f('organization_id', false),
+ 'building_name' =>
$this->db->f('building_name', false),
+ 'resource_name' =>
$this->db->f('resource_name', false),
+ 'organization_name' =>
$this->db->f('organization_name', false),
+ 'organization_shortname' =>
$this->db->f('organization_shortname', false),
+ 'from_' => $this->db->f('from_', false),
+ 'to_' => $this->db->f('to_', false),
+ );
+ }
+ return $results;
+ }
+
+ function get_screen_booking($building_id, $start, $end, $resources =
False)
+ {
+ $start = $start->format('Y-m-d H:i');
+ $end = $end->format('Y-m-d H:i');
+ $building_id = intval($building_id);
+
+ $results = array();
+ $sql = "SELECT
+ bb_booking.id AS id,
+ bb_booking.allocation_id AS allocation_id,
+ bb_booking.building_name as buidling_name,
+ bb_booking.from_ AS from_,
+ bb_booking.to_ AS to_,
+ bb_booking.group_id AS group_id,
+ bb_resource.id AS resource_id,
+ bb_resource.name AS resource_name,
+ bb_resource.sort AS sort,
+ bb_resource.building_id AS building_id,
+ bb_group.name AS group_name,
+ bb_group.shortname AS group_shortname
+ FROM bb_booking
+ INNER JOIN bb_booking_resource ON
(bb_booking_resource.booking_id = bb_booking.id)
+ INNER JOIN bb_resource ON
(bb_booking_resource.resource_id = bb_resource.id)
+ INNER JOIN bb_group ON (bb_group.id = bb_booking.group_id)
+ WHERE bb_booking.from_ > '".$start."' AND bb_booking.to_ <
'".$end."'
+ AND bb_resource.building_id = (".$building_id.")
+ ".$resources."
+ AND bb_booking.active = 1
+ ORDER BY building_name,sort, from_;";
+ $this->db->query($sql, __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array(
+ 'id' => $this->db->f('id', false),
+ 'building_id' => $this->db->f('building_id', false),
+ 'resource_id' => $this->db->f('resource_id', false),
+ 'group_id' => $this->db->f('group_id', false),
+ 'allocation_id' => $this->db->f('allocation_id', false),
+ 'building_name' => $this->db->f('building_name', false),
+ 'resource_name' => $this->db->f('resource_name', false),
+ 'group_name' => $this->db->f('group_name', false),
+ 'group_shortname' => $this->db->f('group_shortname',
false),
+ 'from_' => $this->db->f('from_', false),
+ 'to_' => $this->db->f('to_', false),
+ );
+ }
+ return $results;
+ }
+
+ function get_screen_event($building_id, $start, $end, $resources = '')
+ {
+ $start = $start->format('Y-m-d H:i:s');
+
+ $test = $end->format('H:i');
+
+ if ($test != '00:00') {
+ $end = $end->format('Y-m-d H:i:s');
+
+ } else {
+ $end = $end->format('Y-m-d').' 24:00:00';
+ }
+
+ $building_id = intval($building_id);
+ $results = array();
+ $sql = "SELECT
+ bb_event.id AS id,
+ bb_event.building_name as building_name,
+ bb_event.description as description,
+ bb_event.from_ AS from_,
+ bb_event.to_ AS to_,
+ bb_resource.sort AS sort,
+ bb_resource.id AS resource_id,
+ bb_resource.name AS resource_name,
+ bb_resource.building_id AS building_id
+ FROM bb_event
+ INNER JOIN bb_event_resource ON
(bb_event_resource.event_id = bb_event.id)
+ INNER JOIN bb_resource ON (bb_resource.id =
bb_event_resource.resource_id)
+ WHERE
+ (
+ (bb_event.from_ >= '".$start."' AND bb_event.to_ <=
'".$end."')
+ OR (bb_event.from_ < '".$start."' AND bb_event.to_ <=
'".$end."' AND bb_event.to_ > '".$start."')
+ OR (bb_event.from_ >='".$start."' AND bb_event.from_ <
'".$end."' AND bb_event.to_ > '".$end."')
+ OR (bb_event.from_ < '".$start."' AND bb_event.to_ >
'".$end."')
+ )
+ AND bb_resource.building_id = (".$building_id.")
+ ".$resources."
+ AND bb_event.active = 1
+ ORDER BY building_name,sort,from_;";
+ $this->db->query($sql, __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array(
+ 'id' => $this->db->f('id', false),
+ 'building_id' => $this->db->f('building_id', false),
+ 'resource_id' => $this->db->f('resource_id', false),
+ 'building_name' => $this->db->f('building_name', false),
+ 'resource_id' => $this->db->f('resource_id', false),
+ 'resource_name' => $this->db->f('resource_name', false),
+ 'description' => $this->db->f('description', false),
+ 'from_' => $this->db->f('from_', false),
+ 'to_' => $this->db->f('to_', false),
+ );
+ }
+ return $results;
+ }
+
}
Modified: trunk/booking/inc/class.sobuilding.inc.php
===================================================================
--- trunk/booking/inc/class.sobuilding.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.sobuilding.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -10,12 +10,20 @@
'id' => array('type' => 'int'),
'name' => array('type' => 'string',
'query' => true, 'required' => true),
'homepage' => array('type' => 'string'),
+ 'calendar_text' => array('type' =>
'string'),
'description' => array('type' =>
'string'),
'phone' => array('type' => 'string'),
'email' => array('type' => 'string'),
+ 'tilsyn_name' => array('type' =>
'string'),
+ 'tilsyn_phone' => array('type' =>
'string'),
+ 'tilsyn_email' => array('type' =>
'string'),
+ 'tilsyn_name2' => array('type' =>
'string'),
+ 'tilsyn_phone2' => array('type' =>
'string'),
+ 'tilsyn_email2' => array('type' =>
'string'),
'deactivate_calendar' => array('type'
=> 'int'),
'deactivate_application' =>
array('type' => 'int'),
'deactivate_sendmessage' =>
array('type' => 'int'),
+ 'extra_kalendar' => array('type' =>
'int'),
'location_code' =>array('type' =>
'string', 'required' => false),
'street' => array('type'
=> 'string', 'query' => true),
'zip_code' => array('type'
=> 'string'),
@@ -25,6 +33,29 @@
)
);
}
+
+ function get_endofseason($id)
+ {
+ $this->db->limit_query("SELECT to_ FROM bb_season WHERE
status = 'PUBLISHED' AND active=1 AND building_id =" . intval($id) . "ORDER BY
to_ DESC", 0, __LINE__, __FILE__, 1);
+ if(!$this->db->next_record())
+ {
+ return false;
+ }
+ return $this->db->f('to_', false);
+ }
+
+ function get_metainfo($id)
+ {
+ $this->db->limit_query("SELECT name, district, city,
description FROM bb_building where id=" . intval($id), 0, __LINE__, __FILE__,
1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return array('name' => $this->db->f('name', false),
+ 'district' =>
$this->db->f('district', false),
+ 'city' =>
$this->db->f('city', false),
+ 'description' =>
$this->db->f('description', false));
+ }
/**
* Returns buildings used by the organization with the
specified id
Modified: trunk/booking/inc/class.socommon.inc.php
===================================================================
--- trunk/booking/inc/class.socommon.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.socommon.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -404,7 +404,6 @@
$dir = isset($params['dir']) && $params['dir'] ?
$params['dir'] : 'asc';
$query = isset($params['query']) && $params['query'] ?
$params['query'] : null;
$filters = isset($params['filters']) &&
$params['filters'] ? $params['filters'] : array();
-
$cols_joins = $this->_get_cols_and_joins();
$cols = join(',', $cols_joins[0]);
$joins = join(' ', $cols_joins[1]);
Modified: trunk/booking/inc/class.socompleted_reservation_export.inc.php
===================================================================
--- trunk/booking/inc/class.socompleted_reservation_export.inc.php
2015-03-30 23:28:08 UTC (rev 12926)
+++ trunk/booking/inc/class.socompleted_reservation_export.inc.php
2015-03-31 11:17:44 UTC (rev 12927)
@@ -283,7 +283,21 @@
* @return array with three elements where index 0: total_rows,
index 1: total_cost, index 2: formatted data
*/
public function export_external(array &$reservations, array
$account_codes) {
- $export_format = 'agresso';
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+ if ($config->config_data['external_format'] == 'CSV')
+ {
+ $export_format = 'csv';
+ }
+ elseif ($config->config_data['external_format'] == 'AGRESSO')
+ {
+ $export_format = 'agresso';
+ }
+ elseif ($config->config_data['external_format'] == 'KOMMFAKT')
+ {
+ $export_format = 'kommfakt';
+ }
if (is_array($reservations)) {
if (count($external_reservations =
array_filter($reservations, array($this, 'select_external'))) > 0) {
@@ -292,12 +306,33 @@
throw new
UnexpectedValueException("Unable to find sequential number generator for
external export");
}
- return $this->build_export_result(
+ if ($config->config_data['external_format'] == 'CSV')
+ {
+ return $this->build_export_result(
+ $export_format,
+
count(array_filter($internal_reservations, array($this, 'not_free'))),
+
$this->calculate_total_cost($internal_reservations),
+
$this->format_csv($internal_reservations, $account_codes, $number_generator)
+ );
+ }
+ elseif ($config->config_data['external_format'] ==
'AGRESSO')
+ {
+ return
$this->build_export_result(
$export_format,
count(array_filter($external_reservations, array($this, 'not_free'))),
$this->calculate_total_cost($external_reservations),
$this->format_agresso($external_reservations, $account_codes, $number_generator)
- );
+ );
+ }
+ elseif ($config->config_data['external_format'] ==
'KOMMFAKT')
+ {
+ return
$this->build_export_result(
+ $export_format,
+
count(array_filter($external_reservations, array($this, 'not_free'))),
+
$this->calculate_total_cost($external_reservations),
+
$this->format_kommfakt($external_reservations, $account_codes,
$number_generator)
+ );
+ }
}
}
return $this->build_export_result($export_format, 0,
0.0);
@@ -314,10 +349,14 @@
{
$export_format = 'csv';
}
- elseif ($config->config_data['internal_format'] == 'AGGRESSO')
+ elseif ($config->config_data['internal_format'] == 'AGRESSO')
{
$export_format = 'agresso';
}
+ elseif ($config->config_data['internal_format'] == 'KOMMFAKT')
+ {
+ $export_format = 'kommfakt';
+ }
if (is_array($reservations)) {
if (count($internal_reservations =
array_filter($reservations, array($this, 'select_internal'))) > 0) {
@@ -334,7 +373,7 @@
$this->format_csv($internal_reservations, $account_codes, $number_generator)
);
}
- elseif ($config->config_data['internal_format'] ==
'AGGRESSO')
+ elseif ($config->config_data['internal_format'] ==
'AGRESSO')
{
return
$this->build_export_result(
$export_format,
@@ -343,6 +382,15 @@
$this->format_agresso($internal_reservations, $account_codes, $number_generator)
);
}
+ elseif ($config->config_data['internal_format'] ==
'KOMMFAKT')
+ {
+ return
$this->build_export_result(
+ $export_format,
+
count(array_filter($internal_reservations, array($this, 'not_free'))),
+
$this->calculate_total_cost($internal_reservations),
+
$this->format_kommfakt($internal_reservations, $account_codes,
$number_generator)
+ );
+ }
}
}
return $this->build_export_result($export_format, 0,
0.0);
@@ -397,6 +445,7 @@
$combined_data = array();
$export_format = null;
$combine_method = null;
+
foreach($export_results as &$export_result) {
if (!isset($export_result['export_format']) ||
!is_string($export_result['export_format'])) {
throw new
InvalidArgumentException('export_format must be specified');
@@ -435,7 +484,7 @@
$combined_data[] = substr($export['data'],
strpos($export['data'], "\n")+1); //Remove first line (i.e don't to repeat
headers in file)
}
}
-
+
public function format_csv(array &$reservations, array
$account_codes, $sequential_number_generator) {
$export_info = array();
$output = array();
@@ -710,7 +759,7 @@
$header['line_no'] = '0000'; //Nothing
here according to example file but spec. says so
//Topptekst til faktura, knyttet mot
fagavdeling
- $header['long_info1'] =
str_pad(substr(iconv("utf-8","ISO-8859-1",$account_codes['invoice_instruction']),
0, 120), 120, ' ');
+ $header['long_info1'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$account_codes['invoice_instruction']),
0, 120), 120, ' ');
//Ordrenr. UNIKT, løpenr. genereres i
booking ut fra gitt serie, eks. 38000000
$header['order_id'] =
str_pad($order_id, 9, 0, STR_PAD_LEFT);
@@ -741,7 +790,7 @@
/* Data hentes fra booking, tidspunkt
legges i eget felt som kommer på
* linjen under: 78_short_info. <navn
på bygg>, <navn på ressurs>
*/
- $item['art_descr'] =
str_pad(substr(iconv("utf-8","ISO-8859-1",$reservation['article_description']),
0, 35), 35, ' '); //35 chars long
+ $item['art_descr'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['article_description']),
0, 35), 35, ' '); //35 chars long
//Artikkel opprettes i Agresso (4
siffer), en for kultur og en for idrett, inneholder konteringsinfo.
$item['article'] =
str_pad(substr(strtoupper($account_codes['article']), 0, 15), 15, ' ');
@@ -797,7 +846,7 @@
$text['batch_id'] = $header['batch_id'];
$text['client'] = $header['client'];
$text['line_no'] = $item['line_no'];
- $text['short_info'] =
str_pad(substr(iconv("utf-8","ISO-8859-1",$reservation['description']), 0, 60),
60, ' ');
+ $text['short_info'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['description']),
0, 60), 60, ' ');
$text['trans_type'] =
$header['trans_type'];
$text['voucher_type'] =
$header['voucher_type'];
@@ -855,7 +904,7 @@
/* Data hentes fra booking, tidspunkt
legges i eget felt som kommer på
* linjen under: 78_short_info. <navn
på bygg>, <navn på ressurs>
*/
- $item['art_descr'] =
str_pad(substr(iconv("utf-8","ISO-8859-1",$reservation['article_description']),
0, 35), 35, ' '); //35 chars long
+ $item['art_descr'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['article_description']),
0, 35), 35, ' '); //35 chars long
//Artikkel opprettes i Agresso (4
siffer), en for kultur og en for idrett, inneholder konteringsinfo.
$item['article'] =
str_pad(substr(strtoupper($account_codes['article']), 0, 15), 15, ' ');
@@ -911,7 +960,7 @@
$text['batch_id'] =
$stored_header['batch_id'];
$text['client'] =
$stored_header['client'];
$text['line_no'] = $item['line_no'];
- $text['short_info'] =
str_pad(substr(iconv("utf-8","ISO-8859-1",$reservation['description']), 0, 60),
60, ' ');
+ $text['short_info'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['description']),
0, 60), 60, ' ');
$text['trans_type'] =
$stored_header['trans_type'];
$text['voucher_type'] =
$stored_header['voucher_type'];
@@ -933,8 +982,14 @@
if (count($export_info) == 0) {
return null;
}
+
+ if ($config->config_data['external_format_linebreak'] ==
'Windows') {
+ $file_format_linebreak = "\r\n";
+ } else {
+ $file_format_linebreak = "\n";
+ }
- return array('data' => implode("\n", $output),
'data_log' => implode("\n", $log), 'info' => $export_info, 'header_count' =>
$header_count);
+ return array('data' => implode($file_format_linebreak,
$output), 'data_log' => implode("\n", $log), 'info' => $export_info,
'header_count' => $header_count);
}
protected function get_agresso_row_template() {
@@ -944,4 +999,207 @@
$row_template = array('accept_flag' => str_repeat(' ',
1), 'account' => str_repeat(' ', 8), 'accountable' => str_repeat(' ', 20),
'address' => str_repeat(' ', 160), 'allocation_key' => str_repeat(' ', 2),
'amount' => str_repeat(' ', 17), 'amount_set' => str_repeat(' ', 1), 'apar_id'
=> str_repeat(' ', 8), 'apar_name' => str_repeat(' ', 30), 'art_descr' =>
str_repeat(' ', 35), 'article' => str_repeat(' ', 15), 'att_1_id' =>
str_repeat(' ', 2), 'att_2_id' => str_repeat(' ', 2), 'att_3_id' =>
str_repeat(' ', 2), 'att_4_id' => str_repeat(' ', 2), 'att_5_id' =>
str_repeat(' ', 2), 'att_6_id' => str_repeat(' ', 2), 'att_7_id' =>
str_repeat(' ', 2), 'bank_account' => str_repeat(' ', 35), 'batch_id' =>
str_repeat(' ', 12), 'client' => str_repeat(' ', 2), 'client_ref' =>
str_repeat(' ', 2), 'confirm_date' => str_repeat(' ', 17), 'control' =>
str_repeat(' ', 1), 'cur_amount' => str_repeat(' ', 17), 'currency' =>
str_repeat(' ', 3), 'del_met_descr' => str_repeat(' ', 60), 'del_term_descr' =>
str_repeat(' ', 60), 'deliv_addr' => str_repeat(' ', 255), 'deliv_attention' =>
str_repeat(' ', 50), 'deliv_countr' => str_repeat(' ', 3), 'deliv_date' =>
str_repeat(' ', 17), 'deliv_method' => str_repeat(' ', 8), 'deliv_terms' =>
str_repeat(' ', 8), 'dim_1' => str_repeat(' ', 8), 'dim_2' => str_repeat(' ',
8), 'dim_3' => str_repeat(' ', 8), 'dim_4' => str_repeat(' ', 8), 'dim_5' =>
str_repeat(' ', 12), 'dim_6' => str_repeat(' ', 4), 'dim_7' => str_repeat(' ',
4), 'dim_value_1' => str_repeat(' ', 12), 'dim_value_2' => str_repeat(' ', 12),
'dim_value_3' => str_repeat(' ', 12), 'dim_value_4' => str_repeat(' ', 12),
'dim_value_5' => str_repeat(' ', 12), 'dim_value_6' => str_repeat(' ', 12),
'dim_value_7' => str_repeat(' ', 12), 'disc_percent' => str_repeat(' ', 17),
'exch_rate' => str_repeat(' ', 17), 'ext_ord_ref' => str_repeat(' ', 15),
'intrule_id' => str_repeat(' ', 6), 'line_no' => str_repeat(' ', 4), 'location'
=> str_repeat(' ', 4), 'long_info1' => str_repeat(' ', 120), 'long_info2' =>
str_repeat(' ', 120), 'lot' => str_repeat(' ', 10), 'main_apar_id' =>
str_repeat(' ', 8), 'mark_attention' => str_repeat(' ', 50), 'mark_ctry_cd' =>
str_repeat(' ', 3), 'markings' => str_repeat(' ', 120), 'obs_date' =>
str_repeat(' ', 17), 'order_date' => str_repeat(' ', 17), 'order_id' =>
str_repeat(' ', 9), 'order_type' => str_repeat(' ', 2), 'pay_method' =>
str_repeat(' ', 2), 'period' => str_repeat(' ', 8), 'place' => str_repeat(' ',
30), 'province' => str_repeat(' ', 40), 'rel_value' => str_repeat(' ', 12),
'responsible' => str_repeat(' ', 8), 'responsible2' => str_repeat(' ', 8),
'sequence_no' => str_repeat(' ', 8), 'sequence_ref' => str_repeat(' ', 8),
'serial_no' => str_repeat(' ', 20), 'short_info' => str_repeat(' ', 60),
'status' => str_repeat(' ', 1), 'tax_code' => str_repeat(' ', 2), 'tax_system'
=> str_repeat(' ', 2), 'template_id' => str_repeat(' ', 8), 'terms_id' =>
str_repeat(' ', 2), 'tekx1' => str_repeat(' ', 12), 'tekst2' => str_repeat(' ',
12), 'tekst3' => str_repeat(' ', 12), 'text4' => str_repeat(' ', 12),
'trans_type' => str_repeat(' ', 2), 'unit_code' => str_repeat(' ', 3),
'unit_descr' => str_repeat(' ', 50), 'value_1' => str_repeat(' ', 17),
'voucher_ref' => str_repeat(' ', 9), 'voucher_type' => str_repeat(' ', 2),
'warehouse' => str_repeat(' ', 4), 'zip_code' => str_repeat(' ', 15));
return $row_template;
}
+
+ protected function combine_kommfakt_export_data(array
&$combined_data, $export) {
+ if (count($combined_data) == 0) {
+ $combined_data[] = $export['data'];
+ } else {
+ $combined_data[] = "\n";
+ $combined_data[] = $export['data'];
+ }
+ }
+
+ public function format_kommfakt(array &$reservations, array
$account_codes, $sequential_number_generator) {
+ $export_info = array();
+ $output = array();
+
+ $log = array();
+
+ $date = str_pad(date('Ymd'), 17, ' ', STR_PAD_LEFT);
+
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+
+
+
+ $stored_header = array();
+ $line_no = 0;
+ $header_count = 0;
+ $log_order_id = '';
+ $log_customer_name = '';
+ $log_customer_nr = '';
+ $log_buidling = '';
+
+ $internal = false;
+
+ $ant_post = 0;
+ $linjenr = 1;
+ $lopenr = 1;
+
+ foreach($reservations as &$reservation) {
+
+ if ($this->get_cost_value($reservation['cost'])
<= 0) {
+ continue; //Don't export costless rows
+ }
+
+ if(!empty($reservation['organization_id'])) {
+ $org =
$this->organization_bo->read_single($reservation['organization_id']);
+ $reservation['organization_name'] =
$org['name'];
+ } else {
+ $data =
$this->event_so->get_org($reservation['customer_organization_number']);
+ if(!empty($data['id'])) {
+
$reservation['organization_name'] = $data['name'];
+ } else {
+
if($reservation['reservation_type'] == 'event') {
+ $data =
$this->event_bo->read_single($reservation['reservation_id']);
+
$reservation['organization_name'] = $data['contact_name'];
+# } elseif
($reservation['reservation_type'] == 'booking') {
+# $data =
$this->booking_bo->read_single($reservation['reservation_id']);
+#
error_log('b'.$data['id']." ".$data['group_id']);
+# } else {
+# $data =
$this->allocation_bo->read_single($reservation['reservation_id']);
+#
error_log('a'.$data['id']." ".$data['organization_id']);
+ }
+ }
+ }
+
+ $type = $reservation['customer_type'];
+
+ $order_id =
$sequential_number_generator->increment()->get_current();
+ $export_info[] =
$this->create_export_item_info($reservation, $order_id);
+ $header_count += 1;
+ $stored_header['kundenr'] = $kundenr;
+
+ $kundenr =
str_pad(substr($this->get_customer_identifier_value_for($reservation), 0, 11),
11, '0',STR_PAD_LEFT);
+
+
+ if
(strlen($this->get_customer_identifier_value_for($reservation)) > 9) {
+ $name =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['organization_name']),
30, ' ');
+ } else {
+ $name =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['organization_name']),
30, ' ');
+ }
+
+ //Startpost ST
+ $startpost =
$this->get_kommfakt_ST_row_template();
+ $startpost['posttype'] = 'ST';
+ $startpost['referanse'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['article_description']),
0, 60), 60, ' ');
+# $startpost['referanse'] =
str_pad(substr(iconv("utf-8","ISO-8859-1//TRANSLIT",$account_codes['invoice_instruction']),
0, 60), 60, ' ');
+
+ //Fakturalinje FL
+ $fakturalinje =
$this->get_kommfakt_FL_row_template();
+ $fakturalinje['posttype'] = 'FL';
+ $fakturalinje['kundenr'] = $kundenr;
+ $fakturalinje['navn'] = $name;
+# $fakturalinje['adresse1'] = ;
+# $fakturalinje['adresse2'] = ;
+# $fakturalinje['postnr'] = ;
+ $fakturalinje['betform'] = 'BG';
+ $fakturalinje['oppdrgnr'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$account_codes['object_number']),
3, '0', STR_PAD_LEFT);
+ $fakturalinje['varenr'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$account_codes['responsible_code']),
4, '0', STR_PAD_LEFT);
+ $fakturalinje['lopenr'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$lopenr), 2, '0', STR_PAD_LEFT);
+ $fakturalinje['pris'] =
str_pad($reservation['cost']*100,8,'0',STR_PAD_LEFT).' ';
+ $fakturalinje['grunnlag'] = '000000001';
+ $fakturalinje['belop'] =
str_pad($reservation['cost']*100,8,'0',STR_PAD_LEFT).' ';
+# $fakturalinje['saksnr'] = ;
+
+ //Linjetekst LT
+ $linjetekst =
$this->get_kommfakt_LT_row_template();
+ $linjetekst['posttype'] = 'LT';
+ $linjetekst['kundenr'] = $kundenr;
+ $linjetekst['oppdrgnr'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$account_codes['object_number']),
3, '0', STR_PAD_LEFT);
+ $linjetekst['varenr'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$account_codes['responsible_code']),
4, '0', STR_PAD_LEFT) ;
+ $linjetekst['lopenr'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$lopenr), 2, '0', STR_PAD_LEFT);
+ $linjetekst['linjenr'] = $linjenr;
+ $linjetekst['tekst'] =
str_pad(iconv("utf-8","ISO-8859-1//TRANSLIT",$reservation['description']), 50,
' ');
+ $ant_post += 3;
+
+ //Sluttpost SL
+ $sluttpost =
$this->get_kommfakt_SL_row_template();
+ $sluttpost['posttype'] = 'SL';
+ $sluttpost['antpost'] =
str_pad(intval($ant_post)+1, 8, '0', STR_PAD_LEFT);
+ $ant_post = 0;
+
+
+ $log_order_id = $order_id;
+
+ if(!empty($reservation['organization_id'])) {
+ $org =
$this->organization_bo->read_single($reservation['organization_id']);
+ $log_customer_name = $org['name'];
+ } else {
+ $data =
$this->event_so->get_org($reservation['customer_organization_number']);
+ if(!empty($data['id'])) {
+ $log_customer_name =
$data['name'];
+ } else {
+
if($reservation['reservation_type'] == 'event') {
+ $data =
$this->event_bo->read_single($reservation['reservation_id']);
+ $log_customer_name =
$data['contact_name'];
+# } elseif
($reservation['reservation_type'] == 'booking') {
+# $data =
$this->booking_bo->read_single($reservation['reservation_id']);
+#
error_log('b'.$data['id']." ".$data['group_id']);
+# } else {
+# $data =
$this->allocation_bo->read_single($reservation['reservation_id']);
+#
error_log('a'.$data['id']." ".$data['organization_id']);
+ }
+ }
+ }
+
+ $log_customer_nr =
$this->get_customer_identifier_value_for($reservation);
+ $log_buidling = $reservation['building_name'];
+ $log_cost = $reservation['cost'];
+ $log_varelinjer_med_dato =
$reservation['article_description'].' - '.$reservation['description'];
+
+ $log[] = $log_order_id.';'.$log_customer_name.'
-
'.$log_customer_nr.';'.$log_varelinjer_med_dato.';'.$log_buidling.';'.$log_cost;
+
+ $output[] = implode('', str_replace(array("\n",
"\r"), '', $startpost));
+ $output[] = implode('', str_replace(array("\n",
"\r"), '', $fakturalinje));
+ $output[] = implode('', str_replace(array("\n",
"\r"), '', $linjetekst));
+ $output[] = implode('', str_replace(array("\n",
"\r"), '', $sluttpost));
+
+ }
+
+ if (count($export_info) == 0) {
+ return null;
+ }
+ if ($config->config_data['external_format_linebreak'] ==
'Windows') {
+ $file_format_linebreak = "\r\n";
+ } else {
+ $file_format_linebreak = "\n";
+ }
+
+ return array('data' => implode($file_format_linebreak,
$output), 'data_log' => implode("\n", $log), 'info' => $export_info,
'header_count' => $header_count);
+
+ }
+
+ protected function get_kommfakt_ST_row_template() {
+ static $row_template = false;
+ if ($row_template) { return $row_template; }
+
+ $row_template = array('posttype' => str_repeat(' ', 2),
'referanse' => str_repeat(' ', 60));
+ return $row_template;
+ }
+
+ protected function get_kommfakt_FL_row_template() {
+ static $row_template = false;
+ if ($row_template) { return $row_template; }
+
+ $row_template = array('posttype' => str_repeat(' ', 2),
'kundenr' => str_repeat(' ', 11), 'navn' => str_repeat(' ', 30), 'adresse1' =>
str_repeat(' ', 30), 'adresse2' => str_repeat(' ', 30), 'postnr' =>
str_repeat(' ', 4), 'betform' => str_repeat(' ', 2), 'oppdrgnr' => str_repeat('
', 3), 'varenr' => str_repeat(' ', 4), 'lopenr' => str_repeat(' ', 2), 'pris'
=> str_repeat(' ', 9), 'grunnlag' => str_repeat(' ', 9), 'belop' =>
str_repeat(' ', 11), 'saksnr' => str_repeat(' ', 16));
+ return $row_template;
+
+ }
+
+ protected function get_kommfakt_LT_row_template() {
+ static $row_template = false;
+ if ($row_template) { return $row_template; }
+
+ $row_template = array('posttype' => str_repeat(' ', 2),
'kundenr' => str_repeat(' ', 11), 'oppdrgnr' => str_repeat(' ', 3), 'varenr' =>
str_repeat(' ', 4), 'lopenr' => str_repeat(' ', 2), 'linjenr' => str_repeat('
', 2), 'tekst' => str_repeat(' ', 50));
+ return $row_template;
+ }
+
+ protected function get_kommfakt_SL_row_template() {
+ static $row_template = false;
+ if ($row_template) { return $row_template; }
+
+ $row_template = array('posttype' => str_repeat(' ', 2),
'antpost' => str_repeat(' ', 8));
+ return $row_template;
+ }
}
Modified: trunk/booking/inc/class.socompleted_reservation_export_file.inc.php
===================================================================
--- trunk/booking/inc/class.socompleted_reservation_export_file.inc.php
2015-03-30 23:28:08 UTC (rev 12926)
+++ trunk/booking/inc/class.socompleted_reservation_export_file.inc.php
2015-03-31 11:17:44 UTC (rev 12927)
@@ -43,12 +43,27 @@
{
return 'csv';
}
- elseif ($config->config_data['internal_format'] == 'AGGRESSO')
+ elseif ($config->config_data['internal_format'] == 'AGRESSO')
{
return 'txt';
}
+ elseif ($config->config_data['internal_format'] == 'KOMMFAKT')
+ {
+ return 'txt';
+ }
} elseif ($export_type === 'external'){
- return 'txt';
+ if ($config->config_data['external_format'] == 'CSV')
+ {
+ return 'csv';
+ }
+ elseif ($config->config_data['external_format'] == 'AGRESSO')
+ {
+ return 'txt';
+ }
+ elseif ($config->config_data['external_format'] == 'KOMMFAKT')
+ {
+ return 'txt';
+ }
} else {
return 'txt';
}
@@ -110,7 +125,7 @@
$entity_export_files = array();
$export_files = array();
$export_conf_updates = array();
-
+
try {
$this->db->transaction_begin();
@@ -133,6 +148,7 @@
if ($export_type == 'external') {
$export_result['total_items'] = $export_result['export']['header_count'];
+
if
(!is_null($export_result['export']['data_log'])) {
$export_log .=
$export_result['export']['data_log'];
} else {
@@ -156,7 +172,7 @@
}
foreach($export_types as $export_type) {
- $entity_export_file = array();
+ $entity_export_file = array();
$entity_export_file['type'] =
$export_type;
$entity_export_file['total_cost'] =
$total_cost[$export_type];
$entity_export_file['total_items'] =
$total_items[$export_type];
@@ -167,7 +183,7 @@
$entity_export_file['filename'] =
'export_'.$export_type.'_'.$entity_export_file['id'].'.'.$this->file_type_for_export_type($export_type);
$export_file = new
booking_storage_object($entity_export_file['filename']);
$export_files[] = $export_file;
-
+
$export_file->set_data($export_data[$export_type]);
$this->file_storage->attach($export_file)->persist();
Modified: trunk/booking/inc/class.soevent.inc.php
===================================================================
--- trunk/booking/inc/class.soevent.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.soevent.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -13,7 +13,8 @@
'activity_id' => array('type' =>
'int', 'required' => true),
'application_id' => array('type'
=> 'int', 'required' => false),
'description' => array('type' =>
'string', 'required'=> true, 'query' => true),
- 'building_name' => array('type' =>
'string', 'required'=> true, 'query' => true),
+ 'building_id' => array('type' => 'int', 'required' =>
true),
+ 'building_name' => array('type' => 'string',
'required'=> true, 'query' => true),
'from_' => array('type' =>
'string', 'required'=> true),
'to_' => array('type' =>
'string', 'required'=> true),
'cost' => array('type' =>
'decimal', 'required' => true),
@@ -76,16 +77,32 @@
function get_building_info($id)
{
- $this->db->limit_query("SELECT bb_building.id,
bb_building.name, bb_building.email FROM bb_building, bb_resource,
bb_event_resource WHERE bb_building.id=bb_resource.building_id AND
bb_resource.id=bb_event_resource.resource_id AND bb_event_resource.event_id=" .
intval($id), 0, __LINE__, __FILE__, 1);
+ $this->db->limit_query("SELECT bb_building.id,
bb_building.name, bb_building.email, bb_building.tilsyn_email,
bb_building.tilsyn_email2 FROM bb_building, bb_resource, bb_event_resource
WHERE bb_building.id=bb_resource.building_id AND
bb_resource.id=bb_event_resource.resource_id AND bb_event_resource.event_id=" .
intval($id), 0, __LINE__, __FILE__, 1);
if(!$this->db->next_record())
{
return False;
}
return array('id' => $this->db->f('id', false),
'name' => $this->db->f('name',
false),
- 'email' =>
$this->db->f('email', false));
+ 'email' =>
$this->db->f('email', false),
+ 'tilsyn_email' =>
$this->db->f('tilsyn_email', false),
+ 'tilsyn_email2' =>
$this->db->f('tilsyn_email2', false));
}
+ function get_ordered_comments($id)
+ {
+ $results = array();
+ $this->db->query("select time,author,comment,type from
bb_event_comment where event_id=($id) order by time desc", __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array('time' =>
$this->db->f('time', false),
+ 'author' => $this->db->f('author', false),
+ 'comment' => $this->db->f('comment', false),
+ 'type' =>
$this->db->f('type', false));
+ }
+ return $results;
+ }
+
function get_resource_info($id)
{
$this->db->limit_query("SELECT bb_resource.id,
bb_resource.name FROM bb_resource WHERE bb_resource.id=" . intval($id), 0,
__LINE__, __FILE__, 1);
@@ -120,23 +137,24 @@
function get_contact_mail($id,$type)
{
+ $mail = array();
if ($type == 'allocation')
{
- $this->db->limit_query("SELECT
bb_organization_contact.email FROM bb_organization_contact WHERE
organization_id IN (SELECT bb_allocation.organization_id FROM bb_allocation
WHERE id=$id)", 0, __LINE__, __FILE__, 1);
+ $sql = "SELECT bb_organization_contact.email FROM
bb_organization_contact WHERE organization_id IN (SELECT
bb_allocation.organization_id FROM bb_allocation WHERE id=$id)";
}
else
{
- $this->db->limit_query("SELECT bb_group_contact.email
FROM bb_group_contact WHERE group_id IN (SELECT bb_booking.group_id FROM
bb_booking WHERE id=$id)", 0, __LINE__, __FILE__, 1);
- }
- if(!$result = $this->db->resultSet)
- {
- return False;
+ $sql = "SELECT bb_group_contact.email FROM
bb_group_contact WHERE group_id IN (SELECT bb_booking.group_id FROM bb_booking
WHERE id=$id)";
}
- $mail = array();
- foreach ($result as $res)
- {
- array_push($mail,$res['email']);
- }
+ $this->db->query($sql, __LINE__, __FILE__);
+ if($result = $this->db->resultSet)
+ {
+ foreach ($result as $res)
+ {
+ $mail[] = $res['email'];
+ }
+ }
+
return $mail;
}
@@ -250,6 +268,30 @@
$db->query($sql, __LINE__, __FILE__);
}
+ public function delete_event($id)
+ {
+ $db = $this->db;
+ $table_name = $this->table_name.'_comment';
+ $sql = "DELETE FROM $table_name WHERE event_id = ($id)";
+ $db->query($sql, __LINE__, __FILE__);
+ $table_name = $this->table_name.'_agegroup';
+ $sql = "DELETE FROM $table_name WHERE event_id = ($id)";
+ $db->query($sql, __LINE__, __FILE__);
+ $table_name = $this->table_name.'_targetaudience';
+ $sql = "DELETE FROM $table_name WHERE event_id = ($id)";
+ $db->query($sql, __LINE__, __FILE__);
+ $table_name = $this->table_name.'_date';
+ $sql = "DELETE FROM $table_name WHERE event_id = ($id)";
+ $db->query($sql, __LINE__, __FILE__);
+ $table_name = $this->table_name.'_resource';
+ $sql = "DELETE FROM $table_name WHERE event_id = ($id)";
+ $db->query($sql, __LINE__, __FILE__);
+ $table_name = $this->table_name;
+ $sql = "DELETE FROM $table_name WHERE id = ($id)";
+ $db->query($sql, __LINE__, __FILE__);
+ return True;
+ }
+
public function update_id_string() {
$table_name = $this->table_name;
$db = $this->db;
@@ -319,5 +361,16 @@
return $results;
}
+ function get_resources($ids)
+ {
+ $results = array();
+ $this->db->query("select name from bb_resource where id in
($ids)", __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = $this->db->f('name', false);
+ }
+ return $results;
+ }
+
}
Modified: trunk/booking/inc/class.sogroup.inc.php
===================================================================
--- trunk/booking/inc/class.sogroup.inc.php 2015-03-30 23:28:08 UTC (rev
12926)
+++ trunk/booking/inc/class.sogroup.inc.php 2015-03-31 11:17:44 UTC (rev
12927)
@@ -46,6 +46,21 @@
$this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
}
+ function get_metainfo($id)
+ {
+ $this->db->limit_query("SELECT bg.name, bg.shortname,
bo.name as organization, bo.district, bo.city, bg.description FROM bb_group as
bg, bb_organization as bo where bg.organization_id=bo.id and bg.id=" .
intval($id), 0, __LINE__, __FILE__, 1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return array('name' => $this->db->f('name', false),
+ 'shortname' =>
$this->db->f('shortname', false),
+ 'organization' =>
$this->db->f('organization', false),
+ 'district' =>
$this->db->f('district', false),
+ 'city' => $this->db->f('city',
false),
+ 'description' =>
$this->db->f('description', false));
+ }
+
/**
* Removes any extra contacts from entity if such exists (only
two contacts allowed per group).
*/
Modified: trunk/booking/inc/class.soorganization.inc.php
===================================================================
--- trunk/booking/inc/class.soorganization.inc.php 2015-03-30 23:28:08 UTC
(rev 12926)
+++ trunk/booking/inc/class.soorganization.inc.php 2015-03-31 11:17:44 UTC
(rev 12927)
@@ -49,9 +49,31 @@
),
)
);
- $this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
+ $this->account =
$GLOBALS['phpgw_info']['user']['account_id'];
}
+ function get_metainfo($id)
+ {
+ $this->db->limit_query("SELECT name, shortname,
district, city, description FROM bb_organization where id=" . intval($id), 0,
__LINE__, __FILE__, 1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return array('name' => $this->db->f('name', false),
+ 'shortname' =>
$this->db->f('shortname', false),
+ 'district' =>
$this->db->f('district', false),
+ 'city' =>
$this->db->f('city', false),
+ 'description' =>
$this->db->f('description', false));
+ }
+ function get_orgid($orgnr)
+ {
+ $this->db->limit_query("SELECT id FROM bb_organization where
organization_number ='" . $orgnr."'", 0, __LINE__, __FILE__, 1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return $this->db->f('id', false);
+ }
function get_groups($organization_id)
{
static $groups = null;
@@ -61,27 +83,95 @@
$results = $groups->read(array("filters" =>
array("organization_id" => $organization_id)));
return $results;
}
-
- /**
- * Returns the organizations who've used the building with the
specified id
- * within the last 300 days.
- *
- * @param int $building_id
- * @param array $params Parameters to pass to socommon->read
- *
- * @return array (in socommon->read format)
- */
- function find_building_users($building_id, $params = array()) {
+
+ function get_resource_activity($resources)
+ {
+// print_r($resources);
+ $resource_ids = implode(',',$resources);
+ $results = array();
+ $sql = "SELECT activity_id FROM bb_resource where id in
(".$resource_ids.")";
+ $this->db->query($sql, __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = $this->db->f('activity_id', false);
+ }
+ return $results;
+
+ }
+
+ /**
+ Returns the organizations who've used the building with the
specified id
+ within the last 300 days.
+
+ @param int $building_id
+ @param array $params Parameters to pass to socommon->read
+ @param bool $split Parameter
+ @param array $activities Parameters
+
+ @return array (in socommon->read format)
+ **/
+ function find_building_users($building_id, $params = array(),
$split = false, $activities = array()) {
+ $config = CreateObject('phpgwapi.config','booking');
+ $config->read();
+ $test = '';
+
+ $pools = $config->config_data['split_pool_ids'];
+ $halls = $config->config_data['split_pool2_ids'];
+ $meeting = $config->config_data['split_pool3_ids'];
+ $excluded = $config->config_data['split_pool4_ids'];
+
+ if ($split) {
+ if (count($activities) > 1) {
+ if (array_intersect($activities, explode(',', $pools)) &&
array_intersect($activities, explode(',', $halls))) {
+ $test = " AND r.activity_id not in (".$excluded.") ";
+ } elseif (array_intersect($activities, explode(',',
$pools))) {
+ $test = " AND r.activity_id not in (" . $pools . "," .
$excluded . ") ";
+ } elseif (array_intersect($activities, explode(',',
$halls))) {
+ $test = " AND r.activity_id not in (" . $halls . "," .
$excluded . ") ";
+ } elseif (array_intersect($activities, explode(',',
$excluded))) {
+ $test = " AND r.activity_id not in (" . $halls . "," .
$pools . "," . $meeting . "," . $excluded . ") ";
+ } else {
+ $test = " AND r.activity_id not in (".$excluded.") ";
+ }
+ } else {
+ $activity = $activities[0];
+ if (in_array($activity, explode(',', $pools))) {
+ $test = " AND r.activity_id not in (" . $halls . ",".
$meeting . "," . $excluded . ") ";
+ } elseif (in_array($activity, explode(',', $halls))) {
+ $test = " AND r.activity_id not in (" . $pools . "," .
$excluded . ") ";
+ } elseif (in_array($activity, explode(',', $excluded))) {
+ $test = " AND r.activity_id not in (" . $halls . "," .
$pools . "," . $meeting . "," . $excluded . ") ";
+ } else {
+ $test = " AND r.activity_id not in (".$excluded.") ";
+ }
+ }
+ }
if (!isset($params['filters'])) { $params['filters'] =
array(); }
if (!isset($params['filters']['where'])) {
$params['filters']['where'] = array(); }
-
- $params['filters']['where'][] = '%%table%%.id IN ('.
- 'SELECT o.id FROM bb_resource r '.
- 'JOIN bb_allocation_resource ar ON
ar.resource_id = r.id AND r.building_id = '.$this->_marshal($building_id,
'int').' '.
- 'JOIN bb_allocation a ON a.id =
ar.allocation_id AND (a.from_ - \'now\'::timestamp < \'300 days\')'.
- 'JOIN bb_organization o ON o.id =
a.organization_id '.
- ')';
-
+ if ($config->config_data['mail_users_season'] == 'yes')
+ {
+ $params['filters']['where'][] = '%%table%%.id IN ('.
+ 'SELECT DISTINCT o.id FROM bb_resource r '.
+ 'JOIN bb_allocation_resource ar ON ar.resource_id = r.id
AND r.building_id = '.$this->_marshal($building_id, 'int').' '.
+ 'JOIN bb_allocation a ON a.id = ar.allocation_id '.
+ 'JOIN bb_organization o ON o.id = a.organization_id '.
@@ Diff output truncated at 153600 characters. @@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [12927] Merge from stavanger branch,
Sigurd Nes <=