diff --git a/html/ajax_todo_list.php b/html/ajax_todo_list.php index 3e2e864cf..0f99d5f39 100644 --- a/html/ajax_todo_list.php +++ b/html/ajax_todo_list.php @@ -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 (''); - 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(); +} + diff --git a/html/js/todo_list.js b/html/js/todo_list.js index 6c2c88388..b8b1f9631 100644 --- a/html/js/todo_list.js +++ b/html/js/todo_list.js @@ -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; +} \ No newline at end of file diff --git a/html/style-classic.css b/html/style-classic.css index 52bfcc8f3..73ebd6734 100644 --- a/html/style-classic.css +++ b/html/style-classic.css @@ -973,7 +973,7 @@ div.topmenu { font-variant:small-caps; } /* */ -#add_todo_list { +#add_todo_list , div.add_todo_list { border:1px solid #0000FF; background-color:#DDE6FF; padding:0.07%; diff --git a/include/class_todo_list.php b/include/class_todo_list.php index 119cc30b1..7f494faaf 100644 --- a/include/class_todo_list.php +++ b/include/class_todo_list.php @@ -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=''.$id.$title.$desc.$date.''; 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 = '