forked from extern/egroupware
A new sitemgr module for public reservation of one specified resource. Uses an emailed confirmation link to confirm the reservation
This commit is contained in:
parent
1f76e0c191
commit
59b277ec5f
289
resources/inc/class.resources_reserve.inc.php
Normal file
289
resources/inc/class.resources_reserve.inc.php
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* eGroupWare - resources
|
||||||
|
* Book a single resource through sitemgr module, not the normal method
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package resources
|
||||||
|
* @link http://www.egroupware.org
|
||||||
|
* @author Nathan Gray
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
class resources_reserve {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->tmpl = new etemplate();
|
||||||
|
$this->bo = new resources_bo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Book a resource
|
||||||
|
*/
|
||||||
|
public function book($content = array(), $arguments = array())
|
||||||
|
{
|
||||||
|
$data = array();
|
||||||
|
$readonlys = array();
|
||||||
|
$display_days = $_GET['planner_days'] ? $_GET['planner_days'] : 3;
|
||||||
|
$planner_date = $_GET['date'] ? $_GET['date'] : strtotime('yesterday',$content['date'] ? $content['date'] : time());
|
||||||
|
|
||||||
|
if($_GET['confirm']) {
|
||||||
|
$register_code = ($_GET['confirm'] && preg_match('/^[0-9a-f]{32}$/',$_GET['confirm'])) ? $_GET['confirm'] : false;
|
||||||
|
if($register_code && $registration = registration_bo::confirm($register_code)) {
|
||||||
|
// Get calendar through link
|
||||||
|
$links = egw_link::get_links('registration', $registration['reg_id'],'calendar');
|
||||||
|
$bo = new calendar_boupdate();
|
||||||
|
$data = $bo->read(current($links));
|
||||||
|
|
||||||
|
$addressbook = new addressbook_bo();
|
||||||
|
$data += $addressbook->read(key($data['participant_types']['c']));
|
||||||
|
|
||||||
|
// Show date of reservation, so they can see it blocked off
|
||||||
|
$display_days = 1;
|
||||||
|
$planner_date = mktime(0,0,0,date('m',$data['start']),date('d',$data['start']),date('Y',$data['start']));
|
||||||
|
$readonlys['__ALL__'] = true;
|
||||||
|
$content = array(
|
||||||
|
'resource' => key($data['participant_types']['r']),
|
||||||
|
'date' => $data['start'],
|
||||||
|
'time' => $data['start'] - mktime(0,0,0,date('m',$data['start']),date('d',$data['start']),date('Y',$data['start']))
|
||||||
|
);
|
||||||
|
$data['msg']= '<div class="confirm">'.lang('Registration confirmed %1', egw_time::to($data['start'])) .'</div>';
|
||||||
|
} else {
|
||||||
|
$data['msg']= '<div class="confirm">'.lang('Unable to process confirmation.').'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tmpl->read('resources.sitemgr_book');
|
||||||
|
|
||||||
|
if(!$arguments['resource'] && !($arguments['resource'] = $content['resource'])) return false;
|
||||||
|
$data += $this->bo->read($arguments['resource']);
|
||||||
|
|
||||||
|
$data['quantity'] = $content['quantity'] ? $content['quantity'] : 2;
|
||||||
|
|
||||||
|
$data['date'] = $arguments['date'] ? $arguments['date'] : $content['date'];
|
||||||
|
$data['time'] = $content['time'];
|
||||||
|
|
||||||
|
$preserve = array(
|
||||||
|
'resource' => $data['res_id'],
|
||||||
|
);
|
||||||
|
$preserve['sitemgr_version'] = $arguments['sitemgr_version'] ? $arguments['sitemgr_version'] : $content['sitemgr_version'];
|
||||||
|
$preserve['confirmation'] = $arguments['confirmation'] || $content['confirmation'];
|
||||||
|
$preserve['contact_form'] = $arguments['contact_form'] ? $arguments['contact_form'] : $content['contact_form'];
|
||||||
|
$preserve['link'] = $arguments['link'] ? $arguments['link'] : $content['link'];
|
||||||
|
$preserve['email_message'] = $arguments['email_message'] ? $arguments['email_message'] : $content['email_message'];
|
||||||
|
|
||||||
|
// Check for valid time
|
||||||
|
if($data['date'] && $content['book'])
|
||||||
|
{
|
||||||
|
$start_time = $data['date'] + $data['time'];
|
||||||
|
$duration = ($GLOBALS['egw_info']['user']['preferences']['calendar']['defaultlength'] * 60);
|
||||||
|
$end_time = $start_time + $duration;
|
||||||
|
|
||||||
|
$config = config::read('registration');
|
||||||
|
|
||||||
|
// Not a user, need contact
|
||||||
|
if($GLOBALS['egw_info']['user']['account_lid'] == $GLOBALS['sitemgr_info']['anonymous_user'] && !$content['contact_id'])
|
||||||
|
{
|
||||||
|
if ($config['pending_addressbook']) // save the contact in the addressbook
|
||||||
|
{
|
||||||
|
$content['owner'] = $config['pending_addressbook'];
|
||||||
|
$content['private'] = 0; // in case default_private is set
|
||||||
|
}
|
||||||
|
|
||||||
|
$addressbook = new addressbook_bo();
|
||||||
|
$contact_fields = $addressbook->contact_fields;
|
||||||
|
unset($contact_fields['email']); // Always present
|
||||||
|
unset($contact_fields['id']); // Address already there
|
||||||
|
if(array_intersect_key($contact_fields,$content)) {
|
||||||
|
$result = $addressbook->save($content);
|
||||||
|
if(!$result) {
|
||||||
|
throw new egw_exception_no_permission($addressbook->error);
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$contact_id = $result;
|
||||||
|
$contact = 'c'.$contact_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$contact = $GLOBALS['egw_info']['user']['account_id'];
|
||||||
|
$contact_id = $GLOBALS['egw_info']['user']['person_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($contact) {
|
||||||
|
// Make event
|
||||||
|
$event = array(
|
||||||
|
'title' => egw_link::title('addressbook', $contact_id),
|
||||||
|
'start' => $start_time,
|
||||||
|
'end' => $end_time,
|
||||||
|
'participants' => array(
|
||||||
|
'r'.$data['res_id'] => calendar_so::combine_status('U', $data['quantity'], 'REQ-PARTICIPANT'),
|
||||||
|
$contact => calendar_so::combine_status('U', $data['quantity'], 'REQ-PARTICIPANT')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$cal_bo = new calendar_boupdate();
|
||||||
|
$result = $cal_bo->update($event);
|
||||||
|
|
||||||
|
// Show date of reservation, so they can see it blocked off
|
||||||
|
$display_days = 1;
|
||||||
|
$planner_date = mktime(0,0,0,date('m',$event['start']),date('d',$event['start']),date('Y',$event['start']));
|
||||||
|
|
||||||
|
// Free time search
|
||||||
|
if(!is_numeric($result))
|
||||||
|
{
|
||||||
|
$form = new calendar_uiforms();
|
||||||
|
$freetime = $form->freetime('r'.$data['res_id'],
|
||||||
|
strtotime($GLOBALS['egw_info']['user']['preferences']['calendar']['workdaystarts'] . ':00',$start_time),
|
||||||
|
strtotime($GLOBALS['egw_info']['user']['preferences']['calendar']['workdayends'] . ':00 ',$end_time),
|
||||||
|
$duration
|
||||||
|
);
|
||||||
|
$data += $content;
|
||||||
|
$data['msg'] = lang('Please choose a different time:')."\n";
|
||||||
|
foreach($freetime as $slot) {
|
||||||
|
$data['msg'] .= egw_time::to($slot['start']) . ' - ' . egw_time::to($slot['end'])."<br />\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($preserve['confirmation'] && $contact_id && $result)
|
||||||
|
{
|
||||||
|
// Confirmation required - send registration email
|
||||||
|
$reg_id = registration_bo::save(array(
|
||||||
|
'contact_id' => $contact_id,
|
||||||
|
'timestamp' => time() + ($config['expiry'] * 3600),
|
||||||
|
'post_confirm_hook' => 'resources_reserve::confirm'
|
||||||
|
), false);
|
||||||
|
if(is_numeric($reg_id))
|
||||||
|
{
|
||||||
|
// Link to event
|
||||||
|
egw_link::link('registration', $reg_id, 'calendar', $result);
|
||||||
|
$reg = registration_bo::read($reg_id);
|
||||||
|
|
||||||
|
// Send email
|
||||||
|
$email_info = $config + array(
|
||||||
|
'title' => $data['name'],
|
||||||
|
'subject' => $data['name'] . ' ' . egw_time::to($start_time),
|
||||||
|
'link' => $preserve['link'],
|
||||||
|
);
|
||||||
|
if($preserve['email_message'])
|
||||||
|
{
|
||||||
|
$email_info['message'] = lang($preserve['email_message'],
|
||||||
|
egw_time::to($start_time),
|
||||||
|
$preserve['link'].'&confirm='.$reg['register_code'],
|
||||||
|
egw_time::to($reg['timestamp'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$data['msg'] .= registration_bo::send_confirmation($email_info, $reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['picture'] = $this->bo->get_picture($data);
|
||||||
|
|
||||||
|
// Not a user, need contact
|
||||||
|
if($GLOBALS['egw_info']['user']['account_lid'] == $GLOBALS['sitemgr_info']['anonymous_user'] && !$content['contact_id'])
|
||||||
|
{
|
||||||
|
$data['contact_form'] = $preserve['contact_form'];
|
||||||
|
$data['show_contact'] = !$preserve['contact_form'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cal_user = array('r'.$arguments['resource']);
|
||||||
|
foreach($this->bo->get_acc_list($data['res_id']) as $acc_id => $name)
|
||||||
|
{
|
||||||
|
$cal_user[] = 'r'.$acc_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$data['date']) $data['date'] = strtotime('tomorrow');
|
||||||
|
if(!$data['time']) $data['time'] = $GLOBALS['egw_info']['user']['preferences']['calendar']['workdaystarts'] * 60 * 60;
|
||||||
|
if(!$GLOBALS['egw_info']['user']['apps']['resources'] || !$this->bo->get_calendar_info($data['res_id']) || // Needed for booking
|
||||||
|
!$GLOBALS['egw_info']['user']['apps']['calendar'] // Needed for updating schedule
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$data['planner'] = 'Permission error - site not configured properly. Need ' . lang('resources') . ' & ' . lang('calendar');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data['planner'] = $this->get_planner(
|
||||||
|
$arguments['resource'],
|
||||||
|
$planner_date ? $planner_date : strtotime('yesterday',$date), // Show day before, too
|
||||||
|
$display_days,
|
||||||
|
$preserve['link']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->tmpl->exec('resources.resources_reserve.book',$data,$sel_options,$readonlys,$preserve);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ajax_update_planner($resource_id, $date) {
|
||||||
|
$response = egw_json_response::get();
|
||||||
|
$response->assign('exec[planner_div]','innerHTML',$this->get_planner(
|
||||||
|
$resource_id,
|
||||||
|
strtotime('yesterday',$date),
|
||||||
|
3,
|
||||||
|
$_SERVER['HTTP_REFERER']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get HTML for the planner to show when its busy
|
||||||
|
*
|
||||||
|
* @param resource_id
|
||||||
|
*
|
||||||
|
* @return String - HTML
|
||||||
|
*/
|
||||||
|
protected function get_planner($resource_id, $date, $days = 3, $link)
|
||||||
|
{
|
||||||
|
//echo "get_planner($resource_id, $date, $days, $link)";
|
||||||
|
$calendar = new calendar_uiviews(array(
|
||||||
|
'owner' => 'r'.$resource_id,
|
||||||
|
//'owner' => implode(',',$cal_user),
|
||||||
|
'planner_days' => $days,
|
||||||
|
'view' => 'date_advance',
|
||||||
|
'date' => $date
|
||||||
|
));
|
||||||
|
// Need to add this in explicitly, or it may be lost if use clicks a day
|
||||||
|
$calendar->search_params['users'][] = 'r'.$resource_id;
|
||||||
|
$calendar->search_params['users'][] = $GLOBALS['egw_info']['user']['account_id'];
|
||||||
|
$calendar->allowEdit = false; // switches off all edit popups
|
||||||
|
|
||||||
|
$planner = '<style type="text/css">'."\n".
|
||||||
|
'@import url('.$GLOBALS['egw_info']['server']['webserver_url'].'/calendar/templates/default/app.css'.");\n".
|
||||||
|
'</style>'."\n";
|
||||||
|
|
||||||
|
// replacing egw-urls with sitemgr ones, allows to use navigation links
|
||||||
|
$planner .= str_replace($GLOBALS['egw_info']['server']['webserver_url'].'/index.php?',
|
||||||
|
$link.'&',
|
||||||
|
$calendar->planner(true));
|
||||||
|
|
||||||
|
return $planner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirm a registration done through sitemgr
|
||||||
|
*
|
||||||
|
* @param registration - registration information
|
||||||
|
*/
|
||||||
|
public function confirm($registration)
|
||||||
|
{
|
||||||
|
// Get calendar through link
|
||||||
|
$links = egw_link::get_links('registration', $registration['reg_id'],'calendar');
|
||||||
|
$bo = new calendar_boupdate();
|
||||||
|
$event = $bo->read(current($links));
|
||||||
|
if($registration['status'] == registration_bo::CONFIRMED)
|
||||||
|
{
|
||||||
|
$bo->set_status(current($links), 'c'.$registration['contact_id'], 'A');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$bo->delete(current($links));
|
||||||
|
// Remove contact ID, or registration will try to purge the account
|
||||||
|
if($registration['account_id'])
|
||||||
|
{
|
||||||
|
unset($registration['contact_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $registration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* EGroupware - eTemplates for Application resources
|
* EGroupware - eTemplates for Application resources
|
||||||
* http://www.egroupware.org
|
* http://www.egroupware.org
|
||||||
* generated by soetemplate::dump4setup() 2011-06-07 20:26
|
* generated by soetemplate::dump4setup() 2012-02-10 16:48
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
* @package resources
|
* @package resources
|
||||||
@ -63,5 +63,10 @@ $templ_data[] = array('name' => 'resources.show.rows','template' => '','lang' =>
|
|||||||
|
|
||||||
$templ_data[] = array('name' => 'resources.showdetails','template' => '','lang' => '','group' => '0','version' => '1.5.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:8:{i:0;a:8:{s:2:"c1";s:3:"nmh";s:1:"B";s:4:"100%";s:2:"c5";s:2:"th";s:2:"h3";s:2:"1%";s:2:"c6";s:11:"row_off,top";s:1:"A";s:3:"43%";s:2:"h1";s:5:"240px";s:2:"h5";s:10:",@!link_to";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"image";s:4:"name";s:16:"resource_picture";s:5:"align";s:6:"center";}s:1:"B";a:4:{s:4:"type";s:4:"grid";s:4:"data";a:9:{i:0;a:1:{s:2:"c5";s:4:",top";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:1:"b";s:5:"label";s:5:"Name:";}s:1:"B";a:4:{s:4:"type";s:5:"label";s:4:"size";s:1:"b";s:7:"no_lang";s:1:"1";s:4:"name";s:4:"name";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:17:"Inventory number:";}s:1:"B";a:3:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";s:4:"name";s:16:"inventory_number";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:9:"Category:";}s:1:"B";a:3:{s:4:"type";s:10:"select-cat";s:4:"name";s:6:"cat_id";s:8:"readonly";s:1:"1";}}i:4;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:13:"Responsible: ";}s:1:"B";a:3:{s:4:"type";s:14:"select-account";s:4:"name";s:9:"cat_admin";s:8:"readonly";s:1:"1";}}i:5;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:10:"Quantity: ";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:8:"quantity";}}i:6;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:8:"Useable:";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:7:"useable";}}i:7;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:9:"Location:";}s:1:"B";a:3:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";s:4:"name";s:8:"location";}}i:8;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:20:"Storage information:";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:12:"storage_info";}}}s:4:"rows";i:8;s:4:"cols";i:2;}}i:2;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:4:{s:4:"type";s:4:"html";s:4:"span";s:1:"2";s:4:"name";s:11:"description";s:8:"readonly";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:6:{s:4:"type";s:5:"label";s:4:"span";s:1:"2";s:4:"data";a:2:{i:0;a:1:{s:1:"A";s:4:"100%";}i:1;a:4:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:13:"Related links";}s:1:"B";a:6:{s:4:"type";s:6:"button";s:5:"label";s:17:"Buy this resource";s:5:"align";s:5:"right";s:4:"size";s:7:"buyable";s:4:"help";s:17:"Buy this resource";s:4:"name";s:11:"btn_buyable";}s:1:"C";a:4:{s:4:"type";s:6:"button";s:5:"label";s:18:"Book this resource";s:4:"name";s:12:"btn_bookable";s:4:"size";s:8:"bookable";}s:1:"D";a:5:{s:4:"type";s:6:"button";s:5:"label";s:4:"edit";s:4:"name";s:8:"btn_edit";s:4:"size";s:4:"edit";s:4:"help";s:4:"edit";}}}s:4:"rows";i:1;s:4:"cols";i:4;s:5:"label";s:13:"Related links";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:9:"link-list";s:4:"span";s:3:"all";s:4:"name";s:7:"link_to";s:8:"readonly";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:7;a:2:{s:1:"A";a:8:{s:4:"type";s:4:"hbox";s:5:"label";s:6:"Cancel";s:4:"span";s:1:"2";s:4:"size";s:1:"2";i:1;a:9:{s:4:"type";s:4:"hbox";s:5:"label";s:4:"Edit";s:4:"span";s:1:"2";s:4:"name";s:8:"btn_edit";s:4:"size";s:1:"4";i:1;a:5:{s:4:"type";s:6:"button";s:5:"label";s:4:"Edit";s:4:"span";s:1:"2";s:4:"name";s:8:"btn_edit";s:4:"help";s:16:"Buy this article";}i:2;a:3:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:7:"onclick";s:14:"window.close()";}i:3;a:6:{s:4:"type";s:6:"button";s:5:"label";s:8:"Calendar";s:4:"span";s:1:"2";s:4:"name";s:12:"btn_calendar";s:4:"help";s:25:"Show calendar of resource";s:7:"onclick";s:120:"opener.location=egw::link(\'/index.php\',\'menuaction=calendar.calendar_uiviews.month&owner=r$cont[res_id]\'); return false;";}i:4;a:5:{s:4:"type";s:6:"button";s:5:"label";s:4:"Book";s:7:"onclick";s:209:"window.open(egw::link(\'/index.php\',\'menuaction=calendar.calendar_uiforms.edit&participants=r$cont[res_id]\'),\'\',\'dependent=yes,width=750,height=400,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\');";s:4:"name";s:8:"btn_book";s:4:"help";s:18:"Book this resource";}}i:2;a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"1";s:5:"align";s:5:"right";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:7:"onclick";s:61:"return confirm(\'Do you really want do delte this resource?\');";s:4:"name";s:10:"btn_delete";}}i:3;a:1:{s:4:"type";s:5:"label";}i:4;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:4:"name";s:10:"btn_delete";s:5:"align";s:5:"right";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:7;s:4:"cols";i:2;s:4:"size";s:7:"750,480";s:7:"options";a:2:{i:0;s:3:"750";i:1;s:3:"480";}}}','size' => '750,480','style' => '','modified' => '1129667646',);
|
$templ_data[] = array('name' => 'resources.showdetails','template' => '','lang' => '','group' => '0','version' => '1.5.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:8:{i:0;a:8:{s:2:"c1";s:3:"nmh";s:1:"B";s:4:"100%";s:2:"c5";s:2:"th";s:2:"h3";s:2:"1%";s:2:"c6";s:11:"row_off,top";s:1:"A";s:3:"43%";s:2:"h1";s:5:"240px";s:2:"h5";s:10:",@!link_to";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"image";s:4:"name";s:16:"resource_picture";s:5:"align";s:6:"center";}s:1:"B";a:4:{s:4:"type";s:4:"grid";s:4:"data";a:9:{i:0;a:1:{s:2:"c5";s:4:",top";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:1:"b";s:5:"label";s:5:"Name:";}s:1:"B";a:4:{s:4:"type";s:5:"label";s:4:"size";s:1:"b";s:7:"no_lang";s:1:"1";s:4:"name";s:4:"name";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:17:"Inventory number:";}s:1:"B";a:3:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";s:4:"name";s:16:"inventory_number";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:9:"Category:";}s:1:"B";a:3:{s:4:"type";s:10:"select-cat";s:4:"name";s:6:"cat_id";s:8:"readonly";s:1:"1";}}i:4;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:13:"Responsible: ";}s:1:"B";a:3:{s:4:"type";s:14:"select-account";s:4:"name";s:9:"cat_admin";s:8:"readonly";s:1:"1";}}i:5;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:10:"Quantity: ";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:8:"quantity";}}i:6;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:8:"Useable:";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:7:"useable";}}i:7;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:9:"Location:";}s:1:"B";a:3:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";s:4:"name";s:8:"location";}}i:8;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:20:"Storage information:";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:4:"name";s:12:"storage_info";}}}s:4:"rows";i:8;s:4:"cols";i:2;}}i:2;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:4:{s:4:"type";s:4:"html";s:4:"span";s:1:"2";s:4:"name";s:11:"description";s:8:"readonly";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:6:{s:4:"type";s:5:"label";s:4:"span";s:1:"2";s:4:"data";a:2:{i:0;a:1:{s:1:"A";s:4:"100%";}i:1;a:4:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:13:"Related links";}s:1:"B";a:6:{s:4:"type";s:6:"button";s:5:"label";s:17:"Buy this resource";s:5:"align";s:5:"right";s:4:"size";s:7:"buyable";s:4:"help";s:17:"Buy this resource";s:4:"name";s:11:"btn_buyable";}s:1:"C";a:4:{s:4:"type";s:6:"button";s:5:"label";s:18:"Book this resource";s:4:"name";s:12:"btn_bookable";s:4:"size";s:8:"bookable";}s:1:"D";a:5:{s:4:"type";s:6:"button";s:5:"label";s:4:"edit";s:4:"name";s:8:"btn_edit";s:4:"size";s:4:"edit";s:4:"help";s:4:"edit";}}}s:4:"rows";i:1;s:4:"cols";i:4;s:5:"label";s:13:"Related links";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:9:"link-list";s:4:"span";s:3:"all";s:4:"name";s:7:"link_to";s:8:"readonly";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:7;a:2:{s:1:"A";a:8:{s:4:"type";s:4:"hbox";s:5:"label";s:6:"Cancel";s:4:"span";s:1:"2";s:4:"size";s:1:"2";i:1;a:9:{s:4:"type";s:4:"hbox";s:5:"label";s:4:"Edit";s:4:"span";s:1:"2";s:4:"name";s:8:"btn_edit";s:4:"size";s:1:"4";i:1;a:5:{s:4:"type";s:6:"button";s:5:"label";s:4:"Edit";s:4:"span";s:1:"2";s:4:"name";s:8:"btn_edit";s:4:"help";s:16:"Buy this article";}i:2;a:3:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:7:"onclick";s:14:"window.close()";}i:3;a:6:{s:4:"type";s:6:"button";s:5:"label";s:8:"Calendar";s:4:"span";s:1:"2";s:4:"name";s:12:"btn_calendar";s:4:"help";s:25:"Show calendar of resource";s:7:"onclick";s:120:"opener.location=egw::link(\'/index.php\',\'menuaction=calendar.calendar_uiviews.month&owner=r$cont[res_id]\'); return false;";}i:4;a:5:{s:4:"type";s:6:"button";s:5:"label";s:4:"Book";s:7:"onclick";s:209:"window.open(egw::link(\'/index.php\',\'menuaction=calendar.calendar_uiforms.edit&participants=r$cont[res_id]\'),\'\',\'dependent=yes,width=750,height=400,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\');";s:4:"name";s:8:"btn_book";s:4:"help";s:18:"Book this resource";}}i:2;a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"1";s:5:"align";s:5:"right";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:7:"onclick";s:61:"return confirm(\'Do you really want do delte this resource?\');";s:4:"name";s:10:"btn_delete";}}i:3;a:1:{s:4:"type";s:5:"label";}i:4;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Delete";s:4:"name";s:10:"btn_delete";s:5:"align";s:5:"right";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:7;s:4:"cols";i:2;s:4:"size";s:7:"750,480";s:7:"options";a:2:{i:0;s:3:"750";i:1;s:3:"480";}}}','size' => '750,480','style' => '','modified' => '1129667646',);
|
||||||
|
|
||||||
|
$templ_data[] = array('name' => 'resources.sitemgr_book','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:3:"box";s:4:"data";a:2:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:1;s:4:"cols";i:1;s:4:"size";s:1:"1";i:1;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:12:{i:0;a:6:{s:2:"h2";s:6:",!@msg";s:2:"h7";s:15:",!@contact_form";s:2:"h8";s:15:",!@show_contact";s:2:"h9";s:15:",!@show_contact";s:2:"h4";s:20:",!@short_description";s:2:"h5";s:19:",!@long_description";}i:1;a:2:{s:1:"A";a:2:{s:4:"type";s:6:"hidden";s:4:"name";s:6:"res_id";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:3:{s:4:"type";s:4:"html";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:4:"name";s:4:"span";s:5:",name";}s:1:"B";a:4:{s:4:"type";s:5:"image";s:4:"name";s:7:"picture";s:5:"align";s:5:"right";s:4:"span";s:15:",resource_thumb";}}i:4;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:17:"short_description";s:4:"span";s:15:"all,description";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:3:{s:4:"type";s:4:"html";s:4:"span";s:15:"all,description";s:4:"name";s:16:"long_description";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:5:"label";i:1;a:3:{s:4:"type";s:4:"date";s:5:"label";s:4:"Date";s:4:"name";s:4:"date";}i:2;a:2:{s:4:"type";s:13:"date-timeonly";s:4:"name";s:4:"time";}s:5:"label";s:4:"Date";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:6:"2,,0,0";i:1;a:3:{s:4:"type";s:4:"date";s:4:"name";s:4:"date";s:8:"onchange";s:219:"var request = new egw_json_request(\'resources.resources_reserve.ajax_update_planner\',[document.getElementById(\'exec[res_id]\').value, Math.round(window.calendar.date.getTime()/1000)]);request.sendRequest(); return false;";}i:2;a:2:{s:4:"type";s:13:"date-timeonly";s:4:"name";s:4:"time";}}}i:7;a:2:{s:1:"A";a:3:{s:4:"type";s:8:"template";s:4:"span";s:3:"all";s:4:"name";s:13:"@contact_form";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:8;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:4:"Name";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:6:"2,,0,0";i:1;a:3:{s:4:"type";s:4:"text";s:4:"name";s:7:"n_given";i:1;a:1:{s:4:"type";s:4:"hbox";}}i:2;a:2:{s:4:"type";s:4:"text";s:4:"name";s:8:"n_family";}}}i:9;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:5:"Email";}s:1:"B";a:4:{s:4:"type";s:9:"url-email";s:4:"size";s:2:"48";s:4:"name";s:5:"email";s:6:"needed";s:1:"1";}}i:10;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:10:"Party size";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:2:{s:4:"type";s:3:"int";s:4:"name";s:8:"quantity";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:4:"Book";s:5:"align";s:5:"right";s:4:"name";s:4:"book";}}}i:11;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"span";s:3:"all";s:4:"name";s:11:"planner_div";s:4:"size";s:1:"1";i:1;a:3:{s:4:"type";s:4:"html";s:4:"span";s:3:"all";s:4:"name";s:7:"planner";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:11;s:4:"cols";i:2;s:4:"size";s:4:"100%";s:7:"options";a:1:{i:0;s:4:"100%";}}}}','size' => '','style' => '.resource_thumb img {
|
||||||
|
float:right;
|
||||||
|
position:absolute;
|
||||||
|
}','modified' => '1328133598',);
|
||||||
|
|
||||||
$templ_data[] = array('name' => 'resources.test','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:16:"resources_select";s:4:"size";s:1:"5";s:4:"name";s:4:"test";}}}s:4:"rows";i:1;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1249373358',);
|
$templ_data[] = array('name' => 'resources.test','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:16:"resources_select";s:4:"size";s:1:"5";s:4:"name";s:4:"test";}}}s:4:"rows";i:1;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1249373358',);
|
||||||
|
|
||||||
|
116
resources/sitemgr/class.module_resources_reservation.inc.php
Normal file
116
resources/sitemgr/class.module_resources_reservation.inc.php
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Module for quick & easy resource reservation
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package resources
|
||||||
|
* @author Nathan Gray
|
||||||
|
* @copyright (c) 2011 Nathan Gray
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needs permission to resources to read the resource, calendar app to properly push everything through
|
||||||
|
*/
|
||||||
|
class module_resources_reservation extends sitemgr_module
|
||||||
|
{
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->title = lang('Reserve');
|
||||||
|
$this->description = lang('Simple reservation of a single item');
|
||||||
|
$this->etemplate_method = 'resources.resources_reserve.book';
|
||||||
|
|
||||||
|
$categories = new categories('', 'resources');
|
||||||
|
$cat_list = $categories->return_sorted_array();
|
||||||
|
$cat_options = array();
|
||||||
|
foreach($cat_list as $category)
|
||||||
|
{
|
||||||
|
$cat_options[$category['id']] = $category['name'];
|
||||||
|
}
|
||||||
|
$this->arguments = array(
|
||||||
|
'category' => array(
|
||||||
|
'type' => 'select',
|
||||||
|
'label' => lang('Category'),
|
||||||
|
'options' => $cat_options
|
||||||
|
),
|
||||||
|
'resource' => array(
|
||||||
|
'type' => 'select',
|
||||||
|
'label' => lang('Resource'),
|
||||||
|
'options' => array(
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'contact_form' => array(
|
||||||
|
'type' => 'textfield',
|
||||||
|
'label' => lang('Custom eTemplate for the contactform'),
|
||||||
|
'params' => array('size' => 40),
|
||||||
|
),
|
||||||
|
'confirmation' => array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => lang('Require confirmation'),
|
||||||
|
),
|
||||||
|
'email_message' => array(
|
||||||
|
'type' => 'textarea',
|
||||||
|
'large' => true,
|
||||||
|
'label' => lang('Confirmation email text').'<br />%1 = ' . lang('Event start').'<br/>%2 = link<br />%3 = '.lang('expiry'),
|
||||||
|
'params' => array(
|
||||||
|
'rows' => 8,
|
||||||
|
'cols' => 110
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_user_interface()
|
||||||
|
{
|
||||||
|
$query = array(
|
||||||
|
// Resources uses filter, not cat_id
|
||||||
|
'filter' => $this->block->arguments['category'],
|
||||||
|
'bookable' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add resources from selected category
|
||||||
|
$bo = new resources_bo();
|
||||||
|
$bo->get_rows($query, $list, $readonlys);
|
||||||
|
foreach($list as $resource)
|
||||||
|
{
|
||||||
|
$this->arguments['resource']['options'][$resource['res_id']] = $resource['name'];
|
||||||
|
}
|
||||||
|
return parent::get_user_interface();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generate the module content AND process submitted forms
|
||||||
|
* Overridden from parent to pass arguments
|
||||||
|
*
|
||||||
|
* @param array &$arguments $arguments['arg1']-$arguments['arg3'] will be passed for non-submitted forms (first call)
|
||||||
|
* @param array $properties
|
||||||
|
* @return string the html content
|
||||||
|
*/
|
||||||
|
function get_content(&$arguments,$properties)
|
||||||
|
{
|
||||||
|
list($app) = explode('.',$this->etemplate_method);
|
||||||
|
$GLOBALS['egw']->translation->add_app($app);
|
||||||
|
|
||||||
|
$extra = "<style type=\"text/css\">\n<!--\n@import url(".$GLOBALS['egw_info']['server']['webserver_url'].
|
||||||
|
"/etemplate/templates/default/app.css);\n";
|
||||||
|
|
||||||
|
if ($app != 'etemplate' && file_exists(EGW_SERVER_ROOT.'/'.$app.'/templates/default/app.css'))
|
||||||
|
{
|
||||||
|
$extra .= "@import url(".$GLOBALS['egw_info']['server']['webserver_url'].
|
||||||
|
'/'.$app."/templates/default/app.css);\n";
|
||||||
|
}
|
||||||
|
$extra .= "-->\n</style>\n";
|
||||||
|
$extra .= '<script src="'.$GLOBALS['egw_info']['server']['webserver_url'].'/etemplate/js/etemplate.js" type="text/javascript"></script>'."\n";
|
||||||
|
$ret = false;
|
||||||
|
if($_POST['etemplate_exec_id'])
|
||||||
|
{
|
||||||
|
$ret = ExecMethod('etemplate.etemplate.process_exec');
|
||||||
|
}
|
||||||
|
if($_GET['date']) $arguments['date'] = strtotime($_GET['date']);
|
||||||
|
$arguments['link'] = $this->link();
|
||||||
|
$arguments['sitemgr_version'] = $this->block->version;
|
||||||
|
return $extra.($ret ? $ret : ExecMethod2($this->etemplate_method,null,$arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
75
resources/templates/default/sitemgr_book.xet
Normal file
75
resources/templates/default/sitemgr_book.xet
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- $Id$ -->
|
||||||
|
<overlay>
|
||||||
|
<template id="resources.sitemgr_book" template="" lang="" group="0" version="1.9.001">
|
||||||
|
<box cols="1" rows="1">
|
||||||
|
<grid width="100%">
|
||||||
|
<columns>
|
||||||
|
<column/>
|
||||||
|
<column/>
|
||||||
|
</columns>
|
||||||
|
<rows>
|
||||||
|
<row>
|
||||||
|
<hidden id="res_id"/>
|
||||||
|
<description/>
|
||||||
|
</row>
|
||||||
|
<row disabled="!@msg">
|
||||||
|
<html id="msg" span="all" class="message"/>
|
||||||
|
<description/>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<description id="name" class="name"/>
|
||||||
|
<image align="right" src="picture" class="resource_thumb"/>
|
||||||
|
</row>
|
||||||
|
<row disabled="!@short_description">
|
||||||
|
<description id="short_description" span="all" class="description"/>
|
||||||
|
<description/>
|
||||||
|
</row>
|
||||||
|
<row disabled="!@long_description">
|
||||||
|
<html id="long_description" span="all" class="description"/>
|
||||||
|
<description/>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<description value="Date"/>
|
||||||
|
<hbox options="0,0">
|
||||||
|
<date id="date" onchange="var request = new egw_json_request('resources.resources_reserve.ajax_update_planner',[document.getElementById('exec[res_id]').value, Math.round(window.calendar.date.getTime()/1000)]);request.sendRequest(); return false;"/>
|
||||||
|
<date-timeonly id="time"/>
|
||||||
|
</hbox>
|
||||||
|
</row>
|
||||||
|
<row disabled="!@contact_form">
|
||||||
|
<template id="@contact_form" span="all"/>
|
||||||
|
</row>
|
||||||
|
<row disabled="!@show_contact">
|
||||||
|
<description value="Name"/>
|
||||||
|
<hbox options="0,0">
|
||||||
|
<textbox id="n_given"/>
|
||||||
|
<textbox id="n_family"/>
|
||||||
|
</hbox>
|
||||||
|
</row>
|
||||||
|
<row disabled="!@show_contact">
|
||||||
|
<description value="Email"/>
|
||||||
|
<url-email id="email" needed="1" options="48"/>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<description value="Party size"/>
|
||||||
|
<hbox>
|
||||||
|
<textbox type="integer" id="quantity"/>
|
||||||
|
<button align="right" label="Book" id="book"/>
|
||||||
|
</hbox>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<box id="planner_div" span="all">
|
||||||
|
<html id="planner" span="all"/>
|
||||||
|
</box>
|
||||||
|
</row>
|
||||||
|
</rows>
|
||||||
|
</grid>
|
||||||
|
</box>
|
||||||
|
<styles>
|
||||||
|
.resource_thumb img {
|
||||||
|
float:right;
|
||||||
|
position:absolute;
|
||||||
|
}
|
||||||
|
</styles>
|
||||||
|
</template>
|
||||||
|
</overlay>
|
Loading…
Reference in New Issue
Block a user