Exemplo n.º 1
0
 private static function validateaddVote($input)
 {
     if (CookiesManager::GetUserState() != 'closed') {
         foreach ($input as $key => $value) {
             switch ($key) {
                 case "stance":
                     if (is_bool($input[$key])) {
                         $validity['stance'] = 'valid';
                         break;
                     } else {
                         $validity['stance'] = 'invalid';
                         break;
                     }
                 case "comment":
                     if (is_string($input[$key])) {
                         $input[$key] = trim($input[$key]);
                         if (strlen($input[$key]) <= 350) {
                             $validity['comment'] = 'valid';
                             break;
                         } else {
                             $validity['comment'] = 'invalid';
                             break;
                         }
                     } else {
                         $validity['comment'] = 'invalid';
                         break;
                     }
                 default:
                     return false;
             }
         }
         return $validity;
     } else {
         echo CookiesManager::GetUserState();
         return false;
     }
 }
Exemplo n.º 2
0
 public static function insertRegVote($pID, $uID, $vStance, $vComment)
 {
     mysqli_real_escape_string(dbConnect::dbGetLink(), $vComment);
     if (CookiesManager::GetUserState() != 'closed') {
         if (CookiesManager::GetUserState() == 'only_voted') {
             $vID = CookiesManager::vGetCookie();
             $q = "UPDATE votes SET stance={$vStance}, user_id={$uID}, comment='{$vComment}', commenttime=NOW() WHERE vote_id = {$vID}";
             $r = mysqli_query(dbConnect::dbGetLink(), $q);
             if ($r) {
                 $outcome[] = mysqli_affected_rows(dbConnect::dbGetLink()) == 1 ? true : false;
                 $outcome[] = $vID;
                 return $outcome;
             } else {
                 return $outcome[] = false;
             }
         } else {
             $q = "INSERT INTO votes (poll_id, stance, votetime, user_id, comment, commenttime) VALUES ({$pID}, {$vStance}, NOW(), {$uID}, '{$vComment}', NOW())";
             $r = mysqli_query(dbConnect::dbGetLink(), $q);
             if ($r) {
                 if (mysqli_affected_rows(dbConnect::dbGetLink()) == 1) {
                     $outcome[] = true;
                     $outcome[] = mysqli_insert_id(dbConnect::dbGetLink());
                     return $outcome;
                 } else {
                     return $outcome[] = false;
                 }
             } else {
                 return $outcome[] = false;
             }
         }
     }
 }