2010年4月22日 星期四

login extends controller

class login extends controller{

    function login()
    {
        parent::controller();
    }

    function index()
    {
        $this->load->view("login");
    }

    function chklogin()
    {
        $this->culogin->login($_POST["account"],$_POST["password"]);
        $this->culogin->islogin();
    }

    function logout(){
        $this->session->unset_userdata("login");
        redirect("main","location");
    }
}

2010年4月21日 星期三

CuLogin -- Login base on CodeIgniter Library

class CuLogin {

    function CuLogin()
    {
        $this->Login_Information();
    }

    function Login_Information(){
        $this->login_account = "useric";
        $this->login_password = "password";
    }

    function chk_login($account,$password){
        if (($account == $this->login_account) && ($password == $this->login_password))
            return true;
        return false;
    }

    function login($account = "",$password = ""){
        $CI = &get_instance();
        $CI->session->set_userdata("login",$this->chk_login($account,$password));
    }

    function islogin(){
        $CI = &get_instance();
        if ($CI->session->userdata("login"))
            redirect("bulletin","location");
        redirect("login","location");
    }

    function onlogin(){
        $CI = &get_instance();
        if (!$CI->session->userdata("login"))
            redirect("main","location");
    }


}



2010年4月16日 星期五

weblink -- view

# delete_form.php
<a href="javascript:history.go(-1)"><?=lang("BACK")?></a> <?=anchor("weblink/delete_link/".$row->id,lang("DELETE"))?>
<table>
    <tr>
        <td><?=lang("LINK").lang("DESCRIPTION")?></td>
        <td><?=$row->link_des?></td>
    </tr>
    <tr>
        <td><?=lang("LINK").lang("WEB")?></td>
        <td>http://<?=$row->weblink?></td>
    </tr>
</table>

# edit_form.php
<?=form_open("weblink/{$action}")?>
<table>
    <tr>
        <td><?=lang("LINK").lang("DESCRIPTION")?></td>
        <td><input type="text" name="link_des" size="40" maxlength="64" value="<?=$row->link_des?>" /></td>
    </tr>
    <tr>
        <td><?=lang("LINK").lang("WEB")?></td>
        <td>http://<input type="text" name="weblink" size="40" maxlength="256" value="<?=$row->weblink?>" /></td>
    </tr>
    <tr>
        <td colspan="2" align="center"><input type="submit" value="<?=lang("SUBMIT")?>"></td>
    </tr>
</table>
</form>


# showlink.php

<table border="1">
    <tr>
        <td width="150"><?=lang("LINK").lang("DESCRIPTION")?></td>
        <td width="250"><?=lang("LINK").lang("WEB")?></td>
        <td width="50"><?=lang("EDIT")?></td>
    </tr>
    <?php foreach($query->result() as $row):?>
    <tr>
        <td><?=anchor_popup("http://".$row->weblink,$row->link_des,$atts)?></td>
        <td>http://<?=$row->weblink?></td>
        <td><?=anchor("weblink/edit_form/".$row->id,lang("EDIT"))?> <?=anchor("weblink/delete_form/".$row->id,lang("DELETE"))?></td>
    </tr>
    <?php endforeach;?>
</table>





# submenu.php

<table border="0">
    <tr>
        <td><?=anchor("weblink",lang("VIEW").lang("LINK"))?></td>
        <td><?=anchor("weblink/insert_link_form",lang("INSERT").lang("LINK"))?></td>
    </tr>
</table>

2010年4月15日 星期四

weblink_sql -- model

class weblink_sql extends model{

    function weblink_sql()
    {
        parent::model();
        $database_table = $this->config->item("database_table_name");
        $this->table_name = $database_table."weblink";
    }

    function load_post()
    {
        return array(
            "link_des" => $_POST["link_des"],
            "weblink" => $_POST["weblink"]
        );
    }

    function select($id = ""){
        if($id != "")
            return $this->db->get_where($this->table_name,array("id"=>$id));
        $this->db->order_by("id","desc");
        return $this->db->get($this->table_name);

    }

    function insert()
    {
        $this->db->insert($this->table_name,$this->load_post());
    }

    function update($id)
    {
        $this->db->where("id",$id);
        $this->db->update($this->table_name,$this->load_post());
    }

    function delete($id){
        $this->db->where("id",$id);
        $this->db->delete($this->table_name);
    }

}


2010年4月12日 星期一

weblink - modify web link

class weblink extends controller{

