Ejemplo n.º 1
0
 public function save()
 {
     // See if this is old data
     if ($this->_isLoadedData) {
         if ($this->modelCache->getPrimaryKey() == null) {
             SimpleMVCErrors::generalError("Cannot save " . $this->modelName . " as table has no primary key defined!");
         }
         $sql = "update " . $this->modelName . " set ";
         $updateColumns = array();
         foreach ($this->data as $key => $value) {
             if ($this->modelCache->hasField($key)) {
                 $updateColumns[] = "{$key}=" . $this->modelCache->sanitize($key, $value);
             }
         }
         $sql .= join($updateColumns, ",");
         $sql .= " where " . $this->modelCache->getPrimaryKey() . "=" . $this->modelCache->sanitize($this->modelCache->getPrimaryKey(), $this->data[$this->modelCache->getPrimaryKey()]);
         Datasource::query($sql);
         return true;
     } else {
         $sql = "insert into " . $this->modelName . "(" . join(array_keys($this->data), ",") . ") VALUES (";
         $values = array();
         foreach (array_keys($this->data) as $field) {
             if ($this->modelCache->hasField($field)) {
                 $value = $this->modelCache->sanitize($field, $this->data[$field]);
                 $values[] = $value;
             }
         }
         $sql .= join($values, ",") . ")";
         $id = Datasource::query($sql);
         $this->data[$this->modelCache->getPrimaryKey()] = $id;
         return $id;
     }
 }
Ejemplo n.º 2
0
 public function MailUtil($template)
 {
     $this->template = $template;
     if (!file_exists(WEBAPP_ROOT . "/templates/mail/html/{$template}.php")) {
         SimpleMVCErrors::generalError("Missing text/html mail template for mail {$template} (WEBAPP_ROOT/templates/mail/html/{$template}.php)");
     }
     if (!file_exists(WEBAPP_ROOT . "/templates/mail/txt/{$template}.php")) {
         SimpleMVCErrors::generalError("Missing text/plain mail template for mail {$template} (WEBAPP_ROOT/templates/mail/txt/{$template}.php)");
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates a new Options -set
  */
 public function Options($realm, $values = array())
 {
     $this->_optionRealm = $realm;
     if (!class_exists("AppConfiguration")) {
         SimpleMVCErrors::generalError("Application configuration class not available but is required by Options-class. " . "Make sure that webapp/application.conf.php is present");
     }
     if (property_exists('AppConfiguration', 'OPTIONS')) {
         if (!is_array(AppConfiguration::$OPTIONS[$realm])) {
             SimpleMVCErrors::generalError("Requesting options for non-existant Options-realm: {$realm}. Make sure " . "webapp/application.conf.php contains \$OPTIONS[\"{$realm}\"].");
         }
         $this->_realmConfig = AppConfiguration::$OPTIONS[$realm];
         $this->_initializeWithDefaults();
         foreach ($values as $key => $value) {
             $this->_realmOptions[$key] = $value;
         }
     }
 }
Ejemplo n.º 4
0
 public function sanitize($fld, $value)
 {
     if (preg_match("#text\$#", $this->modelStructure[$fld]["type"]) || preg_match("#char\$#", $this->modelStructure[$fld]["type"]) || $this->modelStructure[$fld]["type"] == "enum" || $this->modelStructure[$fld]["type"] == "date" || $this->modelStructure[$fld]["type"] == "timestamp") {
         $value = "'" . Datasource::escape($value) . "'";
     } else {
         if ($this->modelStructure[$fld]["type"] == "tinyint") {
             if (!(intval($value) == 0 || intval($value) == 1)) {
                 SimpleMVCErrors::generalError("Given value ({$value}) is not a valid boolean value");
             }
         } else {
             // Assume to be numeric
             if (!is_numeric($value) && $value != 'NULL') {
                 SimpleMVCErrors::generalError("{$value} given as numeric database input (" . $this->modelSource . ".{$fld})");
             }
         }
     }
     return $value;
 }