Example #1
0
 function write()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $uid = isset(Request::$post['id']) ? Request::$post['id'] : $current_user->id;
     if (!$uid) {
         throw new Exception('illegal user id');
     }
     if ($current_user->id != $uid) {
         if ($current_user->getRole() >= User::ROLE_BIBER) {
             $editing_user = Users::getByIdsLoaded(array($uid));
             $editing_user = isset($editing_user[$uid]) ? $editing_user[$uid] : false;
         }
     } else {
         $editing_user = $current_user;
     }
     $current_user->can_throw('users_edit', $editing_user);
     foreach ($this->ruleNames as $name => $rule) {
         foreach ($this->typeNames as $typename => $type) {
             if (isset(Request::$post[$name][$typename])) {
                 $editing_user->setNotifyRule($rule, $type, true);
             } else {
                 $editing_user->setNotifyRule($rule, $type, false);
             }
         }
     }
     $editing_user->save();
 }
Example #2
0
 function get_likes($params, &$data)
 {
     $ids = $_POST['ids'];
     $to_check = array();
     foreach ($ids as $event_id) {
         if (is_numeric($event_id) && $event_id > 0) {
             $to_check[$event_id] = $event_id;
         }
     }
     if (count($to_check)) {
         $res = Database::sql2array('SELECT `user_id`,`event_id` FROM `event_likes` WHERE `event_id` IN (' . implode(',', $to_check) . ')');
         $uids = array();
         foreach ($res as $row) {
             $uids[$row['user_id']] = $row['user_id'];
         }
         if (count($uids)) {
             $users = Users::getByIdsLoaded(array_keys($uids));
             foreach ($res as $row) {
                 if (isset($users[$row['user_id']])) {
                     $data['likes'][$row['event_id']][$row['user_id']] = array('nickname' => $users[$row['user_id']]->data['nickname'], 'id' => $users[$row['user_id']]->data['id']);
                     if (CurrentUser::$id == $row['user_id']) {
                         $data['self'][$row['event_id']] = $row['user_id'];
                     }
                 }
             }
         }
     }
     foreach ($to_check as $event_id) {
         if (!isset($data['likes'][$event_id])) {
             $data['likes'][$event_id] = array();
         }
     }
     $data['owner'] = CurrentUser::$id;
     return $data;
 }
Example #3
0
	function getUsers($ids) {
		$users = Users::getByIdsLoaded($ids);
		$out = array();
		/* @var $user User */
		$i = 0;
		if (is_array($users))
			foreach ($users as $user) {
				$out[$user->id] = array(
				    'id' => $user->id,
				    'picture' => $user->getAvatar(),
				    'nickname' => $user->getNickName(),
				);
			}
		if (is_array($ids))
			foreach ($ids as $id) {
				if (!isset($out[$id])) {
					$out[$id] = array(
					    'id' => $id,
					    'picture' => Config::need('www_path') . '/static/upload/avatars/default.jpg',
					    'nickname' => 'аноним',
					);
				}
			}
		return $out;
	}
Example #4
0
 function getCommentUsers($ids)
 {
     $users = Users::getByIdsLoaded($ids);
     $out = array();
     /* @var $user User */
     if (is_array($users)) {
         foreach ($users as $user) {
             $out[] = $user->getListData();
         }
     }
     return $out;
 }
Example #5
0
    function _list($opts)
    {
        $data = array();
        $has_paging = !isset($opts['no_paging']);
        $show_sortings = isset($opts['show_sortings']);
        $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10;
        $per_page = min(100, max(1, (int) $per_page));
        $cond = new Conditions();
        $cond->setSorting(array('time' => array('order' => 'desc', 'title' => 'по дате')), array('time' => array('order' => 'desc', 'title' => 'по дате')));
        $cond->setPaging(100000, $per_page);
        $where = array('parent_id=0');
        if (isset($opts['where'])) {
            foreach ($opts['where'] as $w) {
                $where[] = $w;
            }
        }
        $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL();
        $limit = $cond->getLimit();
        $query = 'SELECT * FROM `comments`
WHERE (' . implode(' AND ', $where) . ')
ORDER BY ' . $order . ' LIMIT ' . $limit . '';
        $comments = Database::sql2array($query, 'id');
        $pids = array();
        $uids = array();
        foreach ($comments as $comment) {
            $pids[$comment['id']] = $comment['id'];
            $uids[$comment['user_id']] = $comment['user_id'];
        }
        if (count($pids)) {
            $query = 'SELECT * FROM `comments` WHERE `thread` IN (' . implode(',', $pids) . ') ORDER BY `thread`,`id`';
            $nextlevel = Database::sql2array($query, 'id');
            $comments += $nextlevel;
            foreach ($comments as $comment) {
                $uids[$comment['user_id']] = $comment['user_id'];
            }
            if (count($uids)) {
                $users = Users::getByIdsLoaded($uids);
            } else {
                $users = array();
            }
            foreach ($comments as &$comment) {
                if (!isset($users[$comment['user_id']])) {
                    continue;
                }
                $comment['user'] = $users[$comment['user_id']];
                $parents[$comment['parent_id']][$comment['id']] = $comment;
                uasort($parents[$comment['parent_id']], 'x_sort_comment');
            }
            $comments = $this->build_tree($parents, 0);
        }
        return $comments;
    }
Example #6
0
	function _list($ids, $opts = array(), $limit = false) {
		$users = Users::getByIdsLoaded($ids);
		$out = array();
		/* @var $user User */
		$i = 0;
		if (is_array($users))
			foreach ($users as $user) {
				if ($limit && ++$i > $limit)
					return $out;
				$out[] = $user->getListData();
			}
		return $out;
	}
Example #7
0
 function _item($row)
 {
     $out = array();
     $usrs = array();
     $out['review'] = array('user_id' => $row['user_id'], 'time' => date('Y-m-d H:i', $row['time']), 'mark' => isset($row['mark']) ? $row['mark'] : 0, 'body' => isset($row['body']) ? $row['body'] : '', 'likesCount' => isset($row['likesCount']) ? (int) $row['likesCount'] : 0);
     $usrs[$row['user_id']] = $row['user_id'];
     if (count($usrs)) {
         $users = Users::getByIdsLoaded($usrs);
         foreach ($users as $user) {
             $out['users'][] = $user->getListData();
         }
     }
     return $out;
 }
