4 by yu (http://nucleus.datoka.jp/)
\r
6 This program is free software; you can redistribute it and/or
\r
7 modify it under the terms of the GNU General Public License
\r
8 as published by the Free Software Foundation; either version 2
\r
9 of the License, or (at your option) any later version.
\r
10 (see nucleus/documentation/index.html#license for more info)
\r
15 <%TodoList(nodate)%> //date setting
\r
16 <%TodoList(normal,1)%> //date setting, memberid
\r
20 2008-12-02 Ver0.44: [Fix] "Add TODO" bug fix. (hilbert)
\r
21 [Chg] Improve quote_smart() function. (yu)
\r
22 2008-05-19 Ver0.43: [Fix] "Delete TODO" bug fix. (yu)
\r
23 2006-09-30 Ver0.42: [Fix] Security fix. (yu)
\r
24 2004-09-29 Ver0.41: [Fix] Check edit authority. (yu)
\r
25 2004-05-30 Ver0.4 : [New] Blog members can own each todo list. (yu)
\r
28 // plugin needs to work on Nucleus versions <=2.0 as well
\r
29 if (!function_exists('sql_table')) {
\r
30 function sql_table($name) {
\r
31 return 'nucleus_' . $name;
\r
35 class NP_TodoList extends NucleusPlugin {
\r
36 function getName() { return 'Todo List'; }
\r
37 function getAuthor() { return 'yu'; }
\r
38 function getURL() { return 'http://works.datoka.jp/index.php?itemid=231'; }
\r
39 function getVersion() { return '0.44'; }
\r
40 function getMinNucleusVersion() { return 200; }
\r
41 function getTableList() { return array( sql_table('plug_todolist') ); }
\r
42 function getEventList() { return array(); }
\r
43 function supportsFeature($what) {
\r
45 case 'SqlTablePrefix':
\r
52 function getDescription() {
\r
53 return 'Show Todo List. [USAGE] <%TodoList(mode,memberid)%> ex. <%TodoList%>, <%TodoList(nodate)%>, <%TodoList(normal,1)%>';
\r
57 function install(){
\r
58 sql_query ("CREATE TABLE IF NOT EXISTS ". sql_table('plug_todolist') ." (
\r
59 tid INT UNSIGNED NOT NULL AUTO_INCREMENT,
\r
60 title VARCHAR(255) NOT NULL DEFAULT '',
\r
61 rank INT UNSIGNED NOT NULL DEFAULT 0,
\r
62 cond INT UNSIGNED NOT NULL DEFAULT 0,
\r
63 regdate DATE NOT NULL DEFAULT '1999-01-01',
\r
64 enddate DATE NOT NULL DEFAULT '1999-01-01',
\r
65 memberid INT UNSIGNED NOT NULL DEFAULT 1,
\r
66 primary key (tid))");
\r
68 if(getNucleusVersion() < 220) {
\r
69 $this->createOption('canedit','Edit authority [self | team | self+admin]', 'text', 'self');
\r
72 $this->createOption('canedit','Edit authority [self | team | self+admin]', 'select', 'self', 'Self|self|Team|team|Self + Admin|self+admin');
\r
75 $this->createOption('dateFormat','Date format', 'text', 'm/d(D)');
\r
76 $this->createOption('flg_pluglink','Show plugin link.','yesno','yes');
\r
77 $this->createOption('flg_erase', 'Erase data on uninstall.', 'yesno', 'no');
\r
80 function unInstall() {
\r
81 if ($this->getOption(flg_erase) == 'yes') {
\r
82 sql_query ('DROP TABLE '. sql_table('plug_todolist') );
\r
87 // .../action.php?action=plugin&name=TodoList&type=verup&vernum=X.X
\r
88 // it need login to update
\r
89 function versionUpdate($oldver) {
\r
94 sql_query ("ALTER TABLE ". sql_table('plug_todolist'). " ADD (
\r
95 memberid INT UNSIGNED NOT NULL DEFAULT 1)");
\r
106 $this->rankname = array('*','**','***');
\r
107 $this->condname = array('notyet','working','finished','pending');
\r
108 $this->condstyle = array('background:#fff','background:#fd6','background:#add','background:#999;color:white','background:#f00;color:white');
\r
110 $query = "SHOW TABLES LIKE '". sql_table('plug_todolist') ."'";
\r
111 $table = sql_query($query);
\r
112 if (mysql_num_rows($table) > 0){
\r
113 $query = "SELECT * FROM ". sql_table('plug_todolist') ." ORDER BY cond, enddate";
\r
114 $res = sql_query($query);
\r
115 while ($data = mysql_fetch_object($res)) {
\r
116 $this->list[$data->memberid][] = $data; //set data by memberid
\r
121 function doSkinVar($skinType, $showmode='normal',$memid='') {
\r
124 if (!$memid) $memid = $memberid; //in member page
\r
125 if (!$memid) $memid = 1; //default
\r
127 $editmode = intRequestVar('todoedit'); //get or post
\r
128 $this->showTodoList($editmode, $showmode, $memid);
\r
131 function isLoggedIn() {
\r
133 return $member->isLoggedIn();
\r
136 function canEdit($memid) {
\r
137 global $blog, $member;
\r
139 if ($blog) $b =& $blog;
\r
140 else $b =& $manager->getBlog($CONF['DefaultBlog']);
\r
141 $bid = $b->getID();
\r
143 if (!$member->isLoggedIn()) return 0;
\r
145 switch ($this->getOption('canedit')) {
\r
147 return ($member->getID() == $memid);
\r
150 return ($member->teamRights($bid));
\r
153 return ($member->getID() == $memid || $member->blogAdminRights($bid));
\r
161 function showEntryForm($editmode, $showmode, $memid) {
\r
164 if (!$editmode) return;
\r
166 <form class="todolist" method="post" action="<?php echo $CONF['ActionURL'] ?>">
\r
167 <input type="hidden" name="action" value="plugin"/>
\r
168 <input type="hidden" name="name" value="TodoList" />
\r
169 <input type="hidden" name="type" value="add" />
\r
170 <input type="hidden" name="memid" value="<?php echo $memid ?>" />
\r
171 <select name="rank">
\r
173 for($i = count($this->rankname)-1; $i>=0; $i--){
\r
174 echo "<option value='$i'>{$this->rankname[$i]}</option>\n";
\r
178 <select name="cond">
\r
181 foreach($this->condname as $cname){
\r
182 echo "<option value='$i'>$cname</option>\n";
\r
188 if ($showmode != 'nodate') {
\r
190 <input class="formfield" type="text" name="enddate" value="<?php echo date('Y-m-d', mktime(0,0,0,date('m'),date('d')+1,date('Y'))) ?>" size="9" maxlength="10" />
\r
194 <input class="formfield" type="text" name="title" value="" size="20" maxlength="255" />
\r
195 <input class="formbutton" type="submit" value="Submit" />
\r
201 function showTodoList($editmode, $showmode, $memid) {
\r
202 global $CONF, $member;
\r
204 $img_path = $this->getAdminURL();
\r
206 $this->showEntryForm($editmode, $showmode, $memid);
\r
208 if (empty($this->list[$memid])) {
\r
209 echo "<p>No data found.</p>";
\r
213 foreach($this->list[$memid] as $l) {
\r
214 //if ($l->memberid != $memid) continue; // id check
\r
215 $byrank[ $l->rank ][] = $l;
\r
217 $sortlist = array();
\r
218 for($i=count($this->rankname); $i>0; $i--) {
\r
219 $sortlist = array_merge($sortlist, (array)$byrank[$i-1]);
\r
222 echo "<ul class='todolist'>\n";
\r
224 foreach($sortlist as $l) {
\r
226 $title = htmlspecialchars($l->title, ENT_QUOTES);
\r
227 $enddate = $l->enddate;
\r
228 $rank = $this->rankname[$l->rank];
\r
229 $cond = $this->condname[$l->cond];
\r
233 <form class="todolist" method="post" action="<?php echo $CONF['ActionURL'] ?>">
\r
234 <input type="hidden" name="action" value="plugin"/>
\r
235 <input type="hidden" name="name" value="TodoList" />
\r
236 <input type="hidden" name="type" value="update" />
\r
237 <input type="hidden" name="tid" value="<?php echo $tid ?>" />
\r
238 <select name="rank">
\r
240 for($i = count($this->rankname)-1; $i>=0; $i--){
\r
242 if ($i == $l->rank) $selected = 'selected';
\r
243 echo "<option value='$i' $selected>{$this->rankname[$i]}</option>\n";
\r
251 $img_file = 'rank'.$l->rank.'.gif';
\r
252 $img_title = $this->rankname[$l->rank];
\r
253 echo "<img class='icon-mid' src='$img_path$img_file' width='14' height='14' alt='$img_title' title='$img_title' />";
\r
258 <select name="cond">
\r
260 $cstyle = $this->condstyle;
\r
262 foreach($this->condname as $cname){
\r
264 if ($i == $l->cond) $selected = 'selected';
\r
265 echo "<option style='$cstyle[$i]' value='$i' $selected>$cname</option>\n";
\r
268 echo "<option style='$cstyle[$i]' value='$i'>[delete]</option>\n";
\r
274 $img_file = 'cond'.$l->cond.'.gif';
\r
275 $img_title = $this->condname[$l->cond];
\r
276 echo " <img class='icon-mid' src='$img_path$img_file' width='52' height='14' alt='$img_title' title='$img_title' />";
\r
279 if ($editmode and $showmode != 'nodate') {
\r
281 <input class="formfield" type="text" name="enddate" value="<?php echo $enddate ?>" size="9" maxlength="10" />
\r
284 else if($showmode != 'nodate') {
\r
285 $date_style = 'enddate';
\r
286 if ( $enddate == date('Y-m-d', mktime( 0,0,0,date('m'),date('d')+1,date('Y'))) ) {
\r
287 $date_style = 'enddate2'; //tomorrow
\r
289 else if ($enddate == date('Y-m-d')) {
\r
290 $date_style = 'enddate3'; //today
\r
292 else if ($enddate < date('Y-m-d')) {
\r
293 $date_style = 'enddate4'; //past
\r
296 //apply date format
\r
297 $enddate = date($this->getOption('dateFormat'), strToTime($enddate));
\r
298 echo " <span class='$date_style'>$enddate</span>";
\r
303 <input class="formfield" type="text" name="title" value="<?php echo $title ?>" size="20" maxlength="255" />
\r
307 echo " <span class='title'>$title</span></li>\n";
\r
311 if ($this->getOption('canedit') == 'team'
\r
312 and $member->getID() != $memid) $disstr = 'disabled';
\r
315 <input class="formbutton" type='submit' value='Update' <?php echo $disstr?> />
\r
319 } //end of foreach($sortlist)
\r
323 }// end of if(isset($this->list))
\r
326 if ($this->canEdit($memid)) {
\r
327 if ($editmode) $str_edit = "checked";
\r
328 else $str_show = "checked";
\r
330 <form class="todolist-r" method="post" action="<?php echo $CONF['ActionURL'] ?>">
\r
331 <input type="hidden" name="action" value="plugin"/>
\r
332 <input type="hidden" name="name" value="TodoList" />
\r
333 <input type="hidden" name="type" value="mode" />
\r
334 <input type="radio" name="todoedit" value="0" <?php echo $str_show ?> />Show
\r
335 <input type="radio" name="todoedit" value="1" <?php echo $str_edit ?> />Edit
\r
336 <input class="formbutton" type='submit' value='Change' />
\r
342 if ($this->getOption('flg_pluglink') == 'yes') {
\r
343 $pluglink_url = $this->getURL();
\r
345 echo "<a href='$pluglink_url' title='Jump to the site of this plugin'>";
\r
346 echo "<span style='font-size:9px'>» Get \"".$this->getName()."\"</span></a>";
\r
349 } //end of function
\r
352 function doAction($type) {
\r
353 global $CONF, $manager, $blog;
\r
355 if (! $this->isLoggedIn()) return;
\r
357 if ($blog) $b = &$blog;
\r
358 else $b = &$manager->getBlog($CONF['DefaultBlog']);
\r
362 $editmode = intRequestVar('todoedit'); //get or post
\r
363 $return = serverVar('HTTP_REFERER');
\r
364 $return = preg_replace('/[?&]todoedit=[^&]*/', '', $return); //delete old parameter
\r
365 if ( preg_match('/\?/',$return) ) $rvalue = "&todoedit=".$editmode;
\r
366 else $rvalue = "?todoedit=".$editmode;
\r
367 header("Location: $return$rvalue");
\r
371 $query = sprintf("INSERT INTO %s SET title=%s, rank=%d, cond=%d, regdate=%s, enddate=%s, memberid=%s",
\r
372 sql_table('plug_todolist'),
\r
373 $this->quote_smart(postVar('title')),
\r
374 $this->quote_smart(intPostVar('rank')),
\r
375 $this->quote_smart(intPostVar('cond')),
\r
376 date("'Y-m-d'", $b->getCorrectTime()),
\r
377 $this->quote_smart(postVar('enddate')),
\r
378 $this->quote_smart(intPostVar('memid')) );
\r
382 if (intPostVar('cond') >= count($this->condname)) { //cond = del
\r
383 $query = sprintf("DELETE FROM %s WHERE tid=%d",
\r
384 sql_table('plug_todolist'),
\r
385 $this->quote_smart(intPostVar('tid')) );
\r
388 $query = sprintf("UPDATE %s SET title=%s, rank=%d, cond=%d, enddate=%s WHERE tid=%d",
\r
389 sql_table('plug_todolist'),
\r
390 $this->quote_smart(postVar('title')),
\r
391 $this->quote_smart(intPostVar('rank')),
\r
392 $this->quote_smart(intPostVar('cond')),
\r
393 $this->quote_smart(postVar('enddate')),
\r
394 $this->quote_smart(intPostVar('tid')) );
\r
399 $vernum = intRequestVar('vernum');
\r
400 $this->versionUpdate($vernum);
\r
405 Header('Location: ' . serverVar('HTTP_REFERER') );
\r
408 // quote variable to make safe
\r
409 function quote_smart($value) {
\r
410 if (get_magic_quotes_gpc()) $value = stripslashes($value);
\r
411 if (!is_numeric($value)) {
\r
412 $value = "'". mysql_real_escape_string($value) ."'";
\r
415 $value = (int)$value;
\r