public function brisi() { $db = new Db(); $sql = "DROP TABLE IF EXISTS " . $this->studenti; $db->query($sql); $sql = "DROP TABLE IF EXISTS " . $this->kolokvij; $db->query($sql); $sql = "DROP TABLE IF EXISTS " . $this->ispit; $db->query($sql); $sql = "DROP TABLE IF EXISTS " . $this->grupe; $db->query($sql); }
public function register($username, $password) { if ($this->userExists($username)) { throw new \Exception("User already exists."); } $result = $this->db->prepare("INSERT INTO users (username, password, gold , food)\n VALUES (?, ? ,?, ?);"); $result->execute([$username, password_hash($password, PASSWORD_DEFAULT), User::GOLD_DEFAULT, User::FOOD_DEFAULT]); if ($result->rowCount() > 0) { $userId = $this->db->lastId(); $this->db->query("INSERT INTO userbuildings (user_id, building_id, level_id)\n SELECT {$userId}, id, 0 FROM buildings"); return true; } throw new \Exception("Cannot register user."); }
public static function calculatePoints($killID, $tempTables = false) { $temp = $tempTables ? "_temporary" : ""; $victim = Db::queryRow("select * from zz_participants{$temp} where killID = :killID and isVictim = 1", array(":killID" => $killID), 0); $kill = $victim; $involved = Db::query("select * from zz_participants{$temp} where killID = :killID and isVictim = 0", array(":killID" => $killID), 0); $vicpoints = self::getPoints($victim["groupID"]); $vicpoints += $kill["total_price"] / 10000000; $maxpoints = round($vicpoints * 1.2); $invpoints = 0; foreach ($involved as $inv) { $invpoints += self::getPoints($inv["groupID"]); } if ($vicpoints + $invpoints == 0) { return 0; } $gankfactor = $vicpoints / ($vicpoints + $invpoints); $points = ceil($vicpoints * ($gankfactor / 0.75)); if ($points > $maxpoints) { $points = $maxpoints; } $points = round($points, 0); return max(1, $points); // a kill is always worth at least one point }
function pagination2($messageParPage, $table, $id) { /* paginatio_array 0->Nbre d'enregistrements paginatio_array 1->Nbre de pages paginatio_array 2->Pages actuelle paginatio_array 3->Premiere entree */ $id = Utils::anti_injection($id); $pagination_array = array(); $sqlQuery = "SELECT COUNT(*) AS total FROM " . TABLE_PREFIX . $table . " where titre_txt_fr like '%" . $id . "%' or description_txtbox_fr like '%" . $id . "%'"; $getTotal = Db::query($sqlQuery); $donnees_total = Db::fetch_assoc($getTotal); $pagination_array[0] = $donnees_total['total']; $pagination_array[1] = ceil($pagination_array[0] / $messageParPage); if (isset($_GET['page'])) { $pagination_array[2] = intval($_GET['page']); if ($pagination_array[2] > $pagination_array[1] && $pagination_array[1] > 0) { $pagination_array[2] = $pagination_array[1]; } } else { $pagination_array[2] = 1; } $pagination_array[3] = ($pagination_array[2] - 1) * $messageParPage; return $pagination_array; }
public function dispatch() { $result = Db::query("SELECT personas.id_personas\n , personas.nombre\n , personas.apellido\n , personas.correo\n , personas.cargo\n , personas.tel_oficina\n , personas.tel_oficina_int\n , personas.tel_celular\n , personas.tel_fax\n , personas.tel_casa\n , personas.foto\n , empresas.id_empresas\n , empresas.nombre AS empresa\n , empresas.direccion_1\n , empresas.direccion_2\n , empresas.ciudad\n , empresas.estado\n , empresas.cod_postal\n , empresas.web\n , empresas.tel_oficina AS e_tel_oficina\n , empresas.tel_fax AS e_tel_fax\n , paises.id_paises\n , paises.nombre AS pais\n FROM personas\n RIGHT JOIN empresas ON empresas.id_empresas = personas.id_empresas\n LEFT JOIN paises ON paises.id_paises = empresas.id_paises\n ORDER BY paises.nombre, empresas.nombre, personas.nombre"); if ($result) { $i = 0; $row = $result[$i]; while (isset($result[$i])) { $idEmpresas = $row['id_empresas']; $direccion = String::format("{%s}{ %s}", $row['direccion_1'], $row['direccion_2']); $lugar = String::format("{%s}{, %s}{ (%s)}", $row['ciudad'], $row['estado'], $row['cod_postal']); $this->data[$idEmpresas] = array('nombre' => $row['empresa'], 'pais' => $row['pais'], 'direccion' => $direccion, 'lugar' => $lugar, 'tel_oficina' => $row['e_tel_oficina'], 'tel_fax' => $row['e_tel_fax'], 'web' => $row['web'], 'personas' => array()); while (isset($result[$i]) && $idEmpresas == $row['id_empresas']) { $idPersonas = $row['id_personas']; if ($idPersonas > 0) { $nombre = String::format("{%s}{ %s}", $row['nombre'], $row['apellido']); $telOficina = String::format("{%s}{ x%s}", $row['tel_oficina'], $row['tel_oficina_int']); $this->data[$idEmpresas]['personas'][$idPersonas] = array('nombre' => $nombre, 'correo' => $row['correo'], 'cargo' => $row['cargo'], 'tel_oficina' => $telOficina, 'tel_celular' => $row['tel_celular'], 'tel_fax' => $row['tel_fax'], 'tel_casa' => $row['tel_casa'], 'foto' => $row['foto']); } $i++; if (isset($result[$i])) { $row = $result[$i]; } } } } parent::dispatch(); }
/** * 获取所有数据 * * @param string $sql * @return multitype:unknown */ public function select($sql, $index = '') { $arr = array(); $query = $this->db->query($sql); if (empty($index)) { while ($row = $this->db->fetchArray($query)) { $arr[] = $row; } return $arr; } else { while ($row = $this->db->fetchArray($query)) { $arr[$row[$index]] = $row; } return $arr; } }
function changepwd() { $retour = true; $oldpwd = Db::escape($_POST['old']); $newpwd = Db::escape($_POST['new']); $verifpwd = Db::escape($_POST['verif']); $login = Db::escape($_POST['login']); $getLogin = Db::query("SELECT * FROM `" . TABLE_PREFIX . "admin` WHERE `login_txt` = '" . $login . "'"); if (Db::num_rows($getLogin) > 0) { $this->login = $login; $getPwd = Db::query("SELECT * FROM `" . TABLE_PREFIX . "admin` WHERE `login_txt` = '" . $login . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND `mdp_txt` = '" . md5($oldpwd) . "'"); if (Db::num_rows($getPwd) > 0) { if ($newpwd != $verifpwd) { $this->errors = "changeVerif"; $retour = false; } else { Db::query("UPDATE " . TABLE_PREFIX . "admin SET mdp_txt = '" . md5($newpwd) . "' WHERE login_txt = '" . $login . "'"); } } else { $this->errors = "pwd"; $retour = false; } } else { $this->errors = "login"; $retour = false; } return $retour; }
/** * count * @param Db $db * @return array */ function getCountRecFood(&$db) { $sql = "select favor,cometrue from recommendedfood,users \n\t\t\twhere recommendedfood.user_id=users.user_id\n\t\t\tand users.school_id={$_POST['school_id']};"; $res = $db->query($sql); if ($res !== false) { $return = array(); $return['count'] = 0; $return['wish_satisfied_rate'] = 0.0; $return['lineover_rate'] = 0.0; $return['line'] = 500; //心愿线数量 $return['count'] = sizeof($res); if ($return['count'] === 0) { return $return; } $linecount = 0; $truecount = 0; foreach ($res as $value) { if ($value['cometrue']) { $truecount++; } if ($value['favor'] >= 500) { $linecount++; } } $return['lineover_rate'] = $linecount / $return['count']; $return['wish_satisfied_rate'] = $truecount / $return['count']; return $return; } else { echo getJsonResponse(1, $db->error, null); Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__)); //错误日志 exit; } }
public function Get($pa_additional_query_params = null, $pa_options = null) { $ps_query = $this->request->getParameter('q', pString); $ps_bundle = $this->request->getParameter('bundle', pString); $va_tmp = explode('.', $ps_bundle); $vs_table = $va_tmp[0]; $vs_field = $va_tmp[1]; $o_dm = Datamodel::load(); if (!($t_table = $o_dm->getInstanceByTableName($vs_table, true))) { // bad table name print _t("Invalid table name"); return null; } if (!$t_table->hasField($vs_field) || !in_array($t_table->getFieldInfo($vs_field, 'FIELD_TYPE'), array(FT_TEXT, FT_NUMBER))) { // bad field name print _t("Invalid bundle name"); return null; } if ($this->request->user->getBundleAccessLevel($vs_table, $vs_field) == __CA_BUNDLE_ACCESS_NONE__) { print _t("You do not have access to this bundle"); return null; } $vn_max_returned_values = 50; $o_db = new Db(); $qr_res = $o_db->query("\n\t\t\t\tSELECT DISTINCT {$vs_field}\n\t\t\t\tFROM {$vs_table}\n\t\t\t\tWHERE\n\t\t\t\t\t({$vs_field} LIKE ?) " . ($t_table->hasField('deleted') ? ' AND deleted = 0' : '') . "\n\t\t\t\tORDER BY\n\t\t\t\t\t{$vs_field}\n\t\t\t\tLIMIT {$vn_max_returned_values}\n\t\t\t", (string) $ps_query . '%'); $this->view->setVar('intrinsic_value_list', $qr_res->getAllFieldValues($vs_field)); return $this->render('ajax_intrinsic_value_list_html.php'); }
public function save() { if (is_numeric($this->page_id) && is_string($this->page_name)) { $db = new Db(); $id = $db->quote($this->page_id); $category_id = $db->quote($this->category_id); $name = $db->quote($this->page_name); $url = $db->quote($this->url); $top_description = $db->quote($this->top_description); $bottem_description = $db->quote($this->bottom_description); $keyword = $db->quote($this->keyword); $title = $db->quote($this->title); $description = $db->quote($this->description); $access_type = $db->quote($this->access_type); $active = $db->quote($this->page_status); $author = $db->quote(1); $modified = $db->quote(1); $query = "INSERT INTO " . $this->tableName() . " (page_id, category_id, name, url, top_description, bottem_description, \n Keyword, title, description, author, modified_by, access_type, active) \n VALUES({$id}, {$category_id}, {$name}, {$url}, {$top_description}, {$bottem_description}, {$keyword}, {$title}, {$description},\n {$author}, {$modified}, {$access_type}, {$active})\n ON DUPLICATE KEY UPDATE \n name= {$name}, category_id={$category_id}, url={$url},top_description={$top_description}, bottem_description={$bottem_description}, \n Keyword={$keyword}, title={$title}, description={$description}, author={$author}, modified_by={$modified}, \n active={$active}, access_type={$access_type}"; if ($db->query($query)) { return true; } else { Error::set($db->error()); } } return false; }
/** * Записывает видео в топ саммых папулярных видео если оно подходит по балам или видео в топе не привышает MAX_POPULAR_VIDEO_IN_CATEGORY * @param $videoId * @param $categoriesIds * @param $balls * @throws Exception */ public function setPopularVideo($videoId, $categoriesIds, $balls) { if (!empty($categoriesIds)) { $categories = explode(',', $categoriesIds); foreach ($categories as $category) { // Если видео есть в списке популярных то в нем просто обновляются баллы $this->db->query("UPDATE video_popular SET balls = :balls WHERE video_id = :videoId AND category_id = :categoryId", ['videoId' => $videoId, 'categoryId' => $category, 'balls' => $balls]); if ($this->db->getConnect()->affected_rows < 1) { // если нет видео, получается видео с самым меньшим колличеством баллов $minBallsVideo = $this->db->fetchRow("SELECT SQL_CALC_FOUND_ROWS * FROM video_popular WHERE category_id = :categoryId ORDER BY balls ASC LIMIT 1", ['categoryId' => $category]); $foundRows = $this->db->fetchOne("SELECT FOUND_ROWS();"); $insertVideo = false; // если популярных видео в категории меньше чем значение это значит что мы можем просто добавить видео в популярные if ($foundRows < self::MAX_POPULAR_VIDEO_IN_CATEGORY) { $insertVideo = true; } else { if ($minBallsVideo['balls'] < $balls) { // если у текущего видео балл выше чем у видео с наименьшим балом, то заменяем видео с наименьшим балом на текущее. $insertVideo = true; $this->db->query("DELETE FROM video_popular WHERE video_id = :videoId AND category_id = :categoryId", ['videoId' => $minBallsVideo['video_id'], 'categoryId' => $minBallsVideo['category_id']]); } } if ($insertVideo) { $this->db->query("INSERT INTO video_popular (video_id, category_id, balls) VALUES (:videoId, :categoryId, :balls)", ['videoId' => $videoId, 'categoryId' => $category, 'balls' => $balls]); } } } } }
function pagination($messageParPage, $table, $sscategorie) { /* paginatio_array 0->Nbre d'enregistrements paginatio_array 1->Nbre de pages paginatio_array 2->Pages actuelle paginatio_array 3->Première entrée */ $sscategorie = Utils::anti_injection($sscategorie); $pagination_array = array(); $sqlQuery = "SELECT COUNT(*) AS total FROM " . TABLE_PREFIX . $table . " WHERE sscat_radio=" . $sscategorie; $getTotal = Db::query($sqlQuery); $donnees_total = Db::fetch_assoc($getTotal); $pagination_array[0] = $donnees_total['total']; $pagination_array[1] = ceil($pagination_array[0] / $messageParPage); if (isset($_GET['page'])) { $pagination_array[2] = intval($_GET['page']); if ($pagination_array[2] > $pagination_array[1] && $pagination_array[1] > 0) { $pagination_array[2] = $pagination_array[1]; } } else { $pagination_array[2] = 1; } $pagination_array[3] = ($pagination_array[2] - 1) * $messageParPage; return $pagination_array; }
function login() { $retour = false; $login = Db::escape($_POST['login']); $getAuth = Db::query("SELECT * FROM `" . TABLE_PREFIX . "admin` WHERE `login_txt` = '" . $login . "'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND `mdp_txt` = '" . Db::escape(md5($_POST['mdp'])) . "'"); if (Db::num_rows($getAuth) > 0) { $_SESSION['key'] = true; // Mise en session de la connexion $entry = Db::fetch_assoc($getAuth); $retour = true; } else { $getLogin = Db::query("SELECT * FROM `" . TABLE_PREFIX . "admin` WHERE `login_txt` = '" . $login . "'"); if (Db::num_rows($getLogin) > 0) { $this->login = $login; $getPwd = Db::query("SELECT * FROM `" . TABLE_PREFIX . "admin` WHERE `login_txt` = '" . $login . "'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND `mdp_txt` = '" . Db::escape(md5($_POST['mdp'])) . "'"); if (Db::num_rows($getPwd) <= 0) { $this->errors = "pwd"; } } else { $this->errors = "login"; } $retour = false; } return $retour; }
function pagination($messageParPage, $sscategorie, $search, $searchColumn) { /* paginatio_array 0->Nbre d'enregistrements paginatio_array 1->Nbre de pages paginatio_array 2->Pages actuelle paginatio_array 3->Première entrée */ $pagination_array = array(); if (!empty($search)) { $sqlQuery = "SELECT COUNT(*) AS total FROM " . TABLE_PREFIX . CATEGORIE_NOM . " WHERE sscat_radio = '" . $sscategorie . "' AND "; for ($i = 0; $i < sizeof($searchColumn); $i++) { if ($i != 0 && $i != sizeof($searchColumn)) { $sqlQuery .= "OR "; } $sqlQuery .= $searchColumn[$i] . " like '%" . Db::escape($search) . "%' "; } } else { $sqlQuery = "SELECT COUNT(*) AS total FROM " . TABLE_PREFIX . CATEGORIE_NOM . " WHERE sscat_radio = '" . $sscategorie . "'"; } $getTotal = Db::query($sqlQuery); $donnees_total = Db::fetch_assoc($getTotal); $pagination_array[0] = $donnees_total['total']; $pagination_array[1] = ceil($pagination_array[0] / $messageParPage); if (isset($_POST['page'])) { $pagination_array[2] = intval($_POST['page']); if ($pagination_array[2] > $pagination_array[1] && $pagination_array[1] > 0) { $pagination_array[2] = $pagination_array[1]; } } else { $pagination_array[2] = 1; } $pagination_array[3] = ($pagination_array[2] - 1) * $messageParPage; return $pagination_array; }
public function update_ressources() { $sql = "SELECT income from modifiers WHERE user_id = {$this->id}"; $req = Db::query($sql); $income = $req->fetchColumn(); $this->increase_ressource(round(get_time_diff($this->last_refresh) * $income), true); }
public function addjobs() { if (is_numeric($this->id)) { $db = new Db(); if (Session::read("userid")) { $user_id = Session::read("userid"); $id = $db->quote($this->id); $heading = $db->quote($this->heading); $post = $db->quote($this->post); $education = $db->quote($this->education); $exp_min = $db->quote($this->exper_min); $exp_max = $db->quote($this->exper_max); $salary = $db->quote($this->salary); $description = $db->quote($this->description); $company_name = $db->quote($this->company_name); $website = $db->quote($this->website); $email = $db->quote($this->email); $phone = $db->quote($this->phone); $city = $db->quote($this->city); $address = $db->quote($this->address); $query = "INSERT INTO " . $this->tableName() . " (id,user_id, heading, post, education, exp_min, exp_max,\n salary, description, company_name, company_url, phone, city, address, active)\n VALUES({$id} ,{$user_id},{$heading},{$post},{$education},{$exp_min},{$exp_max},{$salary},{$description},{$company_name},{$website},{$email},\n {$phone},{$city},{$address},1)"; if ($db->query($query)) { if ($db->affectedRows()) { return true; } } } } return false; }
public function save() { if (is_numeric($this->id) && is_string($this->name)) { $db = new Db(); $id = $db->quote($this->id); $user_id = $db->quote($this->user_id); $doc_type_id = $db->quote($this->doc_type_id); $heading = $db->quote($this->heading); $description = $db->quote($this->desc); $category_id = $db->quote($this->category_id); $cost = $db->quote($this->cost); $case = $db->quote($this->case_no); $judge = $db->quote($this->judges); $act = $db->quote($this->act); $file = $db->quote($this->file); $active = $db->quote($this->active); $query = "INSERT INTO " . $this->tableName() . " (user_id,type_id,heading,desc,category_id,cost,case_no,judges,act,file,active) \n VALUES({$doc_type_id},{$heading},{$description},{$category_id},{$cost},{$case},{$judge},{$act},{$file}, {$active}) \n ON DUPLICATE KEY UPDATE \n user_id={$user_id},type_id={$doc_type_id},heading={$heading},desc={$description},category_id={$category_id},cost={$cost},\n case_no={$cost},judges={$judge},act={$act},file={$file},active={$active}"; if ($db->query($query)) { if ($db->affectedRows()) { return true; } } } return false; }
public function addcompany() { $errors = Error::get("error"); if (!count($errors) || $errors == "") { $db = new Db(); if (Session::read("userid")) { $user_id = Session::read("userid"); //print_r($user_id); exit(); // $user_id=$db->quote($this->user_id); $name = $db->quote($this->name); $email = $db->quote($this->email); $website = $db->quote($this->website); $phone = $db->quote($this->phone); $city = $db->quote($this->city); $location = $db->quote($this->location); $specialization = $db->quote($this->specialization); $description = $db->quote($this->description); $query = "INSERT INTO " . $this->tableName() . " (user_id,name,city,location,website,email,phone,specialization,description,active) \n VALUES({$user_id},{$name},{$city},{$location},{$website},{$email},{$phone},{$specialization},{$description},1)"; if ($db->query($query)) { //print_r($query); exit(); if ($db->affectedRows()) { return true; } } } } return false; }
public function Read() { $prefix = Database::instance()->table_prefix(); $query = "SELECT wp_posts.post_title AS title, wp_posts.post_excerpt AS excerpt,\n (SELECT p.guid FROM wp_posts AS p WHERE p.post_type ='attachment' AND p.post_parent = wp_posts.ID ORDER BY post_date ASC LIMIT 1 ) AS attachment \n FROM wp_term_relationships\n\t LEFT JOIN " . $prefix . "posts ON wp_term_relationships.object_id = wp_posts.ID\n\t LEFT JOIN " . $prefix . "term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id\n\t LEFT JOIN " . $prefix . "terms ON wp_terms.term_id = wp_term_relationships.term_taxonomy_id\n\t WHERE post_type = 'product' AND taxonomy = 'product_cat'"; $this->data = Db::query(Database::SELECT, $query)->execute()->as_array(); return $this->data; }
public function getGroupName($uid = 0) { $uid = $uid ?: v('user.uid'); $sql = "SELECT title,id FROM " . tablename('member') . " m JOIN " . tablename('member_group') . " g ON m.group_id = g.id WHERE m.uid={$uid}"; $d = Db::query($sql); return $d ? $d[0] : NULL; }
public function renderWidget($ps_widget_id, &$pa_settings) { parent::renderWidget($ps_widget_id, $pa_settings); $vn_threshold = time() - $pa_settings['logins_since'] * 60 * 60; $o_db = new Db(); $qr_res = $o_db->query("\n\t\t\t\tSELECT e.code, e.message, e.date_time\n\t\t\t\tFROM ca_eventlog e\n\t\t\t\tWHERE\n\t\t\t\t\t(e.date_time >= ?) AND (e.code = 'LOGN')\n\t\t\t\tORDER BY\n\t\t\t\t\te.date_time DESC\n\t\t\t", $vn_threshold); $va_login_list = array(); $t_user = new ca_users(); $va_user_cache = array(); while ($qr_res->nextRow()) { $va_log = $qr_res->getRow(); $vs_message = $va_log['message']; $va_tmp = explode(';', $vs_message); $vs_username = '******'; if (preg_match('!\'([^\']+)\'!', $va_tmp[0], $va_matches)) { $vs_username = $va_matches[1]; } $va_log['username'] = $vs_username; if (!isset($va_user_cache[$vs_username])) { if ($t_user->load(array('user_name' => $vs_username))) { $va_user_cache[$vs_username] = array('fname' => $t_user->get('fname'), 'lname' => $t_user->get('lname'), 'email' => $t_user->get('email')); } else { $va_user_cache[$vs_username] = array('fname' => '?', 'lname' => '?', 'email' => '?'); } } $va_log = array_merge($va_log, $va_user_cache[$vs_username]); $va_log['ip'] = str_replace('IP=', '', $va_tmp[1]); $va_login_list[] = $va_log; } $this->opo_view->setVar('request', $this->getRequest()); $this->opo_view->setVar('login_list', $va_login_list); return $this->opo_view->render('main_html.php'); }
static function getDataItem($id) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/config/remote.db.php")) { include_once $_SERVER['DOCUMENT_ROOT'] . "/config/remote.db.php"; } if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/helpers/db.operations.php")) { include_once $_SERVER['DOCUMENT_ROOT'] . "/helpers/db.operations.php"; } $products_arr = Db::query("SELECT id,product_code,price,product_name,colors,first_photo FROM products WHERE id='{$id}'"); if (count($products_arr) > 0) { $products = mysql_fetch_assoc($products_arr); if (!$_SESSION['cart']) { $_SESSION['cart'] = array(); } if (!$_SESSION['cart']['count']) { $_SESSION['cart']['count'] = 0; } $pid = $products['id']; if (!$_SESSION['cart'][$pid]) { $_SESSION['cart'][$pid] = $products; $_SESSION['cart'][$pid]['count'] = 1; } else { $_SESSION['cart'][$pid]['count'] = $_SESSION['cart'][$pid]['count'] + 1; } $_SESSION['cart']['count']++; if ($_SESSION['cart']['count'] > 0) { $coun = $_SESSION['cart']['count']; } else { $coun = 0; } echo $coun; } else { echo "Запрошен не существующий товар"; } }
function reset_keywords($new_kws_str, $type = 'equal') { $ks = $this->keywords(); $old_kws = array(); foreach ($ks as $k) { $old_kws[] = $k->keyword; } $ps = explode(',', $new_kws_str); $kws = array(); foreach ($ps as $p) { $p = trim($p); if (strlen($p)) { $kws[$p] = $p; } } $to_del = array_diff($old_kws, $kws); foreach ($to_del as $k) { Db::escape($k); $sql = "delete from wx_reply_keywords where item_id='{$this->id}' and keyword='{$k}'"; Db::query($sql); } $to_add = array_diff($kws, $old_kws); foreach ($to_add as $k) { WxReplyKeyword::save(array('type' => $type, 'keyword' => $k, 'item_id' => $this->id)); } $sql = "update " . WxReplyKeyword::table() . " set type='{$type}' where item_id='{$this->id}'"; Db::update($sql); }
public static function cachePrimer() { Db::execute("set session wait_timeout = 120"); self::storeResult(Db::query("select c.* from zz_characters c left join zz_participants p on (c.characterID = p.characterID) where dttm > date_sub(now(), interval 5 day) group by characterID", array(), 0), "select name from zz_characters where characterID = :id", ":id", "characterID", "name"); self::storeResult(Db::query("select * from zz_corporations", array(), 0), "select name from zz_corporations where corporationID = :id", ":id", "corporationID", "name"); self::storeResult(Db::query("select * from zz_alliances", array(), 0), "select name from zz_alliances where allianceID = :id", ":id", "allianceID", "name"); self::storeResult(Db::query("select * from ccp_invTypes", array(), 0), "select typeName from invTypes where typeID = :typeID", ":typeID", "typeID", "typeName"); }
public function Read($id) { $prefix = Database::instance()->table_prefix(); $query = "SELECT terms.term_id\n FROM " . $prefix . "terms AS terms\n WHERE terms.slug = :id"; $query = DB::select(array("p.ID", "ID"), array("p.post_title", "title"), array("p.post_name", "post_name"), array("p.menu_order", "menu_order"), array("n.post_name", "n_name"), array("n.post_title", "n_title"), array("m.meta_value", "m_meta_value"), array("pp.meta_value", "menu_parent"), array("pt.meta_value", "type"))->from(array("term_relationships", "txr"))->join(array("posts", "p"), "INNER")->on("txr.object_id", "=", "p.ID")->join(array("postmeta", "m"), "LEFT")->on("p.ID", "=", "m.post_id")->join(array("postmeta", "pl"), "LEFT")->on("p.ID", "=", "pl.post_id")->and_where("pl.meta_key", "=", "_menu_item_object_id")->join(array("postmeta", "pp"), "LEFT")->on("p.ID", "=", "pp.post_id")->and_where("pp.meta_key", "=", "_menu_item_menu_item_parent")->join(array("postmeta", "pt"), "LEFT")->on("p.ID", "=", "pt.post_id")->and_where("pt.meta_key", "=", "_menu_item_object")->join(array("posts", "n"), "LEFT")->on("pl.meta_value", "=", "n.ID")->where("p.post_status", "=", "publish")->and_where("p.post_type", "=", "nav_menu_item")->and_where("m.meta_key", "=", "_menu_item_url")->and_where("txr.term_taxonomy_id", "=", Db::query(Database::SELECT, $query)->bind(":id", $id))->order_by("p.menu_order", "ASC")->execute(); $this->data = $this->_FormatTree($query->as_array(), 0, $id); return $this->data; }
public function checkIfFooIsEmpty() { $this->assertEquals(0, $this->db->getTransactionCount()); $qr_select = $this->db->query("SELECT * FROM foo"); $this->assertInternalType('object', $qr_select); $this->assertFalse($qr_select->nextRow()); $this->assertEquals(0, $qr_select->numRows()); }
public function handle($rid) { $sql = "SELECT * FROM hd_reply_basic WHERE rid={$rid} ORDER BY rand()"; if ($res = Db::query($sql)) { $this->text($res[0]['content']); return true; } }
/** * Find feeds from db * * @return array feeds */ protected function getFeeds() { $feeds = array(); $result = $this->dbh->query("SELECT id, title\n FROM ttrss_feeds\n WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title"); while ($line = $this->dbh->fetch_assoc($result)) { $feeds[] = (object) $line; } return $feeds; }
private static function gc() { // dont run gc on every request if (mt_rand(1, 100) <= 10) { $sql = 'delete from sessions where date < ?'; $expire = time() - Config::get('session.expire', 86400); Db::query($sql, array(date(DATE_ISO8601, $expire))); } }
function sendNewsletter($titre, $contenu, $view) { $passage_ligne = "\r\n"; //=====Déclaration des messages au format HTML $patterns = array(); $replacements = array(); $patterns[0] = '/<h1/'; $replacements[0] = '<h1 style="width:770px;line-height:25px;font-size:18px;padding-left:5px;background-color:#f49f25;"'; $string = preg_replace($patterns, $replacements, stripslashes($contenu)); $string = str_replace('../albums', 'http://www.pcf-cdh.be/albums', $string); $string = str_replace("<a href=", "<a style=\"color:#f49f25;\" href=", $string); $message_html = "\n\t\t\t<div style=\"width:800px;min-height:600px;font-size:11px;font-family:Verdana;\">\n\t\t\t\t<div>\n\t\t\t\t\t<img src=\"http://www.pcf-cdh.be/images/header.jpg\" height=\"175px;\" />\n\t\t\t\t</div>\n\t\t\t\t<div style=\"margin-left:14px;width:770px;min-height:300px;\">\n\t\t\t\t" . $string . "\n\t\t\t\t</div>\n\t\t\t\t<div>\n\t\t\t\t\t<a style=\"text-decoration:none;\" href=\"http://www.pcf-cdh.be/deputy.php\"><img src=\"http://www.pcf-cdh.be/images/footer.jpg\" style=\"height:66px;border:none;\" /></a>\n\t\t\t\t\t<a style=\"text-decoration:none;\" href=\"http://www.pcf-cdh.be\"><img src=\"http://www.pcf-cdh.be/images/footer2.jpg\" style=\"height:50px;border:none;\" /></a>\n\t\t\t\t</div>\n\t\t\t\t<div style=\"width:800px;text-align:center;\">\n\t\t\t\t\t<a style=\"text-decoration:none;font-size:8px;\" href=\"http://www.pcf-cdh.be/desincription.php\">Se désabonner de la newsletters</a>\n\t\t\t\t</div>\n\t\t\t</div>"; //=====Création de la boundary $boundary = "-----=" . md5(rand()); $boundary_alt = "-----=" . md5(rand()); //=====Définition du sujet $sujet = "Newsletter du groupe cdH : " . $titre; //========= //=====Création du header de l'e-mail $header = "From: " . MAIL . "" . $passage_ligne; $header .= "Reply-to: " . MAIL . "" . $passage_ligne; $header .= "MIME-Version: 1.0" . $passage_ligne; $header .= "Content-Type: multipart/mixed;" . $passage_ligne . " boundary=\"{$boundary}\"" . $passage_ligne; //========== //=====Création du message $message = $passage_ligne . "--" . $boundary . $passage_ligne; $message .= "Content-Type: multipart/alternative;" . $passage_ligne . " boundary=\"{$boundary_alt}\"" . $passage_ligne; $message .= $passage_ligne . "--" . $boundary_alt . $passage_ligne; //=====Ajout du message au format HTML $message .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $passage_ligne; $message .= "Content-Transfer-Encoding: 8bit" . $passage_ligne; $message .= $passage_ligne . $message_html . $passage_ligne; //=====On ferme la boundary alternative $message .= $passage_ligne . "--" . $boundary_alt . "--" . $passage_ligne; $message .= $passage_ligne . "--" . $boundary . $passage_ligne; //=====Envoi de l'e-mail if ($view == true) { $sqlQuery = "SELECT email_txt FROM cdh_newsletter"; $getEntries = Db::query($sqlQuery); if (Db::num_rows($getEntries) > 0) { $entry = Db::fetch_assoc($getEntries); while ($entry) { foreach ($entry as $column => $value) { $value = stripslashes(htmlentities($value, ENT_QUOTES, "iso-8859-1")); mail($value, $sujet, $message, $header); } $entry = Db::fetch_assoc($getEntries); } } header("Location: http://www.pcf-cdh.be/admin/index.php?module=newsletter&categorie=5&sscategorie=14&send=true"); } else { mail('', $sujet, $message, $header); mail('', $sujet, $message, $header); mail('', $sujet, $message, $header); header("Location: http://www.pcf-cdh.be/admin/index.php?module=newsletter&categorie=5&sscategorie=14&send=true"); } }