Example #8
0
 function _list($ids, $opts = array(), $limit = false)
 {
     $users = Users::getByIdsLoaded($ids);
     $out = array();
     /* @var $user User */
     $i = 0;
     if (is_array($users)) {
         foreach ($users as $user) {
             if ($limit && ++$i > $limit) {
                 return $out;
             }
             $out[] = array('id' => $user->id, 'picture' => $user->getAvatar(), 'nickname' => $user->getNickName());
         }
     }
     return $out;
 }
    function _list($opts = array())
    {
        $has_paging = !isset($opts['no_paging']);
        $show_sortings = isset($opts['show_sortings']);
        $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10;
        $per_page = min(100, max(1, (int) $per_page));
        $cond = new Conditions();
        $cond->setSorting(array('created' => array('order' => 'desc', 'title' => 'по дате')));
        $cond->setPaging(100000, $per_page);
        $where = array('1');
        if (isset($opts['where'])) {
            foreach ($opts['where'] as $w) {
                $where[] = $w;
            }
        }
        $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL();
        $limit = $cond->getLimit();
        $query = 'SELECT SQL_CALC_FOUND_ROWS P. * , GROUP_CONCAT( T.title ) AS tags, GROUP_CONCAT( PT.tag_id ) AS tags_indexes
FROM `publications` P
LEFT JOIN `publications_tags` PT ON PT.publication_id = P.id
LEFT JOIN `tags` T ON T.id = PT.tag_id
WHERE (' . implode(' AND ', $where) . ')
GROUP BY P.id
ORDER BY ' . $order . ' LIMIT ' . $limit . '';
        $publications = Database::sql2array($query, 'id');
        foreach ($publications as $publication) {
            $uids[$publication['user_id']] = $publication['user_id'];
        }
        $users = Users::getByIdsLoaded($uids);
        foreach ($publications as &$publication) {
            $publication['user'] = isset($users[$publication['user_id']]) ? $users[$publication['user_id']]->data : array();
        }
        $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page);
        $data['publications'] = $publications;
        $data['conditions'] = $cond->getConditions();
        if (!$show_sortings) {
            foreach ($data['conditions'] as $key => $group) {
                if ($group['mode'] == 'sorting') {
                    unset($data['conditions'][$key]);
                }
            }
        }
        return $data;
    }
Example #10
0
 function getSubscriptions()
 {
     global $current_user;
     $user = Users::getByIdsLoaded(array($this->params['user_id']));
     $user = isset($user[$this->params['user_id']]) ? $user[$this->params['user_id']] : $current_user;
     /* @var $user User */
     $subscriptions = $user->getSubscriptions();
     $this->data['subscriptions'] = $subscriptions;
     $this->data['user'] = $user->getListData();
     $this->data['user']['unused_points'] = $user->getPoints();
     $this->data['subscriptions']['active'] = $user->isSubscriptionEnabled() ? '1' : 0;
     $this->data['subscriptions']['end'] = $user->getSubscriptionEnd() ? date('Y/m/d H:i:s ', $user->getSubscriptionEnd()) : 0;
 }
Example #11
0
	function getThreadList() {
		global $current_user;
		$query = 'SELECT * FROM `users_messages_index` UMI
			RIGHT JOIN `users_messages` UM ON UM.id = UMI.message_id
			WHERE `id_recipient`=' . $current_user->id;
		$messages = Database::sql2array($query);
		// загрузили все сообщения вообще
		// для каждого треда выбираем последнее сообщение
		$messages_prepared = array();
		$uids = array();
		foreach ($messages as &$message) {
			if (!isset($messages_prepared[$message['thread_id']])) {
				$messages_prepared[$message['thread_id']]['newest']['time'] = 0;
				$messages_prepared[$message['thread_id']]['oldest']['time'] = time() + 10000;
			}
			if ($messages_prepared[$message['thread_id']]['newest']['time'] < $message['time']) {
				$messages_prepared[$message['thread_id']]['newest'] = $message;
				$messages_prepared[$message['thread_id']]['subject'] = $message['subject'];
				$messages_prepared[$message['thread_id']]['html'] = $message['html'];
				
			}

			if ($message['is_new'])
				$messages_prepared[$message['thread_id']]['is_new'] = 1;



			if ($messages_prepared[$message['thread_id']]['oldest']['time'] > $message['time'])
				$messages_prepared[$message['thread_id']]['oldest'] = $message['time'];

			$messages_prepared[$message['thread_id']]['members'][$message['id_recipient']] = $message['id_recipient'];
			$messages_prepared[$message['thread_id']]['members'][$message['id_author']] = $message['id_author'];
			$messages_prepared[$message['thread_id']]['thread_id'] = $message['thread_id'];
		}
		


		foreach ($messages_prepared as $thread_id => &$mess) {
			$mess['oldest'] = date('Y/m/d H:i:s', $mess['oldest']);
			$tmpmess = $mess['newest'];
			$tmpmess['oldest'] = $mess['oldest'];
			$tmpmess['newest'] = date('Y/m/d H:i:s', $mess['newest']['time']);
			$tmpmess['subject'] = $mess['subject'];
			$tmpmess['is_new'] = isset($mess['is_new']) ? 1 : 0;
			foreach ($mess['members'] as $uid) {
				if ($current_user->id != $uid)
					$tmpmess['members'][] = array(
					    'id' => $uid
					);
				$uids[$uid] = $uid;
			}
			$out[] = $tmpmess;
		}
		$users = Users::getByIdsLoaded($uids);
		foreach ($users as $user) {
			$this->data['users'][$user->id] = array(
			    'id' => $user->id,
			    'picture' => $user->getAvatar(),
			    'nickname' => $user->getNickName(),
			);
		}

		$this->data['messages'] = $out;
	}
Example #12
0
 function getStatUsers($uids)
 {
     if (!count($uids)) {
         return array();
     }
     $users = Users::getByIdsLoaded($uids);
     $out = array();
     foreach ($users as $user) {
         $out[] = $user->getListData();
     }
     foreach ($out as &$r) {
         $r['path'] = Config::need('www_path') . '/admin/users/stat/' . $r['id'];
     }
     return $out;
 }
