Selasa, 25 Desember 2012

php

Admin.php

<?php
session_start();
if(!$_SESSION['login_status']) echo '<script>alert("anda harus login"); location.href="login.php";</script>';
include 'user.php';
?>

Delete.php
<?php
include("koneksi.php");
$id=$_GET[id];

$query="delete from admin where id_user='$id'";
$exe=mysql_query($query);
if ($exe){
    echo "<script>alert('Data Berhasil Dihapus')
    location.replace('user.php')</script>";
}else{
    echo "<script>alert('Data Gagal Dihapus')
    location.replace('user.php')</script>";
}
?>

Edit_berita.php
<?php
session_start();
include"koneksi.php";

if(!$_SESSION['login_status'])
echo '<script>alert("anda harus login dulu");location.href="login.php";</script>';

if(isset($_POST['id_berita']) && isset($_POST['judul']) && isset($_POST['isi'])):
    $status = mysql_query("update berita set `judul`='$_POST[judul]',`isi`='$_POST[isi]' where id_berita=$_POST[id_berita]");
    if($status):echo '<script>location.href="list_berita.php";</script>';
    else : echo '<script>alert("gagal");location.href="list_berita.php";</script>';
    endif;
endif;  

if(isset($_GET['id_berita'])):

$result = mysql_query("select * from berita where id_berita=".$_GET['id_berita']);
$berita = mysql_fetch_object($result);

?>

<form method="post" action="edit_berita.php">
    <input type="hidden" name="id_berita" value="<?php echo $berita->id_berita;?>">
    <label>Judul</label><input type="text" name="judul" value="<?php echo $berita->judul;?>"><br>
    <label>Konten</label><textarea name="isi"><?php echo $berita->isi;?></textarea><br>
    <input type="submit" value="Simpan">
</form>

<?php endif; ?>

Hapus_berita.php

<?php
session_start();
include"koneksi.php";

if(isset($_GET['id_berita'])):
    $status = mysql_query("delete from berita where id_berita=".$_GET['id_berita']);
    if($status): echo '<script>location.href="list_berita.php";</script>';
    else : echo '<script>alert("gagal");location.href="list_berita.php";</script>';endif;
endif;

?>

index.php

<form action="simpan.php" method="post">
<table>
    <tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
    </tr>
    <tr>
        <td>Email</td>
        <td><input type="text" name="email"></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" value="Simpan"></td>
    </tr>
   
</table>
</form>

Koneksi.php
<?php
mysql_connect("localhost","root","") or die("gagal koneksi");
mysql_select_db("pwd");
?>

List_berita.php

<?php
session_start();
include "koneksi.php";
if(!$_SESSION['login_status'])
echo '<script>alert("anda harus login dulu");location.href="login.php";</script>';

if(isset($_POST['judul']) && isset($_POST['isi'])):
    $date = date('Y-m-d');
    $status = mysql_query("insert into berita(`judul`,`isi`,`tanggal`) values('$_POST[judul]','$_POST[isi]','".$date."')");
    if($status):echo '<script>location.href="list_berita.php";</script>';
    else : echo '<script>alert("gagal");location.href="list_berita.php";</script>';
    endif;
endif;   
?>

<?php if(isset($_GET['action']) && $_GET['action']=='tambah') :?>

<form method="post" action="list_berita.php">
    <label>Judul</label> <input type="text" name="judul"><br>
    <label>Konten</label> <textarea name="isi"></textarea><br>
    <input type="submit" value="Submit">
</form>

<?php else : ?>

<a href="?action=tambah">Tambah Berita</a>
<table>
    <tr>
        <td>No</td>
        <td>Judul</td>
        <td>Isi</td>
        <td>aksi</td>
    </tr>
    <?php $i=1; ?>
    <?php $result = mysql_query("select * from berita"); ?>
    <?php while($row = mysql_fetch_object($result)): ?>
        <tr>
            <td><?php echo $i++; ?></td>
            <td><?php echo $row->judul; ?></td>
            <td><?php echo $row->isi; ?></td>
            <td>
                <a href="hapus_berita.php?id_berita= <?php echo $row->id_berita ?>" onClick="return confirm('ciyus??')">Hapus</a>
                <a href="edit_berita.php?id_berita= <?php echo $row->id_berita ?>">Edit</a>
            </td>
        </tr>
    <?php endwhile; ?>
