@@ -242,20 +242,20 @@ |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | function ip_is_private($ip) { |
245 | - $safe_ip = array( |
|
246 | - $this->config->item('safeipone'), |
|
247 | - $this->config->item('safeiptwo'), |
|
248 | - $this->config->item('safeipthree'), |
|
249 | - $this->config->item('safeipfour'), |
|
250 | - $this->config->item('safeipfive'), |
|
251 | - $this->config->item('safeipsix'), |
|
252 | - $this->config->item('safeipseven'), |
|
253 | - $this->config->item('safeipeight'), |
|
254 | - $this->config->item('safeipnine'), |
|
255 | - $this->config->item('safeipten'), |
|
256 | - ); |
|
245 | + $safe_ip = array( |
|
246 | + $this->config->item('safeipone'), |
|
247 | + $this->config->item('safeiptwo'), |
|
248 | + $this->config->item('safeipthree'), |
|
249 | + $this->config->item('safeipfour'), |
|
250 | + $this->config->item('safeipfive'), |
|
251 | + $this->config->item('safeipsix'), |
|
252 | + $this->config->item('safeipseven'), |
|
253 | + $this->config->item('safeipeight'), |
|
254 | + $this->config->item('safeipnine'), |
|
255 | + $this->config->item('safeipten'), |
|
256 | + ); |
|
257 | 257 | |
258 | - if (in_array($_SERVER['REMOTE_ADDR'], $safe_ip)) { |
|
258 | + if (in_array($_SERVER['REMOTE_ADDR'], $safe_ip)) { |
|
259 | 259 | return true; |
260 | 260 | } else { |
261 | 261 | return false; |
@@ -93,16 +93,16 @@ discard block |
||
93 | 93 | |
94 | 94 | public function check_status() { |
95 | 95 | $this->db->where('requester_un', $_SESSION['username']) |
96 | - ->or_where('staff_involved_un', $_SESSION['username']) |
|
97 | - ->or_where('staff_involved_un2', $_SESSION['ldap']['full_name']) |
|
98 | - ->or_where('staff_involved_un3', $_SESSION['ldap']['full_name']) |
|
99 | - ->or_where('staff_involved_un4', $_SESSION['ldap']['full_name']) |
|
100 | - ->or_where('staff_involved_un5', $_SESSION['ldap']['full_name']) |
|
101 | - ->or_where('staff_involved_un6', $_SESSION['ldap']['full_name']) |
|
102 | - ->or_where('staff_involved_un7', $_SESSION['ldap']['full_name']) |
|
103 | - ->or_where('staff_involved_un8', $_SESSION['ldap']['full_name']) |
|
104 | - ->or_where('staff_involved_un9', $_SESSION['ldap']['full_name']) |
|
105 | - ->or_where('staff_involved_un10', $_SESSION['ldap']['full_name']); |
|
96 | + ->or_where('staff_involved_un', $_SESSION['username']) |
|
97 | + ->or_where('staff_involved_un2', $_SESSION['ldap']['full_name']) |
|
98 | + ->or_where('staff_involved_un3', $_SESSION['ldap']['full_name']) |
|
99 | + ->or_where('staff_involved_un4', $_SESSION['ldap']['full_name']) |
|
100 | + ->or_where('staff_involved_un5', $_SESSION['ldap']['full_name']) |
|
101 | + ->or_where('staff_involved_un6', $_SESSION['ldap']['full_name']) |
|
102 | + ->or_where('staff_involved_un7', $_SESSION['ldap']['full_name']) |
|
103 | + ->or_where('staff_involved_un8', $_SESSION['ldap']['full_name']) |
|
104 | + ->or_where('staff_involved_un9', $_SESSION['ldap']['full_name']) |
|
105 | + ->or_where('staff_involved_un10', $_SESSION['ldap']['full_name']); |
|
106 | 106 | $query = $this->db->get('room_move'); |
107 | 107 | return $query->result_array(); |
108 | 108 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | public function cancel($id) { |
131 | 131 | |
132 | 132 | $this->db->where('id', $id); |
133 | - $this->db->from('room_move'); |
|
133 | + $this->db->from('room_move'); |
|
134 | 134 | $data = array( |
135 | 135 | 'status' => '4', |
136 | 136 | 'canceled_by' => $_SESSION['ldap']['full_name'], |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | public function eh_reject($id) { |
143 | 143 | |
144 | 144 | $this->db->where('id', $id); |
145 | - $this->db->from('room_move'); |
|
145 | + $this->db->from('room_move'); |
|
146 | 146 | $data = array( |
147 | 147 | 'status' => '2', |
148 | 148 | 'estates_at' => date("Y-m-d H:i:s", time()), |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | public function eh_approve($id) { |
155 | 155 | |
156 | 156 | $this->db->where('id', $id); |
157 | - $this->db->from('room_move'); |
|
157 | + $this->db->from('room_move'); |
|
158 | 158 | $data = array( |
159 | 159 | 'status' => '1', |
160 | 160 | 'estates_at' => date("Y-m-d H:i:s", time()), |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | public function cs_reject($id) { |
168 | 168 | |
169 | 169 | $this->db->where('id', $id); |
170 | - $this->db->from('room_move'); |
|
170 | + $this->db->from('room_move'); |
|
171 | 171 | $data = array( |
172 | 172 | 'status' => '3', |
173 | 173 | 'cs_at' => date("Y-m-d H:i:s", time()), |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | public function cs_approve($id) { |
180 | 180 | |
181 | 181 | $this->db->where('id', $id); |
182 | - $this->db->from('room_move'); |
|
182 | + $this->db->from('room_move'); |
|
183 | 183 | $data = array( |
184 | 184 | 'status' => '5', |
185 | 185 | 'cs_at' => date("Y-m-d H:i:s", time()), |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | public function cs_complete($id) { |
193 | 193 | |
194 | 194 | $this->db->where('id', $id); |
195 | - $this->db->from('room_move'); |
|
195 | + $this->db->from('room_move'); |
|
196 | 196 | $data = array( |
197 | 197 | 'status' => '6', |
198 | 198 | 'completed_at' => date("Y-m-d H:i:s", time()), |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | $this->db->select('faculty'); |
57 | 57 | $this->db->where('cat_id', $faculty); |
58 | - $this->db->from('faculty'); |
|
58 | + $this->db->from('faculty'); |
|
59 | 59 | return $this->db->get()->result_array(); |
60 | 60 | } |
61 | 61 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | $this->db->select('subfaculty'); |
65 | 65 | $this->db->where('cat_key', $department); |
66 | - $this->db->from('facultysub'); |
|
66 | + $this->db->from('facultysub'); |
|
67 | 67 | return $this->db->get()->result_array(); |
68 | 68 | } |
69 | 69 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | public function cancel($id) { |
71 | 71 | |
72 | 72 | $this->db->where('id', $id); |
73 | - $this->db->from('private_drive'); |
|
73 | + $this->db->from('private_drive'); |
|
74 | 74 | $data = array( |
75 | 75 | 'status' => '5', |
76 | 76 | 'canceled_by' => $_SESSION['ldap']['full_name'], |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function fh_reject($id) { |
83 | 83 | |
84 | 84 | $this->db->where('id', $id); |
85 | - $this->db->from('private_drive'); |
|
85 | + $this->db->from('private_drive'); |
|
86 | 86 | $data = array( |
87 | 87 | 'status' => '3', |
88 | 88 | 'approved_at' => date("Y-m-d H:i:s", time()), |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | public function fh_approve($id) { |
94 | 94 | |
95 | 95 | $this->db->where('id', $id); |
96 | - $this->db->from('private_drive'); |
|
96 | + $this->db->from('private_drive'); |
|
97 | 97 | $data = array( |
98 | 98 | 'status' => '1', |
99 | 99 | 'approved_at' => date("Y-m-d H:i:s", time()), |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | public function cs_reject($id) { |
106 | 106 | |
107 | 107 | $this->db->where('id', $id); |
108 | - $this->db->from('private_drive'); |
|
108 | + $this->db->from('private_drive'); |
|
109 | 109 | $data = array( |
110 | 110 | 'status' => '4', |
111 | 111 | 'actioned_at' => date("Y-m-d H:i:s", time()), |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | public function cs_approve($id) { |
118 | 118 | |
119 | 119 | $this->db->where('id', $id); |
120 | - $this->db->from('private_drive'); |
|
120 | + $this->db->from('private_drive'); |
|
121 | 121 | $data = array( |
122 | 122 | 'status' => '2', |
123 | 123 | 'actioned_at' => date("Y-m-d H:i:s", time()), |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | public function approve($id) { |
55 | 55 | |
56 | 56 | $this->db->where('id', $id); |
57 | - $this->db->from('ownership'); |
|
57 | + $this->db->from('ownership'); |
|
58 | 58 | $data = array( |
59 | 59 | 'status' => '3', |
60 | 60 | 'transfer' => date("Y-m-d H:i:s", time()), |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function reject($id) { |
68 | 68 | |
69 | 69 | $this->db->where('id', $id); |
70 | - $this->db->from('ownership'); |
|
70 | + $this->db->from('ownership'); |
|
71 | 71 | $data = array( |
72 | 72 | 'status' => '2', |
73 | 73 | 'transfer' => date("Y-m-d H:i:s", time()), |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function cancel($id) { |
81 | 81 | |
82 | 82 | $this->db->where('id', $id); |
83 | - $this->db->from('ownership'); |
|
83 | + $this->db->from('ownership'); |
|
84 | 84 | $data = array( |
85 | 85 | 'status' => '4', |
86 | 86 | ); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | public function terms($id) { |
92 | 92 | |
93 | 93 | $this->db->where('id', $id); |
94 | - $this->db->from('ownership'); |
|
94 | + $this->db->from('ownership'); |
|
95 | 95 | $data = array( |
96 | 96 | 'status' => '1', |
97 | 97 | 'policy_accepted' => date("Y-m-d H:i:s", time()), |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | public function cancel($id) { |
147 | 147 | |
148 | 148 | $this->db->where('id', $id); |
149 | - $this->db->from('temporary_account'); |
|
149 | + $this->db->from('temporary_account'); |
|
150 | 150 | $data = array( |
151 | 151 | 'status' => '3', |
152 | 152 | ); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | public function reject($id) { |
157 | 157 | |
158 | 158 | $this->db->where('id', $id); |
159 | - $this->db->from('temporary_account'); |
|
159 | + $this->db->from('temporary_account'); |
|
160 | 160 | $data = array( |
161 | 161 | 'status' => '2', |
162 | 162 | 'status_at' => date("Y-m-d H:i:s", time()), |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | public function approve($id) { |
169 | 169 | |
170 | 170 | $this->db->where('id', $id); |
171 | - $this->db->from('temporary_account'); |
|
171 | + $this->db->from('temporary_account'); |
|
172 | 172 | $data = array( |
173 | 173 | 'status' => '1', |
174 | 174 | 'status_at' => date("Y-m-d H:i:s", time()), |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | public function created_account($id) { |
182 | 182 | |
183 | 183 | $this->db->where('id', $id); |
184 | - $this->db->from('temporary_account'); |
|
184 | + $this->db->from('temporary_account'); |
|
185 | 185 | $data = array( |
186 | 186 | 'created' => '1', |
187 | 187 | ); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class Status_model extends CI_Model { |
4 | 4 | |
5 | 5 | public function __construct() { |
6 | - parent::__construct(); |
|
6 | + parent::__construct(); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | public function view() { |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | $data = array( |
20 | 20 | 'id', 'name', 'status', 'url', 'auto_status' |
21 | - ); |
|
21 | + ); |
|
22 | 22 | |
23 | 23 | $query = $this->db->get('status'); |
24 | 24 | return $query->result_array(); |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | $data = array( |
60 | 60 | 'sid' => $service_id, |
61 | 61 | 'auto_status' => $service_status |
62 | - ); |
|
62 | + ); |
|
63 | 63 | |
64 | - return $this->db->insert('status_logs', $data); |
|
64 | + return $this->db->insert('status_logs', $data); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function percentage($sid) { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->db->where('sid', $sid); |
71 | 71 | $this->db->order_by('id', 'DESC'); |
72 | 72 | $this->db->limit('5000'); |
73 | - $this->db->from('status_logs'); |
|
73 | + $this->db->from('status_logs'); |
|
74 | 74 | $total = $this->db->get()->num_rows(); |
75 | 75 | |
76 | 76 | $this->db->select('sid'); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $this->db->where('auto_status', 1); |
79 | 79 | $this->db->order_by('id', 'DESC'); |
80 | 80 | $this->db->limit('5000'); |
81 | - $this->db->from('status_logs'); |
|
81 | + $this->db->from('status_logs'); |
|
82 | 82 | $up = $this->db->get()->num_rows(); |
83 | 83 | |
84 | 84 | if (empty($total)) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | $this->db->select('sid'); |
101 | 101 | $this->db->where('sid', $sid); |
102 | - $this->db->from('status_logs'); |
|
102 | + $this->db->from('status_logs'); |
|
103 | 103 | $this->db->delete(); |
104 | 104 | |
105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | $this->db->select(); |
110 | 110 | $this->db->where('id', $sid); |
111 | - $this->db->from('status'); |
|
111 | + $this->db->from('status'); |
|
112 | 112 | $query = $this->db->get(); |
113 | 113 | return $query->result_array(); |
114 | 114 | } |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | 'auto_status' => $status, |
130 | 130 | 'last_update' => date("Y-m-d H:i:s", time()), |
131 | 131 | 'by' => $username, |
132 | - ); |
|
132 | + ); |
|
133 | 133 | |
134 | 134 | $this->db->where('id', $id); |
135 | - return $this->db->update('status', $data); |
|
135 | + return $this->db->update('status', $data); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | public function create($name, $icon, $url, $category, $status) { |
@@ -146,21 +146,21 @@ discard block |
||
146 | 146 | 'auto_status' => $status, |
147 | 147 | 'last_update' => date("Y-m-d H:i:s", time()), |
148 | 148 | 'by' => $username, |
149 | - ); |
|
149 | + ); |
|
150 | 150 | |
151 | - return $this->db->insert('status', $data); |
|
151 | + return $this->db->insert('status', $data); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | public function delete($sid) { |
155 | 155 | |
156 | 156 | $this->db->select('sid'); |
157 | 157 | $this->db->where('sid', $sid); |
158 | - $this->db->from('status_logs'); |
|
158 | + $this->db->from('status_logs'); |
|
159 | 159 | $this->db->delete(); |
160 | 160 | |
161 | 161 | $this->db->select('id'); |
162 | 162 | $this->db->where('id', $sid); |
163 | - $this->db->from('status'); |
|
163 | + $this->db->from('status'); |
|
164 | 164 | $this->db->delete(); |
165 | 165 | |
166 | 166 | } |
@@ -34,429 +34,429 @@ discard block |
||
34 | 34 | */ |
35 | 35 | class grocery_CRUD_Field_Types |
36 | 36 | { |
37 | - /** |
|
38 | - * Gets the field types of the main table. |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function get_field_types() |
|
42 | - { |
|
43 | - if ($this->field_types !== null) { |
|
44 | - return $this->field_types; |
|
45 | - } |
|
46 | - |
|
47 | - $types = array(); |
|
48 | - foreach($this->basic_model->get_field_types_basic_table() as $field_info) |
|
49 | - { |
|
50 | - $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; |
|
51 | - |
|
52 | - $field_info->display_as = |
|
53 | - isset($this->display_as[$field_info->name]) ? |
|
54 | - $this->display_as[$field_info->name] : |
|
55 | - ucfirst(str_replace("_"," ",$field_info->name)); |
|
56 | - |
|
57 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) |
|
58 | - { |
|
59 | - $field_type = $this->change_field_type[$field_info->name]; |
|
60 | - |
|
61 | - if (isset($this->relation[$field_info->name])) { |
|
62 | - $field_info->crud_type = "relation_".$field_type->type; |
|
63 | - } |
|
64 | - elseif (isset($this->upload_fields[$field_info->name])) { |
|
65 | - $field_info->crud_type = "upload_file_".$field_type->type; |
|
66 | - } else { |
|
67 | - $field_info->crud_type = $field_type->type; |
|
68 | - $field_info->extras = $field_type->extras; |
|
69 | - } |
|
70 | - |
|
71 | - $real_type = $field_info->crud_type; |
|
72 | - } |
|
73 | - elseif(isset($this->relation[$field_info->name])) |
|
74 | - { |
|
75 | - $real_type = 'relation'; |
|
76 | - $field_info->crud_type = 'relation'; |
|
77 | - } |
|
78 | - elseif(isset($this->upload_fields[$field_info->name])) |
|
79 | - { |
|
80 | - $real_type = 'upload_file'; |
|
81 | - $field_info->crud_type = 'upload_file'; |
|
82 | - } |
|
83 | - else |
|
84 | - { |
|
85 | - $real_type = $this->get_type($field_info); |
|
86 | - $field_info->crud_type = $real_type; |
|
87 | - } |
|
88 | - |
|
89 | - switch ($real_type) { |
|
90 | - case 'text': |
|
91 | - if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) |
|
92 | - $field_info->extras = false; |
|
93 | - else |
|
94 | - $field_info->extras = 'text_editor'; |
|
95 | - break; |
|
96 | - |
|
97 | - case 'relation': |
|
98 | - case 'relation_readonly': |
|
99 | - $field_info->extras = $this->relation[$field_info->name]; |
|
100 | - break; |
|
101 | - |
|
102 | - case 'upload_file': |
|
103 | - case 'upload_file_readonly': |
|
104 | - $field_info->extras = $this->upload_fields[$field_info->name]; |
|
105 | - break; |
|
106 | - |
|
107 | - default: |
|
108 | - if(empty($field_info->extras)) |
|
109 | - $field_info->extras = false; |
|
110 | - break; |
|
111 | - } |
|
112 | - |
|
113 | - $types[$field_info->name] = $field_info; |
|
114 | - } |
|
115 | - |
|
116 | - if(!empty($this->relation_n_n)) |
|
117 | - { |
|
118 | - foreach($this->relation_n_n as $field_name => $field_extras) |
|
119 | - { |
|
120 | - $is_read_only = $this->change_field_type !== null |
|
121 | - && isset($this->change_field_type[$field_name]) |
|
122 | - && $this->change_field_type[$field_name]->type == 'readonly' |
|
123 | - ? true : false; |
|
124 | - $field_info = (object)array(); |
|
125 | - $field_info->name = $field_name; |
|
126 | - $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; |
|
127 | - $field_info->extras = $field_extras; |
|
128 | - $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; |
|
129 | - $field_info->display_as = |
|
130 | - isset($this->display_as[$field_name]) ? |
|
131 | - $this->display_as[$field_name] : |
|
132 | - ucfirst(str_replace("_"," ",$field_name)); |
|
133 | - |
|
134 | - $types[$field_name] = $field_info; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - if(!empty($this->add_fields)) |
|
139 | - foreach($this->add_fields as $field_object) |
|
140 | - { |
|
141 | - $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
142 | - |
|
143 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
144 | - { |
|
145 | - $extras = false; |
|
146 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
147 | - { |
|
148 | - $field_type = $this->change_field_type[$field_name]; |
|
149 | - $extras = $field_type->extras; |
|
150 | - } |
|
151 | - |
|
152 | - $field_info = (object)array( |
|
153 | - 'name' => $field_name, |
|
154 | - 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
155 | - $this->change_field_type[$field_name]->type : |
|
156 | - 'string', |
|
157 | - 'display_as' => isset($this->display_as[$field_name]) ? |
|
158 | - $this->display_as[$field_name] : |
|
159 | - ucfirst(str_replace("_"," ",$field_name)), |
|
160 | - 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, |
|
161 | - 'extras' => $extras |
|
162 | - ); |
|
163 | - |
|
164 | - $types[$field_name] = $field_info; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - if(!empty($this->edit_fields)) |
|
169 | - foreach($this->edit_fields as $field_object) |
|
170 | - { |
|
171 | - $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
172 | - |
|
173 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
174 | - { |
|
175 | - $extras = false; |
|
176 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
177 | - { |
|
178 | - $field_type = $this->change_field_type[$field_name]; |
|
179 | - $extras = $field_type->extras; |
|
180 | - } |
|
181 | - |
|
182 | - $field_info = (object)array( |
|
183 | - 'name' => $field_name, |
|
184 | - 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
185 | - $this->change_field_type[$field_name]->type : |
|
186 | - 'string', |
|
187 | - 'display_as' => isset($this->display_as[$field_name]) ? |
|
188 | - $this->display_as[$field_name] : |
|
189 | - ucfirst(str_replace("_"," ",$field_name)), |
|
190 | - 'required' => in_array($field_name,$this->required_fields) ? true : false, |
|
191 | - 'extras' => $extras |
|
192 | - ); |
|
193 | - |
|
194 | - $types[$field_name] = $field_info; |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - $this->field_types = $types; |
|
199 | - |
|
200 | - return $this->field_types; |
|
201 | - } |
|
202 | - |
|
203 | - public function get_primary_key() |
|
204 | - { |
|
205 | - return $this->basic_model->get_primary_key(); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Get the html input for the specific field with the |
|
210 | - * current value |
|
211 | - * |
|
212 | - * @param object $field_info |
|
213 | - * @param string $value |
|
214 | - * @return object |
|
215 | - */ |
|
216 | - protected function get_field_input($field_info, $value = null) |
|
217 | - { |
|
218 | - $real_type = $field_info->crud_type; |
|
219 | - |
|
220 | - $types_array = array( |
|
221 | - 'integer', |
|
222 | - 'text', |
|
223 | - 'true_false', |
|
224 | - 'string', |
|
225 | - 'date', |
|
226 | - 'datetime', |
|
227 | - 'enum', |
|
228 | - 'set', |
|
229 | - 'relation', |
|
230 | - 'relation_readonly', |
|
231 | - 'relation_n_n', |
|
232 | - 'upload_file', |
|
233 | - 'upload_file_readonly', |
|
234 | - 'hidden', |
|
235 | - 'password', |
|
236 | - 'readonly', |
|
237 | - 'dropdown', |
|
238 | - 'multiselect' |
|
239 | - ); |
|
240 | - |
|
241 | - if (in_array($real_type,$types_array)) { |
|
242 | - /* A quick way to go to an internal method of type $this->get_{type}_input . |
|
37 | + /** |
|
38 | + * Gets the field types of the main table. |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function get_field_types() |
|
42 | + { |
|
43 | + if ($this->field_types !== null) { |
|
44 | + return $this->field_types; |
|
45 | + } |
|
46 | + |
|
47 | + $types = array(); |
|
48 | + foreach($this->basic_model->get_field_types_basic_table() as $field_info) |
|
49 | + { |
|
50 | + $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; |
|
51 | + |
|
52 | + $field_info->display_as = |
|
53 | + isset($this->display_as[$field_info->name]) ? |
|
54 | + $this->display_as[$field_info->name] : |
|
55 | + ucfirst(str_replace("_"," ",$field_info->name)); |
|
56 | + |
|
57 | + if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) |
|
58 | + { |
|
59 | + $field_type = $this->change_field_type[$field_info->name]; |
|
60 | + |
|
61 | + if (isset($this->relation[$field_info->name])) { |
|
62 | + $field_info->crud_type = "relation_".$field_type->type; |
|
63 | + } |
|
64 | + elseif (isset($this->upload_fields[$field_info->name])) { |
|
65 | + $field_info->crud_type = "upload_file_".$field_type->type; |
|
66 | + } else { |
|
67 | + $field_info->crud_type = $field_type->type; |
|
68 | + $field_info->extras = $field_type->extras; |
|
69 | + } |
|
70 | + |
|
71 | + $real_type = $field_info->crud_type; |
|
72 | + } |
|
73 | + elseif(isset($this->relation[$field_info->name])) |
|
74 | + { |
|
75 | + $real_type = 'relation'; |
|
76 | + $field_info->crud_type = 'relation'; |
|
77 | + } |
|
78 | + elseif(isset($this->upload_fields[$field_info->name])) |
|
79 | + { |
|
80 | + $real_type = 'upload_file'; |
|
81 | + $field_info->crud_type = 'upload_file'; |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
85 | + $real_type = $this->get_type($field_info); |
|
86 | + $field_info->crud_type = $real_type; |
|
87 | + } |
|
88 | + |
|
89 | + switch ($real_type) { |
|
90 | + case 'text': |
|
91 | + if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) |
|
92 | + $field_info->extras = false; |
|
93 | + else |
|
94 | + $field_info->extras = 'text_editor'; |
|
95 | + break; |
|
96 | + |
|
97 | + case 'relation': |
|
98 | + case 'relation_readonly': |
|
99 | + $field_info->extras = $this->relation[$field_info->name]; |
|
100 | + break; |
|
101 | + |
|
102 | + case 'upload_file': |
|
103 | + case 'upload_file_readonly': |
|
104 | + $field_info->extras = $this->upload_fields[$field_info->name]; |
|
105 | + break; |
|
106 | + |
|
107 | + default: |
|
108 | + if(empty($field_info->extras)) |
|
109 | + $field_info->extras = false; |
|
110 | + break; |
|
111 | + } |
|
112 | + |
|
113 | + $types[$field_info->name] = $field_info; |
|
114 | + } |
|
115 | + |
|
116 | + if(!empty($this->relation_n_n)) |
|
117 | + { |
|
118 | + foreach($this->relation_n_n as $field_name => $field_extras) |
|
119 | + { |
|
120 | + $is_read_only = $this->change_field_type !== null |
|
121 | + && isset($this->change_field_type[$field_name]) |
|
122 | + && $this->change_field_type[$field_name]->type == 'readonly' |
|
123 | + ? true : false; |
|
124 | + $field_info = (object)array(); |
|
125 | + $field_info->name = $field_name; |
|
126 | + $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; |
|
127 | + $field_info->extras = $field_extras; |
|
128 | + $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; |
|
129 | + $field_info->display_as = |
|
130 | + isset($this->display_as[$field_name]) ? |
|
131 | + $this->display_as[$field_name] : |
|
132 | + ucfirst(str_replace("_"," ",$field_name)); |
|
133 | + |
|
134 | + $types[$field_name] = $field_info; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + if(!empty($this->add_fields)) |
|
139 | + foreach($this->add_fields as $field_object) |
|
140 | + { |
|
141 | + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
142 | + |
|
143 | + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
144 | + { |
|
145 | + $extras = false; |
|
146 | + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
147 | + { |
|
148 | + $field_type = $this->change_field_type[$field_name]; |
|
149 | + $extras = $field_type->extras; |
|
150 | + } |
|
151 | + |
|
152 | + $field_info = (object)array( |
|
153 | + 'name' => $field_name, |
|
154 | + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
155 | + $this->change_field_type[$field_name]->type : |
|
156 | + 'string', |
|
157 | + 'display_as' => isset($this->display_as[$field_name]) ? |
|
158 | + $this->display_as[$field_name] : |
|
159 | + ucfirst(str_replace("_"," ",$field_name)), |
|
160 | + 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, |
|
161 | + 'extras' => $extras |
|
162 | + ); |
|
163 | + |
|
164 | + $types[$field_name] = $field_info; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + if(!empty($this->edit_fields)) |
|
169 | + foreach($this->edit_fields as $field_object) |
|
170 | + { |
|
171 | + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
172 | + |
|
173 | + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
174 | + { |
|
175 | + $extras = false; |
|
176 | + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
177 | + { |
|
178 | + $field_type = $this->change_field_type[$field_name]; |
|
179 | + $extras = $field_type->extras; |
|
180 | + } |
|
181 | + |
|
182 | + $field_info = (object)array( |
|
183 | + 'name' => $field_name, |
|
184 | + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
185 | + $this->change_field_type[$field_name]->type : |
|
186 | + 'string', |
|
187 | + 'display_as' => isset($this->display_as[$field_name]) ? |
|
188 | + $this->display_as[$field_name] : |
|
189 | + ucfirst(str_replace("_"," ",$field_name)), |
|
190 | + 'required' => in_array($field_name,$this->required_fields) ? true : false, |
|
191 | + 'extras' => $extras |
|
192 | + ); |
|
193 | + |
|
194 | + $types[$field_name] = $field_info; |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + $this->field_types = $types; |
|
199 | + |
|
200 | + return $this->field_types; |
|
201 | + } |
|
202 | + |
|
203 | + public function get_primary_key() |
|
204 | + { |
|
205 | + return $this->basic_model->get_primary_key(); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Get the html input for the specific field with the |
|
210 | + * current value |
|
211 | + * |
|
212 | + * @param object $field_info |
|
213 | + * @param string $value |
|
214 | + * @return object |
|
215 | + */ |
|
216 | + protected function get_field_input($field_info, $value = null) |
|
217 | + { |
|
218 | + $real_type = $field_info->crud_type; |
|
219 | + |
|
220 | + $types_array = array( |
|
221 | + 'integer', |
|
222 | + 'text', |
|
223 | + 'true_false', |
|
224 | + 'string', |
|
225 | + 'date', |
|
226 | + 'datetime', |
|
227 | + 'enum', |
|
228 | + 'set', |
|
229 | + 'relation', |
|
230 | + 'relation_readonly', |
|
231 | + 'relation_n_n', |
|
232 | + 'upload_file', |
|
233 | + 'upload_file_readonly', |
|
234 | + 'hidden', |
|
235 | + 'password', |
|
236 | + 'readonly', |
|
237 | + 'dropdown', |
|
238 | + 'multiselect' |
|
239 | + ); |
|
240 | + |
|
241 | + if (in_array($real_type,$types_array)) { |
|
242 | + /* A quick way to go to an internal method of type $this->get_{type}_input . |
|
243 | 243 | * For example if the real type is integer then we will use the method |
244 | 244 | * $this->get_integer_input |
245 | 245 | * */ |
246 | - $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); |
|
247 | - } |
|
248 | - else |
|
249 | - { |
|
250 | - $field_info->input = $this->get_string_input($field_info,$value); |
|
251 | - } |
|
246 | + $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); |
|
247 | + } |
|
248 | + else |
|
249 | + { |
|
250 | + $field_info->input = $this->get_string_input($field_info,$value); |
|
251 | + } |
|
252 | 252 | |
253 | - return $field_info; |
|
254 | - } |
|
253 | + return $field_info; |
|
254 | + } |
|
255 | 255 | |
256 | - protected function change_list_value($field_info, $value = null) |
|
257 | - { |
|
258 | - $real_type = $field_info->crud_type; |
|
256 | + protected function change_list_value($field_info, $value = null) |
|
257 | + { |
|
258 | + $real_type = $field_info->crud_type; |
|
259 | + |
|
260 | + switch ($real_type) { |
|
261 | + case 'hidden': |
|
262 | + case 'invisible': |
|
263 | + case 'integer': |
|
264 | + |
|
265 | + break; |
|
266 | + case 'true_false': |
|
267 | + if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { |
|
268 | + $value = $field_info->extras[$value]; |
|
269 | + } else if(isset($this->default_true_false_text[$value])) { |
|
270 | + $value = $this->default_true_false_text[$value]; |
|
271 | + } |
|
272 | + break; |
|
273 | + case 'string': |
|
274 | + $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
275 | + break; |
|
276 | + case 'text': |
|
277 | + $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); |
|
278 | + break; |
|
279 | + case 'date': |
|
280 | + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
281 | + { |
|
282 | + list($year,$month,$day) = explode("-",$value); |
|
259 | 283 | |
260 | - switch ($real_type) { |
|
261 | - case 'hidden': |
|
262 | - case 'invisible': |
|
263 | - case 'integer': |
|
284 | + $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); |
|
285 | + } |
|
286 | + else |
|
287 | + { |
|
288 | + $value = ''; |
|
289 | + } |
|
290 | + break; |
|
291 | + case 'datetime': |
|
292 | + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') |
|
293 | + { |
|
294 | + list($year,$month,$day) = explode("-",$value); |
|
295 | + list($hours,$minutes) = explode(":",substr($value,11)); |
|
264 | 296 | |
265 | - break; |
|
266 | - case 'true_false': |
|
267 | - if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { |
|
268 | - $value = $field_info->extras[$value]; |
|
269 | - } else if(isset($this->default_true_false_text[$value])) { |
|
270 | - $value = $this->default_true_false_text[$value]; |
|
271 | - } |
|
272 | - break; |
|
273 | - case 'string': |
|
274 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
275 | - break; |
|
276 | - case 'text': |
|
277 | - $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); |
|
278 | - break; |
|
279 | - case 'date': |
|
280 | - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
281 | - { |
|
282 | - list($year,$month,$day) = explode("-",$value); |
|
283 | - |
|
284 | - $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); |
|
285 | - } |
|
286 | - else |
|
287 | - { |
|
288 | - $value = ''; |
|
289 | - } |
|
290 | - break; |
|
291 | - case 'datetime': |
|
292 | - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') |
|
293 | - { |
|
294 | - list($year,$month,$day) = explode("-",$value); |
|
295 | - list($hours,$minutes) = explode(":",substr($value,11)); |
|
296 | - |
|
297 | - $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); |
|
298 | - } |
|
299 | - else |
|
300 | - { |
|
301 | - $value = ''; |
|
302 | - } |
|
303 | - break; |
|
304 | - case 'enum': |
|
305 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
306 | - break; |
|
297 | + $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); |
|
298 | + } |
|
299 | + else |
|
300 | + { |
|
301 | + $value = ''; |
|
302 | + } |
|
303 | + break; |
|
304 | + case 'enum': |
|
305 | + $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
306 | + break; |
|
307 | + |
|
308 | + case 'multiselect': |
|
309 | + $value_as_array = array(); |
|
310 | + foreach(explode(",",$value) as $row_value) |
|
311 | + { |
|
312 | + $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; |
|
313 | + } |
|
314 | + $value = implode(",",$value_as_array); |
|
315 | + break; |
|
307 | 316 | |
308 | - case 'multiselect': |
|
309 | - $value_as_array = array(); |
|
310 | - foreach(explode(",",$value) as $row_value) |
|
311 | - { |
|
312 | - $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; |
|
313 | - } |
|
314 | - $value = implode(",",$value_as_array); |
|
315 | - break; |
|
317 | + case 'relation_n_n': |
|
318 | + $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); |
|
319 | + break; |
|
316 | 320 | |
317 | - case 'relation_n_n': |
|
318 | - $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); |
|
319 | - break; |
|
321 | + case 'password': |
|
322 | + $value = '******'; |
|
323 | + break; |
|
320 | 324 | |
321 | - case 'password': |
|
322 | - $value = '******'; |
|
323 | - break; |
|
325 | + case 'dropdown': |
|
326 | + $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; |
|
327 | + break; |
|
324 | 328 | |
325 | - case 'dropdown': |
|
326 | - $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; |
|
327 | - break; |
|
329 | + case 'upload_file': |
|
330 | + if(empty($value)) |
|
331 | + { |
|
332 | + $value = ""; |
|
333 | + } |
|
334 | + else |
|
335 | + { |
|
336 | + $is_image = !empty($value) && |
|
337 | + ( substr($value,-4) == '.jpg' |
|
338 | + || substr($value,-4) == '.png' |
|
339 | + || substr($value,-5) == '.jpeg' |
|
340 | + || substr($value,-4) == '.gif' |
|
341 | + || substr($value,-5) == '.tiff') |
|
342 | + ? true : false; |
|
343 | + |
|
344 | + $file_url = base_url().$field_info->extras->upload_path."/$value"; |
|
345 | + |
|
346 | + $file_url_anchor = '<a href="'.$file_url.'"'; |
|
347 | + if($is_image) |
|
348 | + { |
|
349 | + $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; |
|
350 | + } |
|
351 | + else |
|
352 | + { |
|
353 | + $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); |
|
354 | + } |
|
355 | + $file_url_anchor .= '</a>'; |
|
328 | 356 | |
329 | - case 'upload_file': |
|
330 | - if(empty($value)) |
|
331 | - { |
|
332 | - $value = ""; |
|
333 | - } |
|
334 | - else |
|
335 | - { |
|
336 | - $is_image = !empty($value) && |
|
337 | - ( substr($value,-4) == '.jpg' |
|
338 | - || substr($value,-4) == '.png' |
|
339 | - || substr($value,-5) == '.jpeg' |
|
340 | - || substr($value,-4) == '.gif' |
|
341 | - || substr($value,-5) == '.tiff') |
|
342 | - ? true : false; |
|
343 | - |
|
344 | - $file_url = base_url().$field_info->extras->upload_path."/$value"; |
|
345 | - |
|
346 | - $file_url_anchor = '<a href="'.$file_url.'"'; |
|
347 | - if($is_image) |
|
348 | - { |
|
349 | - $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; |
|
350 | - } |
|
351 | - else |
|
352 | - { |
|
353 | - $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); |
|
354 | - } |
|
355 | - $file_url_anchor .= '</a>'; |
|
356 | - |
|
357 | - $value = $file_url_anchor; |
|
358 | - } |
|
359 | - break; |
|
357 | + $value = $file_url_anchor; |
|
358 | + } |
|
359 | + break; |
|
360 | 360 | |
361 | - default: |
|
362 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
363 | - break; |
|
364 | - } |
|
365 | - |
|
366 | - return $value; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Character Limiter of codeigniter (I just don't want to load the helper ) |
|
371 | - * |
|
372 | - * Limits the string based on the character count. Preserves complete words |
|
373 | - * so the character count may not be exactly as specified. |
|
374 | - * |
|
375 | - * @access public |
|
376 | - * @param string |
|
377 | - * @param integer |
|
378 | - * @param string the end character. Usually an ellipsis |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - function character_limiter($str, $n = 500, $end_char = '…') |
|
382 | - { |
|
383 | - if (strlen($str) < $n) |
|
384 | - { |
|
385 | - return $str; |
|
386 | - } |
|
387 | - |
|
388 | - // a bit complicated, but faster than preg_replace with \s+ |
|
389 | - $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); |
|
390 | - |
|
391 | - if (strlen($str) <= $n) |
|
392 | - { |
|
393 | - return $str; |
|
394 | - } |
|
395 | - |
|
396 | - $out = ''; |
|
397 | - foreach (explode(' ', trim($str)) as $val) |
|
398 | - { |
|
399 | - $out .= $val.' '; |
|
400 | - |
|
401 | - if (strlen($out) >= $n) |
|
402 | - { |
|
403 | - $out = trim($out); |
|
404 | - return (strlen($out) === strlen($str)) ? $out : $out.$end_char; |
|
405 | - } |
|
406 | - } |
|
407 | - } |
|
408 | - |
|
409 | - protected function get_type($db_type) |
|
410 | - { |
|
411 | - $type = false; |
|
412 | - if(!empty($db_type->type)) |
|
413 | - { |
|
414 | - switch ($db_type->type) { |
|
415 | - case '1': |
|
416 | - case '3': |
|
417 | - case 'int': |
|
418 | - case 'tinyint': |
|
419 | - case 'mediumint': |
|
420 | - case 'longint': |
|
421 | - if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
422 | - $type = 'true_false'; |
|
423 | - else |
|
424 | - $type = 'integer'; |
|
425 | - break; |
|
426 | - case '254': |
|
427 | - case 'string': |
|
428 | - case 'enum': |
|
429 | - if($db_type->db_type != 'enum') |
|
430 | - $type = 'string'; |
|
431 | - else |
|
432 | - $type = 'enum'; |
|
433 | - break; |
|
434 | - case 'set': |
|
435 | - if($db_type->db_type != 'set') |
|
436 | - $type = 'string'; |
|
437 | - else |
|
438 | - $type = 'set'; |
|
439 | - break; |
|
440 | - case '252': |
|
441 | - case 'blob': |
|
442 | - case 'text': |
|
443 | - case 'mediumtext': |
|
444 | - case 'longtext': |
|
445 | - $type = 'text'; |
|
446 | - break; |
|
447 | - case '10': |
|
448 | - case 'date': |
|
449 | - $type = 'date'; |
|
450 | - break; |
|
451 | - case '12': |
|
452 | - case 'datetime': |
|
453 | - case 'timestamp': |
|
454 | - $type = 'datetime'; |
|
455 | - break; |
|
456 | - } |
|
457 | - } |
|
458 | - return $type; |
|
459 | - } |
|
361 | + default: |
|
362 | + $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
363 | + break; |
|
364 | + } |
|
365 | + |
|
366 | + return $value; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Character Limiter of codeigniter (I just don't want to load the helper ) |
|
371 | + * |
|
372 | + * Limits the string based on the character count. Preserves complete words |
|
373 | + * so the character count may not be exactly as specified. |
|
374 | + * |
|
375 | + * @access public |
|
376 | + * @param string |
|
377 | + * @param integer |
|
378 | + * @param string the end character. Usually an ellipsis |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + function character_limiter($str, $n = 500, $end_char = '…') |
|
382 | + { |
|
383 | + if (strlen($str) < $n) |
|
384 | + { |
|
385 | + return $str; |
|
386 | + } |
|
387 | + |
|
388 | + // a bit complicated, but faster than preg_replace with \s+ |
|
389 | + $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); |
|
390 | + |
|
391 | + if (strlen($str) <= $n) |
|
392 | + { |
|
393 | + return $str; |
|
394 | + } |
|
395 | + |
|
396 | + $out = ''; |
|
397 | + foreach (explode(' ', trim($str)) as $val) |
|
398 | + { |
|
399 | + $out .= $val.' '; |
|
400 | + |
|
401 | + if (strlen($out) >= $n) |
|
402 | + { |
|
403 | + $out = trim($out); |
|
404 | + return (strlen($out) === strlen($str)) ? $out : $out.$end_char; |
|
405 | + } |
|
406 | + } |
|
407 | + } |
|
408 | + |
|
409 | + protected function get_type($db_type) |
|
410 | + { |
|
411 | + $type = false; |
|
412 | + if(!empty($db_type->type)) |
|
413 | + { |
|
414 | + switch ($db_type->type) { |
|
415 | + case '1': |
|
416 | + case '3': |
|
417 | + case 'int': |
|
418 | + case 'tinyint': |
|
419 | + case 'mediumint': |
|
420 | + case 'longint': |
|
421 | + if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
422 | + $type = 'true_false'; |
|
423 | + else |
|
424 | + $type = 'integer'; |
|
425 | + break; |
|
426 | + case '254': |
|
427 | + case 'string': |
|
428 | + case 'enum': |
|
429 | + if($db_type->db_type != 'enum') |
|
430 | + $type = 'string'; |
|
431 | + else |
|
432 | + $type = 'enum'; |
|
433 | + break; |
|
434 | + case 'set': |
|
435 | + if($db_type->db_type != 'set') |
|
436 | + $type = 'string'; |
|
437 | + else |
|
438 | + $type = 'set'; |
|
439 | + break; |
|
440 | + case '252': |
|
441 | + case 'blob': |
|
442 | + case 'text': |
|
443 | + case 'mediumtext': |
|
444 | + case 'longtext': |
|
445 | + $type = 'text'; |
|
446 | + break; |
|
447 | + case '10': |
|
448 | + case 'date': |
|
449 | + $type = 'date'; |
|
450 | + break; |
|
451 | + case '12': |
|
452 | + case 'datetime': |
|
453 | + case 'timestamp': |
|
454 | + $type = 'datetime'; |
|
455 | + break; |
|
456 | + } |
|
457 | + } |
|
458 | + return $type; |
|
459 | + } |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | // ------------------------------------------------------------------------ |
@@ -473,107 +473,107 @@ discard block |
||
473 | 473 | */ |
474 | 474 | class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types |
475 | 475 | { |
476 | - /** |
|
477 | - * @var Grocery_crud_model |
|
478 | - */ |
|
479 | - public $basic_model = null; |
|
480 | - |
|
481 | - protected function set_default_Model() |
|
482 | - { |
|
483 | - $ci = &get_instance(); |
|
484 | - $ci->load->model('Grocery_crud_model'); |
|
485 | - |
|
486 | - $this->basic_model = new Grocery_crud_model(); |
|
487 | - } |
|
488 | - |
|
489 | - protected function get_total_results() |
|
490 | - { |
|
491 | - if(!empty($this->where)) |
|
492 | - foreach($this->where as $where) |
|
493 | - $this->basic_model->where($where[0],$where[1],$where[2]); |
|
494 | - |
|
495 | - if(!empty($this->or_where)) |
|
496 | - foreach($this->or_where as $or_where) |
|
497 | - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
498 | - |
|
499 | - if(!empty($this->like)) |
|
500 | - foreach($this->like as $like) |
|
501 | - $this->basic_model->like($like[0],$like[1],$like[2]); |
|
502 | - |
|
503 | - if(!empty($this->or_like)) |
|
504 | - foreach($this->or_like as $or_like) |
|
505 | - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
506 | - |
|
507 | - if(!empty($this->having)) |
|
508 | - foreach($this->having as $having) |
|
509 | - $this->basic_model->having($having[0],$having[1],$having[2]); |
|
510 | - |
|
511 | - if(!empty($this->or_having)) |
|
512 | - foreach($this->or_having as $or_having) |
|
513 | - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
514 | - |
|
515 | - if(!empty($this->relation)) |
|
516 | - foreach($this->relation as $relation) |
|
517 | - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
518 | - |
|
519 | - if(!empty($this->relation_n_n)) |
|
520 | - { |
|
521 | - $columns = $this->get_columns(); |
|
522 | - foreach($columns as $column) |
|
523 | - { |
|
524 | - //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
525 | - if(isset($this->relation_n_n[$column->field_name])) |
|
526 | - { |
|
527 | - $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
528 | - } |
|
529 | - } |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - return $this->basic_model->get_total_results(); |
|
534 | - } |
|
535 | - |
|
536 | - public function set_model($model_name) |
|
537 | - { |
|
538 | - $ci = &get_instance(); |
|
539 | - $ci->load->model('Grocery_crud_model'); |
|
540 | - |
|
541 | - $ci->load->model($model_name); |
|
542 | - |
|
543 | - $temp = explode('/',$model_name); |
|
544 | - krsort($temp); |
|
545 | - foreach($temp as $t) |
|
546 | - { |
|
547 | - $real_model_name = $t; |
|
548 | - break; |
|
549 | - } |
|
550 | - |
|
551 | - $this->basic_model = $ci->$real_model_name; |
|
552 | - } |
|
553 | - |
|
554 | - protected function set_ajax_list_queries($state_info = null) |
|
555 | - { |
|
556 | - if(!empty($state_info->per_page)) |
|
557 | - { |
|
558 | - if(empty($state_info->page) || !is_numeric($state_info->page) ) |
|
559 | - $this->limit($state_info->per_page); |
|
560 | - else |
|
561 | - { |
|
562 | - $limit_page = ( ($state_info->page-1) * $state_info->per_page ); |
|
563 | - $this->limit($state_info->per_page, $limit_page); |
|
564 | - } |
|
565 | - } |
|
566 | - |
|
567 | - if(!empty($state_info->order_by)) |
|
568 | - { |
|
569 | - $this->order_by($state_info->order_by[0],$state_info->order_by[1]); |
|
570 | - } |
|
571 | - |
|
572 | - if(!empty($state_info->search)) |
|
573 | - { |
|
574 | - if (!empty($this->relation)) { |
|
575 | - foreach ($this->relation as $relation_name => $relation_values) { |
|
576 | - $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); |
|
476 | + /** |
|
477 | + * @var Grocery_crud_model |
|
478 | + */ |
|
479 | + public $basic_model = null; |
|
480 | + |
|
481 | + protected function set_default_Model() |
|
482 | + { |
|
483 | + $ci = &get_instance(); |
|
484 | + $ci->load->model('Grocery_crud_model'); |
|
485 | + |
|
486 | + $this->basic_model = new Grocery_crud_model(); |
|
487 | + } |
|
488 | + |
|
489 | + protected function get_total_results() |
|
490 | + { |
|
491 | + if(!empty($this->where)) |
|
492 | + foreach($this->where as $where) |
|
493 | + $this->basic_model->where($where[0],$where[1],$where[2]); |
|
494 | + |
|
495 | + if(!empty($this->or_where)) |
|
496 | + foreach($this->or_where as $or_where) |
|
497 | + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
498 | + |
|
499 | + if(!empty($this->like)) |
|
500 | + foreach($this->like as $like) |
|
501 | + $this->basic_model->like($like[0],$like[1],$like[2]); |
|
502 | + |
|
503 | + if(!empty($this->or_like)) |
|
504 | + foreach($this->or_like as $or_like) |
|
505 | + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
506 | + |
|
507 | + if(!empty($this->having)) |
|
508 | + foreach($this->having as $having) |
|
509 | + $this->basic_model->having($having[0],$having[1],$having[2]); |
|
510 | + |
|
511 | + if(!empty($this->or_having)) |
|
512 | + foreach($this->or_having as $or_having) |
|
513 | + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
514 | + |
|
515 | + if(!empty($this->relation)) |
|
516 | + foreach($this->relation as $relation) |
|
517 | + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
518 | + |
|
519 | + if(!empty($this->relation_n_n)) |
|
520 | + { |
|
521 | + $columns = $this->get_columns(); |
|
522 | + foreach($columns as $column) |
|
523 | + { |
|
524 | + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
525 | + if(isset($this->relation_n_n[$column->field_name])) |
|
526 | + { |
|
527 | + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
528 | + } |
|
529 | + } |
|
530 | + |
|
531 | + } |
|
532 | + |
|
533 | + return $this->basic_model->get_total_results(); |
|
534 | + } |
|
535 | + |
|
536 | + public function set_model($model_name) |
|
537 | + { |
|
538 | + $ci = &get_instance(); |
|
539 | + $ci->load->model('Grocery_crud_model'); |
|
540 | + |
|
541 | + $ci->load->model($model_name); |
|
542 | + |
|
543 | + $temp = explode('/',$model_name); |
|
544 | + krsort($temp); |
|
545 | + foreach($temp as $t) |
|
546 | + { |
|
547 | + $real_model_name = $t; |
|
548 | + break; |
|
549 | + } |
|
550 | + |
|
551 | + $this->basic_model = $ci->$real_model_name; |
|
552 | + } |
|
553 | + |
|
554 | + protected function set_ajax_list_queries($state_info = null) |
|
555 | + { |
|
556 | + if(!empty($state_info->per_page)) |
|
557 | + { |
|
558 | + if(empty($state_info->page) || !is_numeric($state_info->page) ) |
|
559 | + $this->limit($state_info->per_page); |
|
560 | + else |
|
561 | + { |
|
562 | + $limit_page = ( ($state_info->page-1) * $state_info->per_page ); |
|
563 | + $this->limit($state_info->per_page, $limit_page); |
|
564 | + } |
|
565 | + } |
|
566 | + |
|
567 | + if(!empty($state_info->order_by)) |
|
568 | + { |
|
569 | + $this->order_by($state_info->order_by[0],$state_info->order_by[1]); |
|
570 | + } |
|
571 | + |
|
572 | + if(!empty($state_info->search)) |
|
573 | + { |
|
574 | + if (!empty($this->relation)) { |
|
575 | + foreach ($this->relation as $relation_name => $relation_values) { |
|
576 | + $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); |
|
577 | 577 | } |
578 | 578 | } |
579 | 579 | |
@@ -600,4036 +600,4036 @@ discard block |
||
600 | 600 | |
601 | 601 | } |
602 | 602 | } elseif ($state_info->search->field !== null) { |
603 | - if (isset($temp_relation[$state_info->search->field])) { |
|
604 | - if (is_array($temp_relation[$state_info->search->field])) { |
|
605 | - foreach ($temp_relation[$state_info->search->field] as $search_field) { |
|
606 | - $this->or_like($search_field , $state_info->search->text); |
|
603 | + if (isset($temp_relation[$state_info->search->field])) { |
|
604 | + if (is_array($temp_relation[$state_info->search->field])) { |
|
605 | + foreach ($temp_relation[$state_info->search->field] as $search_field) { |
|
606 | + $this->or_like($search_field , $state_info->search->text); |
|
607 | 607 | } |
608 | 608 | } else { |
609 | - $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); |
|
609 | + $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); |
|
610 | 610 | } |
611 | - } elseif(isset($this->relation_n_n[$state_info->search->field])) { |
|
612 | - $escaped_text = $this->basic_model->escape_str($state_info->search->text); |
|
613 | - $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); |
|
614 | - } else { |
|
615 | - $this->like($state_info->search->field , $state_info->search->text); |
|
616 | - } |
|
617 | - } |
|
618 | - else |
|
619 | - { |
|
620 | - $columns = $this->get_columns(); |
|
621 | - |
|
622 | - $search_text = $state_info->search->text; |
|
623 | - |
|
624 | - if(!empty($this->where)) |
|
625 | - foreach($this->where as $where) |
|
626 | - $this->basic_model->having($where[0],$where[1],$where[2]); |
|
627 | - |
|
628 | - foreach($columns as $column) |
|
629 | - { |
|
630 | - if(isset($temp_relation[$column->field_name])) |
|
631 | - { |
|
632 | - if(is_array($temp_relation[$column->field_name])) |
|
633 | - { |
|
634 | - foreach($temp_relation[$column->field_name] as $search_field) |
|
635 | - { |
|
636 | - $this->or_like($search_field, $search_text); |
|
637 | - } |
|
638 | - } |
|
639 | - else |
|
640 | - { |
|
641 | - $this->or_like($temp_relation[$column->field_name], $search_text); |
|
642 | - } |
|
643 | - } |
|
644 | - elseif(isset($this->relation_n_n[$column->field_name])) |
|
645 | - { |
|
646 | - //@todo have a where for the relation_n_n statement |
|
647 | - } |
|
648 | - else |
|
649 | - { |
|
650 | - $this->or_like($column->field_name, $search_text); |
|
651 | - } |
|
652 | - } |
|
653 | - } |
|
654 | - } |
|
655 | - } |
|
656 | - |
|
657 | - protected function table_exists($table_name = null) |
|
658 | - { |
|
659 | - if($this->basic_model->db_table_exists($table_name)) |
|
660 | - return true; |
|
661 | - return false; |
|
662 | - } |
|
663 | - |
|
664 | - protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) |
|
665 | - { |
|
666 | - list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; |
|
667 | - |
|
668 | - if($primary_key_value !== null) |
|
669 | - { |
|
670 | - $primary_key = $this->basic_model->get_primary_key($related_table); |
|
671 | - |
|
672 | - //A where clause with the primary key is enough to take the selected key row |
|
673 | - $where_clause = array($primary_key => $primary_key_value); |
|
674 | - } |
|
675 | - |
|
676 | - $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); |
|
677 | - |
|
678 | - return $relation_array; |
|
679 | - } |
|
680 | - |
|
681 | - protected function get_relation_total_rows($relation_info) |
|
682 | - { |
|
683 | - list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; |
|
684 | - |
|
685 | - $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); |
|
686 | - |
|
687 | - return $relation_array; |
|
688 | - } |
|
689 | - |
|
690 | - protected function db_insert_validation() |
|
691 | - { |
|
692 | - $validation_result = (object)array('success'=>false); |
|
693 | - |
|
694 | - $field_types = $this->get_field_types(); |
|
695 | - $required_fields = $this->required_fields; |
|
696 | - $unique_fields = $this->_unique_fields; |
|
697 | - $add_fields = $this->get_add_fields(); |
|
698 | - |
|
699 | - if(!empty($required_fields)) |
|
700 | - { |
|
701 | - foreach($add_fields as $add_field) |
|
702 | - { |
|
703 | - $field_name = $add_field->field_name; |
|
704 | - if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
705 | - { |
|
706 | - $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
707 | - } |
|
708 | - } |
|
709 | - } |
|
710 | - |
|
711 | - /** Checking for unique fields. If the field value is not unique then |
|
712 | - * return a validation error straight away, if not continue... */ |
|
713 | - if(!empty($unique_fields)) |
|
714 | - { |
|
715 | - $form_validation = $this->form_validation(); |
|
716 | - |
|
717 | - foreach($add_fields as $add_field) |
|
718 | - { |
|
719 | - $field_name = $add_field->field_name; |
|
720 | - if(in_array( $field_name, $unique_fields) ) |
|
721 | - { |
|
722 | - $form_validation->set_rules( $field_name, |
|
723 | - $field_types[$field_name]->display_as, |
|
724 | - 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - if(!$form_validation->run()) |
|
729 | - { |
|
730 | - $validation_result->error_message = $form_validation->error_string(); |
|
731 | - $validation_result->error_fields = $form_validation->_error_array; |
|
732 | - |
|
733 | - return $validation_result; |
|
734 | - } |
|
735 | - } |
|
736 | - |
|
737 | - if(!empty($this->validation_rules)) |
|
738 | - { |
|
739 | - $form_validation = $this->form_validation(); |
|
740 | - |
|
741 | - $add_fields = $this->get_add_fields(); |
|
742 | - |
|
743 | - foreach($add_fields as $add_field) |
|
744 | - { |
|
745 | - $field_name = $add_field->field_name; |
|
746 | - if(isset($this->validation_rules[$field_name])) |
|
747 | - { |
|
748 | - $rule = $this->validation_rules[$field_name]; |
|
749 | - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
750 | - } |
|
751 | - } |
|
752 | - |
|
753 | - if($form_validation->run()) |
|
754 | - { |
|
755 | - $validation_result->success = true; |
|
756 | - } |
|
757 | - else |
|
758 | - { |
|
759 | - $validation_result->error_message = $form_validation->error_string(); |
|
760 | - $validation_result->error_fields = $form_validation->_error_array; |
|
761 | - } |
|
762 | - } |
|
763 | - else |
|
764 | - { |
|
765 | - $validation_result->success = true; |
|
766 | - } |
|
767 | - |
|
768 | - return $validation_result; |
|
769 | - } |
|
770 | - |
|
771 | - protected function form_validation() |
|
772 | - { |
|
773 | - if($this->form_validation === null) |
|
774 | - { |
|
775 | - $this->form_validation = new grocery_CRUD_Form_validation(); |
|
776 | - $ci = &get_instance(); |
|
777 | - $ci->load->library('form_validation'); |
|
778 | - $ci->form_validation = $this->form_validation; |
|
779 | - } |
|
780 | - return $this->form_validation; |
|
781 | - } |
|
782 | - |
|
783 | - protected function db_update_validation() |
|
784 | - { |
|
785 | - $validation_result = (object)array('success'=>false); |
|
786 | - |
|
787 | - $field_types = $this->get_field_types(); |
|
788 | - $required_fields = $this->required_fields; |
|
789 | - $unique_fields = $this->_unique_fields; |
|
790 | - $edit_fields = $this->get_edit_fields(); |
|
791 | - |
|
792 | - if(!empty($required_fields)) |
|
793 | - { |
|
794 | - foreach($edit_fields as $edit_field) |
|
795 | - { |
|
796 | - $field_name = $edit_field->field_name; |
|
797 | - if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
798 | - { |
|
799 | - $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
800 | - } |
|
801 | - } |
|
802 | - } |
|
803 | - |
|
804 | - |
|
805 | - /** Checking for unique fields. If the field value is not unique then |
|
806 | - * return a validation error straight away, if not continue... */ |
|
807 | - if(!empty($unique_fields)) |
|
808 | - { |
|
809 | - $form_validation = $this->form_validation(); |
|
810 | - |
|
811 | - $form_validation_check = false; |
|
812 | - |
|
813 | - foreach($edit_fields as $edit_field) |
|
814 | - { |
|
815 | - $field_name = $edit_field->field_name; |
|
816 | - if(in_array( $field_name, $unique_fields) ) |
|
817 | - { |
|
818 | - $state_info = $this->getStateInfo(); |
|
819 | - $primary_key = $this->get_primary_key(); |
|
820 | - $field_name_value = $_POST[$field_name]; |
|
821 | - |
|
822 | - $this->basic_model->where($primary_key,$state_info->primary_key); |
|
823 | - $row = $this->basic_model->get_row(); |
|
824 | - |
|
825 | - if(!isset($row->$field_name)) { |
|
826 | - throw new Exception("The field name doesn't exist in the database. ". |
|
827 | - "Please use the unique fields only for fields ". |
|
828 | - "that exist in the database"); |
|
829 | - } |
|
830 | - |
|
831 | - $previous_field_name_value = $row->$field_name; |
|
832 | - |
|
833 | - if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { |
|
834 | - $form_validation->set_rules( $field_name, |
|
835 | - $field_types[$field_name]->display_as, |
|
836 | - 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
837 | - |
|
838 | - $form_validation_check = true; |
|
839 | - } |
|
840 | - } |
|
841 | - } |
|
842 | - |
|
843 | - if($form_validation_check && !$form_validation->run()) |
|
844 | - { |
|
845 | - $validation_result->error_message = $form_validation->error_string(); |
|
846 | - $validation_result->error_fields = $form_validation->_error_array; |
|
847 | - |
|
848 | - return $validation_result; |
|
849 | - } |
|
850 | - } |
|
851 | - |
|
852 | - if(!empty($this->validation_rules)) |
|
853 | - { |
|
854 | - $form_validation = $this->form_validation(); |
|
855 | - |
|
856 | - $edit_fields = $this->get_edit_fields(); |
|
857 | - |
|
858 | - foreach($edit_fields as $edit_field) |
|
859 | - { |
|
860 | - $field_name = $edit_field->field_name; |
|
861 | - if(isset($this->validation_rules[$field_name])) |
|
862 | - { |
|
863 | - $rule = $this->validation_rules[$field_name]; |
|
864 | - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
865 | - } |
|
866 | - } |
|
867 | - |
|
868 | - if($form_validation->run()) |
|
869 | - { |
|
870 | - $validation_result->success = true; |
|
871 | - } |
|
872 | - else |
|
873 | - { |
|
874 | - $validation_result->error_message = $form_validation->error_string(); |
|
875 | - $validation_result->error_fields = $form_validation->_error_array; |
|
876 | - } |
|
877 | - } |
|
878 | - else |
|
879 | - { |
|
880 | - $validation_result->success = true; |
|
881 | - } |
|
882 | - |
|
883 | - return $validation_result; |
|
884 | - } |
|
885 | - |
|
886 | - protected function db_insert($state_info) |
|
887 | - { |
|
888 | - $validation_result = $this->db_insert_validation(); |
|
889 | - |
|
890 | - if($validation_result->success) |
|
891 | - { |
|
892 | - $post_data = $state_info->unwrapped_data; |
|
893 | - |
|
894 | - $add_fields = $this->get_add_fields(); |
|
895 | - |
|
896 | - if($this->callback_insert === null) |
|
897 | - { |
|
898 | - if($this->callback_before_insert !== null) |
|
899 | - { |
|
900 | - $callback_return = call_user_func($this->callback_before_insert, $post_data); |
|
901 | - |
|
902 | - if(!empty($callback_return) && is_array($callback_return)) |
|
903 | - $post_data = $callback_return; |
|
904 | - elseif($callback_return === false) |
|
905 | - return false; |
|
906 | - } |
|
907 | - |
|
908 | - $insert_data = array(); |
|
909 | - $types = $this->get_field_types(); |
|
910 | - foreach($add_fields as $num_row => $field) |
|
911 | - { |
|
912 | - /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
913 | - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
914 | - { |
|
915 | - $post_data[$field->field_name] = array(); |
|
916 | - } |
|
917 | - |
|
918 | - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
919 | - { |
|
920 | - if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) |
|
921 | - { |
|
922 | - $insert_data[$field->field_name] = null; |
|
923 | - } |
|
924 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
925 | - { |
|
926 | - $insert_data[$field->field_name] = null; |
|
927 | - } |
|
928 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
929 | - { |
|
930 | - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
931 | - } |
|
932 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
933 | - { |
|
934 | - //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
935 | - } |
|
936 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
937 | - { |
|
938 | - $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
939 | - } |
|
940 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
941 | - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
942 | - substr($post_data[$field->field_name],10); |
|
943 | - } |
|
944 | - else |
|
945 | - { |
|
946 | - $insert_data[$field->field_name] = $post_data[$field->field_name]; |
|
947 | - } |
|
948 | - } |
|
949 | - } |
|
950 | - |
|
951 | - $insert_result = $this->basic_model->db_insert($insert_data); |
|
952 | - |
|
953 | - if($insert_result !== false) |
|
954 | - { |
|
955 | - $insert_primary_key = $insert_result; |
|
956 | - } |
|
957 | - else |
|
958 | - { |
|
959 | - return false; |
|
960 | - } |
|
961 | - |
|
962 | - if(!empty($this->relation_n_n)) |
|
963 | - { |
|
964 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
965 | - { |
|
966 | - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
967 | - $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); |
|
968 | - } |
|
969 | - } |
|
970 | - |
|
971 | - if($this->callback_after_insert !== null) |
|
972 | - { |
|
973 | - $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); |
|
974 | - |
|
975 | - if($callback_return === false) |
|
976 | - { |
|
977 | - return false; |
|
978 | - } |
|
979 | - |
|
980 | - } |
|
981 | - }else |
|
982 | - { |
|
983 | - $callback_return = call_user_func($this->callback_insert, $post_data); |
|
984 | - |
|
985 | - if($callback_return === false) |
|
986 | - { |
|
987 | - return false; |
|
988 | - } |
|
989 | - } |
|
990 | - |
|
991 | - if(isset($insert_primary_key)) |
|
992 | - return $insert_primary_key; |
|
993 | - else |
|
994 | - return true; |
|
995 | - } |
|
996 | - |
|
997 | - return false; |
|
998 | - |
|
999 | - } |
|
1000 | - |
|
1001 | - protected function db_update($state_info) |
|
1002 | - { |
|
1003 | - $validation_result = $this->db_update_validation(); |
|
1004 | - |
|
1005 | - $edit_fields = $this->get_edit_fields(); |
|
1006 | - |
|
1007 | - if($validation_result->success) |
|
1008 | - { |
|
1009 | - $post_data = $state_info->unwrapped_data; |
|
1010 | - $primary_key = $state_info->primary_key; |
|
1011 | - |
|
1012 | - if($this->callback_update === null) |
|
1013 | - { |
|
1014 | - if($this->callback_before_update !== null) |
|
1015 | - { |
|
1016 | - $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); |
|
1017 | - |
|
1018 | - if(!empty($callback_return) && is_array($callback_return)) |
|
1019 | - { |
|
1020 | - $post_data = $callback_return; |
|
1021 | - } |
|
1022 | - elseif($callback_return === false) |
|
1023 | - { |
|
1024 | - return false; |
|
1025 | - } |
|
1026 | - |
|
1027 | - } |
|
1028 | - |
|
1029 | - $update_data = array(); |
|
1030 | - $types = $this->get_field_types(); |
|
1031 | - foreach($edit_fields as $num_row => $field) |
|
1032 | - { |
|
1033 | - /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
1034 | - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
1035 | - { |
|
1036 | - $post_data[$field->field_name] = array(); |
|
1037 | - } |
|
1038 | - |
|
1039 | - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
1040 | - { |
|
1041 | - if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) |
|
1042 | - { |
|
1043 | - $update_data[$field->field_name] = null; |
|
1044 | - } |
|
1045 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
1046 | - { |
|
1047 | - $update_data[$field->field_name] = null; |
|
1048 | - } |
|
1049 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
1050 | - { |
|
1051 | - $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
1052 | - } |
|
1053 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
1054 | - { |
|
1055 | - //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
1056 | - } |
|
1057 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
1058 | - { |
|
1059 | - $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
1060 | - } |
|
1061 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
1062 | - $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
1063 | - substr($post_data[$field->field_name],10); |
|
1064 | - } |
|
1065 | - else |
|
1066 | - { |
|
1067 | - $update_data[$field->field_name] = $post_data[$field->field_name]; |
|
1068 | - } |
|
1069 | - } |
|
1070 | - } |
|
1071 | - |
|
1072 | - if($this->basic_model->db_update($update_data, $primary_key) === false) |
|
1073 | - { |
|
1074 | - return false; |
|
1075 | - } |
|
1076 | - |
|
1077 | - if(!empty($this->relation_n_n)) |
|
1078 | - { |
|
1079 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
1080 | - { |
|
1081 | - if ( $this->unset_edit_fields !== null |
|
1082 | - && is_array($this->unset_edit_fields) |
|
1083 | - && in_array($field_name,$this->unset_edit_fields) |
|
1084 | - ) { |
|
1085 | - continue; |
|
1086 | - } |
|
1087 | - |
|
1088 | - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
1089 | - $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); |
|
1090 | - } |
|
1091 | - } |
|
1092 | - |
|
1093 | - if($this->callback_after_update !== null) |
|
1094 | - { |
|
1095 | - $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); |
|
1096 | - |
|
1097 | - if($callback_return === false) |
|
1098 | - { |
|
1099 | - return false; |
|
1100 | - } |
|
1101 | - |
|
1102 | - } |
|
1103 | - } |
|
1104 | - else |
|
1105 | - { |
|
1106 | - $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); |
|
1107 | - |
|
1108 | - if($callback_return === false) |
|
1109 | - { |
|
1110 | - return false; |
|
1111 | - } |
|
1112 | - } |
|
1113 | - |
|
1114 | - return true; |
|
1115 | - } |
|
1116 | - else |
|
1117 | - { |
|
1118 | - return false; |
|
1119 | - } |
|
1120 | - } |
|
1121 | - |
|
1122 | - protected function _convert_date_to_sql_date($date) |
|
1123 | - { |
|
1124 | - $date = substr($date,0,10); |
|
1125 | - if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) |
|
1126 | - { |
|
1127 | - //If it's already a sql-date don't convert it! |
|
1128 | - return $date; |
|
1129 | - }elseif(empty($date)) |
|
1130 | - { |
|
1131 | - return ''; |
|
1132 | - } |
|
1133 | - |
|
1134 | - $date_array = preg_split( '/[-\.\/ ]/', $date); |
|
1135 | - if($this->php_date_format == 'd/m/Y') |
|
1136 | - { |
|
1137 | - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); |
|
1138 | - } |
|
1139 | - elseif($this->php_date_format == 'm/d/Y') |
|
1140 | - { |
|
1141 | - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); |
|
1142 | - } |
|
1143 | - else |
|
1144 | - { |
|
1145 | - $sql_date = $date; |
|
1146 | - } |
|
1147 | - |
|
1148 | - return $sql_date; |
|
1149 | - } |
|
1150 | - |
|
1151 | - protected function _get_field_names_to_search(array $relation_values) |
|
1152 | - { |
|
1153 | - if(!strstr($relation_values[2],'{')) |
|
1154 | - return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
|
1155 | - else |
|
1156 | - { |
|
1157 | - $relation_values[2] = ' '.$relation_values[2].' '; |
|
1158 | - $temp1 = explode('{',$relation_values[2]); |
|
1159 | - unset($temp1[0]); |
|
1160 | - |
|
1161 | - $field_names_array = array(); |
|
1162 | - foreach($temp1 as $field) |
|
1163 | - list($field_names_array[]) = explode('}',$field); |
|
1164 | - |
|
1165 | - return $field_names_array; |
|
1166 | - } |
|
1167 | - } |
|
611 | + } elseif(isset($this->relation_n_n[$state_info->search->field])) { |
|
612 | + $escaped_text = $this->basic_model->escape_str($state_info->search->text); |
|
613 | + $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); |
|
614 | + } else { |
|
615 | + $this->like($state_info->search->field , $state_info->search->text); |
|
616 | + } |
|
617 | + } |
|
618 | + else |
|
619 | + { |
|
620 | + $columns = $this->get_columns(); |
|
1168 | 621 | |
1169 | - protected function _unique_join_name($field_name) |
|
1170 | - { |
|
1171 | - return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number |
|
622 | + $search_text = $state_info->search->text; |
|
623 | + |
|
624 | + if(!empty($this->where)) |
|
625 | + foreach($this->where as $where) |
|
626 | + $this->basic_model->having($where[0],$where[1],$where[2]); |
|
627 | + |
|
628 | + foreach($columns as $column) |
|
629 | + { |
|
630 | + if(isset($temp_relation[$column->field_name])) |
|
631 | + { |
|
632 | + if(is_array($temp_relation[$column->field_name])) |
|
633 | + { |
|
634 | + foreach($temp_relation[$column->field_name] as $search_field) |
|
635 | + { |
|
636 | + $this->or_like($search_field, $search_text); |
|
637 | + } |
|
638 | + } |
|
639 | + else |
|
640 | + { |
|
641 | + $this->or_like($temp_relation[$column->field_name], $search_text); |
|
642 | + } |
|
643 | + } |
|
644 | + elseif(isset($this->relation_n_n[$column->field_name])) |
|
645 | + { |
|
646 | + //@todo have a where for the relation_n_n statement |
|
647 | + } |
|
648 | + else |
|
649 | + { |
|
650 | + $this->or_like($column->field_name, $search_text); |
|
651 | + } |
|
652 | + } |
|
653 | + } |
|
654 | + } |
|
1172 | 655 | } |
1173 | 656 | |
1174 | - protected function _unique_field_name($field_name) |
|
657 | + protected function table_exists($table_name = null) |
|
1175 | 658 | { |
1176 | - return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number |
|
659 | + if($this->basic_model->db_table_exists($table_name)) |
|
660 | + return true; |
|
661 | + return false; |
|
1177 | 662 | } |
1178 | 663 | |
1179 | - protected function db_multiple_delete($state_info) |
|
664 | + protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) |
|
1180 | 665 | { |
1181 | - foreach ($state_info->ids as $delete_id) { |
|
1182 | - $result = $this->db_delete((object)array('primary_key' => $delete_id)); |
|
1183 | - if (!$result) { |
|
1184 | - return false; |
|
1185 | - } |
|
666 | + list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; |
|
667 | + |
|
668 | + if($primary_key_value !== null) |
|
669 | + { |
|
670 | + $primary_key = $this->basic_model->get_primary_key($related_table); |
|
671 | + |
|
672 | + //A where clause with the primary key is enough to take the selected key row |
|
673 | + $where_clause = array($primary_key => $primary_key_value); |
|
1186 | 674 | } |
1187 | 675 | |
1188 | - return true; |
|
676 | + $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); |
|
677 | + |
|
678 | + return $relation_array; |
|
1189 | 679 | } |
1190 | 680 | |
1191 | - protected function db_delete($state_info) |
|
1192 | - { |
|
1193 | - $primary_key_value = $state_info->primary_key; |
|
1194 | - |
|
1195 | - if($this->callback_delete === null) |
|
1196 | - { |
|
1197 | - if($this->callback_before_delete !== null) |
|
1198 | - { |
|
1199 | - $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); |
|
1200 | - |
|
1201 | - if($callback_return === false) |
|
1202 | - { |
|
1203 | - return false; |
|
1204 | - } |
|
1205 | - |
|
1206 | - } |
|
1207 | - |
|
1208 | - if(!empty($this->relation_n_n)) |
|
1209 | - { |
|
1210 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
1211 | - { |
|
1212 | - $this->db_relation_n_n_delete( $field_info, $primary_key_value ); |
|
1213 | - } |
|
1214 | - } |
|
1215 | - |
|
1216 | - $delete_result = $this->basic_model->db_delete($primary_key_value); |
|
1217 | - |
|
1218 | - if($delete_result === false) |
|
1219 | - { |
|
1220 | - return false; |
|
1221 | - } |
|
1222 | - |
|
1223 | - if($this->callback_after_delete !== null) |
|
1224 | - { |
|
1225 | - $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); |
|
1226 | - |
|
1227 | - if($callback_return === false) |
|
1228 | - { |
|
1229 | - return false; |
|
1230 | - } |
|
1231 | - |
|
1232 | - } |
|
1233 | - } |
|
1234 | - else |
|
1235 | - { |
|
1236 | - $callback_return = call_user_func($this->callback_delete, $primary_key_value); |
|
1237 | - |
|
1238 | - if($callback_return === false) |
|
1239 | - { |
|
1240 | - return false; |
|
1241 | - } |
|
1242 | - } |
|
1243 | - |
|
1244 | - return true; |
|
1245 | - } |
|
1246 | - |
|
1247 | - protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) |
|
1248 | - { |
|
1249 | - $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); |
|
1250 | - } |
|
1251 | - |
|
1252 | - protected function db_relation_n_n_delete($field_info, $primary_key_value) |
|
1253 | - { |
|
1254 | - $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); |
|
1255 | - } |
|
1256 | - |
|
1257 | - protected function get_list() |
|
1258 | - { |
|
1259 | - if(!empty($this->order_by)) |
|
1260 | - $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
1261 | - |
|
1262 | - if(!empty($this->where)) |
|
1263 | - foreach($this->where as $where) |
|
1264 | - $this->basic_model->where($where[0],$where[1],$where[2]); |
|
1265 | - |
|
1266 | - if(!empty($this->or_where)) |
|
1267 | - foreach($this->or_where as $or_where) |
|
1268 | - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
1269 | - |
|
1270 | - if(!empty($this->like)) |
|
1271 | - foreach($this->like as $like) |
|
1272 | - $this->basic_model->like($like[0],$like[1],$like[2]); |
|
1273 | - |
|
1274 | - if(!empty($this->or_like)) |
|
1275 | - foreach($this->or_like as $or_like) |
|
1276 | - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
1277 | - |
|
1278 | - if(!empty($this->having)) |
|
1279 | - foreach($this->having as $having) |
|
1280 | - $this->basic_model->having($having[0],$having[1],$having[2]); |
|
1281 | - |
|
1282 | - if(!empty($this->or_having)) |
|
1283 | - foreach($this->or_having as $or_having) |
|
1284 | - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
1285 | - |
|
1286 | - if(!empty($this->relation)) |
|
1287 | - foreach($this->relation as $relation) |
|
1288 | - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
1289 | - |
|
1290 | - if(!empty($this->relation_n_n)) |
|
1291 | - { |
|
1292 | - $columns = $this->get_columns(); |
|
1293 | - foreach($columns as $column) |
|
1294 | - { |
|
1295 | - //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
1296 | - if(isset($this->relation_n_n[$column->field_name])) |
|
1297 | - { |
|
1298 | - $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
1299 | - } |
|
1300 | - } |
|
1301 | - |
|
1302 | - } |
|
1303 | - |
|
1304 | - if($this->theme_config['crud_paging'] === true) |
|
1305 | - { |
|
1306 | - if($this->limit === null) |
|
1307 | - { |
|
1308 | - $default_per_page = $this->config->default_per_page; |
|
1309 | - if(is_numeric($default_per_page) && $default_per_page >1) |
|
1310 | - { |
|
1311 | - $this->basic_model->limit($default_per_page); |
|
1312 | - } |
|
1313 | - else |
|
1314 | - { |
|
1315 | - $this->basic_model->limit(10); |
|
1316 | - } |
|
1317 | - } |
|
1318 | - else |
|
1319 | - { |
|
1320 | - $this->basic_model->limit($this->limit[0],$this->limit[1]); |
|
1321 | - } |
|
1322 | - } |
|
1323 | - |
|
1324 | - $results = $this->basic_model->get_list(); |
|
1325 | - |
|
1326 | - return $results; |
|
1327 | - } |
|
1328 | - |
|
1329 | - protected function get_edit_values($primary_key_value) |
|
1330 | - { |
|
1331 | - $values = $this->basic_model->get_edit_values($primary_key_value); |
|
1332 | - |
|
1333 | - if(!empty($this->relation_n_n)) |
|
1334 | - { |
|
1335 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
1336 | - { |
|
1337 | - $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
1338 | - } |
|
1339 | - } |
|
1340 | - |
|
1341 | - return $values; |
|
1342 | - } |
|
1343 | - |
|
1344 | - protected function get_relation_n_n_selection_array($primary_key_value, $field_info) |
|
1345 | - { |
|
1346 | - return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
1347 | - } |
|
1348 | - |
|
1349 | - protected function get_relation_n_n_unselected_array($field_info, $selected_values) |
|
1350 | - { |
|
1351 | - return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
1352 | - } |
|
1353 | - |
|
1354 | - protected function set_basic_db_table($table_name = null) |
|
1355 | - { |
|
1356 | - $this->basic_model->set_basic_table($table_name); |
|
1357 | - } |
|
1358 | - |
|
1359 | - protected function upload_file($state_info) |
|
1360 | - { |
|
1361 | - if(isset($this->upload_fields[$state_info->field_name]) ) |
|
1362 | - { |
|
1363 | - if($this->callback_upload === null) |
|
1364 | - { |
|
1365 | - if($this->callback_before_upload !== null) |
|
1366 | - { |
|
1367 | - $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
1368 | - |
|
1369 | - if($callback_before_upload_response === false) |
|
1370 | - return false; |
|
1371 | - elseif(is_string($callback_before_upload_response)) |
|
1372 | - return $callback_before_upload_response; |
|
1373 | - } |
|
1374 | - |
|
1375 | - $upload_info = $this->upload_fields[$state_info->field_name]; |
|
1376 | - |
|
1377 | - header('Pragma: no-cache'); |
|
1378 | - header('Cache-Control: private, no-cache'); |
|
1379 | - header('Content-Disposition: inline; filename="files.json"'); |
|
1380 | - header('X-Content-Type-Options: nosniff'); |
|
1381 | - header('Access-Control-Allow-Origin: *'); |
|
1382 | - header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); |
|
1383 | - header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); |
|
1384 | - |
|
1385 | - $allowed_files = $this->config->file_upload_allow_file_types; |
|
1386 | - |
|
1387 | - $reg_exp = ''; |
|
1388 | - if(!empty($upload_info->allowed_file_types)){ |
|
1389 | - $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; |
|
1390 | - }else{ |
|
1391 | - $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; |
|
1392 | - } |
|
1393 | - |
|
1394 | - $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
1395 | - $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
1396 | - |
|
1397 | - $options = array( |
|
1398 | - 'upload_dir' => $upload_info->upload_path.'/', |
|
1399 | - 'param_name' => $this->_unique_field_name($state_info->field_name), |
|
1400 | - 'upload_url' => base_url().$upload_info->upload_path.'/', |
|
1401 | - 'accept_file_types' => $reg_exp, |
|
1402 | - 'max_file_size' => $max_file_size_bytes |
|
1403 | - ); |
|
1404 | - $upload_handler = new UploadHandler($options); |
|
1405 | - $upload_handler->default_config_path = $this->default_config_path; |
|
1406 | - $uploader_response = $upload_handler->post(); |
|
1407 | - |
|
1408 | - if(is_array($uploader_response)) |
|
1409 | - { |
|
1410 | - foreach($uploader_response as &$response) |
|
1411 | - { |
|
1412 | - unset($response->delete_url); |
|
1413 | - unset($response->delete_type); |
|
1414 | - } |
|
1415 | - } |
|
1416 | - |
|
1417 | - if($this->callback_after_upload !== null) |
|
1418 | - { |
|
1419 | - $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); |
|
1420 | - |
|
1421 | - if($callback_after_upload_response === false) |
|
1422 | - return false; |
|
1423 | - elseif(is_string($callback_after_upload_response)) |
|
1424 | - return $callback_after_upload_response; |
|
1425 | - elseif(is_array($callback_after_upload_response)) |
|
1426 | - $uploader_response = $callback_after_upload_response; |
|
1427 | - } |
|
1428 | - |
|
1429 | - return $uploader_response; |
|
1430 | - } |
|
1431 | - else |
|
1432 | - { |
|
1433 | - $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); |
|
1434 | - |
|
1435 | - if($upload_response === false) |
|
1436 | - { |
|
1437 | - return false; |
|
1438 | - } |
|
1439 | - else |
|
1440 | - { |
|
1441 | - return $upload_response; |
|
1442 | - } |
|
1443 | - } |
|
1444 | - } |
|
1445 | - else |
|
1446 | - { |
|
1447 | - return false; |
|
1448 | - } |
|
1449 | - } |
|
1450 | - |
|
1451 | - protected function delete_file($state_info) |
|
1452 | - { |
|
1453 | - |
|
1454 | - if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) |
|
1455 | - { |
|
1456 | - $upload_info = $this->upload_fields[$state_info->field_name]; |
|
1457 | - |
|
1458 | - if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
1459 | - { |
|
1460 | - if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) |
|
1461 | - { |
|
1462 | - $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
1463 | - |
|
1464 | - return true; |
|
1465 | - } |
|
1466 | - else |
|
1467 | - { |
|
1468 | - return false; |
|
1469 | - } |
|
1470 | - } |
|
1471 | - else |
|
1472 | - { |
|
1473 | - $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
1474 | - return true; |
|
1475 | - } |
|
1476 | - } |
|
1477 | - else |
|
1478 | - { |
|
1479 | - return false; |
|
1480 | - } |
|
1481 | - } |
|
1482 | - |
|
1483 | - protected function ajax_relation($state_info) |
|
1484 | - { |
|
1485 | - if(!isset($this->relation[$state_info->field_name])) |
|
1486 | - return false; |
|
1487 | - |
|
1488 | - list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
|
1489 | - |
|
1490 | - return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); |
|
1491 | - } |
|
1492 | -} |
|
681 | + protected function get_relation_total_rows($relation_info) |
|
682 | + { |
|
683 | + list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; |
|
1493 | 684 | |
685 | + $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); |
|
1494 | 686 | |
1495 | -/** |
|
1496 | - * PHP grocery CRUD |
|
1497 | - * |
|
1498 | - * LICENSE |
|
1499 | - * |
|
1500 | - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
1501 | - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
1502 | - * Please see the corresponding license file for details of these licenses. |
|
1503 | - * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
1504 | - * |
|
1505 | - * @package grocery CRUD |
|
1506 | - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
1507 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
1508 | - * @author John Skoumbourdis <[email protected]> |
|
1509 | - */ |
|
687 | + return $relation_array; |
|
688 | + } |
|
1510 | 689 | |
1511 | -// ------------------------------------------------------------------------ |
|
690 | + protected function db_insert_validation() |
|
691 | + { |
|
692 | + $validation_result = (object)array('success'=>false); |
|
1512 | 693 | |
1513 | -/** |
|
1514 | - * PHP grocery Layout |
|
1515 | - * |
|
1516 | - * Here you manage all the HTML Layout |
|
1517 | - * |
|
1518 | - * @package grocery CRUD |
|
1519 | - * @author John Skoumbourdis <[email protected]> |
|
1520 | - * @version 1.5.6 |
|
1521 | - */ |
|
1522 | -class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver |
|
1523 | -{ |
|
1524 | - private $theme_path = null; |
|
1525 | - private $views_as_string = ''; |
|
1526 | - private $echo_and_die = false; |
|
1527 | - protected $theme = null; |
|
1528 | - protected $default_true_false_text = array('inactive' , 'active'); |
|
694 | + $field_types = $this->get_field_types(); |
|
695 | + $required_fields = $this->required_fields; |
|
696 | + $unique_fields = $this->_unique_fields; |
|
697 | + $add_fields = $this->get_add_fields(); |
|
1529 | 698 | |
1530 | - protected $css_files = array(); |
|
1531 | - protected $js_files = array(); |
|
1532 | - protected $js_lib_files = array(); |
|
1533 | - protected $js_config_files = array(); |
|
699 | + if(!empty($required_fields)) |
|
700 | + { |
|
701 | + foreach($add_fields as $add_field) |
|
702 | + { |
|
703 | + $field_name = $add_field->field_name; |
|
704 | + if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
705 | + { |
|
706 | + $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
707 | + } |
|
708 | + } |
|
709 | + } |
|
1534 | 710 | |
1535 | - protected function set_basic_Layout() |
|
1536 | - { |
|
1537 | - if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) |
|
1538 | - { |
|
1539 | - throw new Exception('The template does not exist. Please check your files and try again.', 12); |
|
1540 | - die(); |
|
1541 | - } |
|
1542 | - } |
|
711 | + /** Checking for unique fields. If the field value is not unique then |
|
712 | + * return a validation error straight away, if not continue... */ |
|
713 | + if(!empty($unique_fields)) |
|
714 | + { |
|
715 | + $form_validation = $this->form_validation(); |
|
1543 | 716 | |
1544 | - protected function showList($ajax = false, $state_info = null) |
|
1545 | - { |
|
1546 | - $data = $this->get_common_data(); |
|
717 | + foreach($add_fields as $add_field) |
|
718 | + { |
|
719 | + $field_name = $add_field->field_name; |
|
720 | + if(in_array( $field_name, $unique_fields) ) |
|
721 | + { |
|
722 | + $form_validation->set_rules( $field_name, |
|
723 | + $field_types[$field_name]->display_as, |
|
724 | + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
725 | + } |
|
726 | + } |
|
1547 | 727 | |
1548 | - $data->order_by = $this->order_by; |
|
728 | + if(!$form_validation->run()) |
|
729 | + { |
|
730 | + $validation_result->error_message = $form_validation->error_string(); |
|
731 | + $validation_result->error_fields = $form_validation->_error_array; |
|
1549 | 732 | |
1550 | - $data->types = $this->get_field_types(); |
|
733 | + return $validation_result; |
|
734 | + } |
|
735 | + } |
|
1551 | 736 | |
1552 | - $data->list = $this->get_list(); |
|
1553 | - $data->list = $this->change_list($data->list , $data->types); |
|
1554 | - $data->list = $this->change_list_add_actions($data->list); |
|
737 | + if(!empty($this->validation_rules)) |
|
738 | + { |
|
739 | + $form_validation = $this->form_validation(); |
|
1555 | 740 | |
1556 | - $data->total_results = $this->get_total_results(); |
|
741 | + $add_fields = $this->get_add_fields(); |
|
1557 | 742 | |
1558 | - $data->columns = $this->get_columns(); |
|
743 | + foreach($add_fields as $add_field) |
|
744 | + { |
|
745 | + $field_name = $add_field->field_name; |
|
746 | + if(isset($this->validation_rules[$field_name])) |
|
747 | + { |
|
748 | + $rule = $this->validation_rules[$field_name]; |
|
749 | + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
750 | + } |
|
751 | + } |
|
1559 | 752 | |
1560 | - $data->success_message = $this->get_success_message_at_list($state_info); |
|
753 | + if($form_validation->run()) |
|
754 | + { |
|
755 | + $validation_result->success = true; |
|
756 | + } |
|
757 | + else |
|
758 | + { |
|
759 | + $validation_result->error_message = $form_validation->error_string(); |
|
760 | + $validation_result->error_fields = $form_validation->_error_array; |
|
761 | + } |
|
762 | + } |
|
763 | + else |
|
764 | + { |
|
765 | + $validation_result->success = true; |
|
766 | + } |
|
1561 | 767 | |
1562 | - $data->primary_key = $this->get_primary_key(); |
|
1563 | - $data->add_url = $this->getAddUrl(); |
|
1564 | - $data->edit_url = $this->getEditUrl(); |
|
1565 | - $data->delete_url = $this->getDeleteUrl(); |
|
1566 | - $data->delete_multiple_url = $this->getDeleteMultipleUrl(); |
|
1567 | - $data->read_url = $this->getReadUrl(); |
|
1568 | - $data->ajax_list_url = $this->getAjaxListUrl(); |
|
1569 | - $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); |
|
1570 | - $data->export_url = $this->getExportToExcelUrl(); |
|
1571 | - $data->print_url = $this->getPrintUrl(); |
|
1572 | - $data->actions = $this->actions; |
|
1573 | - $data->unique_hash = $this->get_method_hash(); |
|
1574 | - $data->order_by = $this->order_by; |
|
1575 | - |
|
1576 | - $data->unset_add = $this->unset_add; |
|
1577 | - $data->unset_edit = $this->unset_edit; |
|
1578 | - $data->unset_read = $this->unset_read; |
|
1579 | - $data->unset_delete = $this->unset_delete; |
|
1580 | - $data->unset_export = $this->unset_export; |
|
1581 | - $data->unset_print = $this->unset_print; |
|
1582 | - |
|
1583 | - $default_per_page = $this->config->default_per_page; |
|
1584 | - $data->paging_options = $this->config->paging_options; |
|
1585 | - $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; |
|
1586 | - |
|
1587 | - if($data->list === false) |
|
1588 | - { |
|
1589 | - throw new Exception('It is impossible to get data. Please check your model and try again.', 13); |
|
1590 | - $data->list = array(); |
|
1591 | - } |
|
1592 | - |
|
1593 | - foreach($data->list as $num_row => $row) |
|
1594 | - { |
|
1595 | - $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; |
|
1596 | - $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; |
|
1597 | - $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; |
|
1598 | - $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; |
|
1599 | - } |
|
1600 | - |
|
1601 | - if(!$ajax) |
|
1602 | - { |
|
1603 | - $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); |
|
1604 | - |
|
1605 | - $data->list_view = $this->_theme_view('list.php',$data,true); |
|
1606 | - $this->_theme_view('list_template.php',$data); |
|
1607 | - } |
|
1608 | - else |
|
1609 | - { |
|
1610 | - $this->set_echo_and_die(); |
|
1611 | - $this->_theme_view('list.php',$data); |
|
1612 | - } |
|
1613 | - } |
|
1614 | - |
|
1615 | - protected function exportToExcel($state_info = null) |
|
1616 | - { |
|
1617 | - $data = $this->get_common_data(); |
|
1618 | - |
|
1619 | - $data->order_by = $this->order_by; |
|
1620 | - $data->types = $this->get_field_types(); |
|
1621 | - |
|
1622 | - $data->list = $this->get_list(); |
|
1623 | - $data->list = $this->change_list($data->list , $data->types); |
|
1624 | - $data->list = $this->change_list_add_actions($data->list); |
|
1625 | - |
|
1626 | - $data->total_results = $this->get_total_results(); |
|
1627 | - |
|
1628 | - $data->columns = $this->get_columns(); |
|
1629 | - $data->primary_key = $this->get_primary_key(); |
|
1630 | - |
|
1631 | - @ob_end_clean(); |
|
1632 | - $this->_export_to_excel($data); |
|
1633 | - } |
|
1634 | - |
|
1635 | - protected function _export_to_excel($data) |
|
1636 | - { |
|
1637 | - /** |
|
1638 | - * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining |
|
1639 | - * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. |
|
1640 | - * */ |
|
1641 | - |
|
1642 | - $string_to_export = ""; |
|
1643 | - foreach($data->columns as $column){ |
|
1644 | - $string_to_export .= $column->display_as."\t"; |
|
1645 | - } |
|
1646 | - $string_to_export .= "\n"; |
|
1647 | - |
|
1648 | - foreach($data->list as $num_row => $row){ |
|
1649 | - foreach($data->columns as $column){ |
|
1650 | - $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; |
|
1651 | - } |
|
1652 | - $string_to_export .= "\n"; |
|
1653 | - } |
|
1654 | - |
|
1655 | - // Convert to UTF-16LE and Prepend BOM |
|
1656 | - $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); |
|
1657 | - |
|
1658 | - $filename = "export-".date("Y-m-d_H:i:s").".xls"; |
|
1659 | - |
|
1660 | - header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); |
|
1661 | - header('Content-Disposition: attachment; filename='.$filename); |
|
1662 | - header("Cache-Control: no-cache"); |
|
1663 | - echo $string_to_export; |
|
1664 | - die(); |
|
1665 | - } |
|
1666 | - |
|
1667 | - protected function print_webpage($state_info = null) |
|
1668 | - { |
|
1669 | - $data = $this->get_common_data(); |
|
1670 | - |
|
1671 | - $data->order_by = $this->order_by; |
|
1672 | - $data->types = $this->get_field_types(); |
|
1673 | - |
|
1674 | - $data->list = $this->get_list(); |
|
1675 | - $data->list = $this->change_list($data->list , $data->types); |
|
1676 | - $data->list = $this->change_list_add_actions($data->list); |
|
1677 | - |
|
1678 | - $data->total_results = $this->get_total_results(); |
|
1679 | - |
|
1680 | - $data->columns = $this->get_columns(); |
|
1681 | - $data->primary_key = $this->get_primary_key(); |
|
1682 | - |
|
1683 | - @ob_end_clean(); |
|
1684 | - $this->_print_webpage($data); |
|
1685 | - } |
|
1686 | - |
|
1687 | - protected function _print_webpage($data) |
|
1688 | - { |
|
1689 | - $string_to_print = "<meta charset=\"utf-8\" /><style type=\"text/css\" > |
|
1690 | - #print-table{ color: #000; background: #fff; font-family: Verdana,Tahoma,Helvetica,sans-serif; font-size: 13px;} |
|
1691 | - #print-table table tr td, #print-table table tr th{ border: 1px solid black; border-bottom: none; border-right: none; padding: 4px 8px 4px 4px} |
|
1692 | - #print-table table{ border-bottom: 1px solid black; border-right: 1px solid black} |
|
1693 | - #print-table table tr th{text-align: left;background: #ddd} |
|
1694 | - #print-table table tr:nth-child(odd){background: #eee} |
|
1695 | - </style>"; |
|
1696 | - $string_to_print .= "<div id='print-table'>"; |
|
1697 | - |
|
1698 | - $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>'; |
|
1699 | - foreach($data->columns as $column){ |
|
1700 | - $string_to_print .= "<th>".$column->display_as."</th>"; |
|
1701 | - } |
|
1702 | - $string_to_print .= "</tr>"; |
|
1703 | - |
|
1704 | - foreach($data->list as $num_row => $row){ |
|
1705 | - $string_to_print .= "<tr>"; |
|
1706 | - foreach($data->columns as $column){ |
|
1707 | - $string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>"; |
|
1708 | - } |
|
1709 | - $string_to_print .= "</tr>"; |
|
1710 | - } |
|
1711 | - |
|
1712 | - $string_to_print .= "</table></div>"; |
|
1713 | - |
|
1714 | - echo $string_to_print; |
|
1715 | - die(); |
|
1716 | - } |
|
1717 | - |
|
1718 | - protected function _trim_export_string($value) |
|
1719 | - { |
|
1720 | - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
1721 | - return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); |
|
1722 | - } |
|
1723 | - |
|
1724 | - protected function _trim_print_string($value) |
|
1725 | - { |
|
1726 | - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
1727 | - |
|
1728 | - //If the value has only spaces and nothing more then add the whitespace html character |
|
1729 | - if(str_replace(" ","",$value) == "") |
|
1730 | - $value = " "; |
|
1731 | - |
|
1732 | - return strip_tags($value); |
|
1733 | - } |
|
1734 | - |
|
1735 | - protected function set_echo_and_die() |
|
1736 | - { |
|
1737 | - $this->echo_and_die = true; |
|
1738 | - } |
|
1739 | - |
|
1740 | - protected function unset_echo_and_die() |
|
1741 | - { |
|
1742 | - $this->echo_and_die = false; |
|
1743 | - } |
|
1744 | - |
|
1745 | - protected function showListInfo() |
|
1746 | - { |
|
1747 | - $this->set_echo_and_die(); |
|
1748 | - |
|
1749 | - $total_results = (int)$this->get_total_results(); |
|
1750 | - @ob_end_clean(); |
|
1751 | - echo json_encode(array('total_results' => $total_results)); |
|
1752 | - die(); |
|
1753 | - } |
|
1754 | - |
|
1755 | - protected function change_list_add_actions($list) |
|
1756 | - { |
|
1757 | - if(empty($this->actions)) |
|
1758 | - return $list; |
|
1759 | - |
|
1760 | - $primary_key = $this->get_primary_key(); |
|
1761 | - |
|
1762 | - foreach($list as $num_row => $row) |
|
1763 | - { |
|
1764 | - $actions_urls = array(); |
|
1765 | - foreach($this->actions as $unique_id => $action) |
|
1766 | - { |
|
1767 | - if(!empty($action->url_callback)) |
|
1768 | - { |
|
1769 | - $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); |
|
1770 | - } |
|
1771 | - else |
|
1772 | - { |
|
1773 | - $actions_urls[$unique_id] = |
|
1774 | - $action->url_has_http ? |
|
1775 | - $action->link_url.$row->$primary_key : |
|
1776 | - site_url($action->link_url.'/'.$row->$primary_key); |
|
1777 | - } |
|
1778 | - } |
|
1779 | - $row->action_urls = $actions_urls; |
|
1780 | - } |
|
1781 | - |
|
1782 | - return $list; |
|
1783 | - } |
|
1784 | - |
|
1785 | - protected function change_list($list,$types) |
|
1786 | - { |
|
1787 | - $primary_key = $this->get_primary_key(); |
|
1788 | - $has_callbacks = !empty($this->callback_column) ? true : false; |
|
1789 | - $output_columns = $this->get_columns(); |
|
1790 | - foreach($list as $num_row => $row) |
|
1791 | - { |
|
1792 | - foreach($output_columns as $column) |
|
1793 | - { |
|
1794 | - $field_name = $column->field_name; |
|
1795 | - $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
|
1796 | - if( $has_callbacks && isset($this->callback_column[$field_name]) ) |
|
1797 | - $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
|
1798 | - elseif(isset($types[$field_name])) |
|
1799 | - $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
1800 | - else |
|
1801 | - $list[$num_row]->$field_name = $field_value; |
|
1802 | - } |
|
1803 | - } |
|
1804 | - |
|
1805 | - return $list; |
|
1806 | - } |
|
1807 | - |
|
1808 | - protected function showAddForm() |
|
1809 | - { |
|
1810 | - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
1811 | - |
|
1812 | - $data = $this->get_common_data(); |
|
1813 | - $data->types = $this->get_field_types(); |
|
1814 | - |
|
1815 | - $data->list_url = $this->getListUrl(); |
|
1816 | - $data->insert_url = $this->getInsertUrl(); |
|
1817 | - $data->validation_url = $this->getValidationInsertUrl(); |
|
1818 | - $data->input_fields = $this->get_add_input_fields(); |
|
1819 | - |
|
1820 | - $data->fields = $this->get_add_fields(); |
|
1821 | - $data->hidden_fields = $this->get_add_hidden_fields(); |
|
1822 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
1823 | - $data->unique_hash = $this->get_method_hash(); |
|
1824 | - $data->is_ajax = $this->_is_ajax(); |
|
1825 | - |
|
1826 | - $this->_theme_view('add.php',$data); |
|
1827 | - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
1828 | - |
|
1829 | - $this->_get_ajax_results(); |
|
1830 | - } |
|
1831 | - |
|
1832 | - protected function showEditForm($state_info) |
|
1833 | - { |
|
1834 | - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
1835 | - |
|
1836 | - $data = $this->get_common_data(); |
|
1837 | - $data->types = $this->get_field_types(); |
|
1838 | - |
|
1839 | - $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
1840 | - |
|
1841 | - $data->add_url = $this->getAddUrl(); |
|
1842 | - |
|
1843 | - $data->list_url = $this->getListUrl(); |
|
1844 | - $data->update_url = $this->getUpdateUrl($state_info); |
|
1845 | - $data->delete_url = $this->getDeleteUrl($state_info); |
|
1846 | - $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
1847 | - $data->input_fields = $this->get_edit_input_fields($data->field_values); |
|
1848 | - $data->unique_hash = $this->get_method_hash(); |
|
1849 | - |
|
1850 | - $data->fields = $this->get_edit_fields(); |
|
1851 | - $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
1852 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
1853 | - |
|
1854 | - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
1855 | - $data->is_ajax = $this->_is_ajax(); |
|
1856 | - |
|
1857 | - $this->_theme_view('edit.php',$data); |
|
1858 | - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
1859 | - |
|
1860 | - $this->_get_ajax_results(); |
|
1861 | - } |
|
1862 | - |
|
1863 | - protected function showReadForm($state_info) |
|
1864 | - { |
|
1865 | - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
1866 | - |
|
1867 | - $data = $this->get_common_data(); |
|
1868 | - $data->types = $this->get_field_types(); |
|
1869 | - |
|
1870 | - $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
1871 | - |
|
1872 | - $data->add_url = $this->getAddUrl(); |
|
1873 | - |
|
1874 | - $data->list_url = $this->getListUrl(); |
|
1875 | - $data->update_url = $this->getUpdateUrl($state_info); |
|
1876 | - $data->delete_url = $this->getDeleteUrl($state_info); |
|
1877 | - $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
1878 | - $data->input_fields = $this->get_read_input_fields($data->field_values); |
|
1879 | - $data->unique_hash = $this->get_method_hash(); |
|
1880 | - |
|
1881 | - $data->fields = $this->get_read_fields(); |
|
1882 | - $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
1883 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
1884 | - |
|
1885 | - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
1886 | - $data->is_ajax = $this->_is_ajax(); |
|
1887 | - |
|
1888 | - $this->_theme_view('read.php',$data); |
|
1889 | - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
1890 | - |
|
1891 | - $this->_get_ajax_results(); |
|
1892 | - } |
|
1893 | - |
|
1894 | - protected function delete_layout($delete_result = true) |
|
1895 | - { |
|
1896 | - @ob_end_clean(); |
|
1897 | - if($delete_result === false) |
|
1898 | - { |
|
1899 | - $error_message = '<p>'.$this->l('delete_error_message').'</p>'; |
|
1900 | - |
|
1901 | - echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); |
|
1902 | - } |
|
1903 | - else |
|
1904 | - { |
|
1905 | - $success_message = '<p>'.$this->l('delete_success_message').'</p>'; |
|
1906 | - |
|
1907 | - echo json_encode(array('success' => true , 'success_message' => $success_message)); |
|
1908 | - } |
|
1909 | - $this->set_echo_and_die(); |
|
1910 | - } |
|
1911 | - |
|
1912 | - protected function get_success_message_at_list($field_info = null) |
|
1913 | - { |
|
1914 | - if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) |
|
1915 | - { |
|
1916 | - if(!empty($field_info->primary_key) && !$this->unset_edit) |
|
1917 | - { |
|
1918 | - return $this->l('insert_success_message')." <a class='go-to-edit-form' href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
1919 | - } |
|
1920 | - else |
|
1921 | - { |
|
1922 | - return $this->l('insert_success_message'); |
|
1923 | - } |
|
1924 | - } |
|
1925 | - else |
|
1926 | - { |
|
1927 | - return null; |
|
1928 | - } |
|
1929 | - } |
|
1930 | - |
|
1931 | - protected function insert_layout($insert_result = false) |
|
1932 | - { |
|
1933 | - @ob_end_clean(); |
|
1934 | - if($insert_result === false) |
|
1935 | - { |
|
1936 | - echo json_encode(array('success' => false)); |
|
1937 | - } |
|
1938 | - else |
|
1939 | - { |
|
1940 | - $success_message = '<p>'.$this->l('insert_success_message'); |
|
1941 | - |
|
1942 | - if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) |
|
1943 | - { |
|
1944 | - $success_message .= " <a class='go-to-edit-form' href='".$this->getEditUrl($insert_result)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
1945 | - |
|
1946 | - if (!$this->_is_ajax()) { |
|
1947 | - $success_message .= $this->l('form_or'); |
|
1948 | - } |
|
1949 | - } |
|
1950 | - |
|
1951 | - if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
1952 | - { |
|
1953 | - $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
1954 | - } |
|
1955 | - |
|
1956 | - $success_message .= '</p>'; |
|
1957 | - |
|
1958 | - echo json_encode(array( |
|
1959 | - 'success' => true , |
|
1960 | - 'insert_primary_key' => $insert_result, |
|
1961 | - 'success_message' => $success_message, |
|
1962 | - 'success_list_url' => $this->getListSuccessUrl($insert_result) |
|
1963 | - )); |
|
1964 | - } |
|
1965 | - $this->set_echo_and_die(); |
|
1966 | - } |
|
1967 | - |
|
1968 | - protected function validation_layout($validation_result) |
|
1969 | - { |
|
1970 | - @ob_end_clean(); |
|
1971 | - echo json_encode($validation_result); |
|
1972 | - $this->set_echo_and_die(); |
|
1973 | - } |
|
1974 | - |
|
1975 | - protected function upload_layout($upload_result, $field_name) |
|
1976 | - { |
|
1977 | - @ob_end_clean(); |
|
1978 | - if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) |
|
1979 | - { |
|
1980 | - echo json_encode( |
|
1981 | - (object)array( |
|
1982 | - 'success' => true, |
|
1983 | - 'files' => $upload_result |
|
1984 | - )); |
|
1985 | - } |
|
1986 | - else |
|
1987 | - { |
|
1988 | - $result = (object)array('success' => false); |
|
1989 | - if(is_string($upload_result)) |
|
1990 | - $result->message = $upload_result; |
|
1991 | - if(!empty($upload_result[0]->error)) |
|
1992 | - $result->message = $upload_result[0]->error; |
|
1993 | - |
|
1994 | - echo json_encode($result); |
|
1995 | - } |
|
1996 | - |
|
1997 | - $this->set_echo_and_die(); |
|
1998 | - } |
|
1999 | - |
|
2000 | - protected function delete_file_layout($upload_result) |
|
2001 | - { |
|
2002 | - @ob_end_clean(); |
|
2003 | - if($upload_result !== false) |
|
2004 | - { |
|
2005 | - echo json_encode( (object)array( 'success' => true ) ); |
|
2006 | - } |
|
2007 | - else |
|
2008 | - { |
|
2009 | - echo json_encode((object)array('success' => false)); |
|
2010 | - } |
|
2011 | - |
|
2012 | - $this->set_echo_and_die(); |
|
2013 | - } |
|
2014 | - |
|
2015 | - public function set_css($css_file) |
|
2016 | - { |
|
2017 | - $this->css_files[sha1($css_file)] = base_url().$css_file; |
|
2018 | - } |
|
2019 | - |
|
2020 | - public function set_js($js_file) |
|
2021 | - { |
|
2022 | - $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
2023 | - } |
|
2024 | - |
|
2025 | - public function set_js_lib($js_file) |
|
2026 | - { |
|
2027 | - $this->js_lib_files[sha1($js_file)] = base_url().$js_file; |
|
2028 | - $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
2029 | - } |
|
2030 | - |
|
2031 | - public function set_js_config($js_file) |
|
2032 | - { |
|
2033 | - $this->js_config_files[sha1($js_file)] = base_url().$js_file; |
|
2034 | - $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
2035 | - } |
|
2036 | - |
|
2037 | - public function is_IE7() |
|
2038 | - { |
|
2039 | - return isset($_SERVER['HTTP_USER_AGENT']) |
|
2040 | - && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) |
|
2041 | - ? true : false; |
|
2042 | - } |
|
2043 | - |
|
2044 | - public function get_css_files() |
|
2045 | - { |
|
2046 | - return $this->css_files; |
|
2047 | - } |
|
2048 | - |
|
2049 | - public function get_js_files() |
|
2050 | - { |
|
2051 | - return $this->js_files; |
|
2052 | - } |
|
2053 | - |
|
2054 | - public function get_js_lib_files() |
|
2055 | - { |
|
2056 | - return $this->js_lib_files; |
|
2057 | - } |
|
2058 | - |
|
2059 | - public function get_js_config_files() |
|
2060 | - { |
|
2061 | - return $this->js_config_files; |
|
2062 | - } |
|
2063 | - |
|
2064 | - /** |
|
2065 | - * Load Javascripts |
|
2066 | - **/ |
|
2067 | - protected function load_js_fancybox() |
|
2068 | - { |
|
2069 | - $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); |
|
2070 | - |
|
2071 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); |
|
2072 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); |
|
2073 | - } |
|
2074 | - |
|
2075 | - protected function load_js_chosen() |
|
2076 | - { |
|
2077 | - $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
2078 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
2079 | - } |
|
2080 | - |
|
2081 | - protected function load_js_jqueryui() |
|
2082 | - { |
|
2083 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2084 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2085 | - } |
|
2086 | - |
|
2087 | - protected function load_js_uploader() |
|
2088 | - { |
|
2089 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2090 | - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); |
|
2091 | - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); |
|
2092 | - |
|
2093 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2094 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); |
|
2095 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); |
|
2096 | - |
|
2097 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); |
|
2098 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); |
|
2099 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); |
|
2100 | - } |
|
2101 | - |
|
2102 | - protected function get_layout() |
|
2103 | - { |
|
2104 | - $js_files = $this->get_js_files(); |
|
2105 | - $css_files = $this->get_css_files(); |
|
2106 | - |
|
2107 | - $js_lib_files = $this->get_js_lib_files(); |
|
2108 | - $js_config_files = $this->get_js_config_files(); |
|
2109 | - |
|
2110 | - if ($this->unset_jquery) { |
|
2111 | - unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); |
|
2112 | - } |
|
2113 | - |
|
2114 | - if ($this->unset_jquery_ui) { |
|
2115 | - unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); |
|
2116 | - unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); |
|
2117 | - } |
|
2118 | - |
|
2119 | - if ($this->unset_bootstrap) { |
|
2120 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); |
|
2121 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); |
|
2122 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); |
|
2123 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); |
|
2124 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); |
|
2125 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); |
|
2126 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.css')]); |
|
2127 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); |
|
2128 | - } |
|
2129 | - |
|
2130 | - if($this->echo_and_die === false) |
|
2131 | - { |
|
2132 | - /** Initialize JavaScript variables */ |
|
2133 | - $js_vars = array( |
|
2134 | - 'default_javascript_path' => base_url().$this->default_javascript_path, |
|
2135 | - 'default_css_path' => base_url().$this->default_css_path, |
|
2136 | - 'default_texteditor_path' => base_url().$this->default_texteditor_path, |
|
2137 | - 'default_theme_path' => base_url().$this->default_theme_path, |
|
2138 | - 'base_url' => base_url() |
|
2139 | - ); |
|
2140 | - $this->_add_js_vars($js_vars); |
|
2141 | - |
|
2142 | - return (object)array( |
|
2143 | - 'js_files' => $js_files, |
|
2144 | - 'js_lib_files' => $js_lib_files, |
|
2145 | - 'js_config_files' => $js_config_files, |
|
2146 | - 'css_files' => $css_files, |
|
2147 | - 'output' => $this->views_as_string, |
|
2148 | - ); |
|
2149 | - } |
|
2150 | - elseif($this->echo_and_die === true) |
|
2151 | - { |
|
2152 | - echo $this->views_as_string; |
|
2153 | - die(); |
|
2154 | - } |
|
2155 | - } |
|
2156 | - |
|
2157 | - protected function update_layout($update_result = false, $state_info = null) |
|
2158 | - { |
|
2159 | - @ob_end_clean(); |
|
2160 | - if($update_result === false) |
|
2161 | - { |
|
2162 | - echo json_encode(array('success' => $update_result)); |
|
2163 | - } |
|
2164 | - else |
|
2165 | - { |
|
2166 | - $success_message = '<p>'.$this->l('update_success_message'); |
|
2167 | - if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
2168 | - { |
|
2169 | - $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
2170 | - } |
|
2171 | - $success_message .= '</p>'; |
|
2172 | - |
|
2173 | - echo json_encode(array( |
|
2174 | - 'success' => true , |
|
2175 | - 'insert_primary_key' => $update_result, |
|
2176 | - 'success_message' => $success_message, |
|
2177 | - 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) |
|
2178 | - )); |
|
2179 | - } |
|
2180 | - $this->set_echo_and_die(); |
|
2181 | - } |
|
2182 | - |
|
2183 | - protected function get_integer_input($field_info,$value) |
|
2184 | - { |
|
2185 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); |
|
2186 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); |
|
2187 | - $extra_attributes = ''; |
|
2188 | - if(!empty($field_info->db_max_length)) |
|
2189 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
2190 | - $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric form-control' $extra_attributes />"; |
|
2191 | - return $input; |
|
2192 | - } |
|
2193 | - |
|
2194 | - protected function get_true_false_input($field_info,$value) |
|
2195 | - { |
|
2196 | - $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; |
|
2197 | - |
|
2198 | - $input = "<div class='pretty-radio-buttons'>"; |
|
2199 | - |
|
2200 | - $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; |
|
2201 | - $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; |
|
2202 | - $input .= |
|
2203 | - "<div class=\"radio\"><label> |
|
2204 | - <input id='field-{$field_info->name}-true' type=\"radio\" name=\"{$field_info->name}\" value=\"1\" $checked /> |
|
2205 | - $true_string |
|
2206 | - </label> </div>"; |
|
2207 | - |
|
2208 | - $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; |
|
2209 | - $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; |
|
2210 | - $input .= |
|
2211 | - "<div class=\"radio\"><label> |
|
2212 | - <input id='field-{$field_info->name}-false' type=\"radio\" name=\"{$field_info->name}\" value=\"0\" $checked /> |
|
2213 | - $false_string |
|
2214 | - </label> </div>"; |
|
2215 | - |
|
2216 | - $input .= "</div>"; |
|
2217 | - |
|
2218 | - return $input; |
|
2219 | - } |
|
768 | + return $validation_result; |
|
769 | + } |
|
2220 | 770 | |
2221 | - protected function get_string_input($field_info,$value) |
|
2222 | - { |
|
2223 | - $value = !is_string($value) ? '' : str_replace('"',""",$value); |
|
771 | + protected function form_validation() |
|
772 | + { |
|
773 | + if($this->form_validation === null) |
|
774 | + { |
|
775 | + $this->form_validation = new grocery_CRUD_Form_validation(); |
|
776 | + $ci = &get_instance(); |
|
777 | + $ci->load->library('form_validation'); |
|
778 | + $ci->form_validation = $this->form_validation; |
|
779 | + } |
|
780 | + return $this->form_validation; |
|
781 | + } |
|
2224 | 782 | |
2225 | - $extra_attributes = ''; |
|
2226 | - if (!empty($field_info->db_max_length)) { |
|
783 | + protected function db_update_validation() |
|
784 | + { |
|
785 | + $validation_result = (object)array('success'=>false); |
|
2227 | 786 | |
2228 | - if (in_array($field_info->type, array("decimal", "float"))) { |
|
2229 | - $decimal_lentgh = explode(",", $field_info->db_max_length); |
|
2230 | - $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; |
|
787 | + $field_types = $this->get_field_types(); |
|
788 | + $required_fields = $this->required_fields; |
|
789 | + $unique_fields = $this->_unique_fields; |
|
790 | + $edit_fields = $this->get_edit_fields(); |
|
2231 | 791 | |
2232 | - $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; |
|
2233 | - } else { |
|
2234 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
792 | + if(!empty($required_fields)) |
|
793 | + { |
|
794 | + foreach($edit_fields as $edit_field) |
|
795 | + { |
|
796 | + $field_name = $edit_field->field_name; |
|
797 | + if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
798 | + { |
|
799 | + $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
800 | + } |
|
2235 | 801 | } |
2236 | - |
|
2237 | 802 | } |
2238 | - $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='text' value=\"$value\" $extra_attributes />"; |
|
2239 | - return $input; |
|
2240 | - } |
|
2241 | - |
|
2242 | - protected function get_text_input($field_info,$value) |
|
2243 | - { |
|
2244 | - if($field_info->extras == 'text_editor') |
|
2245 | - { |
|
2246 | - $editor = $this->config->default_text_editor; |
|
2247 | - switch ($editor) { |
|
2248 | - case 'ckeditor': |
|
2249 | - $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); |
|
2250 | - $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); |
|
2251 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); |
|
2252 | - break; |
|
2253 | - |
|
2254 | - case 'tinymce': |
|
2255 | - $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); |
|
2256 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); |
|
2257 | - break; |
|
2258 | - |
|
2259 | - case 'markitup': |
|
2260 | - $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); |
|
2261 | - $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); |
|
2262 | - |
|
2263 | - $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); |
|
2264 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); |
|
2265 | - break; |
|
2266 | - } |
|
2267 | - |
|
2268 | - $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; |
|
2269 | - |
|
2270 | - $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>"; |
|
2271 | - } |
|
2272 | - else |
|
2273 | - { |
|
2274 | - $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}'>$value</textarea>"; |
|
2275 | - } |
|
2276 | - return $input; |
|
2277 | - } |
|
2278 | - |
|
2279 | - protected function get_datetime_input($field_info,$value) |
|
2280 | - { |
|
2281 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2282 | - $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); |
|
2283 | - $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); |
|
2284 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2285 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); |
|
2286 | - |
|
2287 | - if($this->language !== 'english') |
|
2288 | - { |
|
2289 | - include($this->default_config_path.'/language_alias.php'); |
|
2290 | - if(array_key_exists($this->language, $language_alias)) |
|
2291 | - { |
|
2292 | - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
2293 | - if(file_exists($i18n_date_js_file)) |
|
2294 | - { |
|
2295 | - $this->set_js_lib($i18n_date_js_file); |
|
2296 | - } |
|
2297 | - |
|
2298 | - $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; |
|
2299 | - if(file_exists($i18n_datetime_js_file)) |
|
2300 | - { |
|
2301 | - $this->set_js_lib($i18n_datetime_js_file); |
|
2302 | - } |
|
2303 | - } |
|
2304 | - } |
|
2305 | - |
|
2306 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); |
|
2307 | - |
|
2308 | - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ |
|
2309 | - list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
2310 | - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
2311 | - $datetime = $date.substr($value,10); |
|
2312 | - } |
|
2313 | - else |
|
2314 | - { |
|
2315 | - $datetime = ''; |
|
2316 | - } |
|
2317 | - $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$datetime' maxlength='19' class='datetime-input form-control' /> |
|
2318 | - <a class='datetime-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> |
|
2319 | - ({$this->ui_date_format}) hh:mm:ss"; |
|
2320 | - return $input; |
|
2321 | - } |
|
2322 | - |
|
2323 | - protected function get_hidden_input($field_info,$value) |
|
2324 | - { |
|
2325 | - if($field_info->extras !== null && $field_info->extras != false) |
|
2326 | - $value = $field_info->extras; |
|
2327 | - $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; |
|
2328 | - return $input; |
|
2329 | - } |
|
2330 | - |
|
2331 | - protected function get_password_input($field_info,$value) |
|
2332 | - { |
|
2333 | - $value = !is_string($value) ? '' : $value; |
|
2334 | - |
|
2335 | - $extra_attributes = ''; |
|
2336 | - if(!empty($field_info->db_max_length)) |
|
2337 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
2338 | - $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; |
|
2339 | - return $input; |
|
2340 | - } |
|
2341 | - |
|
2342 | - protected function get_date_input($field_info,$value) |
|
2343 | - { |
|
2344 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2345 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2346 | - |
|
2347 | - if($this->language !== 'english') |
|
2348 | - { |
|
2349 | - include($this->default_config_path.'/language_alias.php'); |
|
2350 | - if(array_key_exists($this->language, $language_alias)) |
|
2351 | - { |
|
2352 | - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
2353 | - if(file_exists($i18n_date_js_file)) |
|
2354 | - { |
|
2355 | - $this->set_js_lib($i18n_date_js_file); |
|
2356 | - } |
|
2357 | - } |
|
2358 | - } |
|
2359 | - |
|
2360 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); |
|
2361 | - |
|
2362 | - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
2363 | - { |
|
2364 | - list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
2365 | - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
2366 | - } |
|
2367 | - else |
|
2368 | - { |
|
2369 | - $date = ''; |
|
2370 | - } |
|
2371 | - |
|
2372 | - $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$date' maxlength='10' class='datepicker-input form-control' /> |
|
2373 | - <a class='datepicker-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> (".$this->ui_date_format.")"; |
|
2374 | - return $input; |
|
2375 | - } |
|
2376 | - |
|
2377 | - protected function get_dropdown_input($field_info,$value) |
|
2378 | - { |
|
2379 | - $this->load_js_chosen(); |
|
2380 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2381 | - |
|
2382 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2383 | - |
|
2384 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
2385 | - $options = array('' => '') + $field_info->extras; |
|
2386 | - foreach($options as $option_value => $option_label) |
|
2387 | - { |
|
2388 | - $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
2389 | - $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
2390 | - } |
|
2391 | - |
|
2392 | - $input .= "</select>"; |
|
2393 | - return $input; |
|
2394 | - } |
|
2395 | - |
|
2396 | - protected function get_enum_input($field_info,$value) |
|
2397 | - { |
|
2398 | - $this->load_js_chosen(); |
|
2399 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2400 | - |
|
2401 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2402 | - |
|
2403 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
2404 | - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
2405 | - $options_array = array('' => '') + $options_array; |
|
2406 | - |
|
2407 | - foreach($options_array as $option) |
|
2408 | - { |
|
2409 | - $selected = !empty($value) && $value == $option ? "selected='selected'" : ''; |
|
2410 | - $input .= "<option value='$option' $selected >$option</option>"; |
|
2411 | - } |
|
2412 | - |
|
2413 | - $input .= "</select>"; |
|
2414 | - return $input; |
|
2415 | - } |
|
2416 | - |
|
2417 | - protected function get_readonly_input($field_info, $value) |
|
2418 | - { |
|
2419 | - $read_only_value = " "; |
|
2420 | - |
|
2421 | - if (!empty($value) && !is_array($value)) { |
|
2422 | - $read_only_value = $value; |
|
2423 | - } elseif (is_array($value)) { |
|
2424 | - $all_values = array_values($value); |
|
2425 | - $read_only_value = implode(", ",$all_values); |
|
2426 | - } |
|
2427 | - |
|
2428 | - return '<div id="field-'.$field_info->name.'" class="readonly_label">'.$read_only_value.'</div>'; |
|
2429 | - } |
|
2430 | - |
|
2431 | - protected function get_set_input($field_info,$value) |
|
2432 | - { |
|
2433 | - $this->load_js_chosen(); |
|
2434 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2435 | - |
|
2436 | - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
2437 | - $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
2438 | - |
|
2439 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2440 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
2441 | - |
|
2442 | - foreach($options_array as $option) |
|
2443 | - { |
|
2444 | - $selected = !empty($value) && in_array($option,$selected_values) ? "selected='selected'" : ''; |
|
2445 | - $input .= "<option value='$option' $selected >$option</option>"; |
|
2446 | - } |
|
2447 | 803 | |
2448 | - $input .= "</select>"; |
|
2449 | 804 | |
2450 | - return $input; |
|
2451 | - } |
|
805 | + /** Checking for unique fields. If the field value is not unique then |
|
806 | + * return a validation error straight away, if not continue... */ |
|
807 | + if(!empty($unique_fields)) |
|
808 | + { |
|
809 | + $form_validation = $this->form_validation(); |
|
2452 | 810 | |
2453 | - protected function get_multiselect_input($field_info,$value) |
|
2454 | - { |
|
2455 | - $this->load_js_chosen(); |
|
2456 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2457 | - |
|
2458 | - $options_array = $field_info->extras; |
|
2459 | - $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
2460 | - |
|
2461 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2462 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
2463 | - |
|
2464 | - foreach($options_array as $option_value => $option_label) |
|
2465 | - { |
|
2466 | - $selected = !empty($value) && in_array($option_value,$selected_values) ? "selected='selected'" : ''; |
|
2467 | - $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
2468 | - } |
|
2469 | - |
|
2470 | - $input .= "</select>"; |
|
2471 | - |
|
2472 | - return $input; |
|
2473 | - } |
|
2474 | - |
|
2475 | - protected function get_relation_input($field_info,$value) |
|
2476 | - { |
|
2477 | - $this->load_js_chosen(); |
|
2478 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2479 | - |
|
2480 | - $ajax_limitation = 10000; |
|
2481 | - $total_rows = $this->get_relation_total_rows($field_info->extras); |
|
2482 | - |
|
2483 | - |
|
2484 | - //Check if we will use ajax for our queries or just clien-side javascript |
|
2485 | - $using_ajax = $total_rows > $ajax_limitation ? true : false; |
|
2486 | - |
|
2487 | - //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 |
|
2488 | - $using_ajax = false; |
|
2489 | - |
|
2490 | - //If total rows are more than the limitation, use the ajax plugin |
|
2491 | - $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; |
|
2492 | - |
|
2493 | - $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
2494 | - |
|
2495 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2496 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='$ajax_or_not_class' data-placeholder='$select_title' style='width:300px'>"; |
|
2497 | - $input .= "<option value=''></option>"; |
|
2498 | - |
|
2499 | - if(!$using_ajax) |
|
2500 | - { |
|
2501 | - $options_array = $this->get_relation_array($field_info->extras); |
|
2502 | - foreach($options_array as $option_value => $option) |
|
2503 | - { |
|
2504 | - $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
2505 | - $input .= "<option value='$option_value' $selected >$option</option>"; |
|
2506 | - } |
|
2507 | - } |
|
2508 | - elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items |
|
2509 | - { |
|
2510 | - $selected_options_array = $this->get_relation_array($field_info->extras, $value); |
|
2511 | - foreach($selected_options_array as $option_value => $option) |
|
2512 | - { |
|
2513 | - $input .= "<option value='$option_value'selected='selected' >$option</option>"; |
|
2514 | - } |
|
2515 | - } |
|
2516 | - |
|
2517 | - $input .= "</select>"; |
|
2518 | - return $input; |
|
2519 | - } |
|
2520 | - |
|
2521 | - protected function get_relation_readonly_input($field_info,$value) |
|
2522 | - { |
|
2523 | - $options_array = $this->get_relation_array($field_info->extras); |
|
2524 | - |
|
2525 | - $value = isset($options_array[$value]) ? $options_array[$value] : ''; |
|
2526 | - |
|
2527 | - return $this->get_readonly_input($field_info, $value); |
|
2528 | - } |
|
2529 | - |
|
2530 | - protected function get_upload_file_readonly_input($field_info,$value) |
|
2531 | - { |
|
2532 | - $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
2533 | - |
|
2534 | - $value = !empty($value) ? '<a href="'.$file.'" target="_blank">'.$value.'</a>' : ''; |
|
2535 | - |
|
2536 | - return $this->get_readonly_input($field_info, $value); |
|
2537 | - } |
|
2538 | - |
|
2539 | - protected function get_relation_n_n_input($field_info_type, $selected_values) |
|
2540 | - { |
|
2541 | - $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; |
|
2542 | - $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; |
|
2543 | - |
|
2544 | - if($has_priority_field || $is_ie_7) |
|
2545 | - { |
|
2546 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2547 | - $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); |
|
2548 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2549 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); |
|
2550 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); |
|
2551 | - |
|
2552 | - if($this->language !== 'english') |
|
2553 | - { |
|
2554 | - include($this->default_config_path.'/language_alias.php'); |
|
2555 | - if(array_key_exists($this->language, $language_alias)) |
|
2556 | - { |
|
2557 | - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; |
|
2558 | - if(file_exists($i18n_date_js_file)) |
|
2559 | - { |
|
2560 | - $this->set_js_lib($i18n_date_js_file); |
|
2561 | - } |
|
2562 | - } |
|
2563 | - } |
|
2564 | - } |
|
2565 | - else |
|
2566 | - { |
|
2567 | - $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
2568 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
2569 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2570 | - } |
|
2571 | - |
|
2572 | - $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
2573 | - |
|
2574 | - $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check |
|
2575 | - $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
2576 | - |
|
2577 | - if(empty($unselected_values) && empty($selected_values)) |
|
2578 | - { |
|
2579 | - $input = "Please add {$field_info_type->display_as} first"; |
|
2580 | - } |
|
2581 | - else |
|
2582 | - { |
|
2583 | - $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; |
|
2584 | - $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; |
|
2585 | - |
|
2586 | - $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); |
|
2587 | - $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; |
|
2588 | - |
|
2589 | - if(!empty($unselected_values)) |
|
2590 | - foreach($unselected_values as $id => $name) |
|
2591 | - { |
|
2592 | - $input .= "<option value='$id'>$name</option>"; |
|
2593 | - } |
|
2594 | - |
|
2595 | - if(!empty($selected_values)) |
|
2596 | - foreach($selected_values as $id => $name) |
|
2597 | - { |
|
2598 | - $input .= "<option value='$id' selected='selected'>$name</option>"; |
|
2599 | - } |
|
2600 | - |
|
2601 | - $input .= "</select>"; |
|
2602 | - } |
|
2603 | - |
|
2604 | - return $input; |
|
2605 | - } |
|
2606 | - |
|
2607 | - protected function _convert_bytes_ui_to_bytes($bytes_ui) |
|
2608 | - { |
|
2609 | - $bytes_ui = str_replace(' ','',$bytes_ui); |
|
2610 | - if(strstr($bytes_ui,'MB')) |
|
2611 | - $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
2612 | - elseif(strstr($bytes_ui,'KB')) |
|
2613 | - $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
2614 | - elseif(strstr($bytes_ui,'B')) |
|
2615 | - $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
2616 | - else |
|
2617 | - $bytes = (int)($bytes_ui); |
|
2618 | - |
|
2619 | - return $bytes; |
|
2620 | - } |
|
2621 | - |
|
2622 | - protected function get_upload_file_input($field_info, $value) |
|
2623 | - { |
|
2624 | - $this->load_js_uploader(); |
|
2625 | - |
|
2626 | - //Fancybox |
|
2627 | - $this->load_js_fancybox(); |
|
2628 | - |
|
2629 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); |
|
2630 | - |
|
2631 | - $unique = mt_rand(); |
|
2632 | - |
|
2633 | - $allowed_files = $this->config->file_upload_allow_file_types; |
|
2634 | - $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); |
|
2635 | - $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
2636 | - $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
2637 | - |
|
2638 | - $this->_inline_js(' |
|
2639 | - var upload_info_'.$unique.' = { |
|
2640 | - accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, |
|
2641 | - accepted_file_types_ui : "'.$allowed_files_ui.'", |
|
2642 | - max_file_size: '.$max_file_size_bytes.', |
|
2643 | - max_file_size_ui: "'.$max_file_size_ui.'" |
|
2644 | - }; |
|
2645 | - |
|
2646 | - var string_upload_file = "'.$this->l('form_upload_a_file').'"; |
|
2647 | - var string_delete_file = "'.$this->l('string_delete_file').'"; |
|
2648 | - var string_progress = "'.$this->l('string_progress').'"; |
|
2649 | - var error_on_uploading = "'.$this->l('error_on_uploading').'"; |
|
2650 | - var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; |
|
811 | + $form_validation_check = false; |
|
2651 | 812 | |
2652 | - var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; |
|
2653 | - var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; |
|
2654 | - var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; |
|
2655 | - var error_min_file_size = "'.$this->l('error_min_file_size').'"; |
|
813 | + foreach($edit_fields as $edit_field) |
|
814 | + { |
|
815 | + $field_name = $edit_field->field_name; |
|
816 | + if(in_array( $field_name, $unique_fields) ) |
|
817 | + { |
|
818 | + $state_info = $this->getStateInfo(); |
|
819 | + $primary_key = $this->get_primary_key(); |
|
820 | + $field_name_value = $_POST[$field_name]; |
|
2656 | 821 | |
2657 | - var base_url = "'.base_url().'"; |
|
2658 | - var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; |
|
2659 | - '); |
|
822 | + $this->basic_model->where($primary_key,$state_info->primary_key); |
|
823 | + $row = $this->basic_model->get_row(); |
|
2660 | 824 | |
2661 | - $uploader_display_none = empty($value) ? "" : "display:none;"; |
|
2662 | - $file_display_none = empty($value) ? "display:none;" : ""; |
|
825 | + if(!isset($row->$field_name)) { |
|
826 | + throw new Exception("The field name doesn't exist in the database. ". |
|
827 | + "Please use the unique fields only for fields ". |
|
828 | + "that exist in the database"); |
|
829 | + } |
|
2663 | 830 | |
2664 | - $is_image = !empty($value) && |
|
2665 | - ( substr($value,-4) == '.jpg' |
|
2666 | - || substr($value,-4) == '.png' |
|
2667 | - || substr($value,-5) == '.jpeg' |
|
2668 | - || substr($value,-4) == '.gif' |
|
2669 | - || substr($value,-5) == '.tiff') |
|
2670 | - ? true : false; |
|
831 | + $previous_field_name_value = $row->$field_name; |
|
2671 | 832 | |
2672 | - $image_class = $is_image ? 'image-thumbnail' : ''; |
|
833 | + if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { |
|
834 | + $form_validation->set_rules( $field_name, |
|
835 | + $field_types[$field_name]->display_as, |
|
836 | + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
2673 | 837 | |
2674 | - $input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'"> |
|
2675 | - <span>'.$this->l('form_upload_a_file').'</span> |
|
2676 | - <input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'"> |
|
2677 | - <input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" /> |
|
2678 | - </span>'; |
|
838 | + $form_validation_check = true; |
|
839 | + } |
|
840 | + } |
|
841 | + } |
|
2679 | 842 | |
2680 | - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); |
|
2681 | - |
|
2682 | - $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
2683 | - |
|
2684 | - $input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>"; |
|
2685 | - $input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>"; |
|
2686 | - $input .= "<a href='".$file_url."' id='file_$unique' class='open-file"; |
|
2687 | - $input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value"; |
|
2688 | - $input .= "</a> "; |
|
2689 | - $input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> "; |
|
2690 | - $input .= "</div><div style='clear:both'></div>"; |
|
2691 | - $input .= "<div id='loading-$unique' style='display:none'><span id='upload-state-message-$unique'></span> <span class='qq-upload-spinner'></span> <span id='progress-$unique'></span></div>"; |
|
2692 | - $input .= "<div style='display:none'><a href='".$this->getUploadUrl($field_info->name)."' id='url_$unique'></a></div>"; |
|
2693 | - $input .= "<div style='display:none'><a href='".$this->getFileDeleteUrl($field_info->name)."' id='delete_url_$unique' rel='$value' ></a></div>"; |
|
2694 | - |
|
2695 | - return $input; |
|
2696 | - } |
|
2697 | - |
|
2698 | - protected function get_add_hidden_fields() |
|
2699 | - { |
|
2700 | - return $this->add_hidden_fields; |
|
2701 | - } |
|
2702 | - |
|
2703 | - protected function get_edit_hidden_fields() |
|
2704 | - { |
|
2705 | - return $this->edit_hidden_fields; |
|
2706 | - } |
|
2707 | - |
|
2708 | - protected function get_add_input_fields($field_values = null) |
|
2709 | - { |
|
2710 | - $fields = $this->get_add_fields(); |
|
2711 | - $types = $this->get_field_types(); |
|
2712 | - |
|
2713 | - $input_fields = array(); |
|
2714 | - |
|
2715 | - foreach($fields as $field_num => $field) |
|
2716 | - { |
|
2717 | - $field_info = $types[$field->field_name]; |
|
2718 | - |
|
2719 | - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
2720 | - |
|
2721 | - if(!isset($this->callback_add_field[$field->field_name])) |
|
2722 | - { |
|
2723 | - $field_input = $this->get_field_input($field_info, $field_value); |
|
2724 | - } |
|
2725 | - else |
|
2726 | - { |
|
2727 | - $field_input = $field_info; |
|
2728 | - $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); |
|
2729 | - } |
|
2730 | - |
|
2731 | - switch ($field_info->crud_type) { |
|
2732 | - case 'invisible': |
|
2733 | - unset($this->add_fields[$field_num]); |
|
2734 | - unset($fields[$field_num]); |
|
2735 | - continue; |
|
2736 | - break; |
|
2737 | - case 'hidden': |
|
2738 | - $this->add_hidden_fields[] = $field_input; |
|
2739 | - unset($this->add_fields[$field_num]); |
|
2740 | - unset($fields[$field_num]); |
|
2741 | - continue; |
|
2742 | - break; |
|
2743 | - } |
|
2744 | - |
|
2745 | - $input_fields[$field->field_name] = $field_input; |
|
2746 | - } |
|
2747 | - |
|
2748 | - return $input_fields; |
|
2749 | - } |
|
2750 | - |
|
2751 | - protected function get_edit_input_fields($field_values = null) |
|
2752 | - { |
|
2753 | - $fields = $this->get_edit_fields(); |
|
2754 | - $types = $this->get_field_types(); |
|
2755 | - |
|
2756 | - $input_fields = array(); |
|
2757 | - |
|
2758 | - foreach($fields as $field_num => $field) |
|
2759 | - { |
|
2760 | - $field_info = $types[$field->field_name]; |
|
2761 | - |
|
2762 | - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
2763 | - if(!isset($this->callback_edit_field[$field->field_name])) |
|
2764 | - { |
|
2765 | - $field_input = $this->get_field_input($field_info, $field_value); |
|
2766 | - } |
|
2767 | - else |
|
2768 | - { |
|
2769 | - $primary_key = $this->getStateInfo()->primary_key; |
|
2770 | - $field_input = $field_info; |
|
2771 | - $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
2772 | - } |
|
2773 | - |
|
2774 | - switch ($field_info->crud_type) { |
|
2775 | - case 'invisible': |
|
2776 | - unset($this->edit_fields[$field_num]); |
|
2777 | - unset($fields[$field_num]); |
|
2778 | - continue; |
|
2779 | - break; |
|
2780 | - case 'hidden': |
|
2781 | - $this->edit_hidden_fields[] = $field_input; |
|
2782 | - unset($this->edit_fields[$field_num]); |
|
2783 | - unset($fields[$field_num]); |
|
2784 | - continue; |
|
2785 | - break; |
|
2786 | - } |
|
2787 | - |
|
2788 | - $input_fields[$field->field_name] = $field_input; |
|
2789 | - } |
|
2790 | - |
|
2791 | - return $input_fields; |
|
2792 | - } |
|
2793 | - |
|
2794 | - protected function get_read_input_fields($field_values = null) |
|
2795 | - { |
|
2796 | - $read_fields = $this->get_read_fields(); |
|
2797 | - |
|
2798 | - $this->field_types = null; |
|
2799 | - $this->required_fields = null; |
|
2800 | - |
|
2801 | - $read_inputs = array(); |
|
2802 | - foreach ($read_fields as $field) { |
|
2803 | - if (!empty($this->change_field_type) |
|
2804 | - && isset($this->change_field_type[$field->field_name]) |
|
2805 | - && $this->change_field_type[$field->field_name]->type == 'hidden') { |
|
2806 | - continue; |
|
2807 | - } |
|
2808 | - $this->field_type($field->field_name, 'readonly'); |
|
2809 | - } |
|
2810 | - |
|
2811 | - $fields = $this->get_read_fields(); |
|
2812 | - $types = $this->get_field_types(); |
|
2813 | - |
|
2814 | - $input_fields = array(); |
|
2815 | - |
|
2816 | - foreach($fields as $field_num => $field) |
|
2817 | - { |
|
2818 | - $field_info = $types[$field->field_name]; |
|
2819 | - |
|
2820 | - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
2821 | - if(!isset($this->callback_read_field[$field->field_name])) |
|
2822 | - { |
|
2823 | - $field_input = $this->get_field_input($field_info, $field_value); |
|
2824 | - } |
|
2825 | - else |
|
2826 | - { |
|
2827 | - $primary_key = $this->getStateInfo()->primary_key; |
|
2828 | - $field_input = $field_info; |
|
2829 | - $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
2830 | - } |
|
2831 | - |
|
2832 | - switch ($field_info->crud_type) { |
|
2833 | - case 'invisible': |
|
2834 | - unset($this->read_fields[$field_num]); |
|
2835 | - unset($fields[$field_num]); |
|
2836 | - continue; |
|
2837 | - break; |
|
2838 | - case 'hidden': |
|
2839 | - $this->read_hidden_fields[] = $field_input; |
|
2840 | - unset($this->read_fields[$field_num]); |
|
2841 | - unset($fields[$field_num]); |
|
2842 | - continue; |
|
2843 | - break; |
|
2844 | - } |
|
2845 | - |
|
2846 | - $input_fields[$field->field_name] = $field_input; |
|
2847 | - } |
|
2848 | - |
|
2849 | - return $input_fields; |
|
2850 | - } |
|
2851 | - |
|
2852 | - protected function setThemeBasics() |
|
2853 | - { |
|
2854 | - $this->theme_path = $this->default_theme_path; |
|
2855 | - if(substr($this->theme_path,-1) != '/') |
|
2856 | - $this->theme_path = $this->theme_path.'/'; |
|
2857 | - |
|
2858 | - include($this->theme_path.$this->theme.'/config.php'); |
|
2859 | - |
|
2860 | - $this->theme_config = $config; |
|
2861 | - } |
|
2862 | - |
|
2863 | - public function set_theme($theme = null) |
|
2864 | - { |
|
2865 | - $this->theme = $theme; |
|
2866 | - |
|
2867 | - return $this; |
|
2868 | - } |
|
2869 | - |
|
2870 | - protected function _get_ajax_results() |
|
2871 | - { |
|
2872 | - //This is a $_POST request rather that $_GET request , because |
|
2873 | - //Codeigniter doesn't like the $_GET requests so much! |
|
2874 | - if ($this->_is_ajax()) { |
|
2875 | - @ob_end_clean(); |
|
2876 | - $results= (object)array( |
|
2877 | - 'output' => $this->views_as_string, |
|
2878 | - 'js_files' => array_values($this->get_js_files()), |
|
2879 | - 'js_lib_files' => array_values($this->get_js_lib_files()), |
|
2880 | - 'js_config_files' => array_values($this->get_js_config_files()), |
|
2881 | - 'css_files' => array_values($this->get_css_files()) |
|
2882 | - ); |
|
2883 | - |
|
2884 | - echo json_encode($results); |
|
2885 | - die; |
|
2886 | - } |
|
2887 | - //else just continue |
|
2888 | - } |
|
2889 | - |
|
2890 | - protected function _is_ajax() |
|
2891 | - { |
|
2892 | - return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; |
|
2893 | - } |
|
2894 | - |
|
2895 | - protected function _theme_view($view, $vars = array(), $return = FALSE) |
|
2896 | - { |
|
2897 | - $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; |
|
2898 | - |
|
2899 | - $file_exists = FALSE; |
|
2900 | - |
|
2901 | - $ext = pathinfo($view, PATHINFO_EXTENSION); |
|
2902 | - $file = ($ext == '') ? $view.'.php' : $view; |
|
2903 | - |
|
2904 | - $view_file = $this->theme_path.$this->theme.'/views/'; |
|
2905 | - |
|
2906 | - if (file_exists($view_file.$file)) |
|
2907 | - { |
|
2908 | - $path = $view_file.$file; |
|
2909 | - $file_exists = TRUE; |
|
2910 | - } |
|
2911 | - |
|
2912 | - if ( ! $file_exists) |
|
2913 | - { |
|
2914 | - throw new Exception('Unable to load the requested file: '.$file, 16); |
|
2915 | - } |
|
2916 | - |
|
2917 | - extract($vars); |
|
2918 | - |
|
2919 | - #region buffering... |
|
2920 | - ob_start(); |
|
2921 | - |
|
2922 | - include($path); |
|
2923 | - |
|
2924 | - $buffer = ob_get_contents(); |
|
2925 | - @ob_end_clean(); |
|
2926 | - #endregion |
|
2927 | - |
|
2928 | - if ($return === TRUE) |
|
2929 | - { |
|
2930 | - return $buffer; |
|
2931 | - } |
|
2932 | - |
|
2933 | - $this->views_as_string .= $buffer; |
|
2934 | - } |
|
2935 | - |
|
2936 | - protected function _inline_js($inline_js = '') |
|
2937 | - { |
|
2938 | - $this->views_as_string .= "<script type=\"text/javascript\">\n{$inline_js}\n</script>\n"; |
|
2939 | - } |
|
2940 | - |
|
2941 | - protected function _add_js_vars($js_vars = array()) |
|
2942 | - { |
|
2943 | - $javascript_as_string = "<script type=\"text/javascript\">\n"; |
|
2944 | - foreach ($js_vars as $js_var => $js_value) { |
|
2945 | - $javascript_as_string .= "\tvar $js_var = '$js_value';\n"; |
|
2946 | - } |
|
2947 | - $javascript_as_string .= "\n</script>\n"; |
|
2948 | - $this->views_as_string .= $javascript_as_string; |
|
2949 | - } |
|
2950 | - |
|
2951 | - protected function get_views_as_string() |
|
2952 | - { |
|
2953 | - if(!empty($this->views_as_string)) |
|
2954 | - return $this->views_as_string; |
|
2955 | - else |
|
2956 | - return null; |
|
2957 | - } |
|
2958 | -} |
|
843 | + if($form_validation_check && !$form_validation->run()) |
|
844 | + { |
|
845 | + $validation_result->error_message = $form_validation->error_string(); |
|
846 | + $validation_result->error_fields = $form_validation->_error_array; |
|
2959 | 847 | |
848 | + return $validation_result; |
|
849 | + } |
|
850 | + } |
|
2960 | 851 | |
2961 | -/** |
|
2962 | - * PHP grocery CRUD |
|
2963 | - * |
|
2964 | - * LICENSE |
|
2965 | - * |
|
2966 | - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
2967 | - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
2968 | - * Please see the corresponding license file for details of these licenses. |
|
2969 | - * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
2970 | - * |
|
2971 | - * @package grocery CRUD |
|
2972 | - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
2973 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
2974 | - * @author John Skoumbourdis <[email protected]> |
|
2975 | - */ |
|
852 | + if(!empty($this->validation_rules)) |
|
853 | + { |
|
854 | + $form_validation = $this->form_validation(); |
|
2976 | 855 | |
2977 | -// ------------------------------------------------------------------------ |
|
856 | + $edit_fields = $this->get_edit_fields(); |
|
2978 | 857 | |
2979 | -/** |
|
2980 | - * PHP grocery States |
|
2981 | - * |
|
2982 | - * States of grocery CRUD |
|
2983 | - * |
|
2984 | - * @package grocery CRUD |
|
2985 | - * @author John Skoumbourdis <[email protected]> |
|
2986 | - * @version 1.5.6 |
|
2987 | - */ |
|
2988 | -class grocery_CRUD_States extends grocery_CRUD_Layout |
|
2989 | -{ |
|
2990 | - const STATE_UNKNOWN = 0; |
|
2991 | - const STATE_LIST = 1; |
|
2992 | - const STATE_ADD = 2; |
|
2993 | - const STATE_EDIT = 3; |
|
2994 | - const STATE_DELETE = 4; |
|
2995 | - const STATE_INSERT = 5; |
|
858 | + foreach($edit_fields as $edit_field) |
|
859 | + { |
|
860 | + $field_name = $edit_field->field_name; |
|
861 | + if(isset($this->validation_rules[$field_name])) |
|
862 | + { |
|
863 | + $rule = $this->validation_rules[$field_name]; |
|
864 | + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
865 | + } |
|
866 | + } |
|
2996 | 867 | |
2997 | - const STATE_READ = 18; |
|
2998 | - const STATE_DELETE_MULTIPLE = '19'; |
|
868 | + if($form_validation->run()) |
|
869 | + { |
|
870 | + $validation_result->success = true; |
|
871 | + } |
|
872 | + else |
|
873 | + { |
|
874 | + $validation_result->error_message = $form_validation->error_string(); |
|
875 | + $validation_result->error_fields = $form_validation->_error_array; |
|
876 | + } |
|
877 | + } |
|
878 | + else |
|
879 | + { |
|
880 | + $validation_result->success = true; |
|
881 | + } |
|
2999 | 882 | |
3000 | - protected $states = array( |
|
3001 | - 0 => 'unknown', |
|
3002 | - 1 => 'list', |
|
3003 | - 2 => 'add', |
|
3004 | - 3 => 'edit', |
|
3005 | - 4 => 'delete', |
|
3006 | - 5 => 'insert', |
|
3007 | - 6 => 'update', |
|
3008 | - 7 => 'ajax_list', |
|
3009 | - 8 => 'ajax_list_info', |
|
3010 | - 9 => 'insert_validation', |
|
3011 | - 10 => 'update_validation', |
|
3012 | - 11 => 'upload_file', |
|
3013 | - 12 => 'delete_file', |
|
3014 | - 13 => 'ajax_relation', |
|
3015 | - 14 => 'ajax_relation_n_n', |
|
3016 | - 15 => 'success', |
|
3017 | - 16 => 'export', |
|
3018 | - 17 => 'print', |
|
3019 | - 18 => 'read', |
|
3020 | - 19 => 'delete_multiple' |
|
3021 | - ); |
|
883 | + return $validation_result; |
|
884 | + } |
|
3022 | 885 | |
3023 | - public function getStateInfo() |
|
886 | + protected function db_insert($state_info) |
|
3024 | 887 | { |
3025 | - $state_code = $this->getStateCode(); |
|
3026 | - $segment_object = $this->get_state_info_from_url(); |
|
888 | + $validation_result = $this->db_insert_validation(); |
|
3027 | 889 | |
3028 | - $first_parameter = $segment_object->first_parameter; |
|
3029 | - $second_parameter = $segment_object->second_parameter; |
|
890 | + if($validation_result->success) |
|
891 | + { |
|
892 | + $post_data = $state_info->unwrapped_data; |
|
3030 | 893 | |
3031 | - $state_info = (object)array(); |
|
894 | + $add_fields = $this->get_add_fields(); |
|
3032 | 895 | |
3033 | - switch ($state_code) { |
|
3034 | - case self::STATE_LIST: |
|
3035 | - case self::STATE_ADD: |
|
3036 | - //for now... do nothing! Keeping this switch here in case we need any information at the future. |
|
3037 | - break; |
|
896 | + if($this->callback_insert === null) |
|
897 | + { |
|
898 | + if($this->callback_before_insert !== null) |
|
899 | + { |
|
900 | + $callback_return = call_user_func($this->callback_before_insert, $post_data); |
|
3038 | 901 | |
3039 | - case self::STATE_EDIT: |
|
3040 | - case self::STATE_READ: |
|
3041 | - if ($first_parameter !== null) { |
|
3042 | - $state_info = (object) array('primary_key' => $first_parameter); |
|
3043 | - } else { |
|
3044 | - throw new Exception('On the state "edit" the Primary key cannot be null', 6); |
|
3045 | - die(); |
|
902 | + if(!empty($callback_return) && is_array($callback_return)) |
|
903 | + $post_data = $callback_return; |
|
904 | + elseif($callback_return === false) |
|
905 | + return false; |
|
3046 | 906 | } |
3047 | - break; |
|
3048 | 907 | |
3049 | - case self::STATE_DELETE: |
|
3050 | - if ($first_parameter !== null) { |
|
3051 | - $state_info = (object) array('primary_key' => $first_parameter); |
|
3052 | - } else { |
|
3053 | - throw new Exception('On the state "delete" the Primary key cannot be null',7); |
|
3054 | - die(); |
|
3055 | - } |
|
3056 | - break; |
|
908 | + $insert_data = array(); |
|
909 | + $types = $this->get_field_types(); |
|
910 | + foreach($add_fields as $num_row => $field) |
|
911 | + { |
|
912 | + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
913 | + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
914 | + { |
|
915 | + $post_data[$field->field_name] = array(); |
|
916 | + } |
|
3057 | 917 | |
3058 | - case self::STATE_DELETE_MULTIPLE: |
|
3059 | - if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { |
|
3060 | - $state_info = (object) array('ids' => $_POST['ids']); |
|
3061 | - } else { |
|
3062 | - throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); |
|
3063 | - die(); |
|
918 | + if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
919 | + { |
|
920 | + if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) |
|
921 | + { |
|
922 | + $insert_data[$field->field_name] = null; |
|
923 | + } |
|
924 | + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
925 | + { |
|
926 | + $insert_data[$field->field_name] = null; |
|
927 | + } |
|
928 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
929 | + { |
|
930 | + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
931 | + } |
|
932 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
933 | + { |
|
934 | + //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
935 | + } |
|
936 | + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
937 | + { |
|
938 | + $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
939 | + } |
|
940 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
941 | + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
942 | + substr($post_data[$field->field_name],10); |
|
943 | + } |
|
944 | + else |
|
945 | + { |
|
946 | + $insert_data[$field->field_name] = $post_data[$field->field_name]; |
|
947 | + } |
|
948 | + } |
|
3064 | 949 | } |
3065 | - break; |
|
3066 | 950 | |
3067 | - case self::STATE_INSERT: |
|
3068 | - if(!empty($_POST)) |
|
951 | + $insert_result = $this->basic_model->db_insert($insert_data); |
|
952 | + |
|
953 | + if($insert_result !== false) |
|
3069 | 954 | { |
3070 | - $state_info = (object)array('unwrapped_data' => $_POST); |
|
955 | + $insert_primary_key = $insert_result; |
|
3071 | 956 | } |
3072 | 957 | else |
3073 | 958 | { |
3074 | - throw new Exception('On the state "insert" you must have post data',8); |
|
3075 | - die(); |
|
959 | + return false; |
|
3076 | 960 | } |
3077 | - break; |
|
3078 | 961 | |
3079 | - case 6: |
|
3080 | - if(!empty($_POST) && $first_parameter !== null) |
|
3081 | - { |
|
3082 | - $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); |
|
3083 | - } |
|
3084 | - elseif(empty($_POST)) |
|
962 | + if(!empty($this->relation_n_n)) |
|
3085 | 963 | { |
3086 | - throw new Exception('On the state "update" you must have post data',9); |
|
3087 | - die(); |
|
964 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
965 | + { |
|
966 | + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
967 | + $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); |
|
968 | + } |
|
3088 | 969 | } |
3089 | - else |
|
970 | + |
|
971 | + if($this->callback_after_insert !== null) |
|
3090 | 972 | { |
3091 | - throw new Exception('On the state "update" the Primary key cannot be null',10); |
|
3092 | - die(); |
|
973 | + $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); |
|
974 | + |
|
975 | + if($callback_return === false) |
|
976 | + { |
|
977 | + return false; |
|
978 | + } |
|
979 | + |
|
3093 | 980 | } |
3094 | - break; |
|
981 | + }else |
|
982 | + { |
|
983 | + $callback_return = call_user_func($this->callback_insert, $post_data); |
|
3095 | 984 | |
3096 | - case 7: |
|
3097 | - case 8: |
|
3098 | - case 16: //export to excel |
|
3099 | - case 17: //print |
|
3100 | - $state_info = (object)array(); |
|
3101 | - if(!empty($_POST['per_page'])) |
|
985 | + if($callback_return === false) |
|
986 | + { |
|
987 | + return false; |
|
988 | + } |
|
989 | + } |
|
990 | + |
|
991 | + if(isset($insert_primary_key)) |
|
992 | + return $insert_primary_key; |
|
993 | + else |
|
994 | + return true; |
|
995 | + } |
|
996 | + |
|
997 | + return false; |
|
998 | + |
|
999 | + } |
|
1000 | + |
|
1001 | + protected function db_update($state_info) |
|
1002 | + { |
|
1003 | + $validation_result = $this->db_update_validation(); |
|
1004 | + |
|
1005 | + $edit_fields = $this->get_edit_fields(); |
|
1006 | + |
|
1007 | + if($validation_result->success) |
|
1008 | + { |
|
1009 | + $post_data = $state_info->unwrapped_data; |
|
1010 | + $primary_key = $state_info->primary_key; |
|
1011 | + |
|
1012 | + if($this->callback_update === null) |
|
1013 | + { |
|
1014 | + if($this->callback_before_update !== null) |
|
3102 | 1015 | { |
3103 | - $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; |
|
1016 | + $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); |
|
1017 | + |
|
1018 | + if(!empty($callback_return) && is_array($callback_return)) |
|
1019 | + { |
|
1020 | + $post_data = $callback_return; |
|
1021 | + } |
|
1022 | + elseif($callback_return === false) |
|
1023 | + { |
|
1024 | + return false; |
|
1025 | + } |
|
1026 | + |
|
3104 | 1027 | } |
3105 | - if(!empty($_POST['page'])) |
|
1028 | + |
|
1029 | + $update_data = array(); |
|
1030 | + $types = $this->get_field_types(); |
|
1031 | + foreach($edit_fields as $num_row => $field) |
|
3106 | 1032 | { |
3107 | - $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; |
|
1033 | + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
1034 | + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
1035 | + { |
|
1036 | + $post_data[$field->field_name] = array(); |
|
1037 | + } |
|
1038 | + |
|
1039 | + if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
1040 | + { |
|
1041 | + if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) |
|
1042 | + { |
|
1043 | + $update_data[$field->field_name] = null; |
|
1044 | + } |
|
1045 | + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
1046 | + { |
|
1047 | + $update_data[$field->field_name] = null; |
|
1048 | + } |
|
1049 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
1050 | + { |
|
1051 | + $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
1052 | + } |
|
1053 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
1054 | + { |
|
1055 | + //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
1056 | + } |
|
1057 | + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
1058 | + { |
|
1059 | + $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
1060 | + } |
|
1061 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
1062 | + $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
1063 | + substr($post_data[$field->field_name],10); |
|
1064 | + } |
|
1065 | + else |
|
1066 | + { |
|
1067 | + $update_data[$field->field_name] = $post_data[$field->field_name]; |
|
1068 | + } |
|
1069 | + } |
|
3108 | 1070 | } |
3109 | - //If we request an export or a print we don't care about what page we are |
|
3110 | - if($state_code === 16 || $state_code === 17) |
|
1071 | + |
|
1072 | + if($this->basic_model->db_update($update_data, $primary_key) === false) |
|
3111 | 1073 | { |
3112 | - $state_info->page = 1; |
|
3113 | - $state_info->per_page = 1000000; //a very big number! |
|
1074 | + return false; |
|
3114 | 1075 | } |
3115 | - if(!empty($_POST['order_by'][0])) |
|
1076 | + |
|
1077 | + if(!empty($this->relation_n_n)) |
|
3116 | 1078 | { |
3117 | - $state_info->order_by = $_POST['order_by']; |
|
1079 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
1080 | + { |
|
1081 | + if ( $this->unset_edit_fields !== null |
|
1082 | + && is_array($this->unset_edit_fields) |
|
1083 | + && in_array($field_name,$this->unset_edit_fields) |
|
1084 | + ) { |
|
1085 | + continue; |
|
1086 | + } |
|
1087 | + |
|
1088 | + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
1089 | + $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); |
|
1090 | + } |
|
3118 | 1091 | } |
3119 | - if(!empty($_POST['search_text'])) |
|
1092 | + |
|
1093 | + if($this->callback_after_update !== null) |
|
3120 | 1094 | { |
3121 | - if(empty($_POST['search_field'])) |
|
1095 | + $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); |
|
1096 | + |
|
1097 | + if($callback_return === false) |
|
3122 | 1098 | { |
3123 | - $search_text = strip_tags($_POST['search_field']); |
|
3124 | - $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); |
|
1099 | + return false; |
|
3125 | 1100 | } |
3126 | - else |
|
1101 | + |
|
1102 | + } |
|
1103 | + } |
|
1104 | + else |
|
1105 | + { |
|
1106 | + $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); |
|
1107 | + |
|
1108 | + if($callback_return === false) |
|
1109 | + { |
|
1110 | + return false; |
|
1111 | + } |
|
1112 | + } |
|
1113 | + |
|
1114 | + return true; |
|
1115 | + } |
|
1116 | + else |
|
1117 | + { |
|
1118 | + return false; |
|
1119 | + } |
|
1120 | + } |
|
1121 | + |
|
1122 | + protected function _convert_date_to_sql_date($date) |
|
1123 | + { |
|
1124 | + $date = substr($date,0,10); |
|
1125 | + if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) |
|
1126 | + { |
|
1127 | + //If it's already a sql-date don't convert it! |
|
1128 | + return $date; |
|
1129 | + }elseif(empty($date)) |
|
1130 | + { |
|
1131 | + return ''; |
|
1132 | + } |
|
1133 | + |
|
1134 | + $date_array = preg_split( '/[-\.\/ ]/', $date); |
|
1135 | + if($this->php_date_format == 'd/m/Y') |
|
1136 | + { |
|
1137 | + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); |
|
1138 | + } |
|
1139 | + elseif($this->php_date_format == 'm/d/Y') |
|
1140 | + { |
|
1141 | + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); |
|
1142 | + } |
|
1143 | + else |
|
1144 | + { |
|
1145 | + $sql_date = $date; |
|
1146 | + } |
|
1147 | + |
|
1148 | + return $sql_date; |
|
1149 | + } |
|
1150 | + |
|
1151 | + protected function _get_field_names_to_search(array $relation_values) |
|
1152 | + { |
|
1153 | + if(!strstr($relation_values[2],'{')) |
|
1154 | + return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
|
1155 | + else |
|
1156 | + { |
|
1157 | + $relation_values[2] = ' '.$relation_values[2].' '; |
|
1158 | + $temp1 = explode('{',$relation_values[2]); |
|
1159 | + unset($temp1[0]); |
|
1160 | + |
|
1161 | + $field_names_array = array(); |
|
1162 | + foreach($temp1 as $field) |
|
1163 | + list($field_names_array[]) = explode('}',$field); |
|
1164 | + |
|
1165 | + return $field_names_array; |
|
1166 | + } |
|
1167 | + } |
|
1168 | + |
|
1169 | + protected function _unique_join_name($field_name) |
|
1170 | + { |
|
1171 | + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number |
|
1172 | + } |
|
1173 | + |
|
1174 | + protected function _unique_field_name($field_name) |
|
1175 | + { |
|
1176 | + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number |
|
1177 | + } |
|
1178 | + |
|
1179 | + protected function db_multiple_delete($state_info) |
|
1180 | + { |
|
1181 | + foreach ($state_info->ids as $delete_id) { |
|
1182 | + $result = $this->db_delete((object)array('primary_key' => $delete_id)); |
|
1183 | + if (!$result) { |
|
1184 | + return false; |
|
1185 | + } |
|
1186 | + } |
|
1187 | + |
|
1188 | + return true; |
|
1189 | + } |
|
1190 | + |
|
1191 | + protected function db_delete($state_info) |
|
1192 | + { |
|
1193 | + $primary_key_value = $state_info->primary_key; |
|
1194 | + |
|
1195 | + if($this->callback_delete === null) |
|
1196 | + { |
|
1197 | + if($this->callback_before_delete !== null) |
|
1198 | + { |
|
1199 | + $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); |
|
1200 | + |
|
1201 | + if($callback_return === false) |
|
1202 | + { |
|
1203 | + return false; |
|
1204 | + } |
|
1205 | + |
|
1206 | + } |
|
1207 | + |
|
1208 | + if(!empty($this->relation_n_n)) |
|
1209 | + { |
|
1210 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
1211 | + { |
|
1212 | + $this->db_relation_n_n_delete( $field_info, $primary_key_value ); |
|
1213 | + } |
|
1214 | + } |
|
1215 | + |
|
1216 | + $delete_result = $this->basic_model->db_delete($primary_key_value); |
|
1217 | + |
|
1218 | + if($delete_result === false) |
|
1219 | + { |
|
1220 | + return false; |
|
1221 | + } |
|
1222 | + |
|
1223 | + if($this->callback_after_delete !== null) |
|
1224 | + { |
|
1225 | + $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); |
|
1226 | + |
|
1227 | + if($callback_return === false) |
|
1228 | + { |
|
1229 | + return false; |
|
1230 | + } |
|
1231 | + |
|
1232 | + } |
|
1233 | + } |
|
1234 | + else |
|
1235 | + { |
|
1236 | + $callback_return = call_user_func($this->callback_delete, $primary_key_value); |
|
1237 | + |
|
1238 | + if($callback_return === false) |
|
1239 | + { |
|
1240 | + return false; |
|
1241 | + } |
|
1242 | + } |
|
1243 | + |
|
1244 | + return true; |
|
1245 | + } |
|
1246 | + |
|
1247 | + protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) |
|
1248 | + { |
|
1249 | + $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); |
|
1250 | + } |
|
1251 | + |
|
1252 | + protected function db_relation_n_n_delete($field_info, $primary_key_value) |
|
1253 | + { |
|
1254 | + $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); |
|
1255 | + } |
|
1256 | + |
|
1257 | + protected function get_list() |
|
1258 | + { |
|
1259 | + if(!empty($this->order_by)) |
|
1260 | + $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
1261 | + |
|
1262 | + if(!empty($this->where)) |
|
1263 | + foreach($this->where as $where) |
|
1264 | + $this->basic_model->where($where[0],$where[1],$where[2]); |
|
1265 | + |
|
1266 | + if(!empty($this->or_where)) |
|
1267 | + foreach($this->or_where as $or_where) |
|
1268 | + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
1269 | + |
|
1270 | + if(!empty($this->like)) |
|
1271 | + foreach($this->like as $like) |
|
1272 | + $this->basic_model->like($like[0],$like[1],$like[2]); |
|
1273 | + |
|
1274 | + if(!empty($this->or_like)) |
|
1275 | + foreach($this->or_like as $or_like) |
|
1276 | + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
1277 | + |
|
1278 | + if(!empty($this->having)) |
|
1279 | + foreach($this->having as $having) |
|
1280 | + $this->basic_model->having($having[0],$having[1],$having[2]); |
|
1281 | + |
|
1282 | + if(!empty($this->or_having)) |
|
1283 | + foreach($this->or_having as $or_having) |
|
1284 | + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
1285 | + |
|
1286 | + if(!empty($this->relation)) |
|
1287 | + foreach($this->relation as $relation) |
|
1288 | + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
1289 | + |
|
1290 | + if(!empty($this->relation_n_n)) |
|
1291 | + { |
|
1292 | + $columns = $this->get_columns(); |
|
1293 | + foreach($columns as $column) |
|
1294 | + { |
|
1295 | + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
1296 | + if(isset($this->relation_n_n[$column->field_name])) |
|
1297 | + { |
|
1298 | + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
1299 | + } |
|
1300 | + } |
|
1301 | + |
|
1302 | + } |
|
1303 | + |
|
1304 | + if($this->theme_config['crud_paging'] === true) |
|
1305 | + { |
|
1306 | + if($this->limit === null) |
|
1307 | + { |
|
1308 | + $default_per_page = $this->config->default_per_page; |
|
1309 | + if(is_numeric($default_per_page) && $default_per_page >1) |
|
1310 | + { |
|
1311 | + $this->basic_model->limit($default_per_page); |
|
1312 | + } |
|
1313 | + else |
|
1314 | + { |
|
1315 | + $this->basic_model->limit(10); |
|
1316 | + } |
|
1317 | + } |
|
1318 | + else |
|
1319 | + { |
|
1320 | + $this->basic_model->limit($this->limit[0],$this->limit[1]); |
|
1321 | + } |
|
1322 | + } |
|
1323 | + |
|
1324 | + $results = $this->basic_model->get_list(); |
|
1325 | + |
|
1326 | + return $results; |
|
1327 | + } |
|
1328 | + |
|
1329 | + protected function get_edit_values($primary_key_value) |
|
1330 | + { |
|
1331 | + $values = $this->basic_model->get_edit_values($primary_key_value); |
|
1332 | + |
|
1333 | + if(!empty($this->relation_n_n)) |
|
1334 | + { |
|
1335 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
1336 | + { |
|
1337 | + $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
1338 | + } |
|
1339 | + } |
|
1340 | + |
|
1341 | + return $values; |
|
1342 | + } |
|
1343 | + |
|
1344 | + protected function get_relation_n_n_selection_array($primary_key_value, $field_info) |
|
1345 | + { |
|
1346 | + return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
1347 | + } |
|
1348 | + |
|
1349 | + protected function get_relation_n_n_unselected_array($field_info, $selected_values) |
|
1350 | + { |
|
1351 | + return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
1352 | + } |
|
1353 | + |
|
1354 | + protected function set_basic_db_table($table_name = null) |
|
1355 | + { |
|
1356 | + $this->basic_model->set_basic_table($table_name); |
|
1357 | + } |
|
1358 | + |
|
1359 | + protected function upload_file($state_info) |
|
1360 | + { |
|
1361 | + if(isset($this->upload_fields[$state_info->field_name]) ) |
|
1362 | + { |
|
1363 | + if($this->callback_upload === null) |
|
1364 | + { |
|
1365 | + if($this->callback_before_upload !== null) |
|
1366 | + { |
|
1367 | + $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
1368 | + |
|
1369 | + if($callback_before_upload_response === false) |
|
1370 | + return false; |
|
1371 | + elseif(is_string($callback_before_upload_response)) |
|
1372 | + return $callback_before_upload_response; |
|
1373 | + } |
|
1374 | + |
|
1375 | + $upload_info = $this->upload_fields[$state_info->field_name]; |
|
1376 | + |
|
1377 | + header('Pragma: no-cache'); |
|
1378 | + header('Cache-Control: private, no-cache'); |
|
1379 | + header('Content-Disposition: inline; filename="files.json"'); |
|
1380 | + header('X-Content-Type-Options: nosniff'); |
|
1381 | + header('Access-Control-Allow-Origin: *'); |
|
1382 | + header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); |
|
1383 | + header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); |
|
1384 | + |
|
1385 | + $allowed_files = $this->config->file_upload_allow_file_types; |
|
1386 | + |
|
1387 | + $reg_exp = ''; |
|
1388 | + if(!empty($upload_info->allowed_file_types)){ |
|
1389 | + $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; |
|
1390 | + }else{ |
|
1391 | + $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; |
|
1392 | + } |
|
1393 | + |
|
1394 | + $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
1395 | + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
1396 | + |
|
1397 | + $options = array( |
|
1398 | + 'upload_dir' => $upload_info->upload_path.'/', |
|
1399 | + 'param_name' => $this->_unique_field_name($state_info->field_name), |
|
1400 | + 'upload_url' => base_url().$upload_info->upload_path.'/', |
|
1401 | + 'accept_file_types' => $reg_exp, |
|
1402 | + 'max_file_size' => $max_file_size_bytes |
|
1403 | + ); |
|
1404 | + $upload_handler = new UploadHandler($options); |
|
1405 | + $upload_handler->default_config_path = $this->default_config_path; |
|
1406 | + $uploader_response = $upload_handler->post(); |
|
1407 | + |
|
1408 | + if(is_array($uploader_response)) |
|
1409 | + { |
|
1410 | + foreach($uploader_response as &$response) |
|
1411 | + { |
|
1412 | + unset($response->delete_url); |
|
1413 | + unset($response->delete_type); |
|
1414 | + } |
|
1415 | + } |
|
1416 | + |
|
1417 | + if($this->callback_after_upload !== null) |
|
1418 | + { |
|
1419 | + $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); |
|
1420 | + |
|
1421 | + if($callback_after_upload_response === false) |
|
1422 | + return false; |
|
1423 | + elseif(is_string($callback_after_upload_response)) |
|
1424 | + return $callback_after_upload_response; |
|
1425 | + elseif(is_array($callback_after_upload_response)) |
|
1426 | + $uploader_response = $callback_after_upload_response; |
|
1427 | + } |
|
1428 | + |
|
1429 | + return $uploader_response; |
|
1430 | + } |
|
1431 | + else |
|
1432 | + { |
|
1433 | + $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); |
|
1434 | + |
|
1435 | + if($upload_response === false) |
|
1436 | + { |
|
1437 | + return false; |
|
1438 | + } |
|
1439 | + else |
|
1440 | + { |
|
1441 | + return $upload_response; |
|
1442 | + } |
|
1443 | + } |
|
1444 | + } |
|
1445 | + else |
|
1446 | + { |
|
1447 | + return false; |
|
1448 | + } |
|
1449 | + } |
|
1450 | + |
|
1451 | + protected function delete_file($state_info) |
|
1452 | + { |
|
1453 | + |
|
1454 | + if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) |
|
1455 | + { |
|
1456 | + $upload_info = $this->upload_fields[$state_info->field_name]; |
|
1457 | + |
|
1458 | + if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
1459 | + { |
|
1460 | + if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) |
|
1461 | + { |
|
1462 | + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
1463 | + |
|
1464 | + return true; |
|
1465 | + } |
|
1466 | + else |
|
1467 | + { |
|
1468 | + return false; |
|
1469 | + } |
|
1470 | + } |
|
1471 | + else |
|
1472 | + { |
|
1473 | + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
1474 | + return true; |
|
1475 | + } |
|
1476 | + } |
|
1477 | + else |
|
1478 | + { |
|
1479 | + return false; |
|
1480 | + } |
|
1481 | + } |
|
1482 | + |
|
1483 | + protected function ajax_relation($state_info) |
|
1484 | + { |
|
1485 | + if(!isset($this->relation[$state_info->field_name])) |
|
1486 | + return false; |
|
1487 | + |
|
1488 | + list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
|
1489 | + |
|
1490 | + return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); |
|
1491 | + } |
|
1492 | +} |
|
1493 | + |
|
1494 | + |
|
1495 | +/** |
|
1496 | + * PHP grocery CRUD |
|
1497 | + * |
|
1498 | + * LICENSE |
|
1499 | + * |
|
1500 | + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
1501 | + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
1502 | + * Please see the corresponding license file for details of these licenses. |
|
1503 | + * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
1504 | + * |
|
1505 | + * @package grocery CRUD |
|
1506 | + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
1507 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
1508 | + * @author John Skoumbourdis <[email protected]> |
|
1509 | + */ |
|
1510 | + |
|
1511 | +// ------------------------------------------------------------------------ |
|
1512 | + |
|
1513 | +/** |
|
1514 | + * PHP grocery Layout |
|
1515 | + * |
|
1516 | + * Here you manage all the HTML Layout |
|
1517 | + * |
|
1518 | + * @package grocery CRUD |
|
1519 | + * @author John Skoumbourdis <[email protected]> |
|
1520 | + * @version 1.5.6 |
|
1521 | + */ |
|
1522 | +class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver |
|
1523 | +{ |
|
1524 | + private $theme_path = null; |
|
1525 | + private $views_as_string = ''; |
|
1526 | + private $echo_and_die = false; |
|
1527 | + protected $theme = null; |
|
1528 | + protected $default_true_false_text = array('inactive' , 'active'); |
|
1529 | + |
|
1530 | + protected $css_files = array(); |
|
1531 | + protected $js_files = array(); |
|
1532 | + protected $js_lib_files = array(); |
|
1533 | + protected $js_config_files = array(); |
|
1534 | + |
|
1535 | + protected function set_basic_Layout() |
|
1536 | + { |
|
1537 | + if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) |
|
1538 | + { |
|
1539 | + throw new Exception('The template does not exist. Please check your files and try again.', 12); |
|
1540 | + die(); |
|
1541 | + } |
|
1542 | + } |
|
1543 | + |
|
1544 | + protected function showList($ajax = false, $state_info = null) |
|
1545 | + { |
|
1546 | + $data = $this->get_common_data(); |
|
1547 | + |
|
1548 | + $data->order_by = $this->order_by; |
|
1549 | + |
|
1550 | + $data->types = $this->get_field_types(); |
|
1551 | + |
|
1552 | + $data->list = $this->get_list(); |
|
1553 | + $data->list = $this->change_list($data->list , $data->types); |
|
1554 | + $data->list = $this->change_list_add_actions($data->list); |
|
1555 | + |
|
1556 | + $data->total_results = $this->get_total_results(); |
|
1557 | + |
|
1558 | + $data->columns = $this->get_columns(); |
|
1559 | + |
|
1560 | + $data->success_message = $this->get_success_message_at_list($state_info); |
|
1561 | + |
|
1562 | + $data->primary_key = $this->get_primary_key(); |
|
1563 | + $data->add_url = $this->getAddUrl(); |
|
1564 | + $data->edit_url = $this->getEditUrl(); |
|
1565 | + $data->delete_url = $this->getDeleteUrl(); |
|
1566 | + $data->delete_multiple_url = $this->getDeleteMultipleUrl(); |
|
1567 | + $data->read_url = $this->getReadUrl(); |
|
1568 | + $data->ajax_list_url = $this->getAjaxListUrl(); |
|
1569 | + $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); |
|
1570 | + $data->export_url = $this->getExportToExcelUrl(); |
|
1571 | + $data->print_url = $this->getPrintUrl(); |
|
1572 | + $data->actions = $this->actions; |
|
1573 | + $data->unique_hash = $this->get_method_hash(); |
|
1574 | + $data->order_by = $this->order_by; |
|
1575 | + |
|
1576 | + $data->unset_add = $this->unset_add; |
|
1577 | + $data->unset_edit = $this->unset_edit; |
|
1578 | + $data->unset_read = $this->unset_read; |
|
1579 | + $data->unset_delete = $this->unset_delete; |
|
1580 | + $data->unset_export = $this->unset_export; |
|
1581 | + $data->unset_print = $this->unset_print; |
|
1582 | + |
|
1583 | + $default_per_page = $this->config->default_per_page; |
|
1584 | + $data->paging_options = $this->config->paging_options; |
|
1585 | + $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; |
|
1586 | + |
|
1587 | + if($data->list === false) |
|
1588 | + { |
|
1589 | + throw new Exception('It is impossible to get data. Please check your model and try again.', 13); |
|
1590 | + $data->list = array(); |
|
1591 | + } |
|
1592 | + |
|
1593 | + foreach($data->list as $num_row => $row) |
|
1594 | + { |
|
1595 | + $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; |
|
1596 | + $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; |
|
1597 | + $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; |
|
1598 | + $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; |
|
1599 | + } |
|
1600 | + |
|
1601 | + if(!$ajax) |
|
1602 | + { |
|
1603 | + $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); |
|
1604 | + |
|
1605 | + $data->list_view = $this->_theme_view('list.php',$data,true); |
|
1606 | + $this->_theme_view('list_template.php',$data); |
|
1607 | + } |
|
1608 | + else |
|
1609 | + { |
|
1610 | + $this->set_echo_and_die(); |
|
1611 | + $this->_theme_view('list.php',$data); |
|
1612 | + } |
|
1613 | + } |
|
1614 | + |
|
1615 | + protected function exportToExcel($state_info = null) |
|
1616 | + { |
|
1617 | + $data = $this->get_common_data(); |
|
1618 | + |
|
1619 | + $data->order_by = $this->order_by; |
|
1620 | + $data->types = $this->get_field_types(); |
|
1621 | + |
|
1622 | + $data->list = $this->get_list(); |
|
1623 | + $data->list = $this->change_list($data->list , $data->types); |
|
1624 | + $data->list = $this->change_list_add_actions($data->list); |
|
1625 | + |
|
1626 | + $data->total_results = $this->get_total_results(); |
|
1627 | + |
|
1628 | + $data->columns = $this->get_columns(); |
|
1629 | + $data->primary_key = $this->get_primary_key(); |
|
1630 | + |
|
1631 | + @ob_end_clean(); |
|
1632 | + $this->_export_to_excel($data); |
|
1633 | + } |
|
1634 | + |
|
1635 | + protected function _export_to_excel($data) |
|
1636 | + { |
|
1637 | + /** |
|
1638 | + * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining |
|
1639 | + * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. |
|
1640 | + * */ |
|
1641 | + |
|
1642 | + $string_to_export = ""; |
|
1643 | + foreach($data->columns as $column){ |
|
1644 | + $string_to_export .= $column->display_as."\t"; |
|
1645 | + } |
|
1646 | + $string_to_export .= "\n"; |
|
1647 | + |
|
1648 | + foreach($data->list as $num_row => $row){ |
|
1649 | + foreach($data->columns as $column){ |
|
1650 | + $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; |
|
1651 | + } |
|
1652 | + $string_to_export .= "\n"; |
|
1653 | + } |
|
1654 | + |
|
1655 | + // Convert to UTF-16LE and Prepend BOM |
|
1656 | + $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); |
|
1657 | + |
|
1658 | + $filename = "export-".date("Y-m-d_H:i:s").".xls"; |
|
1659 | + |
|
1660 | + header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); |
|
1661 | + header('Content-Disposition: attachment; filename='.$filename); |
|
1662 | + header("Cache-Control: no-cache"); |
|
1663 | + echo $string_to_export; |
|
1664 | + die(); |
|
1665 | + } |
|
1666 | + |
|
1667 | + protected function print_webpage($state_info = null) |
|
1668 | + { |
|
1669 | + $data = $this->get_common_data(); |
|
1670 | + |
|
1671 | + $data->order_by = $this->order_by; |
|
1672 | + $data->types = $this->get_field_types(); |
|
1673 | + |
|
1674 | + $data->list = $this->get_list(); |
|
1675 | + $data->list = $this->change_list($data->list , $data->types); |
|
1676 | + $data->list = $this->change_list_add_actions($data->list); |
|
1677 | + |
|
1678 | + $data->total_results = $this->get_total_results(); |
|
1679 | + |
|
1680 | + $data->columns = $this->get_columns(); |
|
1681 | + $data->primary_key = $this->get_primary_key(); |
|
1682 | + |
|
1683 | + @ob_end_clean(); |
|
1684 | + $this->_print_webpage($data); |
|
1685 | + } |
|
1686 | + |
|
1687 | + protected function _print_webpage($data) |
|
1688 | + { |
|
1689 | + $string_to_print = "<meta charset=\"utf-8\" /><style type=\"text/css\" > |
|
1690 | + #print-table{ color: #000; background: #fff; font-family: Verdana,Tahoma,Helvetica,sans-serif; font-size: 13px;} |
|
1691 | + #print-table table tr td, #print-table table tr th{ border: 1px solid black; border-bottom: none; border-right: none; padding: 4px 8px 4px 4px} |
|
1692 | + #print-table table{ border-bottom: 1px solid black; border-right: 1px solid black} |
|
1693 | + #print-table table tr th{text-align: left;background: #ddd} |
|
1694 | + #print-table table tr:nth-child(odd){background: #eee} |
|
1695 | + </style>"; |
|
1696 | + $string_to_print .= "<div id='print-table'>"; |
|
1697 | + |
|
1698 | + $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>'; |
|
1699 | + foreach($data->columns as $column){ |
|
1700 | + $string_to_print .= "<th>".$column->display_as."</th>"; |
|
1701 | + } |
|
1702 | + $string_to_print .= "</tr>"; |
|
1703 | + |
|
1704 | + foreach($data->list as $num_row => $row){ |
|
1705 | + $string_to_print .= "<tr>"; |
|
1706 | + foreach($data->columns as $column){ |
|
1707 | + $string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>"; |
|
1708 | + } |
|
1709 | + $string_to_print .= "</tr>"; |
|
1710 | + } |
|
1711 | + |
|
1712 | + $string_to_print .= "</table></div>"; |
|
1713 | + |
|
1714 | + echo $string_to_print; |
|
1715 | + die(); |
|
1716 | + } |
|
1717 | + |
|
1718 | + protected function _trim_export_string($value) |
|
1719 | + { |
|
1720 | + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
1721 | + return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); |
|
1722 | + } |
|
1723 | + |
|
1724 | + protected function _trim_print_string($value) |
|
1725 | + { |
|
1726 | + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
1727 | + |
|
1728 | + //If the value has only spaces and nothing more then add the whitespace html character |
|
1729 | + if(str_replace(" ","",$value) == "") |
|
1730 | + $value = " "; |
|
1731 | + |
|
1732 | + return strip_tags($value); |
|
1733 | + } |
|
1734 | + |
|
1735 | + protected function set_echo_and_die() |
|
1736 | + { |
|
1737 | + $this->echo_and_die = true; |
|
1738 | + } |
|
1739 | + |
|
1740 | + protected function unset_echo_and_die() |
|
1741 | + { |
|
1742 | + $this->echo_and_die = false; |
|
1743 | + } |
|
1744 | + |
|
1745 | + protected function showListInfo() |
|
1746 | + { |
|
1747 | + $this->set_echo_and_die(); |
|
1748 | + |
|
1749 | + $total_results = (int)$this->get_total_results(); |
|
1750 | + @ob_end_clean(); |
|
1751 | + echo json_encode(array('total_results' => $total_results)); |
|
1752 | + die(); |
|
1753 | + } |
|
1754 | + |
|
1755 | + protected function change_list_add_actions($list) |
|
1756 | + { |
|
1757 | + if(empty($this->actions)) |
|
1758 | + return $list; |
|
1759 | + |
|
1760 | + $primary_key = $this->get_primary_key(); |
|
1761 | + |
|
1762 | + foreach($list as $num_row => $row) |
|
1763 | + { |
|
1764 | + $actions_urls = array(); |
|
1765 | + foreach($this->actions as $unique_id => $action) |
|
1766 | + { |
|
1767 | + if(!empty($action->url_callback)) |
|
1768 | + { |
|
1769 | + $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); |
|
1770 | + } |
|
1771 | + else |
|
1772 | + { |
|
1773 | + $actions_urls[$unique_id] = |
|
1774 | + $action->url_has_http ? |
|
1775 | + $action->link_url.$row->$primary_key : |
|
1776 | + site_url($action->link_url.'/'.$row->$primary_key); |
|
1777 | + } |
|
1778 | + } |
|
1779 | + $row->action_urls = $actions_urls; |
|
1780 | + } |
|
1781 | + |
|
1782 | + return $list; |
|
1783 | + } |
|
1784 | + |
|
1785 | + protected function change_list($list,$types) |
|
1786 | + { |
|
1787 | + $primary_key = $this->get_primary_key(); |
|
1788 | + $has_callbacks = !empty($this->callback_column) ? true : false; |
|
1789 | + $output_columns = $this->get_columns(); |
|
1790 | + foreach($list as $num_row => $row) |
|
1791 | + { |
|
1792 | + foreach($output_columns as $column) |
|
1793 | + { |
|
1794 | + $field_name = $column->field_name; |
|
1795 | + $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
|
1796 | + if( $has_callbacks && isset($this->callback_column[$field_name]) ) |
|
1797 | + $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
|
1798 | + elseif(isset($types[$field_name])) |
|
1799 | + $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
1800 | + else |
|
1801 | + $list[$num_row]->$field_name = $field_value; |
|
1802 | + } |
|
1803 | + } |
|
1804 | + |
|
1805 | + return $list; |
|
1806 | + } |
|
1807 | + |
|
1808 | + protected function showAddForm() |
|
1809 | + { |
|
1810 | + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
1811 | + |
|
1812 | + $data = $this->get_common_data(); |
|
1813 | + $data->types = $this->get_field_types(); |
|
1814 | + |
|
1815 | + $data->list_url = $this->getListUrl(); |
|
1816 | + $data->insert_url = $this->getInsertUrl(); |
|
1817 | + $data->validation_url = $this->getValidationInsertUrl(); |
|
1818 | + $data->input_fields = $this->get_add_input_fields(); |
|
1819 | + |
|
1820 | + $data->fields = $this->get_add_fields(); |
|
1821 | + $data->hidden_fields = $this->get_add_hidden_fields(); |
|
1822 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
1823 | + $data->unique_hash = $this->get_method_hash(); |
|
1824 | + $data->is_ajax = $this->_is_ajax(); |
|
1825 | + |
|
1826 | + $this->_theme_view('add.php',$data); |
|
1827 | + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
1828 | + |
|
1829 | + $this->_get_ajax_results(); |
|
1830 | + } |
|
1831 | + |
|
1832 | + protected function showEditForm($state_info) |
|
1833 | + { |
|
1834 | + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
1835 | + |
|
1836 | + $data = $this->get_common_data(); |
|
1837 | + $data->types = $this->get_field_types(); |
|
1838 | + |
|
1839 | + $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
1840 | + |
|
1841 | + $data->add_url = $this->getAddUrl(); |
|
1842 | + |
|
1843 | + $data->list_url = $this->getListUrl(); |
|
1844 | + $data->update_url = $this->getUpdateUrl($state_info); |
|
1845 | + $data->delete_url = $this->getDeleteUrl($state_info); |
|
1846 | + $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
1847 | + $data->input_fields = $this->get_edit_input_fields($data->field_values); |
|
1848 | + $data->unique_hash = $this->get_method_hash(); |
|
1849 | + |
|
1850 | + $data->fields = $this->get_edit_fields(); |
|
1851 | + $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
1852 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
1853 | + |
|
1854 | + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
1855 | + $data->is_ajax = $this->_is_ajax(); |
|
1856 | + |
|
1857 | + $this->_theme_view('edit.php',$data); |
|
1858 | + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
1859 | + |
|
1860 | + $this->_get_ajax_results(); |
|
1861 | + } |
|
1862 | + |
|
1863 | + protected function showReadForm($state_info) |
|
1864 | + { |
|
1865 | + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
1866 | + |
|
1867 | + $data = $this->get_common_data(); |
|
1868 | + $data->types = $this->get_field_types(); |
|
1869 | + |
|
1870 | + $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
1871 | + |
|
1872 | + $data->add_url = $this->getAddUrl(); |
|
1873 | + |
|
1874 | + $data->list_url = $this->getListUrl(); |
|
1875 | + $data->update_url = $this->getUpdateUrl($state_info); |
|
1876 | + $data->delete_url = $this->getDeleteUrl($state_info); |
|
1877 | + $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
1878 | + $data->input_fields = $this->get_read_input_fields($data->field_values); |
|
1879 | + $data->unique_hash = $this->get_method_hash(); |
|
1880 | + |
|
1881 | + $data->fields = $this->get_read_fields(); |
|
1882 | + $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
1883 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
1884 | + |
|
1885 | + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
1886 | + $data->is_ajax = $this->_is_ajax(); |
|
1887 | + |
|
1888 | + $this->_theme_view('read.php',$data); |
|
1889 | + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
1890 | + |
|
1891 | + $this->_get_ajax_results(); |
|
1892 | + } |
|
1893 | + |
|
1894 | + protected function delete_layout($delete_result = true) |
|
1895 | + { |
|
1896 | + @ob_end_clean(); |
|
1897 | + if($delete_result === false) |
|
1898 | + { |
|
1899 | + $error_message = '<p>'.$this->l('delete_error_message').'</p>'; |
|
1900 | + |
|
1901 | + echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); |
|
1902 | + } |
|
1903 | + else |
|
1904 | + { |
|
1905 | + $success_message = '<p>'.$this->l('delete_success_message').'</p>'; |
|
1906 | + |
|
1907 | + echo json_encode(array('success' => true , 'success_message' => $success_message)); |
|
1908 | + } |
|
1909 | + $this->set_echo_and_die(); |
|
1910 | + } |
|
1911 | + |
|
1912 | + protected function get_success_message_at_list($field_info = null) |
|
1913 | + { |
|
1914 | + if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) |
|
1915 | + { |
|
1916 | + if(!empty($field_info->primary_key) && !$this->unset_edit) |
|
1917 | + { |
|
1918 | + return $this->l('insert_success_message')." <a class='go-to-edit-form' href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
1919 | + } |
|
1920 | + else |
|
1921 | + { |
|
1922 | + return $this->l('insert_success_message'); |
|
1923 | + } |
|
1924 | + } |
|
1925 | + else |
|
1926 | + { |
|
1927 | + return null; |
|
1928 | + } |
|
1929 | + } |
|
1930 | + |
|
1931 | + protected function insert_layout($insert_result = false) |
|
1932 | + { |
|
1933 | + @ob_end_clean(); |
|
1934 | + if($insert_result === false) |
|
1935 | + { |
|
1936 | + echo json_encode(array('success' => false)); |
|
1937 | + } |
|
1938 | + else |
|
1939 | + { |
|
1940 | + $success_message = '<p>'.$this->l('insert_success_message'); |
|
1941 | + |
|
1942 | + if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) |
|
1943 | + { |
|
1944 | + $success_message .= " <a class='go-to-edit-form' href='".$this->getEditUrl($insert_result)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
1945 | + |
|
1946 | + if (!$this->_is_ajax()) { |
|
1947 | + $success_message .= $this->l('form_or'); |
|
1948 | + } |
|
1949 | + } |
|
1950 | + |
|
1951 | + if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
1952 | + { |
|
1953 | + $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
1954 | + } |
|
1955 | + |
|
1956 | + $success_message .= '</p>'; |
|
1957 | + |
|
1958 | + echo json_encode(array( |
|
1959 | + 'success' => true , |
|
1960 | + 'insert_primary_key' => $insert_result, |
|
1961 | + 'success_message' => $success_message, |
|
1962 | + 'success_list_url' => $this->getListSuccessUrl($insert_result) |
|
1963 | + )); |
|
1964 | + } |
|
1965 | + $this->set_echo_and_die(); |
|
1966 | + } |
|
1967 | + |
|
1968 | + protected function validation_layout($validation_result) |
|
1969 | + { |
|
1970 | + @ob_end_clean(); |
|
1971 | + echo json_encode($validation_result); |
|
1972 | + $this->set_echo_and_die(); |
|
1973 | + } |
|
1974 | + |
|
1975 | + protected function upload_layout($upload_result, $field_name) |
|
1976 | + { |
|
1977 | + @ob_end_clean(); |
|
1978 | + if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) |
|
1979 | + { |
|
1980 | + echo json_encode( |
|
1981 | + (object)array( |
|
1982 | + 'success' => true, |
|
1983 | + 'files' => $upload_result |
|
1984 | + )); |
|
1985 | + } |
|
1986 | + else |
|
1987 | + { |
|
1988 | + $result = (object)array('success' => false); |
|
1989 | + if(is_string($upload_result)) |
|
1990 | + $result->message = $upload_result; |
|
1991 | + if(!empty($upload_result[0]->error)) |
|
1992 | + $result->message = $upload_result[0]->error; |
|
1993 | + |
|
1994 | + echo json_encode($result); |
|
1995 | + } |
|
1996 | + |
|
1997 | + $this->set_echo_and_die(); |
|
1998 | + } |
|
1999 | + |
|
2000 | + protected function delete_file_layout($upload_result) |
|
2001 | + { |
|
2002 | + @ob_end_clean(); |
|
2003 | + if($upload_result !== false) |
|
2004 | + { |
|
2005 | + echo json_encode( (object)array( 'success' => true ) ); |
|
2006 | + } |
|
2007 | + else |
|
2008 | + { |
|
2009 | + echo json_encode((object)array('success' => false)); |
|
2010 | + } |
|
2011 | + |
|
2012 | + $this->set_echo_and_die(); |
|
2013 | + } |
|
2014 | + |
|
2015 | + public function set_css($css_file) |
|
2016 | + { |
|
2017 | + $this->css_files[sha1($css_file)] = base_url().$css_file; |
|
2018 | + } |
|
2019 | + |
|
2020 | + public function set_js($js_file) |
|
2021 | + { |
|
2022 | + $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
2023 | + } |
|
2024 | + |
|
2025 | + public function set_js_lib($js_file) |
|
2026 | + { |
|
2027 | + $this->js_lib_files[sha1($js_file)] = base_url().$js_file; |
|
2028 | + $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
2029 | + } |
|
2030 | + |
|
2031 | + public function set_js_config($js_file) |
|
2032 | + { |
|
2033 | + $this->js_config_files[sha1($js_file)] = base_url().$js_file; |
|
2034 | + $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
2035 | + } |
|
2036 | + |
|
2037 | + public function is_IE7() |
|
2038 | + { |
|
2039 | + return isset($_SERVER['HTTP_USER_AGENT']) |
|
2040 | + && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) |
|
2041 | + ? true : false; |
|
2042 | + } |
|
2043 | + |
|
2044 | + public function get_css_files() |
|
2045 | + { |
|
2046 | + return $this->css_files; |
|
2047 | + } |
|
2048 | + |
|
2049 | + public function get_js_files() |
|
2050 | + { |
|
2051 | + return $this->js_files; |
|
2052 | + } |
|
2053 | + |
|
2054 | + public function get_js_lib_files() |
|
2055 | + { |
|
2056 | + return $this->js_lib_files; |
|
2057 | + } |
|
2058 | + |
|
2059 | + public function get_js_config_files() |
|
2060 | + { |
|
2061 | + return $this->js_config_files; |
|
2062 | + } |
|
2063 | + |
|
2064 | + /** |
|
2065 | + * Load Javascripts |
|
2066 | + **/ |
|
2067 | + protected function load_js_fancybox() |
|
2068 | + { |
|
2069 | + $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); |
|
2070 | + |
|
2071 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); |
|
2072 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); |
|
2073 | + } |
|
2074 | + |
|
2075 | + protected function load_js_chosen() |
|
2076 | + { |
|
2077 | + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
2078 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
2079 | + } |
|
2080 | + |
|
2081 | + protected function load_js_jqueryui() |
|
2082 | + { |
|
2083 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2084 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2085 | + } |
|
2086 | + |
|
2087 | + protected function load_js_uploader() |
|
2088 | + { |
|
2089 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2090 | + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); |
|
2091 | + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); |
|
2092 | + |
|
2093 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2094 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); |
|
2095 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); |
|
2096 | + |
|
2097 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); |
|
2098 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); |
|
2099 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); |
|
2100 | + } |
|
2101 | + |
|
2102 | + protected function get_layout() |
|
2103 | + { |
|
2104 | + $js_files = $this->get_js_files(); |
|
2105 | + $css_files = $this->get_css_files(); |
|
2106 | + |
|
2107 | + $js_lib_files = $this->get_js_lib_files(); |
|
2108 | + $js_config_files = $this->get_js_config_files(); |
|
2109 | + |
|
2110 | + if ($this->unset_jquery) { |
|
2111 | + unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); |
|
2112 | + } |
|
2113 | + |
|
2114 | + if ($this->unset_jquery_ui) { |
|
2115 | + unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); |
|
2116 | + unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); |
|
2117 | + } |
|
2118 | + |
|
2119 | + if ($this->unset_bootstrap) { |
|
2120 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); |
|
2121 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); |
|
2122 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); |
|
2123 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); |
|
2124 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); |
|
2125 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); |
|
2126 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.css')]); |
|
2127 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); |
|
2128 | + } |
|
2129 | + |
|
2130 | + if($this->echo_and_die === false) |
|
2131 | + { |
|
2132 | + /** Initialize JavaScript variables */ |
|
2133 | + $js_vars = array( |
|
2134 | + 'default_javascript_path' => base_url().$this->default_javascript_path, |
|
2135 | + 'default_css_path' => base_url().$this->default_css_path, |
|
2136 | + 'default_texteditor_path' => base_url().$this->default_texteditor_path, |
|
2137 | + 'default_theme_path' => base_url().$this->default_theme_path, |
|
2138 | + 'base_url' => base_url() |
|
2139 | + ); |
|
2140 | + $this->_add_js_vars($js_vars); |
|
2141 | + |
|
2142 | + return (object)array( |
|
2143 | + 'js_files' => $js_files, |
|
2144 | + 'js_lib_files' => $js_lib_files, |
|
2145 | + 'js_config_files' => $js_config_files, |
|
2146 | + 'css_files' => $css_files, |
|
2147 | + 'output' => $this->views_as_string, |
|
2148 | + ); |
|
2149 | + } |
|
2150 | + elseif($this->echo_and_die === true) |
|
2151 | + { |
|
2152 | + echo $this->views_as_string; |
|
2153 | + die(); |
|
2154 | + } |
|
2155 | + } |
|
2156 | + |
|
2157 | + protected function update_layout($update_result = false, $state_info = null) |
|
2158 | + { |
|
2159 | + @ob_end_clean(); |
|
2160 | + if($update_result === false) |
|
2161 | + { |
|
2162 | + echo json_encode(array('success' => $update_result)); |
|
2163 | + } |
|
2164 | + else |
|
2165 | + { |
|
2166 | + $success_message = '<p>'.$this->l('update_success_message'); |
|
2167 | + if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
2168 | + { |
|
2169 | + $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
2170 | + } |
|
2171 | + $success_message .= '</p>'; |
|
2172 | + |
|
2173 | + echo json_encode(array( |
|
2174 | + 'success' => true , |
|
2175 | + 'insert_primary_key' => $update_result, |
|
2176 | + 'success_message' => $success_message, |
|
2177 | + 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) |
|
2178 | + )); |
|
2179 | + } |
|
2180 | + $this->set_echo_and_die(); |
|
2181 | + } |
|
2182 | + |
|
2183 | + protected function get_integer_input($field_info,$value) |
|
2184 | + { |
|
2185 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); |
|
2186 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); |
|
2187 | + $extra_attributes = ''; |
|
2188 | + if(!empty($field_info->db_max_length)) |
|
2189 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
2190 | + $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric form-control' $extra_attributes />"; |
|
2191 | + return $input; |
|
2192 | + } |
|
2193 | + |
|
2194 | + protected function get_true_false_input($field_info,$value) |
|
2195 | + { |
|
2196 | + $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; |
|
2197 | + |
|
2198 | + $input = "<div class='pretty-radio-buttons'>"; |
|
2199 | + |
|
2200 | + $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; |
|
2201 | + $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; |
|
2202 | + $input .= |
|
2203 | + "<div class=\"radio\"><label> |
|
2204 | + <input id='field-{$field_info->name}-true' type=\"radio\" name=\"{$field_info->name}\" value=\"1\" $checked /> |
|
2205 | + $true_string |
|
2206 | + </label> </div>"; |
|
2207 | + |
|
2208 | + $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; |
|
2209 | + $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; |
|
2210 | + $input .= |
|
2211 | + "<div class=\"radio\"><label> |
|
2212 | + <input id='field-{$field_info->name}-false' type=\"radio\" name=\"{$field_info->name}\" value=\"0\" $checked /> |
|
2213 | + $false_string |
|
2214 | + </label> </div>"; |
|
2215 | + |
|
2216 | + $input .= "</div>"; |
|
2217 | + |
|
2218 | + return $input; |
|
2219 | + } |
|
2220 | + |
|
2221 | + protected function get_string_input($field_info,$value) |
|
2222 | + { |
|
2223 | + $value = !is_string($value) ? '' : str_replace('"',""",$value); |
|
2224 | + |
|
2225 | + $extra_attributes = ''; |
|
2226 | + if (!empty($field_info->db_max_length)) { |
|
2227 | + |
|
2228 | + if (in_array($field_info->type, array("decimal", "float"))) { |
|
2229 | + $decimal_lentgh = explode(",", $field_info->db_max_length); |
|
2230 | + $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; |
|
2231 | + |
|
2232 | + $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; |
|
2233 | + } else { |
|
2234 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
2235 | + } |
|
2236 | + |
|
2237 | + } |
|
2238 | + $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='text' value=\"$value\" $extra_attributes />"; |
|
2239 | + return $input; |
|
2240 | + } |
|
2241 | + |
|
2242 | + protected function get_text_input($field_info,$value) |
|
2243 | + { |
|
2244 | + if($field_info->extras == 'text_editor') |
|
2245 | + { |
|
2246 | + $editor = $this->config->default_text_editor; |
|
2247 | + switch ($editor) { |
|
2248 | + case 'ckeditor': |
|
2249 | + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); |
|
2250 | + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); |
|
2251 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); |
|
2252 | + break; |
|
2253 | + |
|
2254 | + case 'tinymce': |
|
2255 | + $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); |
|
2256 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); |
|
2257 | + break; |
|
2258 | + |
|
2259 | + case 'markitup': |
|
2260 | + $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); |
|
2261 | + $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); |
|
2262 | + |
|
2263 | + $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); |
|
2264 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); |
|
2265 | + break; |
|
2266 | + } |
|
2267 | + |
|
2268 | + $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; |
|
2269 | + |
|
2270 | + $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>"; |
|
2271 | + } |
|
2272 | + else |
|
2273 | + { |
|
2274 | + $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}'>$value</textarea>"; |
|
2275 | + } |
|
2276 | + return $input; |
|
2277 | + } |
|
2278 | + |
|
2279 | + protected function get_datetime_input($field_info,$value) |
|
2280 | + { |
|
2281 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2282 | + $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); |
|
2283 | + $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); |
|
2284 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2285 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); |
|
2286 | + |
|
2287 | + if($this->language !== 'english') |
|
2288 | + { |
|
2289 | + include($this->default_config_path.'/language_alias.php'); |
|
2290 | + if(array_key_exists($this->language, $language_alias)) |
|
2291 | + { |
|
2292 | + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
2293 | + if(file_exists($i18n_date_js_file)) |
|
2294 | + { |
|
2295 | + $this->set_js_lib($i18n_date_js_file); |
|
2296 | + } |
|
2297 | + |
|
2298 | + $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; |
|
2299 | + if(file_exists($i18n_datetime_js_file)) |
|
2300 | + { |
|
2301 | + $this->set_js_lib($i18n_datetime_js_file); |
|
2302 | + } |
|
2303 | + } |
|
2304 | + } |
|
2305 | + |
|
2306 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); |
|
2307 | + |
|
2308 | + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ |
|
2309 | + list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
2310 | + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
2311 | + $datetime = $date.substr($value,10); |
|
2312 | + } |
|
2313 | + else |
|
2314 | + { |
|
2315 | + $datetime = ''; |
|
2316 | + } |
|
2317 | + $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$datetime' maxlength='19' class='datetime-input form-control' /> |
|
2318 | + <a class='datetime-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> |
|
2319 | + ({$this->ui_date_format}) hh:mm:ss"; |
|
2320 | + return $input; |
|
2321 | + } |
|
2322 | + |
|
2323 | + protected function get_hidden_input($field_info,$value) |
|
2324 | + { |
|
2325 | + if($field_info->extras !== null && $field_info->extras != false) |
|
2326 | + $value = $field_info->extras; |
|
2327 | + $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; |
|
2328 | + return $input; |
|
2329 | + } |
|
2330 | + |
|
2331 | + protected function get_password_input($field_info,$value) |
|
2332 | + { |
|
2333 | + $value = !is_string($value) ? '' : $value; |
|
2334 | + |
|
2335 | + $extra_attributes = ''; |
|
2336 | + if(!empty($field_info->db_max_length)) |
|
2337 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
2338 | + $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; |
|
2339 | + return $input; |
|
2340 | + } |
|
2341 | + |
|
2342 | + protected function get_date_input($field_info,$value) |
|
2343 | + { |
|
2344 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2345 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2346 | + |
|
2347 | + if($this->language !== 'english') |
|
2348 | + { |
|
2349 | + include($this->default_config_path.'/language_alias.php'); |
|
2350 | + if(array_key_exists($this->language, $language_alias)) |
|
2351 | + { |
|
2352 | + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
2353 | + if(file_exists($i18n_date_js_file)) |
|
2354 | + { |
|
2355 | + $this->set_js_lib($i18n_date_js_file); |
|
2356 | + } |
|
2357 | + } |
|
2358 | + } |
|
2359 | + |
|
2360 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); |
|
2361 | + |
|
2362 | + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
2363 | + { |
|
2364 | + list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
2365 | + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
2366 | + } |
|
2367 | + else |
|
2368 | + { |
|
2369 | + $date = ''; |
|
2370 | + } |
|
2371 | + |
|
2372 | + $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$date' maxlength='10' class='datepicker-input form-control' /> |
|
2373 | + <a class='datepicker-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> (".$this->ui_date_format.")"; |
|
2374 | + return $input; |
|
2375 | + } |
|
2376 | + |
|
2377 | + protected function get_dropdown_input($field_info,$value) |
|
2378 | + { |
|
2379 | + $this->load_js_chosen(); |
|
2380 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2381 | + |
|
2382 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2383 | + |
|
2384 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
2385 | + $options = array('' => '') + $field_info->extras; |
|
2386 | + foreach($options as $option_value => $option_label) |
|
2387 | + { |
|
2388 | + $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
2389 | + $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
2390 | + } |
|
2391 | + |
|
2392 | + $input .= "</select>"; |
|
2393 | + return $input; |
|
2394 | + } |
|
2395 | + |
|
2396 | + protected function get_enum_input($field_info,$value) |
|
2397 | + { |
|
2398 | + $this->load_js_chosen(); |
|
2399 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2400 | + |
|
2401 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2402 | + |
|
2403 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
2404 | + $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
2405 | + $options_array = array('' => '') + $options_array; |
|
2406 | + |
|
2407 | + foreach($options_array as $option) |
|
2408 | + { |
|
2409 | + $selected = !empty($value) && $value == $option ? "selected='selected'" : ''; |
|
2410 | + $input .= "<option value='$option' $selected >$option</option>"; |
|
2411 | + } |
|
2412 | + |
|
2413 | + $input .= "</select>"; |
|
2414 | + return $input; |
|
2415 | + } |
|
2416 | + |
|
2417 | + protected function get_readonly_input($field_info, $value) |
|
2418 | + { |
|
2419 | + $read_only_value = " "; |
|
2420 | + |
|
2421 | + if (!empty($value) && !is_array($value)) { |
|
2422 | + $read_only_value = $value; |
|
2423 | + } elseif (is_array($value)) { |
|
2424 | + $all_values = array_values($value); |
|
2425 | + $read_only_value = implode(", ",$all_values); |
|
2426 | + } |
|
2427 | + |
|
2428 | + return '<div id="field-'.$field_info->name.'" class="readonly_label">'.$read_only_value.'</div>'; |
|
2429 | + } |
|
2430 | + |
|
2431 | + protected function get_set_input($field_info,$value) |
|
2432 | + { |
|
2433 | + $this->load_js_chosen(); |
|
2434 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2435 | + |
|
2436 | + $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
2437 | + $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
2438 | + |
|
2439 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2440 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
2441 | + |
|
2442 | + foreach($options_array as $option) |
|
2443 | + { |
|
2444 | + $selected = !empty($value) && in_array($option,$selected_values) ? "selected='selected'" : ''; |
|
2445 | + $input .= "<option value='$option' $selected >$option</option>"; |
|
2446 | + } |
|
2447 | + |
|
2448 | + $input .= "</select>"; |
|
2449 | + |
|
2450 | + return $input; |
|
2451 | + } |
|
2452 | + |
|
2453 | + protected function get_multiselect_input($field_info,$value) |
|
2454 | + { |
|
2455 | + $this->load_js_chosen(); |
|
2456 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2457 | + |
|
2458 | + $options_array = $field_info->extras; |
|
2459 | + $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
2460 | + |
|
2461 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2462 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
2463 | + |
|
2464 | + foreach($options_array as $option_value => $option_label) |
|
2465 | + { |
|
2466 | + $selected = !empty($value) && in_array($option_value,$selected_values) ? "selected='selected'" : ''; |
|
2467 | + $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
2468 | + } |
|
2469 | + |
|
2470 | + $input .= "</select>"; |
|
2471 | + |
|
2472 | + return $input; |
|
2473 | + } |
|
2474 | + |
|
2475 | + protected function get_relation_input($field_info,$value) |
|
2476 | + { |
|
2477 | + $this->load_js_chosen(); |
|
2478 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2479 | + |
|
2480 | + $ajax_limitation = 10000; |
|
2481 | + $total_rows = $this->get_relation_total_rows($field_info->extras); |
|
2482 | + |
|
2483 | + |
|
2484 | + //Check if we will use ajax for our queries or just clien-side javascript |
|
2485 | + $using_ajax = $total_rows > $ajax_limitation ? true : false; |
|
2486 | + |
|
2487 | + //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 |
|
2488 | + $using_ajax = false; |
|
2489 | + |
|
2490 | + //If total rows are more than the limitation, use the ajax plugin |
|
2491 | + $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; |
|
2492 | + |
|
2493 | + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
2494 | + |
|
2495 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
2496 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='$ajax_or_not_class' data-placeholder='$select_title' style='width:300px'>"; |
|
2497 | + $input .= "<option value=''></option>"; |
|
2498 | + |
|
2499 | + if(!$using_ajax) |
|
2500 | + { |
|
2501 | + $options_array = $this->get_relation_array($field_info->extras); |
|
2502 | + foreach($options_array as $option_value => $option) |
|
2503 | + { |
|
2504 | + $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
2505 | + $input .= "<option value='$option_value' $selected >$option</option>"; |
|
2506 | + } |
|
2507 | + } |
|
2508 | + elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items |
|
2509 | + { |
|
2510 | + $selected_options_array = $this->get_relation_array($field_info->extras, $value); |
|
2511 | + foreach($selected_options_array as $option_value => $option) |
|
2512 | + { |
|
2513 | + $input .= "<option value='$option_value'selected='selected' >$option</option>"; |
|
2514 | + } |
|
2515 | + } |
|
2516 | + |
|
2517 | + $input .= "</select>"; |
|
2518 | + return $input; |
|
2519 | + } |
|
2520 | + |
|
2521 | + protected function get_relation_readonly_input($field_info,$value) |
|
2522 | + { |
|
2523 | + $options_array = $this->get_relation_array($field_info->extras); |
|
2524 | + |
|
2525 | + $value = isset($options_array[$value]) ? $options_array[$value] : ''; |
|
2526 | + |
|
2527 | + return $this->get_readonly_input($field_info, $value); |
|
2528 | + } |
|
2529 | + |
|
2530 | + protected function get_upload_file_readonly_input($field_info,$value) |
|
2531 | + { |
|
2532 | + $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
2533 | + |
|
2534 | + $value = !empty($value) ? '<a href="'.$file.'" target="_blank">'.$value.'</a>' : ''; |
|
2535 | + |
|
2536 | + return $this->get_readonly_input($field_info, $value); |
|
2537 | + } |
|
2538 | + |
|
2539 | + protected function get_relation_n_n_input($field_info_type, $selected_values) |
|
2540 | + { |
|
2541 | + $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; |
|
2542 | + $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; |
|
2543 | + |
|
2544 | + if($has_priority_field || $is_ie_7) |
|
2545 | + { |
|
2546 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
2547 | + $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); |
|
2548 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
2549 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); |
|
2550 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); |
|
2551 | + |
|
2552 | + if($this->language !== 'english') |
|
2553 | + { |
|
2554 | + include($this->default_config_path.'/language_alias.php'); |
|
2555 | + if(array_key_exists($this->language, $language_alias)) |
|
2556 | + { |
|
2557 | + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; |
|
2558 | + if(file_exists($i18n_date_js_file)) |
|
2559 | + { |
|
2560 | + $this->set_js_lib($i18n_date_js_file); |
|
2561 | + } |
|
2562 | + } |
|
2563 | + } |
|
2564 | + } |
|
2565 | + else |
|
2566 | + { |
|
2567 | + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
2568 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
2569 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
2570 | + } |
|
2571 | + |
|
2572 | + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
2573 | + |
|
2574 | + $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check |
|
2575 | + $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
2576 | + |
|
2577 | + if(empty($unselected_values) && empty($selected_values)) |
|
2578 | + { |
|
2579 | + $input = "Please add {$field_info_type->display_as} first"; |
|
2580 | + } |
|
2581 | + else |
|
2582 | + { |
|
2583 | + $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; |
|
2584 | + $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; |
|
2585 | + |
|
2586 | + $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); |
|
2587 | + $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; |
|
2588 | + |
|
2589 | + if(!empty($unselected_values)) |
|
2590 | + foreach($unselected_values as $id => $name) |
|
2591 | + { |
|
2592 | + $input .= "<option value='$id'>$name</option>"; |
|
2593 | + } |
|
2594 | + |
|
2595 | + if(!empty($selected_values)) |
|
2596 | + foreach($selected_values as $id => $name) |
|
2597 | + { |
|
2598 | + $input .= "<option value='$id' selected='selected'>$name</option>"; |
|
2599 | + } |
|
2600 | + |
|
2601 | + $input .= "</select>"; |
|
2602 | + } |
|
2603 | + |
|
2604 | + return $input; |
|
2605 | + } |
|
2606 | + |
|
2607 | + protected function _convert_bytes_ui_to_bytes($bytes_ui) |
|
2608 | + { |
|
2609 | + $bytes_ui = str_replace(' ','',$bytes_ui); |
|
2610 | + if(strstr($bytes_ui,'MB')) |
|
2611 | + $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
2612 | + elseif(strstr($bytes_ui,'KB')) |
|
2613 | + $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
2614 | + elseif(strstr($bytes_ui,'B')) |
|
2615 | + $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
2616 | + else |
|
2617 | + $bytes = (int)($bytes_ui); |
|
2618 | + |
|
2619 | + return $bytes; |
|
2620 | + } |
|
2621 | + |
|
2622 | + protected function get_upload_file_input($field_info, $value) |
|
2623 | + { |
|
2624 | + $this->load_js_uploader(); |
|
2625 | + |
|
2626 | + //Fancybox |
|
2627 | + $this->load_js_fancybox(); |
|
2628 | + |
|
2629 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); |
|
2630 | + |
|
2631 | + $unique = mt_rand(); |
|
2632 | + |
|
2633 | + $allowed_files = $this->config->file_upload_allow_file_types; |
|
2634 | + $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); |
|
2635 | + $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
2636 | + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
2637 | + |
|
2638 | + $this->_inline_js(' |
|
2639 | + var upload_info_'.$unique.' = { |
|
2640 | + accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, |
|
2641 | + accepted_file_types_ui : "'.$allowed_files_ui.'", |
|
2642 | + max_file_size: '.$max_file_size_bytes.', |
|
2643 | + max_file_size_ui: "'.$max_file_size_ui.'" |
|
2644 | + }; |
|
2645 | + |
|
2646 | + var string_upload_file = "'.$this->l('form_upload_a_file').'"; |
|
2647 | + var string_delete_file = "'.$this->l('string_delete_file').'"; |
|
2648 | + var string_progress = "'.$this->l('string_progress').'"; |
|
2649 | + var error_on_uploading = "'.$this->l('error_on_uploading').'"; |
|
2650 | + var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; |
|
2651 | + |
|
2652 | + var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; |
|
2653 | + var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; |
|
2654 | + var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; |
|
2655 | + var error_min_file_size = "'.$this->l('error_min_file_size').'"; |
|
2656 | + |
|
2657 | + var base_url = "'.base_url().'"; |
|
2658 | + var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; |
|
2659 | + '); |
|
2660 | + |
|
2661 | + $uploader_display_none = empty($value) ? "" : "display:none;"; |
|
2662 | + $file_display_none = empty($value) ? "display:none;" : ""; |
|
2663 | + |
|
2664 | + $is_image = !empty($value) && |
|
2665 | + ( substr($value,-4) == '.jpg' |
|
2666 | + || substr($value,-4) == '.png' |
|
2667 | + || substr($value,-5) == '.jpeg' |
|
2668 | + || substr($value,-4) == '.gif' |
|
2669 | + || substr($value,-5) == '.tiff') |
|
2670 | + ? true : false; |
|
2671 | + |
|
2672 | + $image_class = $is_image ? 'image-thumbnail' : ''; |
|
2673 | + |
|
2674 | + $input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'"> |
|
2675 | + <span>'.$this->l('form_upload_a_file').'</span> |
|
2676 | + <input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'"> |
|
2677 | + <input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" /> |
|
2678 | + </span>'; |
|
2679 | + |
|
2680 | + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); |
|
2681 | + |
|
2682 | + $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
2683 | + |
|
2684 | + $input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>"; |
|
2685 | + $input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>"; |
|
2686 | + $input .= "<a href='".$file_url."' id='file_$unique' class='open-file"; |
|
2687 | + $input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value"; |
|
2688 | + $input .= "</a> "; |
|
2689 | + $input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> "; |
|
2690 | + $input .= "</div><div style='clear:both'></div>"; |
|
2691 | + $input .= "<div id='loading-$unique' style='display:none'><span id='upload-state-message-$unique'></span> <span class='qq-upload-spinner'></span> <span id='progress-$unique'></span></div>"; |
|
2692 | + $input .= "<div style='display:none'><a href='".$this->getUploadUrl($field_info->name)."' id='url_$unique'></a></div>"; |
|
2693 | + $input .= "<div style='display:none'><a href='".$this->getFileDeleteUrl($field_info->name)."' id='delete_url_$unique' rel='$value' ></a></div>"; |
|
2694 | + |
|
2695 | + return $input; |
|
2696 | + } |
|
2697 | + |
|
2698 | + protected function get_add_hidden_fields() |
|
2699 | + { |
|
2700 | + return $this->add_hidden_fields; |
|
2701 | + } |
|
2702 | + |
|
2703 | + protected function get_edit_hidden_fields() |
|
2704 | + { |
|
2705 | + return $this->edit_hidden_fields; |
|
2706 | + } |
|
2707 | + |
|
2708 | + protected function get_add_input_fields($field_values = null) |
|
2709 | + { |
|
2710 | + $fields = $this->get_add_fields(); |
|
2711 | + $types = $this->get_field_types(); |
|
2712 | + |
|
2713 | + $input_fields = array(); |
|
2714 | + |
|
2715 | + foreach($fields as $field_num => $field) |
|
2716 | + { |
|
2717 | + $field_info = $types[$field->field_name]; |
|
2718 | + |
|
2719 | + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
2720 | + |
|
2721 | + if(!isset($this->callback_add_field[$field->field_name])) |
|
2722 | + { |
|
2723 | + $field_input = $this->get_field_input($field_info, $field_value); |
|
2724 | + } |
|
2725 | + else |
|
2726 | + { |
|
2727 | + $field_input = $field_info; |
|
2728 | + $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); |
|
2729 | + } |
|
2730 | + |
|
2731 | + switch ($field_info->crud_type) { |
|
2732 | + case 'invisible': |
|
2733 | + unset($this->add_fields[$field_num]); |
|
2734 | + unset($fields[$field_num]); |
|
2735 | + continue; |
|
2736 | + break; |
|
2737 | + case 'hidden': |
|
2738 | + $this->add_hidden_fields[] = $field_input; |
|
2739 | + unset($this->add_fields[$field_num]); |
|
2740 | + unset($fields[$field_num]); |
|
2741 | + continue; |
|
2742 | + break; |
|
2743 | + } |
|
2744 | + |
|
2745 | + $input_fields[$field->field_name] = $field_input; |
|
2746 | + } |
|
2747 | + |
|
2748 | + return $input_fields; |
|
2749 | + } |
|
2750 | + |
|
2751 | + protected function get_edit_input_fields($field_values = null) |
|
2752 | + { |
|
2753 | + $fields = $this->get_edit_fields(); |
|
2754 | + $types = $this->get_field_types(); |
|
2755 | + |
|
2756 | + $input_fields = array(); |
|
2757 | + |
|
2758 | + foreach($fields as $field_num => $field) |
|
2759 | + { |
|
2760 | + $field_info = $types[$field->field_name]; |
|
2761 | + |
|
2762 | + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
2763 | + if(!isset($this->callback_edit_field[$field->field_name])) |
|
2764 | + { |
|
2765 | + $field_input = $this->get_field_input($field_info, $field_value); |
|
2766 | + } |
|
2767 | + else |
|
2768 | + { |
|
2769 | + $primary_key = $this->getStateInfo()->primary_key; |
|
2770 | + $field_input = $field_info; |
|
2771 | + $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
2772 | + } |
|
2773 | + |
|
2774 | + switch ($field_info->crud_type) { |
|
2775 | + case 'invisible': |
|
2776 | + unset($this->edit_fields[$field_num]); |
|
2777 | + unset($fields[$field_num]); |
|
2778 | + continue; |
|
2779 | + break; |
|
2780 | + case 'hidden': |
|
2781 | + $this->edit_hidden_fields[] = $field_input; |
|
2782 | + unset($this->edit_fields[$field_num]); |
|
2783 | + unset($fields[$field_num]); |
|
2784 | + continue; |
|
2785 | + break; |
|
2786 | + } |
|
2787 | + |
|
2788 | + $input_fields[$field->field_name] = $field_input; |
|
2789 | + } |
|
2790 | + |
|
2791 | + return $input_fields; |
|
2792 | + } |
|
2793 | + |
|
2794 | + protected function get_read_input_fields($field_values = null) |
|
2795 | + { |
|
2796 | + $read_fields = $this->get_read_fields(); |
|
2797 | + |
|
2798 | + $this->field_types = null; |
|
2799 | + $this->required_fields = null; |
|
2800 | + |
|
2801 | + $read_inputs = array(); |
|
2802 | + foreach ($read_fields as $field) { |
|
2803 | + if (!empty($this->change_field_type) |
|
2804 | + && isset($this->change_field_type[$field->field_name]) |
|
2805 | + && $this->change_field_type[$field->field_name]->type == 'hidden') { |
|
2806 | + continue; |
|
2807 | + } |
|
2808 | + $this->field_type($field->field_name, 'readonly'); |
|
2809 | + } |
|
2810 | + |
|
2811 | + $fields = $this->get_read_fields(); |
|
2812 | + $types = $this->get_field_types(); |
|
2813 | + |
|
2814 | + $input_fields = array(); |
|
2815 | + |
|
2816 | + foreach($fields as $field_num => $field) |
|
2817 | + { |
|
2818 | + $field_info = $types[$field->field_name]; |
|
2819 | + |
|
2820 | + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
2821 | + if(!isset($this->callback_read_field[$field->field_name])) |
|
2822 | + { |
|
2823 | + $field_input = $this->get_field_input($field_info, $field_value); |
|
2824 | + } |
|
2825 | + else |
|
2826 | + { |
|
2827 | + $primary_key = $this->getStateInfo()->primary_key; |
|
2828 | + $field_input = $field_info; |
|
2829 | + $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
2830 | + } |
|
2831 | + |
|
2832 | + switch ($field_info->crud_type) { |
|
2833 | + case 'invisible': |
|
2834 | + unset($this->read_fields[$field_num]); |
|
2835 | + unset($fields[$field_num]); |
|
2836 | + continue; |
|
2837 | + break; |
|
2838 | + case 'hidden': |
|
2839 | + $this->read_hidden_fields[] = $field_input; |
|
2840 | + unset($this->read_fields[$field_num]); |
|
2841 | + unset($fields[$field_num]); |
|
2842 | + continue; |
|
2843 | + break; |
|
2844 | + } |
|
2845 | + |
|
2846 | + $input_fields[$field->field_name] = $field_input; |
|
2847 | + } |
|
2848 | + |
|
2849 | + return $input_fields; |
|
2850 | + } |
|
2851 | + |
|
2852 | + protected function setThemeBasics() |
|
2853 | + { |
|
2854 | + $this->theme_path = $this->default_theme_path; |
|
2855 | + if(substr($this->theme_path,-1) != '/') |
|
2856 | + $this->theme_path = $this->theme_path.'/'; |
|
2857 | + |
|
2858 | + include($this->theme_path.$this->theme.'/config.php'); |
|
2859 | + |
|
2860 | + $this->theme_config = $config; |
|
2861 | + } |
|
2862 | + |
|
2863 | + public function set_theme($theme = null) |
|
2864 | + { |
|
2865 | + $this->theme = $theme; |
|
2866 | + |
|
2867 | + return $this; |
|
2868 | + } |
|
2869 | + |
|
2870 | + protected function _get_ajax_results() |
|
2871 | + { |
|
2872 | + //This is a $_POST request rather that $_GET request , because |
|
2873 | + //Codeigniter doesn't like the $_GET requests so much! |
|
2874 | + if ($this->_is_ajax()) { |
|
2875 | + @ob_end_clean(); |
|
2876 | + $results= (object)array( |
|
2877 | + 'output' => $this->views_as_string, |
|
2878 | + 'js_files' => array_values($this->get_js_files()), |
|
2879 | + 'js_lib_files' => array_values($this->get_js_lib_files()), |
|
2880 | + 'js_config_files' => array_values($this->get_js_config_files()), |
|
2881 | + 'css_files' => array_values($this->get_css_files()) |
|
2882 | + ); |
|
2883 | + |
|
2884 | + echo json_encode($results); |
|
2885 | + die; |
|
2886 | + } |
|
2887 | + //else just continue |
|
2888 | + } |
|
2889 | + |
|
2890 | + protected function _is_ajax() |
|
2891 | + { |
|
2892 | + return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; |
|
2893 | + } |
|
2894 | + |
|
2895 | + protected function _theme_view($view, $vars = array(), $return = FALSE) |
|
2896 | + { |
|
2897 | + $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; |
|
2898 | + |
|
2899 | + $file_exists = FALSE; |
|
2900 | + |
|
2901 | + $ext = pathinfo($view, PATHINFO_EXTENSION); |
|
2902 | + $file = ($ext == '') ? $view.'.php' : $view; |
|
2903 | + |
|
2904 | + $view_file = $this->theme_path.$this->theme.'/views/'; |
|
2905 | + |
|
2906 | + if (file_exists($view_file.$file)) |
|
2907 | + { |
|
2908 | + $path = $view_file.$file; |
|
2909 | + $file_exists = TRUE; |
|
2910 | + } |
|
2911 | + |
|
2912 | + if ( ! $file_exists) |
|
2913 | + { |
|
2914 | + throw new Exception('Unable to load the requested file: '.$file, 16); |
|
2915 | + } |
|
2916 | + |
|
2917 | + extract($vars); |
|
2918 | + |
|
2919 | + #region buffering... |
|
2920 | + ob_start(); |
|
2921 | + |
|
2922 | + include($path); |
|
2923 | + |
|
2924 | + $buffer = ob_get_contents(); |
|
2925 | + @ob_end_clean(); |
|
2926 | + #endregion |
|
2927 | + |
|
2928 | + if ($return === TRUE) |
|
2929 | + { |
|
2930 | + return $buffer; |
|
2931 | + } |
|
2932 | + |
|
2933 | + $this->views_as_string .= $buffer; |
|
2934 | + } |
|
2935 | + |
|
2936 | + protected function _inline_js($inline_js = '') |
|
2937 | + { |
|
2938 | + $this->views_as_string .= "<script type=\"text/javascript\">\n{$inline_js}\n</script>\n"; |
|
2939 | + } |
|
2940 | + |
|
2941 | + protected function _add_js_vars($js_vars = array()) |
|
2942 | + { |
|
2943 | + $javascript_as_string = "<script type=\"text/javascript\">\n"; |
|
2944 | + foreach ($js_vars as $js_var => $js_value) { |
|
2945 | + $javascript_as_string .= "\tvar $js_var = '$js_value';\n"; |
|
2946 | + } |
|
2947 | + $javascript_as_string .= "\n</script>\n"; |
|
2948 | + $this->views_as_string .= $javascript_as_string; |
|
2949 | + } |
|
2950 | + |
|
2951 | + protected function get_views_as_string() |
|
2952 | + { |
|
2953 | + if(!empty($this->views_as_string)) |
|
2954 | + return $this->views_as_string; |
|
2955 | + else |
|
2956 | + return null; |
|
2957 | + } |
|
2958 | +} |
|
2959 | + |
|
2960 | + |
|
2961 | +/** |
|
2962 | + * PHP grocery CRUD |
|
2963 | + * |
|
2964 | + * LICENSE |
|
2965 | + * |
|
2966 | + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
2967 | + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
2968 | + * Please see the corresponding license file for details of these licenses. |
|
2969 | + * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
2970 | + * |
|
2971 | + * @package grocery CRUD |
|
2972 | + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
2973 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
2974 | + * @author John Skoumbourdis <[email protected]> |
|
2975 | + */ |
|
2976 | + |
|
2977 | +// ------------------------------------------------------------------------ |
|
2978 | + |
|
2979 | +/** |
|
2980 | + * PHP grocery States |
|
2981 | + * |
|
2982 | + * States of grocery CRUD |
|
2983 | + * |
|
2984 | + * @package grocery CRUD |
|
2985 | + * @author John Skoumbourdis <[email protected]> |
|
2986 | + * @version 1.5.6 |
|
2987 | + */ |
|
2988 | +class grocery_CRUD_States extends grocery_CRUD_Layout |
|
2989 | +{ |
|
2990 | + const STATE_UNKNOWN = 0; |
|
2991 | + const STATE_LIST = 1; |
|
2992 | + const STATE_ADD = 2; |
|
2993 | + const STATE_EDIT = 3; |
|
2994 | + const STATE_DELETE = 4; |
|
2995 | + const STATE_INSERT = 5; |
|
2996 | + |
|
2997 | + const STATE_READ = 18; |
|
2998 | + const STATE_DELETE_MULTIPLE = '19'; |
|
2999 | + |
|
3000 | + protected $states = array( |
|
3001 | + 0 => 'unknown', |
|
3002 | + 1 => 'list', |
|
3003 | + 2 => 'add', |
|
3004 | + 3 => 'edit', |
|
3005 | + 4 => 'delete', |
|
3006 | + 5 => 'insert', |
|
3007 | + 6 => 'update', |
|
3008 | + 7 => 'ajax_list', |
|
3009 | + 8 => 'ajax_list_info', |
|
3010 | + 9 => 'insert_validation', |
|
3011 | + 10 => 'update_validation', |
|
3012 | + 11 => 'upload_file', |
|
3013 | + 12 => 'delete_file', |
|
3014 | + 13 => 'ajax_relation', |
|
3015 | + 14 => 'ajax_relation_n_n', |
|
3016 | + 15 => 'success', |
|
3017 | + 16 => 'export', |
|
3018 | + 17 => 'print', |
|
3019 | + 18 => 'read', |
|
3020 | + 19 => 'delete_multiple' |
|
3021 | + ); |
|
3022 | + |
|
3023 | + public function getStateInfo() |
|
3024 | + { |
|
3025 | + $state_code = $this->getStateCode(); |
|
3026 | + $segment_object = $this->get_state_info_from_url(); |
|
3027 | + |
|
3028 | + $first_parameter = $segment_object->first_parameter; |
|
3029 | + $second_parameter = $segment_object->second_parameter; |
|
3030 | + |
|
3031 | + $state_info = (object)array(); |
|
3032 | + |
|
3033 | + switch ($state_code) { |
|
3034 | + case self::STATE_LIST: |
|
3035 | + case self::STATE_ADD: |
|
3036 | + //for now... do nothing! Keeping this switch here in case we need any information at the future. |
|
3037 | + break; |
|
3038 | + |
|
3039 | + case self::STATE_EDIT: |
|
3040 | + case self::STATE_READ: |
|
3041 | + if ($first_parameter !== null) { |
|
3042 | + $state_info = (object) array('primary_key' => $first_parameter); |
|
3043 | + } else { |
|
3044 | + throw new Exception('On the state "edit" the Primary key cannot be null', 6); |
|
3045 | + die(); |
|
3046 | + } |
|
3047 | + break; |
|
3048 | + |
|
3049 | + case self::STATE_DELETE: |
|
3050 | + if ($first_parameter !== null) { |
|
3051 | + $state_info = (object) array('primary_key' => $first_parameter); |
|
3052 | + } else { |
|
3053 | + throw new Exception('On the state "delete" the Primary key cannot be null',7); |
|
3054 | + die(); |
|
3055 | + } |
|
3056 | + break; |
|
3057 | + |
|
3058 | + case self::STATE_DELETE_MULTIPLE: |
|
3059 | + if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { |
|
3060 | + $state_info = (object) array('ids' => $_POST['ids']); |
|
3061 | + } else { |
|
3062 | + throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); |
|
3063 | + die(); |
|
3064 | + } |
|
3065 | + break; |
|
3066 | + |
|
3067 | + case self::STATE_INSERT: |
|
3068 | + if(!empty($_POST)) |
|
3069 | + { |
|
3070 | + $state_info = (object)array('unwrapped_data' => $_POST); |
|
3071 | + } |
|
3072 | + else |
|
3073 | + { |
|
3074 | + throw new Exception('On the state "insert" you must have post data',8); |
|
3075 | + die(); |
|
3076 | + } |
|
3077 | + break; |
|
3078 | + |
|
3079 | + case 6: |
|
3080 | + if(!empty($_POST) && $first_parameter !== null) |
|
3081 | + { |
|
3082 | + $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); |
|
3083 | + } |
|
3084 | + elseif(empty($_POST)) |
|
3085 | + { |
|
3086 | + throw new Exception('On the state "update" you must have post data',9); |
|
3087 | + die(); |
|
3088 | + } |
|
3089 | + else |
|
3090 | + { |
|
3091 | + throw new Exception('On the state "update" the Primary key cannot be null',10); |
|
3092 | + die(); |
|
3093 | + } |
|
3094 | + break; |
|
3095 | + |
|
3096 | + case 7: |
|
3097 | + case 8: |
|
3098 | + case 16: //export to excel |
|
3099 | + case 17: //print |
|
3100 | + $state_info = (object)array(); |
|
3101 | + if(!empty($_POST['per_page'])) |
|
3102 | + { |
|
3103 | + $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; |
|
3104 | + } |
|
3105 | + if(!empty($_POST['page'])) |
|
3106 | + { |
|
3107 | + $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; |
|
3108 | + } |
|
3109 | + //If we request an export or a print we don't care about what page we are |
|
3110 | + if($state_code === 16 || $state_code === 17) |
|
3111 | + { |
|
3112 | + $state_info->page = 1; |
|
3113 | + $state_info->per_page = 1000000; //a very big number! |
|
3114 | + } |
|
3115 | + if(!empty($_POST['order_by'][0])) |
|
3116 | + { |
|
3117 | + $state_info->order_by = $_POST['order_by']; |
|
3118 | + } |
|
3119 | + if(!empty($_POST['search_text'])) |
|
3120 | + { |
|
3121 | + if(empty($_POST['search_field'])) |
|
3122 | + { |
|
3123 | + $search_text = strip_tags($_POST['search_field']); |
|
3124 | + $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); |
|
3125 | + } |
|
3126 | + else |
|
3127 | + { |
|
3128 | + if (is_array($_POST['search_field'])) { |
|
3129 | + $search_array = array(); |
|
3130 | + foreach ($_POST['search_field'] as $search_key => $search_field_name) { |
|
3131 | + $search_array[$search_field_name] = !empty($_POST['search_text'][$search_key]) ? $_POST['search_text'][$search_key] : ''; |
|
3132 | + } |
|
3133 | + $state_info->search = $search_array; |
|
3134 | + } else { |
|
3135 | + $state_info->search = (object)array( |
|
3136 | + 'field' => strip_tags($_POST['search_field']) , |
|
3137 | + 'text' => $_POST['search_text'] ); |
|
3138 | + } |
|
3139 | + } |
|
3140 | + } |
|
3141 | + break; |
|
3142 | + |
|
3143 | + case 9: |
|
3144 | + |
|
3145 | + break; |
|
3146 | + |
|
3147 | + case 10: |
|
3148 | + if($first_parameter !== null) |
|
3149 | + { |
|
3150 | + $state_info = (object)array('primary_key' => $first_parameter); |
|
3151 | + } |
|
3152 | + break; |
|
3153 | + |
|
3154 | + case 11: |
|
3155 | + $state_info->field_name = $first_parameter; |
|
3156 | + break; |
|
3157 | + |
|
3158 | + case 12: |
|
3159 | + $state_info->field_name = $first_parameter; |
|
3160 | + $state_info->file_name = $second_parameter; |
|
3161 | + break; |
|
3162 | + |
|
3163 | + case 13: |
|
3164 | + $state_info->field_name = $_POST['field_name']; |
|
3165 | + $state_info->search = $_POST['term']; |
|
3166 | + break; |
|
3167 | + |
|
3168 | + case 14: |
|
3169 | + $state_info->field_name = $_POST['field_name']; |
|
3170 | + $state_info->search = $_POST['term']; |
|
3171 | + break; |
|
3172 | + |
|
3173 | + case 15: |
|
3174 | + $state_info = (object)array( |
|
3175 | + 'primary_key' => $first_parameter, |
|
3176 | + 'success_message' => true |
|
3177 | + ); |
|
3178 | + break; |
|
3179 | + } |
|
3180 | + |
|
3181 | + return $state_info; |
|
3182 | + } |
|
3183 | + |
|
3184 | + protected function getStateCode() |
|
3185 | + { |
|
3186 | + $state_string = $this->get_state_info_from_url()->operation; |
|
3187 | + |
|
3188 | + if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) |
|
3189 | + $state_code = array_search($state_string, $this->states); |
|
3190 | + else |
|
3191 | + $state_code = 0; |
|
3192 | + |
|
3193 | + return $state_code; |
|
3194 | + } |
|
3195 | + |
|
3196 | + protected function state_url($url = '', $is_list_page = false) |
|
3197 | + { |
|
3198 | + //Easy scenario, we had set the crud_url_path |
|
3199 | + if (!empty($this->crud_url_path)) { |
|
3200 | + $state_url = !empty($this->list_url_path) && $is_list_page? |
|
3201 | + $this->list_url_path : |
|
3202 | + $this->crud_url_path.'/'.$url ; |
|
3203 | + } else { |
|
3204 | + //Complicated scenario. The crud_url_path is not specified so we are |
|
3205 | + //trying to understand what is going on from the URL. |
|
3206 | + $ci = &get_instance(); |
|
3207 | + |
|
3208 | + $segment_object = $this->get_state_info_from_url(); |
|
3209 | + $method_name = $this->get_method_name(); |
|
3210 | + $segment_position = $segment_object->segment_position; |
|
3211 | + |
|
3212 | + $state_url_array = array(); |
|
3213 | + |
|
3214 | + if( sizeof($ci->uri->segments) > 0 ) { |
|
3215 | + foreach($ci->uri->segments as $num => $value) |
|
3216 | + { |
|
3217 | + $state_url_array[$num] = $value; |
|
3218 | + if($num == ($segment_position - 1)) |
|
3219 | + break; |
|
3220 | + } |
|
3221 | + |
|
3222 | + if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url |
|
3223 | + $state_url_array[$num+1] = 'index'; |
|
3224 | + } |
|
3225 | + |
|
3226 | + $state_url = site_url(implode('/',$state_url_array).'/'.$url); |
|
3227 | + } |
|
3228 | + |
|
3229 | + return $state_url; |
|
3230 | + } |
|
3231 | + |
|
3232 | + protected function get_state_info_from_url() |
|
3233 | + { |
|
3234 | + $ci = &get_instance(); |
|
3235 | + |
|
3236 | + $segment_position = count($ci->uri->segments) + 1; |
|
3237 | + $operation = 'list'; |
|
3238 | + |
|
3239 | + $segements = $ci->uri->segments; |
|
3240 | + foreach($segements as $num => $value) |
|
3241 | + { |
|
3242 | + if($value != 'unknown' && in_array($value, $this->states)) |
|
3243 | + { |
|
3244 | + $segment_position = (int)$num; |
|
3245 | + $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. |
|
3246 | + } |
|
3247 | + } |
|
3248 | + |
|
3249 | + $function_name = $this->get_method_name(); |
|
3250 | + |
|
3251 | + if($function_name == 'index' && !in_array('index',$ci->uri->segments)) |
|
3252 | + $segment_position++; |
|
3253 | + |
|
3254 | + $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; |
|
3255 | + $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; |
|
3256 | + |
|
3257 | + return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); |
|
3258 | + } |
|
3259 | + |
|
3260 | + protected function get_method_hash() |
|
3261 | + { |
|
3262 | + $ci = &get_instance(); |
|
3263 | + |
|
3264 | + $state_info = $this->get_state_info_from_url(); |
|
3265 | + $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; |
|
3266 | + |
|
3267 | + return $this->crud_url_path !== null |
|
3268 | + ? md5($this->crud_url_path) |
|
3269 | + : md5($this->get_controller_name().$this->get_method_name().$extra_values); |
|
3270 | + } |
|
3271 | + |
|
3272 | + protected function get_method_name() |
|
3273 | + { |
|
3274 | + $ci = &get_instance(); |
|
3275 | + return $ci->router->method; |
|
3276 | + } |
|
3277 | + |
|
3278 | + protected function get_controller_name() |
|
3279 | + { |
|
3280 | + $ci = &get_instance(); |
|
3281 | + return $ci->router->class; |
|
3282 | + } |
|
3283 | + |
|
3284 | + public function getState() |
|
3285 | + { |
|
3286 | + return $this->states[$this->getStateCode()]; |
|
3287 | + } |
|
3288 | + |
|
3289 | + protected function getListUrl() |
|
3290 | + { |
|
3291 | + return $this->state_url('',true); |
|
3292 | + } |
|
3293 | + |
|
3294 | + protected function getAjaxListUrl() |
|
3295 | + { |
|
3296 | + return $this->state_url('ajax_list'); |
|
3297 | + } |
|
3298 | + |
|
3299 | + protected function getExportToExcelUrl() |
|
3300 | + { |
|
3301 | + return $this->state_url('export'); |
|
3302 | + } |
|
3303 | + |
|
3304 | + protected function getPrintUrl() |
|
3305 | + { |
|
3306 | + return $this->state_url('print'); |
|
3307 | + } |
|
3308 | + |
|
3309 | + protected function getAjaxListInfoUrl() |
|
3310 | + { |
|
3311 | + return $this->state_url('ajax_list_info'); |
|
3312 | + } |
|
3313 | + |
|
3314 | + protected function getAddUrl() |
|
3315 | + { |
|
3316 | + return $this->state_url('add'); |
|
3317 | + } |
|
3318 | + |
|
3319 | + protected function getInsertUrl() |
|
3320 | + { |
|
3321 | + return $this->state_url('insert'); |
|
3322 | + } |
|
3323 | + |
|
3324 | + protected function getValidationInsertUrl() |
|
3325 | + { |
|
3326 | + return $this->state_url('insert_validation'); |
|
3327 | + } |
|
3328 | + |
|
3329 | + protected function getValidationUpdateUrl($primary_key = null) |
|
3330 | + { |
|
3331 | + if($primary_key === null) |
|
3332 | + return $this->state_url('update_validation'); |
|
3333 | + else |
|
3334 | + return $this->state_url('update_validation/'.$primary_key); |
|
3335 | + } |
|
3336 | + |
|
3337 | + protected function getEditUrl($primary_key = null) |
|
3338 | + { |
|
3339 | + if($primary_key === null) |
|
3340 | + return $this->state_url('edit'); |
|
3341 | + else |
|
3342 | + return $this->state_url('edit/'.$primary_key); |
|
3343 | + } |
|
3344 | + |
|
3345 | + protected function getReadUrl($primary_key = null) |
|
3346 | + { |
|
3347 | + if($primary_key === null) |
|
3348 | + return $this->state_url('read'); |
|
3349 | + else |
|
3350 | + return $this->state_url('read/'.$primary_key); |
|
3351 | + } |
|
3352 | + |
|
3353 | + protected function getUpdateUrl($state_info) |
|
3354 | + { |
|
3355 | + return $this->state_url('update/'.$state_info->primary_key); |
|
3356 | + } |
|
3357 | + |
|
3358 | + protected function getDeleteUrl($state_info = null) |
|
3359 | + { |
|
3360 | + if (empty($state_info)) { |
|
3361 | + return $this->state_url('delete'); |
|
3362 | + } else { |
|
3363 | + return $this->state_url('delete/'.$state_info->primary_key); |
|
3364 | + } |
|
3365 | + } |
|
3366 | + |
|
3367 | + protected function getDeleteMultipleUrl() |
|
3368 | + { |
|
3369 | + return $this->state_url('delete_multiple'); |
|
3370 | + } |
|
3371 | + |
|
3372 | + protected function getListSuccessUrl($primary_key = null) |
|
3373 | + { |
|
3374 | + if(empty($primary_key)) |
|
3375 | + return $this->state_url('success',true); |
|
3376 | + else |
|
3377 | + return $this->state_url('success/'.$primary_key,true); |
|
3378 | + } |
|
3379 | + |
|
3380 | + protected function getUploadUrl($field_name) |
|
3381 | + { |
|
3382 | + return $this->state_url('upload_file/'.$field_name); |
|
3383 | + } |
|
3384 | + |
|
3385 | + protected function getFileDeleteUrl($field_name) |
|
3386 | + { |
|
3387 | + return $this->state_url('delete_file/'.$field_name); |
|
3388 | + } |
|
3389 | + |
|
3390 | + protected function getAjaxRelationUrl() |
|
3391 | + { |
|
3392 | + return $this->state_url('ajax_relation'); |
|
3393 | + } |
|
3394 | + |
|
3395 | + protected function getAjaxRelationManytoManyUrl() |
|
3396 | + { |
|
3397 | + return $this->state_url('ajax_relation_n_n'); |
|
3398 | + } |
|
3399 | +} |
|
3400 | + |
|
3401 | + |
|
3402 | +/** |
|
3403 | + * PHP grocery CRUD |
|
3404 | + * |
|
3405 | + * LICENSE |
|
3406 | + * |
|
3407 | + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
3408 | + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
3409 | + * Please see the corresponding license file for details of these licenses. |
|
3410 | + * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
3411 | + * |
|
3412 | + * @package grocery CRUD |
|
3413 | + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
3414 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
3415 | + * @version 1.5.6 |
|
3416 | + * @author John Skoumbourdis <[email protected]> |
|
3417 | + */ |
|
3418 | + |
|
3419 | +// ------------------------------------------------------------------------ |
|
3420 | + |
|
3421 | +/** |
|
3422 | + * PHP grocery CRUD |
|
3423 | + * |
|
3424 | + * Creates a full functional CRUD with few lines of code. |
|
3425 | + * |
|
3426 | + * @package grocery CRUD |
|
3427 | + * @author John Skoumbourdis <[email protected]> |
|
3428 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
3429 | + * @link http://www.grocerycrud.com/documentation |
|
3430 | + */ |
|
3431 | +class Grocery_CRUD extends grocery_CRUD_States |
|
3432 | +{ |
|
3433 | + /** |
|
3434 | + * Grocery CRUD version |
|
3435 | + * |
|
3436 | + * @var string |
|
3437 | + */ |
|
3438 | + const VERSION = "1.5.6"; |
|
3439 | + |
|
3440 | + const JQUERY = "jquery-1.11.1.min.js"; |
|
3441 | + const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; |
|
3442 | + const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; |
|
3443 | + |
|
3444 | + protected $state_code = null; |
|
3445 | + protected $state_info = null; |
|
3446 | + protected $columns = null; |
|
3447 | + |
|
3448 | + private $basic_db_table_checked = false; |
|
3449 | + private $columns_checked = false; |
|
3450 | + private $add_fields_checked = false; |
|
3451 | + private $edit_fields_checked = false; |
|
3452 | + private $read_fields_checked = false; |
|
3453 | + |
|
3454 | + protected $default_theme = 'flexigrid'; |
|
3455 | + protected $language = null; |
|
3456 | + protected $lang_strings = array(); |
|
3457 | + protected $php_date_format = null; |
|
3458 | + protected $js_date_format = null; |
|
3459 | + protected $ui_date_format = null; |
|
3460 | + protected $character_limiter = null; |
|
3461 | + protected $config = null; |
|
3462 | + |
|
3463 | + protected $add_fields = null; |
|
3464 | + protected $edit_fields = null; |
|
3465 | + protected $read_fields = null; |
|
3466 | + protected $add_hidden_fields = array(); |
|
3467 | + protected $edit_hidden_fields = array(); |
|
3468 | + protected $field_types = null; |
|
3469 | + protected $basic_db_table = null; |
|
3470 | + protected $theme_config = array(); |
|
3471 | + protected $subject = null; |
|
3472 | + protected $subject_plural = null; |
|
3473 | + protected $display_as = array(); |
|
3474 | + protected $order_by = null; |
|
3475 | + protected $where = array(); |
|
3476 | + protected $like = array(); |
|
3477 | + protected $having = array(); |
|
3478 | + protected $or_having = array(); |
|
3479 | + protected $limit = null; |
|
3480 | + protected $required_fields = array(); |
|
3481 | + protected $_unique_fields = array(); |
|
3482 | + protected $validation_rules = array(); |
|
3483 | + protected $relation = array(); |
|
3484 | + protected $relation_n_n = array(); |
|
3485 | + protected $upload_fields = array(); |
|
3486 | + protected $actions = array(); |
|
3487 | + |
|
3488 | + protected $form_validation = null; |
|
3489 | + protected $change_field_type = null; |
|
3490 | + protected $primary_keys = array(); |
|
3491 | + protected $crud_url_path = null; |
|
3492 | + protected $list_url_path = null; |
|
3493 | + |
|
3494 | + /* The unsetters */ |
|
3495 | + protected $unset_texteditor = array(); |
|
3496 | + protected $unset_add = false; |
|
3497 | + protected $unset_edit = false; |
|
3498 | + protected $unset_delete = false; |
|
3499 | + protected $unset_read = false; |
|
3500 | + protected $unset_jquery = false; |
|
3501 | + protected $unset_jquery_ui = false; |
|
3502 | + protected $unset_bootstrap = false; |
|
3503 | + protected $unset_list = false; |
|
3504 | + protected $unset_export = false; |
|
3505 | + protected $unset_print = false; |
|
3506 | + protected $unset_back_to_list = false; |
|
3507 | + protected $unset_columns = null; |
|
3508 | + protected $unset_add_fields = null; |
|
3509 | + protected $unset_edit_fields = null; |
|
3510 | + protected $unset_read_fields = null; |
|
3511 | + |
|
3512 | + /* Callbacks */ |
|
3513 | + protected $callback_before_insert = null; |
|
3514 | + protected $callback_after_insert = null; |
|
3515 | + protected $callback_insert = null; |
|
3516 | + protected $callback_before_update = null; |
|
3517 | + protected $callback_after_update = null; |
|
3518 | + protected $callback_update = null; |
|
3519 | + protected $callback_before_delete = null; |
|
3520 | + protected $callback_after_delete = null; |
|
3521 | + protected $callback_delete = null; |
|
3522 | + protected $callback_column = array(); |
|
3523 | + protected $callback_add_field = array(); |
|
3524 | + protected $callback_edit_field = array(); |
|
3525 | + protected $callback_upload = null; |
|
3526 | + protected $callback_before_upload = null; |
|
3527 | + protected $callback_after_upload = null; |
|
3528 | + |
|
3529 | + protected $default_javascript_path = null; //autogenerate, please do not modify |
|
3530 | + protected $default_css_path = null; //autogenerate, please do not modify |
|
3531 | + protected $default_texteditor_path = null; //autogenerate, please do not modify |
|
3532 | + protected $default_theme_path = null; //autogenerate, please do not modify |
|
3533 | + protected $default_language_path = 'assets/grocery_crud/languages'; |
|
3534 | + protected $default_config_path = 'assets/grocery_crud/config'; |
|
3535 | + protected $default_assets_path = 'assets/grocery_crud'; |
|
3536 | + |
|
3537 | + /** |
|
3538 | + * |
|
3539 | + * Constructor |
|
3540 | + * |
|
3541 | + * @access public |
|
3542 | + */ |
|
3543 | + public function __construct() |
|
3544 | + { |
|
3545 | + |
|
3546 | + } |
|
3547 | + |
|
3548 | + /** |
|
3549 | + * The displayed columns that user see |
|
3550 | + * |
|
3551 | + * @access public |
|
3552 | + * @param string |
|
3553 | + * @param array |
|
3554 | + * @return void |
|
3555 | + */ |
|
3556 | + public function columns() |
|
3557 | + { |
|
3558 | + $args = func_get_args(); |
|
3559 | + |
|
3560 | + if(isset($args[0]) && is_array($args[0])) |
|
3561 | + { |
|
3562 | + $args = $args[0]; |
|
3563 | + } |
|
3564 | + |
|
3565 | + $this->columns = $args; |
|
3566 | + |
|
3567 | + return $this; |
|
3568 | + } |
|
3569 | + |
|
3570 | + |
|
3571 | + /** |
|
3572 | + * Set Validation Rules |
|
3573 | + * |
|
3574 | + * Important note: If the $field is an array then no automated crud fields will take apart |
|
3575 | + * |
|
3576 | + * @access public |
|
3577 | + * @param mixed |
|
3578 | + * @param string |
|
3579 | + * @return void |
|
3580 | + */ |
|
3581 | + function set_rules($field, $label = '', $rules = '') |
|
3582 | + { |
|
3583 | + if(is_string($field)) |
|
3584 | + { |
|
3585 | + $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); |
|
3586 | + }elseif(is_array($field)) |
|
3587 | + { |
|
3588 | + foreach($field as $num_field => $field_array) |
|
3589 | + { |
|
3590 | + $this->validation_rules[$field_array['field']] = $field_array; |
|
3591 | + } |
|
3592 | + } |
|
3593 | + return $this; |
|
3594 | + } |
|
3595 | + |
|
3596 | + /** |
|
3597 | + * |
|
3598 | + * Changes the default field type |
|
3599 | + * @param string $field |
|
3600 | + * @param string $type |
|
3601 | + * @param array|string $extras |
|
3602 | + */ |
|
3603 | + public function change_field_type($field , $type, $extras = null) |
|
3604 | + { |
|
3605 | + $field_type = (object)array('type' => $type); |
|
3606 | + |
|
3607 | + $field_type->extras = $extras; |
|
3608 | + |
|
3609 | + $this->change_field_type[$field] = $field_type; |
|
3610 | + |
|
3611 | + return $this; |
|
3612 | + } |
|
3613 | + |
|
3614 | + /** |
|
3615 | + * |
|
3616 | + * Just an alias to the change_field_type method |
|
3617 | + * @param string $field |
|
3618 | + * @param string $type |
|
3619 | + * @param array|string $extras |
|
3620 | + */ |
|
3621 | + public function field_type($field , $type, $extras = null) |
|
3622 | + { |
|
3623 | + return $this->change_field_type($field , $type, $extras); |
|
3624 | + } |
|
3625 | + |
|
3626 | + /** |
|
3627 | + * Change the default primary key for a specific table. |
|
3628 | + * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method |
|
3629 | + * |
|
3630 | + * @param string $primary_key_field |
|
3631 | + * @param string $table_name |
|
3632 | + */ |
|
3633 | + public function set_primary_key($primary_key_field, $table_name = null) |
|
3634 | + { |
|
3635 | + $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); |
|
3636 | + |
|
3637 | + return $this; |
|
3638 | + } |
|
3639 | + |
|
3640 | + /** |
|
3641 | + * Unsets the texteditor of the selected fields |
|
3642 | + * |
|
3643 | + * @access public |
|
3644 | + * @param string |
|
3645 | + * @param array |
|
3646 | + * @return void |
|
3647 | + */ |
|
3648 | + public function unset_texteditor() |
|
3649 | + { |
|
3650 | + $args = func_get_args(); |
|
3651 | + |
|
3652 | + if(isset($args[0]) && is_array($args[0])) |
|
3653 | + { |
|
3654 | + $args = $args[0]; |
|
3655 | + } |
|
3656 | + foreach($args as $arg) |
|
3657 | + { |
|
3658 | + $this->unset_texteditor[] = $arg; |
|
3659 | + } |
|
3660 | + |
|
3661 | + return $this; |
|
3662 | + } |
|
3663 | + |
|
3664 | + /** |
|
3665 | + * Unsets just the jquery library from the js. This function can be used if there is already a jquery included |
|
3666 | + * in the main template. This will avoid all jquery conflicts. |
|
3667 | + * |
|
3668 | + * @return void |
|
3669 | + */ |
|
3670 | + public function unset_jquery() |
|
3671 | + { |
|
3672 | + $this->unset_jquery = true; |
|
3673 | + |
|
3674 | + return $this; |
|
3675 | + } |
|
3676 | + |
|
3677 | + /** |
|
3678 | + * Unsets the jquery UI Javascript and CSS. This function is really useful |
|
3679 | + * when the jquery UI JavaScript and CSS are already included in the main template. |
|
3680 | + * This will avoid all jquery UI conflicts. |
|
3681 | + * |
|
3682 | + * @return void |
|
3683 | + */ |
|
3684 | + public function unset_jquery_ui() |
|
3685 | + { |
|
3686 | + $this->unset_jquery_ui = true; |
|
3687 | + |
|
3688 | + return $this; |
|
3689 | + } |
|
3690 | + |
|
3691 | + /** |
|
3692 | + * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included |
|
3693 | + * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. |
|
3694 | + * |
|
3695 | + * @return void |
|
3696 | + */ |
|
3697 | + public function unset_bootstrap() |
|
3698 | + { |
|
3699 | + $this->unset_bootstrap = true; |
|
3700 | + |
|
3701 | + return $this; |
|
3702 | + } |
|
3703 | + |
|
3704 | + /** |
|
3705 | + * Unsets the add operation from the list |
|
3706 | + * |
|
3707 | + * @return void |
|
3708 | + */ |
|
3709 | + public function unset_add() |
|
3710 | + { |
|
3711 | + $this->unset_add = true; |
|
3712 | + |
|
3713 | + return $this; |
|
3714 | + } |
|
3715 | + |
|
3716 | + /** |
|
3717 | + * Unsets the edit operation from the list |
|
3718 | + * |
|
3719 | + * @return void |
|
3720 | + */ |
|
3721 | + public function unset_edit() |
|
3722 | + { |
|
3723 | + $this->unset_edit = true; |
|
3724 | + |
|
3725 | + return $this; |
|
3726 | + } |
|
3727 | + |
|
3728 | + /** |
|
3729 | + * Unsets the delete operation from the list |
|
3730 | + * |
|
3731 | + * @return void |
|
3732 | + */ |
|
3733 | + public function unset_delete() |
|
3734 | + { |
|
3735 | + $this->unset_delete = true; |
|
3736 | + |
|
3737 | + return $this; |
|
3738 | + } |
|
3739 | + |
|
3740 | + /** |
|
3741 | + * Unsets the read operation from the list |
|
3742 | + * |
|
3743 | + * @return void |
|
3744 | + */ |
|
3745 | + public function unset_read() |
|
3746 | + { |
|
3747 | + $this->unset_read = true; |
|
3748 | + |
|
3749 | + return $this; |
|
3750 | + } |
|
3751 | + |
|
3752 | + /** |
|
3753 | + * Just an alias to unset_read |
|
3754 | + * |
|
3755 | + * @return void |
|
3756 | + * */ |
|
3757 | + public function unset_view() |
|
3758 | + { |
|
3759 | + return unset_read(); |
|
3760 | + } |
|
3761 | + |
|
3762 | + /** |
|
3763 | + * Unsets the export button and functionality from the list |
|
3764 | + * |
|
3765 | + * @return void |
|
3766 | + */ |
|
3767 | + public function unset_export() |
|
3768 | + { |
|
3769 | + $this->unset_export = true; |
|
3770 | + |
|
3771 | + return $this; |
|
3772 | + } |
|
3773 | + |
|
3774 | + |
|
3775 | + /** |
|
3776 | + * Unsets the print button and functionality from the list |
|
3777 | + * |
|
3778 | + * @return void |
|
3779 | + */ |
|
3780 | + public function unset_print() |
|
3781 | + { |
|
3782 | + $this->unset_print = true; |
|
3783 | + |
|
3784 | + return $this; |
|
3785 | + } |
|
3786 | + |
|
3787 | + /** |
|
3788 | + * Unsets all the operations from the list |
|
3789 | + * |
|
3790 | + * @return void |
|
3791 | + */ |
|
3792 | + public function unset_operations() |
|
3793 | + { |
|
3794 | + $this->unset_add = true; |
|
3795 | + $this->unset_edit = true; |
|
3796 | + $this->unset_delete = true; |
|
3797 | + $this->unset_read = true; |
|
3798 | + $this->unset_export = true; |
|
3799 | + $this->unset_print = true; |
|
3800 | + |
|
3801 | + return $this; |
|
3802 | + } |
|
3803 | + |
|
3804 | + /** |
|
3805 | + * Unsets a column from the list |
|
3806 | + * |
|
3807 | + * @return void. |
|
3808 | + */ |
|
3809 | + public function unset_columns() |
|
3810 | + { |
|
3811 | + $args = func_get_args(); |
|
3812 | + |
|
3813 | + if(isset($args[0]) && is_array($args[0])) |
|
3814 | + { |
|
3815 | + $args = $args[0]; |
|
3816 | + } |
|
3817 | + |
|
3818 | + $this->unset_columns = $args; |
|
3819 | + |
|
3820 | + return $this; |
|
3821 | + } |
|
3822 | + |
|
3823 | + public function unset_list() |
|
3824 | + { |
|
3825 | + $this->unset_list = true; |
|
3826 | + |
|
3827 | + return $this; |
|
3828 | + } |
|
3829 | + |
|
3830 | + public function unset_fields() |
|
3831 | + { |
|
3832 | + $args = func_get_args(); |
|
3833 | + |
|
3834 | + if(isset($args[0]) && is_array($args[0])) |
|
3835 | + { |
|
3836 | + $args = $args[0]; |
|
3837 | + } |
|
3838 | + |
|
3839 | + $this->unset_add_fields = $args; |
|
3840 | + $this->unset_edit_fields = $args; |
|
3841 | + $this->unset_read_fields = $args; |
|
3842 | + |
|
3843 | + return $this; |
|
3844 | + } |
|
3845 | + |
|
3846 | + public function unset_add_fields() |
|
3847 | + { |
|
3848 | + $args = func_get_args(); |
|
3849 | + |
|
3850 | + if(isset($args[0]) && is_array($args[0])) |
|
3851 | + { |
|
3852 | + $args = $args[0]; |
|
3853 | + } |
|
3854 | + |
|
3855 | + $this->unset_add_fields = $args; |
|
3856 | + |
|
3857 | + return $this; |
|
3858 | + } |
|
3859 | + |
|
3860 | + public function unset_edit_fields() |
|
3861 | + { |
|
3862 | + $args = func_get_args(); |
|
3863 | + |
|
3864 | + if(isset($args[0]) && is_array($args[0])) |
|
3865 | + { |
|
3866 | + $args = $args[0]; |
|
3867 | + } |
|
3868 | + |
|
3869 | + $this->unset_edit_fields = $args; |
|
3870 | + |
|
3871 | + return $this; |
|
3872 | + } |
|
3873 | + |
|
3874 | + public function unset_read_fields() |
|
3875 | + { |
|
3876 | + $args = func_get_args(); |
|
3877 | + |
|
3878 | + if(isset($args[0]) && is_array($args[0])) |
|
3879 | + { |
|
3880 | + $args = $args[0]; |
|
3881 | + } |
|
3882 | + |
|
3883 | + $this->unset_read_fields = $args; |
|
3884 | + |
|
3885 | + return $this; |
|
3886 | + } |
|
3887 | + |
|
3888 | + |
|
3889 | + /** |
|
3890 | + * Unsets everything that has to do with buttons or links with go back to list message |
|
3891 | + * @access public |
|
3892 | + * @return void |
|
3893 | + */ |
|
3894 | + public function unset_back_to_list() |
|
3895 | + { |
|
3896 | + $this->unset_back_to_list = true; |
|
3897 | + |
|
3898 | + return $this; |
|
3899 | + } |
|
3900 | + |
|
3901 | + /** |
|
3902 | + * |
|
3903 | + * The fields that user will see on add/edit |
|
3904 | + * |
|
3905 | + * @access public |
|
3906 | + * @param string |
|
3907 | + * @param array |
|
3908 | + * @return void |
|
3909 | + */ |
|
3910 | + public function fields() |
|
3911 | + { |
|
3912 | + $args = func_get_args(); |
|
3913 | + |
|
3914 | + if(isset($args[0]) && is_array($args[0])) |
|
3915 | + { |
|
3916 | + $args = $args[0]; |
|
3917 | + } |
|
3918 | + |
|
3919 | + $this->add_fields = $args; |
|
3920 | + $this->edit_fields = $args; |
|
3921 | + |
|
3922 | + return $this; |
|
3923 | + } |
|
3924 | + |
|
3925 | + /** |
|
3926 | + * |
|
3927 | + * The fields that user can see . It is only for the add form |
|
3928 | + */ |
|
3929 | + public function add_fields() |
|
3930 | + { |
|
3931 | + $args = func_get_args(); |
|
3932 | + |
|
3933 | + if(isset($args[0]) && is_array($args[0])) |
|
3934 | + { |
|
3935 | + $args = $args[0]; |
|
3936 | + } |
|
3937 | + |
|
3938 | + $this->add_fields = $args; |
|
3939 | + |
|
3940 | + return $this; |
|
3941 | + } |
|
3942 | + |
|
3943 | + /** |
|
3944 | + * |
|
3945 | + * The fields that user can see . It is only for the edit form |
|
3946 | + */ |
|
3947 | + public function edit_fields() |
|
3948 | + { |
|
3949 | + $args = func_get_args(); |
|
3950 | + |
|
3951 | + if(isset($args[0]) && is_array($args[0])) |
|
3952 | + { |
|
3953 | + $args = $args[0]; |
|
3954 | + } |
|
3955 | + |
|
3956 | + $this->edit_fields = $args; |
|
3957 | + |
|
3958 | + return $this; |
|
3959 | + } |
|
3960 | + |
|
3961 | + public function set_read_fields() |
|
3962 | + { |
|
3963 | + $args = func_get_args(); |
|
3964 | + |
|
3965 | + if(isset($args[0]) && is_array($args[0])) { |
|
3966 | + $args = $args[0]; |
|
3967 | + } |
|
3968 | + |
|
3969 | + $this->read_fields = $args; |
|
3970 | + |
|
3971 | + return $this; |
|
3972 | + } |
|
3973 | + |
|
3974 | + /** |
|
3975 | + * |
|
3976 | + * Changes the displaying label of the field |
|
3977 | + * @param $field_name |
|
3978 | + * @param $display_as |
|
3979 | + * @return void |
|
3980 | + */ |
|
3981 | + public function display_as($field_name, $display_as = null) |
|
3982 | + { |
|
3983 | + if(is_array($field_name)) |
|
3984 | + { |
|
3985 | + foreach($field_name as $field => $display_as) |
|
3986 | + { |
|
3987 | + $this->display_as[$field] = $display_as; |
|
3988 | + } |
|
3989 | + } |
|
3990 | + elseif($display_as !== null) |
|
3991 | + { |
|
3992 | + $this->display_as[$field_name] = $display_as; |
|
3993 | + } |
|
3994 | + return $this; |
|
3995 | + } |
|
3996 | + |
|
3997 | + /** |
|
3998 | + * |
|
3999 | + * Load the language strings array from the language file |
|
4000 | + */ |
|
4001 | + protected function _load_language() |
|
4002 | + { |
|
4003 | + if($this->language === null) |
|
4004 | + { |
|
4005 | + $this->language = strtolower($this->config->default_language); |
|
4006 | + } |
|
4007 | + include($this->default_language_path.'/'.$this->language.'.php'); |
|
4008 | + |
|
4009 | + foreach($lang as $handle => $lang_string) |
|
4010 | + if(!isset($this->lang_strings[$handle])) |
|
4011 | + $this->lang_strings[$handle] = $lang_string; |
|
4012 | + |
|
4013 | + $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); |
|
4014 | + $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; |
|
4015 | + |
|
4016 | + } |
|
4017 | + |
|
4018 | + protected function _load_date_format() |
|
4019 | + { |
|
4020 | + list($php_day, $php_month, $php_year) = array('d','m','Y'); |
|
4021 | + list($js_day, $js_month, $js_year) = array('dd','mm','yy'); |
|
4022 | + list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); |
|
4023 | + |
|
4024 | + $date_format = $this->config->date_format; |
|
4025 | + switch ($date_format) { |
|
4026 | + case 'uk-date': |
|
4027 | + $this->php_date_format = "$php_day/$php_month/$php_year"; |
|
4028 | + $this->js_date_format = "$js_day/$js_month/$js_year"; |
|
4029 | + $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; |
|
4030 | + break; |
|
4031 | + |
|
4032 | + case 'us-date': |
|
4033 | + $this->php_date_format = "$php_month/$php_day/$php_year"; |
|
4034 | + $this->js_date_format = "$js_month/$js_day/$js_year"; |
|
4035 | + $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; |
|
4036 | + break; |
|
4037 | + |
|
4038 | + case 'sql-date': |
|
4039 | + default: |
|
4040 | + $this->php_date_format = "$php_year-$php_month-$php_day"; |
|
4041 | + $this->js_date_format = "$js_year-$js_month-$js_day"; |
|
4042 | + $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; |
|
4043 | + break; |
|
4044 | + } |
|
4045 | + } |
|
4046 | + |
|
4047 | + /** |
|
4048 | + * |
|
4049 | + * Set a language string directly |
|
4050 | + * @param string $handle |
|
4051 | + * @param string $string |
|
4052 | + */ |
|
4053 | + public function set_lang_string($handle, $lang_string){ |
|
4054 | + $this->lang_strings[$handle] = $lang_string; |
|
4055 | + |
|
4056 | + return $this; |
|
4057 | + } |
|
4058 | + |
|
4059 | + /** |
|
4060 | + * |
|
4061 | + * Just an alias to get_lang_string method |
|
4062 | + * @param string $handle |
|
4063 | + */ |
|
4064 | + public function l($handle) |
|
4065 | + { |
|
4066 | + return $this->get_lang_string($handle); |
|
4067 | + } |
|
4068 | + |
|
4069 | + /** |
|
4070 | + * |
|
4071 | + * Get the language string of the inserted string handle |
|
4072 | + * @param string $handle |
|
4073 | + */ |
|
4074 | + public function get_lang_string($handle) |
|
4075 | + { |
|
4076 | + return $this->lang_strings[$handle]; |
|
4077 | + } |
|
4078 | + |
|
4079 | + /** |
|
4080 | + * |
|
4081 | + * Simply set the language |
|
4082 | + * @example english |
|
4083 | + * @param string $language |
|
4084 | + */ |
|
4085 | + public function set_language($language) |
|
4086 | + { |
|
4087 | + $this->language = $language; |
|
4088 | + |
|
4089 | + return $this; |
|
4090 | + } |
|
4091 | + |
|
4092 | + /** |
|
4093 | + * |
|
4094 | + * Enter description here ... |
|
4095 | + */ |
|
4096 | + protected function get_columns() |
|
4097 | + { |
|
4098 | + if($this->columns_checked === false) |
|
4099 | + { |
|
4100 | + $field_types = $this->get_field_types(); |
|
4101 | + if(empty($this->columns)) |
|
4102 | + { |
|
4103 | + $this->columns = array(); |
|
4104 | + foreach($field_types as $field) |
|
4105 | + { |
|
4106 | + if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) |
|
4107 | + $this->columns[] = $field->name; |
|
4108 | + } |
|
4109 | + } |
|
4110 | + |
|
4111 | + foreach($this->columns as $col_num => $column) |
|
4112 | + { |
|
4113 | + |
|
4114 | + if(isset($this->relation[$column])) |
|
4115 | + { |
|
4116 | + |
|
4117 | + $new_column = $this->_unique_field_name($this->relation[$column][0]); |
|
4118 | + $this->columns[$col_num] = $new_column; |
|
4119 | + |
|
4120 | + if(isset($this->display_as[$column])) |
|
3127 | 4121 | { |
3128 | - if (is_array($_POST['search_field'])) { |
|
3129 | - $search_array = array(); |
|
3130 | - foreach ($_POST['search_field'] as $search_key => $search_field_name) { |
|
3131 | - $search_array[$search_field_name] = !empty($_POST['search_text'][$search_key]) ? $_POST['search_text'][$search_key] : ''; |
|
4122 | + $display_as = $this->display_as[$column]; |
|
4123 | + unset($this->display_as[$column]); |
|
4124 | + $this->display_as[$new_column] = $display_as; |
|
4125 | + } |
|
4126 | + else |
|
4127 | + { |
|
4128 | + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
4129 | + } |
|
4130 | + |
|
4131 | + $column = $new_column; |
|
4132 | + $this->columns[$col_num] = $new_column; |
|
4133 | + } |
|
4134 | + else |
|
4135 | + { |
|
4136 | + if(!empty($this->relation)) |
|
4137 | + { |
|
4138 | + $table_name = $this->get_table(); |
|
4139 | + foreach($this->relation as $relation) |
|
4140 | + { |
|
4141 | + if( $relation[2] == $column ) |
|
4142 | + { |
|
4143 | + $new_column = $table_name.'.'.$column; |
|
4144 | + if(isset($this->display_as[$column])) |
|
4145 | + { |
|
4146 | + $display_as = $this->display_as[$column]; |
|
4147 | + unset($this->display_as[$column]); |
|
4148 | + $this->display_as[$new_column] = $display_as; |
|
4149 | + } |
|
4150 | + else |
|
4151 | + { |
|
4152 | + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
4153 | + } |
|
4154 | + |
|
4155 | + $column = $new_column; |
|
4156 | + $this->columns[$col_num] = $new_column; |
|
3132 | 4157 | } |
3133 | - $state_info->search = $search_array; |
|
3134 | - } else { |
|
3135 | - $state_info->search = (object)array( |
|
3136 | - 'field' => strip_tags($_POST['search_field']) , |
|
3137 | - 'text' => $_POST['search_text'] ); |
|
3138 | 4158 | } |
3139 | 4159 | } |
4160 | + |
|
3140 | 4161 | } |
3141 | - break; |
|
3142 | 4162 | |
3143 | - case 9: |
|
4163 | + if(isset($this->display_as[$column])) |
|
4164 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
4165 | + elseif(isset($field_types[$column])) |
|
4166 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
4167 | + else |
|
4168 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
4169 | + ucfirst(str_replace('_',' ',$column))); |
|
3144 | 4170 | |
3145 | - break; |
|
4171 | + if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) |
|
4172 | + { |
|
4173 | + unset($this->columns[$col_num]); |
|
4174 | + } |
|
4175 | + } |
|
3146 | 4176 | |
3147 | - case 10: |
|
3148 | - if($first_parameter !== null) |
|
4177 | + $this->columns_checked = true; |
|
4178 | + |
|
4179 | + } |
|
4180 | + |
|
4181 | + return $this->columns; |
|
4182 | + } |
|
4183 | + |
|
4184 | + /** |
|
4185 | + * |
|
4186 | + * Enter description here ... |
|
4187 | + */ |
|
4188 | + protected function get_add_fields() |
|
4189 | + { |
|
4190 | + if($this->add_fields_checked === false) |
|
4191 | + { |
|
4192 | + $field_types = $this->get_field_types(); |
|
4193 | + if(!empty($this->add_fields)) |
|
4194 | + { |
|
4195 | + foreach($this->add_fields as $field_num => $field) |
|
3149 | 4196 | { |
3150 | - $state_info = (object)array('primary_key' => $first_parameter); |
|
4197 | + if(isset($this->display_as[$field])) |
|
4198 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
4199 | + elseif(isset($field_types[$field]->display_as)) |
|
4200 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
4201 | + else |
|
4202 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
3151 | 4203 | } |
3152 | - break; |
|
4204 | + } |
|
4205 | + else |
|
4206 | + { |
|
4207 | + $this->add_fields = array(); |
|
4208 | + foreach($field_types as $field) |
|
4209 | + { |
|
4210 | + //Check if an unset_add_field is initialize for this field name |
|
4211 | + if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) |
|
4212 | + continue; |
|
3153 | 4213 | |
3154 | - case 11: |
|
3155 | - $state_info->field_name = $first_parameter; |
|
3156 | - break; |
|
4214 | + if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) |
|
4215 | + { |
|
4216 | + if(isset($this->display_as[$field->name])) |
|
4217 | + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
4218 | + else |
|
4219 | + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
4220 | + } |
|
4221 | + } |
|
4222 | + } |
|
3157 | 4223 | |
3158 | - case 12: |
|
3159 | - $state_info->field_name = $first_parameter; |
|
3160 | - $state_info->file_name = $second_parameter; |
|
3161 | - break; |
|
4224 | + $this->add_fields_checked = true; |
|
4225 | + } |
|
4226 | + return $this->add_fields; |
|
4227 | + } |
|
3162 | 4228 | |
3163 | - case 13: |
|
3164 | - $state_info->field_name = $_POST['field_name']; |
|
3165 | - $state_info->search = $_POST['term']; |
|
3166 | - break; |
|
4229 | + /** |
|
4230 | + * |
|
4231 | + * Enter description here ... |
|
4232 | + */ |
|
4233 | + protected function get_edit_fields() |
|
4234 | + { |
|
4235 | + if($this->edit_fields_checked === false) |
|
4236 | + { |
|
4237 | + $field_types = $this->get_field_types(); |
|
4238 | + if(!empty($this->edit_fields)) |
|
4239 | + { |
|
4240 | + foreach($this->edit_fields as $field_num => $field) |
|
4241 | + { |
|
4242 | + if(isset($this->display_as[$field])) |
|
4243 | + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
4244 | + else |
|
4245 | + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
4246 | + } |
|
4247 | + } |
|
4248 | + else |
|
4249 | + { |
|
4250 | + $this->edit_fields = array(); |
|
4251 | + foreach($field_types as $field) |
|
4252 | + { |
|
4253 | + //Check if an unset_edit_field is initialize for this field name |
|
4254 | + if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) |
|
4255 | + continue; |
|
3167 | 4256 | |
3168 | - case 14: |
|
3169 | - $state_info->field_name = $_POST['field_name']; |
|
3170 | - $state_info->search = $_POST['term']; |
|
3171 | - break; |
|
4257 | + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
4258 | + { |
|
4259 | + if(isset($this->display_as[$field->name])) |
|
4260 | + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
4261 | + else |
|
4262 | + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
4263 | + } |
|
4264 | + } |
|
4265 | + } |
|
3172 | 4266 | |
3173 | - case 15: |
|
3174 | - $state_info = (object)array( |
|
3175 | - 'primary_key' => $first_parameter, |
|
3176 | - 'success_message' => true |
|
3177 | - ); |
|
3178 | - break; |
|
4267 | + $this->edit_fields_checked = true; |
|
3179 | 4268 | } |
4269 | + return $this->edit_fields; |
|
4270 | + } |
|
3180 | 4271 | |
3181 | - return $state_info; |
|
4272 | + /** |
|
4273 | + * |
|
4274 | + * Enter description here ... |
|
4275 | + */ |
|
4276 | + protected function get_read_fields() |
|
4277 | + { |
|
4278 | + if($this->read_fields_checked === false) |
|
4279 | + { |
|
4280 | + $field_types = $this->get_field_types(); |
|
4281 | + if(!empty($this->read_fields)) |
|
4282 | + { |
|
4283 | + foreach($this->read_fields as $field_num => $field) |
|
4284 | + { |
|
4285 | + if(isset($this->display_as[$field])) |
|
4286 | + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
4287 | + else |
|
4288 | + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
4289 | + } |
|
4290 | + } |
|
4291 | + else |
|
4292 | + { |
|
4293 | + $this->read_fields = array(); |
|
4294 | + foreach($field_types as $field) |
|
4295 | + { |
|
4296 | + //Check if an unset_read_field is initialize for this field name |
|
4297 | + if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) |
|
4298 | + continue; |
|
4299 | + |
|
4300 | + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
4301 | + { |
|
4302 | + if(isset($this->display_as[$field->name])) |
|
4303 | + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
4304 | + else |
|
4305 | + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
4306 | + } |
|
4307 | + } |
|
4308 | + } |
|
4309 | + |
|
4310 | + $this->read_fields_checked = true; |
|
4311 | + } |
|
4312 | + return $this->read_fields; |
|
3182 | 4313 | } |
3183 | 4314 | |
3184 | - protected function getStateCode() |
|
3185 | - { |
|
3186 | - $state_string = $this->get_state_info_from_url()->operation; |
|
3187 | - |
|
3188 | - if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) |
|
3189 | - $state_code = array_search($state_string, $this->states); |
|
3190 | - else |
|
3191 | - $state_code = 0; |
|
3192 | - |
|
3193 | - return $state_code; |
|
3194 | - } |
|
3195 | - |
|
3196 | - protected function state_url($url = '', $is_list_page = false) |
|
3197 | - { |
|
3198 | - //Easy scenario, we had set the crud_url_path |
|
3199 | - if (!empty($this->crud_url_path)) { |
|
3200 | - $state_url = !empty($this->list_url_path) && $is_list_page? |
|
3201 | - $this->list_url_path : |
|
3202 | - $this->crud_url_path.'/'.$url ; |
|
3203 | - } else { |
|
3204 | - //Complicated scenario. The crud_url_path is not specified so we are |
|
3205 | - //trying to understand what is going on from the URL. |
|
3206 | - $ci = &get_instance(); |
|
3207 | - |
|
3208 | - $segment_object = $this->get_state_info_from_url(); |
|
3209 | - $method_name = $this->get_method_name(); |
|
3210 | - $segment_position = $segment_object->segment_position; |
|
3211 | - |
|
3212 | - $state_url_array = array(); |
|
3213 | - |
|
3214 | - if( sizeof($ci->uri->segments) > 0 ) { |
|
3215 | - foreach($ci->uri->segments as $num => $value) |
|
3216 | - { |
|
3217 | - $state_url_array[$num] = $value; |
|
3218 | - if($num == ($segment_position - 1)) |
|
3219 | - break; |
|
3220 | - } |
|
3221 | - |
|
3222 | - if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url |
|
3223 | - $state_url_array[$num+1] = 'index'; |
|
3224 | - } |
|
3225 | - |
|
3226 | - $state_url = site_url(implode('/',$state_url_array).'/'.$url); |
|
3227 | - } |
|
3228 | - |
|
3229 | - return $state_url; |
|
3230 | - } |
|
3231 | - |
|
3232 | - protected function get_state_info_from_url() |
|
3233 | - { |
|
3234 | - $ci = &get_instance(); |
|
3235 | - |
|
3236 | - $segment_position = count($ci->uri->segments) + 1; |
|
3237 | - $operation = 'list'; |
|
3238 | - |
|
3239 | - $segements = $ci->uri->segments; |
|
3240 | - foreach($segements as $num => $value) |
|
3241 | - { |
|
3242 | - if($value != 'unknown' && in_array($value, $this->states)) |
|
3243 | - { |
|
3244 | - $segment_position = (int)$num; |
|
3245 | - $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. |
|
3246 | - } |
|
3247 | - } |
|
3248 | - |
|
3249 | - $function_name = $this->get_method_name(); |
|
3250 | - |
|
3251 | - if($function_name == 'index' && !in_array('index',$ci->uri->segments)) |
|
3252 | - $segment_position++; |
|
3253 | - |
|
3254 | - $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; |
|
3255 | - $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; |
|
3256 | - |
|
3257 | - return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); |
|
3258 | - } |
|
3259 | - |
|
3260 | - protected function get_method_hash() |
|
3261 | - { |
|
3262 | - $ci = &get_instance(); |
|
3263 | - |
|
3264 | - $state_info = $this->get_state_info_from_url(); |
|
3265 | - $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; |
|
3266 | - |
|
3267 | - return $this->crud_url_path !== null |
|
3268 | - ? md5($this->crud_url_path) |
|
3269 | - : md5($this->get_controller_name().$this->get_method_name().$extra_values); |
|
3270 | - } |
|
3271 | - |
|
3272 | - protected function get_method_name() |
|
3273 | - { |
|
3274 | - $ci = &get_instance(); |
|
3275 | - return $ci->router->method; |
|
3276 | - } |
|
3277 | - |
|
3278 | - protected function get_controller_name() |
|
3279 | - { |
|
3280 | - $ci = &get_instance(); |
|
3281 | - return $ci->router->class; |
|
3282 | - } |
|
3283 | - |
|
3284 | - public function getState() |
|
3285 | - { |
|
3286 | - return $this->states[$this->getStateCode()]; |
|
3287 | - } |
|
3288 | - |
|
3289 | - protected function getListUrl() |
|
3290 | - { |
|
3291 | - return $this->state_url('',true); |
|
3292 | - } |
|
3293 | - |
|
3294 | - protected function getAjaxListUrl() |
|
3295 | - { |
|
3296 | - return $this->state_url('ajax_list'); |
|
3297 | - } |
|
3298 | - |
|
3299 | - protected function getExportToExcelUrl() |
|
3300 | - { |
|
3301 | - return $this->state_url('export'); |
|
3302 | - } |
|
3303 | - |
|
3304 | - protected function getPrintUrl() |
|
3305 | - { |
|
3306 | - return $this->state_url('print'); |
|
3307 | - } |
|
3308 | - |
|
3309 | - protected function getAjaxListInfoUrl() |
|
3310 | - { |
|
3311 | - return $this->state_url('ajax_list_info'); |
|
3312 | - } |
|
3313 | - |
|
3314 | - protected function getAddUrl() |
|
3315 | - { |
|
3316 | - return $this->state_url('add'); |
|
3317 | - } |
|
3318 | - |
|
3319 | - protected function getInsertUrl() |
|
3320 | - { |
|
3321 | - return $this->state_url('insert'); |
|
3322 | - } |
|
3323 | - |
|
3324 | - protected function getValidationInsertUrl() |
|
3325 | - { |
|
3326 | - return $this->state_url('insert_validation'); |
|
3327 | - } |
|
3328 | - |
|
3329 | - protected function getValidationUpdateUrl($primary_key = null) |
|
3330 | - { |
|
3331 | - if($primary_key === null) |
|
3332 | - return $this->state_url('update_validation'); |
|
3333 | - else |
|
3334 | - return $this->state_url('update_validation/'.$primary_key); |
|
3335 | - } |
|
3336 | - |
|
3337 | - protected function getEditUrl($primary_key = null) |
|
3338 | - { |
|
3339 | - if($primary_key === null) |
|
3340 | - return $this->state_url('edit'); |
|
3341 | - else |
|
3342 | - return $this->state_url('edit/'.$primary_key); |
|
3343 | - } |
|
3344 | - |
|
3345 | - protected function getReadUrl($primary_key = null) |
|
3346 | - { |
|
3347 | - if($primary_key === null) |
|
3348 | - return $this->state_url('read'); |
|
3349 | - else |
|
3350 | - return $this->state_url('read/'.$primary_key); |
|
3351 | - } |
|
3352 | - |
|
3353 | - protected function getUpdateUrl($state_info) |
|
3354 | - { |
|
3355 | - return $this->state_url('update/'.$state_info->primary_key); |
|
3356 | - } |
|
3357 | - |
|
3358 | - protected function getDeleteUrl($state_info = null) |
|
3359 | - { |
|
3360 | - if (empty($state_info)) { |
|
3361 | - return $this->state_url('delete'); |
|
3362 | - } else { |
|
3363 | - return $this->state_url('delete/'.$state_info->primary_key); |
|
4315 | + public function order_by($order_by, $direction = 'asc') |
|
4316 | + { |
|
4317 | + $this->order_by = array($order_by,$direction); |
|
4318 | + |
|
4319 | + return $this; |
|
4320 | + } |
|
4321 | + |
|
4322 | + public function where($key, $value = NULL, $escape = TRUE) |
|
4323 | + { |
|
4324 | + $this->where[] = array($key,$value,$escape); |
|
4325 | + |
|
4326 | + return $this; |
|
4327 | + } |
|
4328 | + |
|
4329 | + public function or_where($key, $value = NULL, $escape = TRUE) |
|
4330 | + { |
|
4331 | + $this->or_where[] = array($key,$value,$escape); |
|
4332 | + |
|
4333 | + return $this; |
|
4334 | + } |
|
4335 | + |
|
4336 | + public function like($field, $match = '', $side = 'both') |
|
4337 | + { |
|
4338 | + $this->like[] = array($field, $match, $side); |
|
4339 | + |
|
4340 | + return $this; |
|
4341 | + } |
|
4342 | + |
|
4343 | + protected function having($key, $value = '', $escape = TRUE) |
|
4344 | + { |
|
4345 | + $this->having[] = array($key, $value, $escape); |
|
4346 | + |
|
4347 | + return $this; |
|
4348 | + } |
|
4349 | + |
|
4350 | + protected function or_having($key, $value = '', $escape = TRUE) |
|
4351 | + { |
|
4352 | + $this->or_having[] = array($key, $value, $escape); |
|
4353 | + |
|
4354 | + return $this; |
|
4355 | + } |
|
4356 | + |
|
4357 | + public function or_like($field, $match = '', $side = 'both') |
|
4358 | + { |
|
4359 | + $this->or_like[] = array($field, $match, $side); |
|
4360 | + |
|
4361 | + return $this; |
|
4362 | + } |
|
4363 | + |
|
4364 | + public function limit($limit, $offset = '') |
|
4365 | + { |
|
4366 | + $this->limit = array($limit,$offset); |
|
4367 | + |
|
4368 | + return $this; |
|
4369 | + } |
|
4370 | + |
|
4371 | + protected function _initialize_helpers() |
|
4372 | + { |
|
4373 | + $ci = &get_instance(); |
|
4374 | + |
|
4375 | + $ci->load->helper('url'); |
|
4376 | + $ci->load->helper('form'); |
|
4377 | + } |
|
4378 | + |
|
4379 | + protected function _initialize_variables() |
|
4380 | + { |
|
4381 | + $ci = &get_instance(); |
|
4382 | + $ci->load->config('grocery_crud'); |
|
4383 | + |
|
4384 | + $this->config = (object)array(); |
|
4385 | + |
|
4386 | + /** Initialize all the config variables into this object */ |
|
4387 | + $this->config->default_language = $ci->config->item('grocery_crud_default_language'); |
|
4388 | + $this->config->date_format = $ci->config->item('grocery_crud_date_format'); |
|
4389 | + $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); |
|
4390 | + $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); |
|
4391 | + $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); |
|
4392 | + $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); |
|
4393 | + $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); |
|
4394 | + $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); |
|
4395 | + $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); |
|
4396 | + $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); |
|
4397 | + $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); |
|
4398 | + $this->config->environment = $ci->config->item('grocery_crud_environment'); |
|
4399 | + |
|
4400 | + /** Initialize default paths */ |
|
4401 | + $this->default_javascript_path = $this->default_assets_path.'/js'; |
|
4402 | + $this->default_css_path = $this->default_assets_path.'/css'; |
|
4403 | + $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; |
|
4404 | + $this->default_theme_path = $this->default_assets_path.'/themes'; |
|
4405 | + |
|
4406 | + $this->character_limiter = $this->config->character_limiter; |
|
4407 | + |
|
4408 | + if ($this->character_limiter === 0 || $this->character_limiter === '0') { |
|
4409 | + $this->character_limiter = 1000000; //a very big number |
|
4410 | + } elseif($this->character_limiter === null || $this->character_limiter === false) { |
|
4411 | + $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value |
|
4412 | + } |
|
4413 | + |
|
4414 | + if ($this->theme === null && !empty($this->config->default_theme)) { |
|
4415 | + $this->set_theme($this->config->default_theme); |
|
3364 | 4416 | } |
3365 | - } |
|
4417 | + } |
|
3366 | 4418 | |
3367 | - protected function getDeleteMultipleUrl() |
|
4419 | + protected function _set_primary_keys_to_model() |
|
3368 | 4420 | { |
3369 | - return $this->state_url('delete_multiple'); |
|
4421 | + if(!empty($this->primary_keys)) |
|
4422 | + { |
|
4423 | + foreach($this->primary_keys as $primary_key) |
|
4424 | + { |
|
4425 | + $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); |
|
4426 | + } |
|
4427 | + } |
|
3370 | 4428 | } |
3371 | 4429 | |
3372 | - protected function getListSuccessUrl($primary_key = null) |
|
3373 | - { |
|
3374 | - if(empty($primary_key)) |
|
3375 | - return $this->state_url('success',true); |
|
3376 | - else |
|
3377 | - return $this->state_url('success/'.$primary_key,true); |
|
3378 | - } |
|
3379 | - |
|
3380 | - protected function getUploadUrl($field_name) |
|
3381 | - { |
|
3382 | - return $this->state_url('upload_file/'.$field_name); |
|
3383 | - } |
|
3384 | - |
|
3385 | - protected function getFileDeleteUrl($field_name) |
|
3386 | - { |
|
3387 | - return $this->state_url('delete_file/'.$field_name); |
|
3388 | - } |
|
3389 | - |
|
3390 | - protected function getAjaxRelationUrl() |
|
3391 | - { |
|
3392 | - return $this->state_url('ajax_relation'); |
|
3393 | - } |
|
3394 | - |
|
3395 | - protected function getAjaxRelationManytoManyUrl() |
|
3396 | - { |
|
3397 | - return $this->state_url('ajax_relation_n_n'); |
|
3398 | - } |
|
3399 | -} |
|
3400 | - |
|
4430 | + /** |
|
4431 | + * Initialize all the required libraries and variables before rendering |
|
4432 | + */ |
|
4433 | + protected function pre_render() |
|
4434 | + { |
|
4435 | + $this->_initialize_variables(); |
|
4436 | + $this->_initialize_helpers(); |
|
4437 | + $this->_load_language(); |
|
4438 | + $this->state_code = $this->getStateCode(); |
|
3401 | 4439 | |
3402 | -/** |
|
3403 | - * PHP grocery CRUD |
|
3404 | - * |
|
3405 | - * LICENSE |
|
3406 | - * |
|
3407 | - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
3408 | - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
3409 | - * Please see the corresponding license file for details of these licenses. |
|
3410 | - * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
3411 | - * |
|
3412 | - * @package grocery CRUD |
|
3413 | - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
3414 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
3415 | - * @version 1.5.6 |
|
3416 | - * @author John Skoumbourdis <[email protected]> |
|
3417 | - */ |
|
4440 | + if($this->basic_model === null) |
|
4441 | + $this->set_default_Model(); |
|
3418 | 4442 | |
3419 | -// ------------------------------------------------------------------------ |
|
4443 | + $this->set_basic_db_table($this->get_table()); |
|
3420 | 4444 | |
3421 | -/** |
|
3422 | - * PHP grocery CRUD |
|
3423 | - * |
|
3424 | - * Creates a full functional CRUD with few lines of code. |
|
3425 | - * |
|
3426 | - * @package grocery CRUD |
|
3427 | - * @author John Skoumbourdis <[email protected]> |
|
3428 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
3429 | - * @link http://www.grocerycrud.com/documentation |
|
3430 | - */ |
|
3431 | -class Grocery_CRUD extends grocery_CRUD_States |
|
3432 | -{ |
|
3433 | - /** |
|
3434 | - * Grocery CRUD version |
|
3435 | - * |
|
3436 | - * @var string |
|
3437 | - */ |
|
3438 | - const VERSION = "1.5.6"; |
|
3439 | - |
|
3440 | - const JQUERY = "jquery-1.11.1.min.js"; |
|
3441 | - const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; |
|
3442 | - const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; |
|
3443 | - |
|
3444 | - protected $state_code = null; |
|
3445 | - protected $state_info = null; |
|
3446 | - protected $columns = null; |
|
3447 | - |
|
3448 | - private $basic_db_table_checked = false; |
|
3449 | - private $columns_checked = false; |
|
3450 | - private $add_fields_checked = false; |
|
3451 | - private $edit_fields_checked = false; |
|
3452 | - private $read_fields_checked = false; |
|
3453 | - |
|
3454 | - protected $default_theme = 'flexigrid'; |
|
3455 | - protected $language = null; |
|
3456 | - protected $lang_strings = array(); |
|
3457 | - protected $php_date_format = null; |
|
3458 | - protected $js_date_format = null; |
|
3459 | - protected $ui_date_format = null; |
|
3460 | - protected $character_limiter = null; |
|
3461 | - protected $config = null; |
|
3462 | - |
|
3463 | - protected $add_fields = null; |
|
3464 | - protected $edit_fields = null; |
|
3465 | - protected $read_fields = null; |
|
3466 | - protected $add_hidden_fields = array(); |
|
3467 | - protected $edit_hidden_fields = array(); |
|
3468 | - protected $field_types = null; |
|
3469 | - protected $basic_db_table = null; |
|
3470 | - protected $theme_config = array(); |
|
3471 | - protected $subject = null; |
|
3472 | - protected $subject_plural = null; |
|
3473 | - protected $display_as = array(); |
|
3474 | - protected $order_by = null; |
|
3475 | - protected $where = array(); |
|
3476 | - protected $like = array(); |
|
3477 | - protected $having = array(); |
|
3478 | - protected $or_having = array(); |
|
3479 | - protected $limit = null; |
|
3480 | - protected $required_fields = array(); |
|
3481 | - protected $_unique_fields = array(); |
|
3482 | - protected $validation_rules = array(); |
|
3483 | - protected $relation = array(); |
|
3484 | - protected $relation_n_n = array(); |
|
3485 | - protected $upload_fields = array(); |
|
3486 | - protected $actions = array(); |
|
3487 | - |
|
3488 | - protected $form_validation = null; |
|
3489 | - protected $change_field_type = null; |
|
3490 | - protected $primary_keys = array(); |
|
3491 | - protected $crud_url_path = null; |
|
3492 | - protected $list_url_path = null; |
|
3493 | - |
|
3494 | - /* The unsetters */ |
|
3495 | - protected $unset_texteditor = array(); |
|
3496 | - protected $unset_add = false; |
|
3497 | - protected $unset_edit = false; |
|
3498 | - protected $unset_delete = false; |
|
3499 | - protected $unset_read = false; |
|
3500 | - protected $unset_jquery = false; |
|
3501 | - protected $unset_jquery_ui = false; |
|
3502 | - protected $unset_bootstrap = false; |
|
3503 | - protected $unset_list = false; |
|
3504 | - protected $unset_export = false; |
|
3505 | - protected $unset_print = false; |
|
3506 | - protected $unset_back_to_list = false; |
|
3507 | - protected $unset_columns = null; |
|
3508 | - protected $unset_add_fields = null; |
|
3509 | - protected $unset_edit_fields = null; |
|
3510 | - protected $unset_read_fields = null; |
|
3511 | - |
|
3512 | - /* Callbacks */ |
|
3513 | - protected $callback_before_insert = null; |
|
3514 | - protected $callback_after_insert = null; |
|
3515 | - protected $callback_insert = null; |
|
3516 | - protected $callback_before_update = null; |
|
3517 | - protected $callback_after_update = null; |
|
3518 | - protected $callback_update = null; |
|
3519 | - protected $callback_before_delete = null; |
|
3520 | - protected $callback_after_delete = null; |
|
3521 | - protected $callback_delete = null; |
|
3522 | - protected $callback_column = array(); |
|
3523 | - protected $callback_add_field = array(); |
|
3524 | - protected $callback_edit_field = array(); |
|
3525 | - protected $callback_upload = null; |
|
3526 | - protected $callback_before_upload = null; |
|
3527 | - protected $callback_after_upload = null; |
|
3528 | - |
|
3529 | - protected $default_javascript_path = null; //autogenerate, please do not modify |
|
3530 | - protected $default_css_path = null; //autogenerate, please do not modify |
|
3531 | - protected $default_texteditor_path = null; //autogenerate, please do not modify |
|
3532 | - protected $default_theme_path = null; //autogenerate, please do not modify |
|
3533 | - protected $default_language_path = 'assets/grocery_crud/languages'; |
|
3534 | - protected $default_config_path = 'assets/grocery_crud/config'; |
|
3535 | - protected $default_assets_path = 'assets/grocery_crud'; |
|
3536 | - |
|
3537 | - /** |
|
3538 | - * |
|
3539 | - * Constructor |
|
3540 | - * |
|
3541 | - * @access public |
|
3542 | - */ |
|
3543 | - public function __construct() |
|
3544 | - { |
|
3545 | - |
|
3546 | - } |
|
3547 | - |
|
3548 | - /** |
|
3549 | - * The displayed columns that user see |
|
3550 | - * |
|
3551 | - * @access public |
|
3552 | - * @param string |
|
3553 | - * @param array |
|
3554 | - * @return void |
|
3555 | - */ |
|
3556 | - public function columns() |
|
3557 | - { |
|
3558 | - $args = func_get_args(); |
|
3559 | - |
|
3560 | - if(isset($args[0]) && is_array($args[0])) |
|
3561 | - { |
|
3562 | - $args = $args[0]; |
|
3563 | - } |
|
3564 | - |
|
3565 | - $this->columns = $args; |
|
3566 | - |
|
3567 | - return $this; |
|
3568 | - } |
|
3569 | - |
|
3570 | - |
|
3571 | - /** |
|
3572 | - * Set Validation Rules |
|
3573 | - * |
|
3574 | - * Important note: If the $field is an array then no automated crud fields will take apart |
|
3575 | - * |
|
3576 | - * @access public |
|
3577 | - * @param mixed |
|
3578 | - * @param string |
|
3579 | - * @return void |
|
3580 | - */ |
|
3581 | - function set_rules($field, $label = '', $rules = '') |
|
3582 | - { |
|
3583 | - if(is_string($field)) |
|
3584 | - { |
|
3585 | - $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); |
|
3586 | - }elseif(is_array($field)) |
|
3587 | - { |
|
3588 | - foreach($field as $num_field => $field_array) |
|
3589 | - { |
|
3590 | - $this->validation_rules[$field_array['field']] = $field_array; |
|
3591 | - } |
|
3592 | - } |
|
3593 | - return $this; |
|
3594 | - } |
|
3595 | - |
|
3596 | - /** |
|
3597 | - * |
|
3598 | - * Changes the default field type |
|
3599 | - * @param string $field |
|
3600 | - * @param string $type |
|
3601 | - * @param array|string $extras |
|
3602 | - */ |
|
3603 | - public function change_field_type($field , $type, $extras = null) |
|
3604 | - { |
|
3605 | - $field_type = (object)array('type' => $type); |
|
3606 | - |
|
3607 | - $field_type->extras = $extras; |
|
3608 | - |
|
3609 | - $this->change_field_type[$field] = $field_type; |
|
3610 | - |
|
3611 | - return $this; |
|
3612 | - } |
|
3613 | - |
|
3614 | - /** |
|
3615 | - * |
|
3616 | - * Just an alias to the change_field_type method |
|
3617 | - * @param string $field |
|
3618 | - * @param string $type |
|
3619 | - * @param array|string $extras |
|
3620 | - */ |
|
3621 | - public function field_type($field , $type, $extras = null) |
|
3622 | - { |
|
3623 | - return $this->change_field_type($field , $type, $extras); |
|
3624 | - } |
|
3625 | - |
|
3626 | - /** |
|
3627 | - * Change the default primary key for a specific table. |
|
3628 | - * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method |
|
3629 | - * |
|
3630 | - * @param string $primary_key_field |
|
3631 | - * @param string $table_name |
|
3632 | - */ |
|
3633 | - public function set_primary_key($primary_key_field, $table_name = null) |
|
3634 | - { |
|
3635 | - $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); |
|
3636 | - |
|
3637 | - return $this; |
|
3638 | - } |
|
3639 | - |
|
3640 | - /** |
|
3641 | - * Unsets the texteditor of the selected fields |
|
3642 | - * |
|
3643 | - * @access public |
|
3644 | - * @param string |
|
3645 | - * @param array |
|
3646 | - * @return void |
|
3647 | - */ |
|
3648 | - public function unset_texteditor() |
|
3649 | - { |
|
3650 | - $args = func_get_args(); |
|
3651 | - |
|
3652 | - if(isset($args[0]) && is_array($args[0])) |
|
3653 | - { |
|
3654 | - $args = $args[0]; |
|
3655 | - } |
|
3656 | - foreach($args as $arg) |
|
3657 | - { |
|
3658 | - $this->unset_texteditor[] = $arg; |
|
3659 | - } |
|
3660 | - |
|
3661 | - return $this; |
|
3662 | - } |
|
3663 | - |
|
3664 | - /** |
|
3665 | - * Unsets just the jquery library from the js. This function can be used if there is already a jquery included |
|
3666 | - * in the main template. This will avoid all jquery conflicts. |
|
3667 | - * |
|
3668 | - * @return void |
|
3669 | - */ |
|
3670 | - public function unset_jquery() |
|
3671 | - { |
|
3672 | - $this->unset_jquery = true; |
|
3673 | - |
|
3674 | - return $this; |
|
3675 | - } |
|
3676 | - |
|
3677 | - /** |
|
3678 | - * Unsets the jquery UI Javascript and CSS. This function is really useful |
|
3679 | - * when the jquery UI JavaScript and CSS are already included in the main template. |
|
3680 | - * This will avoid all jquery UI conflicts. |
|
3681 | - * |
|
3682 | - * @return void |
|
3683 | - */ |
|
3684 | - public function unset_jquery_ui() |
|
3685 | - { |
|
3686 | - $this->unset_jquery_ui = true; |
|
3687 | - |
|
3688 | - return $this; |
|
3689 | - } |
|
3690 | - |
|
3691 | - /** |
|
3692 | - * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included |
|
3693 | - * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. |
|
3694 | - * |
|
3695 | - * @return void |
|
3696 | - */ |
|
3697 | - public function unset_bootstrap() |
|
3698 | - { |
|
3699 | - $this->unset_bootstrap = true; |
|
3700 | - |
|
3701 | - return $this; |
|
3702 | - } |
|
3703 | - |
|
3704 | - /** |
|
3705 | - * Unsets the add operation from the list |
|
3706 | - * |
|
3707 | - * @return void |
|
3708 | - */ |
|
3709 | - public function unset_add() |
|
3710 | - { |
|
3711 | - $this->unset_add = true; |
|
3712 | - |
|
3713 | - return $this; |
|
3714 | - } |
|
3715 | - |
|
3716 | - /** |
|
3717 | - * Unsets the edit operation from the list |
|
3718 | - * |
|
3719 | - * @return void |
|
3720 | - */ |
|
3721 | - public function unset_edit() |
|
3722 | - { |
|
3723 | - $this->unset_edit = true; |
|
3724 | - |
|
3725 | - return $this; |
|
3726 | - } |
|
3727 | - |
|
3728 | - /** |
|
3729 | - * Unsets the delete operation from the list |
|
3730 | - * |
|
3731 | - * @return void |
|
3732 | - */ |
|
3733 | - public function unset_delete() |
|
3734 | - { |
|
3735 | - $this->unset_delete = true; |
|
3736 | - |
|
3737 | - return $this; |
|
3738 | - } |
|
3739 | - |
|
3740 | - /** |
|
3741 | - * Unsets the read operation from the list |
|
3742 | - * |
|
3743 | - * @return void |
|
3744 | - */ |
|
3745 | - public function unset_read() |
|
3746 | - { |
|
3747 | - $this->unset_read = true; |
|
3748 | - |
|
3749 | - return $this; |
|
3750 | - } |
|
3751 | - |
|
3752 | - /** |
|
3753 | - * Just an alias to unset_read |
|
3754 | - * |
|
3755 | - * @return void |
|
3756 | - * */ |
|
3757 | - public function unset_view() |
|
3758 | - { |
|
3759 | - return unset_read(); |
|
3760 | - } |
|
3761 | - |
|
3762 | - /** |
|
3763 | - * Unsets the export button and functionality from the list |
|
3764 | - * |
|
3765 | - * @return void |
|
3766 | - */ |
|
3767 | - public function unset_export() |
|
3768 | - { |
|
3769 | - $this->unset_export = true; |
|
3770 | - |
|
3771 | - return $this; |
|
3772 | - } |
|
3773 | - |
|
3774 | - |
|
3775 | - /** |
|
3776 | - * Unsets the print button and functionality from the list |
|
3777 | - * |
|
3778 | - * @return void |
|
3779 | - */ |
|
3780 | - public function unset_print() |
|
3781 | - { |
|
3782 | - $this->unset_print = true; |
|
3783 | - |
|
3784 | - return $this; |
|
3785 | - } |
|
3786 | - |
|
3787 | - /** |
|
3788 | - * Unsets all the operations from the list |
|
3789 | - * |
|
3790 | - * @return void |
|
3791 | - */ |
|
3792 | - public function unset_operations() |
|
3793 | - { |
|
3794 | - $this->unset_add = true; |
|
3795 | - $this->unset_edit = true; |
|
3796 | - $this->unset_delete = true; |
|
3797 | - $this->unset_read = true; |
|
3798 | - $this->unset_export = true; |
|
3799 | - $this->unset_print = true; |
|
3800 | - |
|
3801 | - return $this; |
|
3802 | - } |
|
3803 | - |
|
3804 | - /** |
|
3805 | - * Unsets a column from the list |
|
3806 | - * |
|
3807 | - * @return void. |
|
3808 | - */ |
|
3809 | - public function unset_columns() |
|
3810 | - { |
|
3811 | - $args = func_get_args(); |
|
3812 | - |
|
3813 | - if(isset($args[0]) && is_array($args[0])) |
|
3814 | - { |
|
3815 | - $args = $args[0]; |
|
3816 | - } |
|
3817 | - |
|
3818 | - $this->unset_columns = $args; |
|
3819 | - |
|
3820 | - return $this; |
|
3821 | - } |
|
3822 | - |
|
3823 | - public function unset_list() |
|
3824 | - { |
|
3825 | - $this->unset_list = true; |
|
3826 | - |
|
3827 | - return $this; |
|
3828 | - } |
|
3829 | - |
|
3830 | - public function unset_fields() |
|
3831 | - { |
|
3832 | - $args = func_get_args(); |
|
3833 | - |
|
3834 | - if(isset($args[0]) && is_array($args[0])) |
|
3835 | - { |
|
3836 | - $args = $args[0]; |
|
3837 | - } |
|
3838 | - |
|
3839 | - $this->unset_add_fields = $args; |
|
3840 | - $this->unset_edit_fields = $args; |
|
3841 | - $this->unset_read_fields = $args; |
|
3842 | - |
|
3843 | - return $this; |
|
3844 | - } |
|
3845 | - |
|
3846 | - public function unset_add_fields() |
|
3847 | - { |
|
3848 | - $args = func_get_args(); |
|
3849 | - |
|
3850 | - if(isset($args[0]) && is_array($args[0])) |
|
3851 | - { |
|
3852 | - $args = $args[0]; |
|
3853 | - } |
|
3854 | - |
|
3855 | - $this->unset_add_fields = $args; |
|
3856 | - |
|
3857 | - return $this; |
|
3858 | - } |
|
3859 | - |
|
3860 | - public function unset_edit_fields() |
|
3861 | - { |
|
3862 | - $args = func_get_args(); |
|
3863 | - |
|
3864 | - if(isset($args[0]) && is_array($args[0])) |
|
3865 | - { |
|
3866 | - $args = $args[0]; |
|
3867 | - } |
|
3868 | - |
|
3869 | - $this->unset_edit_fields = $args; |
|
3870 | - |
|
3871 | - return $this; |
|
3872 | - } |
|
3873 | - |
|
3874 | - public function unset_read_fields() |
|
3875 | - { |
|
3876 | - $args = func_get_args(); |
|
3877 | - |
|
3878 | - if(isset($args[0]) && is_array($args[0])) |
|
3879 | - { |
|
3880 | - $args = $args[0]; |
|
3881 | - } |
|
3882 | - |
|
3883 | - $this->unset_read_fields = $args; |
|
3884 | - |
|
3885 | - return $this; |
|
3886 | - } |
|
3887 | - |
|
3888 | - |
|
3889 | - /** |
|
3890 | - * Unsets everything that has to do with buttons or links with go back to list message |
|
3891 | - * @access public |
|
3892 | - * @return void |
|
3893 | - */ |
|
3894 | - public function unset_back_to_list() |
|
3895 | - { |
|
3896 | - $this->unset_back_to_list = true; |
|
3897 | - |
|
3898 | - return $this; |
|
3899 | - } |
|
3900 | - |
|
3901 | - /** |
|
3902 | - * |
|
3903 | - * The fields that user will see on add/edit |
|
3904 | - * |
|
3905 | - * @access public |
|
3906 | - * @param string |
|
3907 | - * @param array |
|
3908 | - * @return void |
|
3909 | - */ |
|
3910 | - public function fields() |
|
3911 | - { |
|
3912 | - $args = func_get_args(); |
|
3913 | - |
|
3914 | - if(isset($args[0]) && is_array($args[0])) |
|
3915 | - { |
|
3916 | - $args = $args[0]; |
|
3917 | - } |
|
3918 | - |
|
3919 | - $this->add_fields = $args; |
|
3920 | - $this->edit_fields = $args; |
|
3921 | - |
|
3922 | - return $this; |
|
3923 | - } |
|
3924 | - |
|
3925 | - /** |
|
3926 | - * |
|
3927 | - * The fields that user can see . It is only for the add form |
|
3928 | - */ |
|
3929 | - public function add_fields() |
|
3930 | - { |
|
3931 | - $args = func_get_args(); |
|
3932 | - |
|
3933 | - if(isset($args[0]) && is_array($args[0])) |
|
3934 | - { |
|
3935 | - $args = $args[0]; |
|
3936 | - } |
|
3937 | - |
|
3938 | - $this->add_fields = $args; |
|
3939 | - |
|
3940 | - return $this; |
|
3941 | - } |
|
3942 | - |
|
3943 | - /** |
|
3944 | - * |
|
3945 | - * The fields that user can see . It is only for the edit form |
|
3946 | - */ |
|
3947 | - public function edit_fields() |
|
3948 | - { |
|
3949 | - $args = func_get_args(); |
|
3950 | - |
|
3951 | - if(isset($args[0]) && is_array($args[0])) |
|
3952 | - { |
|
3953 | - $args = $args[0]; |
|
3954 | - } |
|
3955 | - |
|
3956 | - $this->edit_fields = $args; |
|
3957 | - |
|
3958 | - return $this; |
|
3959 | - } |
|
3960 | - |
|
3961 | - public function set_read_fields() |
|
3962 | - { |
|
3963 | - $args = func_get_args(); |
|
3964 | - |
|
3965 | - if(isset($args[0]) && is_array($args[0])) { |
|
3966 | - $args = $args[0]; |
|
3967 | - } |
|
3968 | - |
|
3969 | - $this->read_fields = $args; |
|
3970 | - |
|
3971 | - return $this; |
|
3972 | - } |
|
3973 | - |
|
3974 | - /** |
|
3975 | - * |
|
3976 | - * Changes the displaying label of the field |
|
3977 | - * @param $field_name |
|
3978 | - * @param $display_as |
|
3979 | - * @return void |
|
3980 | - */ |
|
3981 | - public function display_as($field_name, $display_as = null) |
|
3982 | - { |
|
3983 | - if(is_array($field_name)) |
|
3984 | - { |
|
3985 | - foreach($field_name as $field => $display_as) |
|
3986 | - { |
|
3987 | - $this->display_as[$field] = $display_as; |
|
3988 | - } |
|
3989 | - } |
|
3990 | - elseif($display_as !== null) |
|
3991 | - { |
|
3992 | - $this->display_as[$field_name] = $display_as; |
|
3993 | - } |
|
3994 | - return $this; |
|
3995 | - } |
|
3996 | - |
|
3997 | - /** |
|
3998 | - * |
|
3999 | - * Load the language strings array from the language file |
|
4000 | - */ |
|
4001 | - protected function _load_language() |
|
4002 | - { |
|
4003 | - if($this->language === null) |
|
4004 | - { |
|
4005 | - $this->language = strtolower($this->config->default_language); |
|
4006 | - } |
|
4007 | - include($this->default_language_path.'/'.$this->language.'.php'); |
|
4008 | - |
|
4009 | - foreach($lang as $handle => $lang_string) |
|
4010 | - if(!isset($this->lang_strings[$handle])) |
|
4011 | - $this->lang_strings[$handle] = $lang_string; |
|
4012 | - |
|
4013 | - $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); |
|
4014 | - $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; |
|
4015 | - |
|
4016 | - } |
|
4017 | - |
|
4018 | - protected function _load_date_format() |
|
4019 | - { |
|
4020 | - list($php_day, $php_month, $php_year) = array('d','m','Y'); |
|
4021 | - list($js_day, $js_month, $js_year) = array('dd','mm','yy'); |
|
4022 | - list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); |
|
4023 | - |
|
4024 | - $date_format = $this->config->date_format; |
|
4025 | - switch ($date_format) { |
|
4026 | - case 'uk-date': |
|
4027 | - $this->php_date_format = "$php_day/$php_month/$php_year"; |
|
4028 | - $this->js_date_format = "$js_day/$js_month/$js_year"; |
|
4029 | - $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; |
|
4030 | - break; |
|
4445 | + $this->_load_date_format(); |
|
4031 | 4446 | |
4032 | - case 'us-date': |
|
4033 | - $this->php_date_format = "$php_month/$php_day/$php_year"; |
|
4034 | - $this->js_date_format = "$js_month/$js_day/$js_year"; |
|
4035 | - $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; |
|
4036 | - break; |
|
4447 | + $this->_set_primary_keys_to_model(); |
|
4448 | + } |
|
4037 | 4449 | |
4038 | - case 'sql-date': |
|
4039 | - default: |
|
4040 | - $this->php_date_format = "$php_year-$php_month-$php_day"; |
|
4041 | - $this->js_date_format = "$js_year-$js_month-$js_day"; |
|
4042 | - $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; |
|
4043 | - break; |
|
4044 | - } |
|
4045 | - } |
|
4046 | - |
|
4047 | - /** |
|
4048 | - * |
|
4049 | - * Set a language string directly |
|
4050 | - * @param string $handle |
|
4051 | - * @param string $string |
|
4052 | - */ |
|
4053 | - public function set_lang_string($handle, $lang_string){ |
|
4054 | - $this->lang_strings[$handle] = $lang_string; |
|
4055 | - |
|
4056 | - return $this; |
|
4057 | - } |
|
4058 | - |
|
4059 | - /** |
|
4060 | - * |
|
4061 | - * Just an alias to get_lang_string method |
|
4062 | - * @param string $handle |
|
4063 | - */ |
|
4064 | - public function l($handle) |
|
4065 | - { |
|
4066 | - return $this->get_lang_string($handle); |
|
4067 | - } |
|
4068 | - |
|
4069 | - /** |
|
4070 | - * |
|
4071 | - * Get the language string of the inserted string handle |
|
4072 | - * @param string $handle |
|
4073 | - */ |
|
4074 | - public function get_lang_string($handle) |
|
4075 | - { |
|
4076 | - return $this->lang_strings[$handle]; |
|
4077 | - } |
|
4078 | - |
|
4079 | - /** |
|
4080 | - * |
|
4081 | - * Simply set the language |
|
4082 | - * @example english |
|
4083 | - * @param string $language |
|
4084 | - */ |
|
4085 | - public function set_language($language) |
|
4086 | - { |
|
4087 | - $this->language = $language; |
|
4088 | - |
|
4089 | - return $this; |
|
4090 | - } |
|
4091 | - |
|
4092 | - /** |
|
4093 | - * |
|
4094 | - * Enter description here ... |
|
4095 | - */ |
|
4096 | - protected function get_columns() |
|
4097 | - { |
|
4098 | - if($this->columns_checked === false) |
|
4099 | - { |
|
4100 | - $field_types = $this->get_field_types(); |
|
4101 | - if(empty($this->columns)) |
|
4102 | - { |
|
4103 | - $this->columns = array(); |
|
4104 | - foreach($field_types as $field) |
|
4105 | - { |
|
4106 | - if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) |
|
4107 | - $this->columns[] = $field->name; |
|
4108 | - } |
|
4109 | - } |
|
4110 | - |
|
4111 | - foreach($this->columns as $col_num => $column) |
|
4112 | - { |
|
4113 | - |
|
4114 | - if(isset($this->relation[$column])) |
|
4115 | - { |
|
4116 | - |
|
4117 | - $new_column = $this->_unique_field_name($this->relation[$column][0]); |
|
4118 | - $this->columns[$col_num] = $new_column; |
|
4119 | - |
|
4120 | - if(isset($this->display_as[$column])) |
|
4121 | - { |
|
4122 | - $display_as = $this->display_as[$column]; |
|
4123 | - unset($this->display_as[$column]); |
|
4124 | - $this->display_as[$new_column] = $display_as; |
|
4125 | - } |
|
4126 | - else |
|
4127 | - { |
|
4128 | - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
4129 | - } |
|
4130 | - |
|
4131 | - $column = $new_column; |
|
4132 | - $this->columns[$col_num] = $new_column; |
|
4133 | - } |
|
4134 | - else |
|
4135 | - { |
|
4136 | - if(!empty($this->relation)) |
|
4137 | - { |
|
4138 | - $table_name = $this->get_table(); |
|
4139 | - foreach($this->relation as $relation) |
|
4140 | - { |
|
4141 | - if( $relation[2] == $column ) |
|
4142 | - { |
|
4143 | - $new_column = $table_name.'.'.$column; |
|
4144 | - if(isset($this->display_as[$column])) |
|
4145 | - { |
|
4146 | - $display_as = $this->display_as[$column]; |
|
4147 | - unset($this->display_as[$column]); |
|
4148 | - $this->display_as[$new_column] = $display_as; |
|
4149 | - } |
|
4150 | - else |
|
4151 | - { |
|
4152 | - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
4153 | - } |
|
4154 | - |
|
4155 | - $column = $new_column; |
|
4156 | - $this->columns[$col_num] = $new_column; |
|
4157 | - } |
|
4158 | - } |
|
4159 | - } |
|
4160 | - |
|
4161 | - } |
|
4162 | - |
|
4163 | - if(isset($this->display_as[$column])) |
|
4164 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
4165 | - elseif(isset($field_types[$column])) |
|
4166 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
4167 | - else |
|
4168 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
4169 | - ucfirst(str_replace('_',' ',$column))); |
|
4170 | - |
|
4171 | - if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) |
|
4172 | - { |
|
4173 | - unset($this->columns[$col_num]); |
|
4174 | - } |
|
4175 | - } |
|
4176 | - |
|
4177 | - $this->columns_checked = true; |
|
4178 | - |
|
4179 | - } |
|
4180 | - |
|
4181 | - return $this->columns; |
|
4182 | - } |
|
4183 | - |
|
4184 | - /** |
|
4185 | - * |
|
4186 | - * Enter description here ... |
|
4187 | - */ |
|
4188 | - protected function get_add_fields() |
|
4189 | - { |
|
4190 | - if($this->add_fields_checked === false) |
|
4191 | - { |
|
4192 | - $field_types = $this->get_field_types(); |
|
4193 | - if(!empty($this->add_fields)) |
|
4194 | - { |
|
4195 | - foreach($this->add_fields as $field_num => $field) |
|
4196 | - { |
|
4197 | - if(isset($this->display_as[$field])) |
|
4198 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
4199 | - elseif(isset($field_types[$field]->display_as)) |
|
4200 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
4201 | - else |
|
4202 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
4203 | - } |
|
4204 | - } |
|
4205 | - else |
|
4206 | - { |
|
4207 | - $this->add_fields = array(); |
|
4208 | - foreach($field_types as $field) |
|
4209 | - { |
|
4210 | - //Check if an unset_add_field is initialize for this field name |
|
4211 | - if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) |
|
4212 | - continue; |
|
4213 | - |
|
4214 | - if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) |
|
4215 | - { |
|
4216 | - if(isset($this->display_as[$field->name])) |
|
4217 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
4218 | - else |
|
4219 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
4220 | - } |
|
4221 | - } |
|
4222 | - } |
|
4223 | - |
|
4224 | - $this->add_fields_checked = true; |
|
4225 | - } |
|
4226 | - return $this->add_fields; |
|
4227 | - } |
|
4228 | - |
|
4229 | - /** |
|
4230 | - * |
|
4231 | - * Enter description here ... |
|
4232 | - */ |
|
4233 | - protected function get_edit_fields() |
|
4234 | - { |
|
4235 | - if($this->edit_fields_checked === false) |
|
4236 | - { |
|
4237 | - $field_types = $this->get_field_types(); |
|
4238 | - if(!empty($this->edit_fields)) |
|
4239 | - { |
|
4240 | - foreach($this->edit_fields as $field_num => $field) |
|
4241 | - { |
|
4242 | - if(isset($this->display_as[$field])) |
|
4243 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
4244 | - else |
|
4245 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
4246 | - } |
|
4247 | - } |
|
4248 | - else |
|
4249 | - { |
|
4250 | - $this->edit_fields = array(); |
|
4251 | - foreach($field_types as $field) |
|
4252 | - { |
|
4253 | - //Check if an unset_edit_field is initialize for this field name |
|
4254 | - if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) |
|
4255 | - continue; |
|
4256 | - |
|
4257 | - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
4258 | - { |
|
4259 | - if(isset($this->display_as[$field->name])) |
|
4260 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
4261 | - else |
|
4262 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
4263 | - } |
|
4264 | - } |
|
4265 | - } |
|
4266 | - |
|
4267 | - $this->edit_fields_checked = true; |
|
4268 | - } |
|
4269 | - return $this->edit_fields; |
|
4270 | - } |
|
4271 | - |
|
4272 | - /** |
|
4273 | - * |
|
4274 | - * Enter description here ... |
|
4275 | - */ |
|
4276 | - protected function get_read_fields() |
|
4277 | - { |
|
4278 | - if($this->read_fields_checked === false) |
|
4279 | - { |
|
4280 | - $field_types = $this->get_field_types(); |
|
4281 | - if(!empty($this->read_fields)) |
|
4282 | - { |
|
4283 | - foreach($this->read_fields as $field_num => $field) |
|
4284 | - { |
|
4285 | - if(isset($this->display_as[$field])) |
|
4286 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
4287 | - else |
|
4288 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
4289 | - } |
|
4290 | - } |
|
4291 | - else |
|
4292 | - { |
|
4293 | - $this->read_fields = array(); |
|
4294 | - foreach($field_types as $field) |
|
4295 | - { |
|
4296 | - //Check if an unset_read_field is initialize for this field name |
|
4297 | - if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) |
|
4298 | - continue; |
|
4299 | - |
|
4300 | - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
4301 | - { |
|
4302 | - if(isset($this->display_as[$field->name])) |
|
4303 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
4304 | - else |
|
4305 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
4306 | - } |
|
4307 | - } |
|
4308 | - } |
|
4309 | - |
|
4310 | - $this->read_fields_checked = true; |
|
4311 | - } |
|
4312 | - return $this->read_fields; |
|
4313 | - } |
|
4314 | - |
|
4315 | - public function order_by($order_by, $direction = 'asc') |
|
4316 | - { |
|
4317 | - $this->order_by = array($order_by,$direction); |
|
4318 | - |
|
4319 | - return $this; |
|
4320 | - } |
|
4321 | - |
|
4322 | - public function where($key, $value = NULL, $escape = TRUE) |
|
4323 | - { |
|
4324 | - $this->where[] = array($key,$value,$escape); |
|
4325 | - |
|
4326 | - return $this; |
|
4327 | - } |
|
4328 | - |
|
4329 | - public function or_where($key, $value = NULL, $escape = TRUE) |
|
4330 | - { |
|
4331 | - $this->or_where[] = array($key,$value,$escape); |
|
4332 | - |
|
4333 | - return $this; |
|
4334 | - } |
|
4335 | - |
|
4336 | - public function like($field, $match = '', $side = 'both') |
|
4337 | - { |
|
4338 | - $this->like[] = array($field, $match, $side); |
|
4339 | - |
|
4340 | - return $this; |
|
4341 | - } |
|
4342 | - |
|
4343 | - protected function having($key, $value = '', $escape = TRUE) |
|
4344 | - { |
|
4345 | - $this->having[] = array($key, $value, $escape); |
|
4346 | - |
|
4347 | - return $this; |
|
4348 | - } |
|
4349 | - |
|
4350 | - protected function or_having($key, $value = '', $escape = TRUE) |
|
4351 | - { |
|
4352 | - $this->or_having[] = array($key, $value, $escape); |
|
4353 | - |
|
4354 | - return $this; |
|
4355 | - } |
|
4356 | - |
|
4357 | - public function or_like($field, $match = '', $side = 'both') |
|
4358 | - { |
|
4359 | - $this->or_like[] = array($field, $match, $side); |
|
4360 | - |
|
4361 | - return $this; |
|
4362 | - } |
|
4363 | - |
|
4364 | - public function limit($limit, $offset = '') |
|
4365 | - { |
|
4366 | - $this->limit = array($limit,$offset); |
|
4367 | - |
|
4368 | - return $this; |
|
4369 | - } |
|
4370 | - |
|
4371 | - protected function _initialize_helpers() |
|
4372 | - { |
|
4373 | - $ci = &get_instance(); |
|
4374 | - |
|
4375 | - $ci->load->helper('url'); |
|
4376 | - $ci->load->helper('form'); |
|
4377 | - } |
|
4378 | - |
|
4379 | - protected function _initialize_variables() |
|
4380 | - { |
|
4381 | - $ci = &get_instance(); |
|
4382 | - $ci->load->config('grocery_crud'); |
|
4383 | - |
|
4384 | - $this->config = (object)array(); |
|
4385 | - |
|
4386 | - /** Initialize all the config variables into this object */ |
|
4387 | - $this->config->default_language = $ci->config->item('grocery_crud_default_language'); |
|
4388 | - $this->config->date_format = $ci->config->item('grocery_crud_date_format'); |
|
4389 | - $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); |
|
4390 | - $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); |
|
4391 | - $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); |
|
4392 | - $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); |
|
4393 | - $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); |
|
4394 | - $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); |
|
4395 | - $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); |
|
4396 | - $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); |
|
4397 | - $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); |
|
4398 | - $this->config->environment = $ci->config->item('grocery_crud_environment'); |
|
4450 | + /** |
|
4451 | + * |
|
4452 | + * Or else ... make it work! The web application takes decision of what to do and show it to the final user. |
|
4453 | + * Without this function nothing works. Here is the core of grocery CRUD project. |
|
4454 | + * |
|
4455 | + * @access public |
|
4456 | + */ |
|
4457 | + public function render() |
|
4458 | + { |
|
4459 | + $this->pre_render(); |
|
4399 | 4460 | |
4400 | - /** Initialize default paths */ |
|
4401 | - $this->default_javascript_path = $this->default_assets_path.'/js'; |
|
4402 | - $this->default_css_path = $this->default_assets_path.'/css'; |
|
4403 | - $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; |
|
4404 | - $this->default_theme_path = $this->default_assets_path.'/themes'; |
|
4461 | + if( $this->state_code != 0 ) |
|
4462 | + { |
|
4463 | + $this->state_info = $this->getStateInfo(); |
|
4464 | + } |
|
4465 | + else |
|
4466 | + { |
|
4467 | + throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); |
|
4468 | + die(); |
|
4469 | + } |
|
4405 | 4470 | |
4406 | - $this->character_limiter = $this->config->character_limiter; |
|
4471 | + switch ($this->state_code) { |
|
4472 | + case 15://success |
|
4473 | + case 1://list |
|
4474 | + if($this->unset_list) |
|
4475 | + { |
|
4476 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
4477 | + die(); |
|
4478 | + } |
|
4407 | 4479 | |
4408 | - if ($this->character_limiter === 0 || $this->character_limiter === '0') { |
|
4409 | - $this->character_limiter = 1000000; //a very big number |
|
4410 | - } elseif($this->character_limiter === null || $this->character_limiter === false) { |
|
4411 | - $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value |
|
4412 | - } |
|
4480 | + if($this->theme === null) |
|
4481 | + $this->set_theme($this->default_theme); |
|
4482 | + $this->setThemeBasics(); |
|
4413 | 4483 | |
4414 | - if ($this->theme === null && !empty($this->config->default_theme)) { |
|
4415 | - $this->set_theme($this->config->default_theme); |
|
4416 | - } |
|
4417 | - } |
|
4418 | - |
|
4419 | - protected function _set_primary_keys_to_model() |
|
4420 | - { |
|
4421 | - if(!empty($this->primary_keys)) |
|
4422 | - { |
|
4423 | - foreach($this->primary_keys as $primary_key) |
|
4424 | - { |
|
4425 | - $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); |
|
4426 | - } |
|
4427 | - } |
|
4428 | - } |
|
4429 | - |
|
4430 | - /** |
|
4431 | - * Initialize all the required libraries and variables before rendering |
|
4432 | - */ |
|
4433 | - protected function pre_render() |
|
4434 | - { |
|
4435 | - $this->_initialize_variables(); |
|
4436 | - $this->_initialize_helpers(); |
|
4437 | - $this->_load_language(); |
|
4438 | - $this->state_code = $this->getStateCode(); |
|
4439 | - |
|
4440 | - if($this->basic_model === null) |
|
4441 | - $this->set_default_Model(); |
|
4442 | - |
|
4443 | - $this->set_basic_db_table($this->get_table()); |
|
4444 | - |
|
4445 | - $this->_load_date_format(); |
|
4446 | - |
|
4447 | - $this->_set_primary_keys_to_model(); |
|
4448 | - } |
|
4449 | - |
|
4450 | - /** |
|
4451 | - * |
|
4452 | - * Or else ... make it work! The web application takes decision of what to do and show it to the final user. |
|
4453 | - * Without this function nothing works. Here is the core of grocery CRUD project. |
|
4454 | - * |
|
4455 | - * @access public |
|
4456 | - */ |
|
4457 | - public function render() |
|
4458 | - { |
|
4459 | - $this->pre_render(); |
|
4460 | - |
|
4461 | - if( $this->state_code != 0 ) |
|
4462 | - { |
|
4463 | - $this->state_info = $this->getStateInfo(); |
|
4464 | - } |
|
4465 | - else |
|
4466 | - { |
|
4467 | - throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); |
|
4468 | - die(); |
|
4469 | - } |
|
4470 | - |
|
4471 | - switch ($this->state_code) { |
|
4472 | - case 15://success |
|
4473 | - case 1://list |
|
4474 | - if($this->unset_list) |
|
4475 | - { |
|
4476 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
4477 | - die(); |
|
4478 | - } |
|
4479 | - |
|
4480 | - if($this->theme === null) |
|
4481 | - $this->set_theme($this->default_theme); |
|
4482 | - $this->setThemeBasics(); |
|
4483 | - |
|
4484 | - $this->set_basic_Layout(); |
|
4484 | + $this->set_basic_Layout(); |
|
4485 | 4485 | |
4486 | - $state_info = $this->getStateInfo(); |
|
4486 | + $state_info = $this->getStateInfo(); |
|
4487 | 4487 | |
4488 | - $this->showList(false,$state_info); |
|
4488 | + $this->showList(false,$state_info); |
|
4489 | 4489 | |
4490 | - break; |
|
4490 | + break; |
|
4491 | 4491 | |
4492 | - case 2://add |
|
4493 | - if($this->unset_add) |
|
4494 | - { |
|
4495 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
4496 | - die(); |
|
4497 | - } |
|
4492 | + case 2://add |
|
4493 | + if($this->unset_add) |
|
4494 | + { |
|
4495 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
4496 | + die(); |
|
4497 | + } |
|
4498 | 4498 | |
4499 | - if($this->theme === null) |
|
4500 | - $this->set_theme($this->default_theme); |
|
4501 | - $this->setThemeBasics(); |
|
4499 | + if($this->theme === null) |
|
4500 | + $this->set_theme($this->default_theme); |
|
4501 | + $this->setThemeBasics(); |
|
4502 | 4502 | |
4503 | - $this->set_basic_Layout(); |
|
4503 | + $this->set_basic_Layout(); |
|
4504 | 4504 | |
4505 | - $this->showAddForm(); |
|
4505 | + $this->showAddForm(); |
|
4506 | 4506 | |
4507 | - break; |
|
4507 | + break; |
|
4508 | 4508 | |
4509 | - case 3://edit |
|
4510 | - if($this->unset_edit) |
|
4511 | - { |
|
4512 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
4513 | - die(); |
|
4514 | - } |
|
4509 | + case 3://edit |
|
4510 | + if($this->unset_edit) |
|
4511 | + { |
|
4512 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
4513 | + die(); |
|
4514 | + } |
|
4515 | 4515 | |
4516 | - if($this->theme === null) |
|
4517 | - $this->set_theme($this->default_theme); |
|
4518 | - $this->setThemeBasics(); |
|
4516 | + if($this->theme === null) |
|
4517 | + $this->set_theme($this->default_theme); |
|
4518 | + $this->setThemeBasics(); |
|
4519 | 4519 | |
4520 | - $this->set_basic_Layout(); |
|
4520 | + $this->set_basic_Layout(); |
|
4521 | 4521 | |
4522 | - $state_info = $this->getStateInfo(); |
|
4522 | + $state_info = $this->getStateInfo(); |
|
4523 | 4523 | |
4524 | - $this->showEditForm($state_info); |
|
4524 | + $this->showEditForm($state_info); |
|
4525 | 4525 | |
4526 | - break; |
|
4526 | + break; |
|
4527 | 4527 | |
4528 | - case 4://delete |
|
4529 | - if($this->unset_delete) |
|
4530 | - { |
|
4531 | - throw new Exception('This user is not allowed to do this operation', 14); |
|
4532 | - die(); |
|
4533 | - } |
|
4528 | + case 4://delete |
|
4529 | + if($this->unset_delete) |
|
4530 | + { |
|
4531 | + throw new Exception('This user is not allowed to do this operation', 14); |
|
4532 | + die(); |
|
4533 | + } |
|
4534 | 4534 | |
4535 | - $state_info = $this->getStateInfo(); |
|
4536 | - $delete_result = $this->db_delete($state_info); |
|
4535 | + $state_info = $this->getStateInfo(); |
|
4536 | + $delete_result = $this->db_delete($state_info); |
|
4537 | 4537 | |
4538 | - $this->delete_layout( $delete_result ); |
|
4539 | - break; |
|
4538 | + $this->delete_layout( $delete_result ); |
|
4539 | + break; |
|
4540 | 4540 | |
4541 | - case 5://insert |
|
4542 | - if($this->unset_add) |
|
4543 | - { |
|
4544 | - throw new Exception('This user is not allowed to do this operation', 14); |
|
4545 | - die(); |
|
4546 | - } |
|
4541 | + case 5://insert |
|
4542 | + if($this->unset_add) |
|
4543 | + { |
|
4544 | + throw new Exception('This user is not allowed to do this operation', 14); |
|
4545 | + die(); |
|
4546 | + } |
|
4547 | 4547 | |
4548 | - $state_info = $this->getStateInfo(); |
|
4549 | - $insert_result = $this->db_insert($state_info); |
|
4548 | + $state_info = $this->getStateInfo(); |
|
4549 | + $insert_result = $this->db_insert($state_info); |
|
4550 | 4550 | |
4551 | - $this->insert_layout($insert_result); |
|
4552 | - break; |
|
4551 | + $this->insert_layout($insert_result); |
|
4552 | + break; |
|
4553 | 4553 | |
4554 | - case 6://update |
|
4555 | - if($this->unset_edit) |
|
4556 | - { |
|
4557 | - throw new Exception('This user is not allowed to do this operation', 14); |
|
4558 | - die(); |
|
4559 | - } |
|
4554 | + case 6://update |
|
4555 | + if($this->unset_edit) |
|
4556 | + { |
|
4557 | + throw new Exception('This user is not allowed to do this operation', 14); |
|
4558 | + die(); |
|
4559 | + } |
|
4560 | 4560 | |
4561 | - $state_info = $this->getStateInfo(); |
|
4562 | - $update_result = $this->db_update($state_info); |
|
4561 | + $state_info = $this->getStateInfo(); |
|
4562 | + $update_result = $this->db_update($state_info); |
|
4563 | 4563 | |
4564 | - $this->update_layout( $update_result,$state_info); |
|
4565 | - break; |
|
4564 | + $this->update_layout( $update_result,$state_info); |
|
4565 | + break; |
|
4566 | 4566 | |
4567 | - case 7://ajax_list |
|
4567 | + case 7://ajax_list |
|
4568 | 4568 | |
4569 | - if($this->unset_list) |
|
4570 | - { |
|
4571 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
4572 | - die(); |
|
4573 | - } |
|
4569 | + if($this->unset_list) |
|
4570 | + { |
|
4571 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
4572 | + die(); |
|
4573 | + } |
|
4574 | 4574 | |
4575 | - if($this->theme === null) |
|
4576 | - $this->set_theme($this->default_theme); |
|
4577 | - $this->setThemeBasics(); |
|
4575 | + if($this->theme === null) |
|
4576 | + $this->set_theme($this->default_theme); |
|
4577 | + $this->setThemeBasics(); |
|
4578 | 4578 | |
4579 | - $this->set_basic_Layout(); |
|
4579 | + $this->set_basic_Layout(); |
|
4580 | 4580 | |
4581 | - $state_info = $this->getStateInfo(); |
|
4582 | - $this->set_ajax_list_queries($state_info); |
|
4581 | + $state_info = $this->getStateInfo(); |
|
4582 | + $this->set_ajax_list_queries($state_info); |
|
4583 | 4583 | |
4584 | - $this->showList(true); |
|
4584 | + $this->showList(true); |
|
4585 | 4585 | |
4586 | - break; |
|
4586 | + break; |
|
4587 | 4587 | |
4588 | - case 8://ajax_list_info |
|
4588 | + case 8://ajax_list_info |
|
4589 | 4589 | |
4590 | - if($this->theme === null) |
|
4591 | - $this->set_theme($this->default_theme); |
|
4592 | - $this->setThemeBasics(); |
|
4590 | + if($this->theme === null) |
|
4591 | + $this->set_theme($this->default_theme); |
|
4592 | + $this->setThemeBasics(); |
|
4593 | 4593 | |
4594 | - $this->set_basic_Layout(); |
|
4594 | + $this->set_basic_Layout(); |
|
4595 | 4595 | |
4596 | - $state_info = $this->getStateInfo(); |
|
4597 | - $this->set_ajax_list_queries($state_info); |
|
4596 | + $state_info = $this->getStateInfo(); |
|
4597 | + $this->set_ajax_list_queries($state_info); |
|
4598 | 4598 | |
4599 | - $this->showListInfo(); |
|
4600 | - break; |
|
4599 | + $this->showListInfo(); |
|
4600 | + break; |
|
4601 | 4601 | |
4602 | - case 9://insert_validation |
|
4602 | + case 9://insert_validation |
|
4603 | 4603 | |
4604 | - $validation_result = $this->db_insert_validation(); |
|
4604 | + $validation_result = $this->db_insert_validation(); |
|
4605 | 4605 | |
4606 | - $this->validation_layout($validation_result); |
|
4607 | - break; |
|
4606 | + $this->validation_layout($validation_result); |
|
4607 | + break; |
|
4608 | 4608 | |
4609 | - case 10://update_validation |
|
4609 | + case 10://update_validation |
|
4610 | 4610 | |
4611 | - $validation_result = $this->db_update_validation(); |
|
4611 | + $validation_result = $this->db_update_validation(); |
|
4612 | 4612 | |
4613 | - $this->validation_layout($validation_result); |
|
4614 | - break; |
|
4613 | + $this->validation_layout($validation_result); |
|
4614 | + break; |
|
4615 | 4615 | |
4616 | - case 11://upload_file |
|
4616 | + case 11://upload_file |
|
4617 | 4617 | |
4618 | - $state_info = $this->getStateInfo(); |
|
4618 | + $state_info = $this->getStateInfo(); |
|
4619 | 4619 | |
4620 | - $upload_result = $this->upload_file($state_info); |
|
4620 | + $upload_result = $this->upload_file($state_info); |
|
4621 | 4621 | |
4622 | - $this->upload_layout($upload_result, $state_info->field_name); |
|
4623 | - break; |
|
4622 | + $this->upload_layout($upload_result, $state_info->field_name); |
|
4623 | + break; |
|
4624 | 4624 | |
4625 | - case 12://delete_file |
|
4626 | - $state_info = $this->getStateInfo(); |
|
4625 | + case 12://delete_file |
|
4626 | + $state_info = $this->getStateInfo(); |
|
4627 | 4627 | |
4628 | - $delete_file_result = $this->delete_file($state_info); |
|
4628 | + $delete_file_result = $this->delete_file($state_info); |
|
4629 | 4629 | |
4630 | - $this->delete_file_layout($delete_file_result); |
|
4631 | - break; |
|
4632 | - /* |
|
4630 | + $this->delete_file_layout($delete_file_result); |
|
4631 | + break; |
|
4632 | + /* |
|
4633 | 4633 | case 13: //ajax_relation |
4634 | 4634 | $state_info = $this->getStateInfo(); |
4635 | 4635 | |
@@ -4646,559 +4646,559 @@ discard block |
||
4646 | 4646 | die(); |
4647 | 4647 | break; |
4648 | 4648 | */ |
4649 | - case 16: //export to excel |
|
4650 | - //a big number just to ensure that the table characters will not be cutted. |
|
4651 | - $this->character_limiter = 1000000; |
|
4649 | + case 16: //export to excel |
|
4650 | + //a big number just to ensure that the table characters will not be cutted. |
|
4651 | + $this->character_limiter = 1000000; |
|
4652 | 4652 | |
4653 | - if($this->unset_export) |
|
4654 | - { |
|
4655 | - throw new Exception('You don\'t have permissions for this operation', 15); |
|
4656 | - die(); |
|
4657 | - } |
|
4653 | + if($this->unset_export) |
|
4654 | + { |
|
4655 | + throw new Exception('You don\'t have permissions for this operation', 15); |
|
4656 | + die(); |
|
4657 | + } |
|
4658 | 4658 | |
4659 | - if($this->theme === null) |
|
4660 | - $this->set_theme($this->default_theme); |
|
4661 | - $this->setThemeBasics(); |
|
4659 | + if($this->theme === null) |
|
4660 | + $this->set_theme($this->default_theme); |
|
4661 | + $this->setThemeBasics(); |
|
4662 | 4662 | |
4663 | - $this->set_basic_Layout(); |
|
4663 | + $this->set_basic_Layout(); |
|
4664 | 4664 | |
4665 | - $state_info = $this->getStateInfo(); |
|
4666 | - $this->set_ajax_list_queries($state_info); |
|
4667 | - $this->exportToExcel($state_info); |
|
4668 | - break; |
|
4665 | + $state_info = $this->getStateInfo(); |
|
4666 | + $this->set_ajax_list_queries($state_info); |
|
4667 | + $this->exportToExcel($state_info); |
|
4668 | + break; |
|
4669 | 4669 | |
4670 | - case 17: //print |
|
4671 | - //a big number just to ensure that the table characters will not be cutted. |
|
4672 | - $this->character_limiter = 1000000; |
|
4670 | + case 17: //print |
|
4671 | + //a big number just to ensure that the table characters will not be cutted. |
|
4672 | + $this->character_limiter = 1000000; |
|
4673 | 4673 | |
4674 | - if($this->unset_print) |
|
4675 | - { |
|
4676 | - throw new Exception('You don\'t have permissions for this operation', 15); |
|
4677 | - die(); |
|
4678 | - } |
|
4674 | + if($this->unset_print) |
|
4675 | + { |
|
4676 | + throw new Exception('You don\'t have permissions for this operation', 15); |
|
4677 | + die(); |
|
4678 | + } |
|
4679 | 4679 | |
4680 | - if($this->theme === null) |
|
4681 | - $this->set_theme($this->default_theme); |
|
4682 | - $this->setThemeBasics(); |
|
4680 | + if($this->theme === null) |
|
4681 | + $this->set_theme($this->default_theme); |
|
4682 | + $this->setThemeBasics(); |
|
4683 | 4683 | |
4684 | - $this->set_basic_Layout(); |
|
4684 | + $this->set_basic_Layout(); |
|
4685 | 4685 | |
4686 | - $state_info = $this->getStateInfo(); |
|
4687 | - $this->set_ajax_list_queries($state_info); |
|
4688 | - $this->print_webpage($state_info); |
|
4689 | - break; |
|
4686 | + $state_info = $this->getStateInfo(); |
|
4687 | + $this->set_ajax_list_queries($state_info); |
|
4688 | + $this->print_webpage($state_info); |
|
4689 | + break; |
|
4690 | 4690 | |
4691 | - case grocery_CRUD_States::STATE_READ: |
|
4692 | - if($this->unset_read) |
|
4693 | - { |
|
4694 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
4695 | - die(); |
|
4696 | - } |
|
4691 | + case grocery_CRUD_States::STATE_READ: |
|
4692 | + if($this->unset_read) |
|
4693 | + { |
|
4694 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
4695 | + die(); |
|
4696 | + } |
|
4697 | 4697 | |
4698 | - if($this->theme === null) |
|
4699 | - $this->set_theme($this->default_theme); |
|
4700 | - $this->setThemeBasics(); |
|
4698 | + if($this->theme === null) |
|
4699 | + $this->set_theme($this->default_theme); |
|
4700 | + $this->setThemeBasics(); |
|
4701 | 4701 | |
4702 | - $this->set_basic_Layout(); |
|
4702 | + $this->set_basic_Layout(); |
|
4703 | 4703 | |
4704 | - $state_info = $this->getStateInfo(); |
|
4704 | + $state_info = $this->getStateInfo(); |
|
4705 | 4705 | |
4706 | - $this->showReadForm($state_info); |
|
4706 | + $this->showReadForm($state_info); |
|
4707 | 4707 | |
4708 | - break; |
|
4708 | + break; |
|
4709 | 4709 | |
4710 | 4710 | case grocery_CRUD_States::STATE_DELETE_MULTIPLE: |
4711 | 4711 | |
4712 | - if($this->unset_delete) |
|
4712 | + if($this->unset_delete) |
|
4713 | 4713 | { |
4714 | 4714 | throw new Exception('This user is not allowed to do this operation'); |
4715 | 4715 | die(); |
4716 | 4716 | } |
4717 | 4717 | |
4718 | - $state_info = $this->getStateInfo(); |
|
4719 | - $delete_result = $this->db_multiple_delete($state_info); |
|
4718 | + $state_info = $this->getStateInfo(); |
|
4719 | + $delete_result = $this->db_multiple_delete($state_info); |
|
4720 | 4720 | |
4721 | - $this->delete_layout($delete_result); |
|
4721 | + $this->delete_layout($delete_result); |
|
4722 | 4722 | |
4723 | 4723 | break; |
4724 | 4724 | |
4725 | - } |
|
4726 | - |
|
4727 | - return $this->get_layout(); |
|
4728 | - } |
|
4729 | - |
|
4730 | - protected function get_common_data() |
|
4731 | - { |
|
4732 | - $data = (object)array(); |
|
4733 | - |
|
4734 | - $data->subject = $this->subject; |
|
4735 | - $data->subject_plural = $this->subject_plural; |
|
4736 | - |
|
4737 | - return $data; |
|
4738 | - } |
|
4739 | - |
|
4740 | - /** |
|
4741 | - * |
|
4742 | - * Enter description here ... |
|
4743 | - */ |
|
4744 | - public function callback_before_insert($callback = null) |
|
4745 | - { |
|
4746 | - $this->callback_before_insert = $callback; |
|
4747 | - |
|
4748 | - return $this; |
|
4749 | - } |
|
4750 | - |
|
4751 | - /** |
|
4752 | - * |
|
4753 | - * Enter description here ... |
|
4754 | - */ |
|
4755 | - public function callback_after_insert($callback = null) |
|
4756 | - { |
|
4757 | - $this->callback_after_insert = $callback; |
|
4758 | - |
|
4759 | - return $this; |
|
4760 | - } |
|
4761 | - |
|
4762 | - /** |
|
4763 | - * |
|
4764 | - * Enter description here ... |
|
4765 | - */ |
|
4766 | - public function callback_insert($callback = null) |
|
4767 | - { |
|
4768 | - $this->callback_insert = $callback; |
|
4769 | - |
|
4770 | - return $this; |
|
4771 | - } |
|
4772 | - |
|
4773 | - |
|
4774 | - /** |
|
4775 | - * |
|
4776 | - * Enter description here ... |
|
4777 | - */ |
|
4778 | - public function callback_before_update($callback = null) |
|
4779 | - { |
|
4780 | - $this->callback_before_update = $callback; |
|
4781 | - |
|
4782 | - return $this; |
|
4783 | - } |
|
4784 | - |
|
4785 | - /** |
|
4786 | - * |
|
4787 | - * Enter description here ... |
|
4788 | - */ |
|
4789 | - public function callback_after_update($callback = null) |
|
4790 | - { |
|
4791 | - $this->callback_after_update = $callback; |
|
4792 | - |
|
4793 | - return $this; |
|
4794 | - } |
|
4795 | - |
|
4796 | - |
|
4797 | - /** |
|
4798 | - * |
|
4799 | - * Enter description here ... |
|
4800 | - * @param mixed $callback |
|
4801 | - */ |
|
4802 | - public function callback_update($callback = null) |
|
4803 | - { |
|
4804 | - $this->callback_update = $callback; |
|
4805 | - |
|
4806 | - return $this; |
|
4807 | - } |
|
4808 | - |
|
4809 | - /** |
|
4810 | - * |
|
4811 | - * Enter description here ... |
|
4812 | - */ |
|
4813 | - public function callback_before_delete($callback = null) |
|
4814 | - { |
|
4815 | - $this->callback_before_delete = $callback; |
|
4816 | - |
|
4817 | - return $this; |
|
4818 | - } |
|
4819 | - |
|
4820 | - /** |
|
4821 | - * |
|
4822 | - * Enter description here ... |
|
4823 | - */ |
|
4824 | - public function callback_after_delete($callback = null) |
|
4825 | - { |
|
4826 | - $this->callback_after_delete = $callback; |
|
4827 | - |
|
4828 | - return $this; |
|
4829 | - } |
|
4830 | - |
|
4831 | - /** |
|
4832 | - * |
|
4833 | - * Enter description here ... |
|
4834 | - */ |
|
4835 | - public function callback_delete($callback = null) |
|
4836 | - { |
|
4837 | - $this->callback_delete = $callback; |
|
4838 | - |
|
4839 | - return $this; |
|
4840 | - } |
|
4841 | - |
|
4842 | - /** |
|
4843 | - * |
|
4844 | - * Enter description here ... |
|
4845 | - * @param string $column |
|
4846 | - * @param mixed $callback |
|
4847 | - */ |
|
4848 | - public function callback_column($column ,$callback = null) |
|
4849 | - { |
|
4850 | - $this->callback_column[$column] = $callback; |
|
4851 | - |
|
4852 | - return $this; |
|
4853 | - } |
|
4854 | - |
|
4855 | - /** |
|
4856 | - * |
|
4857 | - * Enter description here ... |
|
4858 | - * @param string $field |
|
4859 | - * @param mixed $callback |
|
4860 | - */ |
|
4861 | - public function callback_field($field, $callback = null) |
|
4862 | - { |
|
4863 | - $this->callback_add_field[$field] = $callback; |
|
4864 | - $this->callback_edit_field[$field] = $callback; |
|
4865 | - |
|
4866 | - return $this; |
|
4867 | - } |
|
4868 | - |
|
4869 | - /** |
|
4870 | - * |
|
4871 | - * Enter description here ... |
|
4872 | - * @param string $field |
|
4873 | - * @param mixed $callback |
|
4874 | - */ |
|
4875 | - public function callback_add_field($field, $callback = null) |
|
4876 | - { |
|
4877 | - $this->callback_add_field[$field] = $callback; |
|
4878 | - |
|
4879 | - return $this; |
|
4880 | - } |
|
4881 | - |
|
4882 | - /** |
|
4883 | - * |
|
4884 | - * Enter description here ... |
|
4885 | - * @param string $field |
|
4886 | - * @param mixed $callback |
|
4887 | - */ |
|
4888 | - public function callback_edit_field($field, $callback = null) |
|
4889 | - { |
|
4890 | - $this->callback_edit_field[$field] = $callback; |
|
4891 | - |
|
4892 | - return $this; |
|
4893 | - } |
|
4894 | - |
|
4895 | - /** |
|
4896 | - * |
|
4897 | - * Callback that replace the default auto uploader |
|
4898 | - * |
|
4899 | - * @param mixed $callback |
|
4900 | - * @return grocery_CRUD |
|
4901 | - */ |
|
4902 | - public function callback_upload($callback = null) |
|
4903 | - { |
|
4904 | - $this->callback_upload = $callback; |
|
4905 | - |
|
4906 | - return $this; |
|
4907 | - } |
|
4908 | - |
|
4909 | - /** |
|
4910 | - * |
|
4911 | - * A callback that triggered before the upload functionality. This callback is suggested for validation checks |
|
4912 | - * @param mixed $callback |
|
4913 | - * @return grocery_CRUD |
|
4914 | - */ |
|
4915 | - public function callback_before_upload($callback = null) |
|
4916 | - { |
|
4917 | - $this->callback_before_upload = $callback; |
|
4918 | - |
|
4919 | - return $this; |
|
4920 | - } |
|
4921 | - |
|
4922 | - /** |
|
4923 | - * |
|
4924 | - * A callback that triggered after the upload functionality |
|
4925 | - * @param mixed $callback |
|
4926 | - * @return grocery_CRUD |
|
4927 | - */ |
|
4928 | - public function callback_after_upload($callback = null) |
|
4929 | - { |
|
4930 | - $this->callback_after_upload = $callback; |
|
4931 | - |
|
4932 | - return $this; |
|
4933 | - |
|
4934 | - } |
|
4935 | - |
|
4936 | - /** |
|
4937 | - * |
|
4938 | - * Gets the basic database table of our crud. |
|
4939 | - * @return string |
|
4940 | - */ |
|
4941 | - public function get_table() |
|
4942 | - { |
|
4943 | - if($this->basic_db_table_checked) |
|
4944 | - { |
|
4945 | - return $this->basic_db_table; |
|
4946 | - } |
|
4947 | - elseif( $this->basic_db_table !== null ) |
|
4948 | - { |
|
4949 | - if(!$this->table_exists($this->basic_db_table)) |
|
4950 | - { |
|
4951 | - throw new Exception('The table name does not exist. Please check you database and try again.',11); |
|
4952 | - die(); |
|
4953 | - } |
|
4954 | - $this->basic_db_table_checked = true; |
|
4955 | - return $this->basic_db_table; |
|
4956 | - } |
|
4957 | - else |
|
4958 | - { |
|
4959 | - //Last try , try to find the table from your view / function name!!! Not suggested but it works . |
|
4960 | - $last_chance_table_name = $this->get_method_name(); |
|
4961 | - if($this->table_exists($last_chance_table_name)) |
|
4962 | - { |
|
4963 | - $this->set_table($last_chance_table_name); |
|
4964 | - } |
|
4965 | - $this->basic_db_table_checked = true; |
|
4966 | - return $this->basic_db_table; |
|
4967 | - |
|
4968 | - } |
|
4969 | - |
|
4970 | - return false; |
|
4971 | - } |
|
4972 | - |
|
4973 | - /** |
|
4974 | - * |
|
4975 | - * The field names of the required fields |
|
4976 | - */ |
|
4977 | - public function required_fields() |
|
4978 | - { |
|
4979 | - $args = func_get_args(); |
|
4980 | - |
|
4981 | - if(isset($args[0]) && is_array($args[0])) |
|
4982 | - { |
|
4983 | - $args = $args[0]; |
|
4984 | - } |
|
4985 | - |
|
4986 | - $this->required_fields = $args; |
|
4987 | - |
|
4988 | - return $this; |
|
4989 | - } |
|
4990 | - |
|
4991 | - /** |
|
4992 | - * Add the fields that they are as UNIQUE in the database structure |
|
4993 | - * |
|
4994 | - * @return grocery_CRUD |
|
4995 | - */ |
|
4996 | - public function unique_fields() |
|
4997 | - { |
|
4998 | - $args = func_get_args(); |
|
4999 | - |
|
5000 | - if(isset($args[0]) && is_array($args[0])) |
|
5001 | - { |
|
5002 | - $args = $args[0]; |
|
5003 | - } |
|
5004 | - |
|
5005 | - $this->_unique_fields = $args; |
|
5006 | - |
|
5007 | - return $this; |
|
5008 | - } |
|
5009 | - |
|
5010 | - /** |
|
5011 | - * |
|
5012 | - * Sets the basic database table that we will get our data. |
|
5013 | - * @param string $table_name |
|
5014 | - * @return grocery_CRUD |
|
5015 | - */ |
|
5016 | - public function set_table($table_name) |
|
5017 | - { |
|
5018 | - if(!empty($table_name) && $this->basic_db_table === null) |
|
5019 | - { |
|
5020 | - $this->basic_db_table = $table_name; |
|
5021 | - } |
|
5022 | - elseif(!empty($table_name)) |
|
5023 | - { |
|
5024 | - throw new Exception('You have already insert a table name once...', 1); |
|
5025 | - } |
|
5026 | - else |
|
5027 | - { |
|
5028 | - throw new Exception('The table name cannot be empty.', 2); |
|
5029 | - die(); |
|
5030 | - } |
|
5031 | - |
|
5032 | - return $this; |
|
5033 | - } |
|
5034 | - |
|
5035 | - /** |
|
5036 | - * Set a full URL path to this method. |
|
5037 | - * |
|
5038 | - * This method is useful when the path is not specified correctly. |
|
5039 | - * Especially when we are using routes. |
|
5040 | - * For example: |
|
5041 | - * Let's say we have the path http://www.example.com/ however the original url path is |
|
5042 | - * http://www.example.com/example/index . We have to specify the url so we can have |
|
5043 | - * all the CRUD operations correctly. |
|
5044 | - * The url path has to be set from this method like this: |
|
5045 | - * <code> |
|
5046 | - * $crud->set_crud_url_path(site_url('example/index')); |
|
5047 | - * </code> |
|
5048 | - * |
|
5049 | - * @param string $crud_url_path |
|
5050 | - * @param string $list_url_path |
|
5051 | - * @return grocery_CRUD |
|
5052 | - */ |
|
5053 | - public function set_crud_url_path($crud_url_path, $list_url_path = null) |
|
5054 | - { |
|
5055 | - $this->crud_url_path = $crud_url_path; |
|
5056 | - |
|
5057 | - //If the list_url_path is empty so we are guessing that the list_url_path |
|
5058 | - //will be the same with crud_url_path |
|
5059 | - $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; |
|
5060 | - |
|
5061 | - return $this; |
|
5062 | - } |
|
5063 | - |
|
5064 | - /** |
|
5065 | - * |
|
5066 | - * Set a subject to understand what type of CRUD you use. |
|
4725 | + } |
|
4726 | + |
|
4727 | + return $this->get_layout(); |
|
4728 | + } |
|
4729 | + |
|
4730 | + protected function get_common_data() |
|
4731 | + { |
|
4732 | + $data = (object)array(); |
|
4733 | + |
|
4734 | + $data->subject = $this->subject; |
|
4735 | + $data->subject_plural = $this->subject_plural; |
|
4736 | + |
|
4737 | + return $data; |
|
4738 | + } |
|
4739 | + |
|
4740 | + /** |
|
4741 | + * |
|
4742 | + * Enter description here ... |
|
4743 | + */ |
|
4744 | + public function callback_before_insert($callback = null) |
|
4745 | + { |
|
4746 | + $this->callback_before_insert = $callback; |
|
4747 | + |
|
4748 | + return $this; |
|
4749 | + } |
|
4750 | + |
|
4751 | + /** |
|
4752 | + * |
|
4753 | + * Enter description here ... |
|
4754 | + */ |
|
4755 | + public function callback_after_insert($callback = null) |
|
4756 | + { |
|
4757 | + $this->callback_after_insert = $callback; |
|
4758 | + |
|
4759 | + return $this; |
|
4760 | + } |
|
4761 | + |
|
4762 | + /** |
|
4763 | + * |
|
4764 | + * Enter description here ... |
|
4765 | + */ |
|
4766 | + public function callback_insert($callback = null) |
|
4767 | + { |
|
4768 | + $this->callback_insert = $callback; |
|
4769 | + |
|
4770 | + return $this; |
|
4771 | + } |
|
4772 | + |
|
4773 | + |
|
4774 | + /** |
|
4775 | + * |
|
4776 | + * Enter description here ... |
|
4777 | + */ |
|
4778 | + public function callback_before_update($callback = null) |
|
4779 | + { |
|
4780 | + $this->callback_before_update = $callback; |
|
4781 | + |
|
4782 | + return $this; |
|
4783 | + } |
|
4784 | + |
|
4785 | + /** |
|
4786 | + * |
|
4787 | + * Enter description here ... |
|
4788 | + */ |
|
4789 | + public function callback_after_update($callback = null) |
|
4790 | + { |
|
4791 | + $this->callback_after_update = $callback; |
|
4792 | + |
|
4793 | + return $this; |
|
4794 | + } |
|
4795 | + |
|
4796 | + |
|
4797 | + /** |
|
4798 | + * |
|
4799 | + * Enter description here ... |
|
4800 | + * @param mixed $callback |
|
4801 | + */ |
|
4802 | + public function callback_update($callback = null) |
|
4803 | + { |
|
4804 | + $this->callback_update = $callback; |
|
4805 | + |
|
4806 | + return $this; |
|
4807 | + } |
|
4808 | + |
|
4809 | + /** |
|
4810 | + * |
|
4811 | + * Enter description here ... |
|
4812 | + */ |
|
4813 | + public function callback_before_delete($callback = null) |
|
4814 | + { |
|
4815 | + $this->callback_before_delete = $callback; |
|
4816 | + |
|
4817 | + return $this; |
|
4818 | + } |
|
4819 | + |
|
4820 | + /** |
|
4821 | + * |
|
4822 | + * Enter description here ... |
|
4823 | + */ |
|
4824 | + public function callback_after_delete($callback = null) |
|
4825 | + { |
|
4826 | + $this->callback_after_delete = $callback; |
|
4827 | + |
|
4828 | + return $this; |
|
4829 | + } |
|
4830 | + |
|
4831 | + /** |
|
4832 | + * |
|
4833 | + * Enter description here ... |
|
4834 | + */ |
|
4835 | + public function callback_delete($callback = null) |
|
4836 | + { |
|
4837 | + $this->callback_delete = $callback; |
|
4838 | + |
|
4839 | + return $this; |
|
4840 | + } |
|
4841 | + |
|
4842 | + /** |
|
4843 | + * |
|
4844 | + * Enter description here ... |
|
4845 | + * @param string $column |
|
4846 | + * @param mixed $callback |
|
4847 | + */ |
|
4848 | + public function callback_column($column ,$callback = null) |
|
4849 | + { |
|
4850 | + $this->callback_column[$column] = $callback; |
|
4851 | + |
|
4852 | + return $this; |
|
4853 | + } |
|
4854 | + |
|
4855 | + /** |
|
4856 | + * |
|
4857 | + * Enter description here ... |
|
4858 | + * @param string $field |
|
4859 | + * @param mixed $callback |
|
4860 | + */ |
|
4861 | + public function callback_field($field, $callback = null) |
|
4862 | + { |
|
4863 | + $this->callback_add_field[$field] = $callback; |
|
4864 | + $this->callback_edit_field[$field] = $callback; |
|
4865 | + |
|
4866 | + return $this; |
|
4867 | + } |
|
4868 | + |
|
4869 | + /** |
|
4870 | + * |
|
4871 | + * Enter description here ... |
|
4872 | + * @param string $field |
|
4873 | + * @param mixed $callback |
|
4874 | + */ |
|
4875 | + public function callback_add_field($field, $callback = null) |
|
4876 | + { |
|
4877 | + $this->callback_add_field[$field] = $callback; |
|
4878 | + |
|
4879 | + return $this; |
|
4880 | + } |
|
4881 | + |
|
4882 | + /** |
|
4883 | + * |
|
4884 | + * Enter description here ... |
|
4885 | + * @param string $field |
|
4886 | + * @param mixed $callback |
|
4887 | + */ |
|
4888 | + public function callback_edit_field($field, $callback = null) |
|
4889 | + { |
|
4890 | + $this->callback_edit_field[$field] = $callback; |
|
4891 | + |
|
4892 | + return $this; |
|
4893 | + } |
|
4894 | + |
|
4895 | + /** |
|
4896 | + * |
|
4897 | + * Callback that replace the default auto uploader |
|
4898 | + * |
|
4899 | + * @param mixed $callback |
|
4900 | + * @return grocery_CRUD |
|
4901 | + */ |
|
4902 | + public function callback_upload($callback = null) |
|
4903 | + { |
|
4904 | + $this->callback_upload = $callback; |
|
4905 | + |
|
4906 | + return $this; |
|
4907 | + } |
|
4908 | + |
|
4909 | + /** |
|
4910 | + * |
|
4911 | + * A callback that triggered before the upload functionality. This callback is suggested for validation checks |
|
4912 | + * @param mixed $callback |
|
4913 | + * @return grocery_CRUD |
|
4914 | + */ |
|
4915 | + public function callback_before_upload($callback = null) |
|
4916 | + { |
|
4917 | + $this->callback_before_upload = $callback; |
|
4918 | + |
|
4919 | + return $this; |
|
4920 | + } |
|
4921 | + |
|
4922 | + /** |
|
4923 | + * |
|
4924 | + * A callback that triggered after the upload functionality |
|
4925 | + * @param mixed $callback |
|
4926 | + * @return grocery_CRUD |
|
4927 | + */ |
|
4928 | + public function callback_after_upload($callback = null) |
|
4929 | + { |
|
4930 | + $this->callback_after_upload = $callback; |
|
4931 | + |
|
4932 | + return $this; |
|
4933 | + |
|
4934 | + } |
|
4935 | + |
|
4936 | + /** |
|
4937 | + * |
|
4938 | + * Gets the basic database table of our crud. |
|
4939 | + * @return string |
|
4940 | + */ |
|
4941 | + public function get_table() |
|
4942 | + { |
|
4943 | + if($this->basic_db_table_checked) |
|
4944 | + { |
|
4945 | + return $this->basic_db_table; |
|
4946 | + } |
|
4947 | + elseif( $this->basic_db_table !== null ) |
|
4948 | + { |
|
4949 | + if(!$this->table_exists($this->basic_db_table)) |
|
4950 | + { |
|
4951 | + throw new Exception('The table name does not exist. Please check you database and try again.',11); |
|
4952 | + die(); |
|
4953 | + } |
|
4954 | + $this->basic_db_table_checked = true; |
|
4955 | + return $this->basic_db_table; |
|
4956 | + } |
|
4957 | + else |
|
4958 | + { |
|
4959 | + //Last try , try to find the table from your view / function name!!! Not suggested but it works . |
|
4960 | + $last_chance_table_name = $this->get_method_name(); |
|
4961 | + if($this->table_exists($last_chance_table_name)) |
|
4962 | + { |
|
4963 | + $this->set_table($last_chance_table_name); |
|
4964 | + } |
|
4965 | + $this->basic_db_table_checked = true; |
|
4966 | + return $this->basic_db_table; |
|
4967 | + |
|
4968 | + } |
|
4969 | + |
|
4970 | + return false; |
|
4971 | + } |
|
4972 | + |
|
4973 | + /** |
|
4974 | + * |
|
4975 | + * The field names of the required fields |
|
4976 | + */ |
|
4977 | + public function required_fields() |
|
4978 | + { |
|
4979 | + $args = func_get_args(); |
|
4980 | + |
|
4981 | + if(isset($args[0]) && is_array($args[0])) |
|
4982 | + { |
|
4983 | + $args = $args[0]; |
|
4984 | + } |
|
4985 | + |
|
4986 | + $this->required_fields = $args; |
|
4987 | + |
|
4988 | + return $this; |
|
4989 | + } |
|
4990 | + |
|
4991 | + /** |
|
4992 | + * Add the fields that they are as UNIQUE in the database structure |
|
4993 | + * |
|
4994 | + * @return grocery_CRUD |
|
4995 | + */ |
|
4996 | + public function unique_fields() |
|
4997 | + { |
|
4998 | + $args = func_get_args(); |
|
4999 | + |
|
5000 | + if(isset($args[0]) && is_array($args[0])) |
|
5001 | + { |
|
5002 | + $args = $args[0]; |
|
5003 | + } |
|
5004 | + |
|
5005 | + $this->_unique_fields = $args; |
|
5006 | + |
|
5007 | + return $this; |
|
5008 | + } |
|
5009 | + |
|
5010 | + /** |
|
5011 | + * |
|
5012 | + * Sets the basic database table that we will get our data. |
|
5013 | + * @param string $table_name |
|
5014 | + * @return grocery_CRUD |
|
5015 | + */ |
|
5016 | + public function set_table($table_name) |
|
5017 | + { |
|
5018 | + if(!empty($table_name) && $this->basic_db_table === null) |
|
5019 | + { |
|
5020 | + $this->basic_db_table = $table_name; |
|
5021 | + } |
|
5022 | + elseif(!empty($table_name)) |
|
5023 | + { |
|
5024 | + throw new Exception('You have already insert a table name once...', 1); |
|
5025 | + } |
|
5026 | + else |
|
5027 | + { |
|
5028 | + throw new Exception('The table name cannot be empty.', 2); |
|
5029 | + die(); |
|
5030 | + } |
|
5031 | + |
|
5032 | + return $this; |
|
5033 | + } |
|
5034 | + |
|
5035 | + /** |
|
5036 | + * Set a full URL path to this method. |
|
5037 | + * |
|
5038 | + * This method is useful when the path is not specified correctly. |
|
5039 | + * Especially when we are using routes. |
|
5040 | + * For example: |
|
5041 | + * Let's say we have the path http://www.example.com/ however the original url path is |
|
5042 | + * http://www.example.com/example/index . We have to specify the url so we can have |
|
5043 | + * all the CRUD operations correctly. |
|
5044 | + * The url path has to be set from this method like this: |
|
5045 | + * <code> |
|
5046 | + * $crud->set_crud_url_path(site_url('example/index')); |
|
5047 | + * </code> |
|
5048 | + * |
|
5049 | + * @param string $crud_url_path |
|
5050 | + * @param string $list_url_path |
|
5051 | + * @return grocery_CRUD |
|
5052 | + */ |
|
5053 | + public function set_crud_url_path($crud_url_path, $list_url_path = null) |
|
5054 | + { |
|
5055 | + $this->crud_url_path = $crud_url_path; |
|
5056 | + |
|
5057 | + //If the list_url_path is empty so we are guessing that the list_url_path |
|
5058 | + //will be the same with crud_url_path |
|
5059 | + $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; |
|
5060 | + |
|
5061 | + return $this; |
|
5062 | + } |
|
5063 | + |
|
5064 | + /** |
|
5065 | + * |
|
5066 | + * Set a subject to understand what type of CRUD you use. |
|
5067 | 5067 | * ---------------------------------------------------------------------------------------------- |
5068 | 5068 | * Subject_plural: Sets the subject to its plural form. For example the plural |
5069 | 5069 | * of "Customer" is "Customers", "Product" is "Products"... e.t.c. |
5070 | - * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' |
|
5070 | + * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' |
|
5071 | 5071 | * and the $subject_plural will be 'Categories' |
5072 | - * @param string $subject |
|
5073 | - * @param string $subject_plural |
|
5074 | - * @return grocery_CRUD |
|
5075 | - */ |
|
5076 | - public function set_subject($subject, $subject_plural = null) |
|
5077 | - { |
|
5078 | - $this->subject = $subject; |
|
5072 | + * @param string $subject |
|
5073 | + * @param string $subject_plural |
|
5074 | + * @return grocery_CRUD |
|
5075 | + */ |
|
5076 | + public function set_subject($subject, $subject_plural = null) |
|
5077 | + { |
|
5078 | + $this->subject = $subject; |
|
5079 | 5079 | $this->subject_plural = $subject_plural === null ? $subject : $subject_plural; |
5080 | 5080 | |
5081 | - return $this; |
|
5082 | - } |
|
5083 | - |
|
5084 | - /** |
|
5085 | - * |
|
5086 | - * Enter description here ... |
|
5087 | - * @param $title |
|
5088 | - * @param $image_url |
|
5089 | - * @param $url |
|
5090 | - * @param $css_class |
|
5091 | - * @param $url_callback |
|
5092 | - */ |
|
5093 | - public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) |
|
5094 | - { |
|
5095 | - $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string |
|
5096 | - |
|
5097 | - $this->actions[$unique_id] = (object)array( |
|
5098 | - 'label' => $label, |
|
5099 | - 'image_url' => $image_url, |
|
5100 | - 'link_url' => $link_url, |
|
5101 | - 'css_class' => $css_class, |
|
5102 | - 'url_callback' => $url_callback, |
|
5103 | - 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false |
|
5104 | - ); |
|
5105 | - |
|
5106 | - return $this; |
|
5107 | - } |
|
5108 | - |
|
5109 | - /** |
|
5110 | - * |
|
5111 | - * Set a simple 1-n foreign key relation |
|
5112 | - * @param string $field_name |
|
5113 | - * @param string $related_table |
|
5114 | - * @param string $related_title_field |
|
5115 | - * @param mixed $where_clause |
|
5116 | - * @param string $order_by |
|
5081 | + return $this; |
|
5082 | + } |
|
5083 | + |
|
5084 | + /** |
|
5085 | + * |
|
5086 | + * Enter description here ... |
|
5087 | + * @param $title |
|
5088 | + * @param $image_url |
|
5089 | + * @param $url |
|
5090 | + * @param $css_class |
|
5091 | + * @param $url_callback |
|
5092 | + */ |
|
5093 | + public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) |
|
5094 | + { |
|
5095 | + $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string |
|
5096 | + |
|
5097 | + $this->actions[$unique_id] = (object)array( |
|
5098 | + 'label' => $label, |
|
5099 | + 'image_url' => $image_url, |
|
5100 | + 'link_url' => $link_url, |
|
5101 | + 'css_class' => $css_class, |
|
5102 | + 'url_callback' => $url_callback, |
|
5103 | + 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false |
|
5104 | + ); |
|
5105 | + |
|
5106 | + return $this; |
|
5107 | + } |
|
5108 | + |
|
5109 | + /** |
|
5110 | + * |
|
5111 | + * Set a simple 1-n foreign key relation |
|
5112 | + * @param string $field_name |
|
5113 | + * @param string $related_table |
|
5114 | + * @param string $related_title_field |
|
5115 | + * @param mixed $where_clause |
|
5116 | + * @param string $order_by |
|
5117 | 5117 | * @return Grocery_CRUD |
5118 | - */ |
|
5119 | - public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) |
|
5120 | - { |
|
5121 | - $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); |
|
5122 | - return $this; |
|
5123 | - } |
|
5124 | - |
|
5125 | - /** |
|
5126 | - * |
|
5127 | - * Sets a relation with n-n relationship. |
|
5128 | - * @param string $field_name |
|
5129 | - * @param string $relation_table |
|
5130 | - * @param string $selection_table |
|
5131 | - * @param string $primary_key_alias_to_this_table |
|
5132 | - * @param string $primary_key_alias_to_selection_table |
|
5133 | - * @param string $title_field_selection_table |
|
5134 | - * @param string $priority_field_relation_table |
|
5135 | - * @param mixed $where_clause |
|
5118 | + */ |
|
5119 | + public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) |
|
5120 | + { |
|
5121 | + $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); |
|
5122 | + return $this; |
|
5123 | + } |
|
5124 | + |
|
5125 | + /** |
|
5126 | + * |
|
5127 | + * Sets a relation with n-n relationship. |
|
5128 | + * @param string $field_name |
|
5129 | + * @param string $relation_table |
|
5130 | + * @param string $selection_table |
|
5131 | + * @param string $primary_key_alias_to_this_table |
|
5132 | + * @param string $primary_key_alias_to_selection_table |
|
5133 | + * @param string $title_field_selection_table |
|
5134 | + * @param string $priority_field_relation_table |
|
5135 | + * @param mixed $where_clause |
|
5136 | 5136 | * @return Grocery_CRUD |
5137 | - */ |
|
5138 | - public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) |
|
5139 | - { |
|
5140 | - $this->relation_n_n[$field_name] = |
|
5141 | - (object)array( |
|
5142 | - 'field_name' => $field_name, |
|
5143 | - 'relation_table' => $relation_table, |
|
5144 | - 'selection_table' => $selection_table, |
|
5145 | - 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, |
|
5146 | - 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , |
|
5147 | - 'title_field_selection_table' => $title_field_selection_table , |
|
5148 | - 'priority_field_relation_table' => $priority_field_relation_table, |
|
5149 | - 'where_clause' => $where_clause |
|
5150 | - ); |
|
5151 | - |
|
5152 | - return $this; |
|
5153 | - } |
|
5154 | - |
|
5155 | - /** |
|
5156 | - * |
|
5157 | - * Transform a field to an upload field |
|
5158 | - * |
|
5159 | - * @param string $field_name |
|
5160 | - * @param string $upload_path |
|
5137 | + */ |
|
5138 | + public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) |
|
5139 | + { |
|
5140 | + $this->relation_n_n[$field_name] = |
|
5141 | + (object)array( |
|
5142 | + 'field_name' => $field_name, |
|
5143 | + 'relation_table' => $relation_table, |
|
5144 | + 'selection_table' => $selection_table, |
|
5145 | + 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, |
|
5146 | + 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , |
|
5147 | + 'title_field_selection_table' => $title_field_selection_table , |
|
5148 | + 'priority_field_relation_table' => $priority_field_relation_table, |
|
5149 | + 'where_clause' => $where_clause |
|
5150 | + ); |
|
5151 | + |
|
5152 | + return $this; |
|
5153 | + } |
|
5154 | + |
|
5155 | + /** |
|
5156 | + * |
|
5157 | + * Transform a field to an upload field |
|
5158 | + * |
|
5159 | + * @param string $field_name |
|
5160 | + * @param string $upload_path |
|
5161 | 5161 | * @return Grocery_CRUD |
5162 | - */ |
|
5163 | - public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') |
|
5164 | - { |
|
5165 | - $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' |
|
5166 | - ? substr($upload_dir,0,-1) |
|
5167 | - : $upload_dir; |
|
5168 | - $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; |
|
5169 | - |
|
5170 | - /** Check if the upload Url folder exists. If not then throw an exception **/ |
|
5171 | - if (!is_dir(FCPATH.$upload_dir)) { |
|
5172 | - throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name |
|
5162 | + */ |
|
5163 | + public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') |
|
5164 | + { |
|
5165 | + $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' |
|
5166 | + ? substr($upload_dir,0,-1) |
|
5167 | + : $upload_dir; |
|
5168 | + $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; |
|
5169 | + |
|
5170 | + /** Check if the upload Url folder exists. If not then throw an exception **/ |
|
5171 | + if (!is_dir(FCPATH.$upload_dir)) { |
|
5172 | + throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name |
|
5173 | 5173 | \"".$field_name."\" doesn't exists. Please create the folder and try again."); |
5174 | - } |
|
5175 | - |
|
5176 | - $this->upload_fields[$field_name] = (object) array( |
|
5177 | - 'field_name' => $field_name, |
|
5178 | - 'upload_path' => $upload_dir, |
|
5179 | - 'allowed_file_types' => $allowed_file_types, |
|
5180 | - 'encrypted_field_name' => $this->_unique_field_name($field_name)); |
|
5181 | - return $this; |
|
5182 | - } |
|
5174 | + } |
|
5175 | + |
|
5176 | + $this->upload_fields[$field_name] = (object) array( |
|
5177 | + 'field_name' => $field_name, |
|
5178 | + 'upload_path' => $upload_dir, |
|
5179 | + 'allowed_file_types' => $allowed_file_types, |
|
5180 | + 'encrypted_field_name' => $this->_unique_field_name($field_name)); |
|
5181 | + return $this; |
|
5182 | + } |
|
5183 | 5183 | } |
5184 | 5184 | |
5185 | 5185 | if(defined('CI_VERSION')) |
5186 | 5186 | { |
5187 | - $ci = &get_instance(); |
|
5188 | - $ci->load->library('Form_validation'); |
|
5189 | - |
|
5190 | - class grocery_CRUD_Form_validation extends CI_Form_validation{ |
|
5191 | - |
|
5192 | - public $CI; |
|
5193 | - public $_field_data = array(); |
|
5194 | - public $_config_rules = array(); |
|
5195 | - public $_error_array = array(); |
|
5196 | - public $_error_messages = array(); |
|
5197 | - public $_error_prefix = '<p>'; |
|
5198 | - public $_error_suffix = '</p>'; |
|
5199 | - public $error_string = ''; |
|
5200 | - public $_safe_form_data = FALSE; |
|
5201 | - } |
|
5187 | + $ci = &get_instance(); |
|
5188 | + $ci->load->library('Form_validation'); |
|
5189 | + |
|
5190 | + class grocery_CRUD_Form_validation extends CI_Form_validation{ |
|
5191 | + |
|
5192 | + public $CI; |
|
5193 | + public $_field_data = array(); |
|
5194 | + public $_config_rules = array(); |
|
5195 | + public $_error_array = array(); |
|
5196 | + public $_error_messages = array(); |
|
5197 | + public $_error_prefix = '<p>'; |
|
5198 | + public $_error_suffix = '</p>'; |
|
5199 | + public $error_string = ''; |
|
5200 | + public $_safe_form_data = FALSE; |
|
5201 | + } |
|
5202 | 5202 | } |
5203 | 5203 | |
5204 | 5204 | /* |
@@ -5258,19 +5258,19 @@ discard block |
||
5258 | 5258 | // Or else for PHP >= 5.3.0 use: $this->options = array_replace_recursive($this->options, $options); |
5259 | 5259 | foreach($options as $option_name => $option) |
5260 | 5260 | { |
5261 | - $this->options[$option_name] = $option; |
|
5261 | + $this->options[$option_name] = $option; |
|
5262 | 5262 | } |
5263 | 5263 | } |
5264 | 5264 | } |
5265 | 5265 | |
5266 | 5266 | function getFullUrl() { |
5267 | - return |
|
5268 | - (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). |
|
5269 | - (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). |
|
5270 | - (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. |
|
5271 | - (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || |
|
5272 | - $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). |
|
5273 | - substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
5267 | + return |
|
5268 | + (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). |
|
5269 | + (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). |
|
5270 | + (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. |
|
5271 | + (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || |
|
5272 | + $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). |
|
5273 | + substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
5274 | 5274 | } |
5275 | 5275 | |
5276 | 5276 | private function get_file_object($file_name) { |
@@ -5356,26 +5356,26 @@ discard block |
||
5356 | 5356 | |
5357 | 5357 | private function has_error($uploaded_file, $file, $error) { |
5358 | 5358 | if ($error) { |
5359 | - switch($error) { |
|
5360 | - case UPLOAD_ERR_INI_SIZE: |
|
5361 | - return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
|
5362 | - break; |
|
5363 | - case UPLOAD_ERR_PARTIAL: |
|
5364 | - return 'The uploaded file was only partially uploaded.'; |
|
5365 | - break; |
|
5366 | - case UPLOAD_ERR_NO_FILE: |
|
5367 | - return 'No file was uploaded.'; |
|
5368 | - break; |
|
5369 | - case UPLOAD_ERR_CANT_WRITE: |
|
5370 | - return 'Failed to write file to disk.'; |
|
5371 | - break; |
|
5372 | - case UPLOAD_ERR_EXTENSION: |
|
5373 | - return 'File upload stopped by extension.'; |
|
5374 | - break; |
|
5375 | - default: |
|
5376 | - return $error; |
|
5377 | - break; |
|
5378 | - } |
|
5359 | + switch($error) { |
|
5360 | + case UPLOAD_ERR_INI_SIZE: |
|
5361 | + return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
|
5362 | + break; |
|
5363 | + case UPLOAD_ERR_PARTIAL: |
|
5364 | + return 'The uploaded file was only partially uploaded.'; |
|
5365 | + break; |
|
5366 | + case UPLOAD_ERR_NO_FILE: |
|
5367 | + return 'No file was uploaded.'; |
|
5368 | + break; |
|
5369 | + case UPLOAD_ERR_CANT_WRITE: |
|
5370 | + return 'Failed to write file to disk.'; |
|
5371 | + break; |
|
5372 | + case UPLOAD_ERR_EXTENSION: |
|
5373 | + return 'File upload stopped by extension.'; |
|
5374 | + break; |
|
5375 | + default: |
|
5376 | + return $error; |
|
5377 | + break; |
|
5378 | + } |
|
5379 | 5379 | } |
5380 | 5380 | if (!preg_match($this->options['accept_file_types'], $file->name)) { |
5381 | 5381 | return 'acceptFileTypes'; |
@@ -5425,43 +5425,43 @@ discard block |
||
5425 | 5425 | } |
5426 | 5426 | |
5427 | 5427 | private function _transliterate_characters($file_name) |
5428 | - { |
|
5429 | - include($this->default_config_path.'/translit_chars.php'); |
|
5430 | - if ( isset($translit_characters)) |
|
5431 | - { |
|
5432 | - $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); |
|
5433 | - } |
|
5428 | + { |
|
5429 | + include($this->default_config_path.'/translit_chars.php'); |
|
5430 | + if ( isset($translit_characters)) |
|
5431 | + { |
|
5432 | + $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); |
|
5433 | + } |
|
5434 | 5434 | |
5435 | - $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); |
|
5436 | - $file_name = str_replace(" ", "-", $file_name); |
|
5435 | + $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); |
|
5436 | + $file_name = str_replace(" ", "-", $file_name); |
|
5437 | 5437 | |
5438 | - return preg_replace('/\-+/', '-', trim($file_name, '-')); |
|
5439 | - } |
|
5438 | + return preg_replace('/\-+/', '-', trim($file_name, '-')); |
|
5439 | + } |
|
5440 | 5440 | |
5441 | 5441 | private function orient_image($file_path) { |
5442 | - $exif = exif_read_data($file_path); |
|
5443 | - $orientation = intval(@$exif['Orientation']); |
|
5444 | - if (!in_array($orientation, array(3, 6, 8))) { |
|
5445 | - return false; |
|
5446 | - } |
|
5447 | - $image = @imagecreatefromjpeg($file_path); |
|
5448 | - switch ($orientation) { |
|
5449 | - case 3: |
|
5450 | - $image = @imagerotate($image, 180, 0); |
|
5451 | - break; |
|
5452 | - case 6: |
|
5453 | - $image = @imagerotate($image, 270, 0); |
|
5454 | - break; |
|
5455 | - case 8: |
|
5456 | - $image = @imagerotate($image, 90, 0); |
|
5457 | - break; |
|
5458 | - default: |
|
5459 | - return false; |
|
5460 | - } |
|
5461 | - $success = imagejpeg($image, $file_path); |
|
5462 | - // Free up memory (imagedestroy does not delete files): |
|
5463 | - @imagedestroy($image); |
|
5464 | - return $success; |
|
5442 | + $exif = exif_read_data($file_path); |
|
5443 | + $orientation = intval(@$exif['Orientation']); |
|
5444 | + if (!in_array($orientation, array(3, 6, 8))) { |
|
5445 | + return false; |
|
5446 | + } |
|
5447 | + $image = @imagecreatefromjpeg($file_path); |
|
5448 | + switch ($orientation) { |
|
5449 | + case 3: |
|
5450 | + $image = @imagerotate($image, 180, 0); |
|
5451 | + break; |
|
5452 | + case 6: |
|
5453 | + $image = @imagerotate($image, 270, 0); |
|
5454 | + break; |
|
5455 | + case 8: |
|
5456 | + $image = @imagerotate($image, 90, 0); |
|
5457 | + break; |
|
5458 | + default: |
|
5459 | + return false; |
|
5460 | + } |
|
5461 | + $success = imagejpeg($image, $file_path); |
|
5462 | + // Free up memory (imagedestroy does not delete files): |
|
5463 | + @imagedestroy($image); |
|
5464 | + return $success; |
|
5465 | 5465 | } |
5466 | 5466 | |
5467 | 5467 | private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { |
@@ -5496,9 +5496,9 @@ discard block |
||
5496 | 5496 | } |
5497 | 5497 | $file_size = filesize($file_path); |
5498 | 5498 | if ($file_size === $file->size) { |
5499 | - if ($this->options['orient_image']) { |
|
5500 | - $this->orient_image($file_path); |
|
5501 | - } |
|
5499 | + if ($this->options['orient_image']) { |
|
5500 | + $this->orient_image($file_path); |
|
5501 | + } |
|
5502 | 5502 | $file->url = $this->options['upload_url'].rawurlencode($file->name); |
5503 | 5503 | foreach($this->options['image_versions'] as $version => $options) { |
5504 | 5504 | if ($this->create_scaled_image($file->name, $options)) { |
@@ -2,7 +2,7 @@ |
||
2 | 2 | defined('BASEPATH') OR exit('No direct script access allowed'); |
3 | 3 | |
4 | 4 | echo "\nERROR: ", |
5 | - $heading, |
|
6 | - "\n\n", |
|
7 | - $message, |
|
8 | - "\n\n"; |
|
9 | 5 | \ No newline at end of file |
6 | + $heading, |
|
7 | + "\n\n", |
|
8 | + $message, |
|
9 | + "\n\n"; |
|
10 | 10 | \ No newline at end of file |