/** * Constructs the class and verifies if the requirements have been met * @param string $id_field Column to identify the user through */ public function __construct($id_field = 'id') { self::$id_field = $id_field; $req_columns = array('id', 'username', 'email', 'password', 'lastactive'); if (Sql::tableExists('accounts') < 1) { Kernel::Log('The accounts table doesn\'t exist'); return false; } if (Sql::hasColumns('accounts', $req_columns) !== true) { Kernel::Log('The accounts table does not have the required columns'); return false; } return true; }
/** * Returns all the sitevars on the database * @return array Sitevars */ static function getVars() { $query = SQL::Query("SELECT * FROM sitevars"); if (!$query) { Kernel::Log('Could not retrieve sitevars.'); trigger_error('Could not retrieve sitevars.', E_USER_ERROR); return false; } foreach ($query as $reg) { $sitevars[$reg['name']] = $reg['value']; } return $sitevars; }
/** * Modifies an user's database information if we're modifying a cached column. Otherwise it just sets a property. * @param string $name Name of the property * @param string $value New value of the property * @return void */ public function __set($name, $value) { if ($this->boot) { Users::$id_field = $this->id_field; $disallowedKeys = array('id_field', 'user_id', 'boot'); if (!in_array($name, $disallowedKeys)) { $q = Users::modifyUser($this->user_id, $name, $value); } if (!$q) { Kernel::Log('User with ' . $this->id_field . " " . $this->user_id . " could not be modified (" . $name . ")"); return false; } $this->{$name} = $value; } }
/** * Updates a table's row * @param string $table Table to work with * @param array $array Array to use * @param string $criteria Criteria to add at the end of the query * @return bool Returns false if the query was not successful */ static function Update($table, $array, $criteria = null) { $bridge = self::$bridge; $sets = array(); $values = array(); $index = 0; foreach ($array as $key => $value) { $values[$index] = $value; $sets[] = 'SET ' . $key . ' = :' . $index; $index++; } $stmt = $bridge->prepare("UPDATE {$table} " . implode(', ', $sets) . " " . $criteria . ";"); foreach ($values as $key => $i) { $stmt->bindParam(':' . $key, $i); } try { $stmt->execute(); } catch (PDOException $e) { Kernel::Log('Could not execute query. Server returned "' . $e->getMessage() . '"'); return false; } return true; }
/** * Overwatches template and query configuration, if it's not either of those, sets it as an option * @param string $name Name of the property * @param string $value New value of the property * @return bool May return false if the template or query configuration weren't successful */ public function __set($name, $value) { if ($name == 'template') { $columns = Text::parseStringVar($value); foreach ($columns as $key => $i) { if (in_array($i, array_keys($this->vars))) { unset($columns[$key]); } } if (!Sql::hasColumns($this->table, $value)) { Kernel::Log('The template uses columns that do not exist on the ' . $this->table . ' table'); return false; } } elseif ($name == 'query') { if (!Sql::testQuery($value)) { Kernel::Log('The desired query did not run successfully. Please try another one. Your database wasn\'t affected.'); return false; } } else { $this->options[$name] = $value; } }
/** * Sets content or attributes of an HTMLObj * @param string $name Name of the property * @param string $value New value of the property * @return void */ public function __set($name, $value) { $disallowed = array('attr', 'elname', 'content', 'children', 'html'); if (in_array($name, $disallowed)) { Kernel::Log('Could not modify attribute of element ' . $this->elname); return false; } else { if ($name == "content") { $this->content = array($value); } else { $this->attr[$name] = $value; } } }
/** * Adds recipients in bulk using a multidimensional arrays * @param array $array Array of recipients ([] => [email, name, type]) * @return bool Returns true if the recipients were added successfully */ public function addRecipientBulk($array) { if (!is_array($array)) { Kernel::Log('The only argument for addRecipientBulk must be an array composed of the name, address and type of the recipient'); return false; } else { foreach ($array as $i) { $this->recipients[] = $i[0]; switch ($i[2]) { case 'normal': $this->headers['To'][] = $i[1] . ' <' . $i[0] . '>'; break; case 'cc': $this->headers['Cc'][] = $i[0]; break; case 'bcc': $this->headers['Bcc'][] = $i[0]; break; } } return true; } }