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

#1118 : partage des notes avec les autres utilisateurs
This commit is contained in:
Dany De Bontridder 2015-05-27 00:18:31 +02:00
parent 3c652d8795
commit c51865984e
5 changed files with 306 additions and 19 deletions

View file

@ -47,7 +47,9 @@ $g_user=new User($cn);
$g_user->check(true);
$g_user->check_dossier(Dossier::id(),true);
ajax_disconnected('add_todo_list');
////////////////////////////////////////////////////////////////////////////////
// Display the note
////////////////////////////////////////////////////////////////////////////////
if (isset($_REQUEST['show']))
{
$cn=new Database(dossier::id());
@ -70,7 +72,9 @@ if (isset($_REQUEST['show']))
echo $dom->saveXML();
exit();
}
////////////////////////////////////////////////////////////////////////////////
// Delete the note
////////////////////////////////////////////////////////////////////////////////
if (isset($_REQUEST['del']))
{
$cn=new Database(dossier::id());
@ -81,6 +85,9 @@ if (isset($_REQUEST['del']))
}
$ac=HtmlInput::default_value_get('act', 'save');
////////////////////////////////////////////////////////////////////////////////
// Save the modification of a note
////////////////////////////////////////////////////////////////////////////////
if ($ac == 'save')
{
$cn=new Database(dossier::id());
@ -110,3 +117,110 @@ if ($ac == 'save')
exit();
}
////////////////////////////////////////////////////////////////////////////////
// Display a list to select the user with who we want to share notes
////////////////////////////////////////////////////////////////////////////////
if ($ac=='shared_note')
{
$id=HtmlInput::default_value_get("todo_id", 0);
// If note_id is not correct then give an error
if ($id==0||isNumber($id)==0)
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Erreur : note invalide"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
$todo=new Todo_List($cn);
$todo->set_parameter("id", $id);
$todo->load();
if ($g_user->login!=$todo->get_parameter("owner"))
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Cette note n'est pas à vous"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
if ($g_user->check_action(SHARENOTE)== 0)
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Accès interdit"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
ob_start();
echo HtmlInput::title_box(_('Liste utilisateurs'), "shared_".$id);
$todo->display_user();
$result=ob_get_clean();
//
// output the XML
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', escape_xml($result));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
////////////////////////////////////////////////////////////////////////////////
// Share the note with someone or remove it
////////////////////////////////////////////////////////////////////////////////
if ( $ac=="set_share")
{
$id=HtmlInput::default_value_get("todo_id", 0);
$p_login=HtmlInput::default_value_get("login","");
// If note_id is not correct then give an error
if ($id==0||isNumber($id)==0 || trim ($p_login)=="")
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Erreur : paramètre invalide"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
$todo=new Todo_List($cn);
$todo->set_parameter("id", $id);
$todo->load();
if ($g_user->login!=$todo->get_parameter("owner"))
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Cette note n'est pas à vous"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
if ($g_user->login!=$todo->get_parameter("owner"))
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Cette note n'est pas à vous"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
if ($g_user->check_action(SHARENOTE)== 0)
{
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
$tl_id=$dom->createElement('content', _("Accès interdit"));
$dom->appendChild($tl_id);
echo $dom->saveXML();
return;
}
if ( $todo->is_shared_with($p_login) == 0 )
{
// Add a share to the user
$todo->add_share($p_login);
} else {
// remove a share from the user
$todo->remove_share($p_login);
}
}

View file

@ -95,15 +95,6 @@ function todo_list_show_error(request_json)
function add_todo()
{
todo_list_show(0);
/*$('add_todo_list').style.top = posY + offsetY + "px";
$('add_todo_list').style.left = posX + offsetX + "px";
$('p_title').value = '';
$('p_date_todo').value = '';
$('p_desc').value = '';
$('tl_id').value = 0;
$('add_todo_list').style.display = 'block';*/
}
function todo_list_remove(p_ctl)
{
@ -132,7 +123,6 @@ function todo_list_remove(p_ctl)
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',
@ -176,11 +166,14 @@ function todo_list_save(p_form)
}
/**
* @brief maximize or minimize the todo list from the
* dashboard.
* @brief toggle the zoom of the note
*/
var todo_maximize=false;
/**
* @brief maximize or minimize the todo list from the
* dashboard.
* @returns {undefined}
*/
function zoom_todo ()
{
if ( ! todo_maximize)
@ -198,4 +191,56 @@ function zoom_todo ()
if ($('todo_listg_div').style.setAttribute) { $('todo_listg_div').style.setAttribute('cssText', "") ;}
}
}
function todo_list_share(p_note, p_dossier)
{
waiting_node();
new Ajax.Request(
'ajax_todo_list.php',
{
method: "get",
parameters: {"act": 'shared_note',
"todo_id": p_note,
"gDossier": p_dossier
},
onSuccess: function (p_xml) {
try {
/**
* Show the little div to add other user
* or a error message if it is forbidden
*/
remove_waiting_node();
var answer = p_xml.responseXML;
var content = answer.getElementsByTagName('content');
if (content.length == 0) {
return;
}
var html_content=unescape_xml(getNodeText(content[0]));
var shared_note = "shared_" + p_note;
create_div({"id": shared_note, "cssclass": "inner_box",drag:1});
$("shared_" + p_note).setStyle( { top : posY + offsetY+"px",left:posX+offsetY+"px","width":"25%"});
$("shared_" + p_note).hide();
$(shared_note).innerHTML = html_content;
$(shared_note).show();
} catch (e) {
alert(e.message);
}
}
}
);
}
function todo_list_set_share(note_id,p_login,p_dossier)
{
waiting_node();
new Ajax.Request('ajax_todo_list.php',
{
method:"get",
parameters: { todo_id:note_id,act:"set_share","gDossier":p_dossier,"login":p_login},
onSuccess:function() {
remove_waiting_node();
}
}
)
}

