Implementation of the Ajax real-time task prompt function page 1/2
Last Update:2018-12-08
Source: Internet
Author: User
Project Code For the structure, see the article [EXT/FCKeditor Integration -- Ajax UI -- a new way of thinking for web development, which should be converted into ideas 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 ();
}
}
}
?>