get_contracts.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env php
  2. <?php
  3. /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file dev/examples/get_contracts.php
  20. * \brief This file is an example for a command line script
  21. * \author Put author's name here
  22. * \remarks Put here some comments
  23. */
  24. $sapi_type = php_sapi_name();
  25. $script_file = basename(__FILE__);
  26. $path = dirname(__FILE__).'/';
  27. // Test if batch mode
  28. if (substr($sapi_type, 0, 3) == 'cgi') {
  29. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  30. exit;
  31. }
  32. // Global variables
  33. $version = '1.7';
  34. $error = 0;
  35. // -------------------- START OF YOUR CODE HERE --------------------
  36. // Include Dolibarr environment
  37. require_once $path."../../../htdocs/master.inc.php";
  38. // After this $db, $mysoc, $langs and $conf->entity are defined. Opened handler to database will be closed at end of file.
  39. //$langs->setDefaultLang('en_US'); // To change default language of $langs
  40. $langs->load("main"); // To load language file for default language
  41. @set_time_limit(0);
  42. // Load user and its permissions
  43. $result = $user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user.
  44. if (!$result > 0) {
  45. dol_print_error('', $user->error);
  46. exit;
  47. }
  48. $user->getrights();
  49. print "***** ".$script_file." (".$version.") *****\n";
  50. if (!isset($argv[1])) { // Check parameters
  51. print "Usage: ".$script_file." id_thirdparty ...\n";
  52. exit;
  53. }
  54. print '--- start'."\n";
  55. print 'Argument id_thirdparty='.$argv[1]."\n";
  56. // Start of transaction
  57. $db->begin();
  58. require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
  59. // Create contract object
  60. $obj = new Contrat($db);
  61. $obj->socid = $argv[1];
  62. $listofcontractsforcompany = $obj->getListOfContracts('all');
  63. print $listofcontractsforcompany;
  64. // -------------------- END OF YOUR CODE --------------------
  65. $db->close();
  66. return $error;