- Update the copyright notices to use the correct year and not a non-ASCII symbol
[bugdar.git] / includes / api_automation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once ISSO . '/Api.php';
23 require_once('./includes/functions_datastore.php');
24
25 /**
26 * API: Automation
27 *
28 * @author Blue Static
29 * @copyright Copyright (c)2004 - 2008, Blue Static
30 * @package Bugdar
31 *
32 */
33 class AutomationAPI extends BSApi
34 {
35 /**
36 * Fields
37 * @var array
38 */
39 protected $fields = array(
40 'actionid' => array(TYPE_UINT, REQ_AUTO),
41 'name' => array(TYPE_STR, REQ_YES),
42 'description' => array(TYPE_STR, REQ_NO),
43 'fieldchanges' => array(TYPE_NONE, REQ_YES),
44 'comment' => array(TYPE_STR, REQ_NO)
45 );
46
47 /**
48 * Table
49 * @var string
50 */
51 protected $table = 'automation';
52
53 /**
54 * Table prefix
55 * @var string
56 */
57 protected $prefix = TABLE_PREFIX;
58
59 /**
60 * Post-insert
61 */
62 protected function post_insert()
63 {
64 build_automations();
65 }
66
67 /**
68 * Post-update
69 */
70 protected function post_update()
71 {
72 build_automations();
73 }
74
75 /**
76 * Post-delete
77 */
78 protected function post_delete()
79 {
80 build_automations();
81 }
82
83 /**
84 * Validate: actionid
85 */
86 protected function validate_actionid($field)
87 {
88 return $this->_verifyIsNotZero($field);
89 }
90
91 /**
92 * Validate: name
93 */
94 protected function validate_name($field)
95 {
96 return $this->_verifyIsNotEmpty($field);
97 }
98
99 /**
100 * Validate: fieldchanges
101 */
102 protected function validate_fieldchanges()
103 {
104 if (!is_array($this->values['fieldchanges']) || sizeof($this->values['fieldchanges']) != 2 || !is_array($this->values['fieldchanges']['custom']) || !is_array($this->values['fieldchanges']['builtin']))
105 {
106 return T('Invalid array type passed. The fieldchaneges array must be a two-dimensional array: array("builtin" => array("fieldname" => "newvalue" ...), "custom" => array("fieldname" => "fieldvalue" ...))');
107 }
108
109 if (sizeof($this->values['fieldchanges']['custom']) < 1 && sizeof($this->values['fieldchanges']['builtin']) < 1)
110 {
111 return T('You need to specify some fields to change.');
112 }
113
114 $this->values['fieldchanges'] = serialize($this->values['fieldchanges']);
115
116 return true;
117 }
118 }
119
120 ?>