Example #13
0
    function getThreadList($notifications = false)
    {
        global $current_user;
        $out = array();
        if ($notifications) {
            $query = 'SELECT * FROM `users_messages_index` UMI
			RIGHT JOIN `users_messages` UM ON UM.id = UMI.message_id
			WHERE `id_recipient`=' . $current_user->id . ' AND `id_author`=0 AND `is_deleted`=0';
        } else {
            $query = 'SELECT * FROM `users_messages_index` UMI
			RIGHT JOIN `users_messages` UM ON UM.id = UMI.message_id
			WHERE `id_recipient`=' . $current_user->id . ' AND `id_author`<>0 AND `is_deleted`=0';
        }
        $messages = Database::sql2array($query);
        // загрузили все сообщения вообще
        // для каждого треда выбираем последнее сообщение
        $messages_prepared = array();
        $uids = array();
        $thread_ids = array();
        foreach ($messages as &$message) {
            $tr[$message['thread_id']] = $message['id_author'];
            $uids[$message['id_author']] = $message['id_author'];
            $thread_ids[$message['thread_id']] = $message['thread_id'];
            if (!isset($messages_prepared[$message['thread_id']])) {
                $messages_prepared[$message['thread_id']]['newest']['time'] = 0;
                $messages_prepared[$message['thread_id']]['oldest']['time'] = time() + 10000;
            }
            if ($messages_prepared[$message['thread_id']]['newest']['time'] < $message['time']) {
                $messages_prepared[$message['thread_id']]['newest'] = $message;
                $messages_prepared[$message['thread_id']]['html'] = $message['html'];
            }
            if ($message['is_new']) {
                $messages_prepared[$message['thread_id']]['is_new'] = 1;
            }
            if ($messages_prepared[$message['thread_id']]['oldest']['time'] > $message['time']) {
                $messages_prepared[$message['thread_id']]['oldest'] = $message['time'];
                $messages_prepared[$message['thread_id']]['subject'] = $message['subject'];
            }
            $messages_prepared[$message['thread_id']]['thread_id'] = $message['thread_id'];
        }
        foreach ($messages_prepared as $thread_id => &$mess) {
            $mess['oldest'] = date('Y/m/d H:i:s', $mess['oldest']);
            $tmpmess = $mess['newest'];
            $tmpmess['oldest'] = $mess['oldest'];
            $tmpmess['newest'] = date('Y/m/d H:i:s', $mess['newest']['time']);
            $tmpmess['timestamp'] = $mess['newest']['time'];
            $tmpmess['time'] = date('Y/m/d H:i:s', $tmpmess['time']);
            $tmpmess['subject'] = $mess['subject'];
            $tmpmess['is_new'] = isset($mess['is_new']) ? 1 : 0;
            $out[$tmpmess['thread_id']] = $tmpmess;
        }
        // all people from threads
        if (count($thread_ids)) {
            if ($notifications) {
                $query = 'SELECT `thread_id`,`id_recipient`,`type` FROM`users_messages_index` WHERE `thread_id` IN (' . implode(',', $thread_ids) . ')
					AND `id_recipient`=' . $current_user->id;
            } else {
                $query = 'SELECT `thread_id`,`id_recipient`,`type` FROM`users_messages_index` WHERE `thread_id` IN (' . implode(',', $thread_ids) . ')';
            }
            $parts = Database::sql2array($query);
            foreach ($parts as &$p) {
                if (isset($out[$p['thread_id']])) {
                    if ($tr[$p['thread_id']] != $current_user->id) {
                        $out[$p['thread_id']]['members'][$tr[$p['thread_id']]] = array('user_id' => $tr[$p['thread_id']]);
                    }
                    if ($p['id_recipient'] != $current_user->id) {
                        $out[$p['thread_id']]['members'][$p['id_recipient']] = array('user_id' => $p['id_recipient']);
                    }
                    $uids[$p['id_recipient']] = $p['id_recipient'];
                }
            }
        }
        $users = Users::getByIdsLoaded($uids);
        foreach ($users as $user) {
            $this->data['users'][$user->id] = $user->getListData();
        }
        uasort($out, 'sort_by_newest_time');
        $this->data['messages'] = $out;
    }
