public function testGroupList()
    {
        // recuperation de la liste de tous les groupes
        $list = jAcl2DbUserGroup::getGroupList()->fetchAll();
        $verif = '<array>
    <object>
        <string property="id_aclgrp" value="' . $this->grpId1 . '" />
        <string property="name" value="group1" />
        <string property="grouptype" value="0" />
        <null property="ownerlogin"/>
    </object>
    <object>
        <string property="id_aclgrp" value="' . $this->grpId2 . '" />
        <string property="name" value="group2" />
        <string property="grouptype" value="1" />
        <null property="ownerlogin"/>
    </object>
    <object>
        <string property="id_aclgrp" value="' . $this->grpId3 . '" />
        <string property="name" value="newgroup3" />
        <string property="grouptype" value="0" />
        <null property="ownerlogin"/>
    </object>
</array>';
        $this->assertComplexIdenticalStr($list, $verif);
    }
Пример #2
0
 /**
  * check if there is a flood
  * @param integer $timeInterval time between two actions
  * @param integer $onlySameIp  true: the flood is checked only between same ip
  * @return boolean  true if flood is detected
  */
 public static function check($timeInterval, $onlySameIp)
 {
     // since we don't store data of anonymous user, and anonymous user
     // are not allowed to post, we don't check
     if (!jAuth::isConnected()) {
         return false;
     }
     // check if the user is member of Admins (groupid 0) / Moderators (groupid 3)
     // if so, no need to stop the action of this group of users
     // FIXME we should check, not the group, but the rights !
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         if ($grp->id_aclgrp == 'admins' or $grp->id_aclgrp == 'moderators') {
             return false;
         }
     }
     $dao = jDao::get('havefnubb~posts');
     $rec = $dao->getMyLastEditedPost(jAuth::getUserSession()->id);
     if ($rec->member_last_post + $timeInterval > time()) {
         return false;
     }
     if ($onlySameIp && isset($_SERVER['REMOTE_ADDR']) && $rec->poster_ip != $_SERVER['REMOTE_ADDR']) {
         return false;
     }
     return true;
 }
Пример #3
0
 /**
  * reset/set default rights
  * @param integer $id_forum the id_forum.
  */
 public static function resetRights($id_forum)
 {
     // default 'normal' rights for a given forum.
     $id_forum = (int) $id_forum;
     $rights = self::$__defaultRights;
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         $id = $grp->id_aclgrp;
         self::setRightsOnForum($id, isset($rights[$id]) ? $rights[$id] : array(), 'forum' . $id_forum);
     }
     self::setRightsOnForum('__anonymous', $rights['__anonymous'], 'forum' . $id_forum);
 }
Пример #4
0
 function saverights()
 {
     $rep = $this->getResponse('redirect');
     $rights = $this->param('rights', array());
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         $id = intval($grp->id_aclgrp);
         jAcl2DbManager::setRightsOnGroup($id, isset($rights[$id]) ? $rights[$id] : array());
     }
     jAcl2DbManager::setRightsOnGroup(0, isset($rights[0]) ? $rights[0] : array());
     $rep->action = 'jacl2_admin~groups:index';
     return $rep;
 }
Пример #5
0
 function setdefault()
 {
     $rep = $this->getResponse('redirect');
     $groups = $this->param('groups', array());
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         $default = in_array($grp->id_aclgrp, $groups);
         jAcl2DbUserGroup::setDefaultGroup($grp->id_aclgrp, $default);
     }
     jMessage::add(jLocale::get('acl2.message.groups.setdefault.ok'), 'ok');
     $rep->action = 'jacl2db_admin~groups:index';
     return $rep;
 }
