/** static */
 function findByName($name)
 {
     global $db;
     $name = sotf_Utils::magicQuotes($name);
     $res = $db->getOne("SELECT id FROM sotf_contacts WHERE name='{$name}'");
     // what happens when there are 2 matches? but name field is unique...
     return $res;
 }
 /** static */
 function findByName($name)
 {
     global $db, $config;
     $name = sotf_Utils::magicQuotes($name);
     // first find the local contact, then any other...
     //$id = sotf_Contact::findByNameLocal($name);
     //if(!$id)
     $id = $db->getOne("SELECT id FROM sotf_contacts WHERE name='{$name}'");
     // what happens when there are 2 matches? returns first match...
     return $id;
 }
 function save()
 {
     global $db, $user;
     $data = serialize($this);
     $count = $db->getOne("SELECT count(*) FROM sotf_user_prefs WHERE id = '{$this->id}'");
     if ($count == 1) {
         $db->query("UPDATE sotf_user_prefs SET prefs='{$data}' WHERE id = '{$this->id}'");
     } else {
         $name = sotf_Utils::magicQuotes($user->name);
         $db->query("INSERT INTO sotf_user_prefs (id, username, prefs) VALUES('{$user->id}','{$name}','{$data}')");
     }
 }
 /** static: finds a station by its name
  */
 function getByName($stationName)
 {
     global $db;
     $stationName = sotf_Utils::magicQuotes($stationName);
     $id = $db->getOne("SELECT id FROM sotf_stations WHERE name = '{$stationName}'");
     if (DB::isError($id)) {
         raiseError($id);
     }
     if ($id) {
         return new sotf_Station($id);
     } else {
         return NULL;
     }
 }
 /** Sets the value of a persistent variable. */
 function set($name, $val)
 {
     $name = sotf_Utils::magicQuotes($name);
     $val = sotf_Utils::magicQuotes($val);
     if (isset($this->vars[$name])) {
         $update = 1;
     }
     $this->vars[$name] = $val;
     if ($update) {
         $result = $this->db->query("UPDATE {$this->table} SET value='{$val}' WHERE name='{$name}'");
     } else {
         $result = $this->db->query("INSERT INTO {$this->table} (name,value) VALUES('{$name}', '{$val}')");
     }
     if (DB::isError($result)) {
         raiseError($result);
     }
     debug("setvar", "{$name}={$val}");
 }
 function getUsername($user_id)
 {
     global $userdb;
     static $userNameCache;
     $storage =& sotf_User::getStorageObject();
     if (is_numeric($user_id)) {
         if ($userNameCache[$user_id]) {
             return $userNameCache[$user_id];
         }
         $data = $storage->userDbSelect(array('userid' => sotf_Utils::magicQuotes($user_id)));
         if (!$data) {
             return false;
         }
         $name = $data['username'];
         $userNameCache[$user_id] = $name;
         return $name;
     }
     return false;
 }
 function listGroupsOfUser($uid)
 {
     global $db;
     if (!$uid) {
         return array();
     }
     $uid = sotf_Utils::magicQuotes($uid);
     $sql = "SELECT group_id, id FROM sotf_user_groups WHERE user_id='{$uid}'";
     $res = $db->getAssoc($sql);
     if (DB::isError($res)) {
         raiseError($res);
     }
     return $res;
 }
 /** returns series (id,title) within given station owned/edited by current user */
 function mySeriesData($stationId)
 {
     global $page, $db, $user;
     if (!$page->loggedIn()) {
         return NULL;
     }
     // not logged in yet
     $stationId = sotf_Utils::magicQuotes($stationId);
     $sql = "SELECT s.id AS id, s.title AS title FROM sotf_series s, sotf_user_permissions u" . " WHERE u.user_id = '{$user->id}' AND u.object_id=s.id";
     if ($stationId) {
         $sql .= " AND s.station_id='{$stationId}'";
     }
     $sql .= " ORDER BY s.title";
     $sdata = $db->getAll($sql);
     return $sdata;
 }
 function find()
 {
     global $db;
     reset($this->data);
     while (list($key, $val) = each($this->data)) {
         //if($key != $this->idKey && !in_array($key, $this->binaryFields)) {
         if (!in_array($key, $this->binaryFields)) {
             $my_sql[] = $key . " = '" . sotf_Utils::magicQuotes($val) . "'";
         }
     }
     $my_sql = implode(" AND ", $my_sql);
     //execute the query
     $res = $db->getCol("SELECT {$this->idKey} FROM {$this->tablename} WHERE {$my_sql} ");
     if (count($res) > 1) {
         raiseError("not unique");
     }
     if (count($res) == 1) {
         //debug("find()", $res[0]);
         $this->id = $res[0];
         $this->load();
         $this->exists = true;
     } else {
         $this->exists = false;
     }
 }
 function getRoleId($name, $language)
 {
     $this->loadRoles();
     $name = sotf_Utils::magicQuotes($name);
     $language = sotf_Utils::magicQuotes($language);
     return $this->db->getOne("SELECT role_id FROM sotf_role_names WHERE name='{$name}' AND language='{$language}'");
 }
 /**
  * sotf :: setBlob()
  * 
  * purpose: to set a binary property.
  * 
  * @return (void)
  */
 function setBlob($prop_name, $prop_value)
 {
     if (empty($prop_value)) {
         $v = 'NULL';
     } else {
         $v = "'" . sotf_Utils::magicQuotes($this->db->escape_bytea($prop_value)) . "'";
     }
     $res = $this->db->query("UPDATE " . $this->tablename . " SET {$prop_name} = {$v} WHERE " . $this->idKey . "='" . $this->id . "' ");
     if (DB::isError($res)) {
         raiseError("Error in setBlob: {$res}");
     }
     $this->data[$prop_name] = $v;
 }
 /**
  * @method static listStations
  * @return array of sotf_Station objects
  */
 function listStations($start, $hitsPerPage, $mode = '', $language = '')
 {
     global $db;
     if (empty($start)) {
         $start = 0;
     }
     if (empty($mode)) {
         $mode = 'newest';
     }
     if (empty($language)) {
         $language = 'none';
     }
     if ($mode == 'newest') {
         $sortExpr = '  ORDER BY entry_date DESC ';
     } else {
         $sortExpr = '  ORDER BY name ';
     }
     $language = sotf_Utils::magicQuotes($language);
     if ($language != 'none') {
         $whereExpr = " WHERE language LIKE '%{$language}%' ";
     } else {
         $whereExpr = "";
     }
     $res = $db->limitQuery("SELECT * FROM sotf_stations {$whereExpr} {$sortExpr}", $start, $hitsPerPage);
     if (DB::isError($res)) {
         raiseError($res);
     }
     while (DB_OK === $res->fetchInto($st)) {
         $slist[] = new sotf_Station($st['id'], $st);
     }
     return $slist;
 }
 function simpleSearch($words, $language = false, $stationId = '')
 {
     global $db;
     $this->allid = array();
     $words = sotf_Utils::magicQuotes(strip_tags($words));
     //remove special chars
     $word = split(" ", $words);
     //split into separate words
     $max = count($word);
     //count words
     for ($i = 0; $i < $max; $i++) {
         $word[$i] = trim($word[$i]);
         //trim word
         if ($word[$i] == "") {
             continue;
         }
         //in empty get next
         //find word at the most common places
         $serial = str_replace("XXX", $word[$i], "production_date|Bstation|AAND|Bperson|Bcontains|BXXX|Bstring|AOR|Btitle|Bcontains|BXXX|Bstring|AOR|Bkeywords|Bcontains|BXXX|Bstring|AOR|Babstract|Bcontains|BXXX|Bstring|AOR|Bspatial_coverage|Bcontains|BXXX|Bstring");
         if ($language) {
             $serial .= "|AAND|Blanguage|Bis|B" . $language . "|Blang";
         }
         //if language given add to search options
         if ($stationId) {
             $serial .= "|AAND|Bstation|Bis|B" . $stationId . "|Bstation";
         }
         $this->Deserialize($serial);
         //deserialize query
         $query = $this->GetSQLCommand();
         //get desrialized query
         $query = "SELECT id FROM (" . $query . ") as a";
         $result = $db->getAll($query);
         $maxk = count($result);
         //count words
         for ($k = 0; $k < $maxk; $k++) {
             if (array_key_exists($result[$k]["id"], $this->allid)) {
                 $this->allid[$result[$k]["id"]] += 1;
             } else {
                 $this->allid[$result[$k]["id"]] = 1;
             }
         }
     }
     return count($this->allid);
 }
