Commit e907a3c2 authored by lrargerich's avatar lrargerich

User notepad skeleton added

parent a4df399b
......@@ -1043,6 +1043,7 @@ tiki/lib/md5.js -text
tiki/lib/messu/messulib.php -text
tiki/lib/newsletters/nllib.php -text
tiki/lib/newsreader/newslib.php -text
tiki/lib/notepad/notepadlib.php -text
tiki/lib/overlib.js -text
tiki/lib/pclerror.lib.php -text
tiki/lib/pcltrace.lib.php -text
......@@ -1446,6 +1447,9 @@ tiki/templates/tiki-newsreader_groups.tpl -text
tiki/templates/tiki-newsreader_news.tpl -text
tiki/templates/tiki-newsreader_read.tpl -text
tiki/templates/tiki-newsreader_servers.tpl -text
tiki/templates/tiki-notepad_list.tpl -text
tiki/templates/tiki-notepad_read.tpl -text
tiki/templates/tiki-notepad_write.tpl -text
tiki/templates/tiki-objectpermissions.tpl -text
tiki/templates/tiki-old_polls.tpl -text
tiki/templates/tiki-orphan_pages.tpl -text
......@@ -1685,11 +1689,15 @@ tiki/tiki-logout.php -text
tiki/tiki-mailin.php -text
tiki/tiki-modules.php -text
tiki/tiki-my_tiki.php -text
tiki/tiki-mytiki_shared.php -text
tiki/tiki-newsletters.php -text
tiki/tiki-newsreader_groups.php -text
tiki/tiki-newsreader_news.php -text
tiki/tiki-newsreader_read.php -text
tiki/tiki-newsreader_servers.php -text
tiki/tiki-notepad_list.php -text
tiki/tiki-notepad_read.php -text
tiki/tiki-notepad_write.php -text
tiki/tiki-objectpermissions.php -text
tiki/tiki-old_polls.php -text
tiki/tiki-orphan_pages.php -text
......
......@@ -5,6 +5,7 @@ create table tiki_user_notes(
user varchar(200) not null,
noteId integer(12) not null auto_increment,
created integer(14),
name varchar(255),
lastModif integer(14),
data text,
primary key(noteId)
......
<?php
/* Task properties:
user, taskId, title, description, date, status, priority, completed, percentage
*/
class NotepadLib extends TikiLib {
function NotepadLib($db)
{
# this is probably uneeded now
if(!$db) {
die("Invalid db object passed to UsersLib constructor");
}
$this->db = $db;
}
function get_note($user, $noteId)
{
$query = "select * from tiki_user_notes where user='$user' and noteId='$noteId'";
$result = $this->query($query);
$res = $result->fetchRow(DB_FETCHMODE_ASSOC);
return $res;
}
function replace_task($user,$noteId,$name,$data)
{
$name = addslashes($name);
$data = addslashes($data);
$now = date("U");
if($noteId) {
$query = "update tiki_user_notes set
name = '$name',
data = '$data',
lastModif = $now
where user='$user' and noteId=$noteId";
$this->query($query);
return $noteId;
} else {
$query = "insert into tiki_user_notes(user,noteId,name,data,created,lastModif)
values('$user',$noteId,'$name','$data',$now,$now)";
$this->query($query);
$noteId = $this->getOne("select max(noteId) from tiki_user_notes where user='$user' and name='$name' and created=$now");
return $taskId;
}
}
function remove_note($user,$noteId)
{
$query = "delete from tiki_user_notes where user='$user' and noteId=$noteId";
$this->query($query);
}
function list_notes($user,$offset,$maxRecords,$sort_mode,$find)
{
$sort_mode = str_replace("_desc"," desc",$sort_mode);
$sort_mode = str_replace("_asc"," asc",$sort_mode);
if($find) {
$mid=" and (name like '%".$find."%' or data like '%".$find."%')";
} else {
$mid="";
}
$query = "select * from tiki_user_notes where user='$user' $mid order by $sort_mode,taskId desc limit $offset,$maxRecords";
$query_cant = "select count(*) from tiki_user_noteswhere user='$user' $mid";
$result = $this->query($query);
$cant = $this->getOne($query_cant);
$ret = Array();
while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$res['size']=strlen($res['data']);
$ret[] = $res;
}
$retval = Array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
}
$notepadlib= new NotepadLib($dbTiki);
?>
\ No newline at end of file
{*Smarty template*}
<a class="pagetitle" href="tiki-notepad_list.php">{tr}Notes{/tr}</a><br/><br/>
{include file=tiki-mytiki_bar.tpl}
<br/><br/>
<a class="link" href="tiki-notepad_write.php">{tr}Write a note{/tr}</a>
<br/><br/>
<table class="findtable">
<tr><td class="findtable">{tr}Find{/tr}</td>
<td class="findtable">
<form method="get" action="tiki-notepad_list.php">
<input type="text" name="find" value="{$find}" />
<input type="submit" value="{tr}find{/tr}" name="search" />
<input type="hidden" name="sort_mode" value="{$sort_mode}" />
</form>
</td>
</tr>
</table>
<form action="tiki-notepad_list.php" method="post">
<input type="submit" name="delete" value="{tr}delete{/tr}" />
<table class="normal">
<tr>
<td class="heading">&nbsp;</td>
<td class="heading" width="80%"><a class="tableheading" href="tiki-notepad_list.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'name_desc'}name_asc{else}name_desc{/if}">{tr}Name{/tr}</a></td>
<td class="heading" width="10%"><a class="tableheading" href="tiki-notepad_list.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'lastModif_desc'}lastModif_asc{else}lastModif_desc{/if}">{tr}Last Modified{/tr}</a></td>
<td class="heading" width="10%"><a class="tableheading" href="tiki-notepad_list.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'size_desc'}size_asc{else}size_desc{/if}">{tr}Size{/tr}</a></td>
</tr>
{cycle values="odd,even" print=false}
{section name=user loop=$channels}
<tr>
<td class="{cycle advance=false}">
<input type="checkbox" name="note[{$channels[user].noteId}]" />
</td>
<td class="{cycle advance=false}"><a class="link" href="tiki-notepad_read.php?notekId={$channels[user].noteId}&amp;offset={$offset}&amp;sort_mode={$sort_mode}&amp;find={$find}">{$channels[user].name}</a></td>
<td class="{cycle advance=false}">{$channels[user].lastModif|tiki_short_datetime}</td>
<td class="{cycle}">{$channels[user].size}</td>
</tr>
{/section}
</table>
</form>
<div class="mini">
{if $prev_offset >= 0}
[<a class="prevnext" href="tiki-notepad_list.php?find={$find}&amp;offset={$prev_offset}&amp;sort_mode={$sort_mode}">{tr}prev{/tr}</a>]&nbsp;
{/if}
{tr}Page{/tr}: {$actual_page}/{$cant_pages}
{if $next_offset >= 0}
&nbsp;[<a class="prevnext" href="tiki-notepad_list.php?find={$find}&amp;offset={$next_offset}&amp;sort_mode={$sort_mode}">{tr}next{/tr}</a>]
{/if}
{if $direct_pagination eq 'y'}
<br/>
{section loop=$cant_pages name=foo}
{assign var=selector_offset value=$smarty.section.foo.index|times:$maxRecords}
<a class="prevnext" href="tiki-notepad_list.php?find={$find}&amp;offset={$selector_offset}&amp;sort_mode={$sort_mode}">
{$smarty.section.foo.index_next}</a>&nbsp;
{/section}
{/if}
</div>
<h3>{tr}Add or edit a task{/tr}</h3>
<form action="tiki-notepad_list.php" method="post">
<input type="hidden" name="taskId" value="{$taskId}" />
<input type="hidden" name="tasks_useDates" value="{$tasks_useDates}" />
<table class="normal">
<tr><td class="formcolor">{tr}Title{/tr}</td>
<td class="formcolor"><input type="text" name="title" value="{$info.title}" /></td>
</tr>
<tr><td class="formcolor">{tr}Description{/tr}</td>
<td class="formcolor">
<textarea rows="10" cols="80" name="description">{$info.description}</textarea>
</td>
</tr>
{if $tasks_useDates eq 'y'}
<tr><td class="formcolor">{tr}Start date{/tr}</td>
<td class="formcolor">{html_select_date time=$info.date end_year="+1"}</td>
</tr>
{if $info.status eq 'c'}
<tr><td class="formcolor">{tr}Completed{/tr}</td>
<td class="formcolor">{$info.completed|tiki_short_date}</td>
</tr>
{/if}
{/if}
<tr><td class="formcolor">{tr}Status{/tr}</td>
<td class="formcolor">
<select name="status">
<option value="o" {if $info.status eq 'o'}selected="selected"{/if}>{tr}open{/tr}</option>
<option value="c" {if $info.status eq 'c'}selected="selected"{/if}>{tr}completed{/tr}</option>
</select>
</td>
</tr>
<tr><td class="formcolor">{tr}Priority{/tr}</td>
<td class="formcolor">
<select name="priority">
<option value="1" {if $info.priority eq 1}selected="selected"{/if}>1</option>
<option value="2" {if $info.priority eq 2}selected="selected"{/if}>2</option>
<option value="3" {if $info.priority eq 3}selected="selected"{/if}>3</option>
<option value="4" {if $info.priority eq 4}selected="selected"{/if}>4</option>
<option value="5" {if $info.priority eq 5}selected="selected"{/if}>5</option>
</select>
</td>
</tr>
<tr>
<td class="formcolor">{tr}Percentage completed{/tr}</td>
<td class="formcolor">
<select name="percentage">
{html_options values="$comp_array" output="$comp_array_p" selected="$info.percentage"}
</select>
</td>
</tr>
<tr>
<td class="formcolor">&nbsp;</td>
<td class="formcolor"><input type="submit" name="save" value="{tr}save{/tr}" /></td>
</tr>
</table>
</form>
{*Smarty template*}
<a class="pagetitle" href="tiki-notepad_read.php?noteId={$noteId}">{tr}Reading note:{/tr} {$info.name}</a><br/><br/>
{include file=tiki-mytiki_bar.tpl}
<br/><br/>
<a class="link" href="tiki-notepad_list.php">{tr}List notes{/tr}</a>
<a class="link" href="tiki-notepad_write.php">{tr}Write note{/tr}</a>
<br/><br/>
<form action="tiki-notepad_read.php" method="post">
<input type="hidden" name="noteId" value="{$noteId}" />
<select name="mode">
<option value="raw" {if $mode eq 'raw'}seleced="selected"{/if}>{tr}Normal{/tr}</option>
<option value="wiki"{if $mode eq 'wiki'}seleced="selected"{/if}>{tr}Wiki{/tr}</option>
</select>
<input type="submit" name="mode" value="{tr}set{/tr}" />
</form>
<form action="tiki-notepad_read.php" method="post">
<input type="hidden" name="noteId" value="{$noteId}" />
<input type="submit" name="remove" value="{tr}delete{/tr}" />
</form>
<form action="tiki-notepad_write.php" method="post">
<input type="hidden" name="noteId" value="{$noteId}" />
<input type="submit" name="write" value="{tr}edit{/tr}" />
</form>
<table class="normal">
<tr>
<td class="formcolor">
{$info.parsed}
</td>
</tr>
</table>
{*Smarty template*}
<a class="pagetitle" href="tiki-notepad_write.php">{tr}Write a note{/tr}</a><br/><br/>
{include file=tiki-mytiki_bar.tpl}
<br/><br/>
<a class="link" href="tiki-notepad_list.php">{tr}Notes{/tr}</a>
<form action="tiki-notepad_write.php" method="post">
<input type="hidden" name="noteId" value="{$noteId}" />
<table class="normal">
<tr><td class="formcolor">{tr}Name{/tr}</td>
<td class="formcolor"><input type="text" name="name" value="{$info.name}" /></td>
</tr>
<tr><td class="formcolor">{tr}Data{/tr}</td>
<td class="formcolor">
<textarea rows="40" cols="80" name="data">{$info.data}</textarea>
</td>
</tr>
<tr>
<td class="formcolor">&nbsp;</td>
<td class="formcolor"><input type="submit" name="save" value="{tr}save{/tr}" /></td>
</tr>
</table>
</form>
<?php
if($feature_messages=='y' && $tiki_p_messages=='y') {
$unread = $tikilib->user_unread_messages($user);
$smarty->assign('unread',$unread);
}
?>
<?php
require_once('tiki-setup.php');
include_once('lib/notepad/notepadlib.php');
if($feature_notepad != 'y') {
$smarty->assign('msg',tra("This feature is disabled"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(!$user) {
$smarty->assign('msg',tra("Must be logged to use this feature"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(isset($_REQUEST["delete"])) {
foreach(array_keys($_REQUEST["note"]) as $note) {
$notepadlib->remove_task($user, $note);
}
}
if(!isset($_REQUEST["sort_mode"])) {
$sort_mode = 'lastModif_desc';
} else {
$sort_mode = $_REQUEST["sort_mode"];
}
if(!isset($_REQUEST["offset"])) {
$offset = 0;
} else {
$offset = $_REQUEST["offset"];
}
$smarty->assign_by_ref('offset',$offset);
if(isset($_REQUEST["find"])) {
$find = $_REQUEST["find"];
} else {
$find = '';
}
$smarty->assign('find',$find);
$smarty->assign_by_ref('sort_mode',$sort_mode);
if(isset($_SESSION['thedate'])) {
$pdate = $_SESSION['thedate'];
} else {
$pdate = date("U");
}
$channels = $notepadlib->list_notes($user,$offset,$maxRecords,$sort_mode,$find);
$cant_pages = ceil($channels["cant"] / $maxRecords);
$smarty->assign_by_ref('cant_pages',$cant_pages);
$smarty->assign('actual_page',1+($offset/$maxRecords));
if($channels["cant"] > ($offset+$maxRecords)) {
$smarty->assign('next_offset',$offset + $maxRecords);
} else {
$smarty->assign('next_offset',-1);
}
// If offset is > 0 then prev_offset
if($offset>0) {
$smarty->assign('prev_offset',$offset - $maxRecords);
} else {
$smarty->assign('prev_offset',-1);
}
$smarty->assign_by_ref('channels',$channels["data"]);
$smarty->assign('tasks_useDates',$tasks_useDates);
include_once('tiki-mytiki_shared.php');
$smarty->assign('mid','tiki-notepad_list.tpl');
$smarty->display('tiki.tpl');
?>
<?php
require_once('tiki-setup.php');
include_once('lib/notepad/notepadlib.php');
if($feature_notepad != 'y') {
$smarty->assign('msg',tra("This feature is disabled"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(!$user) {
$smarty->assign('msg',tra("Must be logged to use this feature"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(!isset($_REQUEST["noteId"])) {
$smarty->assign('msg',tra("No note indicated"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(isset($_REQUEST["remove"])) {
$notepadlib->remove_note($user, $_REQUEST['remove']);
}
$info = $notepadlib->get_note($user,$_REQUEST["noteId"]);
if(!isset($_REQUEST['mode'])) $_REQUEST['mode']='raw';
if($_REQUEST['mode']=='raw') {
$info['parsed']=htmlentities(nl2br($info['data']));
}
if($_REQUEST['mode']=='wiki') {
$info['parsed']=$tikilib->parse_data($info['data']);
}
$smarty->assign('mode',$_REQUEST['mode']);
$smarty->assign('noteId',$_REQUEST["noteId"]);
$smarty->assign('info',$info);
include_once('tiki-mytiki_shared.php');
$smarty->assign('mid','tiki-notepad_read.tpl');
$smarty->display('tiki.tpl');
?>
<?php
require_once('tiki-setup.php');
include_once('lib/notepad/notepadlib.php');
if($feature_notepad != 'y') {
$smarty->assign('msg',tra("This feature is disabled"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(!$user) {
$smarty->assign('msg',tra("Must be logged to use this feature"));
$smarty->display("styles/$style_base/error.tpl");
die;
}
if(!isset($_REQUEST["noteId"])) $_REQUEST["noteId"]=0;
if(isset($_REQUEST["remove"])) {
$notepadlib->remove_note($user, $_REQUEST['remove']);
}
if($_REQUEST["noteId"]) {
$info = $notepadlib->get_note($user,$_REQUEST["noteId"]);
} else {
$info=Array();
$info['name']='';
$info['data']='';
}
if(isset($_REQUEST['save'])) {
$notepadlib->replace_note($user,$_REQUEST["noteId"],$_REQUEST["name"],$_REQUEST["data"]);
//:TODO: replace this putting the code in notepad-list
header('location: tiki-notepad_list.php');
die;
}
$smarty->assign('noteId',$_REQUEST["noteId"]);
$smarty->assign('info',$info);
include_once('tiki-mytiki_shared.php');
$smarty->assign('mid','tiki-notepad_write.tpl');
$smarty->display('tiki.tpl');
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment