-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployee.module
218 lines (183 loc) · 5.29 KB
/
employee.module
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
require_once ('employee.theme.inc');
function employee_help($path, $arg) {
switch ($path) {
case "admin/help#employee":
return '<p>' . t("Displays links to employee") . '</p>';
break;
}
}
function employee_list() {
// select all rows from books table
$query = db_select('employee_tb', 'tr')
->fields('tr');
$result = $query->execute();
$output = theme('employee_list', array('data'=> $result));
return $output;
}
/**
* Implements hook_menu().
*/
function employee_menu() {
$items = array();
$items['employee1'] = array(
'title' => 'Employee', //page title
'description' => 'Employee Information', //description show when mouse hover on link
'page callback' => 'employee_list', //callback function which is invoked when menu item is called.
'access callback' => true, //any user can access this page
);
$items['employee/add'] = array(
'title' => 'Add employee',
'page callback' => 'drupal_get_form',
'page arguments' => array('employee_add'),
'access arguments' => array('access page manager'),
'expanded' => TRUE,
);
$items['employee/edit'] = array(
'title' => 'Edit Page',
'page callback' => 'drupal_get_form',
'page arguments' => array('employee_edit'),
'access arguments' => array('access page manager'),
'expanded' => FALSE,
);
$items['employee/delete'] = array(
'title' => 'Delete Page',
'page callback' => 'employee_delete',
'access arguments' => array('access page manager'),
'expanded' => FALSE,
);
$items['employee/add'] = array(
'title' => 'Add employee',
'page callback' => 'drupal_get_form',
'page arguments' => array('employee_form'),
'access arguments' => array('access page manager'),
'expanded' => TRUE,
);
return $items;
}
function employee_search($form, &$form_submit){
$form['name'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Search',
);
return $form;
}
function employee_search_submit($form, &$form_state){
//kpr($form);exit;
$name = $form_state['values']['name'];
// if(isset($_GET['name']) && !empty($_GET['name'])){
// $result = db_query("SELECT * FROM employee WHERE name = {$_GET[$name]}");
// }
drupal_set_message(t('Search submitted successfully.' .$name));
// $form_state['redirect'] = 'employee';
}
// function display_employee_form()
// {
// return drupal_get_form(employee_form);
// }
function employee_delete(){
$result = db_query("DELETE FROM employee_tb where emp_id={$_GET['emp_id']}");
header("Location: employee");
}
function employee_edit($form, &$form_submit){
if(isset($_GET['emp_id']) && !empty($_GET['emp_id'])){
$result = db_query("SELECT * FROM employee_tb WHERE emp_id = {$_GET['emp_id']}");
$row = array();
foreach($result as $record){
$row = (array)$record;
}
}
$form['id'] = array(
'#value' => $row['emp_id'],
'#type' => 'hidden',
);
$form['name'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
'#default_value' => $row['emp_name'],
);
$form['email'] = array(
'#title' => t('Email Address'),
'#type' => 'textfield',
'#default_value' => $row['emp_email'],
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
//kpr($form);
return $form;
}
function employee_edit_submit($form, &$form_state){
//kpr($form);exit;
$name = $form_state['values']['name'];
$email = $form_state['values']['email'];
$id = $form_state['values']['emp_id'];
$result = db_query("UPDATE employee_tb SET emp_name='{$name}', emp_email='{$email}' WHERE emp_id = {$id}");
$form_state['redirect'] = 'employee';
}
function employee_form($form, &$form_state){
$form = array();
$form['ajax_markup'] = array(
'#type' => 'markup',
'#prefix' => '
<div class="row">
<div class="container">
<div class="col-sm-6">
<span id="error"></span>',
'#markup' => '',
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => 'Name',
'#size' => 40,
'#maxlength' =>120,
'#required' => true,
'#attributes' => array(
'placeholder' => t('Name (Required)'),
),
);
$form['email'] = array(
'#type' => 'textfield',
'#title' => 'Email address',
'#size' => 40,
'#maxlength' =>120,
'#required' => true,
'#attributes' => array(
'placeholder' => t('Email (Required)'),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
// '#ajax' => array(
// 'callback' => 'employee_send_message',
// 'wrapper' => 'error',
// 'method' => 'html',
// 'effect' => 'fade',
// ),
);
$form['#suffix'] = '</div></div></div>';
return $form;
}
function employee_form_validate($form, &$form_state) {
$email = $form_state['values']['email'];
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
form_set_error('email', t('Please enter valid email address'));
return FALSE;
}
return TRUE;
}
function employee_form_submit($form, &$form_state){
//kpr($form);exit;
if (!form_get_errors()) {
$name = $form_state['values']['name'];
$email = $form_state['values']['email'];
$result = db_query("INSERT INTO employee_tb (emp_name, emp_email) VALUES ('{$name}', '{$email}')");
$form_state['redirect'] = 'employee';
}
}