public function details() { // details combines seeing with editing $id = $_GET['id']; $columns = array('nom, prenom, nom_khmer, prenom_khmer, sex_id, active_id'); $neat_columns = array('Last Name', 'First Name', 'Last Name Khmer', 'First Name Khmer', 'Genre', 'Active', 'Update', 'Delete'); $form = array('action' => '?controller=teachers&action=update&id=' . $id, 'div' => "class='solitary_input'", 'div_button' => "class='submit_button1'", 'action_links' => array(1 => array('delete', '?controller=teachers&action=delete&id=')), 'method' => 'post', 'id' => 'top_form', 'elements' => array(1 => array('text' => 'nom'), 2 => array('text' => 'prenom'), 3 => array('text' => 'nom_khmer'), 4 => array('text' => 'prenom_khmer'), 5 => array('drop_down' => 'sex_id'), 6 => array('drop_down' => 'active_id'), 7 => array('submit' => 'update'))); $connection = new database(); $table = new simple_table_ops(); $sql = 'SELECT sex_id, sex FROM sexes'; $sex_result = $connection->query($sql); $sql2 = 'SELECT active_id, active FROM actives'; $active_result = $connection->query($sql2); $drop_down = array('sex_id' => array('sex' => $sex_result), 'active_id' => array('active' => $active_result)); $table->set_table_name('teachers'); $table->set_id_column('teacher_id'); $table->set_table_column_names($columns); $table->set_html_table_column_names($neat_columns); $table->set_values_form(); // set values found in database into form elements when building top_form $table->set_drop_down($drop_down); $table->set_form_array($form); $content = '<table>'; $content .= $table->details(); $content .= '</table>'; $output['content'] = $content; return $output; }
/** * Fetches hashed data from db and put into instance */ private function __save() { $class = $this->class; $database = new database($class::$database); if ($this->get_attributes()) { $columns = "(`{$class::$entity_id_column}`, `{$class::$key_column}`, `{$class::$value_column}`, `date_added`, `date_updated`)"; $placeholders = $values = $duplicate_keys = array(); foreach ($this->get_attributes() as $key => $value) { $placeholders[] = "(%d, %s, %s, NOW(), NOW())"; $values[] = $this->entity_id; $values[] = $key; $values[] = $value; $duplicate_keys[] = "`{$class::$value_column}` = VALUES(`{$class::$value_column}`)"; } $duplicate_keys[] = '`date_updated` = VALUES(`date_updated`)'; $database->query("INSERT INTO {$class::$table} {$columns} VALUES " . implode(', ', $placeholders) . " ON DUPLICATE KEY UPDATE " . implode(', ', $duplicate_keys), $values); } if ($unset_keys = array_diff($this->original_keys, array_keys($this->get_attributes()))) { // we unset something print_r(array($this->entity_id, $unset_keys)); database::enable_log(); $database->query("DELETE FROM {$class::$table} WHERE `{$class::$entity_id_column}` = %d AND `{$class::$key_column}` IN (%s)", array($this->entity_id, $unset_keys)); } return true; }
function create_usage_graph($from_date, $end_date) { //create an instance of class database here $con = new database(); //set up query string $query_members = "SELECT * FROM people_online WHERE people_online.member = 'y' \r\n\t\t\t\t\t AND people_online.log_date BETWEEN '{$from_date}' AND '{$end_date}'"; $query_visitors = "SELECT * FROM people_online WHERE people_online.member = 'n' \r\n\t\t\t\t\t AND people_online.log_date BETWEEN '{$from_date}' AND '{$end_date}'"; $rs_members = $con->query($query_members) or die($con->error()); $rs_visitors = $con->query($query_visitors) or die($con->error()); // COMMENT : must use OOP style ( use the $con object uve created ) not a procedural one...-mh $data_member = mysql_fetch_assoc($rs_members); // this is wrong... $data_visitors = mysql_fetch_assoc($rs_visitors); $data_member = $con->getnumrows($rs_members); $data_visitors = $con->getnumrows($rs_visitors); $data = $data_member + $data_visitors; if ($data == 0) { echo '<script>alert("Sorry, no usage results found.");window.close();</script>'; exit; } //echo 'm='.$data_member; //echo 'v='.$data_visitors; $arr_label = array("Members", "Visitors"); //$arr_data = array($data_member['MEMBERS'], $data_visitors['VISITORS']); $arr_data = array($data_member, $data_visitors); //start displaying the graph $from_date = explode('-', $from_date); $from_date = strdate($from_date[1], '', '') . ' ' . $from_date[2] . ',' . $from_date[0]; $end_date = explode('-', $end_date); $end_date = strdate($end_date[1], '', '') . ' ' . $end_date[2] . ',' . $end_date[0]; $graph = new graph_creator(320, 600, "People Online As of {$from_date} to {$end_date}", $arr_label, $arr_data, $center_value = 0.45); $graph->create_pie_graph(); }
public static function getFondos() { $db = new database(); $sql = "select subtitulos,img_cursos from cursos WHERE id<=4;"; $db->query($sql); return $db->cargaMatriz(); }
function upload($file_name, $file_type, $file_path, $file_title) { if (!empty($_FILES["fileUpload"]) && !empty($_POST["imgTitle"])) { $file_type = $_FILES['fileUpload']['type']; $file_title = $_POST["imgTitle"]; if ($file_type == "image/gif") { $file_path = $_FILES['fileUpload']['tmp_name']; $file_name = $_FILES['fileUpload']['name']; $new_path = "upload/img/" . $file_name; $file_error = $_FILES["fileUpload"]["error"]; if ($file_error == 0 && move_uploaded_file($file_path, $new_path)) { $sql = "INSERT INTO gif.images (`title_img`, `name_img`, `id_user`) VALUES ('{$file_title}','{$file_name}', '0');"; $upload = new database(); $upload->connect(); $query = $upload->query($sql); if (!empty($query)) { $success = "Upload file và ghi dư liệu thành công."; return $success; } else { $success = "Upload file thành công."; return $success; } } return $file_error; } else { $error = "File không đúng định dạng GIF"; return $error; } } }
function __construct(database $db, user $user) { $this->db =& $db; $this->user =& $user; $usertype = Kit::GetParam('usertype', _SESSION, _INT, 0); $this->groupid = Kit::GetParam('groupid', _REQUEST, _INT, 0); // Do we have a user group selected? if ($this->groupid != 0) { // If so then we will need to get some information about it $SQL = <<<END \t\t\tSELECT \tgroup.GroupID, \t\t\t\t\tgroup.Group \t\t\tFROM `group` \t\t\tWHERE groupID = %d END; $SQL = sprintf($SQL, $this->groupid); if (!($results = $db->query($SQL))) { trigger_error($db->error()); trigger_error(__("Can not get Group information."), E_USER_ERROR); } $aRow = $db->get_assoc_row($results); $this->group = $aRow['Group']; } // Include the group data classes include_once 'lib/data/usergroup.data.class.php'; }
function query($query) { $ex_echo = null; $mt = $this->getmicrotime(); $return = parent::query($query); $time = $this->getmicrotime() - $mt; $r = @parent::only_query('EXPLAIN ' . $query); //$r=mysql_query('EXPLAIN '.$query, $this->mysql_link); $explain = $this->result_to_data($r); $ex_echo .= '<table border="1">'; if (is_array($explain)) { foreach ($explain as $key => $value) { if ($key == 0) { $ex_echo .= '<tr>'; foreach ($value as $key2 => $value2) { $ex_echo .= '<td>' . $key2 . '</td>'; } $ex_echo .= '</tr>'; } $ex_echo .= '<tr>'; foreach ($value as $key2 => $value2) { $ex_echo .= '<td>' . $value2 . '</td>'; } $ex_echo .= '</tr>'; } } $ex_echo .= '</table>'; echo '<tr><td>' . $query . '</td><td>' . $ex_echo . '</td><td>' . $time . '</td></tr>'; return $return; }
public function gc($maxlifetime) { $db = new database(); $db->query("DELETE FROM tbl_session\n WHERE session_lastaccesstime < DATE_SUB(NOW(),\n INTERVAL " . $maxlifetime . " SECOND)"); $db->execute(); return true; }
public static function get($id = null) { $database = new database(); $q = ' SELECT ' . RUDE_DATABASE_TABLE_SPECIALTIES . '.*, ' . RUDE_DATABASE_TABLE_FACULTIES . '.' . RUDE_DATABASE_FIELD_NAME . ' AS faculty_name, ' . RUDE_DATABASE_TABLE_FACULTIES . '.' . RUDE_DATABASE_FIELD_SHORTNAME . ' AS faculty_shortname, ' . RUDE_DATABASE_TABLE_QUALIFICATIONS . '.' . RUDE_DATABASE_FIELD_NAME . ' AS qualification_name FROM ' . RUDE_DATABASE_TABLE_SPECIALTIES . ' LEFT JOIN ' . RUDE_DATABASE_TABLE_FACULTIES . ' ON ' . RUDE_DATABASE_TABLE_SPECIALTIES . '.' . RUDE_DATABASE_FIELD_FACULTY_ID . ' = ' . RUDE_DATABASE_TABLE_FACULTIES . '.' . RUDE_DATABASE_FIELD_ID . ' LEFT JOIN ' . RUDE_DATABASE_TABLE_QUALIFICATIONS . ' ON ' . RUDE_DATABASE_TABLE_SPECIALTIES . '.' . RUDE_DATABASE_FIELD_QUALIFICATION_ID . ' = ' . RUDE_DATABASE_TABLE_QUALIFICATIONS . '.' . RUDE_DATABASE_FIELD_ID . ' '; if ($id !== null) { $q .= PHP_EOL . 'WHERE ' . RUDE_DATABASE_TABLE_SPECIALTIES . '.' . RUDE_DATABASE_FIELD_ID . ' = ' . (int) $id; } $q .= ' GROUP BY ' . RUDE_DATABASE_TABLE_SPECIALTIES . '.' . RUDE_DATABASE_FIELD_ID; $database->query($q); if ($id !== null) { return $database->get_object(); } return $database->get_object_list(); }
public static function getProximosCursos() { $db = new database(); $sql = "SELECT * FROM cursos WHERE id=3"; $db->query($sql); return $db->cargaMatriz(); }
public function index() { $database = new database(); $query = $database->query(); date_default_timezone_set('Europe/London'); require_once "database.php"; $now = time(); $hour = $now - 60 * 60; $day = $now - 24 * 60 * 60; $month = $now - 30 * 24 * 60 * 60; // fetch clicks -hour $sql = "SELECT name, COUNT(*) as clicks FROM clicks WHERE time >=" . $hour . " GROUP BY name"; $clicksMinusHour = $query->fetch($sql); // fetch clicks -day $sql = "SELECT name, COUNT(*) as clicks FROM clicks WHERE time >=" . $day . " GROUP BY name"; $clicksMinusDay = $query->fetch($sql); // fetch clicks -month $sql = "SELECT name, COUNT(*) as clicks FROM clicks WHERE time >=" . $month . " GROUP BY name"; $clicksMinusMonth = $query->fetch($sql); if (count($clicksMinusHour) < 1) { $array = array('name' => 'null', 'clicks' => 'null'); $clicksMinusHour[] = $array; } if (count($clicksMinusDay) < 1) { $array = array('name' => 'null', 'clicks' => 'null'); $clicksMinusDay[] = $array; } if (count($clicksMinusMonth) < 1) { $array = array('name' => 'null', 'clicks' => 'null'); $clicksMinusMonth[] = $array; } $this->setVar('clicksMinusHour', $clicksMinusHour); $this->setVar('clicksMinusDay', $clicksMinusDay); $this->setVar('clicksMinusMonth', $clicksMinusMonth); }
/** * Layout Page Logic * @return * @param $db Object */ function __construct(database $db, user $user) { $this->db =& $db; $this->user =& $user; $this->sub_page = Kit::GetParam('sp', _GET, _WORD, 'view'); $this->layoutid = Kit::GetParam('layoutid', _REQUEST, _INT); // If we have modify selected then we need to get some info if ($this->layoutid != '') { // get the permissions Debug::LogEntry('audit', 'Loading permissions for layoutid ' . $this->layoutid); $this->auth = $user->LayoutAuth($this->layoutid, true); if (!$this->auth->edit) { trigger_error(__("You do not have permissions to edit this layout"), E_USER_ERROR); } $this->sub_page = "edit"; $sql = " SELECT layout, description, userid, retired, xml FROM layout "; $sql .= sprintf(" WHERE layoutID = %d ", $this->layoutid); if (!($results = $db->query($sql))) { trigger_error($db->error()); trigger_error(__("Cannot retrieve the Information relating to this layout. The layout may be corrupt."), E_USER_ERROR); } if ($db->num_rows($results) == 0) { $this->has_permissions = false; } while ($aRow = $db->get_row($results)) { $this->layout = Kit::ValidateParam($aRow[0], _STRING); $this->description = Kit::ValidateParam($aRow[1], _STRING); $this->retired = Kit::ValidateParam($aRow[3], _INT); $this->xml = $aRow[4]; } } }
function show($id, $text = "") { if (!session::get("tooltips")) { // display text from database if ($id) { $helpArray = fetch_to_array(database::query("SELECT * FROM system WHERE name='{$id}'"), ""); if ($helpArray) { $entry = current($helpArray); } $right = right::get_field($id); $user = right::get("rights"); $temp = $entry[text]; // admin informations if (right::superuser()) { $temp .= "<hr><table>"; $temp .= "<tr><td>fieldname</td><td>{$id}</td></tr>"; // fieldname $temp .= "<tr><td>edit</td><td>" . right::int2string($right[edit]) . "</td></tr>"; // edit rights $temp .= "<tr><td>view</td><td>" . right::int2string($right[view]) . "</td></tr>"; // view rights $temp .= "</table>"; $clickEvent = " onmousedown = edit("{$id}")"; } if ($text) { $temp .= "<hr>{$text}"; } return "onmouseover='return overlib("" . $temp . "");' onmouseout='return nd()' {$clickEvent}"; } // display special text } }
static function remove_metadata_field() { $migrated = modOpts::GetOption('metadata_migrated'); if ($migrated) { return; } try { $obj = utopia::GetInstance('uWidgets', false); $obj->BypassSecurity(true); $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uCustomWidget')); while ($row = $ds->fetch()) { $pk = $row['widget_id']; $meta = utopia::jsonTryDecode($row['__metadata']); foreach ($meta as $field => $val) { $obj->UpdateField($field, $val, $pk); } } $obj->BypassSecurity(false); $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uCustomWidget')); } catch (Exception $e) { } try { $obj = utopia::GetInstance('uWidgets', false); $obj->BypassSecurity(true); $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTextWidget')); while ($row = $ds->fetch()) { $pk = $row['widget_id']; $meta = utopia::jsonTryDecode($row['__metadata']); foreach ($meta as $field => $val) { $obj->UpdateField($field, $val, $pk); } } $obj->BypassSecurity(false); $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTextWidget')); } catch (Exception $e) { } try { $obj = utopia::GetInstance('uWidgets', false); $obj->BypassSecurity(true); $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTwitterWidget')); while ($row = $ds->fetch()) { $pk = $row['widget_id']; $meta = utopia::jsonTryDecode($row['__metadata']); foreach ($meta as $field => $val) { $obj->UpdateField($field, $val, $pk); } } $obj->BypassSecurity(false); $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTwitterWidget')); } catch (Exception $e) { } $ds = database::query('SHOW TABLES'); while ($t = $ds->fetch(PDO::FETCH_NUM)) { try { database::query('ALTER TABLE ' . $t[0] . ' DROP `__metadata`'); } catch (Exception $e) { } } modOpts::SetOption('metadata_migrated', true); }
public static function nuevoMensaje() { $db = new database(); $sql = 'INSERT INTO contacto VALUES (NULL, :nombre, :apellidos, :email, :asunto, :mensaje)'; $params = array(':nombre' => $_POST['nombre'], ':apellidos' => $_POST['apellidos'], ':email' => $_POST['email'], ':asunto' => $_POST['asunto'], ':mensaje' => $_POST['mensaje']); $db->query($sql, $params); return $db->affectedRows(); }
public static function getVideos($id) { $db = new database(); $sql = " SELECT r.ruta, r.nombre, r.id\n FROM recurso AS r, apartados AS a, temas AS t, cursos AS c\n WHERE r.id_apartados = a.id\n AND a.id_temas = t.id\n AND t.id_cursos = c.id\n AND c.id=:id"; $params = array(':id' => $id); $db->query($sql, $params); return $db->cargaMatriz(); }
public static function idCursosInscritos($idUser) { $db = new database(); $sql = "SELECT cu.id\n FROM usuarios AS u, cursan AS c, cursos AS cu\n WHERE u.id = c.id_usuario\n AND c.id_curso = cu.id\n AND u.id =:id"; $params = array(':id' => $idUser); $db->query($sql, $params); return $db->cargaFila(); }
public static function registro() { $db = new database(); $sql = 'INSERT INTO usuarios VALUES (NULL, :nombre, :apellidos, :fecha_nacimiento, :localidad, :email, :nick, :clave, :roll)'; $params = array(':nombre' => $_POST['nombre'], ':apellidos' => $_POST['apellidos'], ':fecha_nacimiento' => $_POST['fecha_nacimiento'], ':localidad' => $_POST['localidad'], ':email' => $_POST['email'], ':nick' => $_POST['nick'], ':clave' => $_POST['clave'], ':roll' => 1); $db->query($sql, $params); return $db->affectedRows(); }
public function getBillNo() { require_once "{$_SERVER['DOCUMENT_ROOT']}/classes/database.php"; $con = new database(); $reply = $con->query("select max(billNo) from invoices"); $reply = mysql_fetch_assoc($reply); return $reply['max(billNo)'] + 1; }
public function index() { $database = new database(); $query = $database->query(); $images = new image($query); $currentActive = $images->fetchCurrentActive(); $this->setVar('currentActive', $currentActive); }
public static function altaUsuario($id, $idUsuario) { $db = new database(); $sql = "INSERT INTO cursan(id_usuario, id_curso) VALUES (:id_usuario,:id);"; $params = array(':id' => $id, ':id_usuario' => $idUsuario); $db->query($sql, $params); return $db->cargaFila(); }
public function fetchByPicId($id) { $database = new database(); $result = $database->query("SELECT * FROM personal_pic where member_id = {$id}"); if ($result) { $userSet = $database->fetch($result); } return isset($userSet) ? $userSet : FALSE; }
public function Auth($email, $password) { $database = new database(); $result = $database->query("SELECT * FROM member WHERE email = '{$email}'and password = '******'"); if ($result) { $userSet = $database->fetch($result); } return isset($userSet) ? $userSet : FALSE; }
function update($query = '') { $db = new database(); if ($result = $db->query($query)) { return true; } else { return false; } }
function getval($name) { $res = database::query("SELECT text FROM system WHERE name='{$name}'"); if (mysql_num_rows($res)) { return mysql_result($res, 0, "text"); } else { return FALSE; } }
function getUsers() { global $db; $db = new database('localhost', 'root', null, 'cde_Central'); $result = $db->query('SELECT firstname FROM users WHERE id="1"'); while ($rows = mysql_fetch_array($result)) { echo $rows['firstname']; } }
public function index() { // ______________________________ // | School Year | Level | Action | // |---------------------|--------| // | | | [add] | // |------------------------------| // | 2015/2016 | | details| // ------------------------------ // /* CONFIGURES DROP DOWN Menus (2 in this case: programs and genre) */ $connection = new database(); $table = new simple_table_ops(); $content = "<div class='third_left'><p>Here are the class hours. If you change when a class starts/ends, change it here, but<p>DO NOT change the ORDER!"; $sql = 'SELECT time_id, time_class FROM time ORDER BY time_id ASC'; $levels_result = $connection->query($sql); $drop_down = array('time_id' => array('time_class' => $levels_result)); $table->set_drop_down($drop_down); /********************************************************************/ /* CONFIGURES Form structure */ $top_form = array('action' => '?controller=time&action=add', 'div' => "class='solitary_input'", 'method' => 'post', 'id' => 'top_form', 'elements' => array(1 => array('drop_down' => 'time_id'), 2 => array('submit' => 'add'))); $table->set_top_form($top_form); /********************************************************************/ /* CONFIGURES Main table contents (from MySQL) */ $columns = array('Time', 'Action'); $table->set_html_table_column_names($columns); $sql = "SELECT time.time_id, time_class\n FROM time\n ORDER BY time_id ASC\n "; $result = $connection->query($sql); if ($connection->get_row_num() == 0) { $content .= "<p>Currently, you have no time configured. Choose one and click [ADD]."; } else { $content .= "<p>Currently, you have " . $connection->get_row_num() . " time configured."; } $content .= "</div>"; $details_link = array(1 => array('details', '?controller=time&action=details&id=')); $table->set_details_link($details_link); $table->set_main_table($result); /********************************************************************/ $content .= "<div class='third_middle'><table>{$table->get_table()}</table></div>"; $output['content'] = $content; return $output; }
function validateCliente($email, $password) { global $c_host, $c_user, $c_pass, $c_db; $database = new database($c_host, $c_user, $c_pass); $database->setDb($c_db); $sql = "SELECT * FROM clientes WHERE email = '{$email}' and password = '******'"; $database->setquery($sql); $database->query(); $result = $database->listObjects(); return $result; }
private function log() { $a; if ($this->valid) { $a = 'success'; } else { $a = 'failed'; } $db = new database($GLOBALS['config']); $db->query("\n\t\t\t\tINSERT INTO `project` . `login_log`(\n\t\t\t\t`l_log_id`,\t\n\t\t\t\t`l_u_id`,\n\t\t\t\t`l_time`,\n\t\t\t\t`l_result`,\n\t\t\t\t`l_ip`\n\t\t\t\t)VALUES(\n\t\t\t\t\t'','" . $this->u_id . "', CURRENT_TIMESTAMP ,'" . $a . "' , '" . $_SERVER['REMOTE_ADDR'] . "'\n\t\t\t\t)\n\t\t\t\t"); }
public function get_user_vote() { $db = new database($GLOBALS['config']); $res = $db->query("SELECT * FROM `project` . `vote`\n\t\t\t\t\tWHERE \n\t\t\t\t `v_app_id` = '" . $this->app_id . "' AND `v_u_id` = '" . $this->u_id . "'\n\t\t\t\t\tORDER BY v_time DESC LIMIT 1\n\t\t\t\t\t"); $row = mysql_fetch_assoc($res); if ($row) { $this->u_vote = $row['v_score']; } else { $this->u_vote = 0; } $db->close(); }