Example #1
0
             do_sql('approval', $send, 'delete', $mysqli, $where);
         } else {
             // inserting a vote
             $send['app_position_id'] = $pos_id;
             $send['app_people_id'] = $_SESSION['id'];
             do_sql('approval', $send, 'insert', $mysqli);
         }
         // update top role
         // fetching user id
         $getUID = $mysqli->prepare('SELECT position_people_id FROM position WHERE position_id=? ') or die('Couldn\'t check the userid');
         $getUID->bind_param('s', $pos_id);
         $getUID->execute();
         $getUID->store_result();
         $getUID->bind_result($user_id);
         while ($getUID->fetch()) {
             $top_role = get_top_role($user_id, $mysqli);
         }
     }
     break;
 case 'blog_add':
     if ($_POST['submit'] == 'Save & Publish') {
         $send['blog_final'] = '1';
     }
     if ($_POST['submit'] == 'Save') {
         $send['blog_final'] = '0';
     }
     $send['blog_by'] = $_SESSION['id'];
     $send['blog_title'] = htmlentities($_POST['blog_title']);
     $send['blog_created'] = date("Y-m-d H:i:s");
     /** ------------------------------------------image digestion starts---------------------------------------- **/
     // separating out all image tags
Example #2
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);
    }
}