Пример #6
0
 function rights()
 {
     $rep = $this->getResponse('html');
     $user = $this->param('user');
     if (!$user) {
         $rep->body->assign('MAIN', '<p>invalid user</p>');
         return $rep;
     }
     // retrieve groups of the user
     $hisgroup = null;
     $groupsuser = array();
     foreach (jAcl2DbUserGroup::getGroupList($user) as $grp) {
         if ($grp->grouptype == 2) {
             $hisgroup = $grp;
         } else {
             $groupsuser[$grp->id_aclgrp] = $grp;
         }
     }
     // retrieve all groups
     $gid = array($hisgroup->id_aclgrp);
     $groups = array();
     $grouprights = array($hisgroup->id_aclgrp => false);
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         $gid[] = $grp->id_aclgrp;
         $groups[] = $grp;
         $grouprights[$grp->id_aclgrp] = '';
     }
     // create the list of subjects and their labels
     $rights = array();
     $subjects = array();
     $sbjgroups_localized = array();
     $rs = jDao::get('jacl2db~jacl2subject', 'jacl2_profile')->findAllSubject();
     foreach ($rs as $rec) {
         $rights[$rec->id_aclsbj] = $grouprights;
         $subjects[$rec->id_aclsbj] = array('grp' => $rec->id_aclsbjgrp, 'label' => $this->getLabel($rec->id_aclsbj, $rec->label_key));
         if ($rec->id_aclsbjgrp && !isset($sbjgroups_localized[$rec->id_aclsbjgrp])) {
             $sbjgroups_localized[$rec->id_aclsbjgrp] = $this->getLabel($rec->id_aclsbjgrp, $rec->label_group_key);
         }
     }
     $rightsWithResources = array_fill_keys(array_keys($rights), 0);
     $daorights = jDao::get('jacl2db~jacl2rights', 'jacl2_profile');
     $rs = $daorights->getRightsHavingRes($hisgroup->id_aclgrp);
     $hasRightsOnResources = false;
     foreach ($rs as $rec) {
         $rightsWithResources[$rec->id_aclsbj]++;
         $hasRightsOnResources = true;
     }
     $rs = $daorights->getRightsByGroups($gid);
     foreach ($rs as $rec) {
         $rights[$rec->id_aclsbj][$rec->id_aclgrp] = $rec->canceled ? 'n' : 'y';
     }
     $tpl = new jTpl();
     $tpl->assign(compact('hisgroup', 'groupsuser', 'groups', 'rights', 'user', 'subjects', 'sbjgroups_localized', 'rightsWithResources', 'hasRightsOnResources'));
     $tpl->assign('nbgrp', count($groups));
     if (jAcl2::check('acl.user.modify')) {
         $rep->body->assign('MAIN', $tpl->fetch('user_rights'));
     } else {
         $rep->body->assign('MAIN', $tpl->fetch('user_rights_view'));
     }
     $rep->body->assign('selectedMenuItem', 'usersrights');
     return $rep;
 }
