'; // TEMPLATE VARIABLES // These values will automatically be passed to the template. // These are in the base namespace, so don't pollute it too much. $config['tpl_vars']['css_path'] = '/css'; // No trailing slash $config['tpl_vars']['js_path'] = '/js'; // No trailing slash $config['tpl_vars']['img_path'] = '/images'; // No trailing slash $config['tpl_vars']['index_url'] = $config['url']['index']; $config['tpl_vars']['admin_index_url'] = $config['url']['admin_index']; ?> 'pkvcKey', 'value' => 'txtValue'); parent::__construct("tblSettings",'key',$fields); } private static function getInstance() { if(is_null(self::$instance)) {self::$instance = new self();} return self::$instance; } public static function getSetting($key, $required_type = null) { if(!array_key_exists($key, self::$settings)) { $i = self::getInstance(); $db = $i->getDb(); self::$settings[$key] = $db->GetOne("SELECT txtValue FROM tblSettings WHERE pkvcKey=" . $db->quoteSmart($key)); if(is_null(self::$settings)) {throw new Exception("Setting $key was not found in database!");} } $e = null; // Please add types as they become required. switch($required_type) { case 'numeric': if (!is_numeric(self::$settings[$key])) {$e = "Setting $key must be numeric!";} break; } if(!is_null($e)) {throw new Exception($e);} return self::$settings[$key]; } public static function saveSetting($key, $value) { self::$settings[$key] = $value; $tmp = new self; $tmp->setData(array('value' => $value)); $tmp->setPrimaryKey($key); $tmp->save(); } } ?>setFetchMode(DB_FETCHMODE_ASSOC); Database_Class::setDb($db); } public static function initPear() { PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, '__WampumSite__stupidPearExceptionHandlerIHateIt'); } public static function getSmarty() { global $config; $smarty = new Smarty(); $smarty->left_delimiter = '{{'; $smarty->right_delimiter = '}}'; $smarty->template_dir = $config['template']['full_path']; $smarty->compile_dir = $config['template']['compile_path']; array_push($smarty->plugins_dir, $config['template']['custom_smarty_path']); if($config['debug']) {$smarty->force_compile = true;} $smarty->assign($config['tpl_vars']); return $smarty; } } // Name says it all - PEAR should throw exceptions like everything else, // but the error mode to do that has been deprecated with no replacement. // Instead we have to set a handler for the error, and throw the exception // ourselves. function __WampumSite__stupidPearExceptionHandlerIHateIt($err) { throw new PEAR_Exception($err->getMessage() . "
    " . $err->userinfo, $err->getCode() ? $err->getCode() : null); } ?> 'pkiUserEmailID', 'user_id' => 'fkiUserID', 'email' => 'vcEmail', 'validated' => 'bIsValidated', 'validation_code' => 'vcValidationCode', 'date_added_datetime' => 'dtDateAdded'); parent::__construct('tblUserEmail','id',$fields, $eid); } /** * Check user email and invited user tables to ensure the specified address * is not already in the database. */ public static function canSetAddress($email) { // Can always set an address to the same value. if(isset($this) && $this->getFieldValue('email') == $email) {return true;} $tmp = self::getInstance(); // Check email table for the specified email. The only time an email may // match a database record is if it matches itself (of course) if($tmp->load(array('email' => $email))) { if (isset($this) && $tmp->getPrimaryKey() != $this->getPrimaryKey()) { return false; } } $tmp = new InvitedUser(); if($tmp->load(array('email' => $email))) {return false;} return true; } private static function getInstance() { if(is_null(self::$instance)) {self::$instance = new self();} self::$instance->reset(); return self::$instance; } public static function getEmailOwnerID($email = null) { $i = self::getInstance(); $tmp = $i->load(array('email' => $email), 'user_id'); return $tmp ? $tmp['user_id'] : null; } public static function getEmailByID($id = NULL) { $i = self::getInstance(); $i->setPrimaryKey($id); $tmp = $i->load(array('id'=>$id), 'email'); return $tmp ? $tmp['email'] : null; } public static function getEmailID($email = null) { $i = self::getInstance(); $tmp = $i->load(array('email' => $email), 'id'); return $tmp ? $tmp['id'] : null; } public function isValidated() { return $this->getFieldValue('validated'); } public function isPrimary() { $u = new User($this->getFieldValue('user_id')); if(!$user->getPrimaryKey()) {return false;} if($user->getFieldValue('Primaryemailid') == $this->getPrimaryKey()) { return true; } return false; } /** * Sets the email address with no checks. * * Normally when an email is set by setData, a check is done to see if it is in the * database. Call this function to avoid the check and allow duplicates. */ public function setEmailForce($email) { parent::setData(array('email' => $email)); } public function setData($new_data) { $args = func_get_args(); if(array_key_exists('email', $new_data)) { if(!$this->canSetAddress($new_data['email'])) { throw new Exception("That address already exists in the database."); } } return call_user_func_array(array('parent', 'setData'), $args); } public static function addForUser($email, $user_id, $validated = false) { $i = new self; $i->setData(array('email' => $email, 'user_id' => $user_id, $validated => ($validated ? 1 : 0))); return $i->save(); } public static function getAllForUser($uid) { if($uid instanceof User) {$uid = $uid->getPrimaryKey();} if(!is_numeric($uid)) {throw new Exception("Invalid user ID: $uid");} $i = self::getInstance(); return $i->getAllData(array('user_id' => $uid), 'email'); } public function sendValidation() { if(!$this->getPrimaryKey()) {throw new Exception("Sending validation to a non-record.");} $val_code = $this->getFieldValue('validation_code'); if(!$val_code) { $val_code = User_PasswordEncryptor::generateRandomPlainText(); $this->setFieldValue('validation_code', $val_code); $this->save(); } //now we send out a email to let them verify $smarty=WampumSite::getsmarty(); $smarty->assign('code',$val_code); $smarty->assign('user_id',$this->getFieldValue('user_id')); $from=SiteSettings::getSetting('automatic_emails_from'); $body=$smarty->fetch('_email/email-validation.tpl'); mail($this->getFieldValue('email'), 'Wampum: Validate this email address', $body, "From: $from\nContent-Type: text/html; charset=iso-8859-1\nX-Mailer: PHP mail() function"); } } 'pkiAccessLockID', 'locktype' => 'vcLockType', 'lock_value' => 'vcLockValue', 'lock_ends' => 'tsEndTime' ); parent::__construct("tblAccessLock",'id',$fields, $lid); } private static function getInstance() { if(is_null(self::$instance)) {self::$instance = new LockoutSystem;} self::$instance->reset(); return self::$instance; } private static function getLockTimeout($type, $value) { $instance = self::getInstance(); $results = $instance->load(array('locktype' => $type, 'lock_value' => $value), 'lock_ends'); if(!$results) {return null;} $timeout = $results['lock_ends']; // A NULL timeout indicates a permanent lock if(!$timeout) {return null;} // Remove expired locks $timeout = self::dateTimeFormatFromDatabase($timeout); if($timeout < time()) { $instance->delete(); return null; } return $timeout; } public static function deleteExpired() { $db = self::getDb(); $db->query("DELETE FROM tblAccessLock WHERE tsEndTime < NOW()"); } private static function performLock($type, $value, $timeout, $force = false) { $db = self::getDb(); $ls = self::getInstance(); $needs_update = $force; // If a lock already exists, check to see if it expires later than the // proposed one, and update it if not. if($ls->load(array('locktype' => $type, 'lock_value' => $value), 'lock_ends')) { if($ls->getFieldValue('lock_ends')) { $ends = self::dateTimeFormatFromDatabase($ls->getFieldValue('lock_ends')); if(!$timeout || $ends < $timeout) {$needs_update = true;} } } else { // No lock was found - create it. $ls->setData(array('locktype' => $type, 'lock_value' => $value)); $ls->save(); } $pk = $ls->getPrimaryKey(); if(!$pk) {throw new Exception("Database Error on locking system.");} $db->query('UPDATE tblAccessLock SET tsEndTime=' . $db->quoteSmart(!$timeout ? 'NULL' : self::dateTimeFormatForDatabase($timeout)) . ' WHERE pkiAccessLockID=' . $db->quoteSmart($pk)); } public static function getIpLockTimeout($ip) { if(is_null($ip)) {throw new Exception("No IP specified.");} if(!is_numeric($ip)) {$ip = ip2long($ip);} return self::getLockTimeout('ip', $ip); } public static function getUserLockTimeout($uid) { if(!is_numeric($uid)) {throw new Exception("Non-numeric user_id!");} return self::getLockTimeout('user_id', $uid); } public static function getAdminLockTimeout($aid) { if(!is_numeric($aid)) {throw new Exception("Non-numeric admin_id!");} return self::getLockTimeout('admin_id', $aid); } public static function lockIp($ip, $timeout, $force = false) { if(!is_numeric($ip)) {$ip = ip2long($ip);} self::performLock('ip', $ip, $timeout, $force); } public static function lockUser($user_id, $timeout, $force = false) { if(!is_numeric($user_id)) {throw new Exception("Non-numeric user_id!");} self::performLock('user_id', $user_id, $timeout, $force); } public static function lockAdmin($admin_id, $timeout, $force = false) { if(!is_numeric($admin_id)) {throw new Exception("Non-numeric admin_id!");} self::performLock('admin_id', $admin_id, $timeout, $force); } public static function isIpLocked ($ip = null) { return !is_null(self::getIpLockTimeout($ip)); } public static function isUserLocked ($uid = null) { return !is_null(self::getUserLockTimeout($uid)); } public static function isAdminLocked($aid = null) { return !is_null(self::getAdminLockTimeout($aid)); } } ?>