Source for file instrument.php
Documentation is available at instrument.php
* Instrument object (extends dbo), with extra customisations for other links
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'inc/bb/configreader.php';
require_once 'inc/formslib/dbrow.php';
require_once 'inc/formslib/idfield.php';
require_once 'inc/formslib/textfield.php';
require_once 'inc/formslib/textarea.php';
require_once 'inc/formslib/commentfield.php';
require_once 'inc/formslib/checkbox.php';
require_once 'inc/formslib/radiolist.php';
require_once 'inc/formslib/exampleentries.php';
require_once 'inc/bookings/timeslotrule.php';
* Instrument object (extends dbo), with extra customisations for other links
$this->DBRow('instruments', $id);
$attrs =
array('size' =>
'48');
$f->isValidTest =
'is_nonempty_string';
$f->isValidTest =
'is_nonempty_string';
$f->isValidTest =
'is_nonempty_string';
$f =
new TextField('usualopen', T_('Calendar start time (HH:MM)'));
$f->defaultValue =
$conf->value('instruments', 'usualopen');
$f->isValidTest =
'is_valid_time';
$f =
new TextField('usualclose', T_('Calendar end time (HH:MM)'));
$f->defaultValue =
$conf->value('instruments', 'usualclose');
$f->isValidTest =
'is_valid_time';
$f =
new TextField('calprecision', T_('Precision of calendar display (seconds)'));
$f->defaultValue =
$conf->value('instruments', 'usualprecision');
$f->isValidTest =
'is_number';
$f =
new TextField('caltimemarks', T_('Time-periods per HH:MM displayed'));
$f->defaultValue =
$conf->value('instruments', 'usualtimemarks');
$f->isValidTest =
'is_number';
$f =
new TextField('callength', T_('Number of weeks displayed in calendar'));
$f->defaultValue =
$conf->value('instruments', 'usualcallength');
$f->isValidTest =
'is_number';
$f =
new TextField('calhistory', T_('Number of weeks history shown'));
$f->defaultValue =
$conf->value('instruments', 'usualcalhistory');
$f->isValidTest =
'is_number';
$f =
new TextField('calfuture', T_('Number of days into the future'));
$f->defaultValue =
$conf->value('instruments', 'usualcalfuture');
$f->isValidTest =
'is_number';
$f =
new TextArea('calendarcomment', T_('Advisory text'),
T_('Displayed at the bottom of instrument calendar and on booking form. HTML permitted.'));
$f->setAttr(array('rows' =>
5, 'cols' =>
30));
// associate with a charging class
$f->connectDB('instrumentclass', array('id', 'name'));
$classexample =
new ExampleEntries('id','instruments','class','name',3);
$classexample->separator =
'; ';
$f->setFormat('id', '%s', array('name'), ' (%40.40s)', $classexample);
$newclassname->namebase =
'newclass-';
$newclassname->setAttr(array('size' =>
24));
$newclassname->isValidTest =
'is_nonempty_string';
$newclassname->suppressValidation =
0;
$f->list->append(array('-1',T_('Create new:').
' '), $newclassname);
$f->isValidTest =
'is_valid_radiochoice';
$f =
new TextField('halfdaylength', T_('Hours in a half-day'));
$f->defaultValue =
$conf->value('instruments', 'usualhalfdaylength');
$f->isValidTest =
'is_number';
$f =
new TextField('fulldaylength', T_('Hours in a full-day'));
$f->defaultValue =
$conf->value('instruments', 'usualfulldaylength');
$f->isValidTest =
'is_number';
// create the timeslot rule information required
$f =
new CommentField('timeslotpicturecomment', T_('Instrument timeslots'),
T_('These fields describe when the instrument is available.'));
$f->value =
T_('Format: HH:MM-HH:MM/n-x%,comment');
$f =
new TextField('timeslotpicture', T_('Time slot picture'));
$f->defaultValue =
$conf->value('instruments', 'usualtimeslotpicture');
$f->isValidTest =
'is_set';
for ($day=
0; $day<
7; $day++
) {
$today =
clone($weekstart);
$f =
new TextArea('tsr-'.
$day, $today->dowStr(), T_('Slots in day, one per line'));
$f->setAttr(array('rows' =>
3, 'cols' =>
30));
$f =
new TextField('mindatechange', T_('Minimum notice for booking change (hours)'));
$f->defaultValue =
$conf->value('instruments', 'usualmindatechange');
$f->isValidTest =
'is_number';
$f =
new TextField('supervisors', T_('Instrument supervisors'), T_('comma separated list of usernames'));
$f =
new CheckBox('emailonbooking', T_('Email supervisors when booking'));
//now edit the time slot representation fields
//first construct a timeslot field from the submitted data, then do the sync
if ($this->fields['timeslotpicture']->value !=
$newslotrule /*&& $this->id > -1*/) {
$this->log('Instrument::sync(): indulging in timeslotrule munging: <br />'.
$newslotrule .
'<br/>'.
$this->fields['timeslotpicture']->value);
$this->fields['timeslotpicture']->set($newslotrule);
$this->fields['timeslotpicture']->changed =
1;
// reflect back the data, this is good for checking that it's right, as TimeSlotRule
// will drop bits it doesn't understand or doesn't like.
//$this->_calcSlotRepresentation();
for ($day=
0; $day<
7; $day++
) {
$this->fields['tsr-'.
$day]->value =
'';
//preDump($this->_slotrule->slots[$day]);
foreach ($this->_slotrule->slots[$day] as $key =>
$slot) {
if (is_numeric($key) &&
$slot->picture !=
$prevpicture) {
$prevpicture =
$slot->picture;
$this->log('Added picture '.
$slot->picture);
$this->fields['tsr-'.
$day]->value .=
$slot->picture.
"\n";
for ($day=
0; $day<
7; $day++
) {
//preDump($this->fields['tsr-'.$day]->value);
$lines =
preg_grep('/^\s*$/', $lines, PREG_GREP_INVERT);
$rejects =
preg_grep('{^\d\d:\d\d\-\d\d:\d\d/(\d+|\*)(\-\d+%)?(,.+)?$}', $lines,PREG_GREP_INVERT);
if (count($rejects) >
0) {
//then this input is invalid
$this->fields['tsr-'.
$day]->isValid =
0;
$newslot .=
'['.
$day.
']<'.
join($lines,';').
'>';
$this->log('Calculated picture '.
$newslot);
Documentation generated on Tue, 06 Mar 2007 10:01:40 +0000 by phpDocumentor 1.3.0