Пример #7
0
 /**
  * function to manage data before assigning to the template of its zone
  */
 protected function _prepareTpl()
 {
     $page = (int) $this->param('page');
     $memberSearch = (string) $this->param('memberSearch');
     // get letter  in lowercase
     $letter = $this->param('letter');
     if ($letter < chr(97) or $letter > chr(123)) {
         $letter = '';
     }
     $grpid = -2;
     if ($this->param('grpid')) {
         $grpid = intval($this->param('grpid'));
     }
     $nbMembersPerPage = (int) jApp::config()->havefnubb['members_per_page'];
     $p = jAcl2Db::getProfile();
     // $memberSearch == '' means, we dont search some members by their nickname
     if ($grpid == -2) {
         //all users
         $dao = jDao::get('jacl2db~jacl2groupsofuser', $p);
         $cond = jDao::createConditions();
         $cond->addCondition('grouptype', '=', 2);
         $cond->addCondition('status', '=', 1);
         if (strlen($letter) == 1) {
             $cond->addCondition('login', 'like', $letter . '%');
         } elseif ($memberSearch != '') {
             $cond->addCondition('login', 'like', '%' . $memberSearch . '%');
         }
         $rs = $dao->findBy($cond, $page, $nbMembersPerPage);
         $nbMembers = $dao->countBy($cond);
     } else {
         //in a specific group
         $dao = jDao::get('jacl2db~jacl2usergroup', $p);
         if ($letter == '') {
             $rs = $dao->getPublicUsersGroupLimit($grpid, $page, $nbMembersPerPage);
         } else {
             $rs = $dao->getPublicUsersByLetterGroupLimit($grpid, $page, $nbMembersPerPage, $letter . '%');
         }
         $nbMembers = $dao->getUsersGroupCount($grpid);
     }
     $members = array();
     $dao2 = jDao::get('jacl2db~jacl2groupsofuser', $p);
     foreach ($rs as $u) {
         $u->groups = array();
         $gl = $dao2->getGroupsUser($u->login);
         foreach ($gl as $g) {
             if ($g->grouptype != 2 and $g->status == 1) {
                 $u->groups[] = $g;
             }
         }
         $members[] = $u;
     }
     $groups = array();
     $o = new StdClass();
     $o->id_aclgrp = '-2';
     $o->name = jLocale::get('havefnubb~member.memberlist.allgroups');
     $o->grouptype = 0;
     $groups[] = $o;
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         $groups[] = $grp;
     }
     $letters[] = jLocale::get('havefnubb~member.memberlist.select.an.initial.nickname');
     for ($i = 0; $i < 26; $i++) {
         $letters[] = chr(97 + $i);
     }
     $daoRank = jDao::get('havefnubb~ranks');
     $ranks = $daoRank->findAll();
     // let's build the pagelink var
     // A Preparing / Collecting datas
     // 0- the properties of the pager
     $properties = array('start-label' => '', 'prev-label' => '', 'next-label' => '', 'end-label' => jLocale::get("havefnubb~member.pagelinks.end"), 'area-size' => 5);
     // 1- vars for pagelinks
     $this->_tpl->assign('groups', $groups);
     $this->_tpl->assign('page', $page);
     $this->_tpl->assign('nbMembersPerPage', $nbMembersPerPage);
     $this->_tpl->assign('properties', $properties);
     $this->_tpl->assign('members', $members);
     $this->_tpl->assign('nbMembers', $nbMembers);
     $this->_tpl->assign('letters', $letters);
     $this->_tpl->assign('ranks', $ranks);
 }
 /**
  * Dynamically update form by modifying the filter by login control
  *
  * @param object $form Jelix form to modify control.
  * @param string $save does the form will be used for update or insert.
  * @return modified form.
  */
 private function updateFormByLogin($form, $save)
 {
     if (!is_array($this->loginFilteredLayers)) {
         //&& $this->loginFilteredOveride )
         $this->filterDataByLogin($this->layerName);
     }
     if (is_array($this->loginFilteredLayers)) {
         $type = $this->loginFilteredLayers['type'];
         $attribute = $this->loginFilteredLayers['attribute'];
         // Check if a user is authenticated
         if (!jAuth::isConnected()) {
             return True;
         }
         $user = jAuth::getUserSession();
         if (!$this->loginFilteredOveride) {
             if ($type == 'login') {
                 $user = jAuth::getUserSession();
                 $form->setData($attribute, $user->login);
                 $form->setReadOnly($attribute, True);
             } else {
                 $oldCtrl = $form->getControl($attribute);
                 $userGroups = jAcl2DbUserGroup::getGroups();
                 $userGroups[] = 'all';
                 $uGroups = array();
                 foreach ($userGroups as $uGroup) {
                     if ($uGroup != 'users' and substr($uGroup, 0, 7) != "__priv_") {
                         $uGroups[$uGroup] = $uGroup;
                     }
                 }
                 $dataSource = new jFormsStaticDatasource();
                 $dataSource->data = $uGroups;
                 $ctrl = new jFormsControlMenulist($attribute);
                 $ctrl->required = true;
                 if ($oldCtrl != null) {
                     $ctrl->label = $oldCtrl->label;
                 } else {
                     $ctrl->label = $attribute;
                 }
                 $ctrl->datasource = $dataSource;
                 $value = null;
                 if ($oldCtrl != null) {
                     $value = $form->getData($attribute);
                     $form->removeControl($attribute);
                 }
                 $form->addControl($ctrl);
                 if ($value != null) {
                     $form->setData($attribute, $value);
                 }
             }
         } else {
             $oldCtrl = $form->getControl($attribute);
             $value = null;
             if ($oldCtrl != null) {
                 $value = $form->getData($attribute);
             }
             $data = array();
             if ($type == 'login') {
                 $plugin = jApp::coord()->getPlugin('auth');
                 if ($plugin->config['driver'] == 'Db') {
                     $authConfig = $plugin->config['Db'];
                     $dao = jDao::get($authConfig['dao'], $authConfig['profile']);
                     $cond = jDao::createConditions();
                     $cond->addItemOrder('login', 'asc');
                     $us = $dao->findBy($cond);
                     foreach ($us as $u) {
                         $data[$u->login] = $u->login;
                     }
                 }
             } else {
                 $gp = jAcl2DbUserGroup::getGroupList();
                 foreach ($gp as $g) {
                     if ($g->id_aclgrp != 'users') {
                         $data[$g->id_aclgrp] = $g->id_aclgrp;
                     }
                 }
                 $data['all'] = 'all';
             }
             $dataSource = new jFormsStaticDatasource();
             $dataSource->data = $data;
             $ctrl = new jFormsControlMenulist($attribute);
             $ctrl->required = true;
             if ($oldCtrl != null) {
                 $ctrl->label = $oldCtrl->label;
             } else {
                 $ctrl->label = $attribute;
             }
             $ctrl->datasource = $dataSource;
             $form->removeControl($attribute);
             $form->addControl($ctrl);
             if ($value != null) {
                 $form->setData($attribute, $value);
             } else {
                 if ($type == 'login') {
                     $form->setData($attribute, $user->login);
                 }
             }
         }
     }
     return True;
 }
