fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11504] bkbooking: stavanger bugfix calendar and even


From: Kjell Arne Espedal
Subject: [Fmsystem-commits] [11504] bkbooking: stavanger bugfix calendar and event set inactive/active
Date: Thu, 05 Dec 2013 10:28:07 +0000

Revision: 11504
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11504
Author:   kjell
Date:     2013-12-05 10:28:06 +0000 (Thu, 05 Dec 2013)
Log Message:
-----------
bkbooking: stavanger bugfix calendar and event set inactive/active

Modified Paths:
--------------
    branches/stavangerkommune/booking/inc/class.bobooking.inc.php
    branches/stavangerkommune/booking/inc/class.uievent.inc.php

Modified: branches/stavangerkommune/booking/inc/class.bobooking.inc.php
===================================================================
--- branches/stavangerkommune/booking/inc/class.bobooking.inc.php       
2013-12-01 19:23:01 UTC (rev 11503)
+++ branches/stavangerkommune/booking/inc/class.bobooking.inc.php       
2013-12-05 10:28:06 UTC (rev 11504)
@@ -299,20 +299,83 @@
                 *
                 * @return array containing values from $array for the keys in 
$keys.
                 */
-               function building_schedule($building_id, $date)
+
+        function building_schedule($building_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');
+            $to->setTime(23,59,59);
+            $allocation_ids = 
$this->so->allocation_ids_for_building($building_id, $from, $to);
+            $allocations = $this->allocation_so->read(array('filters'=> 
array('id' => $allocation_ids), 'sort'=>'from_'));
+            $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), 'sort'=>'from_'));
+            $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_building($building_id, 
$from, $to);
+            $events = $this->event_so->read(array('filters'=> array('id' => 
$event_ids), 'sort'=>'from_'));
+            $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);
+
+            $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);
+            return array('total_records'=>count($results), 
'results'=>$results);
+        }
+
+               function building_infoscreen_schedule($building_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');
-                       }
+//                     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 = 
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids), 
'sort'=>'from_'));
                        $allocations = $allocations['results'];
                        foreach($allocations as &$allocation)
                        {
@@ -321,7 +384,7 @@
                                $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 = $this->so->read(array('filters'=> 
array('id' => $booking_ids), 'sort'=>'from_'));
                        $bookings = $bookings['results'];
                        foreach($bookings as &$booking)
                        {
@@ -332,7 +395,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)
                        {
@@ -356,7 +419,7 @@
                        // 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);
+                       $results = build_schedule_screen_table($bookings, 
$resources);
                        return array('total_records'=>count($results), 
'results'=>$results);
                }
 
@@ -378,7 +441,7 @@
             
             $orgids = explode(",", $config->config_data['extra_schedule_ids']);
             
-                       $allocations = 
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids, 
'organization_id' => $orgids)));
+                       $allocations = 
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids, 
'organization_id' => $orgids), 'sort'=>'from_'));
                        $allocations = $allocations['results'];
                        foreach($allocations as &$allocation)
                        {
@@ -387,7 +450,7 @@
                                $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 = $this->so->read(array('filters'=> 
array('id' => $booking_ids), 'sort'=>'from_'));
                        $bookings = $bookings['results'];
                        foreach($bookings as &$booking)
                        {
@@ -398,7 +461,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)
                        {
@@ -447,7 +510,7 @@
                        $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 = 
$this->allocation_so->read(array('filters'=> array('id' => $allocation_ids), 
'sort'=>'from_'));
                        $allocations = $allocations['results'];
                        foreach($allocations as &$allocation)
                        {
@@ -456,7 +519,7 @@
                                $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 = $this->so->read(array('filters'=> 
array('id' => $booking_ids), 'sort'=>'from_'));
                        $bookings = $bookings['results'];
                        foreach($bookings as &$booking)
                        {
@@ -469,7 +532,7 @@
                        $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 = $this->event_so->read(array('filters'=> 
array('id' => $event_ids), 'sort'=>'from_'));
                        $events = $events['results'];
                        foreach($events as &$event)
                        {
@@ -599,14 +662,16 @@
                        {
                                $e['conflicts'] = array();
                        }
-                       $new_bookings = array();
+
+            $new_bookings = array();
                        foreach($bookings as $b)
                        {
-                
+                file_put_contents("/tmp/test.log", "\n", FILE_APPEND);
                                $keep = true;
                                foreach($events as &$e)
                                {
-                                       if((($b['from_'] >= $e['from_'] && 
$b['from_'] < $e['to_']) || 
+
+                                       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()))
                                        {
@@ -615,28 +680,54 @@
                                                $e['conflicts'][] = $b;
 
                         $bf = $b['from_'];
-                        $bt = $b['to_'];            
+                        $bt = $b['to_'];
+                        $ef = $e['from_'];
+                        $et = $e['to_'];
 
-                        if ($bf < $e['from_'])
+                        if ($ef >= $bf && $et <= $bt) {
+                            break;
+                        }
+                        elseif (($ef >= $bf) && ($et > $bt))
                         {
-                            $b['to_'] = $e['from_'];                       
-                            $b['from_'] = $bf;                       
-                            $new_bookings[] = $b;        
+                            $nbrem = false;
+                            foreach ($new_bookings as $key => &$nb)
+                            {
+                                $bid = $b['id'];
+                                if ($nb['id'] == $bid && $nb['from_'] == $ef) {
+                                    unset($new_bookings[$key]);
+                                    $nbrem = true;
+                                }
+                            }
+                            if (!$nbrem) {
+                                $b['from_'] = $bf;
+                                $b['to_'] = $ef;
+                                $new_bookings[] = $b;
+                            }
                         }
-
-                        if ($e['to_'] < $bt)
+                        elseif (($ef <= $bf) && ($et < $bt))
                         {
-                            $b['from_'] = $e['to_'];                       
-                            $b['to_'] = $bt;                       
-                            $new_bookings[] = $b;        
+                            $b['from_'] = $et;
+                            $b['to_'] = $bt;
+                            $new_bookings[] = $b;
                         }
-
-                                               break;
+                        elseif (($ef > $bf) && ($et < $bt))
+                        {
+                            $b['from_'] = $bf;
+                            $b['to_'] = $ef;
+                            $new_bookings[] = $b;
+                            $b['from_'] = $et;
+                            $b['to_'] = $bt;
+                            $new_bookings[] = $b;
+                        }
+                        else
+                        {
+                            break;
+                        }
                                        }
                                }
                                if($keep)
                                {
-                                       $new_bookings[] = $b;
+                   $new_bookings[] = $b;
                                }
                        }
                        return $new_bookings;

Modified: branches/stavangerkommune/booking/inc/class.uievent.inc.php
===================================================================
--- branches/stavangerkommune/booking/inc/class.uievent.inc.php 2013-12-01 
19:23:01 UTC (rev 11503)
+++ branches/stavangerkommune/booking/inc/class.uievent.inc.php 2013-12-05 
10:28:06 UTC (rev 11504)
@@ -306,7 +306,7 @@
                public function add()
                {
                        $errors = array();
-                       $event = array('customer_internal' => 0); 
+                       $event = array('customer_internal' => 0);
                        if($_SERVER['REQUEST_METHOD'] == 'POST')
                        {
 
@@ -566,13 +566,12 @@
                                if ($_POST['cost'] != 0 and 
!$event['customer_organization_number'] and !$event['customer_ssn']) {
                                        $errors['invoice_data'] = lang('There 
is set a cost, but no invoice data is filled inn');
                                } 
-
                                if(!$errors['event'] and 
!$errors['resource_number'] and !$errors['organization_number'] and 
!$errors['invoice_data']  && !$errors['contact_name'] && !$errors['cost'])
-                               { 
-
+                               {
                                        if (( phpgw::get_var('sendtorbuilding', 
'POST') || phpgw::get_var('sendtocontact', 'POST') || 
phpgw::get_var('sendtocollision', 'POST')) && phpgw::get_var('active', 'POST'))
                                        {
-                                               
if(phpgw::get_var('sendtocollision', 'POST') || phpgw::get_var('sendtocontact', 
'POST') || phpgw::get_var('sendtorbuilding', 'POST'))
+
+                        if(phpgw::get_var('sendtocollision', 'POST') || 
phpgw::get_var('sendtocontact', 'POST') || phpgw::get_var('sendtorbuilding', 
'POST'))
                                                {
                                                        $maildata = 
$this->create_sendt_mail_notification_comment_text($event,$errors);
                             
@@ -689,64 +688,67 @@
                                                                        
$this->add_comment($event,$comment);                    
                                                                }
                                                        }
-                                               } 
-                                       } elseif (!phpgw::get_var('active', 
'POST')) {
-
-                        $subject = 
$config->config_data['event_canceled_mail_subject'];
-                        $body = 
$config->config_data['event_canceled_mail']."\n".phpgw::get_var('mail', 'POST');
-                                               
-                                               if 
($event['customer_organization_name']) {
-                                                       $comment_text_log = 
$event['customer_organization_name'];
-                                               } else {
-                                                       $comment_text_log = 
$event['contact_name'];
                                                }
-                                               $comment_text_log = 
$comment_text_log.' sitt arrangement i '.$event['building_name'].' 
'.date('d-m-Y H:i', strtotime($event['from_']))." har blitt kansellert.";
+                    }
+                                       $receipt = $this->bo->update($event);
+                                       $this->redirect(array('menuaction' => 
'booking.uievent.edit', 'id'=>$event['id']));
+                               }
+                if (!phpgw::get_var('active', 'POST')) {
 
-                                               $body .= "<br 
/>\n".$comment_text_log;
-                                               $body = 
html_entity_decode($body);                      
+                    $subject = 
$config->config_data['event_canceled_mail_subject'];
+                    $body = 
$config->config_data['event_canceled_mail']."\n".phpgw::get_var('mail', 'POST');
 
-                        
-                                               $sendt = 0;
-                                               $mail_sendt_to = '';
-                                               if($building_info['email']) {
-                                               $sendt++;
-                                                       $mail_sendt_to = 
$mail_sendt_to.' '.$building_info['email'];
-                                                       
$this->send_mailnotification($building_info['email'], $subject, $body);
-                                               } 
-                                               if 
($building_info['tilsyn_email']) {
-                                                       $sendt++;
-                                                       $mail_sendt_to = 
$mail_sendt_to.' '.$building_info['tilsyn_email'];
-                                                       
$this->send_mailnotification($building_info['tilsyn_email'], $subject, $body);
+                    if ($event['customer_organization_name']) {
+                        $comment_text_log = 
$event['customer_organization_name'];
+                    } else {
+                        $comment_text_log = $event['contact_name'];
+                    }
+                    $comment_text_log = $comment_text_log.' sitt arrangement i 
'.$event['building_name'].' '.date('d-m-Y H:i', strtotime($event['from_']))." 
har blitt kansellert.";
 
-                                               } 
-                                               if 
($building_info['tilsyn_email2']) {
-                                                       $sendt++;
-                                                       $mail_sendt_to = 
$mail_sendt_to.' '.$building_info['tilsyn_email2'];
-                                                       
$this->send_mailnotification($building_info['tilsyn_email2'], $subject, $body);
-                                               }
-                                               if 
($_POST['sendtorbuilding_email1']) {
-                                                       $sendt++;
-                                                       $mail_sendt_to = 
$mail_sendt_to.' '.$_POST['sendtorbuilding_email1'];
-                                                       
$this->send_mailnotification($_POST['sendtorbuilding_email1'], $subject, $body);
-       
-                                               } 
-                                               if 
($_POST['sendtorbuilding_email2']) {
-                                                       $sendt++;
-                                                       $mail_sendt_to = 
$mail_sendt_to.' '.$_POST['sendtorbuilding_email2'];
-                                                       
$this->send_mailnotification($_POST['sendtorbuilding_email2'], $subject, $body);
-                                               }
-                                               if ($sendt <= 0) {
-                                                       
$errors['mailtobuilding'] = lang('Unable to send warning, No mailadresses 
found');
-                                               } 
-                                               else 
-                                               {
-                                                       $comment = '<span 
style="color:red;">Dette arrangemenet er kanselert</span>. Denne er sendt til 
'.$mail_sendt_to.'<br />'.phpgw::get_var('mail', 'POST');
-                                                       
$this->add_comment($event,$comment);                    
-                                               }
-                                       }
-                                       $receipt = $this->bo->update($event);
-                                       $this->redirect(array('menuaction' => 
'booking.uievent.edit', 'id'=>$event['id']));
-                               }
+                    $body .= "<br />\n".$comment_text_log;
+                    $body = html_entity_decode($body);
+
+                    $sendt = 0;
+                    $mail_sendt_to = '';
+                    if($building_info['email']) {
+                        $sendt++;
+                        $mail_sendt_to = $mail_sendt_to.' 
'.$building_info['email'];
+                        $this->send_mailnotification($building_info['email'], 
$subject, $body);
+                    }
+                    if ($building_info['tilsyn_email']) {
+                        $sendt++;
+                        $mail_sendt_to = $mail_sendt_to.' 
'.$building_info['tilsyn_email'];
+                        
$this->send_mailnotification($building_info['tilsyn_email'], $subject, $body);
+
+                    }
+                    if ($building_info['tilsyn_email2']) {
+                        $sendt++;
+                        $mail_sendt_to = $mail_sendt_to.' 
'.$building_info['tilsyn_email2'];
+                        
$this->send_mailnotification($building_info['tilsyn_email2'], $subject, $body);
+                    }
+                    if ($_POST['sendtorbuilding_email1']) {
+                        $sendt++;
+                        $mail_sendt_to = $mail_sendt_to.' 
'.$_POST['sendtorbuilding_email1'];
+                        
$this->send_mailnotification($_POST['sendtorbuilding_email1'], $subject, $body);
+
+                    }
+                    if ($_POST['sendtorbuilding_email2']) {
+                        $sendt++;
+                        $mail_sendt_to = $mail_sendt_to.' 
'.$_POST['sendtorbuilding_email2'];
+                        
$this->send_mailnotification($_POST['sendtorbuilding_email2'], $subject, $body);
+                    }
+                    if ($sendt <= 0) {
+                        $errors['mailtobuilding'] = lang('Unable to send 
warning, No mailadresses found');
+                    }
+                    else
+                    {
+                        $comment = '<span style="color:red;">Dette 
arrangemenet er kanselert</span>. Denne er sendt til '.$mail_sendt_to.'<br 
/>'.phpgw::get_var('mail', 'POST');
+                        $this->add_comment($event,$comment);
+                    }
+                    $receipt = $this->bo->update($event);
+                    $this->redirect(array('menuaction' => 
'booking.uievent.edit', 'id'=>$event['id']));
+
+                }
                        }
 
                        if($errors['allocation'])




reply via email to

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