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.

phcp.php 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. $res=0;
  3. if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
  4. if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
  5. if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
  6. if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  7. if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  8. if (! $res && file_exists("../../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only
  9. if (! $res) die("Include of main fails");
  10. // Change this following line to use the correct relative path from htdocs
  11. dol_include_once('/photocopies/class/phcp.class.php');
  12. // Load traductions files requiredby by page
  13. $langs->load("companies");
  14. $langs->load("other");
  15. // Get parameters
  16. $id = GETPOST('id','int');
  17. $action = GETPOST('action','alpha');
  18. $myparam = GETPOST('myparam','alpha');
  19. $url = DOL_URL_ROOT."/photocopies/phcp.php";
  20. $phcp = null;
  21. $title = null;
  22. if($id){
  23. // Replace with class :
  24. // $phcp = new Phcp($db);
  25. // $phcp->fetch($id);
  26. // echo "<pre>".var_dump($phcp)."</pre>";
  27. $sql = "SELECT";
  28. $sql.= " p.rowid,";
  29. $sql.= " p.nom,";
  30. $sql.= " p.fk_phcp_type,";
  31. $sql.= " pt.nom as phcp_type";
  32. $sql.= " FROM ".MAIN_DB_PREFIX."phcp as p, ";
  33. $sql.= MAIN_DB_PREFIX."phcp_type as pt";
  34. $sql.= " WHERE p.rowid = ".$id;
  35. $sql.= " AND pt.rowid = p.fk_phcp_type";
  36. $resql=$db->query($sql);
  37. if($resql){
  38. $num = $db->num_rows($resql);
  39. $i = 0;
  40. if ($num){
  41. while ($i < $num){
  42. $obj = $db->fetch_object($resql);
  43. if ($obj){ $phcp = $obj; }
  44. $i++;
  45. }
  46. }
  47. }
  48. }
  49. /*******************************************************************
  50. * ACTIONS
  51. *
  52. * Put here all code to do according to value of "action" parameter
  53. ********************************************************************/
  54. //------------------------------------------------------------------------------
  55. if ($action == 'create') {
  56. $phcp = new Phcp($db);
  57. $phcp->nom=$_POST["nom"];
  58. $phcp->fk_phcp_type=$_POST["fk_phcp_type"];
  59. $result = $phcp->create($user);
  60. if ($result > 0)
  61. {
  62. // Creation OK
  63. $action = 'show';
  64. }
  65. {
  66. // Creation KO
  67. $action = 'edit';
  68. }
  69. }
  70. //------------------------------------------------------------------------------
  71. elseif ($action == 'update'){
  72. $phcp = new Phcp($db);
  73. $phcp->fetch($id);
  74. $phcp->nom=$_POST["nom"];
  75. $phcp->fk_phcp_type=$_POST["fk_phcp_type"];
  76. $result = $phcp->update($user);
  77. if ($result > 0)
  78. {
  79. // Creation OK
  80. $action = 'show';
  81. }
  82. {
  83. // Creation KO
  84. $action = 'edit';
  85. }
  86. }
  87. $phcp_types = "";
  88. if($action == 'new' || $action == 'edit'){
  89. $sql = "SELECT pt.rowid, pt.nom ";
  90. $sql.= "FROM ".MAIN_DB_PREFIX."phcp_type as pt";
  91. $resql=$db->query($sql);
  92. if($resql){
  93. $num = $db->num_rows($resql);
  94. $i = 0;
  95. if ($num){
  96. while ($i < $num){
  97. $obj = $db->fetch_object($resql);
  98. if ($obj){
  99. $extra = "";
  100. if($phcp && $phcp->fk_phcp_type == $obj->rowid){ $extra = 'selected="selected"'; }
  101. $phcp_types.= '<option value="'.$obj->rowid.'" '.$extra.'>'.$obj->nom.'</option>'."\n";
  102. }
  103. $i++;
  104. }
  105. }
  106. }
  107. }
  108. switch($action){
  109. case 'new': $title = "Nouveau Photocopieur"; llxHeader('',$title,''); break;
  110. case 'edit': $title = "Modifier Photocopieur"; llxHeader('',$title,''); break;
  111. case 'list': $title = "Liste des Photocopieurs"; llxHeader('',$title,''); break;
  112. case 'show': $title = "Photocopieur : ".$phcp->nom; llxHeader('',$title,''); break;
  113. }
  114. //===============================[TEMPLATE]=====================================
  115. if($phcp && $phcp->error){
  116. ?>
  117. <script type="text/javascript">
  118. $(document).ready(function(){
  119. $.jnotify("<?= $phcp->error ?>", "error");
  120. })
  121. </script>
  122. <?php } ?>
  123. <div class="fiche">
  124. <table width="100%" border="0" style="margin-bottom: 2px;" class="notopnoleftnoright" summary="">
  125. <tbody>
  126. <tr>
  127. <td width="40" valign="middle" align="left" class="nobordernopadding hideonsmartphone">
  128. <img border="0" id="pictotitle" title="" alt="" src="/dolibarr/theme/auguria/img/title.png">
  129. </td>
  130. <td valign="middle" class="nobordernopadding">
  131. <div class="titre"><?= $title ?></div>
  132. </td>
  133. </tr>
  134. </tbody>
  135. </table>
  136. <div class="fichecenter">
  137. <div class="fichethirdleft">
  138. <?php
  139. //------------------------------------------------------------------------------
  140. if ($action == 'new') {
  141. ?>
  142. <form action="<?= $url."?action=create" ?>" method="POST">
  143. <label for="phcp_nom">Nom du photocopieur</label>
  144. <input name="nom" id="phcp_nom" type="text" placeholder="Nom du photocopieur" /><br />
  145. <label for="phcp_type">Type de photocopieur</label>
  146. <select name="fk_phcp_type" id="phcp_type" placeholder="Type de photocopieur">
  147. <?= $phcp_types ?>
  148. </select><br />
  149. <div class="tabsAction">
  150. <div class="inline-block divButAction">
  151. <input type="submit" class="butAction" value="Créer" />
  152. </div>
  153. </div>
  154. </form>
  155. <?php
  156. }
  157. //------------------------------------------------------------------------------
  158. elseif ($action == 'edit') {
  159. ?>
  160. <form action="<?= $url."?action=update" ?>" method="POST">
  161. <input type="hidden" name="id" value="<?= $id ?>" />
  162. <label for="phcp_nom">Nom du photocopieur</label>
  163. <input name="nom" id="phcp_nom" type="text" placeholder="Nom du photocopieur" value="<?= $phcp->nom ?>" /><br />
  164. <label for="phcp_type">Type de photocopieur</label>
  165. <select name="fk_phcp_type" id="phcp_type" placeholder="Type de photocopieur">
  166. <?= $phcp_types ?>
  167. </select><br />
  168. <div class="tabsAction">
  169. <div class="inline-block divButAction">
  170. <input type="submit" class="butAction" value="Modifier" />
  171. </div>
  172. </div>
  173. </form>
  174. <?php
  175. }
  176. //------------------------------------------------------------------------------
  177. elseif ($action == 'show') {
  178. ?>
  179. <strong>Nom : </strong><?= $phcp->nom ?><br />
  180. <strong>Phococopieur Type : </strong><?= $phcp->phcp_type ?><br />
  181. <div class="tabsAction">
  182. <div class="inline-block divButAction">
  183. <a href="<?= $url."?id=".$phcp->rowid."&action=edit" ?>" class="butAction">
  184. Modifier
  185. </a>
  186. </div>
  187. <div class="inline-block divButAction">
  188. <span class="butActionDelete" id="action-delete">Delete</span>
  189. </div>
  190. </div>
  191. <?php
  192. }
  193. //------------------------------------------------------------------------------
  194. else {
  195. $form=new Form($db);
  196. $sql = "SELECT";
  197. $sql.= " p.rowid,";
  198. $sql.= " p.nom,";
  199. $sql.= " pt.nom as phcp_type";
  200. $sql.= " FROM ".MAIN_DB_PREFIX."phcp as p, ";
  201. $sql.= MAIN_DB_PREFIX."phcp_type as pt";
  202. $sql.= " WHERE pt.rowid = p.fk_phcp_type";
  203. print '<table class="noborder" width="100%">'."\n";
  204. print '<tr class="liste_titre">';
  205. print_liste_field_titre($langs->trans('rowid'),$_SERVER['PHP_SELF'],'p.rowid','',$param,'',$sortfield,$sortorder);
  206. print_liste_field_titre($langs->trans('nom'),$_SERVER['PHP_SELF'],'p.nom','',$param,'',$sortfield,$sortorder);
  207. print_liste_field_titre($langs->trans('phcp_type'),$_SERVER['PHP_SELF'],'pt.nom','',$param,'',$sortfield,$sortorder);
  208. print '</tr>';
  209. dol_syslog($script_file." sql=".$sql, LOG_DEBUG);
  210. $resql=$db->query($sql);
  211. if ($resql)
  212. {
  213. $num = $db->num_rows($resql);
  214. $i = 0;
  215. if ($num)
  216. {
  217. while ($i < $num)
  218. {
  219. $obj = $db->fetch_object($resql);
  220. if ($obj)
  221. {
  222. // You can use here results
  223. print '<tr><td>';
  224. print $obj->rowid;
  225. print '</td><td><a href="'.$url.'?id='.$obj->rowid.'&action=show">';
  226. print $obj->nom;
  227. print '</a></td><td>';
  228. print $obj->phcp_type;
  229. print '</td></tr>';
  230. }
  231. $i++;
  232. }
  233. }
  234. }
  235. else
  236. {
  237. $error++;
  238. dol_print_error($db);
  239. }
  240. print '</table>'."\n";
  241. }
  242. ?>
  243. </div>
  244. </div>
  245. </div>
  246. <?php
  247. // End of page
  248. llxFooter();
  249. $db->close();
  250. ?>