fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [6521] bkbooking: rewrite of new allocation


From: Kjell Arne Espedal
Subject: [Fmsystem-commits] [6521] bkbooking: rewrite of new allocation
Date: Thu, 28 Oct 2010 08:03:51 +0000

Revision: 6521
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6521
Author:   kjell
Date:     2010-10-28 08:03:51 +0000 (Thu, 28 Oct 2010)
Log Message:
-----------
bkbooking: rewrite of new allocation

Modified Paths:
--------------
    trunk/booking/inc/class.uiallocation.inc.php
    trunk/booking/setup/phpgw_no.lang
    trunk/booking/templates/base/allocation_new.xsl

Added Paths:
-----------
    trunk/booking/templates/base/allocation_new_preview.xsl

Modified: trunk/booking/inc/class.uiallocation.inc.php
===================================================================
--- trunk/booking/inc/class.uiallocation.inc.php        2010-10-28 07:23:48 UTC 
(rev 6520)
+++ trunk/booking/inc/class.uiallocation.inc.php        2010-10-28 08:03:51 UTC 
(rev 6521)
@@ -19,6 +19,7 @@
                        $this->bo = CreateObject('booking.boallocation');
                        $this->organization_bo    = 
CreateObject('booking.boorganization');
                        $this->building_bo    = 
CreateObject('booking.bobuilding');
+                       $this->season_bo    = CreateObject('booking.boseason');
                        
