update() static public method

Runs an UPDATE query
static public update ( string $table, mixed $input, mixed $where ) : mixed
$table string The table name
$input mixed Either a key/value array or a valid MySQL insert string
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
return mixed The number of affected rows or an error response
Example #1
0
 function saveMail()
 {
     db::table('mails');
     db::where('mail_id', admin::get('id'));
     db::update(array('mail_name' => params::get('mail_name'), 'mail_subject' => params::get('mail_subject'), 'mail_content' => params::get('mail_content')));
     headers::self();
 }
Example #2
0
 function save()
 {
     $array = array('news_title' => params::get('news_title'), 'news_content' => params::get('news_content'), 'news_desc' => params::get('news_desc'));
     db::table('news');
     db::where('news_id', params::get('news_id'));
     db::update($array);
     headers::self();
 }
Example #3
0
 function newPassword($new_pass)
 {
     if (!empty($new_pass)) {
         db::table('admin_users');
         db::where('user_id', ADMIN_USER_ID);
         db::update('user_password', md5($new_pass));
     }
 }
Example #4
0
 function update($name, $value, $user_id = false)
 {
     if (!$user_id) {
         $user_id = ADMIN_USER_ID;
     }
     db::table('admin_users');
     db::where('user_id', $user_id);
     db::update($name, $value);
 }
Example #5
0
function update_password($password)
{
    $db = new db();
    $user = get_user_data();
    $id = $user['id'];
    $password = md5($password);
    $result = $db->update("users", array("password" => $password), "id = :id", array(":id" => $id));
    return $result;
}
Example #6
0
 public function saveNewLearningTime($values)
 {
     $this->_prepareLearningTimes();
     if (isset($values['id'])) {
         $id = $values['id'];
         unset($values['id']);
         db::update(':table:', $values)->where('id = %i', $id)->execute();
     } else {
         $sql = 'INSERT INTO [:table:]';
         $result = db::query($sql, $values);
     }
 }
Example #7
0
 private function recursiveLevelUpdate($parent_id, $level)
 {
     static $counter = 0;
     $counter++;
     $items = db::select('*')->from(':table:')->where('parent = %i', $parent_id)->fetchAll();
     foreach ($items as $key => $item) {
         $update = $level + $counter;
         $values = array('level' => $update);
         db::update(':table:', $values)->where('id = %i', $item->id)->execute();
         $items[$key]['items'] = $this->recursiveLevelUpdate($item->id, $level);
     }
     return $items;
 }
Example #8
0
function save_note($id, $title, $body)
{
    if ($body == "" && $title == "") {
        $title = "Empty note";
    }
    if (($title == "" || $title == "Empty note") && $body != "") {
        $title = truncate(strip_tags($body), 30);
    }
    $db = new db();
    $result = $db->update("notes", array("title" => $title, "body" => $body), "id = :id", array(":id" => $id));
    $result = array("id" => $id, "title" => $title, "body" => $body);
    return $result;
}
Example #9
0
 public function update()
 {
     error_log(__METHOD__);
     if (count($_POST)) {
         unset($this->in['id'], $this->in['created']);
         $this->in['updated'] = date('Y-m-d H:i:s');
         db::update($this->in, [['id', '=', $this->g->in['i']]]);
         header("Location: ?o=" . $this->o);
         exit;
     } elseif ($this->g->in['i']) {
         return $this->t->{$this->o . '_form'}(array_merge(db::read('*', 'id', $this->g->in['i'], '', 'one'), ['submit' => $this->update]));
     } else {
         return 'Error with Update';
     }
 }
Example #10
0
 public function save($values)
 {
     $this->_prepare();
     $values['email'] = String::lower($values['name'] . '.' . $values['surname'] . '@st.fm.uniba.sk');
     if (!isset($values['id'])) {
         $values['password'] = String::lower($values['name'] . $values['surname']);
     }
     if (isset($values['id'])) {
         $id = $values['id'];
         unset($values['id']);
         db::update(':table:', $values)->where('id = %i', $id)->execute();
     } else {
         $sql = 'INSERT INTO [:table:]';
         $result = db::query($sql, $values);
     }
 }
Example #11
0
 function restore()
 {
     db::table('admin_log_trash');
     db::where('log_id', params::get('log_id'));
     $date = date('Y-m-d H:i:s');
     db::update('log_restored', $date);
     db::table('admin_log_trash');
     db::where('log_id', params::get('log_id'));
     $row = db::assoc();
     if ($row['log_tmpl'] == '1') {
         trash::restore(params::get('log_id'), SYS_ROOT . 'tmpls/' . ADMIN_SITE . '/');
     } else {
         trash::restore(params::get('log_id'));
     }
     buffer::set(dt::date2print('%H:%i:%s<br />%d %F %y', $date));
 }
Example #12
0
 public function write($id, $data)
 {
     $data = array('session_id' => $id, 'last_activity' => time(), 'data' => base64_encode($data));
     if ($this->session_id === NULL) {
         // Insert a new session
         $query = db::insert($this->table, $data)->execute($this->db);
     } elseif ($id === $this->session_id) {
         // Do not update the session_id
         unset($data['session_id']);
         // Update the existing session
         $query = db::update($this->table)->set($data)->where('session_id', '=', $id)->execute($this->db);
     } else {
         // Update the session and id
         $query = db::update($this->table)->set($data)->where('session_id', '=', $this->session_id)->execute($this->db);
         // Set the new session id
         $this->session_id = $id;
     }
     return (bool) $query->count();
 }
Example #13
0
<?php

