Task #1118 - Partage de notes via le Pense-bête

#1118 : réécriture de note + mode public
This commit is contained in:
Dany De Bontridder 2015-05-24 20:07:55 +02:00
parent d183eb59a6
commit 6f1f0107a9
8 changed files with 402 additions and 129 deletions

View file

@ -54,9 +54,20 @@ if (isset($_REQUEST['show']))
$todo=new Todo_list($cn);
$todo->set_parameter('id',$_REQUEST['id']);
$todo->load();
$content=$todo->display();
header('Content-type: text/xml; charset=UTF-8');
header ('<?xml version="1.0" encoding="UTF-8"?>');
echo $todo->toXML();
$dom=new DOMDocument('1.0','UTF-8');
$tl_id=$dom->createElement('tl_id',$todo->get_parameter('id'));
$tl_content=$dom->createElement('tl_content',$content);
$root=$dom->createElement("root");
$root->appendChild($tl_id);
$root->appendChild($tl_content);
$dom->appendChild($root);
echo $dom->saveXML();
exit();
}
@ -68,3 +79,34 @@ if (isset($_REQUEST['del']))
$todo->delete();
exit();
}
$ac=HtmlInput::default_value_get('act', 'save');
if ($ac == 'save')
{
$cn=new Database(dossier::id());
$todo=new Todo_List($cn);
$todo->set_parameter("id", HtmlInput::default_value_get("id", 0));
$todo->set_parameter("date", HtmlInput::default_value_get("p_date_todo", ""));
$todo->set_parameter("title", HtmlInput::default_value_get("p_title", ""));
$todo->set_parameter("desc", HtmlInput::default_value_get("p_desc", ""));
$todo->set_is_public(HtmlInput::default_value_get("p_public", "N"));
$todo->save();
$todo->load();
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0','UTF-8');
$tl_id=$dom->createElement('tl_id',$todo->get_parameter('id'));
$tl_content=$dom->createElement('row',$todo->display_row('class="odd"','N'));
$root=$dom->createElement("root");
$todo_class=$todo->get_class();
$todo_class=($todo_class=="")?' odd ':$todo_class;
$class=$dom->createElement("style",$todo_class);
$root->appendChild($tl_id);
$root->appendChild($tl_content);
$root->appendChild($class);
$dom->appendChild($root);
echo $dom->saveXML();
exit();
}

