Exemplo n.º 1
0
 public static function set($PK = '', &$incoming = '')
 {
     $set = array();
     if (empty($incoming)) {
         $incoming = json_decode(file_get_contents('php://input'));
     }
     if (!is_object($incoming)) {
         return $PK;
     }
     foreach (static::$columns as $col => $attrs) {
         if (property_exists($incoming, $col) && empty($incoming->{$col}) && isset($attrs['required']) && $attrs['required'] === TRUE) {
             http_response_code(400) && exit($col . ' is required.');
         }
         if (isset($attrs['fromSession']) && empty($PK)) {
             $set[$col] = $_SESSION[$attrs['fromSession']];
             continue;
         }
         if (!isset($attrs['type'])) {
             continue;
         }
         if (!isset($incoming->{$col})) {
             continue;
         }
         switch ($attrs['type']) {
             case 'int':
                 $set[$col] = (int) $incoming->{$col};
                 break;
             case 'float':
                 $set[$col] = (double) $incoming->{$col};
                 break;
             case 'datetime':
                 if (preg_match('/^[\\d-:\\. TZ]+$/', $incoming->{$col})) {
                     $set[$col] = $incoming->{$col};
                 }
                 break;
             case 'enum':
                 if (!isset($attrs['options']) || !in_array($incoming->{$col}, $attrs['options'])) {
                     continue;
                 }
                 $set[$col] = $incoming->{$col};
             default:
                 $set[$col] = \Core\XSS::clean($incoming->{$col});
         }
     }
     if (!empty($set)) {
         empty($PK) ? $PK = self::insert($set) : self::update($set, $PK);
     }
     return $PK;
 }
Exemplo n.º 2
0
 public static function handle()
 {
     $incoming = json_decode(file_get_contents('php://input'));
     foreach ($_SESSION['range'] as $part => $value) {
         if (!isset($incoming->{$part})) {
             continue;
         }
         $newValue = \Core\XSS::clean($incoming->{$part});
         if (strtotime($newValue) === FALSE) {
             http_response_code(400) && exit('Sorry, could not sort out what time that was :/');
         }
         $_SESSION['range'][$part] = $newValue;
     }
     echo json_encode($_SESSION['range']);
 }