/** * Check in script for clients * * Clients check in client data using $_POST * * @author AvB **/ function check_in() { if (!isset($_POST['items'])) { $this->error("No items in POST"); } $arr = @unserialize($_POST['items']); if (!is_array($arr)) { $this->error("Could not parse items, not a proper serialized file"); } foreach ($arr as $name => $val) { // Skip items without data if (!isset($val['data'])) { continue; } // Rename legacy InventoryItem to inventory $name = str_ireplace('InventoryItem', 'inventory', $name); alert("starting: {$name}"); // All models are lowercase $name = strtolower($name); if (preg_match('/[^\\da-z_]/', $name)) { $this->msg("Model has an illegal name: {$name}"); continue; } // All models should be part of a module if (substr($name, -6) == '_model') { $module = substr($name, 0, -6); } else { $module = $name; $name = $module . '_model'; } $model_path = APP_PATH . "modules/{$module}/"; // Capitalize classname $classname = ucfirst($name); // Todo: prevent admin and user models, sanitize $name if (!file_exists($model_path . $name . '.php')) { $this->msg("Model not found: {$name}"); continue; } require_once $model_path . $name . '.php'; if (!class_exists($classname, false)) { $this->msg("Class not found: {$classname}"); continue; } // Load model $class = new $classname($_POST['serial']); if (!method_exists($class, 'process')) { $this->msg("No process method in: {$classname}"); continue; } try { $class->process($val['data']); // Store hash $hash = new Hash($_POST['serial'], $module); $hash->hash = $val['hash']; $hash->timestamp = time(); $hash->save(); } catch (Exception $e) { $this->msg("An error occurred while processing: {$classname}"); $this->msg("Error: " . $e->getMessage()); } // Handle alerts foreach ($GLOBALS['alerts'] as $type => $list) { foreach ($list as $msg) { $this->msg("{$type}: {$msg}"); } // Remove alert from array unset($GLOBALS['alerts'][$type]); } } }