</table>
<?php endif; ?>

Login.php

<?php
session_start();
if($_SESSION['login_status']) echo '<script>alert("anda harus login terlebih dahulu"); location.href="admin.php";</script>';
?>
<form method="post" action="proseslogin.php">
Username : <input type="text" name="username"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="log in">
</form>

logout.php

<?php
session_start();
unset($_SESSION['login_status']);
echo '<script>alert("anda sudah logout"); location.href="login.php";</script>';
?>

proses_login.php

<?php
include 'koneksi.php';

session_start();
if(isset($_POST['username'])&& isset($_POST['password'])):
    $query_count = mysql_query("select count(*) as jumlah from admin where username='$_POST[username]' AND password=MD5('$_POST[password]')");
   
    $result_count = mysql_fetch_object($query_count);
   
    if($result_count->jumlah>0):
   
    $query = mysql_query("select * from admin where username='$_POST[username]' AND password=MD5('$_POST[password]')");
    $result = mysql_fetch_object($query);
   
    $_SESSION['id_user'] = $result->id_user;
    $_SESSION['login_status'] = true;
        echo '<script>alert("sukses tos sok"); location.href="admin.php";</script>';
    else:
        echo '<script>alert("Username dan password yang anda masukan salah"); location.href="login.php";</script>';
    endif;
else:
    echo '<script>alert("Username dan Password harus di isi"); location.href="login.php";</script>';
endif;
       
?>

Simpan.php

<?php
include "koneksi.php";
$input = $_POST[password];
$password = md5($input);
$sql="INSERT INTO admin (username, password, email)
VALUES
('$_POST[username]','$password','$_POST[email]')";
mysql_query($sql);
header( 'Location: user.php' );
?>

User.php

<form method="post" action="logout.php">
<input type="submit" value="Log out">
</form>
<?php
include "koneksi.php";
$sql=mysql_query("select *from admin");

echo "<table border='1'>
<tr>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Keterangan</th>
</tr>";

while($row = mysql_fetch_array($sql))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td><a href='delete.php?id=" . $row['id_user'] ."'>Delete</a></td>";
  echo "</tr>";
  }
echo "</table>";
?>
 <a href="index.php">Tambah lagi</a><br>





Sabtu, 08 Desember 2012

kalkulator sederhana c++

kalkulator ini dibuat dengan algoritma yang sederhana, meskipun belum sempurna seperti kalkulator biasanya yang kita gunakan, tapi ya lumayan lah untuk menghitung, dan juga buat menyelesaikan tugas kuliah..
ini tampilan screen shoot programnya :
nah seperti itu lah kalkulator sederhana dengan c++
dan disini anda bisa download programnya :
DISINI

source code bisa di download disini

Jumat, 13 April 2012

praktikum grafika 4 Membuat objek garis dengan DDA dan Bresenham

/* Praktikum 04
* Membuat objek garis dengan DDA dan Bresenham
*/

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
#include <math.h>

void display(void)
{
//set display-window background color to white
glClearColor(1.0,1.0,1.0,0.0);
//set projection parameters
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 300.0, 0.0, 300.0);
}
void setPixel(GLint xCoordinate, GLint yCoordinate)
{
glBegin(GL_POINTS);
glVertex2i(xCoordinate, yCoordinate);
glEnd();
glFlush();
}
//Procedure Bresenham line-drawing untuk |m| < 1.0
void lineBres(GLint x0, GLint y0, GLint xEnd, GLint yEnd)
{
GLint dx = (float)fabs((float) xEnd - x0);
GLint dy = (float)fabs((float) yEnd - y0);
GLint p = 2 * dy - dx;
GLint twoDy = 2 * dy;
GLint twoDyMinusDx = 2 * (dy - dx);
GLint x,y;
//determine which endpoint to use as start position
if (x0 > xEnd){
x = xEnd;
y = yEnd;
xEnd = x;
} else {
  x = x0;
  y = y0;
  }
  setPixel(x,y);
  while (x<xEnd){
  x++;
  if (p<0)
  p += twoDy;
  else {
  y++;
  p += twoDyMinusDx;
  }
  setPixel(x,y);
  }
  }
