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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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/phcptype.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') ?: 'list';
  18. $myparam = GETPOST('myparam','alpha');
  19. $url = DOL_URL_ROOT."/photocopies/phcptype.php";
  20. $phcptype = null;
  21. $title = null;
  22. /*******************************************************************
  23. * ACTIONS
  24. *
  25. * Put here all code to do according to value of "action" parameter
  26. ********************************************************************/
  27. $phcptype = new PhcpType($db);
  28. if($id) $phcptype->fetch($id);
  29. else {
  30. $phcptype->initAsSpecimen();
  31. $phcptype->nom = GETPOST('phcp_nom', 'alpha') ?: '';
  32. }
  33. //------------------------------------------------------------------------------
  34. if ($action == 'create') {
  35. $phcptype->ref=$_POST["ref"];
  36. $phcptype->nom=$_POST["nom"];
  37. $phcptype->fk_phcp_type=$_POST["fk_phcp_type"];
  38. if ($phcptype->create($user) >= 0){
  39. $id = $phcptype->id;
  40. $action = 'edit';
  41. } else
  42. $action = 'new';
  43. }
  44. //------------------------------------------------------------------------------
  45. elseif ($action == 'update'){
  46. $phcptype->ref=$_POST["ref"];
  47. $phcptype->nom=$_POST["nom"];
  48. $phcptype->fk_phcp_type=$_POST["fk_phcp_type"];
  49. if ($phcptype->update($user) >= 0)
  50. $action = 'show';
  51. else
  52. $action = 'edit';
  53. }
  54. //------------------------------------------------------------------------------
  55. elseif ($action == 'delete'){
  56. if($phcptype->delete($user) >= 0)
  57. $action = 'list';
  58. else
  59. $action = 'list';
  60. }
  61. //------------------------------------------------------------------------------
  62. elseif ($action == 'add_product'){
  63. $fk_product = GETPOST('fk_product','int') ?: null;
  64. if($fk_product){
  65. $phcptype->add_product($fk_product);
  66. }
  67. $action = "edit";
  68. }
  69. //------------------------------------------------------------------------------
  70. elseif ($action == 'remove_product'){
  71. $fk_product = GETPOST('fk_product','int') ?: null;
  72. if($fk_product){
  73. $phcptype->remove_product($fk_product);
  74. }
  75. $action = "edit";
  76. }
  77. $products = "";
  78. if($action == 'new' || $action == 'edit'){
  79. $sql = "SELECT pr.rowid, pr.ref, pr.label, pr.price ";
  80. $sql.= "FROM ".MAIN_DB_PREFIX."product as pr";
  81. $resql=$db->query($sql);
  82. if($resql){
  83. $num = $db->num_rows($resql);
  84. $i = 0;
  85. if ($num){
  86. while ($i < $num){
  87. $obj = $db->fetch_object($resql);
  88. if ($obj){
  89. $products.= '<option value="'.$obj->rowid.'">'.$obj->ref.' - '.$obj->label.' - '.money_format("%i €", $obj->price).'</option>'."\n";
  90. }
  91. $i++;
  92. }
  93. }
  94. }
  95. }
  96. switch($action){
  97. case 'new': $title = "Nouveau modèle de photocopieur"; llxHeader('',$title,''); break;
  98. case 'edit': $title = "Modifier le modèle de photocopieur"; llxHeader('',$title,''); break;
  99. case 'list': $title = "Liste des modèles de photocopieurs"; llxHeader('',$title,''); break;
  100. case 'show': $title = "Modèle de photocopieur : ".$phcptype->nom; llxHeader('',$title,''); break;
  101. }
  102. //===============================[TEMPLATE]=====================================
  103. if($phcptype && $phcptype->error){
  104. ?>
  105. <script type="text/javascript">
  106. $(document).ready(function(){
  107. $.jnotify("<?= $phcptype->error ?>", "error");
  108. })
  109. </script>
  110. <?php } ?>
  111. <div class="fiche">
  112. <table width="100%" border="0" style="margin-bottom: 2px;" class="notopnoleftnoright" summary="">
  113. <tbody>
  114. <tr>
  115. <td width="40" valign="middle" align="left" class="nobordernopadding hideonsmartphone">
  116. <img border="0" id="pictotitle" title="" alt="" src="/dolibarr/theme/auguria/img/title.png">
  117. </td>
  118. <td valign="middle" class="nobordernopadding">
  119. <div class="titre"><?= $title ?></div>
  120. </td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. <div class="fichecenter">
  125. <!--div class="fichethirdleft"-->
  126. <?php
  127. //------------------------------------------------------------------------------
  128. if (($action == 'new') || ($action == 'edit')){
  129. ?>
  130. <form action="<?= $url."?action=".($action=='new'?'create':'update') ?>" method="POST">
  131. <?php if($id){ ?><input type="hidden" name="id" value="<?= $id ?>" /><?php } ?>
  132. <table width="100%" class="border">
  133. <tbody>
  134. <tr>
  135. <td class="fieldrequired" width="20%"><label for="phcp_ref">Ref.</label></td>
  136. <td><input type="text" id="phcp_ref" name="ref" value="<?= $phcptype->ref ?>" placeholder="Reference" /></td>
  137. </tr>
  138. <tr>
  139. <td class="fieldrequired"><label for="phcp_nom">Label</label></td>
  140. <td><input name="nom" id="phcp_nom" type="tel" value="<?= $phcptype->nom ?>" /></td>
  141. </tr>
  142. <?php if($action == 'edit'){ ?>
  143. <tr>
  144. <td><label for="phcp_type">Tarifs associés</label></td>
  145. <td>
  146. <table class="noborder" width="100%">
  147. <thead>
  148. <tr class="liste_titre">
  149. <th>Ref</th>
  150. <th>Label</th>
  151. <th>Price</th>
  152. <th>&nbsp;</th>
  153. </tr>
  154. </thead>
  155. <tbody>
  156. <?php foreach($phcptype->products as $product){ ?>
  157. <tr>
  158. <td><a href="<?= DOL_URL_ROOT ?>/product/fiche.php?id=<?= $product->id ?>"><?= $product->ref ?></a></td>
  159. <td><?= $product->label ?></td>
  160. <td><?= money_format("%i €", $product->price) ?></td>
  161. <td align="right"><a href="<?= $url.'?action=remove_product&id='.$id.'&fk_product='.$product->id ?>">X</a></td>
  162. </tr>
  163. <?php } ?>
  164. </tbody>
  165. </table>
  166. </td>
  167. </tr>
  168. <?php } ?>
  169. </tbody>
  170. </table>
  171. <div class="tabsAction">
  172. <div class="inline-block divButAction">
  173. <input type="submit" class="butAction" value="<?= $action=='new'?'Créer':'Modifier' ?>" />
  174. </div>
  175. </div>
  176. </form>
  177. <?php if($action == 'edit'){ ?>
  178. <form action="<?= $url."?action=add_product&id=".$id ?>" method="POST">
  179. <label for="fk_product">Tarif à associer</label>
  180. <select name="fk_product" id="fk_product">
  181. <option>Selectionnez un tarif à associer</option>
  182. <?= $products ?>
  183. </select>
  184. <input type="submit" value="+ Associer le tarif" />
  185. </form>
  186. <?php } ?>
  187. <?php
  188. }
  189. //------------------------------------------------------------------------------
  190. elseif ($action == 'show') {
  191. ?>
  192. <div class="tabBar">
  193. <table width="100%" class="border">
  194. <tbody>
  195. <tr>
  196. <td width="15%">Ref.</td>
  197. <td colspan="2"><?= $phcptype->ref ?></td>
  198. </tr>
  199. <tr>
  200. <td>Label</td>
  201. <td colspan="2"><?= $phcptype->nom ?></td>
  202. </tr>
  203. <tr>
  204. <td>Tarifs Associés</td>
  205. <td colspan="2">
  206. <table width="100%" class="border">
  207. <tbody>
  208. <?php foreach($phcptype->products as $product){ ?>
  209. <tr>
  210. <td>
  211. <a href="<?= DOL_URL_ROOT ?>/product/fiche.php?id=<?= $product->id ?>">
  212. <?= $product->ref ?>
  213. </a> - <?= $product->label ?> - <?= money_format("%i €", $product->price) ?>
  214. </td>
  215. </tr>
  216. <?php } ?>
  217. </tbody>
  218. </table>
  219. </td>
  220. </tr>
  221. </tbody>
  222. </table>
  223. </div>
  224. <div class="tabsAction">
  225. <div class="inline-block divButAction">
  226. <a href="<?= $url."?id=".$phcptype->id."&action=edit" ?>" class="butAction">
  227. Modifier
  228. </a>
  229. </div>
  230. <div class="inline-block divButAction">
  231. <a href="<?= $url.'?id='.$phcptype->id.'&action=delete' ?>" class="butActionDelete" id="action-delete">Suprimer</a>
  232. </div>
  233. </div>
  234. <?php
  235. }
  236. //------------------------------------------------------------------------------
  237. else {
  238. $sortfield = GETPOST('sortfield', 'alpha') == 'pt.nom' ? 'pt.nom' : 'pt.ref';
  239. $sortorder = GETPOST('sortorder', 'alpha') == 'desc' ? 'DESC' : 'ASC';
  240. $form= new Form($db);
  241. $sql = "SELECT";
  242. $sql.= " pt.rowid,";
  243. $sql.= " pt.ref,";
  244. $sql.= " pt.nom";
  245. $sql.= " FROM ".MAIN_DB_PREFIX."phcp_type as pt";
  246. $sql.= " ORDER BY ".$sortfield." ".$sortorder;
  247. print '<table class="border" width="100%">'."\n";
  248. print '<tr class="liste_titre">';
  249. print_liste_field_titre($langs->trans('Ref.'),$_SERVER['PHP_SELF'],'pt.ref','',$param,'',$sortfield,$sortorder);
  250. print_liste_field_titre($langs->trans('Label'),$_SERVER['PHP_SELF'],'pt.nom','',$param,'',$sortfield,$sortorder);
  251. print '<th>Tarifs associés</th>';
  252. print '<th>&nbsp;</th>';
  253. print '</tr>';
  254. dol_syslog($script_file." sql=".$sql, LOG_DEBUG);
  255. $resql=$db->query($sql);
  256. if ($resql){
  257. $num = $db->num_rows($resql);
  258. $i = 0;
  259. if ($num){
  260. while ($i < $num){
  261. $obj = $db->fetch_object($resql);
  262. if ($obj){
  263. print '<tr><td><a href="'.$url.'?id='.$obj->rowid.'&action=show">';
  264. print $obj->ref;
  265. print '</a></td><td><a href="'.$url.'?id='.$obj->rowid.'&action=show">';
  266. print $obj->nom;
  267. print '</a></td><td><ul>';
  268. $sql2 = "SELECT";
  269. $sql2.= " pr.rowid,";
  270. $sql2.= " pr.label,";
  271. $sql2.= " pr.ref,";
  272. $sql2.= " pr.price";
  273. $sql2.= " FROM ".MAIN_DB_PREFIX."product as pr,";
  274. $sql2.= " ".MAIN_DB_PREFIX."phcp_type_product as ptpr";
  275. $sql2.= " WHERE pr.rowid = ptpr.fk_product";
  276. $sql2.= " AND ptpr.fk_phcp_type = ".$obj->rowid;
  277. $resql2=$db->query($sql2);
  278. if ($resql2){
  279. $num2 = $db->num_rows($resql2);
  280. $i2 = 0;
  281. if ($num2){
  282. while ($i2 < $num2){
  283. $obj2 = $db->fetch_object($resql2);
  284. if ($obj2){
  285. print "<li>";
  286. print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$obj2->rowid.'">'.$obj2->ref.'</a>';
  287. print ' - '.$obj2->label;
  288. print " - ".money_format("%i €",$obj2->price);
  289. print "</li>";
  290. }
  291. $i2++;
  292. }
  293. }
  294. }
  295. // You can use here results
  296. print '</ul></td><td align="center">';
  297. print '<a href="'.$url.'?id='.$obj->rowid.'&action=delete">X</a>';
  298. print '</td></tr>';
  299. }
  300. $i++;
  301. }
  302. }
  303. }
  304. else
  305. {
  306. $error++;
  307. dol_print_error($db);
  308. }
  309. print '</table>'."\n";
  310. }
  311. ?>
  312. <!--/div-->
  313. </div>
  314. </div>
  315. <?php
  316. // End of page
  317. llxFooter();
  318. $db->close();
  319. ?>