/telephonie/htdocs/telephonie/fournisseur/commande/commande.web.class.php

https://github.com/Dolibarr/obsolete · PHP · 179 lines · 112 code · 33 blank · 34 comment · 14 complexity · 519765b0757797b08b4636ad4b54e1ea MD5 · raw file

  1. <?PHP
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * $Id: commande.web.class.php,v 1.2 2010/08/24 20:27:24 grandoc Exp $
  19. * $Source: /cvsroot/dolibarr/dolibarrmod/telephonie/htdocs/telephonie/fournisseur/commande/commande.web.class.php,v $
  20. *
  21. * Classe de commande de ligne au format Texte
  22. *
  23. *
  24. */
  25. require_once DOL_DOCUMENT_ROOT."/telephonie/dolibarrmail.class.php";
  26. require_once DOL_DOCUMENT_ROOT."/telephonie/fournisseur/commande/methode.commande.class.php";
  27. define ('COMMANDETEXT_NOEMAIL', -3);
  28. class CommandeMethodeWeb extends CommandeMethode
  29. {
  30. function CommandeMethodeWeb ($DB, $USER=0, $fourn=0)
  31. {
  32. $this->nom = "Méthode web";
  33. $this->db = $DB;
  34. $this->user = $USER;
  35. $this->fourn = $fourn;
  36. }
  37. function info()
  38. {
  39. return "Commande les lignes au travers du web";
  40. }
  41. function Create()
  42. {
  43. $this->date = time();
  44. $this->datef = "comm-".$this->fourn->id."-".strftime("%d%b%y-%H:%M:%S", $this->date);
  45. $this->filename = $this->datef.".txt";
  46. $fname = DOL_DATA_ROOT ."/telephonie/ligne/commande/".$this->filename;
  47. if (dol_strlen(trim($this->fourn->email_commande)) == 0)
  48. {
  49. return -3;
  50. }
  51. if (file_exists($fname))
  52. {
  53. return 2;
  54. }
  55. else
  56. {
  57. $res = $this->CreateFile($fname);
  58. if ($res == 0)
  59. {
  60. $res = $res + $this->LogSql();
  61. }
  62. return $res;
  63. }
  64. }
  65. /**
  66. * Creation du fichier
  67. *
  68. */
  69. function CreateFile($fname)
  70. {
  71. $fp = fopen($fname, "w");
  72. if ($fp)
  73. {
  74. fwrite ($fp, "Numcli;");
  75. fwrite ($fp, "nomclient;");
  76. fwrite ($fp, "NDI\n");
  77. $this->ligneids = array();
  78. $sqlall = "SELECT s.nom, s.rowid as socid, l.ligne, l.statut, l.rowid";
  79. $sqlall .= " , comm.name, comm.firstname";
  80. $sqlall .= " FROM ".MAIN_DB_PREFIX."societe as s";
  81. $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
  82. $sqlall .= " , ".MAIN_DB_PREFIX."user as comm";
  83. $sqlall .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f";
  84. $sqlall .= " WHERE l.fk_soc = s.rowid AND l.fk_fournisseur = f.rowid";
  85. $sqlall .= " AND l.fk_commercial = comm.rowid ";
  86. $sqlall .= " AND f.rowid =".$this->fourn->id;
  87. /*
  88. *
  89. */
  90. $sql = $sqlall;
  91. $sql .= " AND l.statut in (1,8)";
  92. $sql .= " ORDER BY l.statut ASC";
  93. $resql = $this->db->query($sql);
  94. if ($resql)
  95. {
  96. $i = 0;
  97. $num = $this->db->num_rows($resql);
  98. while ($i < $num)
  99. {
  100. $obj = $this->db->fetch_object($resql);
  101. if (dol_strlen($obj->ligne)== 10)
  102. {
  103. $soc = new Societe($this->db);
  104. $soc->fetch($obj->socid);
  105. fwrite ($fp, $this->fourn->num_client);
  106. fwrite ($fp, ";");
  107. fwrite ($fp, $obj->nom);
  108. fwrite ($fp, ";");
  109. fwrite ($fp, $obj->ligne);
  110. fwrite ($fp, "\n");
  111. array_push($this->ligneids, $obj->rowid);
  112. }
  113. $i++;
  114. }
  115. $this->db->free($resql);
  116. }
  117. else
  118. {
  119. print $this->db->error() . ' ' . $sql;
  120. }
  121. fclose($fp);
  122. /*
  123. *
  124. *
  125. */
  126. foreach ($this->ligneids as $lid)
  127. {
  128. $lint = new LigneTel($this->db);
  129. $lint->fetch_by_id($lid);
  130. if ($lint->statut == 1)
  131. {
  132. $lint->set_statut($this->user, 9);
  133. }
  134. if ($lint->statut == 8)
  135. {
  136. $lint->set_statut($this->user, 9);
  137. }
  138. }
  139. return 0;
  140. }
  141. else
  142. {
  143. return -1;
  144. }
  145. }
  146. }