You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

societephcpproduct_script.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/usr/bin/php
  2. <?php
  3. /* Copyright (C) 2007-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) ---Put here your own copyright and developer email---
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file dev/skeletons/societephcpproduct_script.php
  21. * \ingroup mymodule
  22. * \brief This file is an example for a command line script
  23. * Initialy built by build_class_from_table on 2013-09-12 16:47
  24. */
  25. $sapi_type = php_sapi_name();
  26. $script_file = basename(__FILE__);
  27. $path=dirname(__FILE__).'/';
  28. // Test if batch mode
  29. if (substr($sapi_type, 0, 3) == 'cgi') {
  30. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  31. exit;
  32. }
  33. // Init global variables
  34. $version='1.0';
  35. $error=0;
  36. // -------------------- START OF YOUR CODE HERE --------------------
  37. @set_time_limit(0); // No timeout for this script
  38. define('EVEN_IF_ONLY_LOGIN_ALLOWED',1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
  39. // Include and load Dolibarr environment variables
  40. require_once($path."../../htdocs/master.inc.php");
  41. // After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
  42. // $user is created but empty.
  43. //$langs->setDefaultLang('en_US'); // To change default language of $langs
  44. $langs->load("main"); // To load language file for default language
  45. // Load user and its permissions
  46. $result=$user->fetch('','admin'); // Load user for login 'admin'. Comment line to run as anonymous user.
  47. if (! $result > 0) { dol_print_error('',$user->error); exit; }
  48. $user->getrights();
  49. print "***** ".$script_file." (".$version.") *****\n";
  50. if (! isset($argv[1])) { // Check parameters
  51. print "Usage: ".$script_file." param1 param2 ...\n";
  52. exit;
  53. }
  54. print '--- start'."\n";
  55. print 'Argument 1='.$argv[1]."\n";
  56. print 'Argument 2='.$argv[2]."\n";
  57. // Start of transaction
  58. $db->begin();
  59. // Examples for manipulating class skeleton_class
  60. require_once(DOL_DOCUMENT_ROOT."/../dev/skeletons/societephcpproduct.class.php");
  61. $myobject=new Societephcpproduct($db);
  62. // Example for inserting creating object in database
  63. /*
  64. dol_syslog($script_file." CREATE", LOG_DEBUG);
  65. $myobject->prop1='value_prop1';
  66. $myobject->prop2='value_prop2';
  67. $id=$myobject->create($user);
  68. if ($id < 0) { $error++; dol_print_error($db,$myobject->error); }
  69. else print "Object created with id=".$id."\n";
  70. */
  71. // Example for reading object from database
  72. /*
  73. dol_syslog($script_file." FETCH", LOG_DEBUG);
  74. $result=$myobject->fetch($id);
  75. if ($result < 0) { $error; dol_print_error($db,$myobject->error); }
  76. else print "Object with id=".$id." loaded\n";
  77. */
  78. // Example for updating object in database ($myobject must have been loaded by a fetch before)
  79. /*
  80. dol_syslog($script_file." UPDATE", LOG_DEBUG);
  81. $myobject->prop1='newvalue_prop1';
  82. $myobject->prop2='newvalue_prop2';
  83. $result=$myobject->update($user);
  84. if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
  85. else print "Object with id ".$myobject->id." updated\n";
  86. */
  87. // Example for deleting object in database ($myobject must have been loaded by a fetch before)
  88. /*
  89. dol_syslog($script_file." DELETE", LOG_DEBUG);
  90. $result=$myobject->delete($user);
  91. if ($result < 0) { $error++; dol_print_error($db,$myobject->error); }
  92. else print "Object with id ".$myobject->id." deleted\n";
  93. */
  94. // An example of a direct SQL read without using the fetch method
  95. /*
  96. $sql = "SELECT field1, field2";
  97. $sql.= " FROM ".MAIN_DB_PREFIX."skeleton";
  98. $sql.= " WHERE field3 = 'xxx'";
  99. $sql.= " ORDER BY field1 ASC";
  100. dol_syslog($script_file." sql=".$sql, LOG_DEBUG);
  101. $resql=$db->query($sql);
  102. if ($resql)
  103. {
  104. $num = $db->num_rows($resql);
  105. $i = 0;
  106. if ($num)
  107. {
  108. while ($i < $num)
  109. {
  110. $obj = $db->fetch_object($resql);
  111. if ($obj)
  112. {
  113. // You can use here results
  114. print $obj->field1;
  115. print $obj->field2;
  116. }
  117. $i++;
  118. }
  119. }
  120. }
  121. else
  122. {
  123. $error++;
  124. dol_print_error($db);
  125. }
  126. */
  127. // -------------------- END OF YOUR CODE --------------------
  128. if (! $error)
  129. {
  130. $db->commit();
  131. print '--- end ok'."\n";
  132. }
  133. else
  134. {
  135. print '--- end error code='.$error."\n";
  136. $db->rollback();
  137. }
  138. $db->close(); // Close $db database opened handler
  139. return $error;
  140. ?>