Example #1
0
 private function onAdd()
 {
     $form = $this->getForm();
     if (false !== ($err = $form->validate($this->module))) {
         return $err . $this->templateAdd();
     }
     $group = new GWF_Group(array('group_id' => 0, 'group_name' => $form->getVar('groupname'), 'group_options' => GWF_Group::FULL | GWF_Group::SCRIPT, 'group_lang' => 0, 'group_country' => 0, 'group_founder' => 0, 'group_memberc' => 0, 'group_bid' => 0, 'group_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND)));
     if (false === $group->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd();
     }
     return $this->module->message('msg_group_added');
 }
Example #2
0
 private function templateUsers(GWF_Group $group)
 {
     $users = GDO::table('GWF_User');
     $gid = $group->getVar('group_id');
     $gn = $group->urlencode('group_name');
     $by = Common::getGet('by', '');
     $dir = Common::getGet('dir', '');
     $orderby = $users->getMultiOrderby($by, $dir);
     $ipp = 50;
     $nItems = $group->getVar('group_memberc');
     $nPages = GWF_PageMenu::getPagecount($ipp, $nItems);
     $page = Common::clamp(Common::getGetInt('page', 1), 1, $nPages);
     $from = GWF_PageMenu::getFrom($page, $ipp);
     $ug = GWF_TABLE_PREFIX . 'usergroup';
     $hidden = GWF_UserGroup::HIDDEN;
     $conditions = "(SELECT 1 FROM {$ug} WHERE ug_userid=user_id AND ug_groupid={$gid} AND ug_options&{$hidden}=0)";
     $tVars = array('sort_url' => GWF_WEB_ROOT . 'users_in_group/' . $gid . '/' . $gn . '/by/%BY%/%DIR%/page-1', 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . sprintf('users_in_group/%s/%s/by/%s/%s/page-%%PAGE%%', $gid, $gn, urlencode($by), urlencode($dir))), 'users' => $users->selectObjects('*', $conditions, $orderby, $ipp, $from));
     return $this->module->templatePHP('users.php', $tVars);
 }
Example #3
0
 private function onJoin($array)
 {
     if (false !== ($error = GWF_Form::validateCSRF_WeakS())) {
         return GWF_HTML::error('Join Group', $error);
     }
     if (false === ($group = GWF_Group::getByID(key($array)))) {
         return $this->module->error('err_unk_group');
     }
     return $this->module->getMethod('Join')->onQuickJoin($group, GWF_User::getStaticOrGuest());
 }
Example #4
0
 private static function installForumDefaults(Module_Forum $module)
 {
     $back = '';
     $module->cachePostcount();
     # Install Root Board
     $back .= self::installRoot($module);
     # Install Moderator group
     if (false === GWF_Group::getByName('moderator')) {
         $moderator = new GWF_Group(array('group_name' => 'moderator'));
         if (false === $moderator->insert()) {
             return GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__);
         }
     }
     $back = '';
     if ($module->cfgLangBoards()) {
         $back = self::installLangBoards($module);
     }
     # Make Admins and Staff become Moderator
     return $back . self::installAdminToMod($module) . self::installAttachments($module);
 }
Example #5
0
 private function createBoard(GWF_Group $group)
 {
     $name = $group->getName();
     $pid = $this->module->getForumBoard()->getID();
     //		$pid = Common::clamp($this->module->cfgBID(), 1);
     if (false === GWF_ForumBoard::getByID($pid)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $groupid = $group->getID();
     $options = GWF_ForumBoard::ALLOW_THREADS;
     if (false === ($board = GWF_ForumBoard::createBoard('Usergroup: ' . $name, 'Board for the ' . $name . ' group', $pid, $options, $groupid))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $group->saveVar('group_bid', $board->getID())) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false !== ($error = $this->module->adjustFlags($group))) {
         return $error;
     }
     return false;
 }
Example #6
0
 public function onRemFromGroup($uid)
 {
     $uid = (int) $uid;
     $gid = $this->group->getID();
     if (false === GDO::table('GWF_UserGroup')->deleteWhere("ug_userid={$uid} AND ug_groupid={$gid}")) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === GWF_UserGroup::fixGroupMC()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_removed_from_grp', array(GWF_User::getByID($uid)->displayUsername(), $this->group->display('group_name')));
 }
