Implementation of the ajax real-time task prompt function page 1/2

Source: Internet
Author: User

For the project code structure, see the article [EXT/FCKEditor Integration -- ajax ui -- a new way of thinking for web development, and the idea should be converted in a timely manner.
In
├ ── Taskofpig
│ ─ ── Controller
│ ─ ── Dao
│ ─ ── Js
│ Audio-music
│ ─ ── Tpl
│ ─ ── Tpl_c
│ ─ ── _ Log
The project code is as follows:
Db. SQL
SET FOREIGN_KEY_CHECKS = 0;
------------------------------
-- Table structure for task
------------------------------
Create table 'task '(
'Id' int (11) not null,
'Title' varchar (100) collate utf8_unicode_ci not null,
'Desc' text collate utf8_unicode_ci,
'Date' datetime not null,
'Created 'int (11) default NULL,
'Updated' int (11) default NULL,
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8 COLLATE = utf8_unicode_ci;
------------------------------
-- Table structure for task_seq
------------------------------
Create table 'Task _ seq '(
'Id' int (11) NOT NULL
) ENGINE = MyISAM default charset = utf8 COLLATE = utf8_unicode_ci;
/Ucren/taskofpig/index. php
<? Php
// Set the correct time zone
Date_default_timezone_set ("Asia/Shanghai ");
Define ('taskofpig _ dir', dirname (_ FILE __));
Require ('../phplibs/FLEA. php ');
// Configure $ GLOBALS [G_FLEA_VAR] ['class _ path ']
FLEA: import (TASKOFPIG_DIR); // Add the current directory to the Environment Variable
FLEA: loadAppInf ('appconfig. php'); // separate the configuration file for easy maintenance
FLEA: init ();
// Because FLEA_Db_TableDataGateway is not automatically loaded, it is necessary to explicitly Load
FLEA: loadClass ('flea _ Db_TableDataGateway ');
FLEA: runMVC ();
?>
/Ucren/taskofpig/appConfig. php
<? Php
// Configure $ GLOBALS [G_FLEA_VAR] ['app _ INF ']
Return array (
'Dispatcher '=> 'flea _ Dispatcher_Simple', // customize the scheduler FLEA_Dispatcher_Auth
'Controlleraccesssor '=> 'ctl ',
'Actionaccesssor '=> 'ac ',
'View' => 'flea _ View_Smarty ', // custom view
'Viewconfig' => array (
'Smartydir' => '../phplibs/Smarty ',
'Template _ dir' => './tpl ',
'Compile _ dir' => './tpl_c ',
'Left _ delimiter '=>' <% ',
'Right _ delimiter '=>' %> ',
'Destgging' => false
),
'Dbdsn '=> array (// custom database connection Parameters
'Driver '=> 'mysql ',
'Host' => 'localhost ',
'Login' => 'dbuser ',
'Password' => 'dbpass ',
'Database' => 'dbname ',
'Charset' => 'utf8'
),
'Logfiledir' => './log', // custom log
'Logfilename' => 'Task _ admin. Log'
);
?>
/Ucren/taskofpig/Dao/Table. php
<? Php
// Task schedule of the angry pig
Class Dao_TaskTable extends FLEA_Db_TableDataGateway
{
// Specify the data table name
Var $ tableName = 'task ';
// Specify the primary key field name
Var $ primaryKey = 'id ';
}
?>
/Ucren/taskofpig/Controller/Default. php
<? Php
FLEA: loadFile ('dao _ Table. php', true );
FLEA: loadFile ('flea _ Ajax_JSON.php ', true );
Class Controller_Default extends FLEA_Controller_Action
{
Var $ smarty;
Function Controller_Default ()
{
$ This-> smarty = $ this-> _ getView ();
$ This-> smarty-> assign ('sitename', 'Task schedule -- angry pig ');
$ This-> smarty-> assign ('opname', 'Task list'); // The value should be changed in the submodule by default.
}
Function actionIndex ()
{
$ This-> toModulePage (); // the task list page is displayed by default.
}
// Define a function to call FCKeditor
Function call_fck ($ input_name, $ input_value, $ w = '000000', $ h = '000000 ')
{
Include_once '../fckeditor. php ';
$ Fcked = new FCKeditor ($ input_name );
$ Fcked-> BasePath = '../fckeditor /';
$ Fcked-> ToolbarSet = 'default'; // toolbar settings
$ Fcked-> InstanceName = $ input_name;
$ Fcked-> Width = $ w;
$ Fcked-> Height = $ h;
$ Fcked-> Value = $ input_value;
$ Fck_area = $ fcked-> CreateHtml ();
$ This-> smarty-> assign ('fck _ region', $ fck_area );
Unset ($ fck_area );
Unset ($ fcked );
}
Function _showpage({tpl}'taskofpig.main.html ')
{
$ This-> smarty-> display ($ tpl );
}
Function actionAdd ()
{
$ This-> addTask ();
}
Function actionUpdate ()
{
$ This-> updateTask ();
}
Function deleteTask ($ id ){
$ Row = array ('id' => $ id );
$ ThisDao = & new Dao_TaskTable ();
$ Status = $ thisDao-> remove ($ row); // return a boolean value.
Unset ($ thisDao );
Return $ status;
}
Function listTask ()
{
$ ThisDao = & new Dao_TaskTable ();
$ Rows = $ thisDao-> findAll (); // two-dimensional array
Foreach ($ rows as & $ row) // note that reference should be passed here
{
$ Row ['desc'] = mb_substr ($ row ['desc'], 'utf-8 ');
}
$ This-> smarty-> assign ('rowset', $ rows );
$ This-> _ showPage ();
}
Function addTask ()
{
$ ThisDao = & new Dao_TaskTable ();
$ Row = array (
'Title' => $ _ REQUEST ['title'],
'Desc' => $ _ REQUEST ['desc'],
'Date' => $ _ REQUEST ['date']
);
$ CommitId = $ thisDao-> create ($ row );
Unset ($ thisDao );
Echo "successfully added a new task ";
Redirect (url ("Default"), 1 );
}
Function updateTask ()
{
$ ThisDao = & new Dao_TaskTable ();
$ Row = array (
'Id' => $ _ REQUEST ['id'],
'Title' => $ _ REQUEST ['title'],
'Desc' => $ _ REQUEST ['desc'],
'Date' => $ _ REQUEST ['date']
);
$ CommitId = $ thisDao-> update ($ row );
Unset ($ thisDao );
Echo "task updated successfully ";
Redirect (url ("Default"), 1 );
}
Function queryTask ($ id ){
$ ThisDao = & new Dao_TaskTable ();
$ Row = $ thisDao-> find (array ('id' => $ id ));
Unset ($ thisDao );
Return $ row;
}
Function queryTaskForDate ($ date = null)
{
$ ThisDao = & new Dao_TaskTable (); // '2017-08-17 07:42:29'
$ Row = $ thisDao-> find (array ('date' => date ('Y-m-d H: I: s ')));
Unset ($ thisDao );
If (! Empty ($ row ))
{
$ Jsonobj = new Services_JSON ();
Echo $ jsonobj-> encode ($ row );
}
Else
Die (date ('Y-m-d H: I: s '));
}
// Task Flow Control Method
Function toModulePage ()
{
If ($ _ REQUEST ['op'] = 'search '){
$ This-> queryTaskForDate ();
}
Else if ($ _ REQUEST ['op'] = 'add '){
$ This-> smarty-> assign ('opname', 'add new task ');
$ This-> smarty-> assign ('tasktime', date ('Y-m-d H: I: s '));
$ This-> call_fck ('desc ','');
$ This-> _showPage('taskofpig.add.html ');
}
Else if ($ _ REQUEST ['op'] = 'del '){
If (isset ($ _ REQUEST ['id']) & is_numeric ($ _ REQUEST ['id'])
$ Status = $ this-> deleteTask ($ _ REQUEST ['id']);
$ This-> listTask ();
}
Else if ($ _ REQUEST ['op'] = 'edit '){
If (isset ($ _ REQUEST ['id']) & is_numeric ($ _ REQUEST ['id']) {
$ Row = $ this-> queryTask ($ _ REQUEST ['id']);
}
$ This-> call_fck ('desc', $ row ['desc']);
Unset ($ row ['desc']);
$ This-> smarty-> assign ('rowset', $ row );
$ This-> smarty-> assign ('opname', 'modify task ');
$ This-> _showPage('taskofpig.edit.html ');
}
Else {// list
$ This-> listTask ();
}
}
}
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.