3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2017 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 Prado::using('Application.Web.Portlets.DirectiveListTemplate');
24 Prado::using('Application.Web.Portlets.BConditional');
25 Prado::using('Application.Web.Portlets.DirectiveText');
27 class DirectiveMessages extends DirectiveListTemplate {
29 private $directive_types = array(
33 public $destination_simple = array(
41 public $destination_address = array(
51 private $messages_types = array(
68 public function loadConfig($sender, $param) {
69 $load_values = $this->getLoadValues();
70 $destinations = (array)$this->getData();
71 if (array_key_exists('Type', $destinations)) {
72 $destinations = array($destinations);
74 $directives = array();
75 for ($i = 0; $i < count($destinations); $i++) {
76 $is_address_type = in_array($destinations[$i]['Type'], $this->destination_address);
77 $directive_value = null;
78 if ($is_address_type && array_key_exists('Where', $destinations[$i])) {
79 $directive_value = implode(',', $destinations[$i]['Where']);
81 $this->setDirectiveName($destinations[$i]['Type']);
82 $directives[$i] = array(
83 'host' => $this->getHost(),
84 'component_type' => $this->getComponentType(),
85 'component_name' => $this->getComponentName(),
86 'resource_type' => $this->getResourceType(),
87 'resource_name' => $this->getResourceName(),
88 'directive_name' => $destinations[$i]['Type'],
89 'directive_value' => $directive_value,
90 'default_value' => false,
92 'label' => $destinations[$i]['Type'],
93 'field_type' => 'TextBox',
96 'parent_name' => __CLASS__,
97 'is_address_type' => $is_address_type,
98 'messages_types' => array()
100 $value_all = $value_not = null;
101 for ($j = 0; $j < count($this->messages_types); $j++) {
102 $value_all = in_array('!' . $this->messages_types[$j], $destinations[$i]['MsgTypes']);
103 $value_not = in_array($this->messages_types[$j], $destinations[$i]['MsgTypes']);
104 $directives[$i]['messages_types'][] = array(
105 'host' => $this->getHost(),
106 'component_type' => $this->getComponentType(),
107 'component_name' => $this->getComponentName(),
108 'resource_type' => $this->getResourceType(),
109 'resource_name' => $this->getResourceName(),
110 'directive_name' => $this->messages_types[$j],
111 'directive_value' => ($value_all || $value_not),
112 'default_value' => false,
114 'label' => $this->messages_types[$j],
115 'field_type' => 'Messages',
116 'data' => $destinations[$i]['Type'],
119 'parent_name' => __CLASS__
123 $this->RepeaterMessages->dataSource = $directives;
124 $this->RepeaterMessages->dataBind();
127 public function getDirectiveValue() {
129 $controls = $this->RepeaterMessages->getControls();
130 for ($i = 0; $i < $controls->count(); $i++) {
131 $directive_values = array();
132 $where_control = $controls->itemAt($i)->findControlsByType('DirectiveText');
133 if (count($where_control) === 1 && $where_control[0]->getShow() === true) {
134 $directive_values = array($where_control[0]->getDirectiveValue());
136 $types_control = $controls->itemAt($i)->Types;
137 $types = $types_control->getDirectiveValues();
138 $directive_name = $types_control->getDirectiveName();
139 if (count($types) > 0 && count($directive_values) > 0) {
140 array_push($directive_values, '=');
142 array_push($directive_values, implode(', ', $types));
143 $directive_values = array_filter($directive_values);
144 if (count($directive_values) === 0) {
147 $values[$directive_name] = implode(' ', $directive_values);
150 if (count($values) > 1) {
151 // multiple messages values
154 // single messages value
155 $ret = implode('', array_values($values));
160 public function getDirectiveData() {
162 $controls = $this->RepeaterMessages->getControls();
163 for ($i = 0; $i < $controls->count(); $i++) {
164 $directive_values = array();
165 $where_control = $controls->itemAt($i)->findControlsByType('DirectiveText');
166 if (count($where_control) === 1 && $where_control[0]->getShow() === true) {
167 $directive_values['Where'] = array($where_control[0]->getDirectiveValue());
169 $types_control = $controls->itemAt($i)->Types;
170 $directive_values['MsgTypes'] = $types_control->getDirectiveValues();
171 $directive_values['Type'] = $types_control->getDirectiveName();
172 array_push($values, $directive_values);
177 public function createDirectiveListElement($sender, $param) {
178 for ($i = 0; $i < count($this->directive_types); $i++) {
179 $control = $this->getChildControl($param->Item, $this->directive_types[$i]);
180 if (is_object($control)) {
181 $control->setHost($param->Item->DataItem['host']);
182 $control->setComponentType($param->Item->DataItem['component_type']);
183 $control->setComponentName($param->Item->DataItem['component_name']);
184 $control->setResourceType($param->Item->DataItem['resource_type']);
185 $control->setResourceName($param->Item->DataItem['resource_name']);
186 $control->setDirectiveName($param->Item->DataItem['directive_name']);
187 $control->setDirectiveValue($param->Item->DataItem['directive_value']);
188 $control->setDefaultValue($param->Item->DataItem['default_value']);
189 $control->setRequired($param->Item->DataItem['required']);
190 $control->setLabel($param->Item->DataItem['label']);
191 $control->setInConfig($param->Item->DataItem['in_config']);
192 $control->setShow($param->Item->DataItem['is_address_type']);
193 $control->setParentName($param->Item->DataItem['parent_name']);
197 $param->Item->Types->setData($param->Item->DataItem['messages_types']);
198 $param->Item->Types->setDirectiveName($param->Item->DataItem['directive_name']);
201 public function loadMessageTypes($sender, $param) {
202 $param->Item->Types->loadConfig();
205 public function newMessagesDirective($sender, $param) {
206 $data = $this->getDirectiveData();
207 $msg_type = $sender->getID();
208 array_push($data, array('Type' => $msg_type, 'MsgTypes' => array()));
209 $data = (object)$data;
210 $this->setData($data);
211 $this->loadConfig(null, null);