Пример #9
0
 function rights()
 {
     $rep = $this->getResponse('html');
     $user = $this->param('user');
     if (!$user) {
         $rep->body->assign('MAIN', '<p>invalid user</p>');
         return $rep;
     }
     $hisgroup = null;
     $groupsuser = array();
     foreach (jAcl2DbUserGroup::getGroupList($user) as $grp) {
         if ($grp->grouptype == 2) {
             $hisgroup = $grp;
         } else {
             $groupsuser[$grp->id_aclgrp] = $grp;
         }
     }
     $gid = array($hisgroup->id_aclgrp);
     $groups = array();
     $grouprights = array($hisgroup->id_aclgrp => false);
     foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
         $gid[] = $grp->id_aclgrp;
         $groups[] = $grp;
         $grouprights[$grp->id_aclgrp] = false;
     }
     $rights = array();
     $p = jAcl2Db::getProfile();
     $rs = jDao::get('jelix~jacl2subject', $p)->findAllSubject();
     foreach ($rs as $rec) {
         $rights[$rec->id_aclsbj] = $grouprights;
     }
     $rightsWithResources = array_fill_keys(array_keys($rights), 0);
     $daorights = jDao::get('jelix~jacl2rights', $p);
     $rs = $daorights->getRightsHavingRes($hisgroup->id_aclgrp);
     $hasRightsOnResources = false;
     foreach ($rs as $rec) {
         $rightsWithResources[$rec->id_aclsbj]++;
         $hasRightsOnResources = true;
     }
     $rs = $daorights->getRightsByGroups($gid);
     foreach ($rs as $rec) {
         $rights[$rec->id_aclsbj][$rec->id_aclgrp] = true;
     }
     $tpl = new jTpl();
     $tpl->assign(compact('hisgroup', 'groupsuser', 'groups', 'rights', 'user', 'rightsWithResources', 'hasRightsOnResources'));
     $tpl->assign('nbgrp', count($groups));
     if (jAcl2::check('acl.user.modify')) {
         $rep->body->assign('MAIN', $tpl->fetch('user_rights'));
     } else {
         $rep->body->assign('MAIN', $tpl->fetch('user_rights_view'));
     }
     $rep->body->assign('selectedMenuItem', 'usersrights');
     return $rep;
 }
Пример #10
0
 function saveedit()
 {
     $id_forum = (int) $this->param('id_forum');
     $submit = $this->param('validate');
     if ($submit == jLocale::get('hfnuadmin~forum.saveBt')) {
         $form = jForms::fill('hfnuadmin~forum_edit', $id_forum);
         if (!$form->check()) {
             jMessage::add(jLocale::get('hfnuadmin~forum.unknown.forum'), 'error');
             $rep = $this->getResponse('redirect');
             $rep->action = 'hfnuadmin~forum:edit';
             $rep->params = array('id_forum' => $id_forum);
             return $rep;
         }
         $form->saveToDao('havefnubb~forum');
     }
     $submitRight = $this->param('validateright');
     if ($submitRight == jLocale::get('hfnuadmin~forum.saveBt')) {
         $hfnuadminrights = jClasses::getService("hfnuadmin~hfnuadminrights");
         $rights = $this->param('rights', array());
         foreach (jAcl2DbUserGroup::getGroupList() as $grp) {
             $id = $grp->id_aclgrp;
             $hfnuadminrights->setRightsOnForum($id, isset($rights[$id]) ? $rights[$id] : array(), 'forum' . $id_forum);
         }
         $hfnuadminrights->setRightsOnForum('__anonymous', isset($rights['__anonymous']) ? $rights['__anonymous'] : array(), 'forum' . $id_forum);
     }
     $rep = $this->getResponse('redirect');
     $rep->action = 'hfnuadmin~forum:index';
     return $rep;
 }