diff --git a/html/ajax_todo_list.php b/html/ajax_todo_list.php index 0f99d5f39..3c4641e4b 100644 --- a/html/ajax_todo_list.php +++ b/html/ajax_todo_list.php @@ -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); + } +} \ No newline at end of file diff --git a/html/js/todo_list.js b/html/js/todo_list.js index ec6161b88..5ebcb0406 100644 --- a/html/js/todo_list.js +++ b/html/js/todo_list.js @@ -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(); + } + } + ) } \ No newline at end of file diff --git a/include/class_todo_list.php b/include/class_todo_list.php index a9af11a63..8af6ab4e1 100644 --- a/include/class_todo_list.php +++ b/include/class_todo_list.php @@ -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() diff --git a/include/template/todo_list_display.php b/include/template/todo_list_display.php index 82e36c916..adc7a429f 100644 --- a/include/template/todo_list_display.php +++ b/include/template/todo_list_display.php @@ -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); ?>
@@ -75,21 +75,29 @@ echo HtmlInput::title_box("Note","todo_list_div".$this->tl_id); + check_action(SHARENOTE)) : + ?> - Partage + tl_id},{$dossier}) \";")?> + input()); ?> tl_id) ?> - +

- +

\ No newline at end of file diff --git a/include/template/todo_list_list_user.php b/include/template/todo_list_list_user.php new file mode 100644 index 000000000..dee9eadae --- /dev/null +++ b/include/template/todo_list_list_user.php @@ -0,0 +1,78 @@ + +* +* 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); +?> + + + + + + + + login) : + continue; + endif; + ?> + + + + + + + + + +
+ + + + + + +
+ + + + + + + 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(); + ?> +
\ No newline at end of file