function onSubmit($vals) { //echo '<pre>'; //print_r ($vals); //exit; $duration = (strtotime($vals['ended']) - strtotime($vals['started'])) / 60 / 60; $res = db_execute('insert into timetracker_entry (id, project_id, task_description, started, duration) values (null, ?, ?, ?, ?)', $vals['project'], $vals['description'], $vals['started'], $duration); if (!$res) { return '<p>Unknown error: ' . db_error() . '</p>'; } $eid = db_lastid(); if (!is_array($vals['users'])) { $vals['users'] = preg_split('/, ?/', $vals['users']); } foreach ($vals['users'] as $user) { db_execute('insert into timetracker_user_entry (id, user_id, entry_id) values (null, ?, ?)', $user, $eid); } header('Location: ' . site_prefix() . '/index/timetracker-app/added.entry'); exit; }
function display($data) { echo '<fieldset><legend style="font-size:1.2em;">Choose the template of the project</legend>'; include $GLOBALS['Language']->getContent('project/template'); $rows = db_numrows($this->db_templates); if ($rows > 0) { //echo '<h3>From templates</h3><blockquote>'; $GLOBALS['HTML']->box1_top($GLOBALS['Language']->getText('register_template', 'choose')); print ' <TABLE width="100%">'; for ($i = 0; $i < $rows; $i++) { $this->_displayProject(db_result($this->db_templates, $i, 'group_id'), db_result($this->db_templates, $i, 'group_name'), db_result($this->db_templates, $i, 'register_time'), db_result($this->db_templates, $i, 'unix_group_name'), db_result($this->db_templates, $i, 'short_description')); } print '</TABLE>'; $GLOBALS['HTML']->box1_bottom(); //echo '</blockquote>'; } //{{{ Projects where current user is admin $result = db_query("SELECT groups.group_name AS group_name, " . "groups.group_id AS group_id, " . "groups.unix_group_name AS unix_group_name, " . "groups.register_time AS register_time, " . "groups.short_description AS short_description " . "FROM groups, user_group " . "WHERE groups.group_id = user_group.group_id " . "AND user_group.user_id = '" . user_getid() . "' " . "AND user_group.admin_flags = 'A' " . "AND groups.status='A' ORDER BY group_name"); echo db_error($result); $rows = db_numrows($result); if ($result && $rows) { include $GLOBALS['Language']->getContent('project/template_my'); echo '<br />'; $GLOBALS['HTML']->box1_top($GLOBALS['Language']->getText('register_template', 'choose_admin')); print '<TABLE width="100%">'; for ($i = 0; $i < $rows; $i++) { $this->_displayProject(db_result($result, $i, 'group_id'), db_result($result, $i, 'group_name'), db_result($result, $i, 'register_time'), db_result($result, $i, 'unix_group_name'), db_result($result, $i, 'short_description')); } print '</TABLE>'; $GLOBALS['HTML']->box1_bottom(); } //}}} echo '</fieldset>'; }
function getContent() { $html_my_bookmarks = ''; $result = db_query("SELECT bookmark_url, bookmark_title, bookmark_id from user_bookmarks where " . "user_id='" . user_getid() . "' ORDER BY bookmark_title"); $rows = db_numrows($result); if (!$result || $rows < 1) { $html_my_bookmarks .= $GLOBALS['Language']->getText('my_index', 'no_bookmark'); $html_my_bookmarks .= db_error(); } else { $purifier = Codendi_HTMLPurifier::instance(); $html_my_bookmarks .= '<table style="width:100%">'; for ($i = 0; $i < $rows; $i++) { $bookmark_url = $purifier->purify(db_result($result, $i, 'bookmark_url'), CODENDI_PURIFIER_CONVERT_HTML); if (my_has_URL_invalid_content($bookmark_url)) { $bookmark_url = ''; } $bookmark_title = $purifier->purify(db_result($result, $i, 'bookmark_title'), CODENDI_PURIFIER_CONVERT_HTML); $html_my_bookmarks .= '<TR class="' . util_get_alt_row_color($i) . '"><TD>'; $html_my_bookmarks .= '<A HREF="' . $bookmark_url . '">' . $bookmark_title . '</A> '; $html_my_bookmarks .= '<small><A HREF="/my/bookmark_edit.php?bookmark_id=' . db_result($result, $i, 'bookmark_id') . '">[' . $GLOBALS['Language']->getText('my_index', 'edit_link') . ']</A></SMALL></TD>'; $html_my_bookmarks .= '<td style="text-align:right"><A HREF="/my/bookmark_delete.php?bookmark_id=' . db_result($result, $i, 'bookmark_id') . '">'; $html_my_bookmarks .= '<IMG SRC="' . util_get_image_theme("ic/trash.png") . '" HEIGHT="16" WIDTH="16" BORDER="0" ALT="DELETE"></A></td></tr>'; } $html_my_bookmarks .= '</table>'; } $html_my_bookmarks .= '<div style="text-align:center; font-size:0.8em;"><a href="/my/bookmark_add.php">[' . $GLOBALS['Language']->getText('my_index', 'add_bookmark') . ']</a></div>'; return $html_my_bookmarks; }
function smarty_function_catalog_detail($params, &$smarty1) { global $smarty; global $db; global $cfg; $tbl_columns = $cfg['tbl_columns']; if (empty($params['template'])) { $template = "catalog_detail.html"; } if (empty($params['catalog_id'])) { print "function article_detail required catalog_id"; return; } extract($params); if (!isset($assign) && $smarty->is_cached($template, $catalog_id)) { $smarty->display($template, $catalog_id); return; } $sql = "select id,name,type,show_position,show_in_guide,url from {$tbl_columns} where id =" . intval($catalog_id) . " limit 1"; $catalog = $db->GetRow($sql); if (!$catalog) { db_error(); } if (isset($assign)) { $smarty->assign($assign, $catalog); } else { $smarty->assign("catalog", $catalog); $smarty->display($template, $catalog_id); $smarty->clear_assign("catalog"); } }
function ReportProjectAct($span, $group_id, $start = 0, $end = 0) { $this->Report(); if (!$start) { $start = mktime(0, 0, 0, date('m'), 1, date('Y')); } if (!$end) { $end = time(); } else { $end--; } if (!$group_id) { $this->setError('No group_id'); return false; } if (!$span || $span == REPORT_TYPE_MONTHLY) { $res = db_query("SELECT * FROM rep_group_act_monthly \n\t\t\tWHERE group_id='{$group_id}' AND month BETWEEN '{$start}' AND '{$end}' ORDER BY month"); } elseif ($span == REPORT_TYPE_WEEKLY) { $res = db_query("SELECT * FROM rep_group_act_weekly \n\t\t\tWHERE group_id='{$group_id}' AND week BETWEEN '{$start}' AND '{$end}' ORDER BY week"); } elseif ($span == REPORT_TYPE_DAILY) { $res = db_query("SELECT * FROM rep_group_act_daily \n\t\t\tWHERE group_id='{$group_id}' AND day BETWEEN '{$start}' AND '{$end}' ORDER BY day ASC"); } $this->start_date = $start; $this->end_date = $end; if (!$res || db_error()) { $this->setError('ReportProjectAct:: ' . db_error()); return false; } $this->setSpan($span); $this->setDates($res, 1); $this->res = $res; return true; }
function sitemap_build($action, $settings, $board) { global $config; // Possible values for $action: // - all (rebuild everything, initialization) // - news (news has been updated) // - boards (board list changed) // - post (a post has been made) // - thread (a thread has been made) if ($action != 'post-thread' && $action != 'post-delete') { return; } if ($settings['regen_time'] > 0) { if ($last_gen = @filemtime($settings['path'])) { if (time() - $last_gen < (int) $settings['regen_time']) { return; } // Too soon } } $boards = explode(' ', $settings['boards']); $threads = array(); foreach ($boards as $board) { $query = query(sprintf("SELECT `id` AS `thread_id`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error()); $threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC); } file_write($settings['path'], Element('themes/sitemap/sitemap.xml', array('settings' => $settings, 'config' => $config, 'threads' => $threads, 'boards' => $boards))); }
public function remove() { $q = $this->_getQuery(); $q->setDelete('modules'); $q->addWhere('mod_id = ' . (int) $this->mod_id); if (!$q->exec()) { $q->clear(); return db_error(); } else { if (!isset($this->mod_admin)) { $this->mod_admin = 0; } if ($this->mod_admin) { $this->_perms->deleteGroupItem($this->mod_directory, 'admin'); } else { $this->_perms->deleteGroupItem($this->mod_directory, 'non_admin'); } $this->_perms->deleteModuleItems($this->mod_directory); $this->_perms->deleteModule($this->mod_directory); if (isset($this->permissions_item_table) && $this->permissions_item_table) { $this->_perms->deleteModuleSection($this->permissions_item_table); } $this->_compactModuleUIOrder(); return null; } }
/** * add_canned_response() - Add a new canned response * * @param string Canned response title * @param string Canned response text */ function add_canned_response($title, $text) { global $feedback; if (!db_query("INSERT INTO canned_responses (response_title, response_text) VALUES('{$title}','{$text}')")) { $feedback .= db_error(); } }
function showDependentTasks() { $sql = "SELECT project_task.project_task_id,project_task.summary \n\t\t\tFROM project_task,project_dependencies \n\t\t\tWHERE project_task.project_task_id=project_dependencies.project_task_id \n\t\t\tAND project_dependencies.is_dependent_on_task_id='" . $this->getID() . "'"; $result = db_query($sql); $rows = db_numrows($result); if ($rows > 0) { echo ' <h3>' . _('Tasks That Depend on This Task') . '</h3> <p>'; $title_arr = array(); $title_arr[] = _('Task Id'); $title_arr[] = _('Task Summary'); echo $GLOBALS['HTML']->listTableTop($title_arr); for ($i = 0; $i < $rows; $i++) { echo ' <tr ' . $GLOBALS['HTML']->boxGetAltRowStyle($i) . '> <td>' . util_make_link('/pm/task.php?func=detailtask&project_task_id=' . db_result($result, $i, 'project_task_id') . '&group_id=' . $this->ProjectGroup->Group->getID() . '&group_project_id=' . $this->ProjectGroup->getID(), db_result($result, $i, 'project_task_id')) . '</td> <td>' . db_result($result, $i, 'summary') . '</td></tr>'; } echo $GLOBALS['HTML']->listTableBottom(); } else { echo ' <h3>' . _('No Tasks are Dependent on This Task') . '</h3>'; echo db_error(); } }
function ReportUserAdded($span, $start = 0, $end = 0) { $this->Report(); if (!$start) { $start = mktime(0, 0, 0, date('m'), 1, date('Y')); } if (!$end) { $end = time(); } else { $end--; } if (!$span || $span == REPORT_TYPE_MONTHLY) { $res = db_query("SELECT * FROM rep_users_added_monthly \n\t\t\tWHERE month BETWEEN '{$start}' AND '{$end}' ORDER BY month"); } elseif ($span == REPORT_TYPE_WEEKLY) { $res = db_query("SELECT * FROM rep_users_added_weekly \n\t\t\tWHERE week BETWEEN '{$start}' AND '{$end}' ORDER BY week"); } elseif ($span == REPORT_TYPE_DAILY) { $res = db_query("SELECT * FROM rep_users_added_daily \n\t\t\tWHERE day BETWEEN '{$start}' AND '{$end}' ORDER BY day ASC"); } $this->start_date = $start; $this->end_date = $end; if (!$res || db_error()) { $this->setError('ReportUserAdded:: ' . db_error()); return false; } $this->setSpan($span); $this->setDates($res, 0); $this->setData($res, 1); return true; }
function unban($id) { $query = prepare("DELETE FROM `bans` WHERE `id` = :id"); $query->bindValue(':id', $id); $query->execute() or error(db_error($query)); modLog("Removed ban #{$id}"); }
function options_submit() { global $calendar_name, $vars, $db; if (!is_admin()) { return tag('div', _('Permission denied')); } $query = "UPDATE " . SQL_PREFIX . "calendars SET\n"; if (isset($vars['hours_24'])) { $query .= "hours_24 = 1,\n"; } else { $query .= "hours_24 = 0,\n"; } if (isset($vars['start_monday'])) { $query .= "start_monday = 1,\n"; } else { $query .= "start_monday = 0,\n"; } if (isset($vars['translate'])) { $query .= "translate = 1,\n"; } else { $query .= "translate = 0,\n"; } $query .= "anon_permission = '{$vars['anon_permission']}',\n" . "calendar_title = '{$vars['calendar_title']}',\n" . "subject_max = '{$vars['subject_max']}'\n" . "WHERE calendar={$calendar_name};"; $result = $db->Execute($query) or db_error(_('Error reading options'), $query); return tag('div', _('Updated options')); }
function store() { $msg = $this->check(); if ($msg) { return get_class($this) . "::store-check failed"; } $q = new DBQuery(); if ($this->user_id) { // save the old password $perm_func = "updateLogin"; $q->addTable('users'); $q->addQuery('user_password'); $q->addWhere("user_id = {$this->user_id}"); $pwd = $q->loadResult(); if ($pwd != $this->user_password) { $this->user_password = md5($this->user_password); addHistory($this->_tbl, $this->user_id, 'password changed', 'Password changed from IP ' . $_SERVER['REMOTE_ADDR']); } else { $this->user_password = null; } $ret = db_updateObject('users', $this, 'user_id', false); } else { $perm_func = "addLogin"; $this->user_password = md5($this->user_password); $ret = db_insertObject('users', $this, 'user_id'); } if (!$ret) { return get_class($this) . "::store failed <br />" . db_error(); } else { $acl =& $GLOBALS['AppUI']->acl(); $acl->{$perm_func}($this->user_id, $this->user_username); return NULL; } }
public static function login($name, $email, $user) { if (!$name || !$user) { throw new Exception('Wypełnij wszystkie pola.'); } $user = new ChatUser(array('name' => $name, 'gravatar' => $user)); include_once "../db_connect.php"; include_once "../include/ust.php"; $Querys = 'SELECT * FROM ' . $pre . 'user WHERE user_id=' . $_SESSION['user_id'] . ''; $results = db_query($Querys) or die(db_error()); while ($rows = db_fetch($results)) { $ile_pkt = $rows['user_money']; if ($rows['user_vip'] >= time()) { $czy_vp = 1; } $user_chat = $rows['user_chat']; } if ($user_chat == 1) { throw new Exception('Masz zablokowany dostęp do czatu.'); } if ($czy_vp != 1) { if ($ile_pkt > $ust['chatp']) { $up = "UPDATE " . $pre . "user SET user_money=user_money-" . $ust['chatp'] . " WHERE user_id='" . db_real_escape_string($_SESSION['user_id']) . "'"; db_query($up); } else { throw new Exception('Masz zamało punktów by dołączyć do czatu.'); } } // The save method returns a MySQLi object if ($user->save()->affected_rows != 1) { throw new Exception('Nick jest zajęty.'); } $_SESSION['user'] = array('name' => $name, 'gravatar' => $user); return array('status' => 1, 'name' => $name, 'gravatar' => $user); }
function db_exec($sql) { global $db, $w2p_performance_dbtime, $w2p_performance_old_dbqueries; if (W2P_PERFORMANCE_DEBUG) { $startTime = array_sum(explode(' ', microtime())); } if (!is_object($db)) { dprint(__FILE__, __LINE__, 0, 'Database object does not exist.'); } $qid = $db->Execute($sql); dprint(__FILE__, __LINE__, 10, $sql); if ($msg = db_error()) { global $AppUI; dprint(__FILE__, __LINE__, 0, "Error executing: <pre>{$sql}</pre>"); // Useless statement, but it is being executed only on error, // and it stops infinite loop. $db->Execute($sql); if (!db_error()) { echo '<script language="JavaScript"> location.reload(); </script>'; } } if (!$qid && preg_match('/^\\<select\\>/i', $sql)) { dprint(__FILE__, __LINE__, 0, $sql); } if (W2P_PERFORMANCE_DEBUG) { ++$w2p_performance_old_dbqueries; $w2p_performance_dbtime += array_sum(explode(' ', microtime())) - $startTime; } return $qid; }
function remove_event($id) { global $db; $sql = 'DELETE FROM ' . SQL_PREFIX . "events WHERE id = '{$id}'"; $result = $db->Execute($sql) or db_error(_('Error while removing an event.'), $sql); return $db->Affected_Rows($result) > 0; }
/** * Retrieve all replies to a given thread */ private function fetchReplies($board, $thread_id) { $query = prepare("SELECT * FROM ``posts_{$board}`` WHERE `thread` = :id"); $query->bindValue(':id', $thread_id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); return $query->fetchAll(PDO::FETCH_ASSOC); }
public function build($settings, $board_name) { global $config, $board; openBoard($board_name); $recent_images = array(); $recent_posts = array(); $stats = array(); $query = query(sprintf("SELECT *, `id` AS `thread_id`,\n\t\t\t\t(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,\n\t\t\t\t(SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`,\n\t\t\t\t'%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']); $post['board_name'] = $board['name']; if ($post['embed'] && preg_match('/^https?:\\/\\/(\\w+\\.)?(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/)([a-zA-Z0-9\\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) { $post['youtube'] = $matches[2]; } if (isset($post['files'])) { $files = json_decode($post['files']); if ($files[0]->file == 'deleted') { continue; } $post['file'] = $config['uri_thumb'] . $files[0]->thumb; } $recent_posts[] = $post; } $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js'); foreach ($required_scripts as $i => $s) { if (!in_array($s, $config['additional_javascript'])) { $config['additional_javascript'][] = $s; } } file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir']))); }
public static function news($settings) { global $config; $query = query("SELECT * FROM `news` ORDER BY `time` DESC") or error(db_error()); $news = $query->fetchAll(PDO::FETCH_ASSOC); return Element('themes/categories/news.html', array('settings' => $settings, 'config' => $config, 'news' => $news)); }
function upgrade($old_version) { $q = new DBQuery(); switch ($old_version) { case '0.1': $q->alterTable('history'); $q->addField('history_table', 'varchar(15) NOT NULL default \'\''); $q->addField('history_action', 'varchar(10) NOT NULL default \'modify\''); $q->dropField('history_module'); $q->exec(); $q->clear(); case '0.2': $q->alterTable('history'); $q->addField('history_item', 'int(10) NOT NULL'); $q->exec(); $q->clear(); case '0.3': $q->alterTable('history'); $q->addIndex('index_history_item', '(history_item)'); $q->exec(); $q->clear(); $q->alterTable('history'); $q->addIndex('index_history_module', '(history_table, history_item)'); $q->exec(); $q->clear(); case '0.31': break; } return db_error(); }
function install() { $sql = "CREATE TABLE `unittest` ( " . "`unittest_id` int(11) NOT NULL auto_increment, " . "`unittest_name` varchar(250) NOT NULL default '', " . "`unittest_description` text NOT NULL, " . "`unittest_expectedresult` text NOT NULL, " . "`unittest_actualresult` text NOT NULL, " . "`unittest_passed` tinyint(4) default NULL, " . "`unittest_lasttested` datetime NOT NULL default '0000-00-00 00:00:00', " . "`unittest_task_id` int(11) NOT NULL default '0', " . "`unittest_project_id` int(11) NOT NULL default '0', " . "PRIMARY KEY (`unittest_id`) " . ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; "; db_exec($sql); db_error(); // execute the queryString return null; }
function delete($id) { $res = db_execute('delete from sitellite_msg_queue where id = ?', $id); if (!$res) { $this->error = db_error(); } return $res; }
function delete($id) { $res = db_execute('delete from sitellite_bookmark where user = ? and id = ?', session_username(), $id); if (!$res) { $this->error = db_error(); } return $res; }
public static function homepage($settings) { global $config; $settings['no_recent'] = (int) $settings['no_recent']; $query = query("SELECT * FROM `news` ORDER BY `time` DESC" . ($settings['no_recent'] ? ' LIMIT ' . $settings['no_recent'] : '')) or error(db_error()); $news = $query->fetchAll(PDO::FETCH_ASSOC); return Element('themes/basic/index.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'news' => $news)); }
function query_db($query) { $result = mysql_query($query); if ($result == FALSE) { db_error($query); } return $result; }
function delete() { $sql = "DELETE FROM unittest WHERE unittest_id = {$this->unittest_id}"; if (!db_exec($sql)) { return db_error(); } else { return NULL; } }
function api_mycss() { $sql = "SELECT `css` FROM `css` WHERE `uid` = '" . intval(uid()) . "' LIMIT 1"; $data = get_var($sql); if (db_errno() != 0) { apiController::send_error(LR_API_DB_ERROR, 'DATABASE ERROR ' . db_error()); } return apiController::send_result($data); }
function selPermWhere($table, $idfld) { global $AppUI; // get any companies denied from viewing $sql = "SELECT {$idfld}" . "\nFROM {$table}, permissions" . "\nWHERE permission_user = {$AppUI->user_id}" . "\n\tAND permission_grant_on = '{$table}'" . "\n\tAND permission_item = {$idfld}" . "\n\tAND permission_value = 0"; $deny = db_loadColumn($sql); echo db_error(); return "permission_user = {$AppUI->user_id}" . "\nAND permission_value <> 0" . "\nAND (" . "\n\t(permission_grant_on = 'all')" . "\n\tOR (permission_grant_on = '{$table}' and permission_item = -1)" . "\n\tOR (permission_grant_on = '{$table}' and permission_item = {$idfld})" . "\n\t)" . (count($deny) > 0 ? "\nAND {$idfld} NOT IN (" . implode(',', $deny) . ')' : ''); }
/** * Returns a resultset consisting of the month, day, total_users, pageviews, and sessions * from the stats_site tables * * @return a resultset of month, day, total_users, pageviews, sessions */ function getSiteStats() { $res = db_query("select byday.month,byday.day,byday.site_page_views as pageviews, ss.total_users, ss.sessions from stats_site_pages_by_day byday, stats_site ss where byday.month=ss.month and byday.day = ss.day order by byday.month asc, byday.day asc"); if (!$res) { $this->setError('Unable to get stats: ' . db_error()); return false; } return $res; }
/** * sysRemoveUser() - Remove a user * * @param int The user ID of the user to remove * @returns true on success/false on failure * */ function sysRemoveUser($user_id) { $res = db_query("UPDATE users SET unix_status='N' WHERE user_id={$user_id}"); if (!$res) { $this->setError('ERROR - Could Not Update User Unix Status: ' . db_error()); return false; } return true; }