Example #14
0
 function getLog()
 {
     if ($this->target_type == 'user') {
         $query = 'SELECT COUNT(DISTINCT(id_log)) FROM `biber_log_index` WHERE `id_user`=' . $this->id_target . ' ';
     } else {
         if ($this->target_type == 'all') {
             $query = 'SELECT COUNT(DISTINCT(id_log)) FROM `biber_log_index` WHERE `is_copy`=0';
         } else {
             $query = 'SELECT COUNT(1) FROM `biber_log_index` WHERE `target_type`=' . $this->target_type . ' AND `id_target`=' . $this->id_target . ' ';
         }
     }
     $count = min(1000, Database::sql2single($query));
     $cond = new Conditions();
     $cond->setPaging($count, 10);
     $this->data['conditions'] = $cond->getConditions();
     $limit = $cond->getLimit();
     if ($this->target_type == 'user') {
         $query = 'SELECT * FROM `biber_log_index` WHERE
         `id_user`=' . $this->id_target . ' GROUP BY id_log
         ORDER BY `time` DESC LIMIT ' . $limit;
     } else {
         if ($this->target_type == 'all') {
             $query = 'SELECT * FROM `biber_log_index` WHERE `is_copy`=0 GROUP BY id_log
         ORDER BY `time` DESC LIMIT ' . $limit;
         } else {
             $query = 'SELECT * FROM `biber_log_index` WHERE
         `target_type`=' . $this->target_type . ' AND
         `id_target`=' . $this->id_target . '
         ORDER BY `time` DESC LIMIT ' . $limit;
         }
     }
     $book_ids = array();
     $person_ids = array();
     $serie_ids = array();
     $magazine_ids = array();
     $uids = array();
     if ($this->target_type == BiberLog::TargetType_book) {
         $book_ids[$this->id_target] = $this->id_target;
     }
     if ($this->target_type == BiberLog::TargetType_person) {
         $person_ids[$this->id_target] = $this->id_target;
     }
     if ($this->target_type == 'user') {
         $uids[$this->id_target] = $this->id_target;
     }
     $arr = array();
     $arri = Database::sql2array($query, 'id_log');
     $to_fetch_log = array();
     foreach ($arri as $row) {
         $to_fetch_log[(int) $row['id_log']] = (int) $row['id_log'];
     }
     if (count($to_fetch_log)) {
         $query = 'SELECT * FROM `biber_log` WHERE `id` IN (' . implode(',', $to_fetch_log) . ') ORDER BY `time` DESC';
         $arr = Database::sql2array($query);
         foreach ($arr as &$rowx) {
             foreach ($arri[$rowx['id']] as $f => $v) {
                 $rowx[$f] = $v;
             }
         }
     }
     foreach ($arr as &$row) {
         $book_id_s = 0;
         $uids[$row['id_user']] = $row['id_user'];
         $vals = unserialize($row['data']);
         if (isset($vals['id1'])) {
             $book_ids[$vals['id1'][0]] = $vals['id1'][0];
             $book_ids[$vals['id1'][1]] = $vals['id1'][1];
         }
         if (isset($vals['id2'])) {
             $book_ids[$vals['id2'][0]] = $vals['id2'][0];
             $book_ids[$vals['id2'][1]] = $vals['id2'][1];
         }
         if (isset($vals['id_person'])) {
             if (isset($vals['id_person'][0])) {
                 $person_ids[$vals['id_person'][0]] = (int) $vals['id_person'][0];
             }
             if (isset($vals['id_person'][1])) {
                 $person_ids[$vals['id_person'][1]] = (int) $vals['id_person'][1];
             }
         }
         if (isset($vals['is_duplicate'])) {
             $book_ids[$vals['is_duplicate'][0]] = $vals['is_duplicate'][0];
             $book_ids[$vals['is_duplicate'][1]] = $vals['is_duplicate'][1];
         }
         $book_id = 0;
         $person_id = 0;
         $serie_id = 0;
         $values = array();
         foreach ($vals as $field => $v) {
             if (!is_array($v)) {
                 if ($field == 'id_book') {
                     $book_id = $v;
                     $book_ids[$v] = $v;
                 }
                 if ($field == 'id_person') {
                     $person_id = $v;
                     $person_ids[$v] = $v;
                 }
                 if ($field == 'id_serie') {
                     $serie_id = $v;
                     $serie_ids[$v] = $v;
                 }
                 if ($field == 'id_magazine') {
                     $serie_id = $v;
                     $magazine_ids[$v] = $v;
                 }
                 continue;
             }
             $tmp = array();
             if ($row['target_type'] == BiberLog::TargetType_book) {
                 if ($field == 'new_relations') {
                     foreach ($v[1] as $new_relation_id) {
                         $book_ids[$new_relation_id] = $new_relation_id;
                         $tmp[] = array('book_id' => $new_relation_id);
                     }
                     $values['new_relations'] = $tmp;
                 } else {
                     if ($field == 'old_relations') {
                         foreach ($v[1] as $new_relation_id) {
                             $book_ids[$new_relation_id] = $new_relation_id;
                             $tmp[] = array('book_id' => $new_relation_id);
                         }
                         $values['old_relations'] = $tmp;
                     } else {
                         if ($field == 'deleted_relations') {
                             foreach ($v[1] as $new_relation_id) {
                                 $book_ids[$new_relation_id] = $new_relation_id;
                                 $tmp[] = array('book_id' => $new_relation_id);
                             }
                             $values['deleted_relations'] = $tmp;
                         } else {
                             $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]);
                         }
                     }
                 }
             } else {
                 if ($row['target_type'] == BiberLog::TargetType_person) {
                     if ($field == 'new_relations') {
                         foreach ($v[1] as $new_relation_id) {
                             $person_ids[$new_relation_id] = (int) $new_relation_id;
                             $tmp[] = array('author_id' => $new_relation_id);
                         }
                         $values['new_relations'] = $tmp;
                     } else {
                         if ($field == 'old_relations') {
                             foreach ($v[1] as $new_relation_id) {
                                 $person_ids[$new_relation_id] = (int) $new_relation_id;
                                 $tmp[] = array('author_id' => $new_relation_id);
                             }
                             $values['old_relations'] = $tmp;
                         } else {
                             if ($field == 'deleted_relations') {
                                 foreach ($v[1] as $new_relation_id) {
                                     $person_ids[$new_relation_id] = (int) $new_relation_id;
                                     $tmp[] = array('author_id' => $new_relation_id);
                                 }
                                 $values['deleted_relations'] = $tmp;
                             } else {
                                 $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]);
                             }
                         }
                     }
                 } else {
                     if ($row['target_type'] == BiberLog::TargetType_magazine) {
                         $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]);
                     } else {
                         if ($row['target_type'] == BiberLog::TargetType_serie) {
                             if ($field == 'id_book') {
                                 $book_id_s = $v[0] ? $v[0] : $v[1];
                                 if ($book_id_s) {
                                     $book_ids[$book_id_s] = $book_id_s;
                                 }
                                 continue;
                             }
                             $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]);
                         }
                     }
                 }
             }
         }
         if (in_array($row['target_type'], array(BiberLog::TargetType_book))) {
             $book_ids[$row['id_target']] = $row['id_target'];
             $book_id = $row['id_target'];
         }
         if (in_array($row['target_type'], array(BiberLog::TargetType_person))) {
             $person_ids[(int) $row['id_target']] = (int) $row['id_target'];
             $person_id = $row['id_target'];
         }
         if (in_array($row['target_type'], array(BiberLog::TargetType_serie))) {
             $serie_id = $row['id_target'];
             $serie_ids[$row['id_target']] = $row['id_target'];
         }
         if (in_array($row['target_type'], array(BiberLog::TargetType_magazine))) {
             $magazine_id = $row['id_target'];
             $magazine_ids[$row['id_target']] = $row['id_target'];
         }
         $this->data['logs'][] = array('id' => $row['id'], 'book_id' => max($book_id, $book_id_s), 'author_id' => $person_id, 'serie_id' => $serie_id, 'time' => date('Y/m/d H:i:s', $row['time']), 'action' => BiberLog::$actionTypes[$row['action_type']], 'id_user' => $row['id_user'], 'values' => $values, 'applied' => $row['undo'] ? 0 : 1);
     }
     $users = Users::getByIdsLoaded($uids);
     foreach ($users as $user) {
         $this->data['users'][$user->id] = $user->getListData();
     }
     if (count($serie_ids)) {
         $query = 'SELECT id,name,title FROM `series` WHERE `id` IN(' . implode(',', $serie_ids) . ')';
         $out = Database::sql2array($query);
         foreach ($out as &$r) {
             $r['path'] = Config::need('www_path') . '/s/' . $r['id'];
         }
         $this->data['series'] = $out;
     }
     if (count($book_ids)) {
         $this->data['books'] = $this->getLogBooks($book_ids);
     }
     if (count($person_ids)) {
         $this->data['authors'] = $this->getLogPersons($person_ids);
     }
     foreach (Config::$langRus as $code => $title) {
         $this->data['lang_codes'][] = array('id' => Config::$langs[$code], 'code' => $code, 'title' => $title);
     }
 }
