[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r4322 - phpcompta/trunk/include
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r4322 - phpcompta/trunk/include |
Date: |
Wed, 9 Nov 2011 00:05:48 +0100 (CET) |
Author: danydb
Date: 2011-11-09 00:05:47 +0100 (Wed, 09 Nov 2011)
New Revision: 4322
Added:
phpcompta/trunk/include/class_menu_ref_sql.php
phpcompta/trunk/include/class_profile_sql.php
phpcompta/trunk/include/menu.inc.php
phpcompta/trunk/include/profile.inc.php
Log:
Modularity : start to develop screen to modify Menu and profile
Added: phpcompta/trunk/include/class_menu_ref_sql.php
===================================================================
--- phpcompta/trunk/include/class_menu_ref_sql.php
(rev 0)
+++ phpcompta/trunk/include/class_menu_ref_sql.php 2011-11-08 23:05:47 UTC
(rev 4322)
@@ -0,0 +1,248 @@
+<?php
+
+/**
+ * @file
+ * @brief Manage the table public.menu_ref
+ *
+ *
+ Example
+ @code
+
+ @endcode
+ */
+require_once('class_database.php');
+require_once('ac_common.php');
+
+/**
+ * @brief Manage the table public.menu_ref
+ */
+class Menu_Ref_sql
+{
+ /* example private
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
*/
+
+ protected $variable = array(
+ "me_code" => "me_code"
+ , "me_menu" => "me_menu"
+ , "me_file" => "me_file"
+ , "me_url" => "me_url"
+ , "me_description" => "me_description"
+ , "me_parameter" => "me_parameter"
+ , "me_javascript" => "me_javascript"
+ , "me_type" => "me_type"
+ );
+
+ function __construct(& $p_cn, $p_id=-1)
+ {
+ $this->cn = $p_cn;
+ $this->me_code = $p_id;
+
+ if ($p_id == -1)
+ {
+ /* Initialize an empty object */
+ foreach ($this->variable as $key => $value)
+ $this->$value = null;
+ $this->me_code = $p_id;
+ }
+ else
+ {
+ /* load it */
+
+ $this->load();
+ }
+ }
+
+ public function get_parameter($p_string)
+ {
+ if (array_key_exists($p_string, $this->variable))
+ {
+ $idx = $this->variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ throw new Exception(__FILE__ . ":" . __LINE__ .
$p_string . 'Erreur attribut inexistant');
+ }
+
+ public function set_parameter($p_string, $p_value)
+ {
+ if (array_key_exists($p_string, $this->variable))
+ {
+ $idx = $this->variable[$p_string];
+ $this->$idx = $p_value;
+ }
+ else
+ throw new Exception(__FILE__ . ":" . __LINE__ .
$p_string . 'Erreur attribut inexistant');
+ }
+
+ public function get_info()
+ {
+ return var_export($this, true);
+ }
+
+ public function verify()
+ {
+ // Verify that the elt we want to add is correct
+ /* verify only the datatype */
+ if (trim($this->me_menu) == '')
+ $this->me_menu = null;
+ if (trim($this->me_file) == '')
+ $this->me_file = null;
+ if (trim($this->me_url) == '')
+ $this->me_url = null;
+ if (trim($this->me_description) == '')
+ $this->me_description = null;
+ if (trim($this->me_parameter) == '')
+ $this->me_parameter = null;
+ if (trim($this->me_javascript) == '')
+ $this->me_javascript = null;
+ if (trim($this->me_type) == '')
+ $this->me_type = null;
+ }
+
+ /**
+ * @brief retrieve array of object thanks a condition
+ * @param $cond condition (where clause) (optional by default all the
rows are fetched)
+ * you can use this parameter for the order or subselect
+ * @param $p_array array for the SQL stmt
+ * @see Database::exec_sql get_object Database::num_row
+ * @return the return value of exec_sql
+ */
+ public function seek($cond='', $p_array=null)
+ {
+ $sql = "select * from public.menu_ref $cond";
+ $aobj = array();
+ $ret = $this->cn->exec_sql($sql, $p_array);
+ return $ret;
+ }
+
+ /**
+ * get_seek return the next object, the return of the query must have
all the column
+ * of the object
+ * @param $p_ret is the return value of an exec_sql
+ * @param $idx is the index
+ * @see seek
+ * @return object
+ */
+ public function get_object($p_ret, $idx)
+ {
+ // map each row in a object
+ $oobj = new Menu_Ref_sql($this->cn);
+ $array = Database::fetch_array($p_ret, $idx);
+ foreach ($array as $idx => $value)
+ {
+ $oobj->$idx = $value;
+ }
+ return $oobj;
+ }
+
+ public function insert()
+ {
+ if ($this->verify() != 0)
+ return;
+
+ $sql = "insert into public.menu_ref(me_menu
+ ,me_file
+ ,me_url
+ ,me_description
+ ,me_parameter
+ ,me_javascript
+ ,me_type
+ ,me_code) values ($1
+ ,$2
+ ,$3
+ ,$4
+ ,$5
+ ,$6
+ ,$7
+ ,$8
+ ) returning me_code";
+
+ $this->me_code = $this->cn->get_value(
+ $sql, array($this->me_menu
+ , $this->me_file
+ , $this->me_url
+ , $this->me_description
+ , $this->me_parameter
+ , $this->me_javascript
+ , $this->me_type
+ , $this->me_code)
+ );
+
+ }
+
+ public function update()
+ {
+ if ($this->verify() != 0)
+ return;
+ /* please adapt */
+ $sql = " update public.menu_ref set me_menu = $1
+ ,me_file = $2
+ ,me_url = $3
+ ,me_description = $4
+ ,me_parameter = $5
+ ,me_javascript = $6
+ ,me_type = $7
+ where me_code= $8";
+ $res = $this->cn->exec_sql(
+ $sql, array($this->me_menu
+ , $this->me_file
+ , $this->me_url
+ , $this->me_description
+ , $this->me_parameter
+ , $this->me_javascript
+ , $this->me_type
+ , $this->me_code)
+ );
+ }
+
+ /**
+ * @brief load a object
+ * @return 0 on success -1 the object is not found
+ */
+ public function load()
+ {
+
+ $sql = "select me_menu
+ ,me_file
+ ,me_url
+ ,me_description
+ ,me_parameter
+ ,me_javascript
+ ,me_type
+ from public.menu_ref where
me_code=$1";
+ /* please adapt */
+ $res = $this->cn->get_array(
+ $sql, array($this->me_code)
+ );
+
+ if (count($res) == 0)
+ {
+ /* Initialize an empty object */
+ foreach ($this->variable as $key => $value)
+ $this->$key = '';
+
+ return -1;
+ }
+ foreach ($res[0] as $idx => $value)
+ {
+ $this->$idx = $value;
+ }
+ return 0;
+ }
+
+ public function delete()
+ {
+ $sql = "delete from public.menu_ref where me_code=$1";
+ $res = $this->cn->exec_sql($sql, array($this->me_code));
+ }
+
+ /**
+ * Unit test for the class
+ */
+ static function test_me()
+ {
+ }
+
+}
+
+// Menu_Ref_sql::test_me();
+?>
Added: phpcompta/trunk/include/class_profile_sql.php
===================================================================
--- phpcompta/trunk/include/class_profile_sql.php
(rev 0)
+++ phpcompta/trunk/include/class_profile_sql.php 2011-11-08 23:05:47 UTC
(rev 4322)
@@ -0,0 +1,240 @@
+<?php
+/**
+ address@hidden
+ address@hidden Manage the table public.profile
+ *
+ *
+Example
address@hidden
+
address@hidden
+ */
+require_once('class_database.php');
+require_once('ac_common.php');
+
+
+/**
+ address@hidden Manage the table public.profile
+*/
+class Profile_sql
+{
+ /* example private
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
*/
+
+ protected $variable=array("p_id"=>"p_id","p_name"=>"p_name"
+,"p_desc"=>"p_desc"
+,"with_calc"=>"with_calc"
+,"with_direct_form"=>"with_direct_form"
+);
+ function __construct ( & $p_cn,$p_id=-1) {
+ $this->cn=$p_cn;
+ $this->p_id=$p_id;
+
+ if ( $p_id == -1 ) {
+ /* Initialize an empty object */
+ foreach ($this->variable as $key=>$value) $this->$value=null;
+ $this->p_id=$p_id;
+ } else {
+ /* load it */
+
+ $this->load();
+ }
+ }
+ public function get_parameter($p_string) {
+ if ( array_key_exists($p_string,$this->variable) ) {
+ $idx=$this->variable[$p_string];
+ return $this->$idx;
+ }
+ else
+ throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut
inexistant');
+ }
+ public function set_parameter($p_string,$p_value) {
+ if ( array_key_exists($p_string,$this->variable) ) {
+ $idx=$this->variable[$p_string];
+ $this->$idx=$p_value;
+ }
+ else
+ throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut
inexistant');
+ }
+ public function get_info() { return var_export($this,true); }
+ public function verify() {
+ // Verify that the elt we want to add is correct
+ /* verify only the datatype */
+ if ( trim($this->p_name) == '') $this->p_name=null;
+ if ( trim($this->p_desc) == '') $this->p_desc=null;
+ if ( trim($this->with_calc) == '') $this->with_calc=null;
+ if ( trim($this->with_direct_form) == '') $this->with_direct_form=null;
+
+
+ }
+ public function save() {
+ /* please adapt */
+ if ( $this->p_id == -1 )
+ $this->insert();
+ else
+ $this->update();
+ }
+ /**
+ address@hidden retrieve array of object thanks a condition
+ address@hidden $cond condition (where clause) (optional by default all the
rows are fetched)
+ * you can use this parameter for the order or subselect
+ address@hidden $p_array array for the SQL stmt
+ address@hidden Database::exec_sql get_object Database::num_row
+ address@hidden the return value of exec_sql
+ */
+ public function seek($cond='',$p_array=null)
+ {
+ $sql="select * from public.profile $cond";
+ $aobj=array();
+ $ret= $this->cn->exec_sql($sql,$p_array);
+ return $ret;
+ }
+ /**
+ *get_seek return the next object, the return of the query must have all
the column
+ * of the object
+ address@hidden $p_ret is the return value of an exec_sql
+ address@hidden $idx is the index
+ address@hidden seek
+ address@hidden object
+ */
+ public function get_object($p_ret,$idx)
+ {
+ // map each row in a object
+ $oobj=new Profile_sql ($this->cn);
+ $array=Database::fetch_array($p_ret,$idx);
+ foreach ($array as $idx=>$value) { $oobj->$idx=$value; }
+ return $oobj;
+ }
+ public function insert() {
+ if ( $this->verify() != 0 ) return;
+ if( $this->p_id==-1 ){
+ /* please adapt */
+ $sql="insert into public.profile(p_name
+,p_desc
+,with_calc
+,with_direct_form
+) values ($1
+,$2
+,$3
+,$4
+) returning p_id";
+
+ $this->p_id=$this->cn->get_value(
+ $sql,
+ array( $this->p_name
+,$this->p_desc
+,$this->with_calc
+,$this->with_direct_form
+)
+ );
+ } else {
+ $sql="insert into public.profile(p_name
+,p_desc
+,with_calc
+,with_direct_form
+,p_id) values ($1
+,$2
+,$3
+,$4
+,$5
+) returning p_id";
+
+ $this->p_id=$this->cn->get_value(
+ $sql,
+ array( $this->p_name
+,$this->p_desc
+,$this->with_calc
+,$this->with_direct_form
+,$this->p_id)
+ );
+
+ }
+
+ }
+
+ public function update() {
+ if ( $this->verify() != 0 ) return;
+ /* please adapt */
+ $sql=" update public.profile set p_name = $1
+,p_desc = $2
+,with_calc = $3
+,with_direct_form = $4
+ where p_id= $5";
+ $res=$this->cn->exec_sql(
+ $sql,
+ array($this->p_name
+,$this->p_desc
+,$this->with_calc
+,$this->with_direct_form
+,$this->p_id)
+ );
+
+ }
+/**
+ address@hidden load a object
+ address@hidden 0 on success -1 the object is not found
+ */
+ public function load() {
+
+ $sql="select p_name
+,p_desc
+,with_calc
+,with_direct_form
+ from public.profile where p_id=$1";
+ /* please adapt */
+ $res=$this->cn->get_array(
+ $sql,
+ array($this->p_id)
+ );
+
+ if ( count($res) == 0 ) {
+ /* Initialize an empty object */
+ foreach ($this->variable as $key=>$value) $this->$key='';
+
+ return -1;
+ }
+ foreach ($res[0] as $idx=>$value) { $this->$idx=$value; }
+ return 0;
+ }
+
+ public function delete() {
+ $sql="delete from public.profile where p_id=$1";
+ $res=$this->cn->exec_sql($sql,array($this->p_id));
+ }
+ /**
+ * Unit test for the class
+ */
+ static function test_me() {
+ $cn=new Database(25);
+$cn->start();
+ echo h2info('Test object vide');
+ $obj=new Profile_sql($cn);
+ var_dump($obj);
+
+ echo h2info('Test object NON vide');
+ $obj->set_parameter('j_id',3);
+ $obj->load();
+ var_dump($obj);
+
+ echo h2info('Update');
+ $obj->set_parameter('j_qcode','NOUVEAU CODE');
+ $obj->save();
+ $obj->load();
+ var_dump($obj);
+
+ echo h2info('Insert');
+ $obj->set_parameter('j_id',0);
+ $obj->save();
+ $obj->load();
+ var_dump($obj);
+
+ echo h2info('Delete');
+ $obj->delete();
+ echo (($obj->load()==0)?'Trouve':'non trouve');
+ var_dump($obj);
+$cn->rollback();
+
+ }
+
+}
+// Profile_sql::test_me();
+?>
Added: phpcompta/trunk/include/menu.inc.php
===================================================================
--- phpcompta/trunk/include/menu.inc.php (rev 0)
+++ phpcompta/trunk/include/menu.inc.php 2011-11-08 23:05:47 UTC (rev
4322)
@@ -0,0 +1,100 @@
+<?php
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpCompta; 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 address@hidden
+
+/* !\file
+ *
+ *
+ * \brief Show the table menu and let you add your own
+ *
+ */
+require_once 'class_menu_ref_sql.php';
+require_once 'class_sort_table.php';
+echo '<div class="content">';
+/**
+ * if post save then we save a new one
+ */
+
+/**
+ * if post update then we update
+ */
+
+/**
+ * if delete then delete
+ */
+
+//////////////////////////////////////////////////////////////////////////////
+// Show the list of menu
+//////////////////////////////////////////////////////////////////////////////
+global $cn;
+
+$table=new Sort_Table();
+$url=$_SERVER['REQUEST_URI'];
+
+$table->add('Code',$url,"order by me_code asc","order by me_code
desc","codea","coded");
+$table->add('Menu',$url,"order by me_menu asc","order by me_menu
desc","menua","menud");
+$table->add('Description',$url,"order by me_description asc","order by
me_description desc","desa","desd");
+$table->add('URL',$url,"order by me_url asc","order by me_url
desc","urla","urld");
+$table->add('Paramètre',$url,"order by me_parametere asc","order by
me_parameter desc","paa","pad");
+$table->add('Javascript',$url,"order by me_javascript asc","order by
me_javascript desc","jsa","jsd");
+$table->add('Type',$url,"order by me_type asc","order by me_type
desc","ta","td");
+
+$ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'codea';
+
+$order=$table->get_sql_order($ord);
+
+$menu=new Menu_Ref_sql($cn);
+$ret=$menu->seek($order);
+echo '<p class="info"> le type vaut :
+ <ul>
+ <li> ME pour Menu</li>
+ <li> PR pour les impressions </li>
+ <li> PL pour les plugins</li>
+ <li> SP pour des valeurs spéciales</li>
+ </p>';
+echo '<table class="result">';
+echo '<tr>';
+echo '<th>'.$table->get_header(0).'</th>';
+echo '<th>'.$table->get_header(1).'</th>';
+echo '<th>'.$table->get_header(2).'</th>';
+echo '<th>'.$table->get_header(3).'</th>';
+echo '<th>'.$table->get_header(4).'</th>';
+echo '<th>'.$table->get_header(5).'</th>';
+echo '<th>'.$table->get_header(6).'</th>';
+echo '</tr>';
+
+for ($i=0;$i<Database::num_row($ret);$i++)
+{
+ $row=$menu->get_object($ret, $i);
+ echo '<tr>';
+ echo td($row->me_code);
+ echo td($row->me_menu);
+ echo td($row->me_description);
+ echo td($row->me_url);
+ echo td($row->me_parameter);
+ echo td($row->me_javascript);
+ echo td($row->me_type);
+ echo '</tr>';
+}
+echo '</table>';
+
+?>
Added: phpcompta/trunk/include/profile.inc.php
===================================================================
--- phpcompta/trunk/include/profile.inc.php (rev 0)
+++ phpcompta/trunk/include/profile.inc.php 2011-11-08 23:05:47 UTC (rev
4322)
@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpCompta; 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 address@hidden
+require_once 'class_profile_sql.php';
+global $cn;
+echo '<div class="content">';
+$table=new Sort_Table();
+$url=$_SERVER['REQUEST_URI'];
+
+$table->add('Nom',$url,"order by p_name asc","order by p_name desc","na","nd");
+$table->add('Description',$url,"order by p_desc asc","order by p_desc
desc","da","dd");
+$table->add('Calculatrice visible',$url,"order by with_calc asc","order by
with_calc desc","ca","cd");
+$table->add('Form Direct visible',$url,"order by with_direct_form asc","order
by with_direct_form desc","fa","fd");
+
+$ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'na';
+
+$order=$table->get_sql_order($ord);
+
+$menu=new Profile_sql($cn);
+$ret=$menu->seek($order);
+echo '<table class="result">';
+echo '<tr>';
+echo '<th>'.$table->get_header(0).'</th>';
+echo '<th>'.$table->get_header(1).'</th>';
+echo '<th>'.$table->get_header(2).'</th>';
+echo '<th>'.$table->get_header(3).'</th>';
+echo '</tr>';
+
+for ($i=0;$i<Database::num_row($ret);$i++)
+{
+ $row=$menu->get_object($ret, $i);
+ echo '<tr>';
+ echo td($row->p_name);
+ echo td($row->p_desc);
+ echo td($row->with_calc);
+ echo td($row->with_direct_form);
+ echo '</tr>';
+}
+echo '</table>';
+echo '</div>';
+
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpcompta-dev] r4322 - phpcompta/trunk/include,
phpcompta-dev <=