summaryrefslogtreecommitdiffstats
path: root/application/modules/dev/forms/FilterEntriesAdd.php
blob: d196cc95aa90e99d7feaa0a209a07a4af9f64d87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
 * This program is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your suggestions, praise, or complaints to feedback@openslx.org
 *
 * General information about OpenSLX can be found at http://openslx.org/
 */

class dev_Form_FilterEntriesAdd extends Zend_Form
{
	private $filterID = 0;

    public function init()
    {
		$this->setName("Add Filterentry");
		$this->setMethod('post');
		$this->setAttrib('id','filterentryform');
		#print_a($this->data);

		try{		
			$filtertypemapper = new Application_Model_FilterTypeMapper();
	       	$filtertype = $filtertypemapper->fetchAll();
		
		$filtertypes = $this->createElement('select','filtertypeID');
        $filtertypes ->setLabel('Type:');
        $filtertypes ->setAttrib('id','filtertype');
        $filtertypes->addMultiOption('','');
		foreach($filtertype as $f){
			$filtertypes->addMultiOption($f->getID(),$f->getFiltertypename());
		}
		$filterentry = $filtertypes->getMultiOption($this->data['filtertypeID']);
		$filterentryID = $this->data['filtertypeID'];
		}catch (Zend_Exception $e) {  
			echo "Error message 1: " . $e->getMessage() . "\n";
		}
		switch($filterentryID){
			default:
				$desc = "Select the filtertype";
				$label1 = 'Value 1:';
				$label2 = 'Value 2:';
				break;
			case "1":
				$desc = "You can set one IP or an IP-Range";
				$label1 = 'Start:';
				$label2 = 'End:';
				break;
			case "2":
				$desc = "You can set one Mac-Adress or an Mac-Range";
				$label1 = 'Start:';
				$label2 = 'End:';
				break;
			case "3":
				$desc = "Select your Pool";
				$label1 = 'PoolID:';
				break;
			case "4":
				$desc = "Select your BootIso";
				$label1 = 'BootIsoID:';
				break;
			case "5":
				$desc = "Select a Membership";
				$label1 = 'Membership:';
				break;
			case "6":
				$desc = "Select a Group";
				$label1 = 'Group:';
				break;
			case "7":
				$desc = "Specify a time-range";
				$label1 = 'Start:';
				$label2 = 'End:';
				break;
			case "8":
				$desc = "Select a Client";
				$label1 = 'Client:';
				break;
			case "9":
				$desc = "Define a Hardwarehash";
				$label1 = 'Hardwarehash:';
				break;
			case "10":
				$desc = "Specify the Weekday (Monday:1, Tuesday:2 ... Sunday:7) or a range";
				$label1 = 'Start Day:';
				$label2 = 'End Day:';
				break;
			case "11":
				$desc = "Specify the date or a day range of the filter";
				$label1 = 'Start Date:';
				$label2 = 'End Date:';
				break;
		}
		$filtertypes->setDescription($desc);
		$this->addElement($filtertypes);    
		
		$this->addElement('text', 'filtervalue', array(
			'label' => $label1,
			'id' => 'val1'
		));
		
		if(!in_array($filterentryID,array(3,4,5,6,8,9))){
			$this->addElement('text', 'filtervalue2', array(
				'label' => $label2,
				'id' => 'val2'
			));
		}

        $this->addElement('submit', 'add', array(
            'required' => false,
            'ignore'   => true,
            'label'    => $this->buttontext,
        ));  	 
        
        $this->addElement('button', 'Cancel', array(
            'onclick' => 'self.location="/filter"'
        ));  
        
         $this->addElement('hidden', 'filterID', array(
            'value' => $this->filterID
        ));  
		
	
    }

	private $buttontext = 'Save';
	function setButtontext($v){
		$this->buttontext = $v;
	}
	private $data ;
	function setData($v){
		$this->data = $v;
	}
	function setFilterID($v){
		$this->filterID = $v;
	}
}

?>
<script type="text/javascript">
	$('#filtertype').change(function(){
		//alert($("#filtertype option:selected").val());
		$('#filterentryform').submit();
	});
	$('#val1').focusout(function(){
		if($("#filtertype option:selected").val() == 1 && $('#val2').val() == ""){
			$('#val2').val($('#val1').val());
		}
		if($("#filtertype option:selected").val() == 2 && $('#val2').val() == ""){
			$('#val2').val($('#val1').val());
		}
	});
</script>