phpcompta-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpcompta-dev] r571 - in trunk/rapport_avance: . include include/templa


From: phpcompta-dev
Subject: [Phpcompta-dev] r571 - in trunk/rapport_avance: . include include/template
Date: Thu, 7 Nov 2013 15:04:33 +0100 (CET)

Author: danydb
Date: 2013-11-07 15:04:33 +0100 (Thu, 07 Nov 2013)
New Revision: 571

Added:
   trunk/rapport_avance/ajax_listing_modify.php
   trunk/rapport_avance/ajax_listing_remove_modele.php
Modified:
   trunk/rapport_avance/ajax.php
   trunk/rapport_avance/include/class_rapav_listing.php
   trunk/rapport_avance/include/liste.inc.php
   trunk/rapport_avance/include/template/rapav_listing_form_add.php
   trunk/rapport_avance/include/template/rapav_listing_to_list.php
   trunk/rapport_avance/rapav_javascript.js
Log:
Modify listing 

Modified: trunk/rapport_avance/ajax.php
===================================================================
--- trunk/rapport_avance/ajax.php       2013-11-07 13:01:40 UTC (rev 570)
+++ trunk/rapport_avance/ajax.php       2013-11-07 14:04:33 UTC (rev 571)
@@ -124,29 +124,15 @@
     
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // Show a div to enter new listing
     
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    case 'listing_add':
-        require_once 'include/class_rapav_listing.php';
-        ob_start();
-        echo HtmlInput::title_box("Ajout d'un listing", $cout);
-        echo '<form method="POST" enctype="multipart/form-data" 
id="listing_frm" onsubmit="return check_listing_add(\'listing_frm\')">';
-        echo 
HtmlInput::request_to_hidden(array('gDossier','ac','plugin_code'));
-        Rapav_Listing::form_add();
-        echo '<p>';
-        echo HtmlInput::submit("listing_add_sb", "Ajout");
-        echo '</p>';
-        echo '</form>';
-        $response = ob_get_clean();
-        ob_end_clean();
-        $html = escape_xml($response);
-        header('Content-type: text/xml; charset=UTF-8');
-        echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
+    case 'listing_modify':
+       include 'ajax_listing_modify.php';
         exit();
+    
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // Remove a document modele
+    
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    case 'listing_remove_modele':
+       include 'ajax_listing_remove_modele.php';
+        exit();
 
         break;
 }

Added: trunk/rapport_avance/ajax_listing_modify.php
===================================================================
--- trunk/rapport_avance/ajax_listing_modify.php                                
(rev 0)
+++ trunk/rapport_avance/ajax_listing_modify.php        2013-11-07 14:04:33 UTC 
(rev 571)
@@ -0,0 +1,30 @@
+<?php
+
+require_once 'include/class_rapav_listing.php';
+$obj=new Rapav_Listing($id);
+ob_start();
+if ( $id == -1 )
+    echo HtmlInput::title_box("Ajout d'un listing", $cout);
+else
+    echo HtmlInput::title_box("Modification d'un listing", $cout);
+
+echo '<form method="POST" enctype="multipart/form-data" id="listing_frm" 
onsubmit="return check_listing_add(\'listing_frm\')">';
+echo HtmlInput::hidden('l_id',$id);
+echo HtmlInput::request_to_hidden(array('gDossier', 'ac', 'plugin_code'));
+$obj->form_modify();
+echo '<p>';
+echo HtmlInput::submit("listing_add_sb", "Ajout");
+echo '</p>';
+echo '</form>';
+$response = ob_get_clean();
+ob_end_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+?>        
\ No newline at end of file

Added: trunk/rapport_avance/ajax_listing_remove_modele.php
===================================================================
--- trunk/rapport_avance/ajax_listing_remove_modele.php                         
(rev 0)
+++ trunk/rapport_avance/ajax_listing_remove_modele.php 2013-11-07 14:04:33 UTC 
(rev 571)
@@ -0,0 +1,20 @@
+<?php
+require_once 'include/class_rapav_listing.php';
+$obj=new Rapav_Listing($id);
+$obj->remove_modele();
+
+ob_start();
+$file=new IFile('listing_mod');
+echo $file->input();
+$response = ob_get_clean();
+ob_end_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>$cout</ctl>
+<code>$html</code>
+</data>
+EOF;
+?>
\ No newline at end of file

Modified: trunk/rapport_avance/include/class_rapav_listing.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_listing.php        2013-11-07 
13:01:40 UTC (rev 570)
+++ trunk/rapport_avance/include/class_rapav_listing.php        2013-11-07 
14:04:33 UTC (rev 571)
@@ -13,19 +13,16 @@
  */
 require_once 'class_rapport_avance_sql.php';
 