self::set_active_menu('booking::applications::allocations');
                        $this->fields = array('resources', 'cost', 
'application_id',
                                                                  
'building_id', 'building_name', 
@@ -119,15 +120,43 @@
                public function add()
                {
                        $errors = array();
+                       $step = phpgw::get_var('step', 'str', 'POST');
+                       if (! isset($step)) $step = 1;
+                       $invalid_dates = array();
+                       $valid_dates = array();
+
                        if($_SERVER['REQUEST_METHOD'] == 'POST')
                        {
+                               $season = 
$this->season_bo->read_single($_POST['season_id']);
                                array_set_default($_POST, 'resources', array());
                                $allocation = extract_values($_POST, 
$this->fields);
                                $allocation['active'] = '1';
                                $allocation['completed'] = '0';
+
+                               $from_date = $_POST['from_'];
+                               $to_date = $_POST['to_'];
+                               $weekday = $_POST['weekday'];
+
+                               $allocation['from_'] = strftime("%Y-%m-%d 
%H:%M", strtotime($_POST['weekday']." ".$_POST['from_']));
+                               $allocation['to_'] = strftime("%Y-%m-%d %H:%M", 
strtotime($_POST['weekday']." ".$_POST['to_']));
+
+                               if (($_POST['weekday'] != 'sunday' &&  
date('w')  > date('w',strtotime($_POST['weekday']))) || (date('w') == 'sunday' 
&&  date('w') < date('w',strtotime($_POST['weekday'])))){
+                                       $allocation['from_'] = 
strftime("%Y-%m-%d %H:%M", strtotime($_POST['weekday']." 
".$_POST['from_'])-60*60*24*7);
+                                       $allocation['to_'] = strftime("%Y-%m-%d 
%H:%M", strtotime($_POST['weekday']." ".$_POST['to_'])-60*60*24*7);
+                               } 
+
+                               $_POST['from_'] = $allocation['from_'];
+                               $_POST['to_'] = $allocation['to_'];
+
                                $errors = $this->bo->validate($allocation);
-                               if(!$errors)
+
+                               if (!$errors)
                                {
+                                       $step++;
+                               }
+
+                               if (!$errors && $_POST['outseason'] != 'on' )
+                               {
                                        try {
                                                $receipt = 
$this->bo->add($allocation);
                                                
$this->redirect(array('menuaction' => 'booking.uiallocation.show', 
'id'=>$receipt['id']));
@@ -135,14 +164,86 @@
                                                $errors['global'] = lang('Could 
not add object due to insufficient permissions');
                                        }
                                }
+                               else if ($_POST['outseason'] == 'on' && 
!$errors && $step > 1)
+                               {
+
+                                       $repeat_until = 
strtotime($season['to_'])+60*60*24; 
+                                       $_POST['repeat_until'] = $season['to_'];
+
+                                       $max_dato = strtotime($_POST['to_']); 
// highest date from input
+                                       $interval = 
$_POST['field_interval']*60*60*24*7; // weeks in seconds
+                                       $i = 0;
+                                       // calculating valid and invalid dates 
from the first booking's to-date to the repeat_until date is reached
+                                       // the form from step 1 should validate 
and if we encounter any errors they are caused by double bookings.
+                                       while (($max_dato+($interval*$i)) <= 
$repeat_until)
+                                       {
+                                               $fromdate = date('Y-m-d H:i', 
strtotime($_POST['from_']) + ($interval*$i));
+                                               $todate = date('Y-m-d H:i', 
strtotime($_POST['to_']) + ($interval*$i));
+                                               $allocation['from_'] = 
$fromdate;
+                                               $allocation['to_'] = $todate;
+                                               $err = 
$this->bo->validate($allocation);
+                                               if ($err) 
+                                               {
+                                                       
$invalid_dates[$i]['from_'] = $fromdate;
+                                                       
$invalid_dates[$i]['to_'] = $todate;
+                                               } 
+                                               else 
+                                               {
+                                                       
$valid_dates[$i]['from_'] = $fromdate;
+                                                       $valid_dates[$i]['to_'] 
= $todate;
+                                                       if ($step == 3)
+                                                       {
+                                                               try {
+                                                                       
$receipt = $this->bo->add($allocation);
+                                                               } catch 
(booking_unauthorized_exception $e) {
+                                                                       
$errors['global'] = lang('Could not add object due to insufficient 
permissions');
+                                                               }
+                                                       }
+                                               }
+                                               $i++;
+                                       }
+                                       if ($step == 3) 
+                                       {
+                                               
$this->redirect(array('menuaction' => 'booking.uiallocation.show', 
'id'=>$receipt['id']));
+                                       }
+                               }
                        }
+
                        $this->flash_form_errors($errors);
                        self::add_javascript('booking', 'booking', 
'allocation.js');
                        array_set_default($allocation, 'resources', array());
                        $allocation['resources_json'] = 
json_encode(array_map('intval', $allocation['resources']));
                        $allocation['cancel_link'] = 
self::link(array('menuaction' => 'booking.uiallocation.index'));
                        array_set_default($allocation, 'cost', '0');
-                       self::render_template('allocation_new', 
array('allocation' => $allocation));
+
+                       if ($step < 2) 
+                       {
+                               if($_SERVER['REQUEST_METHOD'] == 'POST' && 
$errors) {                           
+                                       $allocation['from_'] = 
strftime("%H:%M", strtotime($_POST['weekday']." ".$_POST['from_']));
+                                       $allocation['to_'] = strftime("%H:%M", 
strtotime($_POST['weekday']." ".$_POST['to_']));
+                               }
+                               self::render_template('allocation_new', 
array('allocation' => $allocation,
+                                       'step' => $step, 
+                                       'interval' => $_POST['field_interval'],
+                                       'repeat_until' => 
$_POST['repeat_until'],
+                                       'outseason' => $_POST['outseason'],
+                               ));
+                       } 
+                       else if ($step == 2) 
+                       {
+                               self::render_template('allocation_new_preview', 
array('allocation' => $allocation,
+                                       'step' => $step,
+                                       'recurring' => $_POST['recurring'],
+                                       'outseason' => $_POST['outseason'],
+                                       'interval' => $_POST['field_interval'],
+                                       'repeat_until' => 
$_POST['repeat_until'],
+                                       'weekday' => $weekday,
+                                       'from_date' => $from_date,
+                                       'to_date' => $to_date,
+                                       'valid_dates' => $valid_dates,
+                                       'invalid_dates' => $invalid_dates
+                               ));
+                       }
                }
 
                private function 
send_mailnotification_to_organization($organization, $subject, $body)

Modified: trunk/booking/setup/phpgw_no.lang
===================================================================
--- trunk/booking/setup/phpgw_no.lang   2010-10-28 07:23:48 UTC (rev 6520)
+++ trunk/booking/setup/phpgw_no.lang   2010-10-28 08:03:51 UTC (rev 6521)
@@ -466,3 +466,8 @@
 Lengt of shortname is to long, max 11 characters long  booking no      
Kortnavn er for langt, maks 11 tegn
 The organization number is wrong or not present        booking no      Det er 
ikke registrert et organisjonsnummer på denne organisasjonen
 The resource number is wrong or not present    booking no      Det er ikke 
registert et ressursnummer på denne organisasjonen
+Recurring allocation   booking no      Gjenta tildelingen
+weekday        booking no      Ukedag
+Out season     booking no      Ut sesong
+Allocations colliding with existing allocations or bookings (%1)       booking 
no      Tildelinger ikke kan lages
+Allocations that can be created        booking no      Tildelinger som kan 
lages

Modified: trunk/booking/templates/base/allocation_new.xsl
===================================================================
--- trunk/booking/templates/base/allocation_new.xsl     2010-10-28 07:23:48 UTC 
(rev 6520)
+++ trunk/booking/templates/base/allocation_new.xsl     2010-10-28 08:03:51 UTC 
(rev 6521)
@@ -9,7 +9,9 @@
 
     <form action="" method="POST">
                <input type="hidden" name="application_id" 
value="{allocation/application_id}"/>
+
         <dl class="form-col">
+
             <dt><label for="field_building"><xsl:value-of 
select="php:function('lang', 'Building')" /></label></dt>
             <dd>
                 <div class="autocomplete">
@@ -22,16 +24,7 @@
                     <div id="building_container"/>
                 </div>
             </dd>
-            <dt><label for="field_season"><xsl:value-of 
select="php:function('lang', 'Season')" /></label></dt>
-            <dd>
-                <div id="season_container"><xsl:value-of 
select="php:function('lang', 'Select a building first')" /></div>
-            </dd>
-            <dt><label for="field_resources"><xsl:value-of 
select="php:function('lang', 'Resources')" /></label></dt>
-            <dd>
-                <div id="resources_container"><xsl:value-of 
select="php:function('lang', 'Select a building first')" /></div>
-            </dd>
-        </dl>
-        <dl class="form-col">
+
             <dt><label for="field_org"><xsl:value-of 
select="php:function('lang', 'Organization')" /></label></dt>
             <dd>
                 <div class="autocomplete">
@@ -44,28 +37,138 @@
                     <div id="org_container"/>
                 </div>
             </dd>
+
+                       <dt><label for="field_weekday"><xsl:value-of 
select="php:function('lang', 'Weekday')" /></label></dt>
+                       <dd>
+                               <select name="weekday" id="field_weekday">
+                                       <option value="monday">
+                                               <xsl:if 
test="../allocation/weekday = 'monday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Monday')" />        
+                                       </option>
+                                       <option value="tuesday">
+                                               <xsl:if 
test="../allocation/weekday = 'tuesday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Tuesday')" />
+                                       </option>
+                                       <option value="wednesday">
+                                               <xsl:if 
test="../allocation/weekday = 'wednesday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Wednesday')" />
+                                       </option>
+                                       <option value="thursday">
+                                               <xsl:if 
test="../allocation/weekday = 'thursday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Thursday')" />
+                                       </option>
+                                       <option value="friday">
+                                               <xsl:if 
test="../allocation/weekday = 'friday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Friday')" />
+                                       </option>
+                                       <option value="saturday">
+                                               <xsl:if 
test="../allocation/weekday = 'saturday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Saturday')" />
+                                       </option>
+                                       <option value="sunday">
+                                               <xsl:if 
test="../allocation/weekday = 'sunday'">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', 'Sunday')" />
+                                       </option>
+
+                               </select>
+                       </dd>
+
             <dt><label for="field_from"><xsl:value-of 
select="php:function('lang', 'From')" /></label></dt>
             <dd>
-                <div class="datetime-picker">
+                <div class="time-picker">
                 <input id="field_from" name="from_" type="text">
                     <xsl:attribute name="value"><xsl:value-of 
select="allocation/from_"/></xsl:attribute>
                 </input>
                 </div>
             </dd>
+
             <dt><label for="field_to"><xsl:value-of 
select="php:function('lang', 'To')" /></label></dt>
             <dd>
-                <div class="datetime-picker">
+                <div class="time-picker">
                 <input id="field_to" name="to_" type="text">
                     <xsl:attribute name="value"><xsl:value-of 
select="allocation/to_"/></xsl:attribute>
                 </input>
                 </div>
             </dd>
+                       <dt><label for="field_repeat_until"><xsl:value-of 
select="php:function('lang', 'Recurring allocation')" /></label></dt>
+                       <dd>
+                               <label>
+                                       <input type="checkbox" name="outseason" 
id="outseason">
+                                               <xsl:if test="outseason='on'">
+                                                       <xsl:attribute 
name="checked">checked</xsl:attribute>
+                                               </xsl:if>
+                                       </input>
+                                       <xsl:value-of 
select="php:function('lang', 'Out season')" />
+                               </label>
+                       </dd>
+                       <dt><xsl:value-of select="php:function('lang', 
'Interval')" /></dt>
+                       <dd>
+                               <xsl:value-of select="../field_interval" />
+                               <select id="field_interval" 
name="field_interval">
+                                       <option value="1">
+                                               <xsl:if test="interval=1">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', '1 week')" />
+                                       </option>
+                                       <option value="2">
+                                               <xsl:if test="interval=2">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', '2 weeks')" />
+                                       </option>
+                                       <option value="3">
+                                               <xsl:if test="interval=3">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', '3 weeks')" />
+                                       </option>
+                                       <option value="4">
+                                               <xsl:if test="interval=4">
+                                                       <xsl:attribute 
name="selected">selected</xsl:attribute>
+                                               </xsl:if>
+                                               <xsl:value-of 
select="php:function('lang', '4 weeks')" />
+                                       </option>
+                               </select>
+                       </dd>
+
+
+
+        </dl>
+        <dl class="form-col">
+
+            <dt><label for="field_season"><xsl:value-of 
select="php:function('lang', 'Season')" /></label></dt>
+            <dd>
+                <div id="season_container"><xsl:value-of 
select="php:function('lang', 'Select a building first')" /></div>
+            </dd>
+
             <dt><label for="field_cost"><xsl:value-of 
select="php:function('lang', 'Cost')" /></label></dt>
             <dd>
                 <input id="field_cost" name="cost" type="text">
                     <xsl:attribute name="value"><xsl:value-of 
select="allocation/cost"/></xsl:attribute>
                 </input>
             </dd>
+
+            <dt><label for="field_resources"><xsl:value-of 
select="php:function('lang', 'Resources')" /></label></dt>
+            <dd>
+                <div id="resources_container"><xsl:value-of 
select="php:function('lang', 'Select a building first')" /></div>
+            </dd>
+
+
         </dl>
         <div class="form-buttons">
             <input type="submit">

Added: trunk/booking/templates/base/allocation_new_preview.xsl
===================================================================
--- trunk/booking/templates/base/allocation_new_preview.xsl                     
        (rev 0)
+++ trunk/booking/templates/base/allocation_new_preview.xsl     2010-10-28 
08:03:51 UTC (rev 6521)
@@ -0,0 +1,71 @@
+<xsl:template match="data" xmlns:php="http://php.net/xsl";>
+    <div id="content">
+
+       <dl class="form">
+       <dt class="heading"><xsl:value-of select="php:function('lang', 'New 
Allocation')"/></dt>
+       </dl>
+    <xsl:call-template name="msgbox"/>
+       <xsl:call-template name="yui_booking_i18n"/>
+
+       <!-- <xsl:call-template name="xmlsource"/> -->
+
+           <form action="" method="POST">
+                       <input type="hidden" name="organization_name" 
value="{allocation/organization_name}"/>
+                       <input type="hidden" name="organization_id" 
value="{allocation/organization_id}"/>
+                       <input type="hidden" name="building_name" 
value="{allocation/building_name}"/>
+                       <input type="hidden" name="building_id" 
value="{allocation/building_id}"/>
+                       <input type="hidden" name="from_" value="{from_date}"/>
+                       <input type="hidden" name="to_" value="{to_date}"/>
+                       <input type="hidden" name="weekday" value="{weekday}"/>
+                       <input type="hidden" name="building_id" 
value="{allocation/building_id}"/>
+                       <input type="hidden" name="cost" 
value="{allocation/cost}"/>
+                       <input type="hidden" name="season_id" 
value="{allocation/season_id}"/>
+                       <input type="hidden" name="field_building_id" 
value="{allocation/building_id}"/>
+                       <input type="hidden" name="step" value="{step}" />
+                       <input type="hidden" name="repeat_until" 
value="{repeat_until}" />
+                       <input type="hidden" name="field_interval" 
value="{interval}" />
+                       <input type="hidden" name="outseason" 
value="{outseason}" />
+                       <xsl:for-each select="allocation/resources">
+                               <input type="hidden" name="resources[]" 
value="{.}" />
+                       </xsl:for-each>
+
+                       <h4><xsl:value-of select="php:function('lang', 
'Allocations that can be created')" /></h4>
+                       <div class="allocation-list">
+                               <xsl:for-each select="valid_dates">
+                                       <li>
+                                               <xsl:value-of select="from_"/> 
- <xsl:value-of select="to_"/>
+                                       </li>
+                               </xsl:for-each>
+                       </div>
+
+                       <h4><xsl:value-of select="php:function('lang', 
'Allocations  with existing allocations or bookings (%1)', 
count(result/invalid[from_]))" /></h4>
+                       <div class="allocation-list">
+                               <xsl:for-each select="invalid_dates">
+                                       <li>
+                                               <xsl:value-of select="from_"/> 
- <xsl:value-of select="to_"/>
+                                       </li>
+                               </xsl:for-each>
+                       </div>
+               <div class="form-buttons">
+                   <input type="submit" name="create">
+                               <xsl:attribute name="value"><xsl:value-of 
select="php:function('lang', 'Create')" /></xsl:attribute>
+                               </input>
+                   <a class="cancel">
+                       <xsl:attribute name="href"><xsl:value-of 
select="allocation/cancel_link"/></xsl:attribute>
+                       <xsl:value-of select="php:function('lang', 'Cancel')" />
+                   </a>
+               </div>
+               </form>
+
+    </div>
+    <script type="text/javascript">
+        YAHOO.booking.initialSelection = <xsl:value-of 
select="allocation/resources_json"/>;
+    </script>
+</xsl:template>
+<xsl:template name="xmlsource">
+  NODE <xsl:value-of select="name()"/>
+  ATTR { <xsl:for-each select="attribute::*"><xsl:value-of 
select="name()"/>=<xsl:value-of select="."/> </xsl:for-each> }
+  CHILDREN: { <xsl:for-each select="*"><xsl:call-template 
name="xmlsource"/></xsl:for-each> }
+  TEXT <xsl:value-of select="text()"/>
+  <br/>
+</xsl:template>




reply via email to

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