noalyss Version-9
ajax_todo_list.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief handle the ajax request for the todo_list (delete, update
24 * and insert)
25 * for add, needed parameters
26 * - gDossier
27 * - d date,
28 * - t title
29 * - de description
30 * for update, same as ADD +
31 * - i id
32 * for delete
33 * - gDossier
34 * - i id
35 */
36if ( ! defined ('ALLOWED') ) die (_('Aucun accès direct'));
37mb_internal_encoding("UTF-8");
39
41global $g_user;
43$g_user->check(true);
44$g_user->check_dossier(Dossier::id(),true);
46
47////////////////////////////////////////////////////////////////////////////////
48// Display the note
49////////////////////////////////////////////////////////////////////////////////
50if (isset($_REQUEST['show']))
51{
53 $todo=new Todo_list($cn);
54 $id=$http->request("id");
55 $todo->set_parameter('id',$id);
56 $todo->load();
57 $content=$todo->display();
58 header('Content-type: text/xml; charset=UTF-8');
59 $dom=new DOMDocument('1.0','UTF-8');
60 $tl_id=$dom->createElement('tl_id',$todo->get_parameter('id'));
61 $tl_content=$dom->createElement('tl_content',$content);
62
63
64 $root=$dom->createElement("root");
65
66 $root->appendChild($tl_id);
67 $root->appendChild($tl_content);
68 $dom->appendChild($root);
69
70 echo $dom->saveXML();
71 exit();
72}
73////////////////////////////////////////////////////////////////////////////////
74// Delete the note
75////////////////////////////////////////////////////////////////////////////////
76if (isset($_REQUEST['del']))
77{
78 $id=$http->request("id");
80 $todo=new Todo_list($cn);
81 $todo->set_parameter('id',$id);
82 $todo->delete();
83 exit();
84}
85$ac=$http->get('act', "string",'save');
86
87////////////////////////////////////////////////////////////////////////////////
88// Save the modification of a note
89////////////////////////////////////////////////////////////////////////////////
90if ($ac == 'save')
91{
92
94 $todo=new Todo_List($cn);
95 $id=$http->post("id","string", 0);
96 $todo->set_parameter("id",$id);
97 if ($id <> 0 ) { $todo->load(); }
98 else
99 {
100 $todo->set_parameter("owner", $_SESSION[SESSION_KEY.'g_user']);
101 }
102
103 $todo->set_parameter("date",$http->post("p_date_todo","string", ""));
104 $todo->set_parameter("title", $http->post("p_title","string", ""));
105 $todo->set_parameter("desc", $http->post("p_desc","string", ""));
106 $todo->set_is_public($http->post("p_public", "string","N"));
107
108 ob_start();
109 if ( $todo->get_parameter('owner') == $_SESSION[SESSION_KEY.'g_user'] ) $todo->save();
110 ob_end_clean();
111 $dom=new DOMDocument('1.0','UTF-8');
112
113 if ($todo->get_parameter("id")==0)
114 {
115 $tl_id=$dom->createElement('tl_id', 0);
116 $tl_content=$dom->createElement('row','');
117 $root=$dom->createElement("root");
118 $todo_class=$todo->get_class();
119 $todo_class=($todo_class=="")?' odd ':$todo_class;
120 $class=$dom->createElement("style", $todo_class);
121 }
122 else
123 {
124 $todo->load();
125 $tl_id=$dom->createElement('tl_id', $todo->get_parameter('id'));
126 $tl_content=$dom->createElement('row',$todo->display_row('class="odd"', 'N'));
127 $root=$dom->createElement("root");
128 $todo_class=$todo->get_class();
129 $todo_class=($todo_class=="")?' odd ':$todo_class;
130 $class=$dom->createElement("style", $todo_class);
131 }
132 header('Content-type: text/xml; charset=UTF-8');
133
134
135
136 $root->appendChild($tl_id);
137 $root->appendChild($tl_content);
138 $root->appendChild($class);
139 $dom->appendChild($root);
140
141 echo $dom->saveXML();
142 exit();
143}
144
145////////////////////////////////////////////////////////////////////////////////
146// Display a list to select the user with who we want to share notes
147////////////////////////////////////////////////////////////////////////////////
148if ($ac=='shared_note')
149{
150 $id=$http->get("todo_id", "string",-1);
151 // If note_id is not correct then give an error
152 if ($id==-1||isNumber($id)==0)
153 {
154 header('Content-type: text/xml; charset=UTF-8');
155 $dom=new DOMDocument('1.0', 'UTF-8');
156 $tl_id=$dom->createElement('content', _("Erreur : note invalide"));
157 $dom->appendChild($tl_id);
158 echo $dom->saveXML();
159 return;
160 }
161 if ($id==0)
162 {
163 ob_start();
164 echo HtmlInput::title_box(_('Liste utilisateurs'), "shared_{$id}");
165 echo '<p class="notice">';
166 echo _("Vous devez d'abord sauver");
167 echo '</p>';
168 echo '<p style="text-align:center">';
169 echo HtmlInput::submit('close'.$id, 'Ferme'," onclick=\"\$('shared_{$id}').remove();\"");
170 echo '</p>';
171 $result=ob_get_clean();
172 //
173 // output the XML
174 header('Content-type: text/xml; charset=UTF-8');
175 $dom=new DOMDocument('1.0', 'UTF-8');
176 $tl_id=$dom->createElement('content', escape_xml($result));
177 $dom->appendChild($tl_id);
178 echo $dom->saveXML();
179 return;
180 }
181 $todo=new Todo_List($cn);
182 $todo->set_parameter("id", $id);
183 $todo->load();
184 if ($g_user->login!=$todo->get_parameter("owner"))
185 {
186 header('Content-type: text/xml; charset=UTF-8');
187 $dom=new DOMDocument('1.0', 'UTF-8');
188 $tl_id=$dom->createElement('content', _("Cette note n'est pas à vous").
189 Icon_Action::close('shared_'.$id));
190 $dom->appendChild($tl_id);
191 echo $dom->saveXML();
192 return;
193 }
194 if ($g_user->check_action(SHARENOTE)== 0)
195 {
196 header('Content-type: text/xml; charset=UTF-8');
197 $dom=new DOMDocument('1.0', 'UTF-8');
198 $tl_id=$dom->createElement('content', _("Accès interdit"));
199 $dom->appendChild($tl_id);
200 echo $dom->saveXML();
201 return;
202 }
203 ob_start();
204 echo HtmlInput::title_box(_('Liste utilisateurs'), "shared_".$id);
205 $todo->display_user();
206 echo '<p style="text-align:center">';
207 echo HtmlInput::submit('close'.$id, 'Ferme'," onclick=\"\$('shared_{$id}').remove();\"");
208 echo '</p>';
209 $result=ob_get_clean();
210 //
211 // output the XML
212 header('Content-type: text/xml; charset=UTF-8');
213 $dom=new DOMDocument('1.0', 'UTF-8');
214 $tl_id=$dom->createElement('content', escape_xml($result));
215 $dom->appendChild($tl_id);
216 echo $dom->saveXML();
217 return;
218}
219////////////////////////////////////////////////////////////////////////////////
220// Share the note with someone or remove it
221////////////////////////////////////////////////////////////////////////////////
222if ( $ac=="set_share")
223{
224 $id=$http->get("todo_id", "string",0);
225 $p_login=$http->get("login","string","");
226 // If note_id is not correct then give an error
227 if ($id==0||isNumber($id)==0 || trim ($p_login)=="")
228 {
229 header('Content-type: text/xml; charset=UTF-8');
230 $dom=new DOMDocument('1.0', 'UTF-8');
231 $tl_id=$dom->createElement('content', _("Erreur : paramètre invalide"));
232 $dom->appendChild($tl_id);
233 echo $dom->saveXML();
234 return;
235 }
236 $todo=new Todo_List($cn);
237 $todo->set_parameter("id", $id);
238 $todo->load();
239 if ($g_user->login!=$todo->get_parameter("owner"))
240 {
241 header('Content-type: text/xml; charset=UTF-8');
242 $dom=new DOMDocument('1.0', 'UTF-8');
243 $tl_id=$dom->createElement('content', _("Cette note n'est pas à vous"));
244 $dom->appendChild($tl_id);
245 echo $dom->saveXML();
246 return;
247 }
248 if ($g_user->login!=$todo->get_parameter("owner"))
249 {
250 header('Content-type: text/xml; charset=UTF-8');
251 $dom=new DOMDocument('1.0', 'UTF-8');
252 $tl_id=$dom->createElement('content', _("Cette note n'est pas à vous"));
253 $dom->appendChild($tl_id);
254 echo $dom->saveXML();
255 return;
256 }
257 if ($g_user->check_action(SHARENOTE)== 0)
258 {
259 header('Content-type: text/xml; charset=UTF-8');
260 $dom=new DOMDocument('1.0', 'UTF-8');
261 $tl_id=$dom->createElement('content', _("Accès interdit"));
262 $dom->appendChild($tl_id);
263 echo $dom->saveXML();
264 return;
265 }
266 if ( $todo->is_shared_with($p_login) == 0 )
267 {
268 // Add a share to the user
269 $todo->add_share($p_login);
270
271 } else {
272 // remove a share from the user
273 $todo->remove_share($p_login);
274 }
275}
276////////////////////////////////////////////////////////////////////////////////
277// Remove the share of a note which the connected user doesn't own
278//
279////////////////////////////////////////////////////////////////////////////////
280if ( $ac=="remove_share")
281{
282 $id=$http->get("todo_id","string", 0);
283 $p_login=$http->get("login","string","");
284 // If note_id is not correct then give an error
285 if ($id==0||isNumber($id)==0 || trim ($p_login)=="")
286 {
287 header('Content-type: text/xml; charset=UTF-8');
288 $dom=new DOMDocument('1.0', 'UTF-8');
289 $status=$dom->createElement('status', "nok");
290 $tl_id=$dom->createElement('content', _("Erreur : paramètre invalide"));
291 $dom->appendChild($status);
292 $dom->appendChild($tl_id);
293 echo $dom->saveXML();
294 return;
295 }
296 $todo=new Todo_List($cn);
297 $todo->set_parameter("id", $id);
298 $todo->load();
299 $todo->remove_share($p_login);
300
301 header('Content-type: text/xml; charset=UTF-8');
302 $dom=new DOMDocument('1.0', 'UTF-8');
303 $status=$dom->createElement('status', "ok");
304 $dom->appendChild($status);
305 echo $dom->saveXML();
306 return;
307}
isNumber($p_int)
Definition: ac_common.php:215
set_language()
set the lang thanks the _SESSION['g_lang'] var.
Definition: ac_common.php:754
$_REQUEST['ac']
global $g_user
if(isset( $_REQUEST[ 'show'])) if(isset($_REQUEST['del'])) $ac
$class
static id()
return the 'gDossier' value after a check
static connect()
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
static close($p_div)
Return a html string with an anchor which close the inside popup.
Data & function about connected users.
This class manages the table todo_list.
const SHARENOTE
$todo
Definition: dashboard.php:18
for($e=0; $e< count($afiche); $e++) exit
escape_xml($p_xml)
When data are transfered thanks ajax in a xml document, the xml can not contains some character,...
$dom
Definition: xml.php:15
$content
Definition: xml.php:17