Example #15
0
 function loadReviews()
 {
     if ($this->reviewsLoaded) {
         return false;
     }
     $query = 'SELECT `id_user`,`comment`,`time`,`rate` FROM `reviews` WHERE `id_target`=' . $this->id . ' AND `target_type`=' . self::REVIEW_TYPE_BOOK;
     $reviews = Database::sql2array($query);
     $uids = array();
     foreach ($reviews as $review) {
         $uids[] = $review['id_user'];
     }
     if ($uids) {
         $users = Users::getByIdsLoaded($uids);
     }
     global $current_user;
     /* @var $current_user CurrentUser */
     foreach ($reviews as &$review) {
         if (isset($users[$review['id_user']])) {
             $review['nickname'] = $users[$review['id_user']]->getProperty('nickname', 'аноним');
             $review['picture'] = $users[$review['id_user']]->getProperty('picture') ? $users[$review['id_user']]->id . '.jpg' : 'default.jpg';
         } else {
             $review['nickname'] = 'аноним';
             $review['picture'] = 'default.jpg';
         }
     }
     $this->reviews = $reviews;
     $this->reviewsLoaded = true;
 }
Example #16
0
    function _list($opts = array())
    {
        $has_paging = !isset($opts['no_paging']);
        $show_sortings = isset($opts['show_sortings']);
        $per_page = isset($opts['per_page']) ? $opts['per_page'] : 10;
        $per_page = min(100, max(1, (int) $per_page));
        $cond = new Conditions();
        if (isset($opts['historical']) && $opts['historical']) {
            $cond->setSorting(array('eventTime' => array('order' => 'desc', 'title' => 'по исторической дате')), array('eventTime' => array('order' => 'desc', 'title' => 'по исторической дате')));
        } else {
            $cond->setSorting(array('createTime' => array('order' => 'desc', 'title' => 'по дате')), array('createTime' => array('order' => 'desc', 'title' => 'по дате')));
        }
        $cond->setPaging(100000, $per_page);
        $where = array('1');
        if (isset($opts['where'])) {
            foreach ($opts['where'] as $w) {
                $where[] = $w;
            }
        }
        $order = $cond->getSortingField() . ' ' . $cond->getSortingOrderSQL();
        $limit = $cond->getLimit();
        $query = 'SELECT SQL_CALC_FOUND_ROWS A.child_name as child_name,A.birthDate as birthDate,AE.*, LE.*,AE.description as description, LE.description as event_description, LE.title as event_title,AE.title as title, AE.creator_id as user_id,AE.id as id, LE.id as lib_event_id, LET.id as lib_template_id, AE.id as id
            FROM `album_events` AE
            LEFT JOIN `album` A ON A.id=AE.album_id
            LEFT JOIN `lib_events` LE ON LE.id=AE.event_id
            LEFT JOIN `lib_event_templates` LET ON LET.id=LE.template_id
WHERE (' . implode(' AND ', $where) . ')
ORDER BY ' . $order . ' LIMIT ' . $limit . '';
        $events = Database::sql2array($query, 'id');
        $uids = array();
        if (count($events)) {
            $field_values = Database::sql2array('SELECT AEF.*,LETF.title as event_field_title,T.* FROM `album_events_fields` AEF
                JOIN `lib_event_templates_fields` LETF ON LETF.field_id=AEF.field_id
                JOIN `lib_event_templates_fields_types` T ON T.id=LETF.type
                WHERE `event_id` IN(' . implode(',', array_keys($events)) . ')');
        } else {
            $field_values = array();
        }
        foreach ($field_values as $values) {
            $events[$values['event_id']]['fields'][$values['field_id']] = $values;
        }
        foreach ($events as $event) {
            if ($event['user_id']) {
                $uids[$event['user_id']] = $event['user_id'];
            }
        }
        if (count($uids)) {
            $users = Users::getByIdsLoaded($uids);
        } else {
            $users = array();
        }
        foreach ($events as &$event) {
            $event['user'] = isset($users[$event['user_id']]) ? $users[$event['user_id']]->data : array();
            $event['template_id'] = $event['template_id'] ? $event['template_id'] : 1;
            $image_id = $event['picture'];
            $event['pic_small'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_SMALL) : false;
            $event['pic_normal'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_NORMAL) : false;
            $event['pic_big'] = $image_id ? ImgStore::getUrl($image_id, Config::SIZES_PICTURE_BIG) : false;
            $event['pic_orig'] = $image_id ? ImgStore::getUrl($image_id, 0) : false;
        }
        $cond->setPaging(Database::sql2single('SELECT FOUND_ROWS()'), $per_page);
        $data['events'] = $events;
        $data['conditions'] = $cond->getConditions();
        if (!$show_sortings) {
            foreach ($data['conditions'] as $key => $group) {
                if ($group['mode'] == 'sorting') {
                    unset($data['conditions'][$key]);
                }
            }
        }
        return $data;
    }
Example #17
0
    function getLog() {
        if ($this->target_type == 'user') {
            $query = 'SELECT * FROM `biber_log` WHERE
            `id_user`=' . $this->id_target . '
            ORDER BY `time` DESC LIMIT 100';
        } else
        if ($this->target_type == 'all') {
            $query = 'SELECT * FROM `biber_log`
            ORDER BY `time` DESC LIMIT 100';
        } else {
            $query = 'SELECT * FROM `biber_log` WHERE
            `target_type`=' . $this->target_type . ' AND
            `id_target`=' . $this->id_target . '
            ORDER BY `time` DESC LIMIT 100';
        }
        $book_ids = array();
        $person_ids = array();
        $uids = array();

        if ($this->target_type == BiberLog::TargetType_book)
            $book_ids[$this->id_target] = $this->id_target;

        if ($this->target_type == BiberLog::TargetType_person)
            $person_ids[$this->id_target] = $this->id_target;

        if ($this->target_type == 'user')
            $uids[$this->id_target] = $this->id_target;


        $arr = Database::sql2array($query);


        foreach ($arr as $row) {
            $uids[$row['id_user']] = $row['id_user'];
            $vals = unserialize($row['data']);
            $values = array();
            foreach ($vals as $field => $v) {
                $values[] = array('name' => $field, 'old' => $v[0], 'new' => $v[1]);
            }
            $book_id = 0;

            $person_id = 0;

            if (in_array($row['target_type'], array(BiberLog::TargetType_book))) {
                $book_ids[$row['id_target']] = $row['id_target'];
                $book_id = $row['id_target'];
            }
            if (in_array($row['target_type'], array(BiberLog::TargetType_person))) {
                $person_ids[$row['id_target']] = $row['id_target'];
                $person_id = $row['id_target'];
            }
            $this->data['logs'][] = array(
                'id' => $row['id'],
                'book_id' => $book_id,
                'author_id' => $person_id,
                'time' => date('Y/m/d H:i:s', $row['time']),
                'type' => BiberLog::$actionTypes[$row['action_type']],
                'id_user' => $row['id_user'],
                'values' => $values,
            );
        }
        $users = Users::getByIdsLoaded($uids);
        foreach ($users as $user) {
            $this->data['users'][$user->id] = array(
                'id' => $user->id,
                'picture' => $user->getAvatar(),
                'nickname' => $user->getNickName(),
            );
        }
        if (count($book_ids))
            $this->data['books'] = $this->getLogBooks($book_ids);
        if (count($person_ids))
            $this->data['authors'] = $this->getLogPersons($person_ids);

        foreach (Config::$langRus as $code => $title) {
            $this->data['lang_codes'][] = array(
                'id' => Config::$langs[$code],
                'code' => $code,
                'title' => $title,
            );
        }
    }
Example #18
0
	function _list($data) {
		$out = array();
		$usrs = array();
		if (is_array($data)) {
			foreach ($data as $row) {
				$out['reviews'][] = array(
				    'id_user' => $row['id_user'],
				    'time' => date('Y-m-d H:i', $row['time']),
				    'rate' => $row['rate'],
				    'html' => $row['comment'],
				    'book_id' => $row['id_target'],
				);
				$usrs[$row['id_user']] = $row['id_user'];
			}
		}
		if (count($usrs)) {
			$users = Users::getByIdsLoaded($usrs);
			foreach ($users as $user) {
				$out['users'][$user->id] = array(
				    'id' => $user->id,
				    'picture' => $user->getAvatar(),
				    'nickname' => $user->getNickName(),
				);
			}
		}
		foreach ($usrs as $id => $idd) {
			if (!isset($out['users'][$id])) {
				$out['users'][$user->id] = array(
				    'id' => $id,
				);
			}
		}
		return $out;
	}
Example #19
0
 private static function send($user_ids, $subject, $message, $rule, $only_email = false)
 {
     $users = Users::getByIdsLoaded($user_ids);
     $uids = array();
     $muids = array();
     foreach ($users as $user) {
         /* @var $user User */
         $priority = 1;
         // todo
         if ($user->canNotify($rule, UserNotify::UNT_NOTIFY)) {
             $uids[$user->id] = $user->id;
         }
         if ($user->canNotify($rule, UserNotify::UNT_EMAIL)) {
             $muids[$user->id] = array('priority' => $priority);
         }
     }
     if (!$only_email && count($uids)) {
         $mwm = new MessagesWriteModule();
         $mwm->sendMessage(0, $uids, $subject, $message, time(), false, 1);
     }
     if (count($muids)) {
         // скармливаем демону
         $q = array();
         $now = time();
         $send_time = time();
         $priority = 1;
         foreach ($muids as $id => $data) {
             $q[] = '(' . $id . ',' . Database::escape($subject) . ',' . Database::escape($message) . ',' . $now . ',' . $send_time . ',' . $rule . ',' . $data['priority'] . ')';
         }
         $query = 'INSERT INTO `email_notify` (id_user,subject,message,time,send_time,type,priority) VALUES ' . implode(',', $q) . '';
         Database::query($query);
     }
 }
 function write()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     if (!$current_user->authorized) {
         Error::CheckThrowAuth();
     }
     $mask = array('id' => 'int', 'bday' => 'string', 'city_id' => 'int', 'role' => array('type' => 'int', '*' => true), 'link_fb' => array('type' => 'string', '*' => true), 'link_vk' => array('type' => 'string', '*' => true), 'link_lj' => array('type' => 'string', '*' => true), 'link_tw' => array('type' => 'string', '*' => true), 'quote' => array('type' => 'string', '*' => true), 'about' => array('type' => 'string', '*' => true));
     $params = Request::checkPostParameters($mask);
     $uid = isset($params['id']) ? $params['id'] : 0;
     if (!$uid) {
         throw new Exception('illegal user id');
     }
     if ($current_user->id != $params['id']) {
         if ($current_user->getRole() >= User::ROLE_SITE_ADMIN) {
             $editing_user = Users::getByIdsLoaded(array($params['id']));
             $editing_user = isset($editing_user[$params['id']]) ? $editing_user[$params['id']] : false;
         }
     } else {
         $editing_user = $current_user;
     }
     if ($editing_user) {
         //avatar
         if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) {
             $filename = Config::need('avatar_upload_path') . '/' . $editing_user->id . '.jpg';
             $upload = new UploadAvatar($_FILES['picture']['tmp_name'], 50, 50, "simple", $filename);
             $filename = Config::need('avatar_upload_path') . '/big_' . $editing_user->id . '.jpg';
             $upload = new UploadAvatar($_FILES['picture']['tmp_name'], 100, 100, "simple", $filename);
             if ($upload->out) {
                 $editing_user->setProperty('avatar', 'jpg');
             } else {
                 throw new Exception('cant copy file to ' . $filename, 100);
             }
         }
         if ($editing_user->getRole() < User::ROLE_SITE_ADMIN) {
             if ($current_user->getRole() >= User::ROLE_SITE_ADMIN) {
                 if (($new_role = (int) $params['role']) !== false) {
                     foreach (Users::$rolenames as $id => $name) {
                         if ($id == $new_role) {
                             if ($new_role <= User::ROLE_SITE_ADMIN) {
                                 $editing_user->setRole($new_role);
                             }
                         }
                     }
                 }
             }
         }
         //bday
         $editing_user->setProperty('bday', max(0, (int) @strtotime($params['bday'])));
         // city
         $editing_user->setProperty('city_id', $params['city_id']);
         // facebook etc
         $editing_user->setPropertySerialized('link_fb', $params['link_fb']);
         $editing_user->setPropertySerialized('link_vk', $params['link_vk']);
         $editing_user->setPropertySerialized('link_tw', $params['link_tw']);
         $editing_user->setPropertySerialized('link_lj', $params['link_lj']);
         $params['quote'] = htmlspecialchars($params['quote']);
         $params['about'] = htmlspecialchars($params['about']);
         $editing_user->setPropertySerialized('quote', $params['quote']);
         $editing_user->setPropertySerialized('about', $params['about']);
         $editing_user->save();
         // после редактирования профиля надо посбрасывать кеш со страницы профиля
         // и со страницы редактирования профиля
         // кеш в остальных модулях истечет сам
         Users::dropCache($editing_user->id);
     } else {
         Error::CheckThrowAuth(User::ROLE_SITE_ADMIN);
     }
 }