    function weblink()
    {
        parent::controller();
        $this->culogin->onlogin();
        $this->load->model("weblink_sql","WLINK",TRUE);
    }

    function index()
    {
        $data["atts"] = array("width" => "1024");
        $data["query"] = $this->WLINK->select();
        $frame["body"] = $this->load->view("showlink",$data,TRUE);
        $this->_MainFrame($frame);
    }

    function insert_link_form(){
        $data["row"] = array();
        $data["action"] = "insert_link";
        $frame["body"] = $this->load->view("edit_form",$data,TRUE);
        $this->_MainFrame($frame);
    }

    function edit_form($id){
        $query = $this->WLINK->select($id);
        $data["action"] = "update_link/".$id;
        $data["row"] = $query->row();
        $frame["body"] = $this->load->view("edit_form",$data,TRUE);
        $this->_MainFrame($frame);
    }

    function delete_form($id){
        $query = $this->WLINK->select($id);
        $data["row"] = $query->row();
        $frame["body"] = $this->load->view("delete_form",$data,TRUE);
        $this->_MainFrame($frame);
    }

    function insert_link(){
        $this->WLINK->insert();
        $this->_Redirect();
    }

    function update_link($id){
        $this->WLINK->update($id);
        $this->_Redirect();
    }

    function delete_link($id){
        $this->WLINK->delete($id);
        $this->_Redirect();
    }

    function _Redirect(){
        redirect("weblink","location");
    }

    function _MainFrame($frame = ""){
        $frame["submenu"] = $this->load->view("submenu","",TRUE);
        $frame["leftmenu"] ="";
        $this->cuciload->view("mainframework",$frame);
    }
}



2010年2月24日 星期三

CuGLES

class CuGLES : public CuEGL  
{

public:
    void Ortho(double left, double right, double bottom, double top, double Near, double Far);
    void Frustum( double fovy, double aspect, double zNear, double zFar );
    void Viewport(int x, int y, int width, int height);
#if 0
    void DrawArrays(const void *pvlist, const void *pnvlist, const void *ptclist,int stride, int numvertices);
    void DrawElements(const void *pvlist, const void *pnvlist, const void *ptclist,int stride, int numvertices,
        const void *pfaceindex, int numfaceindex);
#endif
    
    CuGLES();
    virtual ~CuGLES();

};


CuGLES::CuGLES()
{

}

CuGLES::~CuGLES()
{

}

#if 0
void CuGLES::DrawArrays(const void *pvlist, const void *pnvlist, const void *ptclist, int stride, int numvertices)
{

    glTexCoordPointer(2, GL_FIXED, stride, ptclist);
    // setup client states
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);    // setup arrays
    // first the vertices
    glVertexPointer(3, GL_FIXED , stride, pvlist);
    glEnableClientState(GL_VERTEX_ARRAY);


    // next the normals
//  glNormalPointer(GL_SHORT, stride, pnvlist);
    glNormalPointer(GL_FIXED , stride, pnvlist);
    glEnableClientState(GL_NORMAL_ARRAY);

    glDrawArrays(GL_TRIANGLES , 0, numvertices);


    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

}


void CuGLES::DrawElements(const void *pvlist, const void *pnvlist, const void *ptclist,int stride, int numvertices,
    const void *pfaceindex, int numfaceindex)
{

    glTexCoordPointer(2, GL_FIXED, stride, ptclist);
    // setup client states
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);


    // setup arrays
    // first the vertices
    glVertexPointer(3, GL_FIXED , stride, pvlist);
    glEnableClientState(GL_VERTEX_ARRAY);


    // next the normals
    glNormalPointer(GL_FIXED , stride, pnvlist);
    glEnableClientState(GL_NORMAL_ARRAY);

    glDrawElements(GL_TRIANGLES , numfaceindex, GL_UNSIGNED_BYTE , pfaceindex);


    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);

}
#endif

void CuGLES::Viewport(int x, int y, int width, int height)
{
    glViewport(x,y,width,height);
}

#define PI_     3.14159265358979323846
void CuGLES::Frustum(double fovy, double aspect, double zNear, double zFar)
{
    // 設定投影
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float right, left, top, bottom;
    top = zNear * tan(fovy * PI_ / 180.0 / 2 );
    bottom = -top;
    right = top * aspect;
    left = -right;

    glFrustumx(EGL_FixedFromFloat(left), EGL_FixedFromFloat(right),
        EGL_FixedFromFloat(bottom), EGL_FixedFromFloat(top),
        EGL_FixedFromFloat(zNear), EGL_FixedFromFloat(zFar) );

}

