Esempio n. 1
0
function bulletin_add($period_id)
{
    global $pdo, $srcdir;
    include_once $srcdir . '/libs/bocal.php';
    $req = 'SELECT * ' . 'FROM marks ' . 'LEFT JOIN participations ON mark_participation = part_id ' . 'LEFT JOIN users ON mark_user = user_id ' . 'WHERE part_status = \'ACCEPTED\' ' . 'AND mark_period = ?';
    $sql = $pdo->prepare($req);
    $sql->bindValue(1, $period_id);
    $sql->execute();
    $users = array();
    $bocal = new Bocal();
    while ($mark = $sql->fetch()) {
        if ($mark['user_login'] == "") {
            continue;
        }
        $buser = $bocal->getUser($mark['user_login']);
        if ($buser['school'] != "epitech" || $buser['promo'] < date('Y')) {
            continue;
            //Skip no Epitech students and old promotions
        }
        isset($users[$mark['mark_user']]) || ($users[$mark['mark_user']] = array());
        $users[$mark['mark_user']][] = array("label" => $mark['part_title'], "duration" => $mark['part_duration'] * $mark['mark_mark'] / 20);
    }
    $ins = $pdo->prepare('INSERT INTO bulletin_user ' . '(bu_period, bu_user, bu_data) ' . 'VALUES (?, ?, ?)');
    $ins->bindValue(1, $period_id);
    foreach ($users as $userid => $details) {
        $ins->bindValue(2, $userid);
        $ins->bindValue(3, serialize($details));
        $ins->execute();
    }
}
Esempio n. 2
0
/**
 * Détails d'un utilisateur
 * Et optionnellement sa vie.
 */
function user_view()
{
    global $pdo, $tpl, $srcdir;
    $utime = microtime(true);
    $sql = $pdo->prepare('SELECT * FROM users LEFT JOIN user_types ON ut_id = user_type WHERE user_id = ?');
    $sql->bindValue(1, $_REQUEST['user']);
    $sql->execute();
    $user = $sql->fetch();
    $tpl->assign('user', $user);
    $sql = $pdo->prepare('SELECT * FROM user_sections LEFT JOIN sections ON section_id = us_section WHERE us_user = ?');
    $sql->bindValue(1, $user['user_id']);
    $sql->execute();
    $sections = array();
    while ($line = $sql->fetch()) {
        $sections[] = $line['section_id'];
        $tpl->append('sections', $line);
    }
    //List events
    $sql = $pdo->prepare('SELECT * FROM event_staff' . ' LEFT JOIN events ON event_id = est_event' . ' LEFT JOIN sections ON section_id = est_section' . ' WHERE est_user = ?' . ' ORDER BY event_start DESC');
    $sql->bindValue(1, $user['user_id']);
    $sql->execute();
    while ($event = $sql->fetch(PDO::FETCH_ASSOC)) {
        $tpl->append('events', $event);
    }
    $sql = $pdo->prepare('SELECT * FROM sections WHERE section_type = "primary"');
    $sql->execute();
    while ($line = $sql->fetch()) {
        if (!in_array($line['section_id'], $sections)) {
            $tpl->append('section_list', $line);
        }
    }
    $mdt = new Modele('user_mandate');
    $mdt->find(array('um_user' => $_REQUEST['user']));
    while ($mdt->next()) {
        $tpl->append('mandates', $mdt->um_mandate);
    }
    $mdl = new Modele('card');
    $mdl->find(array('card_user' => $_REQUEST['user']));
    while ($l = $mdl->next()) {
        $o = new Modele('card');
        $o->fetch($mdl->card_id);
        $tpl->append('cards', $o);
    }
    require_once $srcdir . '/libs/GoogleApi.php';
    $api = new GoogleApi();
    $mls = $api->findUserGroups($user['user_email']);
    $groups = array();
    if (isset($mls->groups)) {
        $tpl->assign('groups', $mls->groups);
        foreach ($mls->groups as $group) {
            $groups[] = $group->email;
        }
    }
    $allGroups = $api->getGroupsList();
    foreach ($allGroups->groups as $group) {
        if (!in_array($group->email, $groups)) {
            $tpl->append('otherGroups', $group);
        }
    }
    //Get Bocal data
    if ($user['user_login']) {
        include_once $srcdir . '/libs/bocal.php';
        $bocal = new Bocal();
        $bdata = $bocal->getUser($user['user_login']);
        $tpl->assign('bocal', $bdata);
        if ($bdata !== false) {
            include_once $srcdir . '/libs/intra.php';
            $intra = new EIntranet();
            $tpl->assign('intra', $intra->getUserInfos($user['user_login']));
        }
    }
    //Get activities
    $sql = $pdo->prepare('SELECT * FROM marks ' . 'LEFT JOIN participations ON part_id = mark_participation ' . 'LEFT JOIN sections ON part_section = section_id ' . 'LEFT JOIN events ON part_event = event_id ' . 'WHERE mark_user = ? ' . 'ORDER BY part_attribution_date DESC');
    $sql->bindValue(1, $user['user_id']);
    $sql->execute();
    while ($line = $sql->fetch()) {
        $tpl->append('activities', $line);
    }
    //Compta
    $mdl = new Modele('user_accounts');
    $mdl->find(array('ua_user' => $user['user_id']));
    $accounts = array(array('ua_id' => 0, 'ua_identifier' => 'Chèque', 'ua_type' => 'cheq', 'ua_number' => ''));
    while ($mdl->next()) {
        $accounts[] = $mdl->toArray();
    }
    $tpl->assign('accounts', $accounts);
    //Fin compta
    $tpl->assign('time', microtime(true) - $utime);
    $tpl->display('user_details.tpl');
    quit();
}