Example #21
0
 function toggle_vandal()
 {
     global $current_user;
     $this->data['success'] = 0;
     if (!$current_user->authorized) {
         $this->error('Auth');
         return;
     }
     if ($current_user->getRole() < User::ROLE_BIBER) {
         $this->error('Must be biber');
         return;
     }
     $target_id = isset($_POST['id']) ? (int) $_POST['id'] : false;
     if (!$target_id) {
         $this->error('Illegal id');
         return;
     }
     /* @var $target_user CurrentUser */
     $target_user = Users::getByIdsLoaded(array($target_id));
     if (!isset($target_user[$target_id])) {
         $this->error('No user #' . $target_id);
         return;
     }
     $target_user = $target_user[$target_id];
     if ($target_id == $current_user->id) {
         $this->error('Онанизм');
         return;
     }
     $oldRole = $target_user->getRole();
     if ($oldRole < User::ROLE_VANDAL) {
         $this->error('Too small role');
         return;
     }
     if ($oldRole >= User::ROLE_BIBER) {
         $this->error('Too large role');
         return;
     }
     if ($oldRole == User::ROLE_VANDAL) {
         $query = 'UPDATE `users` SET `role`=' . User::ROLE_READER_CONFIRMED . ' WHERE `id`=' . $target_user->id;
         Database::query($query);
         $this->data['user_role'] = User::ROLE_READER_CONFIRMED;
         $this->data['success'] = 1;
         Users::dropCache($target_user->id);
         return;
     }
     if ($oldRole < User::ROLE_SITE_ADMIN) {
         $query = 'UPDATE `users` SET `role`=' . User::ROLE_VANDAL . ' WHERE `id`=' . $target_user->id;
         Database::query($query);
         $this->data['user_role'] = User::ROLE_VANDAL;
         $this->data['success'] = 1;
         Users::dropCache($target_user->id);
         return;
     }
     $this->data['user_role'] = $oldRole;
     $this->data['error'] = '?';
 }