include "../../../../include/classes/main/db.class.php";
$op = $_POST['operation'];
$db = new db();
if ($op == "edit") {
    $id = $_POST['id'];
    $title = $_POST['title'];
    $text = $_POST['text'];
    if ($db->update("content", "title='" . $title . "', content='" . $text . "'", " id = '" . $id . "'")) {
        echo '0';
    } else {
        echo '1';
    }
} elseif ($op == "add") {
    $title = $_POST['title'];
    $text = $_POST['text'];
    $col[] = "title";
    $col[] = "content";
    $var[] = $title;
    $var[] = $text;
    //db::setDebug(2);
    if ($db->insert("content", $col, $var)) {
        if ($db->insert("navigation_links", array("link", "type", "content_id", "titel", "tpl"), array("content", "1", $db->getLastId(), $title, "1"))) {
            echo '0';
        }
    } else {
        echo '1';
    }
} elseif ($op == "delete") {
    $id = $_POST['id'];
Example #14
0
 static function upgrade($version)
 {
     $db = Database::instance();
     if ($version == 1) {
         module::set_var("gallery", "date_format", "Y-M-d");
         module::set_var("gallery", "date_time_format", "Y-M-d H:i:s");
         module::set_var("gallery", "time_format", "H:i:s");
         module::set_version("gallery", $version = 2);
     }
     if ($version == 2) {
         module::set_var("gallery", "show_credits", 1);
         module::set_version("gallery", $version = 3);
     }
     if ($version == 3) {
         $db->query("CREATE TABLE {caches} (\n                 `id` varchar(255) NOT NULL,\n                 `tags` varchar(255),\n                 `expiration` int(9) NOT NULL,\n                 `cache` text,\n                 PRIMARY KEY (`id`),\n                 KEY (`tags`))\n                 DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 4);
     }
     if ($version == 4) {
         Cache::instance()->delete_all();
         $db->query("ALTER TABLE {caches} MODIFY COLUMN `cache` LONGBLOB");
         module::set_version("gallery", $version = 5);
     }
     if ($version == 5) {
         Cache::instance()->delete_all();
         $db->query("ALTER TABLE {caches} DROP COLUMN `id`");
         $db->query("ALTER TABLE {caches} ADD COLUMN `key` varchar(255) NOT NULL");
         $db->query("ALTER TABLE {caches} ADD COLUMN `id` int(9) NOT NULL auto_increment PRIMARY KEY");
         module::set_version("gallery", $version = 6);
     }
     if ($version == 6) {
         module::clear_var("gallery", "version");
         module::set_version("gallery", $version = 7);
     }
     if ($version == 7) {
         $groups = identity::groups();
         $permissions = ORM::factory("permission")->find_all();
         foreach ($groups as $group) {
             foreach ($permissions as $permission) {
                 // Update access intents
                 $db->query("ALTER TABLE {access_intents} MODIFY COLUMN {$permission->name}_{$group->id} BINARY(1) DEFAULT NULL");
                 // Update access cache
                 if ($permission->name === "view") {
                     $db->query("ALTER TABLE {items} MODIFY COLUMN {$permission->name}_{$group->id} BINARY(1) DEFAULT FALSE");
                 } else {
                     $db->query("ALTER TABLE {access_caches} MODIFY COLUMN {$permission->name}_{$group->id} BINARY(1) NOT NULL DEFAULT FALSE");
                 }
             }
         }
         module::set_version("gallery", $version = 8);
     }
     if ($version == 8) {
         $db->query("ALTER TABLE {items} CHANGE COLUMN `left`  `left_ptr`  INT(9) NOT NULL;");
         $db->query("ALTER TABLE {items} CHANGE COLUMN `right` `right_ptr` INT(9) NOT NULL;");
         module::set_version("gallery", $version = 9);
     }
     if ($version == 9) {
         $db->query("ALTER TABLE {items} ADD KEY `weight` (`weight` DESC);");
         module::set_version("gallery", $version = 10);
     }
     if ($version == 10) {
         module::set_var("gallery", "image_sharpen", 15);
         module::set_version("gallery", $version = 11);
     }
     if ($version == 11) {
         $db->query("ALTER TABLE {items} ADD COLUMN `relative_url_cache` varchar(255) DEFAULT NULL");
         $db->query("ALTER TABLE {items} ADD COLUMN `slug` varchar(255) DEFAULT NULL");
         // This is imperfect since some of the slugs may contain invalid characters, but it'll do
         // for now because we don't want a lengthy operation here.
         $db->query("UPDATE {items} SET `slug` = `name`");
         // Flush all path caches because we're going to start urlencoding them.
         $db->query("UPDATE {items} SET `relative_url_cache` = NULL, `relative_path_cache` = NULL");
         module::set_version("gallery", $version = 12);
     }
     if ($version == 12) {
         if (module::get_var("gallery", "active_site_theme") == "default") {
             module::set_var("gallery", "active_site_theme", "wind");
         }
         if (module::get_var("gallery", "active_admin_theme") == "admin_default") {
             module::set_var("gallery", "active_admin_theme", "admin_wind");
         }
         module::set_version("gallery", $version = 13);
     }
     if ($version == 13) {
         // Add rules for generating our thumbnails and resizes
         Database::instance()->query("UPDATE {graphics_rules} SET `operation` = CONCAT('gallery_graphics::', `operation`);");
         module::set_version("gallery", $version = 14);
     }
     if ($version == 14) {
         $sidebar_blocks = block_manager::get_active("site_sidebar");
         if (empty($sidebar_blocks)) {
             $available_blocks = block_manager::get_available_site_blocks();
             foreach (array_keys(block_manager::get_available_site_blocks()) as $id) {
                 $sidebar_blocks[] = explode(":", $id);
             }
             block_manager::set_active("site_sidebar", $sidebar_blocks);
         }
         module::set_version("gallery", $version = 15);
     }
     if ($version == 15) {
         module::set_var("gallery", "identity_provider", "user");
         module::set_version("gallery", $version = 16);
     }
     // Convert block keys to an md5 hash of the module and block name
     if ($version == 16) {
         foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
             $blocks = block_manager::get_active($location);
             $new_blocks = array();
             foreach ($blocks as $block) {
                 $new_blocks[md5("{$block[0]}:{$block[1]}")] = $block;
             }
             block_manager::set_active($location, $new_blocks);
         }
         module::set_version("gallery", $version = 17);
     }
     // We didn't like md5 hashes so convert block keys back to random keys to allow duplicates.
     if ($version == 17) {
         foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
             $blocks = block_manager::get_active($location);
             $new_blocks = array();
             foreach ($blocks as $block) {
                 $new_blocks[random::int()] = $block;
             }
             block_manager::set_active($location, $new_blocks);
         }
         module::set_version("gallery", $version = 18);
     }
     // Rename blocks_site.sidebar to blocks_site_sidebar
     if ($version == 18) {
         $blocks = block_manager::get_active("site.sidebar");
         block_manager::set_active("site_sidebar", $blocks);
         module::clear_var("gallery", "blocks_site.sidebar");
         module::set_version("gallery", $version = 19);
     }
     // Set a default for the number of simultaneous uploads
     // Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
     if ($version == 19 || $version == 20) {
         module::set_var("gallery", "simultaneous_upload_limit", 5);
         module::set_version("gallery", $version = 21);
     }
     // Update the graphics rules table so that the maximum height for resizes is 640 not 480.
     // Fixes ticket #671
     if ($version == 21) {
         $resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
         // make sure it hasn't been changed already
         $args = unserialize($resize_rule->args);
         if ($args["height"] == 480 && $args["width"] == 640) {
             $args["height"] = 640;
             $resize_rule->args = serialize($args);
             $resize_rule->save();
         }
         module::set_version("gallery", $version = 22);
     }
     // Update slug values to be legal.  We should have done this in the 11->12 upgrader, but I was
     // lazy.  Mea culpa!
     if ($version == 22) {
         foreach (db::build()->from("items")->select("id", "slug")->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
             $new_slug = item::convert_filename_to_slug($row->slug);
             if (empty($new_slug)) {
                 $new_slug = random::int();
             }
             db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
         }
         module::set_version("gallery", $version = 23);
     }
     if ($version == 23) {
         $db->query("CREATE TABLE {failed_logins} (\n                  `id` int(9) NOT NULL auto_increment,\n                  `count` int(9) NOT NULL,\n                  `name` varchar(255) NOT NULL,\n                  `time` int(9) NOT NULL,\n                  PRIMARY KEY (`id`))\n                  DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 24);
     }
     if ($version == 24) {
         foreach (array("logs", "tmp", "uploads") as $dir) {
             self::_protect_directory(VARPATH . $dir);
         }
         module::set_version("gallery", $version = 25);
     }
     if ($version == 25) {
         db::build()->update("items")->set("title", db::expr("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
         module::set_version("gallery", $version = 26);
     }
     if ($version == 26) {
         if (in_array("failed_logins", Database::instance()->list_tables())) {
             $db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
         }
         module::set_version("gallery", $version = 27);
     }
     if ($version == 27) {
         // Set the admin area timeout to 90 minutes
         module::set_var("gallery", "admin_area_timeout", 90 * 60);
         module::set_version("gallery", $version = 28);
     }
     if ($version == 28) {
         module::set_var("gallery", "credits", "Powered by <a href=\"%url\">%gallery_version</a>");
         module::set_version("gallery", $version = 29);
     }
     if ($version == 29) {
         $db->query("ALTER TABLE {caches} ADD KEY (`key`);");
         module::set_version("gallery", $version = 30);
     }
     if ($version == 30) {
         module::set_var("gallery", "maintenance_mode", 0);
         module::set_version("gallery", $version = 31);
     }
     if ($version == 31) {
         $db->query("ALTER TABLE {modules} ADD COLUMN `weight` int(9) DEFAULT NULL");
         $db->query("ALTER TABLE {modules} ADD KEY (`weight`)");
         db::update("modules")->set("weight", db::expr("`id`"))->execute();
         module::set_version("gallery", $version = 32);
     }
     if ($version == 32) {
         $db->query("ALTER TABLE {items} ADD KEY (`left_ptr`)");
         module::set_version("gallery", $version = 33);
     }
     if ($version == 33) {
         $db->query("ALTER TABLE {access_caches} ADD KEY (`item_id`)");
         module::set_version("gallery", $version = 34);
     }
     if ($version == 34) {
         module::set_var("gallery", "visible_title_length", 15);
         module::set_version("gallery", $version = 35);
     }
     if ($version == 35) {
         module::set_var("gallery", "favicon_url", "lib/images/favicon.ico");
         module::set_version("gallery", $version = 36);
     }
     if ($version == 36) {
         module::set_var("gallery", "email_from", "*****@*****.**");
         module::set_var("gallery", "email_reply_to", "*****@*****.**");
         module::set_var("gallery", "email_line_length", 70);
         module::set_var("gallery", "email_header_separator", serialize("\n"));
         module::set_version("gallery", $version = 37);
     }
     // Changed our minds and decided that the initial value should be empty
     // But don't just reset it blindly, only do it if the value is version 37 default
     if ($version == 37) {
         $email = module::get_var("gallery", "email_from", "");
         if ($email == "*****@*****.**") {
             module::set_var("gallery", "email_from", "");
         }
         $email = module::get_var("gallery", "email_reply_to", "");
         if ($email == "*****@*****.**") {
             module::set_var("gallery", "email_reply_to", "");
         }
         module::set_version("gallery", $version = 38);
     }
     if ($version == 38) {
         module::set_var("gallery", "show_user_profiles_to", "registered_users");
         module::set_version("gallery", $version = 39);
     }
     if ($version == 39) {
         module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
         module::set_version("gallery", $version = 40);
     }
     if ($version == 40) {
         module::clear_var("gallery", "_cache");
         module::set_version("gallery", $version = 41);
     }
     if ($version == 41) {
         $db->query("TRUNCATE TABLE {caches}");
         $db->query("ALTER TABLE {caches} DROP INDEX `key`, ADD UNIQUE `key` (`key`)");
         module::set_version("gallery", $version = 42);
     }
     if ($version == 42) {
         $db->query("ALTER TABLE {items} CHANGE `description` `description` text DEFAULT NULL");
         module::set_version("gallery", $version = 43);
     }
     if ($version == 43) {
         $db->query("ALTER TABLE {items} CHANGE `rand_key` `rand_key` DECIMAL(11, 10)");
         module::set_version("gallery", $version = 44);
     }
     if ($version == 44) {
         $db->query("ALTER TABLE {messages} CHANGE `value` `value` text default NULL");
         module::set_version("gallery", $version = 45);
     }
     if ($version == 45) {
         // Splice the upgrade_checker block into the admin dashboard at the top
         // of the page, but under the welcome block if it's in the first position.
         $blocks = block_manager::get_active("dashboard_center");
         $index = count($blocks) && current($blocks) == array("gallery", "welcome") ? 1 : 0;
         array_splice($blocks, $index, 0, array(random::int() => array("gallery", "upgrade_checker")));
         block_manager::set_active("dashboard_center", $blocks);
         module::set_var("gallery", "upgrade_checker_auto_enabled", true);
         module::set_version("gallery", $version = 46);
     }
     if ($version == 46) {
         module::set_var("gallery", "apple_touch_icon_url", "lib/images/apple-touch-icon.png");
         module::set_version("gallery", $version = 47);
     }
     if ($version == 47 || $version == 48) {
         // Add configuration variable to set timezone.  Defaults to the currently
         // used timezone (from PHP configuration).  Note that in v48 we were
         // setting this value incorrectly, so we're going to stomp this value for v49.
         module::set_var("gallery", "timezone", null);
         module::set_version("gallery", $version = 49);
     }
     if ($version == 49) {
         // In v49 we changed the Item_Model validation code to disallow files with two dots in them,
         // but we didn't rename any files which fail to validate, so as soon as you do anything to
         // change those files (eg. as a side effect of getting the url or file path) it fails to
         // validate.  Fix those here.  This might be slow, but if it times out it can just pick up
         // where it left off.
         foreach (db::build()->from("items")->select("id")->where("type", "<>", "album")->where(db::expr("`name` REGEXP '\\\\..*\\\\.'"), "=", 1)->order_by("id", "asc")->execute() as $row) {
             set_time_limit(30);
             $item = ORM::factory("item", $row->id);
             $item->name = legal_file::smash_extensions($item->name);
             $item->save();
         }
         module::set_version("gallery", $version = 50);
     }
     if ($version == 50) {
         // In v51, we added a lock_timeout variable so that administrators could edit the time out
         // from 1 second to a higher variable if their system runs concurrent parallel uploads for
         // instance.
         module::set_var("gallery", "lock_timeout", 1);
         module::set_version("gallery", $version = 51);
     }
     if ($version == 51) {
         // In v52, we added functions to the legal_file helper that map photo and movie file
         // extensions to their mime types (and allow extension of the list by other modules).  During
         // this process, we correctly mapped m4v files to video/x-m4v, correcting a previous error
         // where they were mapped to video/mp4.  This corrects the existing items.
         db::build()->update("items")->set("mime_type", "video/x-m4v")->where("name", "REGEXP", "\\.m4v\$")->execute();
         module::set_version("gallery", $version = 52);
     }
     if ($version == 52) {
         // In v53, we added the ability to change the default time used when extracting frames from
         // movies.  Previously we hard-coded this at 3 seconds, so we use that as the default.
         module::set_var("gallery", "movie_extract_frame_time", 3);
         module::set_version("gallery", $version = 53);
     }
     if ($version == 53) {
         // In v54, we changed how we check for name and slug conflicts in Item_Model.  Previously,
         // we checked the whole filename.  As a result, "foo.jpg" and "foo.png" were not considered
         // conflicting if their slugs were different (a rare case in practice since server_add and
         // uploader would give them both the same slug "foo").  Now, we check the filename without its
         // extension.  This upgrade stanza fixes any conflicts where they were previously allowed.
         // This might be slow, but if it times out it can just pick up where it left off.
         // Find and loop through each conflict (e.g. "foo.jpg", "foo.png", and "foo.flv" are one
         // conflict; "bar.jpg", "bar.png", and "bar.flv" are another)
         foreach (db::build()->select_distinct(array("parent_base_name" => db::expr("CONCAT(`parent_id`, ':', LOWER(SUBSTR(`name`, 1, LOCATE('.', `name`) - 1)))")))->select(array("C" => "COUNT(\"*\")"))->from("items")->where("type", "<>", "album")->having("C", ">", 1)->group_by("parent_base_name")->execute() as $conflict) {
             list($parent_id, $base_name) = explode(":", $conflict->parent_base_name, 2);
             $base_name_escaped = Database::escape_for_like($base_name);
             // Loop through the items for each conflict
             foreach (db::build()->from("items")->select("id")->where("type", "<>", "album")->where("parent_id", "=", $parent_id)->where("name", "LIKE", "{$base_name_escaped}.%")->limit(1000000)->offset(1)->execute() as $row) {
                 set_time_limit(30);
                 $item = ORM::factory("item", $row->id);
                 $item->name = $item->name;
                 // this will force Item_Model to check for conflicts on save
                 $item->save();
             }
         }
         module::set_version("gallery", $version = 54);
     }
     if ($version == 54) {
         $db->query("ALTER TABLE {items} ADD KEY `relative_path_cache` (`relative_path_cache`)");
         module::set_version("gallery", $version = 55);
     }
     if ($version == 55) {
         // In v56, we added the ability to change the default behavior regarding movie uploads.  It
         // can be set to "always", "never", or "autodetect" to match the previous behavior where they
         // are allowed only if FFmpeg is found.
         module::set_var("gallery", "movie_allow_uploads", "autodetect");
         module::set_version("gallery", $version = 56);
     }
     if ($version == 56) {
         // Cleanup possible instances where resize_dirty of albums or movies was set to 0.  This is
         // unlikely to have occurred, and doesn't currently matter much since albums and movies don't
         // have resize images anyway.  However, it may be useful to be consistent here going forward.
         db::build()->update("items")->set("resize_dirty", 1)->where("type", "<>", "photo")->execute();
         module::set_version("gallery", $version = 57);
     }
     if ($version == 57) {
         // In v58 we changed the Item_Model validation code to disallow files or directories with
         // backslashes in them, and we need to fix any existing items that have them.  This is
         // pretty unlikely, as having backslashes would have probably already caused other issues for
         // users, but we should check anyway.  This might be slow, but if it times out it can just
         // pick up where it left off.
         foreach (db::build()->from("items")->select("id")->where(db::expr("`name` REGEXP '\\\\\\\\'"), "=", 1)->order_by("id", "asc")->execute() as $row) {
             set_time_limit(30);
             $item = ORM::factory("item", $row->id);
             $item->name = str_replace("\\", "_", $item->name);
             $item->save();
         }
         module::set_version("gallery", $version = 58);
     }
 }
while ($cursor != 0) {
    $connection->request('GET', $connection->url('1.1/friends/ids'), array('user_id' => $engagement_user_id, 'cursor' => $cursor));
    $http_code = $connection->response['code'];
    if ($http_code == 200) {
        $data = json_decode($connection->response['response'], true);
        // Get the list of friend user_ids, which will be an array
        $ids = $data['ids'];
        // Get the cursor value for the next request
        $cursor = $data['next_cursor_str'];
        // If there are any friends returned
        if (sizeof($ids)) {
            foreach ($ids as $user_id) {
                // If this friend is already in the table,
                // set the current field back to 1
                if ($db->in_table('friends', "user_id={$user_id}")) {
                    $db->update('friends', 'current=1', "user_id={$user_id}");
                } else {
                    // If this is a new friend,
                    // insert it with a current value of 1
                    $db->insert('friends', "user_id={$user_id},current=1");
                    // If this is not the first time friends have been collected,
                    // record this new friend event in the follow_log table
                    if (!$first_collection) {
                        $db->insert('follow_log', "user_id={$user_id},event='friend'");
                    }
                }
            }
        } else {
            // Stop collecting if no more friends are found
            break;
        }
Example #16
0
 function saveMap()
 {
     $map = $nomap = array();
     $map = explode(',', params::get('map'));
     $nomap = explode(',', params::get('nomap'));
     foreach ($map as $v) {
         db::table('pages');
         db::where('page_id', $v);
         db::update('page_map', '1');
     }
     foreach ($nomap as $v) {
         db::table('pages');
         db::where('page_id', $v);
         db::update('page_map', '0');
     }
 }
Example #17
0
 static function upgrade($version)
 {
     $db = Database::instance();
     if ($version == 1) {
         module::set_var("gallery", "date_format", "Y-M-d");
         module::set_var("gallery", "date_time_format", "Y-M-d H:i:s");
         module::set_var("gallery", "time_format", "H:i:s");
         module::set_version("gallery", $version = 2);
     }
     if ($version == 2) {
         module::set_var("gallery", "show_credits", 1);
         module::set_version("gallery", $version = 3);
     }
     if ($version == 3) {
         $db->query("CREATE TABLE {caches} (\n                 `id` varchar(255) NOT NULL,\n                 `tags` varchar(255),\n                 `expiration` int(9) NOT NULL,\n                 `cache` text,\n                 PRIMARY KEY (`id`),\n                 KEY (`tags`))\n                 DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 4);
     }
     if ($version == 4) {
         Cache::instance()->delete_all();
         $db->query("ALTER TABLE {caches} MODIFY COLUMN `cache` LONGBLOB");
         module::set_version("gallery", $version = 5);
     }
     if ($version == 5) {
         Cache::instance()->delete_all();
         $db->query("ALTER TABLE {caches} DROP COLUMN `id`");
         $db->query("ALTER TABLE {caches} ADD COLUMN `key` varchar(255) NOT NULL");
         $db->query("ALTER TABLE {caches} ADD COLUMN `id` int(9) NOT NULL auto_increment PRIMARY KEY");
         module::set_version("gallery", $version = 6);
     }
     if ($version == 6) {
         module::clear_var("gallery", "version");
         module::set_version("gallery", $version = 7);
     }
     if ($version == 7) {
         $groups = identity::groups();
         $permissions = ORM::factory("permission")->find_all();
         foreach ($groups as $group) {
             foreach ($permissions as $permission) {
                 // Update access intents
                 $db->query("ALTER TABLE {access_intents} MODIFY COLUMN {$permission->name}_{$group->id} BINARY(1) DEFAULT NULL");
                 // Update access cache
                 if ($permission->name === "view") {
                     $db->query("ALTER TABLE {items} MODIFY COLUMN {$permission->name}_{$group->id} BINARY(1) DEFAULT FALSE");
                 } else {
                     $db->query("ALTER TABLE {access_caches} MODIFY COLUMN {$permission->name}_{$group->id} BINARY(1) NOT NULL DEFAULT FALSE");
                 }
             }
         }
         module::set_version("gallery", $version = 8);
     }
     if ($version == 8) {
         $db->query("ALTER TABLE {items} CHANGE COLUMN `left`  `left_ptr`  INT(9) NOT NULL;");
         $db->query("ALTER TABLE {items} CHANGE COLUMN `right` `right_ptr` INT(9) NOT NULL;");
         module::set_version("gallery", $version = 9);
     }
     if ($version == 9) {
         $db->query("ALTER TABLE {items} ADD KEY `weight` (`weight` DESC);");
         module::set_version("gallery", $version = 10);
     }
     if ($version == 10) {
         module::set_var("gallery", "image_sharpen", 15);
         module::set_version("gallery", $version = 11);
     }
     if ($version == 11) {
         $db->query("ALTER TABLE {items} ADD COLUMN `relative_url_cache` varchar(255) DEFAULT NULL");
         $db->query("ALTER TABLE {items} ADD COLUMN `slug` varchar(255) DEFAULT NULL");
         // This is imperfect since some of the slugs may contain invalid characters, but it'll do
         // for now because we don't want a lengthy operation here.
         $db->query("UPDATE {items} SET `slug` = `name`");
         // Flush all path caches becuase we're going to start urlencoding them.
         $db->query("UPDATE {items} SET `relative_url_cache` = NULL, `relative_path_cache` = NULL");
         module::set_version("gallery", $version = 12);
     }
     if ($version == 12) {
         if (module::get_var("gallery", "active_site_theme") == "default") {
             module::set_var("gallery", "active_site_theme", "wind");
         }
         if (module::get_var("gallery", "active_admin_theme") == "admin_default") {
             module::set_var("gallery", "active_admin_theme", "admin_wind");
         }
         module::set_version("gallery", $version = 13);
     }
     if ($version == 13) {
         // Add rules for generating our thumbnails and resizes
         Database::instance()->query("UPDATE {graphics_rules} SET `operation` = CONCAT('gallery_graphics::', `operation`);");
         module::set_version("gallery", $version = 14);
     }
     if ($version == 14) {
         $sidebar_blocks = block_manager::get_active("site_sidebar");
         if (empty($sidebar_blocks)) {
             $available_blocks = block_manager::get_available_site_blocks();
             foreach (array_keys(block_manager::get_available_site_blocks()) as $id) {
                 $sidebar_blocks[] = explode(":", $id);
             }
             block_manager::set_active("site_sidebar", $sidebar_blocks);
         }
         module::set_version("gallery", $version = 15);
     }
     if ($version == 15) {
         module::set_var("gallery", "identity_provider", "user");
         module::set_version("gallery", $version = 16);
     }
     // Convert block keys to an md5 hash of the module and block name
     if ($version == 16) {
         foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
             $blocks = block_manager::get_active($location);
             $new_blocks = array();
             foreach ($blocks as $block) {
                 $new_blocks[md5("{$block[0]}:{$block[1]}")] = $block;
             }
             block_manager::set_active($location, $new_blocks);
         }
         module::set_version("gallery", $version = 17);
     }
     // We didn't like md5 hashes so convert block keys back to random keys to allow duplicates.
     if ($version == 17) {
         foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
             $blocks = block_manager::get_active($location);
             $new_blocks = array();
             foreach ($blocks as $block) {
                 $new_blocks[random::int()] = $block;
             }
             block_manager::set_active($location, $new_blocks);
         }
         module::set_version("gallery", $version = 18);
     }
     // Rename blocks_site.sidebar to blocks_site_sidebar
     if ($version == 18) {
         $blocks = block_manager::get_active("site.sidebar");
         block_manager::set_active("site_sidebar", $blocks);
         module::clear_var("gallery", "blocks_site.sidebar");
         module::set_version("gallery", $version = 19);
     }
     // Set a default for the number of simultaneous uploads
     // Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
     if ($version == 19 || $version == 20) {
         module::set_var("gallery", "simultaneous_upload_limit", 5);
         module::set_version("gallery", $version = 21);
     }
     // Update the graphics rules table so that the maximum height for resizes is 640 not 480.
     // Fixes ticket #671
     if ($version == 21) {
         $resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
         // make sure it hasn't been changed already
         $args = unserialize($resize_rule->args);
         if ($args["height"] == 480 && $args["width"] == 640) {
             $args["height"] = 640;
             $resize_rule->args = serialize($args);
             $resize_rule->save();
         }
         module::set_version("gallery", $version = 22);
     }
     // Update slug values to be legal.  We should have done this in the 11->12 upgrader, but I was
     // lazy.  Mea culpa!
     if ($version == 22) {
         foreach (db::build()->from("items")->select("id", "slug")->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
             $new_slug = item::convert_filename_to_slug($row->slug);
             if (empty($new_slug)) {
                 $new_slug = random::int();
             }
             db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
         }
         module::set_version("gallery", $version = 23);
     }
     if ($version == 23) {
         $db->query("CREATE TABLE {failed_logins} (\n                  `id` int(9) NOT NULL auto_increment,\n                  `count` int(9) NOT NULL,\n                  `name` varchar(255) NOT NULL,\n                  `time` int(9) NOT NULL,\n                  PRIMARY KEY (`id`))\n                  DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 24);
     }
     if ($version == 24) {
         foreach (array("logs", "tmp", "uploads") as $dir) {
             self::_protect_directory(VARPATH . $dir);
         }
         module::set_version("gallery", $version = 25);
     }
     if ($version == 25) {
         db::build()->update("items")->set("title", db::expr("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
         module::set_version("gallery", $version = 26);
     }
     if ($version == 26) {
         if (in_array("failed_logins", Database::instance()->list_tables())) {
             $db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
         }
         module::set_version("gallery", $version = 27);
     }
     if ($version == 27) {
         // Set the admin area timeout to 90 minutes
         module::set_var("gallery", "admin_area_timeout", 90 * 60);
         module::set_version("gallery", $version = 28);
     }
     if ($version == 28) {
         module::set_var("gallery", "credits", "Powered by <a href=\"%url\">%gallery_version</a>");
         module::set_version("gallery", $version = 29);
     }
     if ($version == 29) {
         $db->query("ALTER TABLE {caches} ADD KEY (`key`);");
         module::set_version("gallery", $version = 30);
     }
     if ($version == 30) {
         module::set_var("gallery", "maintenance_mode", 0);
         module::set_version("gallery", $version = 31);
     }
     if ($version == 31) {
         $db->query("ALTER TABLE {modules} ADD COLUMN `weight` int(9) DEFAULT NULL");
         $db->query("ALTER TABLE {modules} ADD KEY (`weight`)");
         db::update("modules")->set("weight", db::expr("`id`"))->execute();
         module::set_version("gallery", $version = 32);
     }
     if ($version == 32) {
         $db->query("ALTER TABLE {items} ADD KEY (`left_ptr`)");
         module::set_version("gallery", $version = 33);
     }
     if ($version == 33) {
         $db->query("ALTER TABLE {access_caches} ADD KEY (`item_id`)");
         module::set_version("gallery", $version = 34);
     }
     if ($version == 34) {
         module::set_var("gallery", "visible_title_length", 15);
         module::set_version("gallery", $version = 35);
     }
     if ($version == 35) {
         module::set_var("gallery", "favicon_url", "lib/images/favicon.ico");
         module::set_version("gallery", $version = 36);
     }
     if ($version == 36) {
         module::set_var("gallery", "email_from", "*****@*****.**");
         module::set_var("gallery", "email_reply_to", "*****@*****.**");
         module::set_var("gallery", "email_line_length", 70);
         module::set_var("gallery", "email_header_separator", serialize("\n"));
         module::set_version("gallery", $version = 37);
     }
     // Changed our minds and decided that the initial value should be empty
     // But don't just reset it blindly, only do it if the value is version 37 default
     if ($version == 37) {
         $email = module::get_var("gallery", "email_from", "");
         if ($email == "*****@*****.**") {
             module::set_var("gallery", "email_from", "");
         }
         $email = module::get_var("gallery", "email_reply_to", "");
         if ($email == "*****@*****.**") {
             module::set_var("gallery", "email_reply_to", "");
         }
         module::set_version("gallery", $version = 38);
     }
     if ($version == 38) {
         module::set_var("gallery", "show_user_profiles_to", "registered_users");
         module::set_version("gallery", $version = 39);
     }
     if ($version == 39) {
         module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
         module::set_version("gallery", $version = 40);
     }
     if ($version == 40) {
         module::clear_var("gallery", "_cache");
         module::set_version("gallery", $version = 41);
     }
     if ($version == 41) {
         $db->query("TRUNCATE TABLE {caches}");
         $db->query("ALTER TABLE {caches} DROP INDEX `key`, ADD UNIQUE `key` (`key`)");
         module::set_version("gallery", $version = 42);
     }
     if ($version == 42) {
         $db->query("ALTER TABLE {items} CHANGE `description` `description` text DEFAULT NULL");
         module::set_version("gallery", $version = 43);
     }
     if ($version == 43) {
         $db->query("ALTER TABLE {items} CHANGE `rand_key` `rand_key` DECIMAL(11, 10)");
         module::set_version("gallery", $version = 44);
     }
     if ($version == 44) {
         $db->query("ALTER TABLE {messages} CHANGE `value` `value` text default NULL");
         module::set_version("gallery", $version = 45);
     }
     if ($version == 45) {
         // Splice the upgrade_checker block into the admin dashboard at the top
         // of the page, but under the welcome block if it's in the first position.
         $blocks = block_manager::get_active("dashboard_center");
         $index = count($blocks) && current($blocks) == array("gallery", "welcome") ? 1 : 0;
         array_splice($blocks, $index, 0, array(random::int() => array("gallery", "upgrade_checker")));
         block_manager::set_active("dashboard_center", $blocks);
         module::set_var("gallery", "upgrade_checker_auto_enabled", true);
         module::set_version("gallery", $version = 46);
     }
 }
Example #18
0
 $created_at = $oDB->date($tweet_object->created_at);
 if (isset($tweet_object->geo)) {
     $geo_lat = $tweet_object->geo->coordinates[0];
     $geo_long = $tweet_object->geo->coordinates[1];
 } else {
     $geo_lat = $geo_long = 0;
 }
 $user_object = $tweet_object->user;
 $user_id = $user_object->id_str;
 $screen_name = $oDB->escape($user_object->screen_name);
 $name = $oDB->escape($user_object->name);
 $profile_image_url = $user_object->profile_image_url;
 // Add a new user row or update an existing one
 $field_values = 'screen_name = "' . $screen_name . '", ' . 'profile_image_url = "' . $profile_image_url . '", ' . 'user_id = ' . $user_id . ', ' . 'name = "' . $name . '", ' . 'location = "' . $oDB->escape($user_object->location) . '", ' . 'url = "' . $user_object->url . '", ' . 'description = "' . $oDB->escape($user_object->description) . '", ' . 'created_at = "' . $oDB->date($user_object->created_at) . '", ' . 'followers_count = ' . $user_object->followers_count . ', ' . 'friends_count = ' . $user_object->friends_count . ', ' . 'statuses_count = ' . $user_object->statuses_count . ', ' . 'time_zone = "' . $user_object->time_zone . '", ' . 'last_update = "' . $oDB->date($tweet_object->created_at) . '"';
 if ($oDB->in_table('users', 'user_id="' . $user_id . '"')) {
     $oDB->update('users', $field_values, 'user_id = "' . $user_id . '"');
 } else {
     $oDB->insert('users', $field_values);
 }
 // Add the new tweet
 $field_values = 'tweet_id = ' . $tweet_id . ', ' . 'tweet_text = "' . $tweet_text . '", ' . 'created_at = "' . $created_at . '", ' . 'geo_lat = ' . $geo_lat . ', ' . 'geo_long = ' . $geo_long . ', ' . 'user_id = ' . $user_id . ', ' . 'screen_name = "' . $screen_name . '", ' . 'name = "' . $name . '", ' . 'profile_image_url = "' . $profile_image_url . '", ' . 'is_rt = ' . $is_rt;
 $oDB->insert('tweets', $field_values);
 // The mentions, tags, and URLs from the entities object are also
 // parsed into separate tables so they can be data mined later
 foreach ($entities->user_mentions as $user_mention) {
     $where = 'tweet_id=' . $tweet_id . ' ' . 'AND source_user_id=' . $user_id . ' ' . 'AND target_user_id=' . $user_mention->id;
     if (!$oDB->in_table('tweet_mentions', $where)) {
         $field_values = 'tweet_id=' . $tweet_id . ', ' . 'source_user_id=' . $user_id . ', ' . 'target_user_id=' . $user_mention->id;
         $oDB->insert('tweet_mentions', $field_values);
     }
 }
Example #19
0
    }
    //imagedestroy($image);
    //imagedestroy($crop);
    if (!$fi) {
        return array("false", "Error saving picture");
    }
    return array("true", $newn);
}
$img = $_FILES["upl"]["tmp_name"];
if (isset($_POST["bgimg"]) && is_uploaded_file($img)) {
    $fa = array();
    $bg = (array) mvcp($img, 320, 630, uniqid($uid . "-"), $_FILES["upl"]["type"]);
    if ($bg[0]) {
        $con = new db();
        $r = $con->fromTable("users", "bg", "id={$uid}");
        if (strlen($r[0]) > 5 && !stristr($r[0], "default")) {
            @unlink(".." . $r[0]);
        }
        $st = $bg[1];
        $q = $con->update("users", "bg='{$st}'", "id={$uid}");
        if ($q) {
            echo "<script>\n\t\t\t\tparent._\$('prof_table').style.backgroundImage = '';\n\t\t\t\tparent.\$('.prof_table').fadeTo(200,0.5,function(){\n\t\t\t\t\tparent.\$('.prof_table').fadeTo(500,1);\n\t\t\t\t\tparent._\$('prof_table').style.backgroundImage = 'url(" . PTH . "{$st})';\n\t\t\t\t\t});\n\n\t\t\t\t</script>";
        } else {
            $msg = "{$bg['0']}:DB Error";
        }
    }
    $msg = $bg[0] ? "Background changed" : $bg[1];
    echo "<script>parent.\$('#upltxt').fadeIn('slow',function(){});parent.\$('#upltxt').html('{$msg}');parent.window.uploading(false);</script>";
} else {
    echo "error";
}
Example #20
0
            $obs .= $vi . $v;
            $vi = ", ";
        }
    }
    if (is_array($_POST["itens2"])) {
        $vi = '';
        $obs .= " AD:";
        while (list($k, $v) = each($_POST["itens2"])) {
            $db->executa($db->getAll("catprodutos_itens", "cpi_id={$v}", '', 0), true, "ext");
            $campos2 = array("ext_iteid" => $item, "ext_cipid" => $v, "ext_valor" => str_replace(".", ",", $db->ext["cpi_valor"]));
            $db->executa($db->insert($campos2, "comanda_itensextra"));
            $obs .= $vi . $db->ext["cpi_item"];
            $vi = ", ";
        }
    }
    $db->executa($db->update(array("cti_obs" => $obs), "comanda_itens", "cti_id", $item));
    $db->commit();
    //echo "<script>parent.consulta.location.reload();</script>";
}
if (isset($_POST["btnfecha"])) {
    $db->executa("select sum(cti_qtde*pro_preco)+coalesce(sum(ext_valor),0) as vltotal\n\t             from    comanda_itens inner join produtos on pro_id = cti_proid\n                         left outer join comanda_itensextra on cti_id = ext_iteid\n\t             where cti_comid= " . $_POST["com_id"], true, "vlt");
    $db->executa("update comandas set com_vltotal =" . $db->vlt["vltotal"] . " where com_id = " . $_POST["com_id"]);
    $nota = new atendimento($_POST["com_id"], $db);
    $nota->emite();
    echo "<script>parent.location.href='ate_mapamesas.php';</script>";
}
if (isset($_POST["btnexcluir"])) {
    $db->executa("delete from comandas where com_id= " . $_POST["com_id"]);
    echo "<script>parent.location.href='ate_mapamesas.php';</script>";
}
$form->Makeform("form1", "post", "", "", "", true, "Pedido");
Example #21
0
if (isset($_POST['course'])) {
    $std_id = $crnt_session->std_id;
    include_once "../classes/db.class.php";
    $dbh = new db();
    $mobile = $_POST['mobile'];
    $course = $_POST['course'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $exam_year = $_POST['exam_year'];
    $coaching_name = $_POST['coaching_name'];
    if (isset($_FILES['pic']['tmp_name']) && $_FILES['pic']['size'] > 0) {
        $pic_name = time() . ".jpg";
        if (!is_dir('../students/' . $std_id)) {
            mkdir('../students/' . $std_id);
            mkdir('../students/' . $std_id . '/images');
        } else {
            if (!is_dir('../students/' . $std_id . '/images')) {
                mkdir('../students/' . $std_id . '/images');
            }
        }
        move_uploaded_file($_FILES['pic']['tmp_name'], "../students/" . $std_id . "/images/" . $pic_name);
        $dbh->update("students", "img_src='{$pic_name}'", "id='{$std_id}'", "1");
    }
    $dbh->update("students", "first_name='{$fname}', last_name='{$lname}'", "id='{$std_id}'", "1");
    $dbh->update("registration", "mobile='{$mobile}', course='{$course}', coaching_name='{$coaching_name}', exam_year='{$exam_year}'", "id='{$std_id}'", "1");
    header("Location:../student-profile.php?msg=Update successfully!&msg_clr=green");
    exit;
} else {
    header("Location:../edit-std-profile.php?msg=Some error");
    exit;
}
Example #22
0
 /**
  * Saves the current object.
  *
  * @chainable
  * @return  ORM
  */
 public function save()
 {
     if (!empty($this->changed)) {
         // Require model validation before saving
         if (!$this->_valid) {
             $this->validate();
         }
         $data = array();
         foreach ($this->changed as $column) {
             // Compile changed data
             $data[$column] = $this->object[$column];
         }
         if (!$this->empty_primary_key() and !isset($this->changed[$this->primary_key])) {
             // Primary key isn't empty and hasn't been changed so do an update
             if (is_array($this->updated_column)) {
                 // Fill the updated column
                 $column = $this->updated_column['column'];
                 $format = $this->updated_column['format'];
                 $data[$column] = $this->object[$column] = $format === TRUE ? time() : date($format);
             }
             $query = db::update($this->table_name)->set($data)->where($this->primary_key, '=', $this->primary_key_value)->execute($this->db);
             // Object has been saved
             $this->_saved = TRUE;
         } else {
             if (is_array($this->created_column)) {
                 // Fill the created column
                 $column = $this->created_column['column'];
                 $format = $this->created_column['format'];
                 $data[$column] = $this->object[$column] = $format === TRUE ? time() : date($format);
             }
             $result = db::insert($this->table_name)->columns(array_keys($data))->values(array_values($data))->execute($this->db);
             if ($result->count() > 0) {
                 if (empty($this->object[$this->primary_key])) {
                     // Load the insert id as the primary key
                     $this->object[$this->primary_key] = $result->insert_id();
                 }
                 // Object is now loaded and saved
                 $this->_loaded = $this->_saved = TRUE;
             }
         }
         if ($this->saved() === TRUE) {
             // All changes have been saved
             $this->changed = array();
         }
     }
     if ($this->saved() === TRUE and !empty($this->changed_relations)) {
         foreach ($this->changed_relations as $column => $values) {
             // All values that were added
             $added = array_diff($values, $this->object_relations[$column]);
             // All values that were saved
             $removed = array_diff($this->object_relations[$column], $values);
             if (empty($added) and empty($removed)) {
                 // No need to bother
                 continue;
             }
             // Clear related columns
             unset($this->related[$column]);
             // Load the model
             $model = ORM::factory(inflector::singular($column));
             if (($join_table = array_search($column, $this->has_and_belongs_to_many)) === FALSE) {
                 continue;
             }
             if (is_int($join_table)) {
                 // No "through" table, load the default JOIN table
                 $join_table = $model->join_table($this->table_name);
             }
             // Foreign keys for the join table
             $object_fk = $this->foreign_key($join_table);
             $related_fk = $model->foreign_key($join_table);
             if (!empty($added)) {
                 foreach ($added as $id) {
                     // Insert the new relationship
                     db::insert($join_table)->columns($object_fk, $related_fk)->values($this->primary_key_value, $id)->execute($this->db);
                 }
             }
             if (!empty($removed)) {
                 db::delete($join_table)->where($object_fk, '=', $this->primary_key_value)->where($related_fk, 'IN', $removed)->execute($this->db);
             }
             // Clear all relations for this column
             unset($this->object_relations[$column], $this->changed_relations[$column]);
         }
     }
     if ($this->saved() === TRUE) {
         // Clear the per-request database cache
         $this->db->clear_cache(NULL, Database::PER_REQUEST);
     }
     return $this;
 }
<?php

//
require 'config.php';
require 'db_lib.php';
$db = new db();
// Get day of week number (Monday = 1)
$current_dow = date('N', strtotime('now'));
// Get all the randomly timed tweets for today
$query = "SELECT id\r\n\tFROM autotweet_recurring\r\n\tWHERE random_time\r\n\tAND dow LIKE '%{$current_dow}%'";
$results = $db->select($query);
while ($row = mysqli_fetch_assoc($results)) {
    $id = $row['id'];
    // Pick a new hour and minute
    // $autotweet_start and $autotweet_stop are set in config.php
    $new_hour = rand($autotweet_start, $autotweet_stop);
    $new_minute = rand(0, 59);
    // Save the new hour and minute
    $db->update('autotweet_recurring', "tweet_hour={$new_hour}, tweet_minute={$new_minute}", "id={$id}");
}
Example #24
0
     $common_url = "home.php?mod=space&uid={$org['uid']}&do=blog&id={$article['id']}";
     $form_url = "home.php?mod=spacecp&ac=comment";
     $article['commentnum'] = getcount('home_comment', array('id' => $article['id'], 'idtype' => 'blogid'));
     $query = DB::query("SELECT authorid AS uid, author AS username, dateline, message\n\t\t\tFROM " . DB::table('home_comment') . " WHERE id='{$article['id']}' AND idtype='blogid' ORDER BY dateline DESC LIMIT 0,20");
     while ($value = DB::fetch($query)) {
         $commentlist[] = $value;
     }
 } else {
     $common_url = "forum.php?mod=viewthread&tid={$article['id']}";
     $form_url = "forum.php?mod=post&action=reply&tid={$article['id']}&replysubmit=yes&infloat=yes&handlekey=fastpost";
     require_once libfile('function/discuzcode');
     $posttable = getposttablebytid($article['id']);
     $article['commentnum'] = getcount($posttable, array('tid' => $article['id'], 'first' => '0'));
     $firstpost = DB::fetch_first("SELECT first, authorid AS uid, author AS username, dateline, message, smileyoff, bbcodeoff, htmlon, attachment, pid\n\t\t\tFROM " . DB::table($posttable) . " WHERE tid='{$article['id']}' AND first='1'");
     if (!($org = $firstpost)) {
         db::update('portal_article_title', array('id' => 0, 'idtype' => ''), array('aid' => $aid));
         header("location: portal.php?mod=view&aid={$aid}");
         exit;
     }
     $attachpids = -1;
     $attachtags = $aimgs = array();
     $firstpost['message'] = $content['content'];
     if ($firstpost['attachment']) {
         if ($_G['group']['allowgetattach']) {
             $attachpids .= ",{$firstpost['pid']}";
             if (preg_match_all("/\\[attach\\](\\d+)\\[\\/attach\\]/i", $firstpost['message'], $matchaids)) {
                 $attachtags[$firstpost['pid']] = $matchaids[1];
             }
         } else {
             $firstpost['message'] = preg_replace("/\\[attach\\](\\d+)\\[\\/attach\\]/i", '', $firstpost['message']);
         }
Example #25
0
<?php

define('ROOT', '../');
//define('HOST','localhost');
//define('USER','root');
//define('PASS','admin');
//define('DBNAME','2015_etc');
define('HOST', 'localhost');
define('USER', 'root');
define('PASS', '');
define('DBNAME', 'admin_masterapk');
//require_once( ROOT.'../wp-admin/admin.php' );
include "inc/db.php";
include "inc/lib.php";
include "inc/simple_html_dom.php";
include "inc/function_string.php";
$db = new db();
$sql = "SELECT ID, file FROM wp_posts as p, wp_downloads as d WHERE p.ID = d.post_id ORDER BY ID DESC";
$list = $db->result($sql);
foreach ($list as $rs) {
    $id_com = getCom($rs->file);
    $vdata['id_com'] = $id_com;
    $db->update("wp_posts", $vdata, array("ID" => $rs->ID));
    unset($vdata);
}
Example #26
0
require "libs/classes.class";
require "libs/form2.class";
require "libs/funcoes.php";
require "libs/class_interface.php";
$db = new db();
if (isset($_POST['btncadastrar'])) {
    $campos = array("pro_id" => $_POST["pro_id"], "pro_nome" => $_POST["pro_nome"], "pro_descr" => $_POST["pro_descr"], "pro_estoque" => $_POST["pro_estoque"], "pro_catid" => $_POST["pro_catid"], "pro_foto" => $_POST["pro_foto"], "pro_preco" => $_POST["pro_preco"]);
    $rs = $db->executa($db->insert($campos, "produtos"));
    if ($rs) {
        $pro_id = $db->last_id("produtos_itens", 'ite_id');
        echo "<script>\n              parent.Ingredientes1.location.href='cad_nprodutoitem.php?pro_id={$pro_id}';\n              parent.mo_camada('Ingredientes','Ingredientes1');    \n              </script>";
    }
}
if (isset($_POST['btnalterar'])) {
    $campos = array("pro_nome" => $_POST["pro_nome"], "pro_descr" => $_POST["pro_descr"], "pro_estoque" => $_POST["pro_estoque"], "pro_catid" => $_POST["pro_catid"], "pro_foto" => $_POST["pro_foto"], "pro_preco" => $_POST["pro_preco"]);
    $db->valida_trans($db->update($campos, "produtos", "\n\t               pro_id", $_POST["pro_id"]), 0);
}
if (isset($_GET["pro_id"])) {
    $btnlabel = "Alterar";
    $btnname = "btnalterar";
    $db->dselect("produtos", "pro_id", $_GET["pro_id"], true);
    echo "<script>\n              parent.Ingredientes1.location.href='cad_nprodutoitem.php?pro_id={$pro_id}';\n              \n              </script>";
} else {
    $btnlabel = "Cadastrar";
    $btnname = "btncadastrar";
}
$form = new form('', false, "libs", false);
?>

<html>
<head>
Example #27
0
        @unlink("../video/" . $vid);
        if (!strstr($img, DEF_VID_IMG)) {
            @unlink("../prev/" . $img);
        }
        $con->close_db_con($conc);
        exit("<div {$style}>Successfully Deleted.</div>");
    } else {
        $con->close_db_con($conc);
        exit("<div {$style}>Error deleting video.</div>");
    }
}
if (isset($_POST["upd"])) {
    $id = intval($_POST["id"]);
    $name = strclean($_POST["name"]);
    $info = strclean($_POST["info"]);
    $upd = $con->update("videos", "name='{$name}', info ='{$info}'", "id={$id}");
    if ($upd) {
        exit("<div {$style}>Successfully updated {$name}</div>");
    } else {
        exit("<div {$style}>Error updating {$name}</div>");
    }
}
if (isset($_POST["add"])) {
    $img = $_FILES["upl"]["tmp_name"];
    $video = $_FILES["vid"]["tmp_name"];
    if (is_uploaded_file($video) && preg_match('/mp4|avi|mpeg|3gp|mkv|flv|mov/', extension($_FILES["vid"]["name"]))) {
        $_300x300 = is_uploaded_file($img) ? upload_pic($img, $_FILES["upl"]["type"], $_FILES["upl"]["tmp_name"], 300, 300) : DEF_VID_IMG;
        $vid = md5($video . " " . date("U")) . rand(0, 9) . extension($_FILES["vid"]["name"]);
        if ($_300x300 && copy($video, "../video/{$vid}")) {
            $name = strclean($_POST["name"]);
            $name = strlen($name) < 2 ? $_SESSION["user"] . "'s video " . rand(10, 999) : $name;
Example #28
0
        }
    }
    if (count($errors) > 0) {
        foreach ($errors as $error) {
            echo baltsms::alert($error, "danger");
        }
    } else {
        $baltsms = new baltsms();
        $baltsms->setPrice($_POST['price']);
        $baltsms->setCode($_POST['code']);
        $baltsms->sendRequest();
        if ($baltsms->getResponse() === true) {
            if ($db->count("SELECT `id` FROM `" . $c[$p]['db']['table'] . "` WHERE `name` = ?", array($_POST['name'])) == 0) {
                $db->insert("INSERT INTO `" . $c[$p]['db']['table'] . "` (`name`, `message`, `amount`, `time`) VALUES (?, ?, ?, ?)", array($_POST['name'], $_POST['message'], $_POST['price'], time()));
            } else {
                $db->update("UPDATE `" . $c[$p]['db']['table'] . "` SET `message` = ?, `amount` = `amount` + ?, `time` = ? WHERE `name` = ?", array($_POST['message'], $_POST['price'], time(), $_POST['name']));
            }
            echo baltsms::alert($lang[$p]['thanks_for_donating'], "success");
            ?>
			<script type="text/javascript">
				setTimeout(function(){
					loadPlugin('<?php 
            echo $p;
            ?>
');
				}, 3000 );
			</script>
			<?php 
        } else {
            echo $baltsms->getResponse();
        }
Example #29
0
function notification_add($touid, $type, $note, $notevars = array(), $system = 0)
{
    global $_G;
    $tospace = array('uid' => $touid);
    space_merge($tospace, 'field_home');
    $filter = empty($tospace['privacy']['filter_note']) ? array() : array_keys($tospace['privacy']['filter_note']);
    if ($filter && (in_array($type . '|0', $filter) || in_array($type . '|' . $_G['uid'], $filter))) {
        return false;
    }
    $notevars['actor'] = "<a href=\"home.php?mod=space&uid={$_G['uid']}\">" . $_G['member']['username'] . "</a>";
    $notestring = lang('notification', $note, $notevars);
    $oldnote = array();
    if ($notevars['from_id'] && $notevars['from_idtype']) {
        $oldnote = db::fetch_first("SELECT * FROM " . db::table('home_notification') . "\n\t\t\tWHERE from_id='{$notevars['from_id']}' AND from_idtype='{$notevars['from_idtype']}'");
    }
    if (empty($oldnote['from_num'])) {
        $oldnote['from_num'] = 0;
    }
    $setarr = array('uid' => $touid, 'type' => $type, 'new' => 1, 'authorid' => $_G['uid'], 'author' => $_G['username'], 'note' => addslashes($notestring), 'dateline' => $_G['timestamp'], 'from_id' => $notevars['from_id'], 'from_idtype' => $notevars['from_idtype'], 'from_num' => $oldnote['from_num'] + 1);
    if ($system) {
        $setarr['authorid'] = 0;
        $setarr['author'] = '';
    }
    if ($oldnote['id']) {
        db::update('home_notification', $setarr, array('id' => $oldnote['id']));
    } else {
        $oldnote['new'] = 0;
        DB::insert('home_notification', $setarr);
    }
    if (empty($oldnote['new'])) {
        DB::query("UPDATE " . DB::table('common_member_status') . " SET notifications=notifications+1 WHERE uid='{$touid}'");
        DB::query("UPDATE " . DB::table('common_member') . " SET newprompt=newprompt+1 WHERE uid='{$touid}'");
        require_once libfile('function/mail');
        $mail_subject = lang('notification', 'mail_to_user');
        sendmail_touser($touid, $mail_subject, $notestring, $type);
    }
    if (!$system && $_G['uid'] && $touid != $_G['uid']) {
        DB::query("UPDATE " . DB::table('home_friend') . " SET num=num+1 WHERE uid='{$_G['uid']}' AND fuid='{$touid}'");
    }
}
        $dm_text = $db->escape($dm->text);
        $created_at = $db->date($dm->created_at);
        $sender_user_id = $dm->sender->id;
        $recipient_user_id = $dm->recipient->id;
        $db->insert('dms', "dm_id={$dm_id},dm_text='{$dm_text}',created_at='{$created_at}',\r\n\t\t\tsender_user_id={$sender_user_id},recipient_user_id={$recipient_user_id},sent=1");
        $screen_name = $db->escape($dm->recipient->screen_name);
        $name = $db->escape($dm->recipient->name);
        $location = $db->escape($dm->recipient->location);
        $description = $db->escape($dm->recipient->description);
        $url = $db->escape($dm->recipient->url);
        $profile_image_url = $db->escape($dm->recipient->profile_image_url);
        $created_at = $dm->recipient->created_at;
        $friends_count = $dm->recipient->friends_count;
        $followers_count = $dm->recipient->followers_count;
        $statuses_count = $dm->recipient->statuses_count;
        $listed_count = $dm->recipient->listed_count;
        $lang = $dm->recipient->lang;
        if (empty($dm->recipient->protected)) {
            $protected = 0;
        } else {
            $protected = 1;
        }
        $field_values = "user_id={$sender_user_id}, name='{$name}', screen_name='{$screen_name}', profile_image_url='{$profile_image_url}',\r\n\t\t\tlocation='{$location}', description='{$description}', url='{$url}', created_at='{$created_at}', friends_count={$friends_count},\r\n\t\t\tfollowers_count={$followers_count}, statuses_count={$statuses_count}, listed_count={$listed_count}, lang='{$lang}',\r\n\t\t\tprotected={$protected}";
        if (!$db->in_table('users', "user_id={$recipient_user_id}")) {
            $db->insert('users', $field_values);
        } else {
            $db->update('users', $field_values, "user_id={$recipient_user_id}");
        }
    }
}
$db->update('engagement_account', 'old_dms_sent_collected=now()', "user_id={$engagement_user_id}");