View file

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder danydb@aevalys.eu
@ -27,28 +27,60 @@
*/
function todo_list_show(p_id)
{
waiting_box();
var gDossier=$('gDossier').value;
$('add_todo_list').style.top=(posY+offsetY)+'px';
$('add_todo_list').style.left=(posX+offsetX-200)+'px';
$('add_todo_list').hide();
waiting_node();
/*
* create a div id based on p_id
*/
try
{
var action=new Ajax.Request(
'ajax_todo_list.php',
{
method:'get',
parameters:
{'show':
1,'id':
p_id,'gDossier':
gDossier
},
onFailure:todo_list_show_error,
onSuccess:todo_list_show_success
}
);
var gDossier = $('gDossier').value;
var action = new Ajax.Request(
'ajax_todo_list.php',
{
method: 'get',
parameters:
{'show':
1, 'id':
p_id, 'gDossier':
gDossier
},
onFailure: todo_list_show_error,
onSuccess: function (req)
{
try
{
var todo_div=create_div({id:'todo_list_div'+p_id,cssclass:'add_todo_list',drag:1});
todo_div.style.top = (posY + offsetY) + 'px';
todo_div.style.left = (posX + offsetX - 200) + 'px';
var answer = req.responseXML;
var tl_id = answer.getElementsByTagName('tl_id');
var tl_content = answer.getElementsByTagName('tl_content');
if (tl_id.length == 0)
{
var rec = req.responseText;
alert('erreur :' + rec);
}
var content = unescape_xml(getNodeText(tl_content[0]));
todo_div.innerHTML=content;
remove_waiting_node();
content.evalScripts();
Effect.SlideDown(todo_div, {duration: 0.1, direction: 'top-left'})
}
catch (e)
{
alert(e.message);
}
}
}
);
}
catch (e)
{
@ -56,72 +88,89 @@ function todo_list_show(p_id)
}
return false;
}
function todo_list_show_success(req)
{
try
{
var answer=req.responseXML;
var tl_id=answer.getElementsByTagName('tl_id');
var tl_title=answer.getElementsByTagName('tl_title');
var tl_desc=answer.getElementsByTagName('tl_desc');
var tl_date=answer.getElementsByTagName('tl_date');
if ( tl_id.length == 0 )
{
var rec=req.responseText;
alert ('erreur :'+rec);
}
remove_waiting_box();
$('p_title').value=getNodeText(tl_title[0]);
$('p_date_todo').value=getNodeText(tl_date[0]);
$('p_desc').value=getNodeText(tl_desc[0]);
$('tl_id').value=getNodeText(tl_id[0]);
if ($('add_todo_list').visible()==false) { Effect.Grow('add_todo_list',{duration:0.2,direction:'top-left'}) };
}
catch (e)
{
alert(e.message);
}
}
function todo_list_show_error(request_json)
{
alert ('failure');
alert('failure');
}
function add_todo()
{
$('add_todo_list').style.top=posY+offsetY+"px";
$('add_todo_list').style.left=posX+offsetX+"px";
todo_list_show(0);
/*$('add_todo_list').style.top = posY + offsetY + "px";
$('add_todo_list').style.left = posX + offsetX + "px";
$('p_title').value='';
$('p_title').value = '';
$('p_date_todo').value='';
$('p_desc').value='';
$('tl_id').value=0;
$('add_todo_list').style.display='block';
$('p_date_todo').value = '';
$('p_desc').value = '';
$('tl_id').value = 0;
$('add_todo_list').style.display = 'block';*/
}
function todo_list_remove(p_ctl)
{
if ( confirm('Effacer ?') == false )
if (confirm('Effacer ?') == false)
{
return;
}
$("tr"+p_ctl).hide();
var gDossier=$('gDossier').value;
$("tr" + p_ctl).hide();
var gDossier = $('gDossier').value;
var action=new Ajax.Request(
'ajax_todo_list.php',
{
method:'get',
parameters:
{'del':
1,'id':
p_ctl,'gDossier':
gDossier
}
}
);
var action = new Ajax.Request(
'ajax_todo_list.php',
{
method: 'get',
parameters:
{'del':
1, 'id':
p_ctl, 'gDossier':
gDossier
}
}
);
return false;
}
function todo_list_save(p_form)
{
try {
console.log(p_form);
var form=$('todo_form_'+p_form);
var json=form.serialize(true);
new Ajax.Request('ajax_todo_list.php',
{
method:'get',
parameters:json,
onSuccess:function (req) {
// On success : reload the correct row and close
// the box
var answer = req.responseXML;
var tl_id = answer.getElementsByTagName('tl_id');
var content = answer.getElementsByTagName('row');
var style = answer.getElementsByTagName('style');
if (tl_id.length == 0)
{
var rec = req.responseText;
alert('erreur :' + rec);
}
var tr = $('tr'+p_form);
if ( p_form == 0)
{
tr=document.createElement('tr');
tr.id='tr'+getNodeText(tl_id[0]);
$('table_todo').appendChild(tr);
}
var html=getNodeText(content[0]);
tr.innerHTML=unescape_xml(html);
$w(tr.className).each ( function(p_class) { tr.removeClassName(p_class); } );
tr.addClassName(getNodeText(style[0]));
Effect.Fold('todo_list_div'+p_form,{duration:0.1});
}
}
);
}
catch (e) {
console.log(e.message);
return false;
}
return false;
}

View file

@ -973,7 +973,7 @@ div.topmenu {
font-variant:small-caps;
}
/* </style> */
#add_todo_list {
#add_todo_list , div.add_todo_list {
border:1px solid #0000FF;
background-color:#DDE6FF;
padding:0.07%;

View file

