3 require_once 'MTrack/Config.php';
4 class MTrackTicket_CustomField {
13 static function canonName($name) {
14 if (!preg_match("/^x_/", $name)) {
20 /** load the field definition from the configuration file */
21 static function load($name) {
22 if (!preg_match("/^x_[a-z_]+$/", $name)) {
23 throw new Exception("invalid field name $name");
26 $field = new MTrackTicket_CustomField;
29 $field->type = MTrackConfig::get('ticket.custom', "$name.type");
30 $field->label = MTrackConfig::get('ticket.custom', "$name.label");
31 $field->group = MTrackConfig::get('ticket.custom', "$name.group");
32 $field->order = (int)MTrackConfig::get('ticket.custom', "$name.order");
33 $field->default = MTrackConfig::get('ticket.custom', "$name.default");
34 $field->options = MTrackConfig::get('ticket.custom', "$name.options");
40 if (!preg_match("/^x_[a-z_]+$/", $this->name)) {
41 throw new Exception("invalid field name $this->name");
44 MTrackConfig::set('ticket.custom', "$name.type", $this->type);
45 MTrackConfig::set('ticket.custom', "$name.label", $this->label);
46 MTrackConfig::set('ticket.custom', "$name.group", $this->group);
47 MTrackConfig::set('ticket.custom', "$name.order", (int)$this->order);
48 MTrackConfig::set('ticket.custom', "$name.default", $this->default);
49 MTrackConfig::set('ticket.custom', "$name.options", $this->options);
52 function ticketData() {
53 /* compatible with the $FIELDSET data used in web/ticket.php */
55 'label' => $this->label,
56 'type' => $this->type,
59 if (strlen($this->default)) {
60 $data['default'] = $this->default;
63 switch ($this->type) {
67 $data['ownrow'] = true;
73 $options = array('' => ' --- ');
74 foreach (explode('|', $this->options) as $opt) {
75 $options[$opt] = $opt;
77 $data['options'] = $options;