Ejemplo n.º 1
0
 public function initiateTerm($term)
 {
     $db = new Database();
     if ($db->update('judgeInvitations', array('ShowTerm' => $term == '' || $term == null ? 'NA' : 'yes'), "termInitiated = '" . $term . "'")) {
         return $db->update('judgeInvitations', array('ShowTerm' => $term == '' || $term == null ? 'NA' : 'no'), "termInitiated != '" . $term . "'");
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
	public function add ($query) {

		list($place, $item_id) = $this->parse_referer($query);

		if (!empty($query['parent'])) {
			$root = Database::get_field('comment', 'root', $query['parent']);

			if (empty($root)) {
				$root = $query['parent'];
			}
		} else {
			$root = 0;
		}

		$insert = array(
			'root' => $root,
			'parent' => $query['parent'],
			'place' => $place,
			'item_id' => $item_id,
			'area' => 'main',
			'username' => $query['name'],
			'email' => $query['email'],
			'ip' => Globals::$user_data['ip'],
			'cookie' => Globals::$user_data['cookie'],
			'text' => Transform_Text::format($query['text']),
			'pretty_text' => $query['text'],
		);

		Database::insert('comment', $insert);
		
		Database::update($place, $item_id, array('comments' => '++'));

		$this->redirect_address = $this->referer;
	}
Ejemplo n.º 3
0
function addNewEquip($value)
{
    $db = new Database();
    $link = $db->connect();
    $result = $db->update($link, 'equip_type', array('name' => 2));
    return $result;
}
Ejemplo n.º 4
0
 /**
  * Merge page histories
  *
  * @param integer $id The page_id
  * @param Title $newTitle The new title
  * @return bool
  */
 private function mergePage($row, Title $newTitle)
 {
     $id = $row->page_id;
     // Construct the WikiPage object we will need later, while the
     // page_id still exists. Note that this cannot use makeTitleSafe(),
     // we are deliberately constructing an invalid title.
     $sourceTitle = Title::makeTitle($row->page_namespace, $row->page_title);
     $sourceTitle->resetArticleID($id);
     $wikiPage = new WikiPage($sourceTitle);
     $wikiPage->loadPageData('fromdbmaster');
     $destId = $newTitle->getArticleID();
     $this->beginTransaction($this->db, __METHOD__);
     $this->db->update('revision', ['rev_page' => $destId], ['rev_page' => $id], __METHOD__);
     $this->db->delete('page', ['page_id' => $id], __METHOD__);
     $this->commitTransaction($this->db, __METHOD__);
     /* Call LinksDeletionUpdate to delete outgoing links from the old title,
      * and update category counts.
      *
      * Calling external code with a fake broken Title is a fairly dubious
      * idea. It's necessary because it's quite a lot of code to duplicate,
      * but that also makes it fragile since it would be easy for someone to
      * accidentally introduce an assumption of title validity to the code we
      * are calling.
      */
     DeferredUpdates::addUpdate(new LinksDeletionUpdate($wikiPage));
     DeferredUpdates::doUpdates();
     return true;
 }
Ejemplo n.º 5
0
 public static function isAuthenticated()
 {
     //TODO
     //look if Token is present in $_Session
     Session::get('UserID') ? $auth = 'TRUE' : ($auth = 'FALSE');
     if ($auth === 'TRUE') {
         return TRUE;
     } else {
         if (isset($_COOKIE["RemembeR"])) {
             $db = new Database();
             //Get TOKEN from $_COOKIE
             //hash(Token) and compare with hashed Tokens in the Database
             $userdata['tokenhash'] = hash('sha1', $_COOKIE["RemembeR"]);
             echo $userdata['tokenhash'];
             $arr = $db->select("SELECT id, tokenhash FROM users WHERE tokenhash = :tokenhash LIMIT 1", $userdata);
             var_dump($arr);
             if (sizeof($arr[0]['id']) !== 0) {
                 //Set 'UserID' in Session
                 Session::set('UserID', $arr[0]['id']);
                 //Renew Cookie
                 $token = hash("md5", $arr[0]['id'] . Session::get('ID'));
                 $userdata['id'] = $arr[0]['id'];
                 $userdata['tokenhash'] = hash("sha1", $token);
                 $db->update("users", $userdata, "id = :id");
                 setcookie("RemembeR", $token, time() + 259200, "/", "studi.f4.htw-berlin.de", false, true);
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
Ejemplo n.º 6
0
 /**
  * @param ResultWrapper $res
  * @param Database $dbw
  * @return null|int
  */
 function convertOptionBatch($res, $dbw)
 {
     $id = null;
     foreach ($res as $row) {
         $this->mConversionCount++;
         $insertRows = [];
         foreach (explode("\n", $row->user_options) as $s) {
             $m = [];
             if (!preg_match("/^(.[^=]*)=(.*)\$/", $s, $m)) {
                 continue;
             }
             // MW < 1.16 would save even default values. Filter them out
             // here (as in User) to avoid adding many unnecessary rows.
             $defaultOption = User::getDefaultOption($m[1]);
             if (is_null($defaultOption) || $m[2] != $defaultOption) {
                 $insertRows[] = ['up_user' => $row->user_id, 'up_property' => $m[1], 'up_value' => $m[2]];
             }
         }
         if (count($insertRows)) {
             $dbw->insert('user_properties', $insertRows, __METHOD__, ['IGNORE']);
         }
         $dbw->update('user', ['user_options' => ''], ['user_id' => $row->user_id], __METHOD__);
         $id = $row->user_id;
     }
     return $id;
 }
Ejemplo n.º 7
0
 public function process()
 {
     $tag = $this->get('tag');
     $type = $this->get('type');
     if (empty($tag)) {
         throw new Error_Api('Пропущено обязательное поле: tag', Error_Api::MISSING_INPUT);
     }
     if (empty($type)) {
         throw new Error_Api('Пропущено обязательное поле: type', Error_Api::MISSING_INPUT);
     }
     if (!array_key_exists($type, $this->types)) {
         throw new Error_Api('Неправильно заполнено поле: type', Error_Api::INCORRECT_INPUT);
     }
     $color = $this->types[$type];
     $tag = trim(undo_safety($tag));
     $args = array($tag, '|' . $tag . '|', $tag);
     $exists = Database::get_field('tag', 'alias', 'name = ? or locate(?, variants) or alias = ?', $args);
     if ($exists) {
         $alias = $exists;
     } else {
         $alias = Transform_Meta::make_alias($tag);
         Database::insert('tag', array('alias' => $alias, 'name' => $tag, 'variants' => '|'));
         $this->add_error(Error_Api::UNKNOWN_TAG);
     }
     Database::update('tag', array('color' => $color), 'alias = ?', $alias);
     $this->set_success(true);
     $this->add_answer('tag', $alias);
 }
Ejemplo n.º 8
0
 public function save()
 {
     if (!$this->tableName || !$this->databaseFields) {
         return;
     }
     $invalid = false;
     $values = array();
     foreach ($this->databaseFields as $fieldName) {
         if (isset($this->{$fieldName})) {
             if (is_object($this->{$fieldName})) {
                 $values[$fieldName] = $this->{$fieldName}->id;
             } else {
                 $values[$fieldName] = $this->{$fieldName};
             }
         }
     }
     if (!$invalid) {
         if ($this->id == null) {
             $this->id = Database::insert($this->tableName, $values);
         } else {
             Database::update($this->tableName, $this->id, $values);
         }
         $this->saved = true;
     }
 }
Ejemplo n.º 9
0
 protected function test_links($links)
 {
     $this->worker->enable_limit(self::MAX_DOWNLOAD_SIZE)->add($links)->exec();
     foreach ($links as $id => $link) {
         $status = $this->test_result($link);
         if ($status === false) {
             continue;
         }
         Database::update('post_url', array('status' => $status, 'lastcheck' => Database::unix_to_date()), $id);
         if ($status == self::STATUS_UNKNOWN) {
             $this->create_unknown_file($link);
         }
     }
     $this->worker->flush();
     $keys = array_keys($links);
     $post_ids = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->get_vector('post_link', 'post_id', Database::array_in('pu.id', $keys), $keys);
     $post_ids = array_unique($post_ids);
     foreach ($post_ids as $post_id) {
         $status = new Model_Post_Status($post_id);
         $status->load()->calculate()->commit();
     }
     $update_ids = Database::join('post_update_link_url', 'pulu.link_id = pul.id')->join('post_url', 'pulu.url_id = pu.id')->get_vector('post_update_link', 'update_id', Database::array_in('pu.id', $keys), $keys);
     $update_ids = array_unique($update_ids);
     foreach ($update_ids as $update_id) {
         $status = new Model_Post_Update_Status($update_id);
         $status->load()->calculate()->commit();
     }
 }
Ejemplo n.º 10
0
 function update($criteria, $new_object, $options = [])
 {
     if (!isset($new_object['rmts']) && !isset($new_object['upts'])) {
         $new_object['upts'] = $_SERVER['REQUEST_TIME'];
     }
     return parent::update($criteria, $new_object, $options);
 }
Ejemplo n.º 11
0
function editEquip($value, $id)
{
    $db = new Database();
    $link = $db->connect();
    $result = $db->update($link, 'equip_type', array('name' => $value), 'type_id=' . $id);
    return $result;
}
Ejemplo n.º 12
0
 public function init($database, $dbName, $public, $version)
 {
     # Check dependencies
     self::dependencies(isset($this->settings, $public, $version));
     # Call plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     # Update
     if (!isset($this->settings['version']) || $this->settings['version'] !== $version) {
         if (!Database::update($database, $dbName, @$this->settings['version'])) {
             Log::error($database, __METHOD__, __LINE__, 'Updating the database failed');
             exit('Error: Updating the database failed!');
         }
     }
     # Clear expired sessions
     $query = Database::prepare($this->database, "DELETE FROM ? WHERE expires < UNIX_TIMESTAMP(NOW())", array(LYCHEE_TABLE_SESSIONS));
     $this->database->query($query);
     # Return settings
     $return['config'] = $this->settings;
     # Remove username and password from response
     unset($return['config']['username']);
     unset($return['config']['password']);
     # Remove identifier from response
     unset($return['config']['identifier']);
     # Path to Lychee for the server-import dialog
     $return['config']['location'] = LYCHEE;
     # Check if login credentials exist and login if they don't
     if ($this->noLogin() === true) {
         $public = false;
         $return['config']['login'] = false;
     } else {
         $return['config']['login'] = true;
     }
     # Check login with crypted hash
     if (isset($_COOKIE['SESSION']) && $this->sessionExists($_COOKIE['SESSION'])) {
         $_SESSION['login'] = true;
         $_SESSION['identifier'] = $this->settings['identifier'];
         $public = false;
     }
     if ($public === false) {
         # Logged in
         $return['status'] = LYCHEE_STATUS_LOGGEDIN;
     } else {
         # Logged out
         $return['status'] = LYCHEE_STATUS_LOGGEDOUT;
         # Unset unused vars
         unset($return['config']['thumbQuality']);
         unset($return['config']['sortingAlbums']);
         unset($return['config']['sortingPhotos']);
         unset($return['config']['dropboxKey']);
         unset($return['config']['login']);
         unset($return['config']['location']);
         unset($return['config']['imagick']);
         unset($return['config']['medium']);
         unset($return['config']['plugins']);
     }
     # Call plugins
     $this->plugins(__METHOD__, 1, func_get_args());
     return $return;
 }
Ejemplo n.º 13
0
/**
 * Package metadata updates.
 *
 * @param Database $db
 * @param array $updates
 * @return bool
 * @throws TypeError
 */
function processUpdates(Database $db, array $updates = []) : bool
{
    $db->beginTransaction();
    foreach ($updates as $update) {
        $db->update('airship_package_cache', ['skyport_metadata' => \json_encode($update['metadata'])], ['packagetype' => $update['package']['type'], 'supplier' => $update['package']['supplier'], 'name' => $update['package']['name']]);
    }
    return $db->commit();
}
Ejemplo n.º 14
0
 public static function fin_notificaciones()
 {
     ///$configdb = new Mysql('localhost','root','','corsione');
     $configdb = new Database();
     $configdb->connect();
     $configdb->update('notificaciones', array('estado' => "1"), 'estado="0"');
     $res = $configdb->getResult();
 }
Ejemplo n.º 15
0
	protected function update_lifetime()
	{
		$domain = preg_replace('/^[^\.]+/ui', '', $_SERVER['SERVER_NAME']);
		setcookie($this->name, $this->hash, time()+3600*24*60, '/', $domain);
		// Фиксируем факт обновления в БД
		Database::update('cookie', ['lastchange' => time()],
			'cookie = ?', $this->hash);
	}
Ejemplo n.º 16
0
 protected function do_delete($data)
 {
     if (!isset($data['id']) || !is_numeric($data['id']) || !Database::get_count('game', 'id_user = ? and id = ? and state != ?', array($this->user, $data['id'], 4))) {
         return array('success' => false);
     }
     Database::update('game', array('state' => 4), 'id_user = ? and id = ?', array($this->user, $data['id']));
     return array('success' => true);
 }
Ejemplo n.º 17
0
 public function update($question)
 {
     $db = new Database();
     $success = $db->update('Questions', array('Text' => $question->Text), "id = " . $question->id);
     if (!$success) {
         return array('success' => false, 'msg' => $db->getResult());
     }
     return array('success' => $success, 'data' => $question);
 }
Ejemplo n.º 18
0
 public function updateTemplate($template)
 {
     $db = new Database();
     $success = $db->update('emailTemplates', array('TemplateTitle' => $template->TemplateTitle, 'Subject' => $template->Subject, 'Body' => $template->Body), "TemplateID = " . $template->TemplateID);
     if (!$success) {
         return array('success' => false, 'msg' => $db->getResult());
     }
     return array('success' => true, 'data' => $template);
 }
Ejemplo n.º 19
0
 public function save_sort()
 {
     $db = new Database();
     foreach ($_GET['item'] as $position => $id) {
         $db->update('forum_cats', array('position' => $position), "id = '{$id}'");
     }
     die('Item sort order saved');
     # success
 }
Ejemplo n.º 20
0
 /**
  * Sets the number of active users in the site_stats table
  */
 protected function doActiveUsersInit()
 {
     $activeUsers = $this->db->selectField('site_stats', 'ss_active_users', false, __METHOD__);
     if ($activeUsers == -1) {
         $activeUsers = $this->db->selectField('recentchanges', 'COUNT( DISTINCT rc_user_text )', ['rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'"], __METHOD__);
         $this->db->update('site_stats', ['ss_active_users' => intval($activeUsers)], ['ss_row_id' => 1], __METHOD__, ['LIMIT' => 1]);
     }
     $this->output("...ss_active_users user count set...\n");
 }
Ejemplo n.º 21
0
 public function insert()
 {
     $this->set('pretty_date', Transform_Text::rudate());
     $this->set('sortdate', ceil(microtime(true) * 1000));
     $this->set('area', def::area(0));
     parent::insert();
     Database::update('post', array('update_count' => '++'), $this->get('post_id'));
     $this->add_children();
     return $this;
 }
Ejemplo n.º 22
0
 public function set($key, $value, User $user = null)
 {
     $receipt = null;
     $this->record[$key] = $value;
     Database::update('albums', array($key => $value), 'id=' . $this->record['id']);
     if (isset($user)) {
         $receipt = AuditTrail::createAuditTrailForChange($user, 'album', $this->record['id'], $key, $this->record[$key], $value);
     }
     return $receipt;
 }
Ejemplo n.º 23
0
 public function delete($id, $id_host)
 {
     include_once '../db.php';
     $db = new Database();
     $db->connect();
     $rows = array();
     $rows[activo] = 0;
     $db->update('pagos', $rows, 'id=' . $id);
     $this->updateVencimiento($id_host, 0);
     return 1;
 }
Ejemplo n.º 24
0
 public function save($settings)
 {
     $db = new Database();
     if (!file_put_contents('../resources/' . basename($settings->MapImage), file_get_contents($settings->MapImage))) {
         return false;
     }
     $db->select('Settings', 'Term');
     $term = $db->getResult();
     $db->update('Settings', array('Term' => $settings->Term, 'StudentsPerJudge' => $settings->StudentsPerJudge, 'Date' => $settings->Date, 'Time' => $settings->Time, 'Location' => $settings->Location, 'Subject' => $settings->Subject, 'EmailText' => str_replace('"', '\\"', $settings->EmailText), 'SrProjectURL' => $settings->SrProjectURL, 'SrProjectToken' => $settings->SrProjectToken, 'MapImage' => $settings->MapImage, 'GradesPosted' => $settings->GradesPosted ? 1 : 0, 'AllowJudgesToLogin' => $settings->AllowJudgesToLogin ? 1 : 0), "Term = '" . $term['Term'] . "'");
     return true;
 }
Ejemplo n.º 25
0
 public function update_category($cid, $cname)
 {
     $db = new Database();
     if (!$db->connect()) {
         return false;
     }
     if (!$db->update('categories', array('c_name' => $cname), 'c_id=' . $cid)) {
         return false;
     }
     $db->disconnect();
     return true;
 }
Ejemplo n.º 26
0
 /**
  * Set a variable value for later retrieval.
  * @param $name string Name of the variable to set.
  * @param variant $value Value to set.
  * @param $caching boolean Set to true to enable use of the Kohana cache.
  */
 public static function set($name, $value, $caching = true)
 {
     $db = new Database();
     $query = $db->update('variables', array('value' => json_encode(array($value))), array('name' => $name));
     if ($query->count() === 0) {
         // insert record if nothing to update
         $db->insert('variables', array('name' => $name, 'value' => json_encode(array($value))));
     }
     if ($caching) {
         $cache = Cache::instance();
         $cache->set("variable-{$name}", $value, array('variables'));
     }
 }
Ejemplo n.º 27
0
 public static function edit()
 {
     $visible = 0;
     if ($_POST['visible'] == "True") {
         $visible = 1;
     }
     $values = [self::TYPEID => $_POST['typeid'], self::TITLE => $_POST['title'], self::CONTENT => $_POST['content'], self::VISIBLE => $visible];
     $where = [self::ID => $_POST['id']];
     Database::update(self::TABLE_NAME, $values, $where);
     Tag::remove($_POST['id']);
     //TODO detect tags, and add them
     //Tag::add($_POST['id'], *);
 }
Ejemplo n.º 28
0
 public function init($database, $dbName, $public, $version)
 {
     # Check dependencies
     self::dependencies(isset($this->settings, $public, $version));
     # Call plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     # Update
     if (!isset($this->settings['version']) || $this->settings['version'] !== $version) {
         if (!Database::update($database, $dbName, @$this->settings['version'])) {
             Log::error($database, __METHOD__, __LINE__, 'Updating the database failed');
             exit('Error: Updating the database failed!');
         }
     }
     # Return settings
     $return['config'] = $this->settings;
     # Remove username and password from response
     unset($return['config']['username']);
     unset($return['config']['password']);
     # Remove identifier from response
     unset($return['config']['identifier']);
     # Path to Lychee for the server-import dialog
     $return['config']['location'] = LYCHEE;
     # Check if login credentials exist and login if they don't
     if ($this->noLogin() === true) {
         $public = false;
         $return['config']['login'] = false;
     } else {
         $return['config']['login'] = true;
     }
     if ($public === false) {
         # Logged in
         $return['status'] = LYCHEE_STATUS_LOGGEDIN;
     } else {
         # Logged out
         $return['status'] = LYCHEE_STATUS_LOGGEDOUT;
         # Unset unused vars
         unset($return['config']['thumbQuality']);
         unset($return['config']['sortingAlbums']);
         unset($return['config']['sortingPhotos']);
         unset($return['config']['dropboxKey']);
         unset($return['config']['login']);
         unset($return['config']['location']);
         unset($return['config']['imagick']);
         unset($return['config']['medium']);
         unset($return['config']['plugins']);
     }
     # Call plugins
     $this->plugins(__METHOD__, 1, func_get_args());
     return $return;
 }
Ejemplo n.º 29
0
	public function edit_painter_theme ($query) {
return;		
		$update = array();
		
		$id = (int) $query['item_id'];
		
		foreach ($query as $field => $value) {
			if (substr($field, 0, 6) == 'field_') {
				$update[substr($field, 6)] = $value;
			}
		}
		
		Database::update('painter_themes', $id, $update);
	}	
Ejemplo n.º 30
0
 public function setAccept($judgeId, $studentId, $acceptance)
 {
     $db = new Database();
     $success = $db->update('JudgeStudentGrade', array('Accepted' => $acceptance ? 1 : 0), 'JudgeId = ' . $judgeId . ' and StudentId = ' . $studentId);
     $msg = $db->getResult();
     if (!$success) {
         return array('success' => false, 'msg' => $msg);
     }
     $db->select('JudgeStudentGrade', 'Grade, Accepted', null, 'StudentId = ' . $studentId);
     $res = $db->getResult();
     if (array_key_exists('Grade', $res)) {
         $res = array($res);
     }
     $grade = 0;
     $reviewed = 0;
     $accepted = 0;
     $total = 0;
     foreach ($res as $judge) {
         $total++;
         if (is_null($judge['Accepted'])) {
             continue;
         }
         if (intval($judge['Accepted']) === 1) {
             $accepted++;
             $grade += intval($judge['Grade']);
         }
         $reviewed++;
     }
     if ($total == $reviewed && $accepted > 0) {
         $grade /= $accepted;
         $db->update('Students', array('Grade' => $grade), 'id = ' . $studentId);
         return array('success' => true, 'grade' => $grade);
     } else {
         $db->sql('UPDATE Students SET Grade = NULL WHERE id = ' . $studentId . ';');
         return array('success' => true, 'grade' => null);
     }
 }