Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * MyUCP
- */
- class UserModel extends Model {
- protected $table = "site_users";
- protected $lang = null;
- public function getUser($value, $row = "user_id") {
- return $this->db->getRow("SELECT * FROM `{$this->table}` WHERE `{$row}` = '{$value}'");
- }
- public function sendMailTo($userid) {
- $this->langDetect();
- $user = $this->getUser($userid);
- $code = md5($userid."maksa988");
- $body = view("email/verify", ["userid" => $userid, "code" => $code]);
- $this->smtpmail($user['user_email'], $this->lang->user['active_account'], $body);
- }
- public function sendRestore($email, $password) {
- $body = view("email/restore", ["newpass" => $password]);
- $this->smtpmail($email, $this->lang->user['restore_pass'], $body);
- }
- public function getChars($userid, $lim = false) {
- $dbs = new DBServer;
- $userid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
- if($lim){
- if($dbs->getOne("SELECT COUNT(*) FROM `basetab_sg` WHERE `AccountID` = '$userid'") >= 5){
- $limit = "LIMIT 5";
- $count = true;
- }
- $chars = $dbs->getAll("SELECT `RoleID`, `Name`, `Profession`, `Sex`, `Money`, `Level`, `Give`,`SciencePoint`,`Liveness`,`Military`,`ScienceLevel`,`Point` FROM `basetab_sg` WHERE `AccountID` = '$userid' ".$limit);
- $dbs->closeConnect();
- return ["chars" => $chars, "count" => $count];
- }
- $result = $dbs->getAll("SELECT `RoleID`, `Name`, `Profession`, `Sex`, `Money`, `Level`, `Give`,`SciencePoint`,`Liveness`,`Military`,`ScienceLevel`,`Point` FROM `basetab_sg` WHERE `AccountID` = '$userid'");
- $dbs->closeConnect();
- return $result;
- }
- public function getReferalsCount($uid) {
- // dd($uid);
- $dbs = new DBServer;
- $users = $this->db->getAll("SELECT `user_id` FROM `{$this->table}` WHERE `user_referal` = '{$uid}'");
- foreach($users as $key) {
- $userid[] = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '{$key['user_id']}'");
- }
- $count = 0;
- foreach($userid as $key) {
- if($key) {
- if($dbs->getOne("SELECT COUNT(*) as 'count' FROM `basetab_sg` WHERE `AccountID` = '$key' AND `Level` >= 60")){
- $count++;
- }
- }
- }
- $dbs->closeConnect();
- return $count;
- }
- public function createEvent($eventDesc,$userID)
- {
- return $this->db->query("INSERT INTO `site_events` (`event_dec`, `user_id`, `event_date`) VALUES ('{$eventDesc}', '{$userID}', NOW());");
- }
- public function getCharsCount($userid, $lim = false) {
- $dbs = new DBServer;
- $userid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$userid'");
- if($lim){
- if($dbs->getOne("SELECT COUNT(*) FROM `basetab_sg` WHERE `AccountID` = '$userid'") >= 5){
- $limit = "LIMIT 5";
- $count = true;
- }
- $chars = $dbs->getAll("SELECT `Name`, `Profession`, `Sex`, `Money`, `Level` FROM `basetab_sg` WHERE `AccountID` = '$userid' ".$limit);
- $dbs->closeConnect();
- return ["chars" => $chars, "count" => $count];
- }
- $result = $dbs->getOne("SELECT COUNT(*) FROM `basetab_sg` WHERE `AccountID` = '$userid'");
- $dbs->closeConnect();
- return $result;
- }
- public function getPayments()
- {
- $sql = "SELECT SUM(sum) FROM `unitpay_payments` WHERE date_format(dateComplete, '%Y%m') = date_format(now(), '%Y%m') AND status = 1";
- return $this->db->getOne($sql);
- }
- public function getGold($id) {
- $dbs = new DBServer;
- $userid = $dbs->getOne("SELECT `ID` FROM `users` WHERE `qq` = '$id'");
- $result = $dbs->getOne("SELECT `Gold` FROM `goldtab_sg` WHERE `AccountID` = '{$userid}'");
- $dbs->closeConnect();
- return $result;
- }
- function smtpmail($mail_to, $subject, $message) {
- require './mailer/PHPMailerAutoload.php';
- $mail = new PHPMailer; // Enable verbose debug output
- $mail->CharSet = 'utf-8';
- $mail->isSMTP();
- $mail->Host = $this->config->mail['smtp']['smtp_host'];
- $mail->SMTPAuth = true;
- $mail->Username = $this->config->mail['smtp']['smtp_username'];
- $mail->Password = $this->config->mail['smtp']['smtp_password'];
- $mail->SMTPSecure = 'ssl';
- $mail->Port = $this->config->mail['smtp']['smtp_port'];
- $mail->setFrom($this->config->mail['smtp']['smtp_from']);
- $mail->addAddress($mail_to); // Name is optional
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = $subject;
- $mail->Body = $message;
- if(!$mail->send()) {
- return 'Mailer Error: ' . $mail->ErrorInfo;
- }
- return true;
- }
- public function getDeps($status = '0') {
- if($status) {
- return $this->db->getAll("SELECT * FROM `site_groups` WHERE `group_status` = {$status}");
- }
- return $this->db->getAll("SELECT * FROM `site_groups`");
- }
- public function getDep($id) {
- return $this->db->getRow("SELECT * FROM `site_groups` WHERE `group_id` = '{$id}'");
- }
- public function editDep($name, $status, $id) {
- $this->table("site_groups");
- return $this->set(["group_name" => $name, "group_status" => $status])->where("group_id", "=", $id)->update();
- }
- public function removeDep($id) {
- $this->table("site_groups");
- return $this->where("group_id", "=", $id)->delete();
- }
- public function newDep($name) {
- $this->table("site_groups");
- return $this->create(['group_name' => $name, 'group_status' => 1]);
- }
- public function sendTelegramMSG($text) {
- file_get_contents("URL".$text);
- }
- private function langDetect() {
- library("Lang");
- $LangLib = new Lang;
- if(!empty($this->request->cookie['__lang'])) {
- $lang = $this->request->cookie['__lang']."_lang";
- $this->lang = ($this->request->cookie['__lang'] == 'ru' or $this->request->cookie['__lang'] == 'en') ? $this->config->$lang : $this->config->en_lang;
- } else {
- $langs = array(
- 'ru' => array('ru', 'be', 'uk', 'ky', 'ab', 'mo', 'et', 'lv')
- );
- $lang = $LangLib->getBestMatch('en', $langs);
- $this->lang = $this->config->$lang."_lang";
- setcookie("__lang", $lang, time()+60*60*24*30);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement