diff --git a/include/class.forms.php b/include/class.forms.php index e3791044bf08d7cf4148a116cf9dcb65611f33c7..6e7de311d7381fca72bc53d1468d08fc82240d9f 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -3201,4 +3201,193 @@ class VisibilityConstraint { } } +class AssignmentForm extends Form { + + static $id = 'assign'; + var $_assignee = null; + + function __construct($source=null, $options=array()) { + parent::__construct($source, $options); + } + + function getFields() { + + if ($this->fields) + return $this->fields; + + $fields = array( + 'assignee' => new AssigneeField(array( + 'id'=>1, + 'label' => __('Assignee'), + 'flags' => hexdec(0X450F3), + 'required' => true, + 'validator-error' => __('Assignee selection required'), + ) + ), + 'comments' => new TextareaField(array( + 'id' => 2, + 'label'=> '', + 'required'=>false, + 'default'=>'', + 'configuration' => array( + 'html' => true, + 'size' => 'large', + 'placeholder' => __('Optional reason for the assignment'), + ), + ) + ), + ); + + $this->setFields($fields); + + return $this->fields; + } + + function isValid() { + + if (!parent::isValid()) + return false; + + // Do additional assignment validation + if (!($assignee = $this->getAssignee())) { + $this->getField('assignee')->addError( + __('Unknown assignee')); + } elseif ($assignee instanceof Staff) { + // Make sure the agent is available + if (!$assignee->isAvailable()) + $this->getField('assignee')->addError( + __('Agent is unavailable for assignment') + ); + } + + return !$this->errors(); + } + + function getClean() { + return parent::getClean(); + } + + function render($options) { + + switch(strtolower($options['template'])) { + case 'simple': + $inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php'; + break; + default: + throw new Exception(sprintf(__('%s: Unknown template style %s'), + 'FormUtils', $options['template'])); + } + + $form = $this; + include $inc; + } + + function getAssignee() { + + if (!isset($this->_assignee)) { + $value = $this->getField('assignee')->getClean(); + if ($value[0] == 's') + $this->_assignee = Staff::lookup(substr($value, 1)); + elseif ($value[0] == 't') + $this->_assignee = Team::lookup(substr($value, 1)); + } + + return $this->_assignee; + } + + function assigneeCriteria() { + $dept = $this->id; + return function () use($dept) { + return array('dept_id' =>$dept); + }; + } +} + +class TransferForm extends Form { + + static $id = 'transfer'; + var $_dept = null; + + function __construct($source=null, $options=array()) { + parent::__construct($source, $options); + } + + function getFields() { + + if ($this->fields) + return $this->fields; + + $fields = array( + 'dept' => new DepartmentField(array( + 'id'=>1, + 'label' => __('Department'), + 'flags' => hexdec(0X450F3), + 'required' => true, + 'validator-error' => __('Department selection required'), + ) + ), + 'comments' => new TextareaField(array( + 'id' => 2, + 'label'=> '', + 'required'=>false, + 'default'=>'', + 'configuration' => array( + 'html' => true, + 'size' => 'large', + 'placeholder' => __('Optional reason for the transfer'), + ), + ) + ), + ); + + $this->setFields($fields); + + return $this->fields; + } + + function isValid() { + + if (!parent::isValid()) + return false; + + // Do additional validations + if (!($dept = $this->getDept())) + $this->getField('dept')->addError( + __('Unknown department')); + + return !$this->errors(); + } + + function getClean() { + return parent::getClean(); + } + + function render($options) { + + switch(strtolower($options['template'])) { + case 'simple': + $inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php'; + break; + default: + throw new Exception(sprintf(__('%s: Unknown template style %s'), + get_class(), $options['template'])); + } + + $form = $this; + include $inc; + + } + + function getDept() { + + if (!isset($this->_dept)) { + if (($id = $this->getField('dept')->getClean())) + $this->_dept = Dept::lookup($id); + } + + return $this->_dept; + } +} + + ?>