目标:为TeamToy的todo添加Due Date的功能。
public function update() {
$tid = intval(v('tid'));
if( $tid < 1 ) return ajax_box('错误的TODO ID');
$todo = z(v('todo'));
$link = z(v('link'));
$desp = z(v('desp'));
$due_date = z(v('due_date'));
//如果期限未设置,则设置默认期限为当日
if($due_date=="") $due_date = date("Y-m-d");
if( $todo == '' ) return ajax_box('TODO内容不能为空');
$sql = "UPDATE `todo` SET `name` = '" . s($todo) . "' , `link` = '" . s($link) . "' , `desp` = '" . s($desp) . "' , `due_date` = '" . $due_date . "' WHERE `id` = '" .intval($tid) . "' AND `uid` = '" . uid() . "' LIMIT 1 "; ... } public function save() {
$todo = z(v('todo'));
$link = z(v('link'));
$desp = z(v('desp'));
$due_date = z(v('due_date'));
$pid = intval(v('pid'));
//如果期限未设置,则设置默认期限为当日
if($due_date=="") $due_date = date("Y-m-d");
...
$sql = "INSERT INTO `todo` ( `name` , `link` , `desp` , `uid` , `creator_uid` , `pid` , `is_done` , `follow_uids` , `timeline` , `check_time`, `due_date` ) VALUES ( '" . s($todo) . "' , '" . s($link) . "', '" . s($desp) . "' , '" . $uid . "' , '" . uid() . "' , '" . intval($pid) . "' , '" . intval( $is_done ) . "' , '" . s( serialize( $follow_uids ) ) . "' , NOW() , NOW() , '" . $due_date . "' )";
...
}
<a href="javascript:$('todo_due_date').setStyle('display' ,'');void(0)">期限</a> <img src=\'#\'" /image/paperclip.gif" /> <a href="javascript:$('todo_link').setStyle('display' ,'');void(0)">链接</a>
<div id="todo_due_date" style="display:none;padding-top:5px"><input type="text" name="due_date" class="text" style="width:300px" /></div>
<div id="todo_due_date" style="<?php if( $tinfo['due_date'] == '' ){ echo 'display:none;'; } ?>padding-top:5px"><input type="text" name="due_date" class="text" style="width:300px" value="<?=$tinfo['due_date']?>" /></div>
<link rel="stylesheet" type="text/css" href="static/css/datepicker.css"> <script type="text/javascript" src=\'#\'" /script/datepicker.js" ></script>
<input type="text" id="due_date" name="due_date" class="text" style="width:200px" value="<?=$tinfo['due_date']?>" />
<img src=\'#\'" /image/transparent.gif" DatePicker('#due_date', { format: 'Y-m-d', inputOutputFormat: 'Y-m-d', positionOffset: { x: 0, y: 5 } }); "/>
<div style="padding-top:5px;">期限:<input type="text" id="due_date" name="due_date" class="text" style="width:80px" value="<?=date('Y-m-d')?>" />
<img src=\'#\'" /image/transparent.gif" DatePicker('#due_date', { format: 'Y-m-d', inputOutputFormat: 'Y-m-d', positionOffset: { x: 0, y: 5 } }); "/></div>
<label>[<?=$todo['due_date']?>]</label>
<label>[<?=date('m-d',strtotime($todo['due_date']))?>]</label>
<input type="button" class="button" value="添加"
<input type="submit" class="button" value="添加"
onsubmit="show_float_box('?m=todo&a=save&pid=<?=get_current_pid()?>&todo=' + encodeURIComponent( $('todo_box_side').value ));$('todo_box_side').value='';$('todo_side_link').value='';$('todo_side_link').setStyle('display' ,'none');return false;void(0)"
onsubmit="if($('todo_box_side').value != ''){show_float_box('?m=todo&a=save&pid=<?=get_current_pid()?>&todo=' + encodeURIComponent( $('todo_box_side').value ));$('todo_box_side').value='';$('todo_side_link').value='';$('todo_side_link').setStyle('display' ,'none');}return false;void(0)"
onclick="if($('todo_box_side').value != ''){send_form_pop('form_todo_side');$('todo_box_side').value='';}else{$('todo_box_side').value='这里不能为空哦!';$('todo_box_side').focus();}"
<form action="?m=todo&a=save&pid=<?=get_current_pid()?>" method="post" id="form_todo_side" onsubmit="if($('todo_box_side').value != ''){send_form_pop('form_todo_side');$('todo_box_side').value='';$('todo_side_link').value='';$('todo_side_link').setStyle('display' ,'none');}return false;void(0)">