void CuGLES::Ortho(double left, double right, double bottom, double top, double Near, double Far)
{

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthox(
        EGL_FixedFromFloat(left),
        EGL_FixedFromFloat(right),
        EGL_FixedFromFloat(bottom), 
        EGL_FixedFromFloat(top), 
        EGL_FixedFromFloat(Near), 
        EGL_FixedFromFloat(Far));

}


完全不了解為什麼要繼承, 想不起來.

2010年2月23日 星期二

CuEGL

class CuEGL  
{

    int _red_size;
    int _green_size;
    int _bule_size;
    int _alpha_size;

public:

    // 
    void SwapBuffers();


    // 只要有呼叫 Init() 做初始化 就要呼叫 Exit() 
    // 在這裡 解構會自動呼叫
    void Exit();

    // 初始化 EGL
    // Return:  1 有問題初始化失敗   0: 一切正常
    bool Init(NativeWindowType hWnd);

    CuEGL();
    virtual ~CuEGL();

    EGLDisplay  _eglDisplay;
    EGLConfig   _eglConfig;
    EGLSurface  _eglSurface;
    EGLContext  _eglContext;



};

CuEGL::CuEGL()
{

    _eglDisplay = EGL_NO_DISPLAY;
    _eglConfig;
    _eglSurface = EGL_NO_SURFACE;
    _eglContext = EGL_NO_CONTEXT;

    _red_size = 5;
    _green_size = 6;
    _bule_size = 5;
    _alpha_size = 0;


}

CuEGL::~CuEGL()
{

    if( _eglDisplay != EGL_NO_DISPLAY )
        this->Exit();

}


bool CuEGL::Init(NativeWindowType hWnd)
{

    int buffer_size = _red_size + _green_size + _bule_size + _alpha_size;
    EGLint  attrs[] = {
        EGL_ALPHA_SIZE, _alpha_size,
        EGL_RED_SIZE, _red_size,
        EGL_GREEN_SIZE, _green_size,
        EGL_BLUE_SIZE, _bule_size,
        EGL_BUFFER_SIZE, buffer_size,
        EGL_DEPTH_SIZE, 16,
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_NONE};

    EGLint  numConfig;
    LONG        lRet = 1; 

    // NOTE: Theres a bunch of stuff we should be doing to release resources
    //       in the case of failure that we're not bothering with atm

    HDC hdc = GetWindowDC((HWND)hWnd);

    // Get the display device


    _eglDisplay = eglGetDisplay(hdc);

    Assert( _eglDisplay != EGL_NO_DISPLAY, L"CuEGL::Init:\n _eglDisplay == EGL_NO_DISPLAY");

    // Initialize the display
    if (!eglInitialize(_eglDisplay, NULL, NULL))
        {  
            Assert(0, L"CuEGL::Init:\n can't Initialize egl");
            return lRet;

        }

    // Obtain the first configuration with a depth buffer
    if (!eglChooseConfig(_eglDisplay, attrs, &_eglConfig, 1, &numConfig))
        { 
            Assert(0, L"CuEGL::Init:\n can't ChooseConfig");
            return lRet; 
        }

    // Create a surface for the main window
    _eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (NativeWindowType)hWnd, NULL);
    Assert( _eglSurface != EGL_NO_SURFACE, L"CuEGL::Init:\n _eglSurface == EGL_NO_SURFACE");

    // Create an OpenGL ES context
    _eglContext = eglCreateContext(_eglDisplay, _eglConfig, EGL_NO_CONTEXT, NULL);
    Assert( _eglContext != EGL_NO_CONTEXT, L"CuEGL::Init:\n _eglContext == EGL_NO_CONTEXT");


    // Make the context and surface current
    if (!eglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext))
        {  
            Assert(0, L"CuEGL::Init:\n can't MakeCurrent");
            return lRet; 
        }

    return 0;

}

void CuEGL::Exit()
{

    // Set the current context to nothing
    eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

    // Free any EGL contexts; should be called per context created
    eglDestroyContext(_eglDisplay, _eglContext);

    // Free any EGL surfaces; should be called per surface created
    eglDestroySurface(_eglDisplay, _eglSurface);

    // Terminate any EGL displays; should be called per display initialized
    eglTerminate(_eglDisplay); 

}

void CuEGL::SwapBuffers()
{

    eglSwapBuffers(_eglDisplay, _eglSurface);

}


好舊的碼了~ 如果有更新會在加上去