diff --git a/objects/subscribe.php b/objects/subscribe.php index 574c196a2..09d51b92c 100644 --- a/objects/subscribe.php +++ b/objects/subscribe.php @@ -1,341 +1,341 @@ load($id); } if (!empty($subscriber_users_id)) { $this->email = $email; $this->users_id = $user_id; $this->subscriber_users_id = $subscriber_users_id; if (empty($this->id)) { $this->loadFromId($this->subscriber_users_id, $user_id, ""); } } } private function load($id) { $obj = self::getSubscribe($id); if (empty($obj)) return false; foreach ($obj as $key => $value) { $this->$key = $value; } return true; } private function loadFromEmail($email, $user_id, $status = "a") { $obj = self::getSubscribeFromEmail($email, $user_id, $status); if (empty($obj)) return false; foreach ($obj as $key => $value) { $this->$key = $value; } return true; } private function loadFromId($subscriber_users_id, $user_id, $status = "a") { $obj = self::getSubscribeFromID($subscriber_users_id, $user_id, $status); if (empty($obj)) return false; foreach ($obj as $key => $value) { $this->$key = $value; } return true; } function save() { global $global; if (!empty($this->id)) { $sql = "UPDATE subscribes SET status = '{$this->status}', notify = '{$this->notify}',ip = '" . getRealIpAddr() . "', modified = now() WHERE id = {$this->id}"; } else { $sql = "INSERT INTO subscribes ( users_id, email,status,ip, created, modified, subscriber_users_id) VALUES ('{$this->users_id}','{$this->email}', 'a', '" . getRealIpAddr() . "',now(), now(), '$this->subscriber_users_id')"; } return sqlDAL::writeSql($sql); } static function getSubscribe($id) { global $global; $id = intval($id); $sql = "SELECT * FROM subscribes WHERE id = $id LIMIT 1"; $res = sqlDAL::readSql($sql, "i", array($id)); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res != false) { $subscribe = $data; } else { $subscribe = false; } return $subscribe; } static function getSubscribeFromEmail($email, $user_id, $status = "a") { global $global; $status = str_replace("'","", $status); $sql = "SELECT * FROM subscribes WHERE email = '$email' AND users_id = {$user_id} "; if (!empty($status)) { $sql .= " AND status = '{$status}' "; } $sql .= " LIMIT 1"; $res = sqlDAL::readSql($sql); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res != false) { $subscribe = $data; } else { $subscribe = false; } return $subscribe; } static function getSubscribeFromID($subscriber_users_id, $user_id, $status = "a") { global $global; $status = str_replace("'","", $status); $sql = "SELECT * FROM subscribes WHERE subscriber_users_id = '$subscriber_users_id' AND users_id = {$user_id} "; if (!empty($status)) { $sql .= " AND status = '{$status}' "; } $sql .= " LIMIT 1"; $res = sqlDAL::readSql($sql); $data = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($res != false) { $subscribe = $data; } else { $subscribe = false; } return $subscribe; } /** * return all subscribers that has subscribe to an user channel * @global type $global * @param type $user_id * @return boolean */ static function getAllSubscribes($user_id = "", $status = "a") { global $global; $status = str_replace("'","", $status); $sql = "SELECT subscriber_users_id as subscriber_id, s.id, s.status, s.ip, s.users_id, s.notify, " - . " s.subscriber_users_id , s.created , s.modified, suId.email as email FROM subscribes as s " + . " s.subscriber_users_id , s.created , s.modified, suId.email as email, suId.emailVerified as emailVerified FROM subscribes as s " //. " LEFT JOIN users as su ON s.email = su.email " . " LEFT JOIN users as suId ON suId.id = s.subscriber_users_id " . " LEFT JOIN users as u ON users_id = u.id WHERE 1=1 AND subscriber_users_id > 0 "; if (!empty($user_id)) { $sql .= " AND users_id = {$user_id} "; } if (!empty($status)) { $sql .= " AND u.status = '{$status}' "; //$sql .= " AND su.status = '{$status}' "; } //$sql .= " GROUP BY subscriber_id "; $sql .= BootGrid::getSqlFromPost(array('email')); $res = sqlDAL::readSql($sql); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $subscribe = array(); if ($res != false) { $emails = array(); foreach ($fullData as $row) { if (in_array($row['email'], $emails)) { //continue; } $emails[] = $row['email']; $row['identification'] = User::getNameIdentificationById($row['subscriber_id']); if ($row['identification'] === __("Unknown User")) { $row['identification'] = $row['email']; } $row['backgroundURL'] = User::getBackground($row['subscriber_id']); $row['photoURL'] = User::getPhoto($row['subscriber_id']); $subscribe[] = $row; } //$subscribe = $res->fetch_all(MYSQLI_ASSOC); } else { $subscribe = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $subscribe; } /** * return all channels that a user has subscribed * @global type $global * @param type $user_id * @return boolean */ static function getSubscribedChannels($user_id) { global $global; $sql = "SELECT s.* FROM subscribes as s WHERE status = 'a' AND subscriber_users_id = ? "; $res = sqlDAL::readSql($sql, "i", array($user_id)); $fullData = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $subscribe = array(); if ($res != false) { foreach ($fullData as $row) { if($row['users_id']==$user_id){ continue; } $row['identification'] = User::getNameIdentificationById($row['users_id']); if ($row['identification'] === __("Unknown User")) { $row['identification'] = $row['email']; } $row['backgroundURL'] = User::getBackground($row['users_id']); $row['photoURL'] = User::getPhoto($row['users_id']); $subscribe[] = $row; } //$subscribe = $res->fetch_all(MYSQLI_ASSOC); } else { $subscribe = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $subscribe; } static function getTotalSubscribes($user_id = "") { global $global; $sql = "SELECT id FROM subscribes WHERE status = 'a' AND subscriber_users_id > 0 "; if (!empty($user_id)) { $sql .= " AND users_id = '{$user_id}' "; } $sql .= BootGrid::getSqlSearchFromPost(array('email')); $res = sqlDAL::readSql($sql); $numRows = sqlDAL::num_rows($res); sqlDAL::close($res); return $numRows; } function toggle() { if (empty($this->status) || $this->status == "i") { $this->status = 'a'; } else { $this->status = 'i'; } $this->save(); } function notifyToggle() { if (empty($this->notify)) { $this->notify = 1; } else { $this->notify = 0; } $this->save(); } function getStatus() { return $this->status; } function getNotify() { return $this->notify; } function setNotify($notify) { $this->notify = $notify; } static function getButton($user_id) { global $global, $advancedCustom; if(!empty($advancedCustom->removeSubscribeButton)){ return ""; } $total = static::getTotalSubscribes($user_id); $subscribe = "