?
Current Path : /home1/savoy/public_html/savoyglobal.net/chess2015open/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/chess2015open/application/models/mastermodel.php |
<?php class Mastermodel extends CI_Model { function __construct() { parent::__construct(); } function htmlmail($subject, $content) { $this->mail->send($content, $subject, 'info@savoyglobal.net', 'Savoy Chess Tournament 2015', 'savoy1975', 'smtp.gmail.com', 1); } function gettabledata($table, $sortfield = "", $sort_order = "asc", $primary_field = '') { $data = array(); if (!empty($sortfield)) { $this->db->order_by($sortfield, $sort_order); } if (!empty($primary_field)) { $this->db->join('master', "master.master_id=$table.$primary_field"); } $Q = $this->db->get($table); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function getdatas($table, $sortfield = "", $sorttype = "asc", $pagenum = "") { $data = array(); $count = $this->db->count_all_results($table); $arr = $this->fpaginate->paginate($pagenum, $count); $data['startpage'] = $arr[0]; $data['endpage'] = $arr[1]; $start = $arr[2]; $perpage = $arr[3]; $data['count'] = $count; if (!empty($pagenum)) $this->db->limit($perpage, $start); if (!empty($sortfield)) { $this->db->order_by($sortfield, $sorttype); } $data['results'] = $this->db->get($table); return $data; } function get_data($table, $id, $field, $sortfield = "", $sorttype = "asc", $pagenum = "") { $data = array(); $this->db->where($field, $id); $this->db->get($table); $count = $this->db->count_all_results(); $arr = $this->fpaginate->paginate($pagenum, $count); $data['startpage'] = $arr[0]; $data['endpage'] = $arr[1]; $start = $arr[2]; $perpage = $arr[3]; $data['count'] = $count; $this->db->where($field, $id); if (!empty($sortfield)) { $this->db->order_by($sortfield, $sorttype); } $data['results'] = $this->db->get($table); return $data; } function get_post_values() { $data = array(); foreach ($_POST as $key => $value) { if ($key != "submit") { $data[$key] = $this->input->post($key); } } return $data; } function get_data_srow($table, $id, $field, $sortfield = "") { $data = array(); $this->db->where($field, $id); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'asc'); } $Q = $this->db->get($table); $row = $Q->row(); return $row; } function deletedata($table, $field, $id) { $this->db->where($field, $id); $res = $this->db->delete($table); return $res; } function get_num_rows($table, $field, $value) { $this->db->where($field, $value); $Q = $this->db->get($table); return $Q->num_rows(); } function insert_contact($postdata) { $SpamCheck = "Y"; // Y or N $SpamReplaceText = "*content removed*"; $data = array(); $this->db->trans_begin(); $name = $postdata['q1_fullName1']['first'] . " " . $postdata['q1_fullName1']['last']; $contact_no = $postdata['q3_phoneNumber3']['area'] . $postdata['q3_phoneNumber3']['phone']; $email = $postdata['q4_email4']; $comments = $postdata['q6_comments']; $tbl1Values = array('name' => $name, 'contact_no' => $contact_no, 'email' => $email, 'reference' => $comments, 'datetime' => date("Y-m-d H:i:s")); $this->db->insert('contact', $tbl1Values); $content = '<table> <tr><td colspan="2">Savoyglobal.net/chess2015open contact form was submitted with the following information:</td></tr> <tr><td>Name :</td><td>' . $name . '</td></tr> <tr><td>Contact No:</td><td>' . $contact_no . '</td></tr> <tr><td>Email:</td><td>' . $email . '</td></tr> <tr><td>Comments:</td><td>' . $comments . '</td></tr> </table>'; if ($SpamCheck == "Y") { // Check for Website URL's in the form input boxes as if we block website URLs from the form, // then this will stop the spammers wastignt ime sending emails if (preg_match("/http/i", "$name")) { echo "$SpamErrorMessage"; exit(); } if (preg_match("/http/i", "$contact_no")) { echo "$SpamErrorMessage"; exit(); } if (preg_match("/http/i", "$email")) { echo "$SpamErrorMessage"; exit(); } if (preg_match("/http/i", "$comments")) { echo "$SpamErrorMessage"; exit(); } // Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer $pattern = '/(;|\||`|>|<|&|^|"|' . "\n|\r|'" . '|{|}|[|]|\)|\()/i'; // build the pattern match string $name = preg_replace($pattern, "", $name); $contact_no = preg_replace($pattern, "", $contact_no); $email = preg_replace($pattern, "", $email); $reference = preg_replace($pattern, "", $comments); // Check for the injected headers from the spammer attempt // This will replace the injection attempt text with the string you have set in the above config section $find = array("/bcc\:/i", "/Content\-Type\:/i", "/cc\:/i", "/to\:/i"); $name = preg_replace($find, "$SpamReplaceText", $name); $email = preg_replace($find, "$SpamReplaceText", $email); $contact_no = preg_replace($find, "$SpamReplaceText", $contact_no); $reference = preg_replace($find, "$SpamReplaceText", $comments); // Check to see if the fields contain any content we want to ban if (stristr($name, $SpamReplaceText) !== FALSE) { echo "$SpamErrorMessage"; exit(); } if (stristr($email, $SpamReplaceText) !== FALSE) { echo "$SpamErrorMessage"; exit(); } if (stristr($contact_no, $SpamReplaceText) !== FALSE) { echo "$SpamErrorMessage"; exit(); } if (stristr($comments, $SpamReplaceText) !== FALSE) { echo "$SpamErrorMessage"; exit(); } } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return 0; } else { $this->mastermodel->htmlmail("Chess Website Contact Form Filled", $content); $this->db->trans_commit(); $data['res'] = 1; return $data; } } function insert_registration($postdata) { $data = array(); $this->db->trans_begin(); $name = $postdata['fullname']; $br = "<br/>"; $content = "Dear $name ,$br Thank You for Registering for the Savoy Global Open Chess Tournament 2015 (under 14), on February 21, 2015 (Saturday) at Savoy Education Center. Your registration has been sent for approval to the Organisers.$br You will hear from us on approval of the registration.$br$br Regards$br Team Savoy."; $subject = "SAVOY GLOBAL OPEN CHESS TOURNAMENT 2015 (UNDER 14)"; $tblvalues = array( 'name' => $name, 'gender' => $postdata['gender'], 'school_name' => $postdata['school_name'], 'date_of_birth' => $this->mastermodel->convertdateformat($postdata['date_of_birth']), 'proof' => $postdata['proof'], 'father_name' => $postdata['father_name'], 'father_mobile' => $postdata['father_mobile'], 'father_email' => $postdata['father_email'], 'mother_name' => $postdata['mother_name'], 'mother_mobile' => $postdata['mother_mobile'], 'mother_email' => $postdata['mother_email'], 'status' => $postdata['status'], 'datetime' => date("Y-m-d H:i:s") ); $this->db->insert('registration', $tblvalues); $this->mail->send($content, $subject, 'info@savoyglobal.net', 'Savoy Global Open Chess Tournament', 'savoy987', 'smtp.gmail.com', 0, $postdata['father_email']); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function get_pending_student() { $this->db->select('*') ->from('registration') ->where('status', "Pending"); $this->db->order_by('registration_id', 'asc'); $result = $this->db->get(); return $result->result_array(); } function convertdateformat($date) { if ($date == "" || $date == "00-00-0000") { return ""; } else { $time = strtotime($date); return date('Y-m-d', $time); } } function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } function get_data_table($table, $id, $field, $sortfield = "") { $data = array(); $this->db->where($field, $id); if (!empty($sortfield)) { $this->db->order_by($sortfield, 'asc'); } $Q = $this->db->get($table); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_master_code($table, $prefix_code, $field) { $Q = $this->db->get($table); $num = $Q->num_rows(); $num = $this->mastermodel->number_rows($table, '', '', '', '', '', ''); $num+=100; do { $master_code = $prefix_code . str_pad($num, "0", STR_PAD_LEFT); $num_rows_code = $this->mastermodel->number_rows($table, $field, $master_code); $num++; } while ($num_rows_code != 0); return $master_code; } function number_rows($tabname, $field1 = '', $value1 = '', $field2 = '', $value2 = '', $field3 = '', $value3 = '') { $this->db->from($tabname); if ($field1 != '') $this->db->where($field1, $value1); if ($field2 != '') $this->db->where($field2, $value2); if ($field3 != '') $this->db->where($field3, $value3); $num = $this->db->count_all_results(); return $num; } function convertdatenormalformat($date) { if ($date == "" || $date == "0000-00-00") { return ""; } else { $time = strtotime($date); return date('d-m-Y', $time); } } function get_approved_student_count($student_type) { $data = array(); $this->db->select('*'); $this->db->from('registration'); $this->db->where('status', 'Approved'); if ($student_type == "J") $this->db->where('floor(datediff(curdate(),date_of_birth) / 365) < 10', NULL, FALSE); else $this->db->where('floor(datediff(curdate(),date_of_birth) / 365) > 10', NULL, FALSE); $result = $this->db->get(); return count($result->result_array()); } } ?>