phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] api/class.datamine.php, 1.1.2.2


From: nomail
Subject: [Phpgroupware-cvs] api/class.datamine.php, 1.1.2.2
Date: Fri, 21 May 2004 07:50:53 -0000

Update of /api
Modified Files:
        Branch: proposal-branch
          class.datamine.php

date: 2004/04/23 15:03:30;  author: dcech;  state: Exp;  lines: +67 -46

Log Message:
tidied up database access
=====================================================================
Index: api/class.datamine.php
diff -u api/class.datamine.php:1.1.2.1 api/class.datamine.php:1.1.2.2
--- api/class.datamine.php:1.1.2.1      Fri Apr 16 20:59:48 2004
+++ api/class.datamine.php      Fri Apr 23 15:03:30 2004
@@ -22,31 +22,40 @@
        
\**************************************************************************/
 
        /* $Id$ */
-       /* $Source$ */
+       /* $Source$ */
 
        $GLOBALS['datamine_menus_loaded'] = false;
        class api_datamine
        {
-               function api_datamine()
+               function api_datamine()
                {
-                       //
+                       //
                }
 
-               function __create_menu($location)
+               function __create_menu()
                {
-                       if (! $GLOBALS['datamine_menus_loaded'])
+                       $args = new safe_args();
+                       $args->set('location',REQUIRED,'any');
+                       $args = $args->get(func_get_args());
+
+                       if ($GLOBALS['datamine_menus_loaded'])
                        {
-                               $dbresult = 
$GLOBALS['phpgw']->db->execute("SELECT dml_title,dml_op FROM "
-                                       . "phpgw_datamine_locations ORDER BY 
dml_title");
-                               while (! $dbresult->EOF)
-                               {
-                                       
$GLOBALS['phpgw']->add_appmenu('Datamine 
menu',$dbresult->fields['dml_title'],$dbresult->fields['dml_op'] . 
'&dm_type=D&datamine_location=' . $location . '&dm_redirect=' . 
$_SESSION['phpgw_session']['phpgw_data']['current_history_position']);
-
-                                       $dbresult->movenext();
-                               }
-                               $GLOBALS['datamine_menus_loaded'] = true;
-                               $GLOBALS['phpgw']->add_appmenu('Datamine 
menu','Show map',' ');
+                               return;
                        }
+
+                       $sql = 'SELECT dml_title,dml_op'
+                                . ' FROM phpgw_datamine_locations'
+                                . ' ORDER BY dml_title';
+                       if (!is_object($rs = 
$GLOBALS['phpgw']->db->execute($sql)))
+                       {
+                               return false;
+                       }
+                       while ($row = $rs->FetchRow())
+                       {
+                               $GLOBALS['phpgw']->add_appmenu('Datamine 
menu',$row['dml_title'],$row['dml_op'] . '&dm_type=D&datamine_location=' . 
$args['location'] . '&dm_redirect=' . 
$_SESSION['phpgw_session']['phpgw_data']['current_history_position']);
+                       }
+                       $GLOBALS['datamine_menus_loaded'] = true;
+                       $GLOBALS['phpgw']->add_appmenu('Datamine menu','Show 
map',' ');
                }
 
                function _get()
@@ -55,34 +64,27 @@
                        $args->set('location',REQUIRED,'any');
                        $args = $args->get(func_get_args());
 
-                       $this->__create_menu($args['location']);
-                       $dbresult = $GLOBALS['phpgw']->db->execute("SELECT * 
from phpgw_datamine WHERE "
-                               . "dm_location_from='" . $args['location'] . "' 
and dm_owner="
-                               . $GLOBALS['phpgw_data']['user']['id']);
-
-                       if ($dbresult->EOF)
+                       $this->__create_menu($args);
+                       $sql = 'SELECT dm_location_to'
+                                . ' FROM phpgw_datamine'
+                                . ' WHERE dm_location_from=' . 
$GLOBALS['phpgw']->db->qstr($args['location'])
+                                . ' AND dm_owner=' . 
$GLOBALS['phpgw_data']['user']['id'];
+                       if (!is_object($rs = 
$GLOBALS['phpgw']->db->execute($sql)))
                        {
-                               return array();
+                               return false;
                        }
-                       else
+                       $result = array();
+                       while ($row = $rs->FetchRow())
                        {
-                               while (! $dbresult->EOF)
-                               {
-                                       // The no_app_menu is *ONLY* a temp 
workaround for not showing the app menu
-                                       // durring _datamine_get(), I am 
currently working on another solution to it
-                                       $GLOBALS['no_app_menu'] = true;
-
-                                       list($app,$class,$id) = 
explode('.',$dbresult->fields['dm_location_to']);
-
-                                       $result[] = array
-                                       (
-                                               'type' => $app . '_' . $class,
-                                               'data' => execMethod($app . '.' 
. $class . '._datamine_get',$id)
-                                       );
-                                       $dbresult->movenext();
-                               }
+                               // The no_app_menu is *ONLY* a temp workaround 
for not showing the app menu
+                               // during _datamine_get(), I am currently 
working on another solution to it
+                               $GLOBALS['no_app_menu'] = true;
+                               list($app,$class,$id) = 
explode('.',$row['dm_location_to']);
+                               $result[] = array(
+                                       'type' => $app . '_' . $class,
+                                       'data' => execMethod($app . '.' . 
$class . '._datamine_get',$id)
+                               );
                        }
-
                        return $result;
                }
 
@@ -92,11 +94,30 @@
                        $args->set('location_from',REQUIRED,'any');
                        $args->set('location_to',REQUIRED,'any');
                        $args = $args->get(func_get_args());
-
-                       $GLOBALS['phpgw']->db->execute("INSERT into 
phpgw_datamine (dm_owner,dm_location_from,"
-                               . "dm_location_to) VALUES (" . 
$GLOBALS['phpgw_data']['user']['id'] . ",'"
-                               . $args['location_from'] . "','" . 
$args['location_to'] . "')");
-
-                       return true;
+                       
+                       $details = array(
+                               'dm_owner'                      => 
$GLOBALS['phpgw_data']['user']['id'],
+                               'dm_location_from'      => 
$args['location_from'],
+                               'dm_location_to'        => $args['location_to']
+                       );
+                       
+                       $sql = 'SELECT * FROM phpgw_datamine'
+                                . ' WHERE dm_owner=' . $details['dm_owner']
+                                . ' AND dm_location_from=' . 
$GLOBALS['phpgw']->db->qstr($details['dm_location_from'])
+                                . ' AND dm_location_to=' . 
$GLOBALS['phpgw']->db->qstr($details['dm_location_to']);
+                       if (!is_object($rs = 
$GLOBALS['phpgw']->db->execute($sql)))
+                       {
+                               return false;
+                       }
+                       
+                       if ($rs->EOF)
+                       {
+                               $sql = 
$GLOBALS['phpgw']->db->GetInsertSQL($rs,$details);
+                       }
+                       else
+                       {
+                               $sql = 
$GLOBALS['phpgw']->db->GetUpdateSQL($rs,$details);
+                       }
+                       return is_object($rs = 
$GLOBALS['phpgw']->db->execute($sql));
                }
        }




reply via email to

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