Esempio n. 14
0
 /** Search for users. */
 function findUsers($pattern, $prefix = false)
 {
     global $userdb;
     $storage =& sotf_User::getStorageObject();
     $fields['pattern'] = sotf_Utils::magicQuotes($pattern);
     if ($prefix) {
         $fields['prefix'] = 1;
     }
     $res = $storage->userDbFind($fields);
     if (DB::isError($res)) {
         raiseError($res);
     }
     return $res;
 }
 function login($name, $password)
 {
     global $user, $userdb, $page;
     $res = $userdb->getRow("SELECT auth_id, passwd FROM authenticate WHERE username='******'");
     if (DB::isError($res)) {
         raiseError($res);
     }
     if ($res['passwd'] != $password) {
         error_log("Login failed for {$name} from " . getHostName(), 0);
         return $page->getlocalized("invalid_login");
     } else {
         $user = new sotf_User($res['auth_id']);
         debug("Login successful", $user->name . ' = ' . $user->id);
         $userdb->query("UPDATE user_preferences SET num_logins=num_logins+1, last_visit='" . db_Wrap::getSQLDate() . "' WHERE auth_id='" . $user->id . "' ");
         $_SESSION['currentUserId'] = $user->id;
     }
 }
 /** static */
 function searchContactNames($pattern)
 {
     global $db, $config, $user;
     $pattern = sotf_Utils::magicQuotes($pattern);
     $res = $db->getAssoc("SELECT c.id AS id, c.name AS name FROM sotf_contacts c WHERE name ~* '{$pattern}' ORDER BY name");
     if (DB::isError($res)) {
         raiseError($res);
     }
     return $res;
 }
 function listUsers($start, $hitsPerPage, $pattern)
 {
     global $userdb;
     $storage =& sotf_User::getStorageObject();
     $pattern = sotf_Utils::magicQuotes($pattern);
     $list = $storage->userDbList($start, $hitsPerPage, $pattern);
     return $list;
 }