noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
todo_list.class.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 the todo list is managed by this class
24 */
25
26require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
27
28/*!\brief
29 * This class manages the table todo_list
30 *
31 *
32 * Data Member :
33 * - $cn database connx
34 * - $variable
35 * - id (todo_list.tl_id)
36 * - date (todo_list.tl_Date)
37 * - title (todo_list.title)
38 * - desc (todo_list.tl_desc)
39 * - owner (todo_list.use_id)
40 *
41 */
43{
44
45 private static $variable=array(
46 "id"=>"tl_id",
47 "date"=>"tl_date",
48 "title"=>"tl_title",
49 "desc"=>"tl_desc",
50 "owner"=>"use_login",
51 "is_public"=>"is_public");
52 private $cn;
55 function __construct ($p_init)
56 {
57 $this->cn=$p_init;
58 $this->tl_id=0;
59 $this->tl_desc="";
60 $this->use_login=$_SESSION[SESSION_KEY.'g_user'];
61 $this->is_public="N";
62
63 }
64 public function get_parameter($p_string)
65 {
66 if ( array_key_exists($p_string,self::$variable) )
67 {
68 $idx=self::$variable[$p_string];
69 return $this->$idx;
70 }
71 else
72 throw new Exception("Attribut inexistant $p_string");
73 }
74 public function check($p_idx,&$p_value)
75 {
76 if ( strcmp ($p_idx, 'tl_id') == 0 )
77 {
78 if ( strlen($p_value) > 6 || isNumber ($p_value) == false) return false;
79 }
80 if ( strcmp ($p_idx, 'tl_date') == 0 )
81 {
82 if ( noalyss_strlentrim($p_value) ==0 ||strlen($p_value) > 12 || isDate ($p_value) == false)
83 { $p_value = null;return true;}
84 }
85 if ( strcmp ($p_idx, 'tl_title') == 0 )
86 {
87 $p_value=mb_substr($p_value,0,120) ;
88 return true;
89 }
90 if ( strcmp ($p_idx, 'tl_desc') == 0 )
91 {
92 $p_value=mb_substr($p_value,0,1000) ;
93 return true;
94 }
95 return true;
96 }
97 public function set_parameter($p_string,$p_value)
98 {
99 if ( array_key_exists($p_string,self::$variable) )
100 {
101 $idx=self::$variable[$p_string];
102 if ($this->check($idx,$p_value) == true ) $this->$idx=$p_value;
103 }
104 else
105 throw new Exception("Attribut inexistant $p_string");
106
107
108 }
109 public function get_info()
110 {
111 return var_export(self::$variable,true);
112 }
113 public function verify()
114 {
115 if ( isDate($this->tl_date) == false )
116 {
117 $this->tl_date=null;
118 }
119 return 0;
120 }
121 public function save()
122 {
123 if ( $this->get_parameter("id") == 0 )
124 $this->insert();
125 else
126 $this->update();
127 }
128
129 public function insert()
130 {
131 if ( $this->verify() != 0 ) return;
132 if (trim($this->tl_title)=='')
133 $this->tl_title=mb_substr(trim($this->tl_desc??""),0,30);
134
135 if (trim($this->tl_title)=='')
136 {
137 alert('La note est vide');
138 return;
139 }
140
141 /* limit the title to 35 char */
142 $this->tl_title=mb_substr(trim($this->tl_title),0,30);
143
144 $sql="insert into todo_list (tl_date,tl_title,tl_desc,use_login,is_public) ".
145 " values (to_date($1,'DD.MM.YYYY'),$2,$3,$4,$5) returning tl_id";
146
147 if ($this->tl_date == null) {
148 $sql="insert into todo_list (tl_date,tl_title,tl_desc,use_login,is_public) ".
149 " values ($1,$2,$3,$4,$5) returning tl_id";
150
151 }
152 $res=$this->cn->exec_sql(
153 $sql,
154 array($this->tl_date,
155 $this->tl_title,
156 $this->tl_desc,
157 $this->use_login,
158 $this->is_public)
159 );
160 $this->tl_id=Database::fetch_result($res,0,0);
161
162 }
163
164 public function update()
165 {
166 if ( $this->verify() != 0 ) return;
167
168 if (trim($this->tl_title)=='')
169 $this->tl_title=mb_substr(trim($this->tl_desc),0,40);
170
171 if (trim($this->tl_title)=='')
172 {
173
174 return;
175 }
176
177 /* limit the title to 35 char */
178 $this->tl_title=mb_substr(trim($this->tl_title),0,40);
179
180 $sql="update todo_list set tl_title=$1,tl_date=to_date($2,'DD.MM.YYYY'),tl_desc=$3,is_public=$5 ".
181 " where tl_id = $4";
182
183 if ($this->tl_date == null) {
184 $sql="update todo_list set tl_title=$1,tl_date=$2,tl_desc=$3,is_public=$5 ".
185 " where tl_id = $4";
186 }
187 $res=$this->cn->exec_sql(
188 $sql,
189 array($this->tl_title,
190 $this->tl_date,
191 $this->tl_desc,
192 $this->tl_id,
193 $this->is_public)
194 );
195
196 }
197 /*!\brief load all the task
198 *\return an array of the existing tasks of the current user
199 */
200 public function load_all()
201 {
202 $sql="select tl_id,
203 tl_title,
204 tl_desc,
205 to_char( tl_date,'DD.MM.YYYY') as tl_date,
206 is_public,
207 use_login
208 from todo_list
209 where
210 use_login=$1
211 or is_public = 'Y'
212 or tl_id in (select todo_list_id from todo_list_shared where use_login=$1)
213 order by tl_date::date desc";
214 $res=$this->cn->exec_sql(
215 $sql,
216 array($this->use_login));
218
219 return $array;
220 }
221 /**
222 * @brief load the todo_list row thanks it's ID
223 * @return boolean true if found else false
224 */
225 public function load():bool
226 {
227
228 $sql="select tl_id,tl_title,tl_desc,to_char( tl_date,'DD.MM.YYYY') as tl_date,is_public,use_login
229 from todo_list where tl_id=$1 ";
230
231 $res=$this->cn->exec_sql(
232 $sql,
233 array($this->tl_id)
234 );
235
236 if ( Database::num_row($res) == 0 ) return false;
238 $aIndex=array_values(self::$variable);
239 foreach ($aIndex as $idx)
240 {
241 $this->$idx=$row[$idx];
242 }
243 return true;
244 }
245 public function delete()
246 {
247 global $g_user;
248 if ( $this->use_login != $_SESSION[SESSION_KEY.'g_user'] && $g_user->check_action(SHARENOTEREMOVE)==0) return;
249
250 $sql="delete from todo_list_shared where todo_list_id=$1 ";
251 $res=$this->cn->exec_sql($sql,array($this->tl_id));
252
253 $sql="delete from todo_list where tl_id=$1 ";
254 $res=$this->cn->exec_sql($sql,array($this->tl_id));
255
256
257
258 }
259 /**
260 *@brief transform into xml for ajax answer
261 */
262 public function toXML()
263 {
264 $id='<tl_id>'.$this->tl_id.'</tl_id>';
265 $title='<tl_title>'.escape_xml($this->tl_title).'</tl_title>';
266 $desc='<tl_desc>'.escape_xml($this->tl_desc).'</tl_desc>';
267 $date='<tl_date>'.$this->tl_date.'</tl_date>';
268 $ret='<data>'.$id.$title.$desc.$date.'</data>';
269 return $ret;
270 }
271 /**
272 * @brief set a note public
273 * @param $p_value is Y or N
274 */
275 public function set_is_public($p_value)
276 {
277 global $g_user;
278 if ($g_user->check_action(SHARENOTEPUBLIC) == 1 )
279 {
280 $this->is_public=$p_value;
281 }
282 }
283 /**
284 * @brief Insert a share for current note
285 * in the table todo_list_shared
286 * @param string (use_login)
287 */
288 public function save_shared_with($p_array)
289 {
290 global $g_user;
291 if ($g_user->check_action(SHARENOTE) == 1 )
292 {
293 $this->cn->exec_sql('insert into todo_list_shared (todo_list_id,use_login) values ($1,$2)',
294 array($this->tl_id,$p_array));
295
296 }
297 }
298 /**
299 * @brief Insert a share for current note
300 * in the table todo_list_shared
301 * The public shared note cannot be removed
302 * @param string (use_login)
303 */
305 {
306 $this->cn->exec_sql('delete from todo_list_shared where todo_list_id = $1 and use_login=$2',
307 array($this->tl_id,$p_array));
308 }
309
310 /**
311 * @brief Display the note
312 * @return html string
313 */
314 function display()
315 {
316 ob_start();
317 $this->load();
318 include NOALYSS_TEMPLATE.'/todo_list_display.php';
319 $ret=ob_get_clean();
320
321 return $ret;
322 }
323 /**
324 * Highlight today
325 * @return string
326 */
327 function get_class()
328 {
329 $p_odd="";
330 $a=date('d.m.Y');
331 if ($a == $this->tl_date) $p_odd='highlight';
332 return $p_odd;
333 }
334 function display_row($p_odd,$with_tag='Y')
335 {
336 $r="";
337 $highlight=$this->get_class();
338 $p_odd=($highlight == "")?$p_odd:$highlight;
339 if ( $with_tag == 'Y') $r = '<tr id="tr'.$this->tl_id.'" class="'.$p_odd.'">';
340 $r.=
341 '<td sorttable_customkey="'.format_date($this->tl_date,'DD.MM.YYYY','YYYYMMDD').'">'.
342 $this->tl_date.
343 '</td>'.
344 '<td>'.
345 '<a class="line" href="javascript:void(0)" onclick="todo_list_show(\''.$this->tl_id.'\')">'.
346 htmlspecialchars($this->tl_title).
347 '</a>'.
348 '</td>';
349 if ( $this->is_public == 'Y' && $this->use_login != $_SESSION[SESSION_KEY.'g_user'] )
350 { // This is a public note, cannot be removed
351 $r.= '<td></td>';
352 }
353 elseif ($this->use_login == $_SESSION[SESSION_KEY.'g_user'] )
354 {
355 // This a note the user owns
356 $r.= '<td>'.
357 Icon_Action::trash(uniqid(),sprintf("todo_list_remove('%s')",$this->tl_id)).
358 '</td>';
359 }
360 else
361 {
362 // this is a note shared by someone else
363 $r.= '<td>'.
364 Icon_Action::trash(uniqid(),sprintf("todo_list_remove_share('%s','%s','%s')",$this->tl_id,$this->use_login,Dossier::id())).
365 '</td>';
366 }
367
368 if ( $with_tag == 'Y') $r .= '</tr>';
369 return $r;
370 }
371 static function to_object ($p_cn,$p_array)
372 {
373
374 $ret=array();
375 if ( $p_array == FALSE ) return $ret;
376 $end=count($p_array);
377 for ($i=0;$i < $end;$i++)
378 {
379 $t=new Todo_List($p_cn);
380 $t->tl_id=$p_array[$i]['tl_id'];
381 $t->tl_date=$p_array[$i]['tl_date'];
382 $t->tl_title=$p_array[$i]['tl_title'];
383 $t->tl_desc=$p_array[$i]['tl_desc'];
384 $t->is_public=$p_array[$i]['is_public'];
385 $t->use_login=$p_array[$i]['use_login'];
386 $ret[$i]=clone $t;
387 }
388 return $ret;
389 }
390 /**
391 * @brief display all the user to select the user with who we want to share
392 * the connected user is not shown
393 * @global type $g_user
394 */
395 function display_user()
396 {
397 global $g_user;
398 // Get array of user
399 $p_array=Noalyss_User::get_list(Dossier::id());
400 $dossier=Dossier::id();
401 include NOALYSS_TEMPLATE.'/todo_list_list_user.php';
402
403 }
404 /**
405 * return the todo_list_shared.id of the note, if nothing is found then
406 * return 0
407 * @param $p_login
408 * @return int
409 */
410 function is_shared_with($p_login)
411 {
412 $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));
413 if ($ret == "")return 0;
414 return $ret;
415 }
416 /**
417 * @brief Add a share with someone
418 * @param type $p_login
419 */
420 function add_share($p_login)
421 {
422 $this->cn->exec_sql("insert into todo_list_shared(todo_list_id,use_login) values ($1,$2)",array($this->tl_id,$p_login));
423 }
424 /**
425 * @brief remove the share with someone
426 * @param type $p_login
427 */
428 function remove_share($p_login)
429 {
430 $this->cn->exec_sql("delete from todo_list_shared where todo_list_id = $1 and use_login = $2 ",array($this->tl_id,$p_login));
431 }
432 /*!\brief static testing function
433 */
434 static function test_me()
435 {
436 }
437
438}
439
440
isNumber($p_int)
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
noalyss_strlentrim($p_string)
alert($p_msg, $buffer=false)
alert in javascript
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$anc_grandlivre from
$input_from cn
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
This class manages the table todo_list.
display()
Display the note.
save_shared_with($p_array)
Insert a share for current note in the table todo_list_shared.
load_all()
load all the task
load()
load the todo_list row thanks it's ID
display_row($p_odd, $with_tag='Y')
get_class()
Highlight today.
__construct($p_init)
remove_shared_with($p_array)
Insert a share for current note in the table todo_list_shared The public shared note cannot be remove...
set_parameter($p_string, $p_value)
check($p_idx, &$p_value)
get_parameter($p_string)
set_is_public($p_value)
set a note public
toXML()
transform into xml for ajax answer
const SHARENOTEREMOVE
const SHARENOTEPUBLIC
const SHARENOTE