void drawMyLine1(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glPointSize(4.0);
GLint x0 = 10;
GLint y0 = 10;
GLint xEnd = 50;
GLint yEnd = 50;
lineBres(x0,y0,xEnd, yEnd);
}
void drawMyLine(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glPointSize(4.0);
GLint x0 = 50;
GLint y0 = 50;
GLint xEnd = 10;
GLint yEnd = 0;
lineBres(x0,y0,xEnd, yEnd);
}
int main(int argc, char** argv)
{
//initialize GLUT
glutInit(&argc, argv);
//initialize display mode
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
//set display-window width & height
glutInitWindowSize(400,400);
//set display-window upper-left position
glutInitWindowPosition(0,0);
//create display-window with a title
glutCreateWindow("Digital Differential Analiyzer Algorithm");
//initialize OpenGL
display();
//call graphics to be diplayes on the window
glutDisplayFunc(drawMyLine);
glutDisplayFunc(drawMyLine1);
//display everything and wait
glutMainLoop();
return 0;
}

Jumat, 06 April 2012

grafika komputer 3

/* Praktikum 03
* Membuat objek primitif : poligon
*/


#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>

void display(void)
{

GLubyte fly[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60,
0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20,
0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC,
0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0,
0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0,
0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30,
0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08,
0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08,
0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08};
GLubyte halftone[] = {
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55};




glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glRectf (25.0, 25.0, 125.0, 125.0);
glEnable (GL_POLYGON_STIPPLE);
glPolygonStipple (fly);
glRectf (125.0, 25.0, 225.0, 125.0);
glPolygonStipple (halftone);
glRectf (225.0, 25.0, 325.0, 125.0);
glColor3f (1.0, 1.0, 0.0);

glDisable (GL_POLYGON_STIPPLE);
glFlush ();
}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (350, 150);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMainLoop();
return 0;
}

Jumat, 30 Maret 2012

grafika komputer objek primitif garis

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>

#define drawOnLine(x1,y1,x2,y2) glBegin(GL_LINES);
glVertex2f((x1),(y1)); glVertex2f((x2),(y2));glEnd();

void init(void){
     glClearColor(0.0,0.0,0.0,0.0);
     glShadeModel(GL_FLAT);
     }
   
void display(void){
     int i;
     glClear (GL_COLOR_BUFFER_BIT);
     glColor3f(1.0,1.0,1.0,1.0);
     glEnable (GL_LINE_STIPPLE);
     glLineStipple(1, 0x0101);
     drawOneLine(50.0,125.0,150.0,125.0);
     glLineStipple(1, 0x00FF);
     drawOneLine(150.0,125.0,250.0,125.0);
     glLineStipple(1, 0x1C47);
     drawOneLine(250.0,125.0,350.0,125.0);
   
     glLineWidth(5.0);
     glLineStipple(1, 0x0101);
     drawOneLine(50.0,100.0,150.0,100.0);
     glLineStipple(1, 0x00FF);
     drawOneLine(150.0,100.0,250.0,100.0);
     glLineStipple(1, 0x1C47);
     drawOneLine(250.0,100.0,350.0,100.0);
   
     glLineWidth(1.0);
     glLineStipple(1, 0x1c47)
     glBegin(GL_LINE_STRIP);
     for(i=0;i<7;i++)
     glVertex2f(50.0+(GLfloat)i*50.0),75.0);
     glEnd();
     for(i=0;i<6;i++){
                      drawOneLine(50.0+((GLfloat)i*50.0),50.0,50.0 +((GLfloat)(i+1)*50.0),50.0);
                      }
     glLineStipple(5, 0x1C47);
     drawOneLine(50.0,25.0,350.0,25.0);
     glDisable(GL_LINE_STIPPLE);
     glFlush();
     }
   
     void reshape(int w, int h)
     {
          glViewport(0,0,(GLsizei)w,(GLsizei)h);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
          gluOrtho2D(0.0,(GLdouble)w,0.0,(Gldouble)h);
          }
         
     int main(int argc, char** argv){
         glutInit(&argc, argv);
         glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
         glutInitWindowSize(400,150);
         glutInitWindowsPosition(100,100);
         glutCreateWindow(argv[0]);
         init();
         glutDisplayFunc(display);
         glutReshapeFunc(reshape);
         glutMainLoop();
         return 0;
         }