Пример #1
0
/**
 * Update a group
 * @return Group instance
 */
function update_group($name, $label, $ns, Userfilter $filter)
{
    $gf = new GroupFilter(new GFC_Name($name));
    $g = $gf->get(true);
    if ($g instanceof Group) {
        echo 'Updating ' . $label . ' (' . $name . ', ' . $g->id() . ') ';
        $g->select(GroupSelect::castes());
    } else {
        echo 'Creating ' . $label . ' (' . $name . ') ';
        $g = new Group();
        $g->insert();
        $g->ns($ns);
        $g->name($name);
        $g->label($label);
    }
    $c = $g->caste(Rights::member());
    $c->select(CasteSelect::base());
    $c->userfilter($filter);
    $c->compute();
    echo '... ' . $c->users()->count() . ' member(s)' . "\n";
    return $g;
}
Пример #2
0
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program; if not, write to the Free Software            *
 *  Foundation, Inc.,                                                      *
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
 ***************************************************************************/
/*
 * This script creates and updates the groups corresponding to the promos
 */
require_once dirname(__FILE__) . '/../connect.db.inc.php';
$gf = new GroupFilter(new GFC_Name('everybody'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe everybody mis à jour' . "\n";
$gf = new GroupFilter(new GFC_Name('public'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe visibilité extérieure mis à jour' . "\n";
$gf = new GroupFilter(new GFC_Name('licenses'));
$g = $gf->get(true);
$g->select(GroupSelect::castes());
$c = $g->caste(Rights::member());
$c->select(CasteSelect::base())->compute();
echo 'Groupe licenses mis à jour' . "\n";
Пример #3
0
 public function collections()
 {
     return array('targets' => CasteSelect::validate());
 }
Пример #4
0
function check_group(Group $g)
{
    global $available_rights, $formations;
    global $ufc_web, $ufc_kes, $ufc_shalom_ccx_amep, $ufc_licenses;
    $gtext = $g->id() . " (" . $g->name() . ")";
    // For each group, get castes in an array, indexed by rights
    $gc = array();
    $gcid = array();
    $g->castes()->select(CasteSelect::base());
    foreach ($g->castes() as $c) {
        $cright = (string) $c->rights();
        if (!in_array($cright, $available_rights)) {
            echo "Error: caste " . $c->id() . " has invalid rights " . $cright . "\n";
            continue;
        }
        $gcid[$cright] = intval($c->id());
        $gc[$cright] = $c;
    }
    if (!count($gc)) {
        echo "Error: user group " . $gtext . " does not have any caste !\n";
        return;
    }
    // Check userfilters
    if ($g->ns() == 'user') {
        if (!preg_match('/^user_[1-9][0-9]*$/', $g->name())) {
            echo "Warning: user group " . $gtext . " has an invalid name\n";
        }
        if (count($gc) != 2 || !isset($gc['admin']) || !isset($gc['restricted'])) {
            echo "Error: user group " . $gtext . " has invalid castes, " . implode(', ', array_keys($gc)) . "\n";
            return;
        }
        if ($gc['admin']->userfilter() != null) {
            echo "Warning: user group " . $gtext . " has an admin userfilter\n";
        }
        if ($gc['restricted']->userfilter() != null) {
            echo "Warning: user group " . $gtext . " has a restricted userfilter\n";
        }
    } else {
        // Everything else has all rights
        if (count($gc) != count($available_rights)) {
            echo $gtext . " has " . count($gc) . " castes " . implode(', ', array_keys($gc)) . "\n";
        }
        // Check restricted userfilter
        test_userfilters($gtext, 'restricted', $gc['restricted'], new UFC_Caste(array($gcid['admin'], $gcid['member'], $gcid['logic'])));
        // Check everybody userfilter
        test_userfilters($gtext, 'everybody', $gc['everybody'], new UFC_Caste(array($gcid['admin'], $gcid['member'], $gcid['logic'], $gcid['friend'])));
        // Check special group admins
        if (in_array($g->name(), array('on_platal', 'everybody', 'public', 'tol', 'postit', 'temp'))) {
            // Webmasters are automatically admins of some groups
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_web);
        } elseif ($g->name() == 'formation_x') {
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_kes);
        } elseif ($g->name() == 'adherents-kes') {
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_kes);
        } elseif ($g->name() == 'shalom-ccx-amep') {
            test_userfilters($gtext, 'admin', $gc['admin'], $ufc_shalom_ccx_amep);
        } else {
            test_userfilters($gtext, 'admin', $gc['admin']);
        }
        // Check special group members
        if ($g->name() == 'everybody') {
            test_userfilters($gtext, 'member', $gc['member'], new PFC_Not(new UFC_Uid(-1)));
        } elseif ($g->name() == 'public') {
            test_userfilters($gtext, 'member', $gc['member'], new PFC_True());
        } elseif ($g->name() == 'shalom-ccx-amep') {
            test_userfilters($gtext, 'member', $gc['member'], $ufc_shalom_ccx_amep);
        } elseif ($g->name() == 'licenses') {
            test_userfilters($gtext, 'member', $gc['member'], $ufc_licenses);
        } elseif ($g->ns() == 'promo') {
            $matches = array();
            if ($g->name() == 'on_platal') {
                $promos = array();
                if ($gc['member']->userfilter()) {
                    $data = $gc['member']->userfilter()->export();
                    for ($i = 0; isset($data['condition']['children'][$i]['promo']); $i++) {
                        // This only checks logic connectors
                        // TODO: Check years
                        $p = $data['condition']['children'][$i]['promo'];
                        $f = $data['condition']['children'][$i]['formation_id'];
                        array_push($promos, new UFC_Promo($p, '=', $f));
                    }
                }
                test_userfilters($gtext, 'member', $gc['member'], new PFC_Or($promos));
            } elseif (!preg_match('/^promo_([a-z]*)([0-9]{4})$/', $g->name(), $matches)) {
                echo "Warning: promo group " . $gtext . " has an invalid name\n";
            } else {
                $fid = $matches[1] ? (string) $formations[$matches[1]] : 0;
                test_userfilters($gtext, 'member', $gc['member'], new UFC_Promo($matches[2], '=', $fid));
            }
        } elseif ($g->ns() == 'study' || $g->name() == 'formation_fkz') {
            $matches = array();
            if (!preg_match('/^formation_([a-z]+)$/', $g->name(), $matches)) {
                echo "Warning: study group " . $gtext . " has an invalid name\n";
            } elseif (!isset($formations[$matches[1]])) {
                echo "Error: study group " . $gtext . " has an unknown formation\n";
            } else {
                test_userfilters($gtext, 'member', $gc['member'], new UFC_Study((string) $formations[$matches[1]]));
            }
        } else {
            test_userfilters($gtext, 'member', $gc['member']);
        }
        test_userfilters($gtext, 'friend', $gc['friend']);
        // Check name
        if (!$g->ns()) {
            // Empty name means it is a special group
            if (!in_array($g->name(), array('everybody', 'public', 'tol', 'postit', 'temp', 'postit', 'licenses', 'formation_fkz'))) {
                echo "Warning: group " . $gtext . " has an empty namespace\n";
            }
        } elseif ($g->ns() == 'nationality') {
            if (!preg_match('/^nation_[a-z-]+$/', $g->name())) {
                echo "Warning: nationality group " . $gtext . " has an invalid name\n";
            }
        } elseif ($g->ns() == 'course') {
            if (!preg_match('/^pa_[a-z0-9-_]+$/', $g->name()) && !preg_match('/^modal[a-z0-9-_]+$/', $g->name())) {
                echo "Warning: course group " . $gtext . " has an invalid name\n";
            }
        } elseif ($g->ns() == 'sport') {
            if (!preg_match('/^sport_[a-z]+$/', $g->name())) {
                echo "Warning: sport group " . $gtext . " has an invalid name\n";
            }
        } elseif ($g->ns() == 'bde') {
            if ($g->name() != 'adherents-kes') {
                echo "Warning: unknown BDE " . $gtext . "\n";
            }
        } elseif (!in_array($g->ns(), array('study', 'promo', 'binet', 'free'))) {
            echo "Error: Unknown NS " . $g->ns() . " for group " . $gtext . "\n";
        }
    }
}
Пример #5
0
 public function objects()
 {
     return array('writer' => UserSelect::base(), 'target' => CasteSelect::validate(), 'origin' => GroupSelect::base());
 }
Пример #6
0
 public static function see()
 {
     return new GroupSelect(array('ns', 'score', 'name', 'label', 'description', 'image', 'wikix', 'web', 'mail', 'visible', 'castes', 'leavable', 'external', 'rooms'), array('castes' => CasteSelect::base(), 'rooms' => RoomSelect::premise()));
 }
Пример #7
0
 public static function minitol()
 {
     return new UserSelect(array_merge(self::$natives, array('rooms', 'castes', 'comments', 'studies')), array('castes' => CasteSelect::group(), 'rooms' => RoomSelect::all(), 'studies' => FormationSelect::base()));
 }
Пример #8
0
 public static function gc()
 {
     return new self(array('label', 'seen', 'lastseen', 'created', 'caste'), array('caste' => CasteSelect::group()));
 }
Пример #9
0
 public static function news()
 {
     return new NewsSelect(array_merge(self::$natives, array('read', 'star')), array('writer' => UserSelect::base(), 'target' => CasteSelect::group(), 'origin' => GroupSelect::base()));
 }
Пример #10
0
 public function bubble()
 {
     $castes = $this->parents()->select(CasteSelect::bubble());
     foreach ($castes as $caste) {
         $caste->compute();
     }
 }
Пример #11
0
 function handler_mail($page)
 {
     $subject = Env::t('subject', '');
     $body = Env::t('mail_body', '');
     $no_wiki = Env::has('no_wiki');
     // Retrieve the years on_platal of each formation
     $formations = Formation::selectAll(FormationSelect::on_platal());
     if (Env::has('send')) {
         try {
             $required_fields = array('subject' => 'Il faut donner un sujet à ton mail', 'mail_body' => 'Tu ne veux pas envoyer de mail vide à tous. Si ?');
             foreach ($required_fields as $field => $msg) {
                 if (Env::v($field, '') == '') {
                     throw new Exception($msg);
                 }
             }
             if (Env::t('origin_mail_proposal') == 'false') {
                 $origin = false;
             } else {
                 $origin = new Group(Env::i('origin_mail_proposal'));
             }
             if ($origin !== false && !S::user()->hasRights($origin, Rights::admin())) {
                 throw new Exception("Invalid credentials for origin Group");
             }
             if (Env::t('type_mail_proposal') == 'group') {
                 // Mail to a group
                 list($temp, $target_group) = self::target_picker_to_caste_group('mail');
                 $target = new Collection('Caste');
                 $target->add($temp);
                 $target_group->select(GroupSelect::validate());
                 $nv = new MailValidate(array('writer' => S::user(), 'type_mail' => Env::t('type_mail_proposal'), 'origin' => $origin, 'targets' => $target, 'subject' => $subject, 'body' => $body, 'nowiki' => $no_wiki, 'formation' => $target_group));
                 $el = new Validate(array('item' => $nv, 'group' => $target_group, 'writer' => S::user(), 'type' => 'mail'));
                 $el->insert();
             } elseif (Env::t('type_mail_proposal') == 'promo') {
                 // Target group is a Collection of formation groups, which validate requests
                 $target_group = new Collection('Group');
                 // Group promos by formation
                 $promos = unflatten(Env::v('promos'));
                 $promosByFormation = array();
                 foreach ($promos as $formation_promo) {
                     $formation_promo = trim($formation_promo);
                     if (!$formation_promo) {
                         continue;
                     }
                     if (!preg_match('/^([0-9]+)_([0-9]+)$/', $formation_promo, $matches)) {
                         throw new Exception("Oops, mauvais format de destinataire.");
                     }
                     $formid = (int) $matches[1];
                     $promo = (int) $matches[2];
                     if (isset($promosByFormation[$formid])) {
                         $promosByFormation[$formid][] = $promo;
                     } else {
                         $promosByFormation[$formid] = array($promo);
                     }
                 }
                 if (empty($promosByFormation)) {
                     throw new Exception("Il faut indiquer au moins un destinataire.");
                 }
                 foreach ($promosByFormation as $formid => $promos) {
                     // Now, $promos are the list of promos of formation $formid
                     $form = $formations->get($formid);
                     // Study group are the people the mail is sent to, array of CasteFilterCondition
                     $cfc_study_groups = array();
                     foreach ($promos as $promo) {
                         if (!$form->hasPlatalYear($promo)) {
                             throw new Exception("Mauvaise promo " . $promo . " pour " . $form->label() . ".");
                         }
                         $cfc_study_groups[] = new CFC_Group($form->getGroupForPromo($promo), Rights::restricted());
                     }
                     $target = new CasteFilter(new PFC_Or($cfc_study_groups));
                     $target = $target->get();
                     $target->select(CasteSelect::validate());
                     // $target_group is the group which validates this email
                     $target_group = $form->getGroup();
                     $target_group->select(GroupSelect::validate());
                     $nv = new MailValidate(array('writer' => S::user(), 'type_mail' => Env::t('type_mail_proposal'), 'origin' => $origin, 'targets' => $target, 'subject' => $subject, 'body' => $body, 'nowiki' => $no_wiki, 'formation' => $target_group));
                     $el = new Validate(array('item' => $nv, 'group' => $target_group, 'writer' => S::user(), 'type' => 'mail'));
                     $el->insert();
                 }
             }
             $page->assign('envoye', true);
         } catch (Exception $e) {
             $page->trigError($e->getMessage());
         }
     }
     $page->assign('subject', $subject);
     $page->assign('body', $body);
     $page->assign('nowiki', $no_wiki);
     $page->assign('formations', $formations);
     $page->assign('title', 'Envoi des mails');
     $page->addCssLink('validate.css');
     $page->changeTpl('validate/prop.mail.tpl');
 }
Пример #12
0
 public static function base()
 {
     return new ActivitySelect(self::$natives, array('target' => CasteSelect::validate(), 'origin' => GroupSelect::base()));
 }