[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7220] bkbooking: added delete allocation
From: |
Kjell Arne Espedal |
Subject: |
[Fmsystem-commits] [7220] bkbooking: added delete allocation |
Date: |
Fri, 15 Apr 2011 10:35:29 +0000 |
Revision: 7220
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7220
Author: kjell
Date: 2011-04-15 10:35:29 +0000 (Fri, 15 Apr 2011)
Log Message:
-----------
bkbooking: added delete allocation
Modified Paths:
--------------
trunk/booking/inc/class.soallocation.inc.php
trunk/booking/inc/class.uiallocation.inc.php
trunk/booking/setup/phpgw_no.lang
trunk/booking/templates/base/allocation.xsl
trunk/booking/templates/base/allocation_info.xsl
Modified: trunk/booking/inc/class.soallocation.inc.php
===================================================================
--- trunk/booking/inc/class.soallocation.inc.php 2011-04-15 10:34:04 UTC
(rev 7219)
+++ trunk/booking/inc/class.soallocation.inc.php 2011-04-15 10:35:29 UTC
(rev 7220)
@@ -220,9 +220,52 @@
}
return $results;
}
+ function get_allocation_id($allocation)
+ {
- public function update_id_string() {
+ $from = "'".$allocation['from_']."'";
+ $to = "'".$allocation['to_']."'";
+ $org_id = $allocation['organization_id'];
+ $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))";
+
+ $this->db->limit_query($sql, 0,__LINE__, __FILE__,1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return $this->db->f('id', false);
+ }
+
+ function check_for_booking($id)
+ {
+ $sql = "SELECT id FROM bb_booking WHERE allocation_id = ($id)";
+
+ $this->db->limit_query($sql, 0,__LINE__, __FILE__,1);
+ if(!$this->db->next_record())
+ {
+ return False;
+ }
+ return $this->db->f('id', false);
+
+ }
+
+ public function delete_allocation($id)
+ {
+ $db = $this->db;
+ $table_name = $this->table_name.'_resource';
+ $sql = "DELETE FROM $table_name WHERE allocation_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__);
+ }
+
+ public function update_id_string()
+ {
+ $table_name = $this->table_name;
$db = $this->db;
$sql = "UPDATE $table_name SET id_string = cast(id AS
varchar)";
$db->query($sql, __LINE__, __FILE__);
Modified: trunk/booking/inc/class.uiallocation.inc.php
===================================================================
--- trunk/booking/inc/class.uiallocation.inc.php 2011-04-15 10:34:04 UTC
(rev 7219)
+++ trunk/booking/inc/class.uiallocation.inc.php 2011-04-15 10:35:29 UTC
(rev 7220)
@@ -10,6 +10,7 @@
'add' => true,
'show' => true,
'edit' => true,
+ 'delete' => true,
'info' => true,
'toggle_show_inactive' => true,
);
@@ -373,11 +374,115 @@
$allocation['application_link'] =
self::link(array('menuaction' => 'booking.uiapplication.show', 'id' =>
$allocation['application_id']));
self::render_template('allocation_edit',
array('allocation' => $allocation));
}
+
+ public function delete()
+ {
+ $id = intval(phpgw::get_var('allocation_id', 'GET'));
+ $allocation = $this->bo->read_single($id);
+ $season =
$this->season_bo->read_single($allocation['season_id']);
+ $step = phpgw::get_var('step', 'str', 'POST');
+ if (! isset($step)) $step = 1;
+ $errors = array();
+ $invalid_dates = array();
+ $valid_dates = array();
+
+
+ if($_SERVER['REQUEST_METHOD'] == 'POST')
+ {
+ $from_date = $_POST['from_'];
+ $to_date = $_POST['to_'];
+ $step++;
+
+ if ($_POST['recurring'] != 'on' &&
$_POST['outseason'] != 'on' )
+ {
+ $err = $this->bo->so->check_for_booking($id);
+ if ($err)
+ {
+ $errors['booking'] = lang('Could not delete
allocation due to a booking still use it');
+ }
+ else
+ {
+ $err = $this->bo->so->delete_allocation($id);
+ $this->redirect(array('menuaction' =>
'booking.uimassbooking.schedule', 'id'=>$allocation['building_id']));
+ }
+ }
+ else
+ {
+ if ($_POST['recurring'] == 'on') {
+ $repeat_until =
strtotime($_POST['repeat_until'])+60*60*24;
+ }
+ else
+ {
+ $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;
+
+ $id = $this->bo->so->get_allocation_id($allocation);
+ $err = $this->bo->so->check_for_booking($id);
+ 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)
+ {
+ $stat = $this->bo->so->delete_allocation($id);
}
+ }
+ $i++;
+ }
+ if ($step == 3)
+ {
+
$this->redirect(array('menuaction' => 'booking.uimassbooking.schedule',
'id'=>$allocation['building_id']));
+ }
+ }
+ }
+ $this->flash_form_errors($errors);
+ self::add_javascript('booking', 'booking',
'allocation.js');
+ $allocation['resources_json'] =
json_encode(array_map('intval', $allocation['resources']));
+ $allocation['cancel_link'] =
self::link(array('menuaction' => 'booking.uiallocation.show', 'id' =>
$allocation['id']));
+ $allocation['application_link'] =
self::link(array('menuaction' => 'booking.uiapplication.show', 'id' =>
$allocation['application_id']));
+
+ if ($step < 2)
+ {
+ self::render_template('allocation_delete',
array('allocation' => $allocation));
+ }
+ elseif ($step == 2)
+ {
+
self::render_template('allocation_delete_preview', array('allocation' =>
$allocation,
+ 'step' => $step,
+ 'recurring' => $_POST['recurring'],
+ 'outseason' => $_POST['outseason'],
+ 'interval' => $_POST['field_interval'],
+ 'repeat_until' =>
$_POST['repeat_until'],
+ 'from_date' => $from_date,
+ 'to_date' => $to_date,
+ 'valid_dates' => $valid_dates,
+ 'invalid_dates' => $invalid_dates
+ ));
+ }
+ }
public function show()
{
$allocation =
$this->bo->read_single(phpgw::get_var('id', 'GET'));
$allocation['allocations_link'] =
self::link(array('menuaction' => 'booking.uiallocation.index'));
+ $allocation['delete_link'] =
self::link(array('menuaction' => 'booking.uiallocation.delete',
'allocation_id'=>$allocation['id'], 'from_'=>$allocation['from_'],
'to_'=>$allocation['to_'], 'resource'=>$allocation['resource']));
$allocation['edit_link'] =
self::link(array('menuaction' => 'booking.uiallocation.edit', 'id' =>
$allocation['id']));
$resource_ids = '';
foreach($allocation['resources'] as $res)
@@ -401,6 +506,7 @@
$allocation['resource_info'] = join(', ', $res_names);
$allocation['building_link'] =
self::link(array('menuaction' => 'booking.uibuilding.show', 'id' =>
$allocation['resources'][0]['building_id']));
$allocation['org_link'] = self::link(array('menuaction'
=> 'booking.uiorganization.show', 'id' => $allocation['organization_id']));
+ $allocation['delete_link'] =
self::link(array('menuaction' => 'booking.uiallocation.delete',
'allocation_id'=>$allocation['id'], 'from_'=>$allocation['from_'],
'to_'=>$allocation['to_'], 'resource'=>$allocation['resource']));
$allocation['add_link'] = self::link(array('menuaction'
=> 'booking.uibooking.add', 'allocation_id'=>$allocation['id'],
'from_'=>$allocation['from_'], 'to_'=>$allocation['to_'],
'resource'=>$allocation['resource']));
$allocation['when'] =
pretty_timestamp($allocation['from_']).' -
'.pretty_timestamp($allocation['to_']);
self::render_template('allocation_info',
array('allocation'=>$allocation));
Modified: trunk/booking/setup/phpgw_no.lang
===================================================================
--- trunk/booking/setup/phpgw_no.lang 2011-04-15 10:34:04 UTC (rev 7219)
+++ trunk/booking/setup/phpgw_no.lang 2011-04-15 10:35:29 UTC (rev 7220)
@@ -491,3 +491,9 @@
NB! No data will be saved, if you navigate away you will loose all. booking
no NB! Ingen data er lagret.
Activity booking no Aktiviteter
Not selected booking no Ikke valgt
+Delete until booking no Slett til
+Recurring allocation deletion booking no Slettings intervall
+Delete allocation booking no Slett tildeling
+Delete allocations booking no Slett tildelinger
+Allocations that will be deleted booking no Tildelinger som vil bli
slettet
+Allocations with existing bookings (%1) booking no Tildeinger med
eksisterende bookinger (%1)
Modified: trunk/booking/templates/base/allocation.xsl
===================================================================
--- trunk/booking/templates/base/allocation.xsl 2011-04-15 10:34:04 UTC (rev
7219)
+++ trunk/booking/templates/base/allocation.xsl 2011-04-15 10:35:29 UTC (rev
7220)
@@ -36,6 +36,10 @@
<xsl:attribute
name="onclick">window.location.href="<xsl:value-of
select="allocation/edit_link"/>"</xsl:attribute>
<xsl:value-of select="php:function('lang', 'Edit')"
/>
</button>
+ <button>
+ <xsl:attribute
name="onclick">window.location.href="<xsl:value-of
select="allocation/delete_link"/>"</xsl:attribute>
+ <xsl:value-of select="php:function('lang',
'Delete')" />
+ </button>
</xsl:if>
</div>
</div>
Modified: trunk/booking/templates/base/allocation_info.xsl
===================================================================
--- trunk/booking/templates/base/allocation_info.xsl 2011-04-15 10:34:04 UTC
(rev 7219)
+++ trunk/booking/templates/base/allocation_info.xsl 2011-04-15 10:35:29 UTC
(rev 7220)
@@ -16,7 +16,13 @@
</dl>
<xsl:if test="allocation/add_link">
<div class="actions">
- <button
onclick="location.href='{allocation/add_link}'"><xsl:value-of
select="php:function('lang', 'Create new booking')"/></button>
+ <button
onclick="location.href='{allocation/add_link}'"><xsl:value-of
select="php:function('lang', 'Create new booking')"/></button>
</div>
</xsl:if>
+ <xsl:if test="allocation/delete_link">
+ <div class="actions">
+ <button
onclick="location.href='{allocation/delete_link}'"><xsl:value-of
select="php:function('lang', 'Delete allocation')"/></button>
+ </div>
+ </xsl:if>
+
</xsl:template>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7220] bkbooking: added delete allocation,
Kjell Arne Espedal <=