PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Products/addPbProductRelToDB.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 61 lines | 47 code | 2 blank | 12 comment | 9 complexity | 5f70af3ea1e077832f4ca059cb530f41 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /*+********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ********************************************************************************/
  10. require_once('include/database/PearDatabase.php');
  11. require_once('user_privileges/default_module_view.php');
  12. global $adb,$singlepane_view;
  13. global $log;
  14. $idlist = vtlib_purify($_POST['idlist']);
  15. $returnmodule=vtlib_purify($_REQUEST['return_module']);
  16. $returnaction=vtlib_purify($_REQUEST['return_action']);
  17. $pricebook_id=vtlib_purify($_REQUEST['pricebook_id']);
  18. $productid=vtlib_purify($_REQUEST['product_id']);
  19. $parenttab = getParentTab();
  20. if(isset($_REQUEST['pricebook_id']) && $_REQUEST['pricebook_id']!='')
  21. {
  22. $currency_id = getPriceBookCurrency($pricebook_id);
  23. //split the string and store in an array
  24. $storearray = explode(";",$idlist);
  25. foreach($storearray as $id)
  26. {
  27. if($id != '') {
  28. $lp_name = $id.'_listprice';
  29. $list_price = CurrencyField::convertToDBFormat($_REQUEST[$lp_name], null, false);
  30. //Updating the vtiger_pricebook product rel vtiger_table
  31. $log->info("Products :: Inserting vtiger_products to price book");
  32. $query= "insert into vtiger_pricebookproductrel (pricebookid,productid,listprice,usedcurrency) values(?,?,?,?)";
  33. $adb->pquery($query, array($pricebook_id,$id,$list_price,$currency_id));
  34. }
  35. }
  36. if($singlepane_view == 'true')
  37. header("Location: index.php?module=PriceBooks&action=DetailView&record=$pricebook_id&parenttab=$parenttab");
  38. else
  39. header("Location: index.php?module=PriceBooks&action=CallRelatedList&record=$pricebook_id&parenttab=$parenttab");
  40. }
  41. elseif(isset($_REQUEST['product_id']) && $_REQUEST['product_id']!='')
  42. {
  43. //split the string and store in an array
  44. $storearray = explode(";",$idlist);
  45. foreach($storearray as $id)
  46. {
  47. if($id != '') {
  48. $currency_id = getPriceBookCurrency($id);
  49. $lp_name = $id.'_listprice';
  50. $list_price = CurrencyField::convertToDBFormat($_REQUEST[$lp_name], null, false);
  51. //Updating the vtiger_pricebook product rel vtiger_table
  52. $log->info("Products :: Inserting PriceBooks to Product");
  53. $query= "insert into vtiger_pricebookproductrel (pricebookid,productid,listprice,usedcurrency) values(?,?,?,?)";
  54. $adb->pquery($query, array($id,$productid,$list_price,$currency_id));
  55. }
  56. }
  57. header("Location: index.php?module=$returnmodule&action=$returnaction&record=$productid&parenttab=$parenttab");
  58. }
  59. ?>