View file

@ -342,6 +342,48 @@ class Todo_List
}
return $ret;
}
/**
* @brief display all the user to select the user with who we want to share
* the connected user is not shown
* @global type $g_user
*/
function display_user()
{
global $g_user;
// Get array of user
$p_array=User::get_list(Dossier::id());
$dossier=Dossier::id();
include 'template/todo_list_list_user.php';
}
/**
* return the todo_list_shared.id of the note, if nothing is found then
* return 0
* @param $p_login
* @return int
*/
function is_shared_with($p_login)
{
$ret=$this->cn->get_value("select id from todo_list_shared where use_login=$1 and todo_list_id=$2",array($p_login,$this->tl_id));
if ($ret == "")return 0;
return $ret;
}
/**
* @brief Add a share with someone
* @param type $p_login
*/
function add_share($p_login)
{
$this->cn->exec_sql("insert into todo_list_shared(todo_list_id,use_login) values ($1,$2)",array($this->tl_id,$p_login));
}
/**
* @brief remove the share with someone
* @param type $p_login
*/
function remove_share($p_login)
{
$this->cn->exec_sql("delete from todo_list_shared where todo_list_id = $1 and use_login = $2 ",array($this->tl_id,$p_login));
}
/*!\brief static testing function
*/
static function test_me()

View file

@ -33,7 +33,7 @@ $wDesc->width=40;
$is_public=new ICheckBox('p_public');
$is_public->value='Y';
$is_public->set_check($this->is_public);
$dossier=Dossier::id();
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">
@ -75,21 +75,29 @@ echo HtmlInput::title_box("Note","todo_list_div".$this->tl_id);
<?php
endif;
?>
<?php
// section if the user can share note with other
//users
if ($g_user->check_action(SHARENOTE)) :
?>
<tr>
<td>
<?php echo _('Partage')?>
</td>
<td>
Partage
<?php echo HtmlInput::anchor(_('Partage'), "", " onclick=\"todo_list_share({$this->tl_id},{$dossier}) \";")?>
</td>
</tr>
<?php
endif;
?>
</table>
<?php echo h($wDesc->input()); ?>
<?php echo dossier::hidden(); ?>
<?php echo HtmlInput::hidden('act','save') ?>
<?php echo HtmlInput::hidden('id',$this->tl_id) ?>
<p style='text-align: center'>
<input type="submit" class="smallbutton" value="<?php echo _('Sauve');?>" onclick="todo_list_save(<?php echo $this->tl_id?>);return false">
</p>
</form>

View file

@ -0,0 +1,78 @@
<?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 display all the user for the todo_list.
* @see Todo_List::display_user
* @param $p_array array of user who can access this folder
* @param Object Todo_List
* @param $dossier = Dossier::id()
*
*/
echo _('Filtre')." ".HtmlInput::filter_table("todo_user_table", "0,1,2", 1);
?>
<table id="todo_user_table<?php echo $this->tl_id?>" class="result">
<tr>
<th>
<?php echo _('Login')?>
</th>
<th>
<?php echo _('Nom ')?>
</th>
<th>
<?php echo _('Prénom')?>
</th>
<th>
</th>
<?php
$max=count($p_array);
for ($i=0;$i<$max;$i++):
if ($p_array[$i]["use_login"]==$g_user->login) :
continue;
endif;
?>
<tr>
<td>
<?php echo $p_array[$i]['use_login'];?>
</td>
<td>
<?php echo $p_array[$i]['use_name'];?>
</td>
<td>
<?php echo $p_array[$i]['use_first_name'];?>
</td>
<td>
<?php
$check=new ICheckBox('use_login'.$p_array[$i]['use_login']."_".$this->tl_id);
if ($this->is_shared_with($p_array[$i]['use_login']) != 0) {
$check->selected=true;
}
$check->javascript=" onclick=\"todo_list_set_share({$this->tl_id},'{$p_array[$i]['use_login']}','{$dossier}')\"";
echo $check->input();
?>
</td>
</tr>
<?php endfor; ?>
</tr>
</table>