@ -47,9 +47,10 @@ class Todo_List
"date"=>"tl_date",
"title"=>"tl_title",
"desc"=>"tl_desc",
"owner"=>"use_login");
"owner"=>"use_login",
"is_public"=>"is_public");
private $cn;
private $tl_id,$tl_date,$tl_title,$use_login;
private $tl_id,$tl_date,$tl_title,$use_login,$is_public;
function __construct ($p_init)
{
@ -57,6 +58,7 @@ class Todo_List
$this->tl_id=0;
$this->tl_desc="";
$this->use_login=$_SESSION['g_user'];
$this->is_public="N";
}
public function get_parameter($p_string)
@ -139,13 +141,14 @@ class Todo_List
$this->tl_title=mb_substr(trim($this->tl_title),0,30);
$sql="insert into todo_list (tl_date,tl_title,tl_desc,use_login) ".
" values (to_date($1,'DD.MM.YYYY'),$2,$3,$4) returning tl_id";
" values (to_date($1,'DD.MM.YYYY'),$2,$3,$4,$5) returning tl_id";
$res=$this->cn->exec_sql(
$sql,
array($this->tl_date,
$this->tl_title,
$this->tl_desc,
$this->use_login)
$this->use_login,
$this->is_public)
);
$this->tl_id=Database::fetch_result($res,0,0);
@ -158,23 +161,24 @@ class Todo_List
if (trim($this->tl_title)=='')
$this->tl_title=mb_substr(trim($this->tl_desc),0,40);
if (trim($this->tl_desc)=='')
if (trim($this->tl_title)=='')
{
alert('La note est vide');
return;
}
/* limit the title to 35 char */
$this->tl_title=mb_substr(trim($this->tl_title),0,40);
$sql="update todo_list set tl_title=$1,tl_date=to_date($2,'DD.MM.YYYY'),tl_desc=$3 ".
$sql="update todo_list set tl_title=$1,tl_date=to_date($2,'DD.MM.YYYY'),tl_desc=$3,is_public=$5 ".
" where tl_id = $4";
$res=$this->cn->exec_sql(
$sql,
array($this->tl_title,
$this->tl_date,
$this->tl_desc,
$this->tl_id)
$this->tl_id,
$this->is_public)
);
}
@ -183,19 +187,29 @@ class Todo_List
*/
public function load_all()
{
$sql="select tl_id, tl_title,tl_desc,to_char( tl_date,'DD.MM.YYYY') as str_tl_date,tl_date
from todo_list where use_login=$1".
" order by tl_date::date desc";
$sql="select tl_id,
tl_title,
tl_desc,
to_char( tl_date,'DD.MM.YYYY') as tl_date,
is_public,
use_login
from todo_list
where
use_login=$1
or is_public = 'Y'
or tl_id in (select tl_id from todo_list_shared where use_login=$1)
order by tl_date::date desc";
$res=$this->cn->exec_sql(
$sql,
array($this->use_login));
$array=Database::fetch_all($res);
return $array;
}
public function load()
{
$sql="select tl_id,tl_title,tl_desc,to_char( tl_date,'DD.MM.YYYY') as tl_date
$sql="select tl_id,tl_title,tl_desc,to_char( tl_date,'DD.MM.YYYY') as tl_date,is_public
from todo_list where tl_id=$1 and use_login=$2";
$res=$this->cn->exec_sql(
@ -213,12 +227,14 @@ class Todo_List
}
public function delete()
{
$sql="delete from todo_list where tl_id=$1 and use_login=$2";
$res=$this->cn->exec_sql($sql,array($this->tl_id,$_SESSION['g_user']));
global $g_user;
if ( $this->use_login != $_SESSION['g_user'] && $g_user->check_action(SHARENOTEREMOVE)==0) return;
$sql="delete from todo_list where tl_id=$1 ";
$res=$this->cn->exec_sql($sql,array($this->tl_id));
}
/**
*@brief transform into xml
*@brief transform into xml for ajax answer
*/
public function toXML()
{
@ -229,24 +245,107 @@ class Todo_List
$ret='<data>'.$id.$title.$desc.$date.'</data>';
return $ret;
}
/**
* @brief set a note public
* @param $p_value is Y or N
*/
public function set_is_public($p_value)
{
global $g_user;
if ($g_user->check_action(SHARENOTEPUBLIC) == 1 )
{
$this->is_public=$p_value;
}
}
/**
* @brief Insert a share for current note
* in the table todo_list_shared
* @param string (use_login)
*/
public function save_shared_with($p_array)
{
global $g_user;
if ($g_user->check_action(SHARENOTE) == 1 )
{
$this->cn->exec_sql('insert into todo_list_shared (todo_list_id,use_login) values ($1,$2)',
array($this->tl_id,$p_array));
}
}
/**
* @brief Insert a share for current note
* in the table todo_list_shared
* The public shared note cannot be removed
* @param string (use_login)
*/
public function remove_shared_with($p_array)
{
$this->cn->exec_sql('delete from todo_list_shared where todo_list_id = $1 and use_login=$2',
array($this->tl_id,$p_array));
}
/**
* Display the note
* @return html string
*/
function display()
{
ob_start();
$this->load();
include 'template/todo_list_display.php';
$ret=ob_get_clean();
return $ret;
}
function get_class()
{
$p_odd="";
$a=date('d.m.Y');
if ($a == $this->tl_date) $p_odd='highlight';
return $p_odd;
}
function display_row($p_odd,$with_tag='Y')
{
$r="";
$highlight=$this->get_class();
$p_odd=($highlight == "")?$p_odd:$highlight;
if ( $with_tag == 'Y') $r = '<tr id="tr'.$this->tl_id.'" class="'.$p_odd.'">';
$r.=
'<td sorttable_customkey="'.format_date($this->tl_date,'DD.MM.YYYY','YYYYMMDD').'">'.
$this->tl_date.
'</td>'.
'<td>'.
'<a class="line" href="javascript:void(0)" onclick="todo_list_show(\''.$this->tl_id.'\')">'.
htmlspecialchars($this->tl_title).
'</a>'.
'</td>'.
'<td>'.
HtmlInput::button('del','X','onClick="todo_list_remove('.$this->tl_id.')"','smallbutton').
'</td>';
if ( $with_tag == 'Y') $r .= '</tr>';
return $r;
}
static function to_object ($p_cn,$p_array)
{
$end=count($p_array);
$ret=array();
for ($i=0;$i < $end;$i++)
{
$t=new Todo_List($p_cn);
$t->tl_id=$p_array[$i]['tl_id'];
$t->tl_date=$p_array[$i]['tl_date'];
$t->tl_title=$p_array[$i]['tl_title'];
$t->tl_desc=$p_array[$i]['tl_desc'];
$t->is_public=$p_array[$i]['is_public'];
$t->use_login=$p_array[$i]['use_login'];
$ret[$i]=clone $t;
}
return $ret;
}
/*!\brief static testing function
*/
static function test_me()
{
$cn=new Database(dossier::id());
$r=new Todo_List($cn);
$r->set_parameter('title','test');
$r->use_login='phpcompta';
$r->set_parameter('date','02.03.2008');
$r->save();
$r->set_parameter('id',3);
$r->load();
print_r($r);
$r->set_parameter('title','Test UPDATE');
$r->save();
print_r($r);
$r->set_parameter('id',1);
$r->delete();
}
}

