2007-02-11 18:50:43 +01:00
< ? php
2010-02-28 16:13:27 +01:00
/* Copyright ( C ) 2007 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2008-01-20 19:47:10 +01:00
* Copyright ( C ) --- Put here your own copyright and developer email ---
2007-02-11 18:50:43 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2007-02-11 18:50:43 +01:00
* ( at your option ) any later version .
*
* This program 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
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2007-02-11 18:50:43 +01:00
*/
/**
2009-01-18 19:38:47 +01:00
* \file dev / skeletons / skeleton_page . php
* \ingroup mymodule othermodule1 othermodule2
* \brief This file is an example of a php page
2012-01-18 00:15:10 +01:00
* Put here some comments
2009-01-18 19:38:47 +01:00
*/
2010-02-28 16:13:27 +01:00
2010-04-05 19:02:32 +02:00
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
2013-03-24 19:01:30 +01:00
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test
//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
2010-04-05 19:02:32 +02:00
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
2013-03-24 19:01:30 +01:00
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
2010-04-05 19:02:32 +02:00
2010-02-28 16:13:27 +01:00
// Change this following line to use the correct relative path (../, ../../, etc)
2011-01-16 14:24:29 +01:00
$res = 0 ;
2013-08-28 16:39:23 +02:00
if ( ! $res && file_exists ( " ../main.inc.php " )) $res =@ include '../main.inc.php' ; // to work if your module directory is into dolibarr root htdocs directory
if ( ! $res && file_exists ( " ../../main.inc.php " )) $res =@ include '../../main.inc.php' ; // to work if your module directory is into a subdir of root htdocs directory
2012-08-23 02:04:35 +02:00
if ( ! $res && file_exists ( " ../../../dolibarr/htdocs/main.inc.php " )) $res =@ include '../../../dolibarr/htdocs/main.inc.php' ; // Used on dev env only
if ( ! $res && file_exists ( " ../../../../dolibarr/htdocs/main.inc.php " )) $res =@ include '../../../../dolibarr/htdocs/main.inc.php' ; // Used on dev env only
2011-01-16 14:24:29 +01:00
if ( ! $res ) die ( " Include of main fails " );
2012-06-27 01:27:22 +02:00
// Change this following line to use the correct relative path from htdocs
2012-08-23 02:04:35 +02:00
dol_include_once ( '/module/class/skeleton_class.class.php' );
2007-02-11 18:50:43 +01:00
2008-01-29 20:03:26 +01:00
// Load traductions files requiredby by page
2007-02-11 18:50:43 +01:00
$langs -> load ( " companies " );
$langs -> load ( " other " );
// Get parameters
2011-11-27 18:44:27 +01:00
$id = GETPOST ( 'id' , 'int' );
$action = GETPOST ( 'action' , 'alpha' );
$myparam = GETPOST ( 'myparam' , 'alpha' );
2007-02-11 18:50:43 +01:00
2008-01-29 20:03:26 +01:00
// Protection if external user
2007-02-11 18:50:43 +01:00
if ( $user -> societe_id > 0 )
{
2008-01-29 20:03:26 +01:00
//accessforbidden();
2007-02-11 18:50:43 +01:00
}
/*******************************************************************
* ACTIONS
*
* Put here all code to do according to value of " action " parameter
********************************************************************/
2011-09-02 20:26:42 +02:00
if ( $action == 'add' )
2007-02-11 18:50:43 +01:00
{
2013-01-16 14:11:19 +01:00
$object = new Skeleton_Class ( $db );
$object -> prop1 = $_POST [ " field1 " ];
$object -> prop2 = $_POST [ " field2 " ];
$result = $object -> create ( $user );
2007-02-11 18:50:43 +01:00
if ( $result > 0 )
{
// Creation OK
}
{
// Creation KO
2013-01-16 14:11:19 +01:00
$mesg = $object -> error ;
2007-02-11 18:50:43 +01:00
}
}
/***************************************************
2011-09-02 20:26:42 +02:00
* VIEW
2007-02-11 18:50:43 +01:00
*
* Put here all code to build page
****************************************************/
2010-05-26 13:28:10 +02:00
llxHeader ( '' , 'MyPageName' , '' );
2007-02-11 18:50:43 +01:00
2008-01-29 20:03:26 +01:00
$form = new Form ( $db );
2007-02-11 18:50:43 +01:00
// Put here content of your page
2011-09-02 20:26:42 +02:00
// Example 1 : Adding jquery code
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
function init_myfunc ()
{
jQuery ( " #myid " ) . removeAttr ( \ ' disabled\ ' );
jQuery ( " #myid " ) . attr ( \ ' disabled\ ' , \ ' disabled\ ' );
}
init_myfunc ();
jQuery ( " #mybutton " ) . click ( function () {
init_needroot ();
});
});
</ script > ' ;
2007-02-11 18:50:43 +01:00
2011-09-02 20:26:42 +02:00
2012-06-27 01:27:22 +02:00
// Example 2 : Adding links to objects
2013-01-16 12:57:09 +01:00
// The class must extends CommonObject class to have this method available
2013-01-16 14:11:19 +01:00
//$somethingshown=$object->showLinkedObjectBlock();
2010-04-09 10:15:46 +02:00
2011-09-02 20:26:42 +02:00
2012-06-27 01:27:22 +02:00
// Example 3 : List of data
if ( $action == 'list' )
{
$sql = " SELECT " ;
2013-01-16 15:54:07 +01:00
$sql .= " t.rowid, " ;
$sql .= " t.field1, " ;
2012-06-27 01:27:22 +02:00
$sql .= " t.field2 " ;
2013-01-16 12:57:09 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " mytable as t " ;
2012-06-27 01:27:22 +02:00
$sql .= " WHERE field3 = 'xxx' " ;
$sql .= " ORDER BY field1 ASC " ;
2013-01-16 12:57:09 +01:00
print '<table class="noborder">' . " \n " ;
2012-06-27 01:27:22 +02:00
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $langs -> trans ( 'field1' ), $_SERVER [ 'PHP_SELF' ], 't.field1' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'field2' ), $_SERVER [ 'PHP_SELF' ], 't.field2' , '' , $param , '' , $sortfield , $sortorder );
print '</tr>' ;
dol_syslog ( $script_file . " sql= " . $sql , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
if ( $num )
{
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
// You can use here results
print '<tr><td>' ;
print $obj -> field1 ;
print $obj -> field2 ;
print '</td></tr>' ;
}
$i ++ ;
}
}
}
else
{
$error ++ ;
dol_print_error ( $db );
}
2013-01-16 12:57:09 +01:00
2013-01-16 15:54:07 +01:00
print '</table>' . " \n " ;
2012-06-27 01:27:22 +02:00
}
2007-02-11 18:50:43 +01:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-03-14 15:08:40 +01:00
$db -> close ();
2007-02-11 18:50:43 +01:00
?>