-class Rapav_Listing
-{
+class Rapav_Listing {
 
-    function __construct($p_id = -1)
-    {
+    function __construct($p_id = -1) {
         $this->Data = new RAPAV_Listing_SQL($p_id);
     }
 
     /**
      * display a list of the existing list
      */
-    function to_list()
-    {
+    function to_list() {
         $res = $this->Data->seek('join fiche_def using (fd_id) order by 
l_name');
         require 'template/rapav_listing_to_list.php';
     }
@@ -33,16 +30,15 @@
     /**
      * Display a button for adding a new listing
      */
-    static function Button_Add_Listing()
-    {
+    static function Button_Add_Listing() {
         $arg = array(
             'gDossier' => Dossier::id(),
             'ac' => $_REQUEST['ac'],
             'pc' => $_REQUEST['plugin_code'],
-            'id' => 0,
+            'id' => -1,
             'cin' => 'listing_tb_id',
             'cout' => 'listing_add_div');
-        $json = 'listing_add(' . str_replace('"', "'", json_encode($arg)) . 
')';
+        $json = 'listing_modify(' . str_replace('"', "'", json_encode($arg)) . 
')';
         echo HtmlInput::button_action("Ajout", $json);
     }
 
@@ -50,42 +46,63 @@
      * @brief display a form to save a new list
      * 
      */
-    static function form_add()
-    {
+    function form_modify() {
         global $cn;
         $name = new IText('name');
         $description = new ITextArea('description');
         $file = new IFile('listing_mod');
         $fichedef = new ISelect('fiche_def');
         $fichedef->value = $cn->make_array('select fd_id,fd_label from 
fiche_def order by fd_label');
+        $str_remove = "";
+        /*
+         * if $this->l_id <> -1 then modification otherwise add
+         */
+        if ($this->Data->l_id <> -1) {
+            $name->value = $this->Data->l_name;
+            $description->value = $this->Data->l_description;
+            $fichedef->selected = $this->Data->fd_id;
+            $ck = new ICheckBox('remove');
+            $str_remove = " Cochez pour effacer " . $ck->input();
+            // If there is a file
+            if ($this->Data->l_filename != "") {
+                $file = new ISpan('listing_mod_id');
+                // Add js for removing 
+                $arg = array(
+                    'gDossier' => Dossier::id(),
+                    'ac' => $_REQUEST['ac'],
+                    'pc' => $_REQUEST['plugin_code'],
+                    'id' => $this->Data->l_id,
+                    'cin' => '',
+                    'cout' => 'listing_mod_id');
+                $json = 'listing_remove_modele(' . str_replace('"', "'", 
json_encode($arg)) . ')';
+                $file->value = $this->Data->l_filename . HtmlInput::anchor(' 
<span style="background-color:red">X </span>', "", ' onclick="' . $json . '"');
+            }
+        }
         require 'template/rapav_listing_form_add.php';
     }
 
     /**
-     * Insert a new list into rapport_advanced.listing
+     * Insert or update a listing into rapport_advanced.listing, load also the
+     * file
      * @global type $cn
      * @param type $p_array
      * @throws Exception
      */
-    function insert($p_array)
-    {
+    function save($p_array) {
         global $cn;
-        try
-        {
+        try {
             $cn->start();
-            if (strlen(trim($p_array['name'])) == 0)
-            {
+            if (strlen(trim($p_array['name'])) == 0) {
                 throw new Exception('Le nom ne peut pas ĂȘtre vide');
             }
 
             $this->Data->setp('name', $p_array['name']);
             $this->Data->setp('description', $p_array['description']);
             $this->Data->setp('fiche_def_id', $p_array['fiche_def']);
-            $this->Data->insert();
+            $this->Data->save();
             $this->load_file();
             $cn->commit();
-        } catch (Exception $ex)
-        {
+        } catch (Exception $ex) {
             $cn->rollback();
         }
     }
@@ -95,26 +112,21 @@
      * @global type $cn
      * @return int
      */
-    function load_file()
-    {
+    function load_file() {
         global $cn;
         // nothing to save
         if (sizeof($_FILES) == 0)
             return;
-        try
-        {
+        try {
             $name = $_FILES['listing_mod']['name'];
             $new_name = tempnam($_ENV['TMP'], 'fiche_def');
             // check if a file is submitted
-            if (strlen($_FILES['listing_mod']['tmp_name']) != 0)
-            {
+            if (strlen($_FILES['listing_mod']['tmp_name']) != 0) {
                 // upload the file and move it to temp directory
-                if (move_uploaded_file($_FILES['listing_mod']['tmp_name'], 
$new_name))
-                {
+                if (move_uploaded_file($_FILES['listing_mod']['tmp_name'], 
$new_name)) {
                     $oid = $cn->lo_import($new_name);
                     // check if the lob is in the database
-                    if ($oid == false)
-                    {
+                    if ($oid == false) {
                         $cn->rollback();
                         return 1;
                     }
@@ -128,11 +140,29 @@
                 // update rapav
                 $this->Data->update();
             }
-        } catch (Exception $ex)
-        {
+        } catch (Exception $ex) {
             $cn->rollback();
             throw $ex;
         }
     }
 
+    function remove_modele() {
+        global $cn;
+        if ($this->Data->l_lob == null)
+            return;
+        $cn->start();
+        $this->Data->cn->lo_unlink($this->Data->l_lob);
+        $this->Data->l_filename = null;
+        $this->Data->l_lob = null;
+        $this->Data->l_size = null;
+        $this->Data->l_mimetype = null;
+        $this->Data->update();
+        $cn->commit();
+    }
+    function delete()
+    {
+        $this->remove_modele();
+        $this->Data->delete();
+    }
+
 }

Modified: trunk/rapport_avance/include/liste.inc.php
===================================================================
--- trunk/rapport_avance/include/liste.inc.php  2013-11-07 13:01:40 UTC (rev 
570)
+++ trunk/rapport_avance/include/liste.inc.php  2013-11-07 14:04:33 UTC (rev 
571)
@@ -13,8 +13,11 @@
  */
 if ( isset ($_POST['listing_add_sb']))
 {
-    $new=new Rapav_Listing();
-    $new->insert($_POST);
+    $new=new Rapav_Listing($_POST['l_id']);
+    if ( ! isset ($_POST['remove']))
+        $new->save($_POST);
+    else
+        $new->delete($_POST);
 }
 
 ///////////////////////////////////////////////////////////////////////////////

Modified: trunk/rapport_avance/include/template/rapav_listing_form_add.php
===================================================================
--- trunk/rapport_avance/include/template/rapav_listing_form_add.php    
2013-11-07 13:01:40 UTC (rev 570)
+++ trunk/rapport_avance/include/template/rapav_listing_form_add.php    
2013-11-07 14:04:33 UTC (rev 571)
@@ -36,4 +36,7 @@
         
     </tr>
 
-</table>
\ No newline at end of file
+</table>
+<?php
+echo $str_remove;
+?>
\ No newline at end of file

Modified: trunk/rapport_avance/include/template/rapav_listing_to_list.php
===================================================================
--- trunk/rapport_avance/include/template/rapav_listing_to_list.php     
2013-11-07 13:01:40 UTC (rev 570)
+++ trunk/rapport_avance/include/template/rapav_listing_to_list.php     
2013-11-07 14:04:33 UTC (rev 571)
@@ -16,10 +16,18 @@
     $max=Database::num_row($res);
     for ($i=0;$i<$max;$i++):
         $row=  Database::fetch_array($res, $i);
+        $arg = array(
+            'gDossier' => Dossier::id(),
+            'ac' => $_REQUEST['ac'],
+            'pc' => $_REQUEST['plugin_code'],
+            'id' => $row['l_id'],
+            'cin' => 'listing_tb_id',
+            'cout' => 'listing_mod_div');
+        $json = 'listing_modify(' . str_replace('"', "'", json_encode($arg)) . 
')';
     ?>
     <tr>
         <td>
-            <?php echo h($row['l_name']); ?>
+            <?php echo HtmlInput::anchor(h($row['l_name']),'',' 
onclick="'.$json.'"'); ?>
         </td>
         <td>
             <?php echo h($row['l_description']); ?>

Modified: trunk/rapport_avance/rapav_javascript.js
===================================================================
--- trunk/rapport_avance/rapav_javascript.js    2013-11-07 13:01:40 UTC (rev 
570)
+++ trunk/rapport_avance/rapav_javascript.js    2013-11-07 14:04:33 UTC (rev 
571)
@@ -439,11 +439,11 @@
  *    - cout the div to display
  *    
  */
-function listing_add(json)
+function listing_modify(json)
 {
     console.log(json)
     try {
-        var querystring = 'plugin_code=' + json.pc + '&ac=' + json.ac + 
'&gDossier=' + json.gDossier + '&act=listing_add' + "&cin=" + json.cin + 
'&cout=' + json.cout;
+        var querystring = 'plugin_code=' + json.pc + '&ac=' + json.ac + 
'&gDossier=' + json.gDossier + '&act=listing_modify' + "&cin=" + json.cin + 
'&cout=' + json.cout+'&id='+json.id;
         waiting_box();
         var action = new Ajax.Request(
                 "ajax.php",
@@ -493,4 +493,45 @@
         return false;
     }
     return true;
+}
+
+function listing_remove_modele(json)
+{
+    console.log(json)
+    try {
+        var querystring = 'plugin_code=' + json.pc + '&ac=' + json.ac + 
'&gDossier=' + json.gDossier + '&act=listing_remove_modele' + "&cin=" + 
json.cin + '&cout=' + json.cout+'&id='+json.id;
+        waiting_box();
+        var action = new Ajax.Request(
+                "ajax.php",
+                {
+                    method: 'get',
+                    parameters: querystring,
+                    onFailure: error_get_predef,
+                    onSuccess: function(req) {
+                        try {
+                            var answer = req.responseXML;
+                            var a = answer.getElementsByTagName('ctl');
+                            var html = answer.getElementsByTagName('code');
+                            if (a.length == 0) {
+                                var rec = req.responseText;
+                                throw 'cannot find ctl element';
+                            }
+                            remove_waiting_box();
+                            var code_html = getNodeText(html[0]); 
+                            code_html = unescape_xml(code_html);
+                             console.log(code_html);
+                           $(json.cout).innerHTML = code_html;
+                        } catch (e) {
+                            console.log(e);
+                            console.log(code_html);
+                        }
+                    }
+                }
+        );
+
+    } catch (e)
+    {
+        alert(e.message);
+
+    }
 }
\ No newline at end of file



---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]