Example #7
0
 private static function createGroups(Module_Audit $module, $dropTable)
 {
     $table = GDO::table('GWF_Group');
     $groups = array('live', 'auditor', 'sysmin', 'poweruser');
     foreach ($groups as $group) {
         if (false !== GWF_Group::getByName($group)) {
             continue;
         }
         if (false === $table->insertAssoc(array('group_name' => $group, 'group_lang' => 1, 'group_date' => GWF_Time::getDate()))) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     return '';
 }
Example #8
0
 private function getAdminProfiles()
 {
     $admin = GWF_Group::getByName('admin')->getID();
     $u = GWF_TABLE_PREFIX . 'user';
     $ug = GWF_TABLE_PREFIX . 'usergroup';
     $db = gdo_db();
     $query = "SELECT user_name FROM {$ug} AS ug INNER JOIN {$u} AS u ON u.user_id=ug_userid WHERE ug_groupid={$admin}";
     if (false === ($result = $db->queryRead($query))) {
         return '';
     }
     $back = '';
     while (false !== ($row = $db->fetchRow($result))) {
         $name = $row[0];
         $back .= sprintf(', <a href="%s">%s</a>', GWF_WEB_ROOT . 'profile/' . urlencode($name), GWF_HTML::display($name));
     }
     $db->free($result);
     return substr($back, 2);
 }
Example #9
0
 public function onAddToGroup(GWF_User $user)
 {
     $form = $this->getFormAdd($user);
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $user->loadGroups();
     if (false === ($group = GWF_Group::getByID($form->getVar('groups')))) {
         return $this->module->error('err_group');
     }
     if ($user->isInGroupName($group->getName())) {
         return $this->module->error('err_in_group');
     }
     if (false === GWF_UserGroup::addToGroup($user->getID(), $group->getID())) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_added_to_grp', array($user->displayUsername(), $group->display('group_name')));
 }
Example #10
0
 public function execute()
 {
     if (false === ($mod_c = GWF_Module::loadModuleDB('Comments', true, true))) {
         return GWF_HTML::err('ERR_MODULE_MISSING', array('Comments'));
     }
     if (false === ($news = GWF_News::getByID(Common::getGetString('newsid')))) {
         return $this->module->error('err_news');
     }
     $key = $news->getCommentsKey();
     $gid = GWF_Group::getByName(GWF_Group::MODERATOR)->getID();
     if (false === ($comments = GWF_Comments::getOrCreateComments($key, 0, $gid))) {
         return $this->module->error('err_news');
     }
     $_REQUEST['cmts_id'] = $comments->getID();
     $back = '';
     if (isset($_POST['reply'])) {
         return $this->onReply($mod_c, $news, $comments);
     }
     return $back . $this->templateComments($mod_c, $news, $comments);
 }
Example #11
0
 private function acceptByToken($token)
 {
     $uid = (int) Common::getGet('uid');
     $gid = (int) Common::getGet('gid');
     if (false === ($group = GWF_Group::getByID($gid))) {
         return GWF_HTML::err('ERR_UNKNOWN_GROUP');
     }
     if (false === ($request = GWF_UsergroupsInvite::getRequestRow($uid, $gid))) {
         return GWF_HTML::err('ERR_NO_PERMISSION');
     }
     if (false === ($user = GWF_User::getByID($uid))) {
         return GWF_HTML::err('ERR_UNKNOWN_USER');
     }
     if ($token !== $request->getHashcode()) {
         return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     if (false === GWF_UserGroup::addToGroup($uid, $gid)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_joined', array($group->getName()));
 }
Example #12
0
 /**
  * Check if we have permission to view that link. In case we do, return empty string. else return verbose permission text.
  * @param Module_Links $module
  * @param GWF_User $user
  * @return string
  */
 public function getPermissionText(Module_Links $module, $user)
 {
     static $text = NULL;
     if ($text === NULL) {
         $text = array($module->lang('permtext_in_mod'), $module->lang('permtext_score', array('%1%')), $module->lang('permtext_member'), $module->lang('permtext_group', array('%1%')));
     }
     if ($this->isInModeration()) {
         return $text[0];
     }
     $score = $user === false ? 0 : $user->getLevel();
     # Check score
     $need_score = $this->getVar('link_score');
     if ($score < $need_score) {
         return str_replace('%1%', $need_score, $text[1]);
     }
     # Check memberlink
     if ($user === false && $this->isMemberLink()) {
         return $text[2];
     }
     # Check group
     $need_gid = $this->getGroupID();
     if ($need_gid > 0) {
         if ($user === false || !$user->isInGroupID($need_gid)) {
             return str_replace('%1%', GWF_Group::getByID($need_gid)->displayName(), $text[3]);
         }
     }
     return '';
 }
Example #13
0
 public function mayDownload($user, GWF_Download $download)
 {
     if ($user === false) {
         # Guest
         if (!$download->isEnabled()) {
             return $this->error('err_disabled');
         }
         if ($download->isAdult()) {
             return $this->error('err_adult');
         }
         if (!$download->isOptionEnabled(GWF_Download::GUEST_DOWNLOAD)) {
             return $this->error('err_guest');
         }
         if (!$this->cfgAnonDown()) {
             return $this->error('err_guest');
         }
         return false;
     } else {
         $user instanceof GWF_User;
         # Admin
         if ($user->isAdmin()) {
             return false;
         }
         if (!$download->isEnabled()) {
             return $this->error('err_disabled');
         }
         if ($download->isAdult() && !$user->wantsAdult()) {
             return $this->error('err_adult');
         }
         # Level
         if ($download->getVar('dl_level') > $user->getVar('user_level')) {
             return $this->error('err_level', $download->getVar('dl_level'));
         }
         # Group
         $gid = $download->getVar('dl_gid');
         if (false === ($group = GWF_Group::getByID($gid))) {
         } elseif ($gid > 0 && !$user->isInGroupID($download->getVar('dl_gid'))) {
             return $this->error('err_group', $group->display('group_name'));
         }
         return false;
     }
 }
Example #14
0
 public function adjustFlags(GWF_Group $group)
 {
     if (false === ($mod_forum = GWF_Module::getModule('Forum'))) {
         return false;
     }
     $mod_forum->onInclude();
     if (false === ($board = GWF_ForumBoard::getByID($group->getBoardID()))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     # Adjust Board and Thread Flags
     $gid = 0;
     $guestview = true;
     switch ($group->getVisibleMode()) {
         case GWF_Group::VISIBLE:
             //				$board->saveVar('board_gid', 0);
             //				$board->saveGuestView(true);
             //				$board->saveOption(GWF_ForumBoard::GUEST_VIEW, true);
             //				$this->adjustThreads($board, 0, true);
             //				return false;
             break;
         case GWF_Group::COMUNITY:
             //				$board->saveVar('board_gid', 0);
             //				$board->saveGuestView(false);
             //				$board->saveOption(GWF_ForumBoard::GUEST_VIEW, false);
             $guestview = false;
             break;
         case GWF_Group::HIDDEN:
         case GWF_Group::SCRIPT:
             //				$board->saveVar('board_gid', $group->getID());
             //				$board->saveGuestView(false);
             //				$board->saveOption(GWF_ForumBoard::GUEST_VIEW, false);
             $gid = $group->getID();
             $guestview = false;
             break;
         default:
             return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     $board->saveGroupID($gid);
     $board->saveGuestView($guestview);
 }
Example #15
0
 public function validate_groupid($arg)
 {
     $arg = (int) $arg;
     if ($arg === 0) {
         return false;
     }
     if (false === ($group = GWF_Group::getByID($arg))) {
         return $this->lang('err_groupid');
     }
     return false;
 }
Example #16
0
 public static function createAdmin($username, $password, $email, &$output)
 {
     if (false === ($user = GWF_User::getByName($username))) {
         $user = new GWF_User(array('user_name' => $username, 'user_email' => $email, 'user_password' => GWF_Password::hashPasswordS($password), 'user_regdate' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'user_regip' => GWF_IP6::getIP(GWF_IP_EXACT), 'user_lastactivity' => time()));
         if (false === $user->insert()) {
             return false;
         }
     }
     $userid = $user->getID();
     if (false === GWF_UserGroup::addToGroup($userid, GWF_Group::getByName(GWF_Group::ADMIN)->getID())) {
         return false;
     }
     if (false === GWF_UserGroup::addToGroup($userid, GWF_Group::getByName(GWF_Group::STAFF)->getID())) {
         return false;
     }
     $output .= GWF_HTML::message('Install Wizard', sprintf('Added new admin user: %s - Password: [censored]', $username));
     return true;
 }
Example #17
0
 private static function sendMails(Module_Audit $module, GWF_AuditLog $log, $mode = 1)
 {
     if (!$log->isScript()) {
         return true;
     }
     $gid1 = GWF_Group::getByName('auditor')->getID();
     if ($log->isRoot()) {
         $gid2 = GWF_Group::getByName('sysmin')->getID();
         $where = "(ug_groupid={$gid1} OR ug_groupid={$gid2})";
     } elseif ($mode === 1) {
         $gid3 = GWF_Group::getByName('live')->getID();
         $where = "(ug_groupid={$gid3})";
     } else {
         $where = "(ug_groupid={$gid1})";
     }
     $users = GDO::table('GWF_UserGroup');
     if (false === ($result = $users->select('DISTINCT(ug_userid),user.*', $where, '', array('user')))) {
         echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return false;
     }
     while (false !== ($user = $users->fetch($result, 'GWF_User'))) {
         switch ($mode) {
             case 1:
                 self::sendMailGo($module, $user, $log);
                 break;
             case 2:
                 self::sendMailDone($module, $user, $log);
                 break;
         }
     }
     $users->free($result);
     if ($mode == 2) {
         self::sendMailDoneUser($module, $log);
     }
     return true;
 }
Example #18
0
		</div>
		<h3><?php 
        echo GWF_HTML::display($news['newst_title']);
        ?>
</h3>
		<div class="cb"></div>
	</div>
	<?php 
        #if ($is_staff) { echo '<div class="gwf_newsbox_translate">'.$news->getTranslateSelect().'</div>'; }
        ?>
	<?php 
        $more = '';
        if ($module->cfgAllowComments()) {
            if (false !== ($comments = GWF_Module::loadModuleDB('Comments', true, true, true))) {
                $comments instanceof Module_Comments;
                $gid = GWF_Group::getByName(GWF_Group::MODERATOR)->getID();
                if (false !== ($c = GWF_Comments::getOrCreateComments('_NEWS_ID_' . $news['news_id'], 0, $gid))) {
                }
                $c instanceof GWF_Comments;
                //			$more .= '<br/>'.$c->displayMore($tVars['href_comments_more']);
                //			$more .= '<br/>'.$c->displayTopComments();
                //			$more .= '<br/>'.$c->displayReplyForm($tVars['href_comments_reply']);
                $more .= '<br/>' . $c->displayMore();
                $more .= '<br/>' . $c->displayTopComments();
                $more .= '<br/>' . $c->displayReplyForm();
            }
        }
        ?>

	<article class="gwf_newsbox_message"><?php 
        echo GWF_Message::display($news['newst_message']) . $more;
Example #19
0
 private function onInviteJoin(GWF_Group $group, GWF_User $user)
 {
     if (false === ($invite = GWF_UsergroupsInvite::getInviteRow($user->getID(), $group->getID()))) {
         return $this->module->error('err_not_invited');
     }
     if ($invite->getVar('ugi_type') !== 'invite') {
         return $this->module->error('err_not_invited');
     }
     if (false === $invite->delete()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->onQuickJoin($group, $user);
 }
Example #20
0
 /**
  * Validate a group ID.
  * @param GWF_Module $m
  * @param $key
  * @param $arg
  * @param boolean $unset
  * @param boolean $allow_zero
  */
 public static function validateGroupID($m, $key, $arg, $unset = true, $allow_zero = false)
 {
     $_POST[$key] = $arg = trim($arg);
     if ($allow_zero && $arg == 0) {
         $arg = '0';
         return false;
     }
     if (false !== GWF_Group::getByID($arg)) {
         return false;
     }
     if ($unset) {
         unset($_POST[$key]);
     }
     return $m->lang('err_' . $key, array(3, GWF_Group::NAME_LEN));
 }
Example #21
0
 private function formDelete(GWF_Group $group)
 {
     $data = array('del_groupname' => array(GWF_Form::STRING, '', $this->module->lang('th_del_groupname'), $this->module->lang('tt_del_groupname')), 'del_confirm' => array(GWF_Form::SUBMIT, $this->module->lang('btn_del_group', array($group->display('group_name')))));
     return new GWF_Form($this, $data);
 }