@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $this->load->view('computing-support/room-move/complete'); |
53 | 53 | $this->load->view('templates/footer'); |
54 | 54 | |
55 | - if ($furniture == "No Furniture"){ |
|
55 | + if ($furniture == "No Furniture") { |
|
56 | 56 | |
57 | 57 | $to_add = array('[email protected]', '[email protected]', '[email protected]'); |
58 | 58 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $staff_involved_un6 = $user_un6; |
166 | 166 | $staff_involved_email6 = $this->room_move_model->get_email_username($staff_involved_un6); |
167 | 167 | |
168 | - $staff_involved_un7= $user_un7; |
|
168 | + $staff_involved_un7 = $user_un7; |
|
169 | 169 | $staff_involved_email7 = $this->room_move_model->get_email_username($staff_involved_un7); |
170 | 170 | |
171 | 171 | $staff_involved_un8 = $user_un8; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | $id = $_GET['id']; |
257 | 257 | $this->room_move_model->cancel($id); |
258 | 258 | |
259 | - $function = 'room_move_CANCEL_' . $id; |
|
259 | + $function = 'room_move_CANCEL_'.$id; |
|
260 | 260 | $this->user_model->function_log($function); |
261 | 261 | |
262 | 262 | $get_request = $this->room_move_model->get_request($id); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $staff_involved_un6 = $get_request[0]['staff_involved_un6']; |
283 | 283 | $staff_involved_email6 = $this->room_move_model->get_email_username($staff_involved_un6); |
284 | 284 | |
285 | - $staff_involved_un7= $get_request[0]['staff_involved_un7']; |
|
285 | + $staff_involved_un7 = $get_request[0]['staff_involved_un7']; |
|
286 | 286 | $staff_involved_email7 = $this->room_move_model->get_email_username($staff_involved_un7); |
287 | 287 | |
288 | 288 | $staff_involved_un8 = $get_request[0]['staff_involved_un8']; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $id = $_GET['id']; |
329 | 329 | $this->room_move_model->eh_reject($id); |
330 | 330 | |
331 | - $function = 'room_move_EH_REJECT_' . $id; |
|
331 | + $function = 'room_move_EH_REJECT_'.$id; |
|
332 | 332 | $this->user_model->function_log($function); |
333 | 333 | |
334 | 334 | $get_request = $this->room_move_model->get_request($id); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | $staff_involved_un6 = $get_request[0]['staff_involved_un6']; |
355 | 355 | $staff_involved_email6 = $this->room_move_model->get_email_username($staff_involved_un6); |
356 | 356 | |
357 | - $staff_involved_un7= $get_request[0]['staff_involved_un7']; |
|
357 | + $staff_involved_un7 = $get_request[0]['staff_involved_un7']; |
|
358 | 358 | $staff_involved_email7 = $this->room_move_model->get_email_username($staff_involved_un7); |
359 | 359 | |
360 | 360 | $staff_involved_un8 = $get_request[0]['staff_involved_un8']; |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | $id = $_GET['id']; |
403 | 403 | $this->room_move_model->eh_approve($id); |
404 | 404 | |
405 | - $function = 'room_move_EH_APPROVED_' . $id; |
|
405 | + $function = 'room_move_EH_APPROVED_'.$id; |
|
406 | 406 | $this->user_model->function_log($function); |
407 | 407 | |
408 | 408 | $get_request = $this->room_move_model->get_request($id); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $reason = $_GET['reason']; |
445 | 445 | $this->room_move_model->cs_reject($id); |
446 | 446 | |
447 | - $function = 'room_move_CS_REJECT_' . $id; |
|
447 | + $function = 'room_move_CS_REJECT_'.$id; |
|
448 | 448 | $this->user_model->function_log($function); |
449 | 449 | |
450 | 450 | $get_request = $this->room_move_model->get_request($id); |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | $staff_involved_un6 = $get_request[0]['staff_involved_un6']; |
471 | 471 | $staff_involved_email6 = $this->room_move_model->get_email_username($staff_involved_un6); |
472 | 472 | |
473 | - $staff_involved_un7= $get_request[0]['staff_involved_un7']; |
|
473 | + $staff_involved_un7 = $get_request[0]['staff_involved_un7']; |
|
474 | 474 | $staff_involved_email7 = $this->room_move_model->get_email_username($staff_involved_un7); |
475 | 475 | |
476 | 476 | $staff_involved_un8 = $get_request[0]['staff_involved_un8']; |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | $id = $_GET['id']; |
519 | 519 | $this->room_move_model->cs_approve($id); |
520 | 520 | |
521 | - $function = 'room_move_CS_APPROVED_' . $id; |
|
521 | + $function = 'room_move_CS_APPROVED_'.$id; |
|
522 | 522 | $this->user_model->function_log($function); |
523 | 523 | |
524 | 524 | $get_request = $this->room_move_model->get_request($id); |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | $staff_involved_un6 = $get_request[0]['staff_involved_un6']; |
545 | 545 | $staff_involved_email6 = $this->room_move_model->get_email_username($staff_involved_un6); |
546 | 546 | |
547 | - $staff_involved_un7= $get_request[0]['staff_involved_un7']; |
|
547 | + $staff_involved_un7 = $get_request[0]['staff_involved_un7']; |
|
548 | 548 | $staff_involved_email7 = $this->room_move_model->get_email_username($staff_involved_un7); |
549 | 549 | |
550 | 550 | $staff_involved_un8 = $get_request[0]['staff_involved_un8']; |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | $id = $_GET['id']; |
592 | 592 | $this->room_move_model->cs_complete($id); |
593 | 593 | |
594 | - $function = 'room_move_CS_COMPLETE_' . $id; |
|
594 | + $function = 'room_move_CS_COMPLETE_'.$id; |
|
595 | 595 | $this->user_model->function_log($function); |
596 | 596 | |
597 | 597 | $get_request = $this->room_move_model->get_request($id); |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | $staff_involved_un6 = $get_request[0]['staff_involved_un6']; |
618 | 618 | $staff_involved_email6 = $this->room_move_model->get_email_username($staff_involved_un6); |
619 | 619 | |
620 | - $staff_involved_un7= $get_request[0]['staff_involved_un7']; |
|
620 | + $staff_involved_un7 = $get_request[0]['staff_involved_un7']; |
|
621 | 621 | $staff_involved_email7 = $this->room_move_model->get_email_username($staff_involved_un7); |
622 | 622 | |
623 | 623 | $staff_involved_un8 = $get_request[0]['staff_involved_un8']; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $crud = new grocery_CRUD(); |
73 | 73 | $crud->set_table('disposals'); |
74 | 74 | $crud->set_subject('disposals', 'Disposals'); |
75 | - $crud->display_as('sn','Serial Number'); |
|
75 | + $crud->display_as('sn', 'Serial Number'); |
|
76 | 76 | $crud->unset_columns('id'); |
77 | 77 | $crud->unset_add(); |
78 | 78 | $crud->unset_read(); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $crud->set_table('disposals_current'); |
99 | 99 | $crud->set_subject('disposals', 'Disposals'); |
100 | 100 | $crud->set_primary_key('id'); |
101 | - $crud->display_as('sn','Serial Number'); |
|
101 | + $crud->display_as('sn', 'Serial Number'); |
|
102 | 102 | $crud->unset_columns('id'); |
103 | 103 | $crud->unset_add(); |
104 | 104 | $crud->unset_read(); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->email->to($_SESSION['ldap']['email']); |
34 | 34 | $this->email->subject('Mobile Phone Policy'); |
35 | 35 | $this->email->message( |
36 | - 'Name: ' . $_SESSION['ldap']['fll_name']. ' |
|
36 | + 'Name: ' . $_SESSION['ldap']['fll_name']. ' |
|
37 | 37 | |
38 | 38 | Has accepted the Canterbury College mobile phone policy. |
39 | 39 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->email->to('[email protected]'); |
67 | 67 | $this->email->subject('Mobile Phone Policy Accepted'); |
68 | 68 | $this->email->message( |
69 | - 'Name: ' . $_SESSION['ldap']['full_name'] . ' |
|
69 | + 'Name: ' . $_SESSION['ldap']['full_name'] . ' |
|
70 | 70 | |
71 | 71 | Has accepted the Canterbury College mobile phone policy. |
72 | 72 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->email->to($_SESSION['ldap']['email']); |
34 | 34 | $this->email->subject('Mobile Phone Policy'); |
35 | 35 | $this->email->message( |
36 | - 'Name: ' . $_SESSION['ldap']['fll_name']. ' |
|
36 | + 'Name: '.$_SESSION['ldap']['fll_name'].' |
|
37 | 37 | |
38 | 38 | Has accepted the Canterbury College mobile phone policy. |
39 | 39 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | $this->email->to('[email protected]'); |
67 | 67 | $this->email->subject('Mobile Phone Policy Accepted'); |
68 | 68 | $this->email->message( |
69 | - 'Name: ' . $_SESSION['ldap']['full_name'] . ' |
|
69 | + 'Name: '.$_SESSION['ldap']['full_name'].' |
|
70 | 70 | |
71 | 71 | Has accepted the Canterbury College mobile phone policy. |
72 | 72 | |
73 | - ' . date("d/m/Y") . ' ' . date("h:i")); |
|
73 | + ' . date("d/m/Y").' '.date("h:i")); |
|
74 | 74 | $this->email->send(); |
75 | 75 | |
76 | 76 | $function = 'mobile_policy_accepted'; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | $data['faculty'] = $this->temporary_account_model->get_faculty(); |
18 | 18 | $data['department'] = $this->temporary_account_model->get_department(); |
19 | - $data['tempid'] = "tempuser" . $this->temporary_account_model->get_next_temp(); |
|
19 | + $data['tempid'] = "tempuser".$this->temporary_account_model->get_next_temp(); |
|
20 | 20 | |
21 | 21 | //validation |
22 | 22 | $this->form_validation->set_rules('faculty', 'Faculty', 'trim|required'); |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | $this->email->from('[email protected]', 'Temporary Logon Account Request'); |
47 | 47 | $this->email->to('[email protected]'); |
48 | 48 | $this->email->subject('Temporary Logon Account Request'); |
49 | - $this->email->message('A temporary network account has been requested by ' . $_SESSION['ldap']['full_name'] |
|
50 | - . ' for ' . $this->input->post('requester') |
|
49 | + $this->email->message('A temporary network account has been requested by '.$_SESSION['ldap']['full_name'] |
|
50 | + . ' for '.$this->input->post('requester') |
|
51 | 51 | . '' |
52 | - . 'the user will be: ' . $this->input->post('first_name') . ' ' . $this->input->post('last_name') |
|
52 | + . 'the user will be: '.$this->input->post('first_name').' '.$this->input->post('last_name') |
|
53 | 53 | . '' |
54 | 54 | . 'Approve https://intranet.cant-col.ac.uk/dashboard/computing-support/temporary-account/approve'); |
55 | 55 | $this->email->send(); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $id = $_GET['id']; |
119 | 119 | $this->temporary_account_model->cancel($id); |
120 | 120 | |
121 | - $function = 'temp_account_CANCEL_' . $id; |
|
121 | + $function = 'temp_account_CANCEL_'.$id; |
|
122 | 122 | $this->user_model->function_log($function); |
123 | 123 | |
124 | 124 | redirect($_SERVER['HTTP_REFERER']); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $id = $_GET['id']; |
139 | 139 | $this->temporary_account_model->reject($id); |
140 | 140 | |
141 | - $function = 'temp_account_REJECT_' . $id; |
|
141 | + $function = 'temp_account_REJECT_'.$id; |
|
142 | 142 | $this->user_model->function_log($function); |
143 | 143 | |
144 | 144 | redirect($_SERVER['HTTP_REFERER']); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $id = $_GET['id']; |
160 | 160 | //$this->temporary_account_model->approve($id); |
161 | 161 | |
162 | - $function = 'temp_account_APPROVED_' . $id; |
|
162 | + $function = 'temp_account_APPROVED_'.$id; |
|
163 | 163 | $this->user_model->function_log($function); |
164 | 164 | |
165 | 165 | $data['AD'] = $this->temporary_account_model->get_account($id); |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | |
175 | 175 | //Format dd-mm-yyyy |
176 | 176 | //Expiry is beginning of day (thats why +1 day |
177 | - $dateFromForm = date('d-m-Y', strtotime($data['AD'][0]['expiry']. ' +1 day')); |
|
177 | + $dateFromForm = date('d-m-Y', strtotime($data['AD'][0]['expiry'].' +1 day')); |
|
178 | 178 | |
179 | 179 | //Format hh:mm:ss |
180 | 180 | $timeFromForm = "00:00:00"; |
181 | 181 | |
182 | - $dateWithTime = $dateFromForm . " " . $timeFromForm; |
|
182 | + $dateWithTime = $dateFromForm." ".$timeFromForm; |
|
183 | 183 | |
184 | 184 | function convertDateToUnix($input) { |
185 | 185 | $format = 'd-m-Y H:i:s'; |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | //$WIN = convertUnixtoWin($UNIX); |
197 | 197 | |
198 | 198 | //Create Unicode password |
199 | - $passwordWithQuotes = '"' . $data['AD'][0]['password'] . '"'; |
|
199 | + $passwordWithQuotes = '"'.$data['AD'][0]['password'].'"'; |
|
200 | 200 | $ldaprecord["unicodepwd"] = iconv('UTF-8', 'UTF-16LE', $passwordWithQuotes); |
201 | 201 | |
202 | 202 | //Build Active Directory record |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | $ldaprecord["sn"] = $data['AD'][0]['last_name']; |
206 | 206 | $ldaprecord["mail"] = $data['AD'][0]['email']; |
207 | 207 | $ldaprecord["sAMAccountName"] = $data['AD'][0]['username']; |
208 | - $ldaprecord["displayName"] = $data['AD'][0]['first_name'] . " " . $data['AD'][0]['last_name']; |
|
208 | + $ldaprecord["displayName"] = $data['AD'][0]['first_name']." ".$data['AD'][0]['last_name']; |
|
209 | 209 | $ldaprecord["l"] = "Canterbury"; |
210 | - $ldaprecord["description"] = "Temp account created by dashboard for " . $ldaprecord["displayName"]; |
|
210 | + $ldaprecord["description"] = "Temp account created by dashboard for ".$ldaprecord["displayName"]; |
|
211 | 211 | //$ldaprecord["accountExpires"] = $WIN; |
212 | 212 | $ldaprecord["UserAccountControl"] = "512"; //512 - Enabled Account |
213 | - $ldaprecord['userPrincipalName'] = $data['AD'][0]['username'] . '@cant-col.ac.uk'; |
|
213 | + $ldaprecord['userPrincipalName'] = $data['AD'][0]['username'].'@cant-col.ac.uk'; |
|
214 | 214 | $ldaprecord['objectclass'][0] = "top"; |
215 | 215 | $ldaprecord['objectclass'][1] = "person"; |
216 | 216 | $ldaprecord['objectclass'][2] = "organizationalPerson"; |
217 | 217 | $ldaprecord['objectclass'][3] = "user"; |
218 | - $dn = 'CN=' . $ldaprecord["cn"] . ',OU=Temp Accounts,OU=Students,OU=Accounts,DC=cant-col,DC=ac,DC=uk'; |
|
218 | + $dn = 'CN='.$ldaprecord["cn"].',OU=Temp Accounts,OU=Students,OU=Accounts,DC=cant-col,DC=ac,DC=uk'; |
|
219 | 219 | |
220 | 220 | // Connect to Active Directory |
221 | - $ds = ldap_connect('ldaps://' . $AD_server); |
|
221 | + $ds = ldap_connect('ldaps://'.$AD_server); |
|
222 | 222 | |
223 | 223 | if ($ds) { |
224 | 224 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
@@ -44,11 +44,11 @@ |
||
44 | 44 | $this->email->from('[email protected]', 'Address Book Update'); |
45 | 45 | $this->email->to('[email protected]'); |
46 | 46 | $this->email->subject('Address Book Update'); |
47 | - $this->email->message('A global address book update request been made by ' . $_SESSION['ldap']['full_name'] . ' |
|
48 | - Change name to: ' . $name . ' |
|
49 | - Change Faculty to: ' . $faculty[0]['faculty'] . ' |
|
50 | - Change Department to: ' . $department[0]['subfaculty'] . ' |
|
51 | - Change Room to : ' . $room . ' |
|
47 | + $this->email->message('A global address book update request been made by '.$_SESSION['ldap']['full_name'].' |
|
48 | + Change name to: ' . $name.' |
|
49 | + Change Faculty to: ' . $faculty[0]['faculty'].' |
|
50 | + Change Department to: ' . $department[0]['subfaculty'].' |
|
51 | + Change Room to : ' . $room.' |
|
52 | 52 | Change Telephone to : ' . $phone.' |
53 | 53 | Change Position to : ' . $position); |
54 | 54 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | !empty($entries[$x]['samaccountname'][0]) && |
38 | 38 | !empty($entries[$x]['sn'][0]) && |
39 | 39 | !empty($entries[$x]['mail'][0])) { |
40 | - $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
40 | + $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '.trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | !empty($entries[$x]['samaccountname'][0]) && |
50 | 50 | !empty($entries[$x]['sn'][0]) && |
51 | 51 | !empty($entries[$x]['mail'][0])) { |
52 | - $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
52 | + $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '.trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | !empty($entries[$x]['samaccountname'][0]) && |
62 | 62 | !empty($entries[$x]['sn'][0]) && |
63 | 63 | !empty($entries[$x]['mail'][0])) { |
64 | - $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
64 | + $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '.trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | !empty($entries[$x]['samaccountname'][0]) && |
74 | 74 | !empty($entries[$x]['sn'][0]) && |
75 | 75 | !empty($entries[$x]['mail'][0])) { |
76 | - $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
76 | + $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '.trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | !empty($entries[$x]['samaccountname'][0]) && |
86 | 86 | !empty($entries[$x]['sn'][0]) && |
87 | 87 | !empty($entries[$x]['mail'][0])) { |
88 | - $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
88 | + $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '.trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0])); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -29,347 +29,347 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class Grocery_crud_model extends CI_Model { |
31 | 31 | |
32 | - protected $primary_key = null; |
|
33 | - protected $table_name = null; |
|
34 | - protected $relation = array(); |
|
35 | - protected $relation_n_n = array(); |
|
36 | - protected $primary_keys = array(); |
|
32 | + protected $primary_key = null; |
|
33 | + protected $table_name = null; |
|
34 | + protected $relation = array(); |
|
35 | + protected $relation_n_n = array(); |
|
36 | + protected $primary_keys = array(); |
|
37 | 37 | |
38 | - function __construct() |
|
38 | + function __construct() |
|
39 | 39 | { |
40 | 40 | parent::__construct(); |
41 | 41 | } |
42 | 42 | |
43 | 43 | function db_table_exists($table_name = null) |
44 | 44 | { |
45 | - return $this->db->table_exists($table_name); |
|
45 | + return $this->db->table_exists($table_name); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | function get_list() |
49 | 49 | { |
50 | - if($this->table_name === null) |
|
51 | - return false; |
|
50 | + if($this->table_name === null) |
|
51 | + return false; |
|
52 | 52 | |
53 | - $select = "`{$this->table_name}`.*"; |
|
53 | + $select = "`{$this->table_name}`.*"; |
|
54 | 54 | |
55 | - //set_relation special queries |
|
56 | - if(!empty($this->relation)) |
|
57 | - { |
|
58 | - foreach($this->relation as $relation) |
|
59 | - { |
|
60 | - list($field_name , $related_table , $related_field_title) = $relation; |
|
61 | - $unique_join_name = $this->_unique_join_name($field_name); |
|
62 | - $unique_field_name = $this->_unique_field_name($field_name); |
|
63 | - |
|
64 | - if(strstr($related_field_title,'{')) |
|
65 | - { |
|
66 | - $related_field_title = str_replace(" "," ",$related_field_title); |
|
67 | - $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; |
|
68 | - } |
|
69 | - else |
|
70 | - { |
|
71 | - $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; |
|
72 | - } |
|
73 | - |
|
74 | - if($this->field_exists($related_field_title)) |
|
75 | - $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; |
|
76 | - } |
|
77 | - } |
|
55 | + //set_relation special queries |
|
56 | + if(!empty($this->relation)) |
|
57 | + { |
|
58 | + foreach($this->relation as $relation) |
|
59 | + { |
|
60 | + list($field_name , $related_table , $related_field_title) = $relation; |
|
61 | + $unique_join_name = $this->_unique_join_name($field_name); |
|
62 | + $unique_field_name = $this->_unique_field_name($field_name); |
|
63 | + |
|
64 | + if(strstr($related_field_title,'{')) |
|
65 | + { |
|
66 | + $related_field_title = str_replace(" "," ",$related_field_title); |
|
67 | + $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; |
|
68 | + } |
|
69 | + else |
|
70 | + { |
|
71 | + $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; |
|
72 | + } |
|
73 | + |
|
74 | + if($this->field_exists($related_field_title)) |
|
75 | + $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. |
|
80 | - if(!empty($this->relation_n_n)) |
|
81 | - { |
|
82 | - $select = $this->relation_n_n_queries($select); |
|
83 | - } |
|
79 | + //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. |
|
80 | + if(!empty($this->relation_n_n)) |
|
81 | + { |
|
82 | + $select = $this->relation_n_n_queries($select); |
|
83 | + } |
|
84 | 84 | |
85 | - $this->db->select($select, false); |
|
85 | + $this->db->select($select, false); |
|
86 | 86 | |
87 | - $results = $this->db->get($this->table_name)->result(); |
|
87 | + $results = $this->db->get($this->table_name)->result(); |
|
88 | 88 | |
89 | - return $results; |
|
89 | + return $results; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public function get_row($table_name = null) |
93 | 93 | { |
94 | - $table_name = $table_name === null ? $this->table_name : $table_name; |
|
94 | + $table_name = $table_name === null ? $this->table_name : $table_name; |
|
95 | 95 | |
96 | - return $this->db->get($table_name)->row(); |
|
96 | + return $this->db->get($table_name)->row(); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function set_primary_key($field_name, $table_name = null) |
100 | 100 | { |
101 | - $table_name = $table_name === null ? $this->table_name : $table_name; |
|
101 | + $table_name = $table_name === null ? $this->table_name : $table_name; |
|
102 | 102 | |
103 | - $this->primary_keys[$table_name] = $field_name; |
|
103 | + $this->primary_keys[$table_name] = $field_name; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | protected function relation_n_n_queries($select) |
107 | 107 | { |
108 | - $this_table_primary_key = $this->get_primary_key(); |
|
109 | - foreach($this->relation_n_n as $relation_n_n) |
|
110 | - { |
|
111 | - list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, |
|
112 | - $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n); |
|
113 | - |
|
114 | - $primary_key_selection_table = $this->get_primary_key($selection_table); |
|
115 | - |
|
116 | - $field = ""; |
|
117 | - $use_template = strpos($title_field_selection_table,'{') !== false; |
|
118 | - $field_name_hash = $this->_unique_field_name($title_field_selection_table); |
|
119 | - if($use_template) |
|
120 | - { |
|
121 | - $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); |
|
122 | - $field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')"; |
|
123 | - } |
|
124 | - else |
|
125 | - { |
|
126 | - $field .= "$selection_table.$title_field_selection_table"; |
|
127 | - } |
|
128 | - |
|
129 | - //Sorry Codeigniter but you cannot help me with the subquery! |
|
130 | - $select .= ", (SELECT GROUP_CONCAT(DISTINCT $field) FROM $selection_table " |
|
131 | - ."LEFT JOIN $relation_table ON $relation_table.$primary_key_alias_to_selection_table = $selection_table.$primary_key_selection_table " |
|
132 | - ."WHERE $relation_table.$primary_key_alias_to_this_table = `{$this->table_name}`.$this_table_primary_key GROUP BY $relation_table.$primary_key_alias_to_this_table) AS $field_name"; |
|
133 | - } |
|
108 | + $this_table_primary_key = $this->get_primary_key(); |
|
109 | + foreach($this->relation_n_n as $relation_n_n) |
|
110 | + { |
|
111 | + list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, |
|
112 | + $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n); |
|
113 | + |
|
114 | + $primary_key_selection_table = $this->get_primary_key($selection_table); |
|
115 | + |
|
116 | + $field = ""; |
|
117 | + $use_template = strpos($title_field_selection_table,'{') !== false; |
|
118 | + $field_name_hash = $this->_unique_field_name($title_field_selection_table); |
|
119 | + if($use_template) |
|
120 | + { |
|
121 | + $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); |
|
122 | + $field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')"; |
|
123 | + } |
|
124 | + else |
|
125 | + { |
|
126 | + $field .= "$selection_table.$title_field_selection_table"; |
|
127 | + } |
|
128 | + |
|
129 | + //Sorry Codeigniter but you cannot help me with the subquery! |
|
130 | + $select .= ", (SELECT GROUP_CONCAT(DISTINCT $field) FROM $selection_table " |
|
131 | + ."LEFT JOIN $relation_table ON $relation_table.$primary_key_alias_to_selection_table = $selection_table.$primary_key_selection_table " |
|
132 | + ."WHERE $relation_table.$primary_key_alias_to_this_table = `{$this->table_name}`.$this_table_primary_key GROUP BY $relation_table.$primary_key_alias_to_this_table) AS $field_name"; |
|
133 | + } |
|
134 | 134 | |
135 | - return $select; |
|
135 | + return $select; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | function order_by($order_by , $direction) |
139 | 139 | { |
140 | - $this->db->order_by( $order_by , $direction ); |
|
140 | + $this->db->order_by( $order_by , $direction ); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | function where($key, $value = NULL, $escape = TRUE) |
144 | 144 | { |
145 | - $this->db->where( $key, $value, $escape); |
|
145 | + $this->db->where( $key, $value, $escape); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | function or_where($key, $value = NULL, $escape = TRUE) |
149 | 149 | { |
150 | - $this->db->or_where( $key, $value, $escape); |
|
150 | + $this->db->or_where( $key, $value, $escape); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function having($key, $value = NULL, $escape = TRUE) |
154 | 154 | { |
155 | - $this->db->having( $key, $value, $escape); |
|
155 | + $this->db->having( $key, $value, $escape); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | function or_having($key, $value = NULL, $escape = TRUE) |
159 | 159 | { |
160 | - $this->db->or_having( $key, $value, $escape); |
|
160 | + $this->db->or_having( $key, $value, $escape); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function like($field, $match = '', $side = 'both') |
164 | 164 | { |
165 | - $this->db->like($field, $match, $side); |
|
165 | + $this->db->like($field, $match, $side); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function or_like($field, $match = '', $side = 'both') |
169 | 169 | { |
170 | - $this->db->or_like($field, $match, $side); |
|
170 | + $this->db->or_like($field, $match, $side); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function limit($value, $offset = '') |
174 | 174 | { |
175 | - $this->db->limit( $value , $offset ); |
|
175 | + $this->db->limit( $value , $offset ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | function get_total_results() |
179 | 179 | { |
180 | - //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. |
|
181 | - if(!empty($this->relation_n_n)) |
|
182 | - { |
|
183 | - $select = "{$this->table_name}.*"; |
|
184 | - $select = $this->relation_n_n_queries($select); |
|
180 | + //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. |
|
181 | + if(!empty($this->relation_n_n)) |
|
182 | + { |
|
183 | + $select = "{$this->table_name}.*"; |
|
184 | + $select = $this->relation_n_n_queries($select); |
|
185 | 185 | |
186 | - $this->db->select($select,false); |
|
187 | - } |
|
186 | + $this->db->select($select,false); |
|
187 | + } |
|
188 | 188 | |
189 | - return $this->db->get($this->table_name)->num_rows(); |
|
189 | + return $this->db->get($this->table_name)->num_rows(); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function set_basic_table($table_name = null) |
193 | 193 | { |
194 | - if( !($this->db->table_exists($table_name)) ) |
|
195 | - return false; |
|
194 | + if( !($this->db->table_exists($table_name)) ) |
|
195 | + return false; |
|
196 | 196 | |
197 | - $this->table_name = $table_name; |
|
197 | + $this->table_name = $table_name; |
|
198 | 198 | |
199 | - return true; |
|
199 | + return true; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | function get_edit_values($primary_key_value) |
203 | 203 | { |
204 | - $primary_key_field = $this->get_primary_key(); |
|
205 | - $this->db->where($primary_key_field,$primary_key_value); |
|
206 | - $result = $this->db->get($this->table_name)->row(); |
|
207 | - return $result; |
|
204 | + $primary_key_field = $this->get_primary_key(); |
|
205 | + $this->db->where($primary_key_field,$primary_key_value); |
|
206 | + $result = $this->db->get($this->table_name)->row(); |
|
207 | + return $result; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | function join_relation($field_name , $related_table , $related_field_title) |
211 | 211 | { |
212 | - $related_primary_key = $this->get_primary_key($related_table); |
|
212 | + $related_primary_key = $this->get_primary_key($related_table); |
|
213 | 213 | |
214 | - if($related_primary_key !== false) |
|
215 | - { |
|
216 | - $unique_name = $this->_unique_join_name($field_name); |
|
217 | - $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left'); |
|
214 | + if($related_primary_key !== false) |
|
215 | + { |
|
216 | + $unique_name = $this->_unique_join_name($field_name); |
|
217 | + $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left'); |
|
218 | 218 | |
219 | - $this->relation[$field_name] = array($field_name , $related_table , $related_field_title); |
|
219 | + $this->relation[$field_name] = array($field_name , $related_table , $related_field_title); |
|
220 | 220 | |
221 | - return true; |
|
222 | - } |
|
221 | + return true; |
|
222 | + } |
|
223 | 223 | |
224 | - return false; |
|
224 | + return false; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | function set_relation_n_n_field($field_info) |
228 | 228 | { |
229 | - $this->relation_n_n[$field_info->field_name] = $field_info; |
|
229 | + $this->relation_n_n[$field_info->field_name] = $field_info; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | protected function _unique_join_name($field_name) |
233 | 233 | { |
234 | - return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not with a number |
|
234 | + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not with a number |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | protected function _unique_field_name($field_name) |
238 | 238 | { |
239 | - return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number |
|
239 | + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | function get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null) |
243 | 243 | { |
244 | - $relation_array = array(); |
|
245 | - $field_name_hash = $this->_unique_field_name($field_name); |
|
244 | + $relation_array = array(); |
|
245 | + $field_name_hash = $this->_unique_field_name($field_name); |
|
246 | 246 | |
247 | - $related_primary_key = $this->get_primary_key($related_table); |
|
247 | + $related_primary_key = $this->get_primary_key($related_table); |
|
248 | 248 | |
249 | - $select = "$related_table.$related_primary_key, "; |
|
249 | + $select = "$related_table.$related_primary_key, "; |
|
250 | 250 | |
251 | - if(strstr($related_field_title,'{')) |
|
252 | - { |
|
253 | - $related_field_title = str_replace(" ", " ", $related_field_title); |
|
254 | - $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
255 | - } |
|
256 | - else |
|
257 | - { |
|
258 | - $select .= "$related_table.$related_field_title as $field_name_hash"; |
|
259 | - } |
|
251 | + if(strstr($related_field_title,'{')) |
|
252 | + { |
|
253 | + $related_field_title = str_replace(" ", " ", $related_field_title); |
|
254 | + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
255 | + } |
|
256 | + else |
|
257 | + { |
|
258 | + $select .= "$related_table.$related_field_title as $field_name_hash"; |
|
259 | + } |
|
260 | 260 | |
261 | - $this->db->select($select,false); |
|
262 | - if($where_clause !== null) |
|
263 | - $this->db->where($where_clause); |
|
261 | + $this->db->select($select,false); |
|
262 | + if($where_clause !== null) |
|
263 | + $this->db->where($where_clause); |
|
264 | 264 | |
265 | - if($where_clause !== null) |
|
266 | - $this->db->where($where_clause); |
|
265 | + if($where_clause !== null) |
|
266 | + $this->db->where($where_clause); |
|
267 | 267 | |
268 | - if($limit !== null) |
|
269 | - $this->db->limit($limit); |
|
268 | + if($limit !== null) |
|
269 | + $this->db->limit($limit); |
|
270 | 270 | |
271 | - if($search_like !== null) |
|
272 | - $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); |
|
271 | + if($search_like !== null) |
|
272 | + $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); |
|
273 | 273 | |
274 | - $order_by !== null |
|
275 | - ? $this->db->order_by($order_by) |
|
276 | - : $this->db->order_by($field_name_hash); |
|
274 | + $order_by !== null |
|
275 | + ? $this->db->order_by($order_by) |
|
276 | + : $this->db->order_by($field_name_hash); |
|
277 | 277 | |
278 | - $results = $this->db->get($related_table)->result(); |
|
278 | + $results = $this->db->get($related_table)->result(); |
|
279 | 279 | |
280 | - foreach($results as $row) |
|
281 | - { |
|
282 | - $relation_array[$row->$related_primary_key] = $row->$field_name_hash; |
|
283 | - } |
|
280 | + foreach($results as $row) |
|
281 | + { |
|
282 | + $relation_array[$row->$related_primary_key] = $row->$field_name_hash; |
|
283 | + } |
|
284 | 284 | |
285 | - return $relation_array; |
|
285 | + return $relation_array; |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | function get_ajax_relation_array($search, $field_name , $related_table , $related_field_title, $where_clause, $order_by) |
289 | 289 | { |
290 | - return $this->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, 10 , $search); |
|
290 | + return $this->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, 10 , $search); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | function get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause) |
294 | 294 | { |
295 | - if($where_clause !== null) |
|
296 | - $this->db->where($where_clause); |
|
295 | + if($where_clause !== null) |
|
296 | + $this->db->where($where_clause); |
|
297 | 297 | |
298 | - return $this->db->count_all_results($related_table); |
|
298 | + return $this->db->count_all_results($related_table); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | function get_relation_n_n_selection_array($primary_key_value, $field_info) |
302 | 302 | { |
303 | - $select = ""; |
|
304 | - $related_field_title = $field_info->title_field_selection_table; |
|
305 | - $use_template = strpos($related_field_title,'{') !== false;; |
|
306 | - $field_name_hash = $this->_unique_field_name($related_field_title); |
|
307 | - if($use_template) |
|
308 | - { |
|
309 | - $related_field_title = str_replace(" ", " ", $related_field_title); |
|
310 | - $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
311 | - } |
|
312 | - else |
|
313 | - { |
|
314 | - $select .= "$related_field_title as $field_name_hash"; |
|
315 | - } |
|
316 | - $this->db->select('*, '.$select,false); |
|
317 | - |
|
318 | - $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
|
319 | - |
|
320 | - if(empty($field_info->priority_field_relation_table)) |
|
321 | - { |
|
322 | - if(!$use_template){ |
|
323 | - $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
|
324 | - } |
|
325 | - } |
|
326 | - else |
|
327 | - { |
|
328 | - $this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}"); |
|
329 | - } |
|
330 | - $this->db->where($field_info->primary_key_alias_to_this_table, $primary_key_value); |
|
331 | - $this->db->join( |
|
332 | - $field_info->selection_table, |
|
333 | - "{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}" |
|
334 | - ); |
|
335 | - $results = $this->db->get($field_info->relation_table)->result(); |
|
336 | - |
|
337 | - $results_array = array(); |
|
338 | - foreach($results as $row) |
|
339 | - { |
|
340 | - $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash}; |
|
341 | - } |
|
342 | - |
|
343 | - return $results_array; |
|
303 | + $select = ""; |
|
304 | + $related_field_title = $field_info->title_field_selection_table; |
|
305 | + $use_template = strpos($related_field_title,'{') !== false;; |
|
306 | + $field_name_hash = $this->_unique_field_name($related_field_title); |
|
307 | + if($use_template) |
|
308 | + { |
|
309 | + $related_field_title = str_replace(" ", " ", $related_field_title); |
|
310 | + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
311 | + } |
|
312 | + else |
|
313 | + { |
|
314 | + $select .= "$related_field_title as $field_name_hash"; |
|
315 | + } |
|
316 | + $this->db->select('*, '.$select,false); |
|
317 | + |
|
318 | + $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
|
319 | + |
|
320 | + if(empty($field_info->priority_field_relation_table)) |
|
321 | + { |
|
322 | + if(!$use_template){ |
|
323 | + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
|
324 | + } |
|
325 | + } |
|
326 | + else |
|
327 | + { |
|
328 | + $this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}"); |
|
329 | + } |
|
330 | + $this->db->where($field_info->primary_key_alias_to_this_table, $primary_key_value); |
|
331 | + $this->db->join( |
|
332 | + $field_info->selection_table, |
|
333 | + "{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}" |
|
334 | + ); |
|
335 | + $results = $this->db->get($field_info->relation_table)->result(); |
|
336 | + |
|
337 | + $results_array = array(); |
|
338 | + foreach($results as $row) |
|
339 | + { |
|
340 | + $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash}; |
|
341 | + } |
|
342 | + |
|
343 | + return $results_array; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | function get_relation_n_n_unselected_array($field_info, $selected_values) |
347 | 347 | { |
348 | - $use_where_clause = !empty($field_info->where_clause); |
|
349 | - |
|
350 | - $select = ""; |
|
351 | - $related_field_title = $field_info->title_field_selection_table; |
|
352 | - $use_template = strpos($related_field_title,'{') !== false; |
|
353 | - $field_name_hash = $this->_unique_field_name($related_field_title); |
|
354 | - |
|
355 | - if($use_template) |
|
356 | - { |
|
357 | - $related_field_title = str_replace(" ", " ", $related_field_title); |
|
358 | - $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
359 | - } |
|
360 | - else |
|
361 | - { |
|
362 | - $select .= "$related_field_title as $field_name_hash"; |
|
363 | - } |
|
364 | - $this->db->select('*, '.$select,false); |
|
365 | - |
|
366 | - if($use_where_clause){ |
|
367 | - $this->db->where($field_info->where_clause); |
|
368 | - } |
|
369 | - |
|
370 | - $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
|
348 | + $use_where_clause = !empty($field_info->where_clause); |
|
349 | + |
|
350 | + $select = ""; |
|
351 | + $related_field_title = $field_info->title_field_selection_table; |
|
352 | + $use_template = strpos($related_field_title,'{') !== false; |
|
353 | + $field_name_hash = $this->_unique_field_name($related_field_title); |
|
354 | + |
|
355 | + if($use_template) |
|
356 | + { |
|
357 | + $related_field_title = str_replace(" ", " ", $related_field_title); |
|
358 | + $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
359 | + } |
|
360 | + else |
|
361 | + { |
|
362 | + $select .= "$related_field_title as $field_name_hash"; |
|
363 | + } |
|
364 | + $this->db->select('*, '.$select,false); |
|
365 | + |
|
366 | + if($use_where_clause){ |
|
367 | + $this->db->where($field_info->where_clause); |
|
368 | + } |
|
369 | + |
|
370 | + $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
|
371 | 371 | if(!$use_template) |
372 | - $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
|
372 | + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
|
373 | 373 | $results = $this->db->get($field_info->selection_table)->result(); |
374 | 374 | |
375 | 375 | $results_array = array(); |
@@ -384,199 +384,199 @@ discard block |
||
384 | 384 | |
385 | 385 | function db_relation_n_n_update($field_info, $post_data ,$main_primary_key) |
386 | 386 | { |
387 | - $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); |
|
388 | - if(!empty($post_data)) |
|
389 | - $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); |
|
390 | - $this->db->delete($field_info->relation_table); |
|
391 | - |
|
392 | - $counter = 0; |
|
393 | - if(!empty($post_data)) |
|
394 | - { |
|
395 | - foreach($post_data as $primary_key_value) |
|
396 | - { |
|
397 | - $where_array = array( |
|
398 | - $field_info->primary_key_alias_to_this_table => $main_primary_key, |
|
399 | - $field_info->primary_key_alias_to_selection_table => $primary_key_value, |
|
400 | - ); |
|
401 | - |
|
402 | - $this->db->where($where_array); |
|
403 | - $count = $this->db->from($field_info->relation_table)->count_all_results(); |
|
404 | - |
|
405 | - if($count == 0) |
|
406 | - { |
|
407 | - if(!empty($field_info->priority_field_relation_table)) |
|
408 | - $where_array[$field_info->priority_field_relation_table] = $counter; |
|
387 | + $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); |
|
388 | + if(!empty($post_data)) |
|
389 | + $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); |
|
390 | + $this->db->delete($field_info->relation_table); |
|
409 | 391 | |
410 | - $this->db->insert($field_info->relation_table, $where_array); |
|
411 | - |
|
412 | - }elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) |
|
413 | - { |
|
414 | - $this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array); |
|
415 | - } |
|
416 | - |
|
417 | - $counter++; |
|
418 | - } |
|
419 | - } |
|
392 | + $counter = 0; |
|
393 | + if(!empty($post_data)) |
|
394 | + { |
|
395 | + foreach($post_data as $primary_key_value) |
|
396 | + { |
|
397 | + $where_array = array( |
|
398 | + $field_info->primary_key_alias_to_this_table => $main_primary_key, |
|
399 | + $field_info->primary_key_alias_to_selection_table => $primary_key_value, |
|
400 | + ); |
|
401 | + |
|
402 | + $this->db->where($where_array); |
|
403 | + $count = $this->db->from($field_info->relation_table)->count_all_results(); |
|
404 | + |
|
405 | + if($count == 0) |
|
406 | + { |
|
407 | + if(!empty($field_info->priority_field_relation_table)) |
|
408 | + $where_array[$field_info->priority_field_relation_table] = $counter; |
|
409 | + |
|
410 | + $this->db->insert($field_info->relation_table, $where_array); |
|
411 | + |
|
412 | + }elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) |
|
413 | + { |
|
414 | + $this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array); |
|
415 | + } |
|
416 | + |
|
417 | + $counter++; |
|
418 | + } |
|
419 | + } |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | function db_relation_n_n_delete($field_info, $main_primary_key) |
423 | 423 | { |
424 | - $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); |
|
425 | - $this->db->delete($field_info->relation_table); |
|
424 | + $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); |
|
425 | + $this->db->delete($field_info->relation_table); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | function get_field_types_basic_table() |
429 | 429 | { |
430 | - $db_field_types = array(); |
|
431 | - foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) |
|
432 | - { |
|
433 | - $type = explode("(",$db_field_type->Type); |
|
434 | - $db_type = $type[0]; |
|
435 | - |
|
436 | - if(isset($type[1])) |
|
437 | - { |
|
438 | - if(substr($type[1],-1) == ')') |
|
439 | - { |
|
440 | - $length = substr($type[1],0,-1); |
|
441 | - } |
|
442 | - else |
|
443 | - { |
|
444 | - list($length) = explode(" ",$type[1]); |
|
445 | - $length = substr($length,0,-1); |
|
446 | - } |
|
447 | - } |
|
448 | - else |
|
449 | - { |
|
450 | - $length = ''; |
|
451 | - } |
|
452 | - $db_field_types[$db_field_type->Field]['db_max_length'] = $length; |
|
453 | - $db_field_types[$db_field_type->Field]['db_type'] = $db_type; |
|
454 | - $db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false; |
|
455 | - $db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra; |
|
456 | - } |
|
457 | - |
|
458 | - $results = $this->db->field_data($this->table_name); |
|
459 | - foreach($results as $num => $row) |
|
460 | - { |
|
461 | - $row = (array)$row; |
|
462 | - $results[$num] = (object)( array_merge($row, $db_field_types[$row['name']]) ); |
|
463 | - } |
|
464 | - |
|
465 | - return $results; |
|
430 | + $db_field_types = array(); |
|
431 | + foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) |
|
432 | + { |
|
433 | + $type = explode("(",$db_field_type->Type); |
|
434 | + $db_type = $type[0]; |
|
435 | + |
|
436 | + if(isset($type[1])) |
|
437 | + { |
|
438 | + if(substr($type[1],-1) == ')') |
|
439 | + { |
|
440 | + $length = substr($type[1],0,-1); |
|
441 | + } |
|
442 | + else |
|
443 | + { |
|
444 | + list($length) = explode(" ",$type[1]); |
|
445 | + $length = substr($length,0,-1); |
|
446 | + } |
|
447 | + } |
|
448 | + else |
|
449 | + { |
|
450 | + $length = ''; |
|
451 | + } |
|
452 | + $db_field_types[$db_field_type->Field]['db_max_length'] = $length; |
|
453 | + $db_field_types[$db_field_type->Field]['db_type'] = $db_type; |
|
454 | + $db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false; |
|
455 | + $db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra; |
|
456 | + } |
|
457 | + |
|
458 | + $results = $this->db->field_data($this->table_name); |
|
459 | + foreach($results as $num => $row) |
|
460 | + { |
|
461 | + $row = (array)$row; |
|
462 | + $results[$num] = (object)( array_merge($row, $db_field_types[$row['name']]) ); |
|
463 | + } |
|
464 | + |
|
465 | + return $results; |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | function get_field_types($table_name) |
469 | 469 | { |
470 | - $results = $this->db->field_data($table_name); |
|
470 | + $results = $this->db->field_data($table_name); |
|
471 | 471 | |
472 | - return $results; |
|
472 | + return $results; |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | function db_update($post_array, $primary_key_value) |
476 | 476 | { |
477 | - $primary_key_field = $this->get_primary_key(); |
|
478 | - return $this->db->update($this->table_name,$post_array, array( $primary_key_field => $primary_key_value)); |
|
477 | + $primary_key_field = $this->get_primary_key(); |
|
478 | + return $this->db->update($this->table_name,$post_array, array( $primary_key_field => $primary_key_value)); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | function db_insert($post_array) |
482 | 482 | { |
483 | - $insert = $this->db->insert($this->table_name,$post_array); |
|
484 | - if($insert) |
|
485 | - { |
|
486 | - return $this->db->insert_id(); |
|
487 | - } |
|
488 | - return false; |
|
483 | + $insert = $this->db->insert($this->table_name,$post_array); |
|
484 | + if($insert) |
|
485 | + { |
|
486 | + return $this->db->insert_id(); |
|
487 | + } |
|
488 | + return false; |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | function db_delete($primary_key_value) |
492 | 492 | { |
493 | - $primary_key_field = $this->get_primary_key(); |
|
493 | + $primary_key_field = $this->get_primary_key(); |
|
494 | 494 | |
495 | - if($primary_key_field === false) |
|
496 | - return false; |
|
495 | + if($primary_key_field === false) |
|
496 | + return false; |
|
497 | 497 | |
498 | - $this->db->limit(1); |
|
499 | - $this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value)); |
|
500 | - if( $this->db->affected_rows() != 1) |
|
501 | - return false; |
|
502 | - else |
|
503 | - return true; |
|
498 | + $this->db->limit(1); |
|
499 | + $this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value)); |
|
500 | + if( $this->db->affected_rows() != 1) |
|
501 | + return false; |
|
502 | + else |
|
503 | + return true; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | function db_file_delete($field_name, $filename) |
507 | 507 | { |
508 | - if( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) ) |
|
509 | - { |
|
510 | - return true; |
|
511 | - } |
|
512 | - else |
|
513 | - { |
|
514 | - return false; |
|
515 | - } |
|
508 | + if( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) ) |
|
509 | + { |
|
510 | + return true; |
|
511 | + } |
|
512 | + else |
|
513 | + { |
|
514 | + return false; |
|
515 | + } |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | function field_exists($field,$table_name = null) |
519 | 519 | { |
520 | - if(empty($table_name)) |
|
521 | - { |
|
522 | - $table_name = $this->table_name; |
|
523 | - } |
|
524 | - return $this->db->field_exists($field,$table_name); |
|
520 | + if(empty($table_name)) |
|
521 | + { |
|
522 | + $table_name = $this->table_name; |
|
523 | + } |
|
524 | + return $this->db->field_exists($field,$table_name); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | function get_primary_key($table_name = null) |
528 | 528 | { |
529 | - if($table_name == null) |
|
530 | - { |
|
531 | - if(isset($this->primary_keys[$this->table_name])) |
|
532 | - { |
|
533 | - return $this->primary_keys[$this->table_name]; |
|
534 | - } |
|
535 | - |
|
536 | - if(empty($this->primary_key)) |
|
537 | - { |
|
538 | - $fields = $this->get_field_types_basic_table(); |
|
539 | - |
|
540 | - foreach($fields as $field) |
|
541 | - { |
|
542 | - if($field->primary_key == 1) |
|
543 | - { |
|
544 | - return $field->name; |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - return false; |
|
549 | - } |
|
550 | - else |
|
551 | - { |
|
552 | - return $this->primary_key; |
|
553 | - } |
|
554 | - } |
|
555 | - else |
|
556 | - { |
|
557 | - if(isset($this->primary_keys[$table_name])) |
|
558 | - { |
|
559 | - return $this->primary_keys[$table_name]; |
|
560 | - } |
|
561 | - |
|
562 | - $fields = $this->get_field_types($table_name); |
|
563 | - |
|
564 | - foreach($fields as $field) |
|
565 | - { |
|
566 | - if($field->primary_key == 1) |
|
567 | - { |
|
568 | - return $field->name; |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - return false; |
|
573 | - } |
|
529 | + if($table_name == null) |
|
530 | + { |
|
531 | + if(isset($this->primary_keys[$this->table_name])) |
|
532 | + { |
|
533 | + return $this->primary_keys[$this->table_name]; |
|
534 | + } |
|
535 | + |
|
536 | + if(empty($this->primary_key)) |
|
537 | + { |
|
538 | + $fields = $this->get_field_types_basic_table(); |
|
539 | + |
|
540 | + foreach($fields as $field) |
|
541 | + { |
|
542 | + if($field->primary_key == 1) |
|
543 | + { |
|
544 | + return $field->name; |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + return false; |
|
549 | + } |
|
550 | + else |
|
551 | + { |
|
552 | + return $this->primary_key; |
|
553 | + } |
|
554 | + } |
|
555 | + else |
|
556 | + { |
|
557 | + if(isset($this->primary_keys[$table_name])) |
|
558 | + { |
|
559 | + return $this->primary_keys[$table_name]; |
|
560 | + } |
|
561 | + |
|
562 | + $fields = $this->get_field_types($table_name); |
|
563 | + |
|
564 | + foreach($fields as $field) |
|
565 | + { |
|
566 | + if($field->primary_key == 1) |
|
567 | + { |
|
568 | + return $field->name; |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + return false; |
|
573 | + } |
|
574 | 574 | |
575 | 575 | } |
576 | 576 | |
577 | 577 | function escape_str($value) |
578 | 578 | { |
579 | - return $this->db->escape_str($value); |
|
579 | + return $this->db->escape_str($value); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @version 1.5.6 |
28 | 28 | * @link http://www.grocerycrud.com/documentation |
29 | 29 | */ |
30 | -class Grocery_crud_model extends CI_Model { |
|
30 | +class Grocery_crud_model extends CI_Model { |
|
31 | 31 | |
32 | 32 | protected $primary_key = null; |
33 | 33 | protected $table_name = null; |
@@ -47,37 +47,37 @@ discard block |
||
47 | 47 | |
48 | 48 | function get_list() |
49 | 49 | { |
50 | - if($this->table_name === null) |
|
50 | + if ($this->table_name === null) |
|
51 | 51 | return false; |
52 | 52 | |
53 | 53 | $select = "`{$this->table_name}`.*"; |
54 | 54 | |
55 | 55 | //set_relation special queries |
56 | - if(!empty($this->relation)) |
|
56 | + if (!empty($this->relation)) |
|
57 | 57 | { |
58 | - foreach($this->relation as $relation) |
|
58 | + foreach ($this->relation as $relation) |
|
59 | 59 | { |
60 | - list($field_name , $related_table , $related_field_title) = $relation; |
|
60 | + list($field_name, $related_table, $related_field_title) = $relation; |
|
61 | 61 | $unique_join_name = $this->_unique_join_name($field_name); |
62 | 62 | $unique_field_name = $this->_unique_field_name($field_name); |
63 | 63 | |
64 | - if(strstr($related_field_title,'{')) |
|
64 | + if (strstr($related_field_title, '{')) |
|
65 | 65 | { |
66 | - $related_field_title = str_replace(" "," ",$related_field_title); |
|
67 | - $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; |
|
66 | + $related_field_title = str_replace(" ", " ", $related_field_title); |
|
67 | + $select .= ", CONCAT('".str_replace(array('{', '}'), array("',COALESCE({$unique_join_name}.", ", ''),'"), str_replace("'", "\\'", $related_field_title))."') as $unique_field_name"; |
|
68 | 68 | } |
69 | 69 | else |
70 | 70 | { |
71 | 71 | $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; |
72 | 72 | } |
73 | 73 | |
74 | - if($this->field_exists($related_field_title)) |
|
74 | + if ($this->field_exists($related_field_title)) |
|
75 | 75 | $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; |
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | 79 | //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. |
80 | - if(!empty($this->relation_n_n)) |
|
80 | + if (!empty($this->relation_n_n)) |
|
81 | 81 | { |
82 | 82 | $select = $this->relation_n_n_queries($select); |
83 | 83 | } |
@@ -106,20 +106,20 @@ discard block |
||
106 | 106 | protected function relation_n_n_queries($select) |
107 | 107 | { |
108 | 108 | $this_table_primary_key = $this->get_primary_key(); |
109 | - foreach($this->relation_n_n as $relation_n_n) |
|
109 | + foreach ($this->relation_n_n as $relation_n_n) |
|
110 | 110 | { |
111 | 111 | list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, |
112 | - $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n); |
|
112 | + $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array) $relation_n_n); |
|
113 | 113 | |
114 | 114 | $primary_key_selection_table = $this->get_primary_key($selection_table); |
115 | 115 | |
116 | 116 | $field = ""; |
117 | - $use_template = strpos($title_field_selection_table,'{') !== false; |
|
117 | + $use_template = strpos($title_field_selection_table, '{') !== false; |
|
118 | 118 | $field_name_hash = $this->_unique_field_name($title_field_selection_table); |
119 | - if($use_template) |
|
119 | + if ($use_template) |
|
120 | 120 | { |
121 | 121 | $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); |
122 | - $field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')"; |
|
122 | + $field .= "CONCAT('".str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $title_field_selection_table))."')"; |
|
123 | 123 | } |
124 | 124 | else |
125 | 125 | { |
@@ -135,29 +135,29 @@ discard block |
||
135 | 135 | return $select; |
136 | 136 | } |
137 | 137 | |
138 | - function order_by($order_by , $direction) |
|
138 | + function order_by($order_by, $direction) |
|
139 | 139 | { |
140 | - $this->db->order_by( $order_by , $direction ); |
|
140 | + $this->db->order_by($order_by, $direction); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | function where($key, $value = NULL, $escape = TRUE) |
144 | 144 | { |
145 | - $this->db->where( $key, $value, $escape); |
|
145 | + $this->db->where($key, $value, $escape); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | function or_where($key, $value = NULL, $escape = TRUE) |
149 | 149 | { |
150 | - $this->db->or_where( $key, $value, $escape); |
|
150 | + $this->db->or_where($key, $value, $escape); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function having($key, $value = NULL, $escape = TRUE) |
154 | 154 | { |
155 | - $this->db->having( $key, $value, $escape); |
|
155 | + $this->db->having($key, $value, $escape); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | function or_having($key, $value = NULL, $escape = TRUE) |
159 | 159 | { |
160 | - $this->db->or_having( $key, $value, $escape); |
|
160 | + $this->db->or_having($key, $value, $escape); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function like($field, $match = '', $side = 'both') |
@@ -172,18 +172,18 @@ discard block |
||
172 | 172 | |
173 | 173 | function limit($value, $offset = '') |
174 | 174 | { |
175 | - $this->db->limit( $value , $offset ); |
|
175 | + $this->db->limit($value, $offset); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | function get_total_results() |
179 | 179 | { |
180 | 180 | //set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables. |
181 | - if(!empty($this->relation_n_n)) |
|
181 | + if (!empty($this->relation_n_n)) |
|
182 | 182 | { |
183 | 183 | $select = "{$this->table_name}.*"; |
184 | 184 | $select = $this->relation_n_n_queries($select); |
185 | 185 | |
186 | - $this->db->select($select,false); |
|
186 | + $this->db->select($select, false); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | return $this->db->get($this->table_name)->num_rows(); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | function set_basic_table($table_name = null) |
193 | 193 | { |
194 | - if( !($this->db->table_exists($table_name)) ) |
|
194 | + if (!($this->db->table_exists($table_name))) |
|
195 | 195 | return false; |
196 | 196 | |
197 | 197 | $this->table_name = $table_name; |
@@ -202,21 +202,21 @@ discard block |
||
202 | 202 | function get_edit_values($primary_key_value) |
203 | 203 | { |
204 | 204 | $primary_key_field = $this->get_primary_key(); |
205 | - $this->db->where($primary_key_field,$primary_key_value); |
|
205 | + $this->db->where($primary_key_field, $primary_key_value); |
|
206 | 206 | $result = $this->db->get($this->table_name)->row(); |
207 | 207 | return $result; |
208 | 208 | } |
209 | 209 | |
210 | - function join_relation($field_name , $related_table , $related_field_title) |
|
210 | + function join_relation($field_name, $related_table, $related_field_title) |
|
211 | 211 | { |
212 | 212 | $related_primary_key = $this->get_primary_key($related_table); |
213 | 213 | |
214 | - if($related_primary_key !== false) |
|
214 | + if ($related_primary_key !== false) |
|
215 | 215 | { |
216 | 216 | $unique_name = $this->_unique_join_name($field_name); |
217 | - $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left'); |
|
217 | + $this->db->join($related_table.' as '.$unique_name, "$unique_name.$related_primary_key = {$this->table_name}.$field_name", 'left'); |
|
218 | 218 | |
219 | - $this->relation[$field_name] = array($field_name , $related_table , $related_field_title); |
|
219 | + $this->relation[$field_name] = array($field_name, $related_table, $related_field_title); |
|
220 | 220 | |
221 | 221 | return true; |
222 | 222 | } |
@@ -231,15 +231,15 @@ discard block |
||
231 | 231 | |
232 | 232 | protected function _unique_join_name($field_name) |
233 | 233 | { |
234 | - return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not with a number |
|
234 | + return 'j'.substr(md5($field_name), 0, 8); //This j is because is better for a string to begin with a letter and not with a number |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | protected function _unique_field_name($field_name) |
238 | 238 | { |
239 | - return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number |
|
239 | + return 's'.substr(md5($field_name), 0, 8); //This s is because is better for a string to begin with a letter and not with a number |
|
240 | 240 | } |
241 | 241 | |
242 | - function get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null) |
|
242 | + function get_relation_array($field_name, $related_table, $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null) |
|
243 | 243 | { |
244 | 244 | $relation_array = array(); |
245 | 245 | $field_name_hash = $this->_unique_field_name($field_name); |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | |
249 | 249 | $select = "$related_table.$related_primary_key, "; |
250 | 250 | |
251 | - if(strstr($related_field_title,'{')) |
|
251 | + if (strstr($related_field_title, '{')) |
|
252 | 252 | { |
253 | 253 | $related_field_title = str_replace(" ", " ", $related_field_title); |
254 | - $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
254 | + $select .= "CONCAT('".str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $related_field_title))."') as $field_name_hash"; |
|
255 | 255 | } |
256 | 256 | else |
257 | 257 | { |
258 | 258 | $select .= "$related_table.$related_field_title as $field_name_hash"; |
259 | 259 | } |
260 | 260 | |
261 | - $this->db->select($select,false); |
|
262 | - if($where_clause !== null) |
|
261 | + $this->db->select($select, false); |
|
262 | + if ($where_clause !== null) |
|
263 | 263 | $this->db->where($where_clause); |
264 | 264 | |
265 | - if($where_clause !== null) |
|
265 | + if ($where_clause !== null) |
|
266 | 266 | $this->db->where($where_clause); |
267 | 267 | |
268 | - if($limit !== null) |
|
268 | + if ($limit !== null) |
|
269 | 269 | $this->db->limit($limit); |
270 | 270 | |
271 | - if($search_like !== null) |
|
271 | + if ($search_like !== null) |
|
272 | 272 | $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); |
273 | 273 | |
274 | 274 | $order_by !== null |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | |
278 | 278 | $results = $this->db->get($related_table)->result(); |
279 | 279 | |
280 | - foreach($results as $row) |
|
280 | + foreach ($results as $row) |
|
281 | 281 | { |
282 | 282 | $relation_array[$row->$related_primary_key] = $row->$field_name_hash; |
283 | 283 | } |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | return $relation_array; |
286 | 286 | } |
287 | 287 | |
288 | - function get_ajax_relation_array($search, $field_name , $related_table , $related_field_title, $where_clause, $order_by) |
|
288 | + function get_ajax_relation_array($search, $field_name, $related_table, $related_field_title, $where_clause, $order_by) |
|
289 | 289 | { |
290 | - return $this->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, 10 , $search); |
|
290 | + return $this->get_relation_array($field_name, $related_table, $related_field_title, $where_clause, $order_by, 10, $search); |
|
291 | 291 | } |
292 | 292 | |
293 | - function get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause) |
|
293 | + function get_relation_total_rows($field_name, $related_table, $related_field_title, $where_clause) |
|
294 | 294 | { |
295 | - if($where_clause !== null) |
|
295 | + if ($where_clause !== null) |
|
296 | 296 | $this->db->where($where_clause); |
297 | 297 | |
298 | 298 | return $this->db->count_all_results($related_table); |
@@ -302,24 +302,24 @@ discard block |
||
302 | 302 | { |
303 | 303 | $select = ""; |
304 | 304 | $related_field_title = $field_info->title_field_selection_table; |
305 | - $use_template = strpos($related_field_title,'{') !== false;; |
|
305 | + $use_template = strpos($related_field_title, '{') !== false; ; |
|
306 | 306 | $field_name_hash = $this->_unique_field_name($related_field_title); |
307 | - if($use_template) |
|
307 | + if ($use_template) |
|
308 | 308 | { |
309 | 309 | $related_field_title = str_replace(" ", " ", $related_field_title); |
310 | - $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
310 | + $select .= "CONCAT('".str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $related_field_title))."') as $field_name_hash"; |
|
311 | 311 | } |
312 | 312 | else |
313 | 313 | { |
314 | 314 | $select .= "$related_field_title as $field_name_hash"; |
315 | 315 | } |
316 | - $this->db->select('*, '.$select,false); |
|
316 | + $this->db->select('*, '.$select, false); |
|
317 | 317 | |
318 | 318 | $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
319 | 319 | |
320 | - if(empty($field_info->priority_field_relation_table)) |
|
320 | + if (empty($field_info->priority_field_relation_table)) |
|
321 | 321 | { |
322 | - if(!$use_template){ |
|
322 | + if (!$use_template) { |
|
323 | 323 | $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
324 | 324 | } |
325 | 325 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | $results = $this->db->get($field_info->relation_table)->result(); |
336 | 336 | |
337 | 337 | $results_array = array(); |
338 | - foreach($results as $row) |
|
338 | + foreach ($results as $row) |
|
339 | 339 | { |
340 | 340 | $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash}; |
341 | 341 | } |
@@ -349,50 +349,50 @@ discard block |
||
349 | 349 | |
350 | 350 | $select = ""; |
351 | 351 | $related_field_title = $field_info->title_field_selection_table; |
352 | - $use_template = strpos($related_field_title,'{') !== false; |
|
352 | + $use_template = strpos($related_field_title, '{') !== false; |
|
353 | 353 | $field_name_hash = $this->_unique_field_name($related_field_title); |
354 | 354 | |
355 | - if($use_template) |
|
355 | + if ($use_template) |
|
356 | 356 | { |
357 | 357 | $related_field_title = str_replace(" ", " ", $related_field_title); |
358 | - $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
|
358 | + $select .= "CONCAT('".str_replace(array('{', '}'), array("',COALESCE(", ", ''),'"), str_replace("'", "\\'", $related_field_title))."') as $field_name_hash"; |
|
359 | 359 | } |
360 | 360 | else |
361 | 361 | { |
362 | 362 | $select .= "$related_field_title as $field_name_hash"; |
363 | 363 | } |
364 | - $this->db->select('*, '.$select,false); |
|
364 | + $this->db->select('*, '.$select, false); |
|
365 | 365 | |
366 | - if($use_where_clause){ |
|
366 | + if ($use_where_clause) { |
|
367 | 367 | $this->db->where($field_info->where_clause); |
368 | 368 | } |
369 | 369 | |
370 | 370 | $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
371 | - if(!$use_template) |
|
371 | + if (!$use_template) |
|
372 | 372 | $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
373 | 373 | $results = $this->db->get($field_info->selection_table)->result(); |
374 | 374 | |
375 | 375 | $results_array = array(); |
376 | - foreach($results as $row) |
|
376 | + foreach ($results as $row) |
|
377 | 377 | { |
378 | - if(!isset($selected_values[$row->$selection_primary_key])) |
|
378 | + if (!isset($selected_values[$row->$selection_primary_key])) |
|
379 | 379 | $results_array[$row->$selection_primary_key] = $row->{$field_name_hash}; |
380 | 380 | } |
381 | 381 | |
382 | 382 | return $results_array; |
383 | 383 | } |
384 | 384 | |
385 | - function db_relation_n_n_update($field_info, $post_data ,$main_primary_key) |
|
385 | + function db_relation_n_n_update($field_info, $post_data, $main_primary_key) |
|
386 | 386 | { |
387 | 387 | $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); |
388 | - if(!empty($post_data)) |
|
389 | - $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); |
|
388 | + if (!empty($post_data)) |
|
389 | + $this->db->where_not_in($field_info->primary_key_alias_to_selection_table, $post_data); |
|
390 | 390 | $this->db->delete($field_info->relation_table); |
391 | 391 | |
392 | 392 | $counter = 0; |
393 | - if(!empty($post_data)) |
|
393 | + if (!empty($post_data)) |
|
394 | 394 | { |
395 | - foreach($post_data as $primary_key_value) |
|
395 | + foreach ($post_data as $primary_key_value) |
|
396 | 396 | { |
397 | 397 | $where_array = array( |
398 | 398 | $field_info->primary_key_alias_to_this_table => $main_primary_key, |
@@ -402,16 +402,16 @@ discard block |
||
402 | 402 | $this->db->where($where_array); |
403 | 403 | $count = $this->db->from($field_info->relation_table)->count_all_results(); |
404 | 404 | |
405 | - if($count == 0) |
|
405 | + if ($count == 0) |
|
406 | 406 | { |
407 | - if(!empty($field_info->priority_field_relation_table)) |
|
407 | + if (!empty($field_info->priority_field_relation_table)) |
|
408 | 408 | $where_array[$field_info->priority_field_relation_table] = $counter; |
409 | 409 | |
410 | 410 | $this->db->insert($field_info->relation_table, $where_array); |
411 | 411 | |
412 | - }elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) |
|
412 | + }elseif ($count >= 1 && !empty($field_info->priority_field_relation_table)) |
|
413 | 413 | { |
414 | - $this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array); |
|
414 | + $this->db->update($field_info->relation_table, array($field_info->priority_field_relation_table => $counter), $where_array); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $counter++; |
@@ -428,21 +428,21 @@ discard block |
||
428 | 428 | function get_field_types_basic_table() |
429 | 429 | { |
430 | 430 | $db_field_types = array(); |
431 | - foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) |
|
431 | + foreach ($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type) |
|
432 | 432 | { |
433 | - $type = explode("(",$db_field_type->Type); |
|
433 | + $type = explode("(", $db_field_type->Type); |
|
434 | 434 | $db_type = $type[0]; |
435 | 435 | |
436 | - if(isset($type[1])) |
|
436 | + if (isset($type[1])) |
|
437 | 437 | { |
438 | - if(substr($type[1],-1) == ')') |
|
438 | + if (substr($type[1], -1) == ')') |
|
439 | 439 | { |
440 | - $length = substr($type[1],0,-1); |
|
440 | + $length = substr($type[1], 0, -1); |
|
441 | 441 | } |
442 | 442 | else |
443 | 443 | { |
444 | - list($length) = explode(" ",$type[1]); |
|
445 | - $length = substr($length,0,-1); |
|
444 | + list($length) = explode(" ", $type[1]); |
|
445 | + $length = substr($length, 0, -1); |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | else |
@@ -456,10 +456,10 @@ discard block |
||
456 | 456 | } |
457 | 457 | |
458 | 458 | $results = $this->db->field_data($this->table_name); |
459 | - foreach($results as $num => $row) |
|
459 | + foreach ($results as $num => $row) |
|
460 | 460 | { |
461 | - $row = (array)$row; |
|
462 | - $results[$num] = (object)( array_merge($row, $db_field_types[$row['name']]) ); |
|
461 | + $row = (array) $row; |
|
462 | + $results[$num] = (object) (array_merge($row, $db_field_types[$row['name']])); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | return $results; |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | function db_update($post_array, $primary_key_value) |
476 | 476 | { |
477 | 477 | $primary_key_field = $this->get_primary_key(); |
478 | - return $this->db->update($this->table_name,$post_array, array( $primary_key_field => $primary_key_value)); |
|
478 | + return $this->db->update($this->table_name, $post_array, array($primary_key_field => $primary_key_value)); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | function db_insert($post_array) |
482 | 482 | { |
483 | - $insert = $this->db->insert($this->table_name,$post_array); |
|
484 | - if($insert) |
|
483 | + $insert = $this->db->insert($this->table_name, $post_array); |
|
484 | + if ($insert) |
|
485 | 485 | { |
486 | 486 | return $this->db->insert_id(); |
487 | 487 | } |
@@ -492,12 +492,12 @@ discard block |
||
492 | 492 | { |
493 | 493 | $primary_key_field = $this->get_primary_key(); |
494 | 494 | |
495 | - if($primary_key_field === false) |
|
495 | + if ($primary_key_field === false) |
|
496 | 496 | return false; |
497 | 497 | |
498 | 498 | $this->db->limit(1); |
499 | - $this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value)); |
|
500 | - if( $this->db->affected_rows() != 1) |
|
499 | + $this->db->delete($this->table_name, array($primary_key_field => $primary_key_value)); |
|
500 | + if ($this->db->affected_rows() != 1) |
|
501 | 501 | return false; |
502 | 502 | else |
503 | 503 | return true; |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | |
506 | 506 | function db_file_delete($field_name, $filename) |
507 | 507 | { |
508 | - if( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) ) |
|
508 | + if ($this->db->update($this->table_name, array($field_name => ''), array($field_name => $filename))) |
|
509 | 509 | { |
510 | 510 | return true; |
511 | 511 | } |
@@ -515,31 +515,31 @@ discard block |
||
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
518 | - function field_exists($field,$table_name = null) |
|
518 | + function field_exists($field, $table_name = null) |
|
519 | 519 | { |
520 | - if(empty($table_name)) |
|
520 | + if (empty($table_name)) |
|
521 | 521 | { |
522 | 522 | $table_name = $this->table_name; |
523 | 523 | } |
524 | - return $this->db->field_exists($field,$table_name); |
|
524 | + return $this->db->field_exists($field, $table_name); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | function get_primary_key($table_name = null) |
528 | 528 | { |
529 | - if($table_name == null) |
|
529 | + if ($table_name == null) |
|
530 | 530 | { |
531 | - if(isset($this->primary_keys[$this->table_name])) |
|
531 | + if (isset($this->primary_keys[$this->table_name])) |
|
532 | 532 | { |
533 | 533 | return $this->primary_keys[$this->table_name]; |
534 | 534 | } |
535 | 535 | |
536 | - if(empty($this->primary_key)) |
|
536 | + if (empty($this->primary_key)) |
|
537 | 537 | { |
538 | 538 | $fields = $this->get_field_types_basic_table(); |
539 | 539 | |
540 | - foreach($fields as $field) |
|
540 | + foreach ($fields as $field) |
|
541 | 541 | { |
542 | - if($field->primary_key == 1) |
|
542 | + if ($field->primary_key == 1) |
|
543 | 543 | { |
544 | 544 | return $field->name; |
545 | 545 | } |
@@ -554,16 +554,16 @@ discard block |
||
554 | 554 | } |
555 | 555 | else |
556 | 556 | { |
557 | - if(isset($this->primary_keys[$table_name])) |
|
557 | + if (isset($this->primary_keys[$table_name])) |
|
558 | 558 | { |
559 | 559 | return $this->primary_keys[$table_name]; |
560 | 560 | } |
561 | 561 | |
562 | 562 | $fields = $this->get_field_types($table_name); |
563 | 563 | |
564 | - foreach($fields as $field) |
|
564 | + foreach ($fields as $field) |
|
565 | 565 | { |
566 | - if($field->primary_key == 1) |
|
566 | + if ($field->primary_key == 1) |
|
567 | 567 | { |
568 | 568 | return $field->name; |
569 | 569 | } |
@@ -47,8 +47,9 @@ discard block |
||
47 | 47 | |
48 | 48 | function get_list() |
49 | 49 | { |
50 | - if($this->table_name === null) |
|
51 | - return false; |
|
50 | + if($this->table_name === null) { |
|
51 | + return false; |
|
52 | + } |
|
52 | 53 | |
53 | 54 | $select = "`{$this->table_name}`.*"; |
54 | 55 | |
@@ -65,14 +66,14 @@ discard block |
||
65 | 66 | { |
66 | 67 | $related_field_title = str_replace(" "," ",$related_field_title); |
67 | 68 | $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; |
68 | - } |
|
69 | - else |
|
69 | + } else |
|
70 | 70 | { |
71 | 71 | $select .= ", $unique_join_name.$related_field_title AS $unique_field_name"; |
72 | 72 | } |
73 | 73 | |
74 | - if($this->field_exists($related_field_title)) |
|
75 | - $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; |
|
74 | + if($this->field_exists($related_field_title)) { |
|
75 | + $select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'"; |
|
76 | + } |
|
76 | 77 | } |
77 | 78 | } |
78 | 79 | |
@@ -120,8 +121,7 @@ discard block |
||
120 | 121 | { |
121 | 122 | $title_field_selection_table = str_replace(" ", " ", $title_field_selection_table); |
122 | 123 | $field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')"; |
123 | - } |
|
124 | - else |
|
124 | + } else |
|
125 | 125 | { |
126 | 126 | $field .= "$selection_table.$title_field_selection_table"; |
127 | 127 | } |
@@ -191,8 +191,9 @@ discard block |
||
191 | 191 | |
192 | 192 | function set_basic_table($table_name = null) |
193 | 193 | { |
194 | - if( !($this->db->table_exists($table_name)) ) |
|
195 | - return false; |
|
194 | + if( !($this->db->table_exists($table_name)) ) { |
|
195 | + return false; |
|
196 | + } |
|
196 | 197 | |
197 | 198 | $this->table_name = $table_name; |
198 | 199 | |
@@ -252,24 +253,27 @@ discard block |
||
252 | 253 | { |
253 | 254 | $related_field_title = str_replace(" ", " ", $related_field_title); |
254 | 255 | $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
255 | - } |
|
256 | - else |
|
256 | + } else |
|
257 | 257 | { |
258 | 258 | $select .= "$related_table.$related_field_title as $field_name_hash"; |
259 | 259 | } |
260 | 260 | |
261 | 261 | $this->db->select($select,false); |
262 | - if($where_clause !== null) |
|
263 | - $this->db->where($where_clause); |
|
262 | + if($where_clause !== null) { |
|
263 | + $this->db->where($where_clause); |
|
264 | + } |
|
264 | 265 | |
265 | - if($where_clause !== null) |
|
266 | - $this->db->where($where_clause); |
|
266 | + if($where_clause !== null) { |
|
267 | + $this->db->where($where_clause); |
|
268 | + } |
|
267 | 269 | |
268 | - if($limit !== null) |
|
269 | - $this->db->limit($limit); |
|
270 | + if($limit !== null) { |
|
271 | + $this->db->limit($limit); |
|
272 | + } |
|
270 | 273 | |
271 | - if($search_like !== null) |
|
272 | - $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); |
|
274 | + if($search_like !== null) { |
|
275 | + $this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'"); |
|
276 | + } |
|
273 | 277 | |
274 | 278 | $order_by !== null |
275 | 279 | ? $this->db->order_by($order_by) |
@@ -292,8 +296,9 @@ discard block |
||
292 | 296 | |
293 | 297 | function get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause) |
294 | 298 | { |
295 | - if($where_clause !== null) |
|
296 | - $this->db->where($where_clause); |
|
299 | + if($where_clause !== null) { |
|
300 | + $this->db->where($where_clause); |
|
301 | + } |
|
297 | 302 | |
298 | 303 | return $this->db->count_all_results($related_table); |
299 | 304 | } |
@@ -308,8 +313,7 @@ discard block |
||
308 | 313 | { |
309 | 314 | $related_field_title = str_replace(" ", " ", $related_field_title); |
310 | 315 | $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
311 | - } |
|
312 | - else |
|
316 | + } else |
|
313 | 317 | { |
314 | 318 | $select .= "$related_field_title as $field_name_hash"; |
315 | 319 | } |
@@ -322,8 +326,7 @@ discard block |
||
322 | 326 | if(!$use_template){ |
323 | 327 | $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
324 | 328 | } |
325 | - } |
|
326 | - else |
|
329 | + } else |
|
327 | 330 | { |
328 | 331 | $this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}"); |
329 | 332 | } |
@@ -356,8 +359,7 @@ discard block |
||
356 | 359 | { |
357 | 360 | $related_field_title = str_replace(" ", " ", $related_field_title); |
358 | 361 | $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; |
359 | - } |
|
360 | - else |
|
362 | + } else |
|
361 | 363 | { |
362 | 364 | $select .= "$related_field_title as $field_name_hash"; |
363 | 365 | } |
@@ -368,15 +370,17 @@ discard block |
||
368 | 370 | } |
369 | 371 | |
370 | 372 | $selection_primary_key = $this->get_primary_key($field_info->selection_table); |
371 | - if(!$use_template) |
|
372 | - $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
|
373 | + if(!$use_template) { |
|
374 | + $this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}"); |
|
375 | + } |
|
373 | 376 | $results = $this->db->get($field_info->selection_table)->result(); |
374 | 377 | |
375 | 378 | $results_array = array(); |
376 | 379 | foreach($results as $row) |
377 | 380 | { |
378 | - if(!isset($selected_values[$row->$selection_primary_key])) |
|
379 | - $results_array[$row->$selection_primary_key] = $row->{$field_name_hash}; |
|
381 | + if(!isset($selected_values[$row->$selection_primary_key])) { |
|
382 | + $results_array[$row->$selection_primary_key] = $row->{$field_name_hash}; |
|
383 | + } |
|
380 | 384 | } |
381 | 385 | |
382 | 386 | return $results_array; |
@@ -385,8 +389,9 @@ discard block |
||
385 | 389 | function db_relation_n_n_update($field_info, $post_data ,$main_primary_key) |
386 | 390 | { |
387 | 391 | $this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key); |
388 | - if(!empty($post_data)) |
|
389 | - $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); |
|
392 | + if(!empty($post_data)) { |
|
393 | + $this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data); |
|
394 | + } |
|
390 | 395 | $this->db->delete($field_info->relation_table); |
391 | 396 | |
392 | 397 | $counter = 0; |
@@ -404,12 +409,13 @@ discard block |
||
404 | 409 | |
405 | 410 | if($count == 0) |
406 | 411 | { |
407 | - if(!empty($field_info->priority_field_relation_table)) |
|
408 | - $where_array[$field_info->priority_field_relation_table] = $counter; |
|
412 | + if(!empty($field_info->priority_field_relation_table)) { |
|
413 | + $where_array[$field_info->priority_field_relation_table] = $counter; |
|
414 | + } |
|
409 | 415 | |
410 | 416 | $this->db->insert($field_info->relation_table, $where_array); |
411 | 417 | |
412 | - }elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) |
|
418 | + } elseif($count >= 1 && !empty($field_info->priority_field_relation_table)) |
|
413 | 419 | { |
414 | 420 | $this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array); |
415 | 421 | } |
@@ -438,14 +444,12 @@ discard block |
||
438 | 444 | if(substr($type[1],-1) == ')') |
439 | 445 | { |
440 | 446 | $length = substr($type[1],0,-1); |
441 | - } |
|
442 | - else |
|
447 | + } else |
|
443 | 448 | { |
444 | 449 | list($length) = explode(" ",$type[1]); |
445 | 450 | $length = substr($length,0,-1); |
446 | 451 | } |
447 | - } |
|
448 | - else |
|
452 | + } else |
|
449 | 453 | { |
450 | 454 | $length = ''; |
451 | 455 | } |
@@ -492,15 +496,17 @@ discard block |
||
492 | 496 | { |
493 | 497 | $primary_key_field = $this->get_primary_key(); |
494 | 498 | |
495 | - if($primary_key_field === false) |
|
496 | - return false; |
|
499 | + if($primary_key_field === false) { |
|
500 | + return false; |
|
501 | + } |
|
497 | 502 | |
498 | 503 | $this->db->limit(1); |
499 | 504 | $this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value)); |
500 | - if( $this->db->affected_rows() != 1) |
|
501 | - return false; |
|
502 | - else |
|
503 | - return true; |
|
505 | + if( $this->db->affected_rows() != 1) { |
|
506 | + return false; |
|
507 | + } else { |
|
508 | + return true; |
|
509 | + } |
|
504 | 510 | } |
505 | 511 | |
506 | 512 | function db_file_delete($field_name, $filename) |
@@ -508,8 +514,7 @@ discard block |
||
508 | 514 | if( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) ) |
509 | 515 | { |
510 | 516 | return true; |
511 | - } |
|
512 | - else |
|
517 | + } else |
|
513 | 518 | { |
514 | 519 | return false; |
515 | 520 | } |
@@ -546,13 +551,11 @@ discard block |
||
546 | 551 | } |
547 | 552 | |
548 | 553 | return false; |
549 | - } |
|
550 | - else |
|
554 | + } else |
|
551 | 555 | { |
552 | 556 | return $this->primary_key; |
553 | 557 | } |
554 | - } |
|
555 | - else |
|
558 | + } else |
|
556 | 559 | { |
557 | 560 | if(isset($this->primary_keys[$table_name])) |
558 | 561 | { |
@@ -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; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | $ldap = ldap_connect($this->config->item('ldapserver')); |
15 | 15 | |
16 | - $ldaprdn = $this->config->item('ldapshortdomain') . $username; |
|
16 | + $ldaprdn = $this->config->item('ldapshortdomain').$username; |
|
17 | 17 | |
18 | 18 | ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); |
19 | 19 | ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $two_hour_login = strtotime("-2 hours"); |
136 | 136 | $current_timestamp = date("Y-m-d H:i:s", time()); |
137 | 137 | $login_count = 1; |
138 | - $browser = $this->agent->browser() . ' ' . $this->agent->version(); |
|
138 | + $browser = $this->agent->browser().' '.$this->agent->version(); |
|
139 | 139 | |
140 | 140 | if ($query->num_rows() > 0) { |
141 | 141 | |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | |
236 | 236 | $iv = mcrypt_create_iv(IV_SIZE, MCRYPT_DEV_URANDOM); |
237 | 237 | $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $encrypt_item, MCRYPT_MODE_CBC, $iv); |
238 | - $combo = $iv . $crypt; |
|
239 | - $output = base64_encode($iv . $crypt); |
|
238 | + $combo = $iv.$crypt; |
|
239 | + $output = base64_encode($iv.$crypt); |
|
240 | 240 | |
241 | 241 | return $output; |
242 | 242 | } |
@@ -73,8 +73,9 @@ |
||
73 | 73 | ldap_sort($ldap, $result, "sn"); |
74 | 74 | $info = ldap_get_entries($ldap, $result); |
75 | 75 | for ($i = 0; $i < $info["count"]; $i++) { |
76 | - if ($info['count'] > 1) |
|
77 | - break; |
|
76 | + if ($info['count'] > 1) { |
|
77 | + break; |
|
78 | + } |
|
78 | 79 | |
79 | 80 | //clean |
80 | 81 | $groups = $info[$i]["memberof"]; |
@@ -12,7 +12,7 @@ |
||
12 | 12 | 'last_name' => $this->input->post('last_name'), |
13 | 13 | 'email' => $this->input->post('email'), |
14 | 14 | 'postcode' => $this->input->post('postcode'), |
15 | - 'date_birth' => $this->input->post('dob_d') .'/'. $this->input->post('dob_m') .'/'. $this->input->post('dob_y'), |
|
15 | + 'date_birth' => $this->input->post('dob_d').'/'.$this->input->post('dob_m').'/'.$this->input->post('dob_y'), |
|
16 | 16 | 'current_school' => $this->input->post('current'), |
17 | 17 | 'current_other' => $this->input->post('current_other'), |
18 | 18 | 'subject_interest' => implode(', ', $this->input->post('subject')), |