Advertisement
Maksa988

Untitled

Mar 10th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.75 KB | None | 0 0
  1. <?php
  2. /*
  3. * MyUCP
  4. */
  5.  
  6. class UserModel extends Model {
  7.    
  8.     protected $table = "site_users";
  9.     protected $lang = null;
  10.  
  11.     public function getUser($value, $row = "user_id") {
  12.         return $this->db->getRow("SELECT * FROM `{$this->table}` WHERE `{$row}` = '{$value}'");
  13.     }
  14.  
  15.     public function sendMailTo($userid) {
  16.         $this->langDetect();
  17.         $user = $this->getUser($userid);
  18.         $code = md5($userid."maksa988");
  19.         $body = view("email/verify", ["userid" => $userid, "code" => $code]);
  20.         $this->smtpmail($user['user_email'], $this->lang->user['active_account'], $body);
  21.     }
  22.  
  23.     public function sendRestore($email, $password) {
  24.         $body = view("email/restore", ["newpass" => $password]);
  25.         $this->smtpmail($email, $this->lang->user['restore_pass'], $body);
  26.     }
  27.  
  28.     public function getChars($userid, $lim = false) {
  29.         $dbs = new DBServer;
  30.         $userid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
  31.  
  32.         if($lim){
  33.             if($dbs->getOne("SELECT COUNT(*) FROM `basetab_sg` WHERE `AccountID` = '$userid'") >= 5){
  34.                 $limit = "LIMIT 5";
  35.                 $count = true;
  36.             }
  37.            
  38.             $chars = $dbs->getAll("SELECT `RoleID`, `Name`, `Profession`, `Sex`, `Money`, `Level`, `Give`,`SciencePoint`,`Liveness`,`Military`,`ScienceLevel`,`Point` FROM `basetab_sg` WHERE `AccountID` = '$userid' ".$limit);
  39.             $dbs->closeConnect();
  40.             return ["chars" => $chars, "count" => $count];
  41.         }
  42.         $result = $dbs->getAll("SELECT `RoleID`, `Name`, `Profession`, `Sex`, `Money`, `Level`, `Give`,`SciencePoint`,`Liveness`,`Military`,`ScienceLevel`,`Point` FROM `basetab_sg` WHERE `AccountID` = '$userid'");
  43.         $dbs->closeConnect();
  44.         return $result;
  45.     }
  46.  
  47.  
  48.     public function getReferalsCount($uid) {
  49.         // dd($uid);
  50.         $dbs = new DBServer;
  51.  
  52.         $users = $this->db->getAll("SELECT `user_id` FROM `{$this->table}` WHERE `user_referal` = '{$uid}'");
  53.        
  54.         foreach($users as $key) {
  55.             $userid[] = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '{$key['user_id']}'");
  56.         }
  57.        
  58.         $count = 0;
  59.         foreach($userid as $key) {
  60.             if($key) {
  61.                 if($dbs->getOne("SELECT COUNT(*) as 'count' FROM `basetab_sg` WHERE `AccountID` = '$key' AND `Level` >= 60")){
  62.                     $count++;
  63.                 }
  64.             }
  65.         }
  66.         $dbs->closeConnect();
  67.         return $count;
  68.     }
  69.  
  70.     public function createEvent($eventDesc,$userID)
  71.     {
  72.         return $this->db->query("INSERT INTO `site_events` (`event_dec`, `user_id`, `event_date`) VALUES ('{$eventDesc}', '{$userID}', NOW());");
  73.     }
  74.     public function getCharsCount($userid, $lim = false) {
  75.          $dbs = new DBServer;
  76.         $userid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
  77.  
  78.         if($lim){
  79.             if($dbs->getOne("SELECT COUNT(*) FROM `basetab_sg` WHERE `AccountID` = '$userid'") >= 5){
  80.                 $limit = "LIMIT 5";
  81.                 $count = true;
  82.             }
  83.  
  84.             $chars = $dbs->getAll("SELECT `Name`, `Profession`, `Sex`, `Money`, `Level` FROM `basetab_sg` WHERE `AccountID` = '$userid' ".$limit);
  85.  
  86.             $dbs->closeConnect();
  87.             return ["chars" => $chars, "count" => $count];
  88.         }
  89.         $result = $dbs->getOne("SELECT COUNT(*) FROM `basetab_sg` WHERE `AccountID` = '$userid'");
  90.         $dbs->closeConnect();
  91.         return $result;
  92.     }
  93.  
  94.     public function getPayments()
  95.     {
  96.         $sql = "SELECT SUM(sum) FROM `unitpay_payments` WHERE date_format(dateComplete, '%Y%m') = date_format(now(), '%Y%m') AND status = 1";
  97.         return $this->db->getOne($sql);
  98.     }
  99.  
  100.     public function getGold($id) {
  101.         $dbs = new DBServer;
  102.         $userid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$id'");
  103.  
  104.         $result = $dbs->getOne("SELECT `Gold` FROM `goldtab_sg` WHERE `AccountID` = '{$userid}'");
  105.         $dbs->closeConnect();
  106.         return $result;
  107.     }
  108.  
  109.     function smtpmail($mail_to, $subject, $message) {
  110.         require './mailer/PHPMailerAutoload.php';
  111.  
  112.         $mail = new PHPMailer;                          // Enable verbose debug output
  113.         $mail->CharSet = 'utf-8';
  114.         $mail->isSMTP();
  115.         $mail->Host = $this->config->mail['smtp']['smtp_host'];
  116.         $mail->SMTPAuth = true;
  117.         $mail->Username = $this->config->mail['smtp']['smtp_username'];
  118.         $mail->Password = $this->config->mail['smtp']['smtp_password'];
  119.         $mail->SMTPSecure = 'ssl';
  120.         $mail->Port = $this->config->mail['smtp']['smtp_port'];
  121.  
  122.         $mail->setFrom($this->config->mail['smtp']['smtp_from']);
  123.         $mail->addAddress($mail_to);               // Name is optional
  124.         $mail->isHTML(true);                                  // Set email format to HTML
  125.  
  126.         $mail->Subject = $subject;
  127.         $mail->Body    = $message;
  128.  
  129.         if(!$mail->send()) {
  130.             return 'Mailer Error: ' . $mail->ErrorInfo;
  131.         }
  132.         return true;
  133.     }
  134.  
  135.     public function getDeps($status = '0') {
  136.         if($status) {
  137.             return $this->db->getAll("SELECT * FROM `site_groups` WHERE `group_status` = {$status}");
  138.         }
  139.         return $this->db->getAll("SELECT * FROM `site_groups`");
  140.     }
  141.  
  142.     public function getDep($id) {
  143.         return $this->db->getRow("SELECT * FROM `site_groups` WHERE `group_id` = '{$id}'");
  144.     }
  145.  
  146.     public function editDep($name, $status, $id) {
  147.         $this->table("site_groups");
  148.         return $this->set(["group_name" => $name, "group_status" => $status])->where("group_id", "=", $id)->update();
  149.     }
  150.  
  151.     public function removeDep($id) {
  152.         $this->table("site_groups");
  153.         return $this->where("group_id", "=", $id)->delete();
  154.     }
  155.  
  156.     public function newDep($name) {
  157.         $this->table("site_groups");
  158.         return $this->create(['group_name' => $name, 'group_status' => 1]);
  159.     }
  160.  
  161.     public function sendTelegramMSG($text) {
  162.         file_get_contents("URL".$text);
  163.     }
  164.  
  165.     private function langDetect() {
  166.         library("Lang");
  167.         $LangLib = new Lang;
  168.  
  169.         if(!empty($this->request->cookie['__lang'])) {
  170.             $lang = $this->request->cookie['__lang']."_lang";
  171.  
  172.             $this->lang = ($this->request->cookie['__lang'] == 'ru' or $this->request->cookie['__lang'] == 'en') ? $this->config->$lang : $this->config->en_lang;
  173.         } else {
  174.             $langs = array(
  175.               'ru' => array('ru', 'be', 'uk', 'ky', 'ab', 'mo', 'et', 'lv')
  176.             );
  177.             $lang = $LangLib->getBestMatch('en', $langs);
  178.  
  179.             $this->lang = $this->config->$lang."_lang";
  180.             setcookie("__lang", $lang, time()+60*60*24*30);
  181.         }
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement