2010年5月12日 星期三

Create General Object From DLL.

// the GUI is a GUI.DLL

// GUI.h


typedef IuGUI* (*LPFN_CREATEGUI)(void);

GUI_API IuGUI* CreateObject(void);
GUI_API IuGUI* CreateObject(void)
{
    return new CuGUI;
}

// CuGUI

class CuGUI :
    public IuGUI
{
public:
    CuGUI(void);
    ~CuGUI(void);

     virtual ULONG Release() 
     { 
        delete this;
        return 0;
     }

    virtual void OnDraw(HDC hDC);
};

// CGUILoadTest

void CGUILoadTest::testDllCreateObject(void)
{

    LPFN_CREATEGUI lpfnCreateGUI = NULL;

    CuDllManager dllGUI;
    BOOL bResult = dllGUI.LoadLibrary(TEXT("GUI.dll"));
    CPPUNIT_ASSERT( bResult != NULL );

    lpfnCreateGUI = (LPFN_CREATEGUI)dllGUI.GetProcAddress(("CreateObject"));
    CPPUNIT_ASSERT( lpfnCreateGUI != NULL );

    IuGUI *pIuGUI = NULL;

    if( lpfnCreateGUI != NULL )
        pIuGUI = lpfnCreateGUI();

    CPPUNIT_ASSERT( pIuGUI != NULL );

    if( pIuGUI != NULL )
        pIuGUI->Release();

}

2010年5月2日 星期日

filedrive - file upload download

class filedrive extends controller{

    function filedrive()
    {
        parent::controller();
        $this->load->model('filedrive_model','FileDrive',true);
        $this->load->library("cudownload");
        $this->load->library("cuupload");
        $this->culogin->onlogin();
    }

    function index($id="")
    {
        $data["downloadlist"] = "";
        if (empty($id))
                $query = $this->FileDrive->file_query();
        else
                $query = $this->FileDrive->tags_like($id);

        foreach($query->result() as $row){
                $filelist["row"] = $row;
                $data["downloadlist"] .= $this->load->view("downloadlist",$filelist,true);
        }
        $dnTable = $this->load->view("downloadtable",$data,true);
        $viewData["body"] = $dnTable;
        $this->_MainFrame($viewData);
    }

    function upload_form(){
        $tags = $this->FileDrive->get_tags();
        $upForm = array("error"=>"");
        $upForm["active_url"] = "filedrive/upload";
        $upLoadform = $this->cuciload->view("upload_form",$upForm,true);
        $tags = $this->cuciload->view("tags",array("tags"=>$tags,),true);
        $backpage = $this->cuciload->view("backpage",array("goback" => "filedrive"),true);
        $viewData["body"] = $backpage.$upLoadform.$tags;
        $this->_MainFrame($viewData);
    }

    function update_form($id){
        $data["row"] = $this->FileDrive->select_file($id);
        $viewData["body"] = $this->load->view("update_form",$data,true).$this->file_tags();
        $this->_MainFrame($viewData);
    }

    function delete_form($id){
        $data["row"] = $this->FileDrive->select_file($id);
        $viewData["body"] = $this->load->view("delete_form",$data,true);
        $this->_MainFrame($viewData);
    }
    
    function file_tags(){
        $tags = $this->FileDrive->get_tags();
        return $this->cuciload->view("tags",array("tags"=>$tags,),true);
    }

    function update($id){
        $this->FileDrive->update($id);
        redirect("filedrive","location");
    }

    function delete($id){
        $row = $this->FileDrive->select_file($id);
        $this->FileDrive->delete_file($id);
        unlink("./uploads/".$row->file_name.$row->file_ext);
        redirect("filedrive","location");
    }


    function IsUpload($result){
        $data = $this->upload->data();
        $data["true_name"] = $result["true_name"];
        $data["file_date"] = date("Y-m-d");
        $data["file_time"] = date("H:i:s");
        $data["file_tag"] = $this->FileDrive->write_sql($data);
        $data["is_img"]= lang("NO")."</li>";
        if($data["is_image"])
        {
            $data["is_img"] = $this->load->view("is_image",$data,true);
        }

        return $data;
    }

    function Upload()
    {
        if ( empty($_FILES["userfile"]["name"]) )
                redirect("filedrive/upload_form", "location");
        $result = $this->FileDrive->filename();

        $this->cuupload->InitUploadLib_($result["file_name"]);

        if ( ! $this->upload->do_upload())
        {
            $data["body"] = $this->upload->display_errors()."<br>".anchor("filedrive","return file upload!");
        }
        else
        {
            $susess_data = $this->IsUpload($result);
            redirect("filedrive","location");
        }
        $this->_MainFrame($data);
    }

    function _MainFrame($frame)
    {
        $data = $this->_Tag_List();
        $frame["leftmenu"] = $this->load->view("leftmenu",$data,true);
        $frame["submenu"] = $this->load->view("submenu","",true);
        $this->csmainframe->view($frame);
    }

    function _Tag_List(){
        $tags = array();
        $query =$this->FileDrive->get_tags();

        foreach($query->result() as $row){
                $number = $this->FileDrive->count_tags_like($row->id);
                $tags[] = anchor("filedrive/index/".$row->id, $row->tags . " ( ".$number ." ) ");
        }

        $query_all = $this->FileDrive->tags_like("");
        $data["all_num"] = $query_all->num_rows();

        $notags_num = $this->FileDrive->tags_like("null");
        $data["notags_num"] = $notags_num->num_rows();
        $data["tag"] = $tags;
        return $data;
    }

    function download($id){
        $result = $this->FileDrive->download($id);
        $this->cudownload->DownLoadEx($result, "./uploads/");
    }

}


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);
    }
}