Example #22
0
 function getMessagesUsers($uids)
 {
     $users = Users::getByIdsLoaded($uids);
     $out = array();
     foreach ($users as $user) {
         $out[$user->id] = $user->getListData();
     }
     return $out;
 }
Example #23
0
 function write()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     $mask = array('id' => 'int', 'nickname' => array('type' => 'string', 'regexp' => '/^[A-Za-z][A-Za-z0-9_]+$/', 'min_length' => 3, 'max_length' => 26, '*' => true), 'role' => array('type' => 'int', '*' => true), 'link_fb' => array('type' => 'string', '*' => true), 'link_vk' => array('type' => 'string', '*' => true), 'link_lj' => array('type' => 'string', '*' => true), 'link_tw' => array('type' => 'string', '*' => true), 'quote' => array('type' => 'string', '*' => true), 'about' => array('type' => 'string', '*' => true));
     $params = Request::checkPostParameters($mask);
     $uid = isset($params['id']) ? $params['id'] : 0;
     if (!$uid) {
         throw new Exception('illegal user id');
     }
     if ($current_user->id != $params['id']) {
         if ($current_user->getRole() >= User::ROLE_BIBER) {
             $editing_user = Users::getByIdsLoaded(array($params['id']));
             $editing_user = isset($editing_user[$params['id']]) ? $editing_user[$params['id']] : false;
         }
     } else {
         $editing_user = $current_user;
     }
     $current_user->can_throw('users_edit', $editing_user);
     if ($editing_user) {
         if (trim($params['nickname']) != $editing_user->getNickName()) {
             if (!$editing_user->checkNickChanging()) {
                 throw new Exception('You can\'t change your nickname');
             }
         }
         //avatar
         if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) {
             $filename = Config::need('avatar_upload_path') . '/' . $editing_user->id . '.jpg';
             $folder = Config::need('avatar_upload_path');
             $filename_normal = $folder . '/default_' . $editing_user->id . '.jpg';
             $filename_small = $folder . '/small_' . $editing_user->id . '.jpg';
             $filename_big = $folder . '/big_' . $editing_user->id . '.jpg';
             $filename_orig = $folder . '/orig_' . $editing_user->id . '.jpg';
             $thumb = new Thumb();
             $thumb->createThumbnails($_FILES['picture']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes);
             $editing_user->setProperty('picture', 1);
             $editing_user->setProperty('lastSave', time());
         }
         if ($editing_user->getRole() < User::ROLE_SITE_ADMIN) {
             if ($current_user->getRole() == User::ROLE_BIBER) {
                 if (($new_role = (int) $params['role']) !== false) {
                     foreach (Users::$rolenames as $id => $name) {
                         if ($id == $new_role) {
                             if ($new_role < User::ROLE_SITE_ADMIN) {
                                 $editing_user->setRole($new_role);
                             }
                         }
                     }
                 }
             }
             if ($current_user->getRole() > User::ROLE_BIBER) {
                 if (($new_role = (int) $params['role']) !== false) {
                     foreach (Users::$rolenames as $id => $name) {
                         if ($id == $new_role) {
                             if ($new_role <= User::ROLE_SITE_ADMIN) {
                                 $editing_user->setRole($new_role);
                             }
                         }
                     }
                 }
             }
         }
         $editing_user->save();
         // после редактирования профиля надо посбрасывать кеш со страницы профиля
         // и со страницы редактирования профиля
         // кеш в остальных модулях истечет сам
         Users::dropCache($editing_user->id);
     } else {
         Error::CheckThrowAuth(User::ROLE_SITE_ADMIN);
     }
 }