View file

@ -26,5 +26,8 @@ define ('VIEWDOC',1010); // Voir document pour follow up
define ('PARCATDOC',1050); // modifier type document pour follow up
define ('RMRECEIPT',1110); // Effacer un document d'une pièce comptable
define ('RMOPER',1120); // Effacer une opération comptable
define ('SHARENOTE',1210); // Can share a note
define ('SHARENOTEPUBLIC',1230); // Can create public note
define ('SHARENOTEREMOVE',1240); // Can drop drop of other
global $audit; $audit=false;
?>

View file

@ -14,17 +14,9 @@
* Todo list
*/
echo dossier::hidden();
if ( isset($_REQUEST['save_todo_list'])) {
/* Save the new elt */
$add_todo=new Todo_List($cn);
$add_todo->set_parameter('id',$_REQUEST['tl_id']);
$add_todo->set_parameter('title',$_REQUEST['p_title']);
$add_todo->set_parameter('desc',$_REQUEST['p_desc']);
$add_todo->set_parameter('date',$_REQUEST['p_date_todo']);
$add_todo->save();
}
$todo=new Todo_List($cn);
$array=$todo->load_all();
$a_todo=Todo_List::to_object($cn,$array);
echo HtmlInput::button('add',_('Ajout'),'onClick="add_todo()"','smallbutton');
if ( ! empty ($array) ) {
@ -33,23 +25,10 @@ if ( ! empty ($array) ) {
$nb=0;
$today=date('d.m.Y');
foreach ($array as $row) {
if ( $nb % 2 == 0 ) $odd='class="odd" '; else $odd='class="even" ';
if ( strcmp($today,$row['str_tl_date'])==0) { $odd.=' style="background-color:#FFEA00"';}
foreach ($a_todo as $row) {
if ( $nb % 2 == 0 ) $odd='odd '; else $odd='even ';
$nb++;
echo '<tr id="tr'.$row['tl_id'].'" '.$odd.'>'.
'<td sorttable_customkey="'.$row['tl_date'].'">'.
$row['str_tl_date'].
'</td>'.
'<td>'.
'<a class="line" href="javascript:void(0)" onclick="todo_list_show(\''.$row['tl_id'].'\')">'.
htmlspecialchars($row['tl_title']).
'</a>'.
'</td>'.
'<td>'.
HtmlInput::button('del','X','onClick="todo_list_remove('.$row['tl_id'].')"','smallbutton').
'</td>'.
'</tr>';
echo $row->display_row($odd);
}
echo '</table>';
}

View file

@ -65,3 +65,10 @@ $array=$cn->get_array("select ac_id, ac_description from action where ac_id >=$
$array=$cn->get_array("select ac_id, ac_description from action where ac_id >=$1 and ac_id <=$2 order by ac_id ",
array(1101,1200));
display_security_fieldset(_('Comptabilité'),$array,$sec_User); ?>
<?php
// Note Sharing
$array=$cn->get_array("select ac_id, ac_description from action where ac_id >=$1 and ac_id <=$2 order by ac_id ",
array(1200,1300));
display_security_fieldset(_('Note'),$array,$sec_User);
?>

View file

@ -0,0 +1,94 @@
<?php
/*
* * Copyright (C) 2015 Dany De Bontridder <dany@alchimerys.be>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* @brief included from Todo_List::display
* create a html with content
* @see Todo_List
*/
$wDate=new IDate('p_date_todo',$this->tl_date);
$wTitle=new IText('p_title',$this->tl_title);
$wDesc=new ITextArea('p_desc', strip_tags($this->tl_desc));
$wDesc->heigh=5;
$wDesc->width=40;
$is_public=new ICheckBox('p_public');
$is_public->value='Y';
$is_public->set_check($this->is_public);
echo HtmlInput::title_box("Note","todo_list_div".$this->tl_id);
?>
<form id="todo_form_<?php echo $this->tl_id?>" onsubmit="todo_list_save(<?php echo $this->tl_id?>);return false">
<table>
<tr>
<td>
<?php echo _("Date") ?>
</td>
<td>
<?php echo $wDate->input() ?>
</td>
</tr>
<tr>
<td>
<?php echo _("Titre") ?>
</td>
<td>
<?php echo h($wTitle->input());?>
</td>
</tr>
<?php
// Section about Public note
// display only if priv granted
if ($g_user->check_action(SHARENOTEPUBLIC)):
?>
<tr>
<td>
<?php echo _('Public')?>
</td>
<td>
<?php echo $is_public->input()?>
</td>
</tr>
<?php
endif;
?>
<tr>
<td>
<?php echo _('Partage')?>
</td>
<td>
Partage
</td>
</tr>
</table>
<?php echo h($wDesc->input()); ?>
<?php echo dossier::hidden(); ?>
<?php echo HtmlInput::hidden('act','save') ?>
<?php echo HtmlInput::hidden('id',$this->tl_id) ?>
<input type="submit" class="smallbutton" value="<?php echo _('Sauve');?>" onclick="todo_list_save(<?php echo $this->tl_id?>);return false">
</form>