diff --git a/html/ajax_misc.php b/html/ajax_misc.php index ec952b526..815427e5f 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -724,6 +724,14 @@ EOF; case 'action_show': require_once NOALYSS_INCLUDE.'/ajax_gestion.php'; break; + // From dashboard, display form for a new event + case 'action_add': + require_once NOALYSS_INCLUDE.'/ajax_gestion.php'; + break; + // Save a event given in the short form + case 'action_save': + require_once NOALYSS_INCLUDE.'/ajax_gestion.php'; + break; default: var_dump($_GET); } diff --git a/html/js/gestion.js b/html/js/gestion.js index 27b0da271..4cc9760b1 100644 --- a/html/js/gestion.js +++ b/html/js/gestion.js @@ -280,7 +280,7 @@ function action_show(p_dossier) parameters : {gDossier:p_dossier,'op':'action_show'}, onSuccess : function(p_xml, p_text) { remove_waiting_box(); - add_div({id: 'action_list_div', style:"top:1%;width:90%;margin-left:5%" , cssclass: 'inner_box'}); + add_div({id: 'action_list_div', style:"top:1%;width:90%;left:5%" , cssclass: 'inner_box'}); $('action_list_div').innerHTML=p_xml.responseText; } }); @@ -288,4 +288,98 @@ function action_show(p_dossier) { alert('action_show '+e.message); } +} +/** + * @brief add a new event + * @param {type} p_dossier + * @returns {undefined} + */ +function action_add(p_dossier) { + try { + if ( $('action_add_div')) { + alert('Désolé, événement en cours de création à sauver'); + return; + } + waiting_box(); + var action = new Ajax.Request('ajax_misc.php', + { + method:'get', + parameters : {gDossier:p_dossier,'op':'action_add'}, + onSuccess : function(p_xml, p_text) { + remove_waiting_box(); + add_div({id: 'action_add_div', + style:"top:1%;width:80%;left:10%" , + cssclass: 'inner_box'}); + $('action_add_div').innerHTML=p_xml.responseText; + p_xml.responseText.evalScripts(); + } + }); + } catch (e) + { + alert('action_add '+e.message); + } +} +/** + * @brief The new event is entered into the div action_add_div, we try + * to save and receive as answer a XML file with a code of success and possibly + * a message + * If the message is OK then the div is fading out, otherwise the reason of + * failure is shown and the div remains + */ +function action_save_short() +{ + try { + $('action_add_frm_info').innerHTML=""; + $('action_add_frm')['date_event_action_short'].parentNode.className=""; + $('action_add_frm')['title_event'].parentNode.className=""; + $('action_add_frm')['type_event'].parentNode.className=""; + + if ( $('action_add_frm')['date_event_action_short'].value.trim() == '') { + $('action_add_frm')['date_event_action_short'].parentNode.className="notice"; + return false; + } + + if ( $('action_add_frm')['title_event'].value.trim()=="") { + $('action_add_frm')['title_event'].parentNode.className="notice"; + return false; + } + + if ( $('action_add_frm')['type_event'].options[$('action_add_frm')['type_event'].selectedIndex].value == -1 ) + { + $('action_add_frm')['type_event'].parentNode.className="notice"; + return false; + } + var form=$('action_add_frm').serialize(); + waiting_box(); + var action = new Ajax.Request('ajax_misc.php', + { + method: 'get', + parameters: form, + onSuccess: function (p_xml, p_text) { + remove_waiting_box(); + var answer=p_xml.responseXML; + var code_tags=answer.getElementsByTagName('status'); + var code=getNodeText(code_tags[0]); + var message_tags=answer.getElementsByTagName('content'); + var message=getNodeText(message_tags[0]); + + if ( code == 'OK') { + // Successfully saved + $('action_add_frm_info').innerHTML=message; + $('action_add_div').remove(); + + } + else if (code == 'NOK') { + // issue while saving + $('action_add_frm_info').innerHTML=message; + } + + + } + }); + } catch (e) + { + alert('action_add ' + e.message); + } + return false; } \ No newline at end of file diff --git a/include/ajax_gestion.php b/include/ajax_gestion.php index f5be0a840..67aee1fd0 100644 --- a/include/ajax_gestion.php +++ b/include/ajax_gestion.php @@ -1,4 +1,5 @@ get_last(25); $len_array=count($array); require_once NOALYSS_INCLUDE.'/template/action_show.php'; + return; +} +if ($op=='action_add') +{ + require_once NOALYSS_INCLUDE.'/class_follow_up.php'; + $gestion=new Follow_Up($cn); + $gestion->display_short(); + return; +} +if ($op=='action_save') +{ + require_once NOALYSS_INCLUDE.'/class_follow_up.php'; + + /** + * save info from the get + */ + $date_event=HtmlInput::default_value_get("date_event", -1); + $dest=HtmlInput::default_value_get("dest", ""); + $event_group=HtmlInput::default_value_get("event_group", 0); + $event_priority=HtmlInput::default_value_get("event_priority", 0); + $title=HtmlInput::default_value_get("title_event", NULL); + $summary=HtmlInput::default_value_get("summary", ""); + $type_event=HtmlInput::default_value_get('type_event', -1); + /* + * Check if data are valid + */ + try + { + if ($date_event==-1||isDate($date_event)==0) + throw new Exception(_('Date invalide')); + if (trim($dest)=="") + $dest_id=NULL; + else + { + $fiche=new Fiche($cn); + $fiche->get_by_qcode($dest); + $dest_id=$fiche->id; + if ($dest_id==0) + throw new Exception(_('Destinataire invalide')); + } + if ($type_event==-1) + throw new Exception(_('Type invalide')); + if (trim($title)=="") + throw new Exception(_('Aucun titre')); + } + catch (Exception $ex) + { + header('Content-type: text/xml; charset=UTF-8'); + $dom=new DOMDocument('1.0', 'UTF-8'); + $xml_content=$dom->createElement('content', $ex->getMessage()); + $xml_status=$dom->createElement('status', "NOK"); + $root=$dom->createElement("root"); + $root->appendChild($xml_content); + $root->appendChild($xml_status); + $dom->appendChild($root); + echo $dom->saveXML(); + return; + } + /* + * Save data + */ + $gestion=new Follow_Up($cn); + $gestion->ag_priority=$event_priority; + $gestion->ag_title=$title; + $gestion->ag_dest=$event_group; + $gestion->ag_type=$type_event; + $gestion->f_id_dest=$dest_id; + $gestion->ag_state=3; + $gestion->dt_id=$type_event; + $gestion->ag_comment=h($summary); + $gestion->ag_timestamp=$date_event; + $gestion->save_short(); + header('Content-type: text/xml; charset=UTF-8'); + $dom=new DOMDocument('1.0', 'UTF-8'); + $xml_content=$dom->createElement('content', _("Sauvé")); + $xml_status=$dom->createElement('status', "OK"); + $root=$dom->createElement("root"); + $root->appendChild($xml_content); + $root->appendChild($xml_status); + $dom->appendChild($root); + echo $dom->saveXML(); + return; } \ No newline at end of file diff --git a/include/ajax_get_profile.php b/include/ajax_get_profile.php index 5e6c91c9c..c33a67e84 100644 --- a/include/ajax_get_profile.php +++ b/include/ajax_get_profile.php @@ -106,7 +106,7 @@ if ($profile->p_id > 0) echo $add_impression; echo ''; echo '
'; echo '