Example #24
0
	function getEventsUsers($ids) {
		$users = Users::getByIdsLoaded($ids);
		$out = array();
		/* @var $user User */
		$i = 0;
		if (is_array($users))
			foreach ($users as $user) {
				$out[] = array(
				    'id' => $user->id,
				    'picture' => $user->getAvatar(),
				    'nickname' => $user->getNickName(),
				);
			}
		return $out;
	}
Example #25
0
 public static function buildPageTitlePart($var)
 {
     $x = explode(':', $var[1]);
     $name = false;
     if (count($x) == 3) {
         list($name, $paramtype, $paramvalue) = $x;
     }
     if (count($x) == 2) {
         list($name, $paramvalue) = $x;
         $paramtype = 'raw_get';
     }
     if ($name) {
         $val = self::parseParams($paramtype, $paramvalue);
         switch ($name) {
             case 'profile-nickname':
                 $user = Users::getByIdsLoaded(array((int) $val));
                 $user = isset($user[$val]) ? $user[$val] : false;
                 /* @var $user User */
                 if ($user) {
                     return $user->getNickName();
                 }
                 break;
             case 'book-title':
                 $book = Books::getInstance()->getByIdLoaded((int) $val);
                 /* @var $book Book */
                 return $book->getTitle(1);
                 break;
             case 'person-title':
                 $person = Persons::getInstance()->getById((int) $val);
                 /* @var $person Person */
                 return $person->getName();
                 break;
             case 'genre-title':
                 return Request::pass('genre-title');
                 break;
             case 'forum-title':
                 $t = Request::pass('forum-title');
                 if (!$t) {
                     $t = Database::sql2single('SELECT name FROM `term_data` WHERE `tid`=' . (int) $val);
                 }
                 return $t;
                 break;
             case 'post-subject':
                 return Request::pass('post-subject');
                 break;
             case 'theme-title':
                 return Request::pass('theme-title');
                 break;
             case 'serie-title':
                 $t = Request::pass('serie-title');
                 if (!$t) {
                     $t = Database::sql2single('SELECT `title` FROM `series` WHERE `id`=' . (int) $val);
                 }
                 return $t;
                 break;
             case 'shelf-name':
                 if ($val == 'loved') {
                     return 'Любимые книги';
                 }
                 if (isset(Config::$shelfIdByNames[$val])) {
                     return isset(Config::$shelves[Config::$shelfIdByNames[$val]]) ? Config::$shelves[Config::$shelfIdByNames[$val]] : $val;
                 }
                 break;
             case 'magazine-title':
                 $query = 'SELECT `title` FROM `magazines` WHERE `id`=' . (int) $val;
                 return Database::sql2single($query);
                 break;
             case 'thread-subject':
                 $query = 'SELECT `subject` FROM `users_messages` WHERE `id`=' . (int) $val;
                 return Database::sql2single($query);
                 break;
             case 'get':
                 return $val;
                 break;
             default:
                 throw new Exception('Cant process title part "' . $var[1] . '"');
                 break;
         }
     }
 }
Example #26
0
    function sendMessage($id_author, $to_users, $subject, $body, $time, $thread_id = false, $type = 0)
    {
        global $current_user;
        if (!is_array($to_users)) {
            throw new Exception('$to_users must be an array');
        }
        Database::query('START TRANSACTION');
        $query = 'INSERT INTO `users_messages` SET
			`id_author`=' . (int) $id_author . ',
			`time`=' . $time . ',
			`subject`=' . Database::escape($subject) . ',
			`html`=' . Database::escape($body);
        Database::query($query);
        // если есть тред - пишем в тот же тред
        $lastId = Database::lastInsertId();
        $thread_id = $thread_id ? $thread_id : $lastId;
        if ($thread_id) {
            $q = array();
            foreach ($to_users as $receiver_id) {
                if (!(int) $receiver_id) {
                    continue;
                }
                $to_user = new User($receiver_id);
                $to_user->reloadNewMessagesCount();
                $is_new = $receiver_id == $id_author ? 0 : 1;
                $q[] = '(' . (int) $lastId . ',' . (int) $thread_id . ',' . (int) $receiver_id . ',' . (int) $is_new . ',0,' . (int) $type . ')';
            }
            if (count($q)) {
                $query = 'INSERT INTO `users_messages_index`(message_id,thread_id,id_recipient,is_new,is_deleted,type) VALUES ' . implode(',', $q);
                Database::query($query);
            }
        }
        // increase counters
        $receivers = Users::getByIdsLoaded($to_users);
        foreach ($receivers as $receiver) {
            /* @var $receiver User */
            if ($type == 0) {
                $receiver->setCounter('new_messages', $receiver->getCounter('new_messages') + 1);
            } else {
                $receiver->setCounter('new_notifications', $receiver->getCounter('new_notifications') + 1);
            }
            $receiver->save();
        }
        if ($type == 0 && $current_user) {
            // не нотифай
            Notify::notifyNewInbox($to_users, $id_author);
        }
        Database::query('COMMIT');
    }