예제 #1
0
function role_update($mysqli)
{
    include 'db-config.php';
    // get the person for whom this position as meant to be
    $getPosName = $mysqli->prepare('SELECT position_lastUpdate,position_id,position_code,position_people_id FROM position WHERE 1') or die('Couldn\'t check the vote.');
    $getPosName->execute();
    $getPosName->store_result();
    $getPosName->bind_result($pos_last_updates, $pos_id, $pos_code, $pos_ppl);
    $base = 0;
    while ($getPosName->fetch()) {
        $pos_deletion_score = get_deletion_on_position($pos_id, $mysqli);
        $then = strtotime($pos_last_updates);
        $now = time();
        $diff = $now - $then;
        $year_diff = date('Y', $diff);
        $mon_diff = date('n', $diff);
        $day_diff = date('j', $diff);
        // checking if 7 days have expired since last update
        if ($year_diff > 1970 || $mon_diff > 1) {
            $day_diff = 8;
        }
        if ($day_diff > $expiry_days && is_role_active($pos_id, $mysqli) || $pos_deletion_score > $position_deletion_ceil) {
            // check if he is active or his deletion status is high
            $sql = "DELETE FROM position WHERE position_id='" . $pos_id . "'";
            // delete from positions
            if ($mysqli->query($sql) === false) {
                trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);
            } else {
                $affected_rows = $mysqli->affected_rows;
            }
            $sql = "DELETE FROM approval WHERE app_position_id='" . $pos_id . "'";
            // delete from approvals
            if ($mysqli->query($sql) === false) {
                trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $mysqli->error, E_USER_ERROR);
            } else {
                $affected_rows = $mysqli->affected_rows;
            }
        }
    }
    // Updating the topCode
    $getPplName = $mysqli->prepare('SELECT people_id FROM people WHERE people_archive=0') or die('Couldn\'t check the ppl.');
    $getPplName->execute();
    $getPplName->store_result();
    $getPplName->bind_result($ppl_id);
    while ($getPplName->fetch()) {
        $where['people_id'] = $ppl_id;
        $upd['people_topCode'] = get_top_role($ppl_id, $mysqli);
        do_sql('people', $upd, 'update', $mysqli, $where);
    }
}
예제 #2
0
파일: users.php 프로젝트: bitsapien/stuchx
			<th> Name </th>
			<th> Edit Profile</th>
			<th> Roles </th>
			<th> Delete </th>
			<th> Last Login </th>
			</tr>
	      </thead>
	      ';
$i = 0;
while ($getInfo->fetch()) {
    $roles_edit = '<a href="#" class= "" data-toggle="modal" data-target="#positions_modal" title="Edit" onclick="getPosition(' . $id . ',\'' . $name . '\');" ><span class="fa fa-star"></span></a>';
    // remove add role for user himself
    if ($id == $_SESSION['id']) {
        $roles_edit = '<span class="fa fa-times"></span>';
    }
    $deletionScore = get_deletion_on_position($id, $mysqli);
    // check if deletion flag has been put
    $exclaim = '<tr>';
    $alert_del = '';
    if ($deletionScore > $people_deletion_ceil - 0.3) {
        $exclaim = '<tr class="alert alert-danger">';
        $alert_del = '<p><small style="color:red;">Marked for deletion with a high vote.</small>';
    }
    // check if the person has made a delete request
    $getDel = $mysqli->prepare('SELECT deletion_tbl_id FROM deletion WHERE deletion_people_id=? AND deletion_tbl=? AND deletion_tbl_id=?') or die('Couldn\'t check the deletion');
    $tbl = 'people';
    $getDel->bind_param('sss', $_SESSION['id'], $tbl, $id);
    $getDel->execute();
    $getDel->store_result();
    $countRows = $getDel->num_rows;
    if ($countRows == 0) {