function action_editzone() { global $smarty, $ref; $db = Database::singletone()->db(); $date = getdate(); $submit = Utils::p("submit", 0); $zid = Utils::pg("zid", 0); $mode = Utils::pg("mode", "add"); $smarty->assign("mode", $mode); $zone = array(); if (!$submit) { if ($mode == "add") { $zone['zone_name'] = ""; $zone['zone_type'] = "IN"; $zone['zone_serial'] = sprintf("%04d%02d%02d01", $date['year'], $date['mon'], $date['mday']); $zone['zone_admin'] = ""; $zone['zone_origin'] = ""; $zone['zone_refresh'] = 10800; $zone['zone_retry'] = 900; $zone['zone_expiry'] = 604800; $zone['zone_minimum'] = 86400; $zone['zone_ttl'] = 3600; } else { $q = $db->prepare("SELECT * FROM phpdns_zones WHERE zone_id = ?"); $r = $db->execute($q, $zid); $zone = $r->fetchRow(); } $smarty->assign("zone", $zone); } else { $zone['zone_name'] = Utils::p("zone_name"); $zone['zone_type'] = Utils::p("zone_type"); $zone['zone_serial'] = Utils::p("zone_serial"); $zone['zone_admin'] = Utils::p("zone_admin"); $zone['zone_origin'] = Utils::p("zone_origin"); $zone['zone_refresh'] = Utils::p("zone_refresh"); $zone['zone_retry'] = Utils::p("zone_retry"); $zone['zone_expiry'] = Utils::p("zone_expiry"); $zone['zone_minimum'] = Utils::p("zone_minimum"); $zone['zone_ttl'] = Utils::p("zone_ttl"); if ($mode == "add") { $q = $db->prepare("INSERT INTO phpdns_zones (zone_name, zone_type, zone_serial, zone_admin, zone_origin, zone_refresh, zone_retry, zone_expiry, zone_minimum, zone_ttl) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $db->execute($q, array_values($zone)); } else { if ($mode == "edit") { $q = $db->prepare("UPDATE phpdns_zones SET zone_name = ?, zone_type = ?, zone_serial = ?, zone_admin = ?, zone_origin = ?, zone_refresh = ?, zone_retry = ?, zone_expiry = ?, zone_minimum = ?, zone_ttl = ? WHERE zone_id = ?"); $z = array_values($zone); $z[] = $zid; $db->execute($q, $z); } } header("Location: " . $ref); } }
static function set($name, $val) { $db = Database::singletone()->db(); $q = $db->prepare("SELECT config_value FROM phpdns_config WHERE config_name = ?"); if (PEAR::isError($q)) { die($q->getMessage()); } $r = $db->execute($q, $name); if (PEAR::isError($r)) { return $def; } if ($r->numRows() == 0) { $q = $db->prepare("INSERT INTO Config (config_value, config_name) VALUES (?, ?)"); } else { $q = $db->prepare("UPDATE Config SET config_value = ?, config_name = ?"); } if (PEAR::isError($q)) { die($q->getMessage()); } $db->execute($q, array($val, $name)); }
static function setUser($uid, $name, $val) { $name = str_replace('_', '-', $name); $db = Database::singletone()->db(); if ($uid > 0) { $sth = $db->prepare("SELECT COUNT(*) FROM phph_user_settings WHERE user_id = :user_id AND setting_name = :setting_name"); $sth->bindParam(":user_id", $uid); $sth->bindParam(":setting_name", $name); $sth->execute(); $r = $sth->fetchColumn(0); $sth = null; if ($r > 0) { $sth = $db->prepare("UPDATE phph_user_settings SET setting_value = :setting_value WHERE setting_name = :setting_name AND user_id = :user_id"); } else { $sth = $db->prepare("INSERT INTO phph_user_settings (user_id. setting_name, setting_value) VALUES (:user_id, :setting_name, :setting_value)"); } $sth->bindParam(":user_id", $uid); $sth->bindParam(":setting_name", $name); $sth->bindParam(":setting_value", $val); $sth->execute(); } }
function setPerm($perm, $val) { $db = Database::singletone()->db(); $sth = $db->prepare('DELETE FROM phph_permissions WHERE permission = :permission AND user_id = :user_id'); $sth->bindParam(':permission', $perm); $sth->bindValue(':user_id', $this->uid()); $sth->execute(); $sth = null; if ($val) { $sth = $db->prepare('INSERT INTO phph_permissions (permission, user_id) VALUES (:permission, :user_id)'); $sth->bindParam(':permission', $perm); $sth->bindValue(':user_id', $this->uid()); $sth->execute(); $sth = null; } }
function getLogins() { $session = Session::singletone(); $db = Database::singletone()->db(); $sth = $db->prepare("SELECT user_login FROM phph_users ORDER BY user_login"); $sth->execute(); while ($row = $sth->fetch()) { $this->_response->appendChild($this->_dom->createElement('login', $row['user_login'])); } $this->success(); }
function removeMember($user) { $db = Database::singletone()->db(); if (!$this->isMember($user->uid())) { throw new Exception(_T("Użytkownik nie jest członkiem tej grupy.")); } $sth = $db->prepare('DELETE FROM phph_group_members WHERE user_id = :user_id AND group_id = :group_id'); $sth->bindValue(':user_id', $user->uid()); $sth->bindValue(':group_id', $this->gid()); $sth->execute(); $sth = null; $user->removeFromGroup($this); $this->updateDBData(); }
protected function _photos() { if (!$this->session()->checkPerm("photos-list")) { $this->denyAccess(); } $this->addScript("js/functions.js"); $this->addScript("js/behaviour.js"); $this->addScript("js/advajax.js"); $this->addScript("js/ajax.js"); $this->addScript("js/tabs.js"); $this->addScript("js/ac.js"); $this->addScript("js/admin/ctree.js"); $this->addScript("js/admin/photos.js"); $this->addCSS('css/admin/ctree.css'); $this->addCSS('css/admin/tabs.css'); $this->addCSS('css/admin/ac.css'); $this->addCSS('css/admin/preview.css'); $this->addCSS('css/admin/photos.css'); $db = Database::singletone()->db(); $this->setDefaultCount(16); $wq = $this->getPhotosWhereSql(); $sth = $db->query("SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id " . $wq); $photos = $sth->fetchColumn(0); $sth = null; $sth = $db->prepare('SELECT p.photo_id FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . $wq . ' ORDER BY photo_added DESC LIMIT :p, :c'); $sth->bindValue(":p", $this->startItem()); $sth->bindValue(":c", $this->count()); $sth->execute(); $rows = $sth->fetchAll(); $sth = null; $aphotos = array(); foreach ($rows as &$row) { $photo = new Photo($row['photo_id']); $ph = $photo->fullData(); $ph['file'] = $photo->get(100, 100); $aphotos[] = $ph; } $this->setTemplateVar('photos', $aphotos); $pages = $this->pager($photos); $this->setTemplateVar('pager', $pages); $stats = array(); $sth = $db->query('SELECT COUNT(*) FROM phph_photos p'); $stats['total']['total'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . $wq); $stats['selected']['total'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . "WHERE pm.moderation_mode = 'approve'"); $stats['total']['approved'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . $wq . " AND pm.moderation_mode = 'approve'"); $stats['selected']['approved'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . "WHERE pm.moderation_mode = 'reject'"); $stats['total']['rejected'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . $wq . " AND pm.moderation_mode = 'reject'"); $stats['selected']['rejected'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p WHERE p.moderation_id IS NULL'); $stats['total']['waiting'] = $sth->fetchColumn(0); $sth = null; $sth = $db->query('SELECT COUNT(*) FROM phph_photos p LEFT OUTER JOIN phph_photos_moderation pm ON p.moderation_id = pm.moderation_id ' . $wq . ' AND p.moderation_id IS NULL'); $stats['selected']['waiting'] = $sth->fetchColumn(0); $sth = null; //$sth = $db $this->setTemplateVar('stats', $stats); //$this->setTemplateVar("users", $rows); }
function moveCategory($dir) { $cid = 0; $db = Database::singletone()->db(); if ($dir == 1) { if ($this->dbdata('category_parent', 0) > 0) { $sth = $db->prepare("SELECT category_id, category_order FROM phph_categories WHERE category_parent = :parent AND category_order < :order ORDER BY category_order DESC LIMIT 0,1"); $sth->bindValue(':parent', $this->dbdata('category_parent')); } else { $sth = $db->prepare("SELECT category_id, category_order FROM phph_categories WHERE category_parent IS NULL AND category_order < :order ORDER BY category_order DESC LIMIT 0,1"); } } elseif ($dir == -1) { if ($this->dbdata('category_parent', 0) > 0) { $sth = $db->prepare("SELECT category_id, category_order FROM phph_categories WHERE category_parent = :parent AND category_order > :order ORDER BY category_order ASC LIMIT 0,1"); $sth->bindValue(':parent', $this->dbdata('category_parent')); } else { $sth = $db->prepare("SELECT category_id, category_order FROM phph_categories WHERE category_parent IS NULL AND category_order > :order ORDER BY category_order ASC LIMIT 0,1"); } } else { return 0; } $sth->bindValue(':order', $this->dbdata('category_order')); $sth->execute(); if ($row = $sth->fetch()) { $cid = $row['category_id']; $new_order = $row['category_order']; } $sth = null; if ($cid > 0) { $sth = $db->prepare('UPDATE phph_categories SET category_order = :order WHERE category_id = :cid'); $sth->bindValue(':order', $this->dbdata('category_order')); $sth->bindValue(':cid', $cid); $sth->execute(); $sth = null; $this->setDBData('category_order', $new_order); $this->save(); } return $cid; }
function get($w = 0, $h = 0, $opt = 0, $resize_up = true, $alt = "") { $db = Database::singletone()->db(); $file_name = ''; $file_width = 0; $file_height = 0; $fid = 0; $newopt = $opt & ~PHOTO_OPT_APPROVED; if ($opt & PHOTO_OPT_APPROVED && $this->dbdata('photo_approved') == 0) { $newopt = PHOTO_OPT_APPROVED; } if ($w == 0 || $h == 0 || $w >= $this->dbdata('photo_width') && $h >= $this->dbdata('photo_height') && !$resize_up) { $sth = $db->prepare('SELECT * FROM phph_files WHERE file_original = 1 AND photo_id = :pid AND file_options = :opt'); $sth->bindValue(':pid', $this->pid()); $sth->bindParam(':opt', $newopt); $sth->execute(); $row = $sth->fetch(); $file_name = $row['file_name']; $file_width = $row['file_width']; $file_height = $row['file_height']; $fid = $row['file_id']; $sth = null; } else { $f_w = $w / floatval($this->dbdata('photo_width')); $f_h = $h / floatval($this->dbdata('photo_height')); $f = min($f_w, $f_h); $nw = round(floatval($this->dbdata('photo_width')) * $f); $nh = round(floatval($this->dbdata('photo_height')) * $f); $file_width = $nw; $file_height = $nh; $sth = $db->prepare('SELECT * FROM phph_files WHERE photo_id = :pid AND file_width = :w AND file_height = :h AND file_options = :opt'); $sth->bindValue(':pid', $this->pid()); $sth->bindValue(':w', $nw); $sth->bindValue(':h', $nh); $sth->bindParam(':opt', $newopt); $sth->execute(); $row = $sth->fetch(); $sth = null; if ($row) { $file_name = $row['file_name']; $file_width = $row['file_width']; $file_height = $row['file_height']; $fid = $row['file_id']; } else { $name_a = $this->genName($nw, $nh, $this->dbdata('user_id')); $name = $name_a[2]; if (!file_exists($name_a[3])) { mkdir($name_a[3], 0755, true); } $sth = $db->prepare('SELECT file_name FROM phph_files WHERE file_original = 1 AND photo_id = :pid'); $sth->bindValue(':pid', $this->pid()); $sth->execute(); $row = $sth->fetch(); $orig_file_name = $row['file_name']; $sth = null; $original = @imagecreatefromjpeg(dirname(__FILE__) . "/../photos/" . $orig_file_name); $sized = imagecreatetruecolor($nw, $nh); imagecopyresampled($sized, $original, 0, 0, 0, 0, $nw, $nh, $this->dbdata('photo_width'), $this->dbdata('photo_height')); //imagefilter($sized, IMG_FILTER_GRAYSCALE); imagejpeg($sized, dirname(__FILE__) . "/../photos/" . $name, 100); $sth = $db->prepare('INSERT INTO phph_files ' . '(photo_id, file_original, file_keep, file_width, file_height, file_created, file_accessed, file_name, file_options) VALUES ' . '(:pid, 0, 0, :w, :h, :created, :accessed, :name, :opt)'); $sth->bindValue(':pid', $this->pid()); $sth->bindParam(':opt', $newopt); $sth->bindValue(':w', $nw); $sth->bindValue(':h', $nh); $sth->bindValue(':name', $name); $sth->bindValue(':created', time()); $sth->bindValue(':accessed', time()); $sth->execute(); $fid = $db->lastInsertId(); $sth = null; $file_name = $name; $file_width = $nw; $file_height = $nh; } } $sth = $db->prepare('UPDATE phph_files SET file_accessed = :accessed WHERE file_id = :fid'); $sth->bindValue(':accessed', time()); $sth->bindValue(':fid', $fid); $sth->execute(); $ret[0] = Utils::fullURL('photos/' . $file_name); $ret[1] = $file_width; $ret[2] = $file_height; $ret[3] = "width=\"" . $file_width . "\""; $ret[4] = "height=\"" . $file_height . "\""; $ret[5] = $ret[3] . " " . $ret[4]; $ret[6] = dirname(__FILE__) . "/../photos/" . $file_name; $ret[7] = "<img src=\"" . $ret[0] . "\" " . $ret[5] . " alt=\" "; if (empty($alt)) { $ret[7] .= htmlspecialchars($this->dbdata('photo_title')); } else { $ret[7] .= $alt; } $ret[7] .= "\" />"; self::clearCache(); return $ret; }
public function logout() { $db = Database::singletone()->db(); if ($this->uid() == ANON_USER) { return; } $sth = $db->prepare("DELETE FROM phph_sessions WHERE session_id = :sid"); $sth->bindParam(":sid", $this->_sid); $sth->execute(); $this->_user = null; $this->_method = SESSION_METHOD_GET; $this->_sid = ''; $this->_uid = ANON_USER; $this->newSession(); }
function output($time_start) { Utils::negotiateContentType(); if (ereg("MSIE", $_SERVER['HTTP_USER_AGENT'])) { $this->setTemplateVar("is_ie", 1); } if ($this->_session->logged()) { $this->setTemplateVar("logged_in", 1); $this->setTemplateVar("logged_user_login", $this->_session->getUser()->dbdata("user_login")); $this->setTemplateVar("logged_user_name", $this->_session->getUser()->dbdata("user_name")); } else { $this->setTemplateVar("logged_in", 0); } $this->setTemplateVar('page', $this->page()); $this->setTemplateVar('count', $this->count()); $this->setTemplateVar("datetime_format", $this->session()->getUserSetting("datetime_format", "%Y-%m-%d %H:%M:%S")); $this->setTemplateVar("time_format", $this->session()->getUserSetting("time_format", "%H:%M:%S")); $this->setTemplateVar("date_format", $this->session()->getUserSetting("date_format", "%Y-%m-%d")); $this->setTemplateVar('queries', Database::singletone()->db()->count()); foreach ($this->_template_vars as $key => $val) { $this->smarty()->assign($key, $val); } $this->smarty()->assign("time_generated", sprintf("%.3f", microtime(true) - $time_start)); if (isset($_SESSION['messages'])) { $this->smarty()->assign("messages", $_SESSION['messages']); $this->smarty()->assign("messages_count", count($_SESSION['messages'])); } else { $this->smarty()->assign("messages_count", 0); } $this->smarty()->assign("_scripts", $this->_scripts); $this->smarty()->assign("_links", $this->_links); self::$_time_start = $time_start; ob_start('ob_statistics'); $this->_smarty->display($this->_main_template); ob_flush(); $_SESSION['messages'] = array(); }