phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r566 - in trunk/rapport_avance: doc include include/temp


From: phpcompta-dev
Subject: [Phpcompta-dev] r566 - in trunk/rapport_avance: doc include include/template sql
Date: Wed, 6 Nov 2013 21:34:19 +0100 (CET)

Author: danydb
Date: 2013-11-06 21:34:19 +0100 (Wed, 06 Nov 2013)
New Revision: 566

Modified:
   trunk/rapport_avance/doc/listing-db.dia
   trunk/rapport_avance/include/class_rapav_listing.php
   trunk/rapport_avance/include/class_rapport_avance_sql.php
   trunk/rapport_avance/include/template/rapav_listing_to_list.php
   trunk/rapport_avance/sql/1-add-listing.sql
Log:
Add modele to save
Add column filename
Display in list the card category

Modified: trunk/rapport_avance/doc/listing-db.dia
===================================================================
(Binary files differ)

Modified: trunk/rapport_avance/include/class_rapav_listing.php
===================================================================
--- trunk/rapport_avance/include/class_rapav_listing.php        2013-11-06 
15:53:40 UTC (rev 565)
+++ trunk/rapport_avance/include/class_rapav_listing.php        2013-11-06 
20:34:19 UTC (rev 566)
@@ -12,36 +12,40 @@
  * @author dany
  */
 require_once 'class_rapport_avance_sql.php';
+
 class Rapav_Listing
 {
-    
-    function __construct($p_id=-1)
+
+    function __construct($p_id = -1)
     {
-        $this->Data=new RAPAV_Listing_SQL($p_id);
+        $this->Data = new RAPAV_Listing_SQL($p_id);
     }
+
     /**
      * display a list of the existing list
      */
     function to_list()
     {
-       $res= $this->Data->seek(' order by l_name');
-       require 'template/rapav_listing_to_list.php';
+        $res = $this->Data->seek('join fiche_def using (fd_id) order by 
l_name');
+        require 'template/rapav_listing_to_list.php';
     }
+
     /**
      * Display a button for adding a new listing
      */
     static function Button_Add_Listing()
     {
-        $arg=array(
-            'gDossier'=>Dossier::id(),
-            'ac'=>$_REQUEST['ac'],
-            'pc'=>$_REQUEST['plugin_code'],
-            'id'=>0,
-            'cin'=>'listing_tb_id',
-            'cout'=>'listing_add_div');
-        $json='listing_add('.str_replace('"',"'",json_encode($arg)).')';
+        $arg = array(
+            'gDossier' => Dossier::id(),
+            'ac' => $_REQUEST['ac'],
+            'pc' => $_REQUEST['plugin_code'],
+            'id' => 0,
+            'cin' => 'listing_tb_id',
+            'cout' => 'listing_add_div');
+        $json = 'listing_add(' . str_replace('"', "'", json_encode($arg)) . 
')';
         echo HtmlInput::button_action("Ajout", $json);
     }
+
     /**
      * @brief display a form to save a new list
      * 
@@ -49,22 +53,86 @@
     static function form_add()
     {
         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');
+        $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');
         require 'template/rapav_listing_form_add.php';
     }
+
+    /**
+     * Insert a new list into rapport_advanced.listing
+     * @global type $cn
+     * @param type $p_array
+     * @throws Exception
+     */
     function insert($p_array)
     {
-        if (strlen(trim($p_array['name']))==0) {
-            die ('Le nom ne peut pas être vide');
+        global $cn;
+        try
+        {
+            $cn->start();
+            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->load_file();
+            $cn->commit();
+        } catch (Exception $ex)
+        {
+            $cn->rollback();
         }
-        $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();
     }
-    
+
+    /**
+     * @brief 
+     * @global type $cn
+     * @return int
+     */
+    function load_file()
+    {
+        global $cn;
+        // nothing to save
+        if (sizeof($_FILES) == 0)
+            return;
+        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)
+            {
+                // upload the file and move it to temp directory
+                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)
+                    {
+                        $cn->rollback();
+                        return 1;
+                    }
+                }
+                // the upload in the database is successfull
+                $this->Data->l_lob = $oid;
+                $this->Data->l_filename = $_FILES['listing_mod']['name'];
+                $this->Data->l_mimetype = $_FILES['listing_mod']['type'];
+                $this->Data->l_size = $_FILES['listing_mod']['size'];
+
+                // update rapav
+                $this->Data->update();
+            }
+        } catch (Exception $ex)
+        {
+            $cn->rollback();
+            throw $ex;
+        }
+    }
+
 }

Modified: trunk/rapport_avance/include/class_rapport_avance_sql.php
===================================================================
--- trunk/rapport_avance/include/class_rapport_avance_sql.php   2013-11-06 
15:53:40 UTC (rev 565)
+++ trunk/rapport_avance/include/class_rapport_avance_sql.php   2013-11-06 
20:34:19 UTC (rev 566)
@@ -292,6 +292,7 @@
             "description" => "l_description",
             "name"=>'l_name',
             "lob" => "l_lob",
+            "filename" => "l_filename",
             "mimetype" => "l_mimetype",
             "size" => "l_size",
             "fiche_def_id" => "fd_id"
@@ -301,6 +302,7 @@
             "l_name"=>'text',
             "l_description" => "text",
             "l_lob" => "oid",
+            "l_filename" => "text", 
             "l_mimetype" => "text",
             "l_size" => "numeric",
             "fd_id" => "numeric"

Modified: trunk/rapport_avance/include/template/rapav_listing_to_list.php
===================================================================
--- trunk/rapport_avance/include/template/rapav_listing_to_list.php     
2013-11-06 15:53:40 UTC (rev 565)
+++ trunk/rapport_avance/include/template/rapav_listing_to_list.php     
2013-11-06 20:34:19 UTC (rev 566)
@@ -9,7 +9,7 @@
             Description
         </th>
         <th>
-            
+            Catégorie de fiche
         </th>
     </tr>
     <?php
@@ -25,6 +25,9 @@
             <?php echo h($row['l_description']); ?>
         </td>
         <td>
+            <?php echo h($row['fd_label']); ?>
+        </td>
+        <td>
             Action
         </td>
     </tr>

Modified: trunk/rapport_avance/sql/1-add-listing.sql
===================================================================
--- trunk/rapport_avance/sql/1-add-listing.sql  2013-11-06 15:53:40 UTC (rev 
565)
+++ trunk/rapport_avance/sql/1-add-listing.sql  2013-11-06 20:34:19 UTC (rev 
566)
@@ -4,8 +4,9 @@
     l_name text check (length(trim(l_name)) > 0 and l_name is not null),
     l_description   text,
     l_lob oid,
+    l_filename text,
     l_mimetype text,
-    l_size bigint,
+    l_size bigint default 0,
     fd_id bigint references fiche_def (fd_id) on update cascade on delete set 
null
 );
 create table rapport_advanced.listing_param



---
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]