PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Reports/DuplicateReport.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 169 lines | 130 code | 31 blank | 8 comment | 22 complexity | fb4d5d2efca31b4cfa34d6d293ccfc5a 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('modules/Reports/Reports.php');
  11. require_once('include/logging.php');
  12. require_once('include/database/PearDatabase.php');
  13. require_once 'include/Zend/Json.php';
  14. global $adb,$mod_strings,$app_strings;
  15. $reportid = vtlib_purify($_REQUEST['record']);
  16. $newreportname = vtlib_purify($_REQUEST['newreportname']);
  17. $newreportdescription = vtlib_purify($_REQUEST['newreportdescription']);
  18. $newreportfolder = vtlib_purify($_REQUEST['newreportfolder']);
  19. $sql = "select * from vtiger_report where reportid=?";
  20. $res = $adb->pquery($sql, array($reportid));
  21. $Report_ID = $adb->query_result($res,0,'reportid');
  22. $numOfRows = $adb->num_rows($res);
  23. $response_array = array();
  24. if($numOfRows > 0) {
  25. global $current_user;
  26. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  27. $ogReport = new Reports($reportid);
  28. $primarymodule = $ogReport->primodule;
  29. $restrictedmodules = array();
  30. if($ogReport->secmodule!='')
  31. $rep_modules = split(":",$ogReport->secmodule);
  32. else
  33. $rep_modules = array();
  34. array_push($rep_modules,$primarymodule);
  35. $modules_permitted = true;
  36. foreach($rep_modules as $mod) {
  37. if(isPermitted($mod,'index')!= "yes" || vtlib_isModuleActive($mod)==false) {
  38. $modules_permitted = false;
  39. $restrictedmodules[] = $mod;
  40. }
  41. }
  42. if(isPermitted($primarymodule,'index') == "yes" && $modules_permitted == true) {
  43. $genQueryId = $adb->getUniqueID("vtiger_selectquery");
  44. if($genQueryId != "") {
  45. $response_array['reportid'] = $genQueryId;
  46. $response_array['folderid'] = $newreportfolder;
  47. $response_array['errormessage'] = '';
  48. $iquerysql = "insert into vtiger_selectquery (QUERYID,STARTINDEX,NUMOFOBJECTS) values (?,?,?)";
  49. $iquerysqlresult = $adb->pquery($iquerysql, array($genQueryId,0,0));
  50. $log->info("Reports :: Save->Successfully saved vtiger_selectquery");
  51. if($iquerysqlresult != false) {
  52. $adb->pquery("INSERT INTO vtiger_selectcolumn (queryid,columnindex,columnname)
  53. SELECT $genQueryId, columnindex, columnname FROM vtiger_selectcolumn WHERE queryid = ?", array($reportid));
  54. $adb->pquery("INSERT INTO vtiger_reportsharing (reportid,shareid,setype)
  55. SELECT $genQueryId,shareid,setype FROM vtiger_reportsharing WHERE reportid=?", array($reportid));
  56. $owner = $current_user->id;
  57. $ireportresult = $adb->pquery("INSERT INTO vtiger_report (reportid,folderid,reportname,description,reporttype,queryid,state,owner,sharingtype)
  58. SELECT $genQueryId,$newreportfolder,'$newreportname','$newreportdescription',reporttype,$genQueryId,state,$owner,sharingtype FROM vtiger_report WHERE reportid=?",
  59. array($reportid));
  60. $log->info("Reports :: Save->Successfully saved vtiger_report");
  61. if($ireportresult != false) {
  62. $adb->pquery("INSERT INTO vtiger_reportmodules (reportmodulesid,primarymodule,secondarymodules)
  63. SELECT $genQueryId,primarymodule,secondarymodules FROM vtiger_reportmodules WHERE reportmodulesid=?", array($reportid));
  64. $log->info("Reports :: Save->Successfully saved vtiger_reportmodules");
  65. $adb->pquery("INSERT INTO vtiger_reportsortcol (sortcolid,reportid,columnname,sortorder)
  66. SELECT sortcolid,$genQueryId,columnname,sortorder FROM vtiger_reportsortcol WHERE reportid=?", array($reportid));
  67. $log->info("Reports :: Save->Successfully saved vtiger_reportsortcol");
  68. $adb->pquery("INSERT INTO vtiger_reportdatefilter (datefilterid,datecolumnname,datefilter,startdate,enddate)
  69. SELECT $genQueryId,datecolumnname,datefilter,startdate,enddate FROM vtiger_reportdatefilter WHERE datefilterid=?", array($reportid));
  70. $log->info("Reports :: Save->Successfully saved vtiger_reportdatefilter");
  71. $adb->pquery("INSERT INTO vtiger_reportsummary (reportsummaryid,summarytype,columnname)
  72. SELECT $genQueryId,summarytype,columnname FROM vtiger_reportsummary WHERE reportsummaryid=?", array($reportid));
  73. $log->info("Reports :: Save->Successfully saved vtiger_reportsummary");
  74. $adb->pquery("INSERT INTO vtiger_relcriteria (queryid,columnindex,columnname,comparator,value,groupid,column_condition)
  75. SELECT $genQueryId,columnindex,columnname,comparator,value,groupid,column_condition FROM vtiger_relcriteria WHERE queryid=?", array($reportid));
  76. $log->info("Reports :: Save->Successfully saved vtiger_relcriteria");
  77. $adb->pquery("INSERT INTO vtiger_relcriteria_grouping (groupid,queryid,group_condition,condition_expression)
  78. SELECT groupid,$genQueryId,group_condition,condition_expression FROM vtiger_relcriteria_grouping WHERE queryid=?", array($reportid));
  79. $log->info("Reports :: Save->Successfully saved vtiger_relcriteria_grouping");
  80. $advft_criteria = $_REQUEST['advft_criteria'];
  81. $advft_criteria_groups = $_REQUEST['advft_criteria_groups'];
  82. if(!empty($advft_criteria) && !empty($advft_criteria_groups)) {
  83. $json = new Zend_Json();
  84. $advft_criteria = $json->decode($advft_criteria);
  85. $advft_criteria_groups = $json->decode($advft_criteria_groups);
  86. updateAdvancedCriteria($genQueryId,$advft_criteria,$advft_criteria_groups);
  87. }
  88. } else {
  89. $errormessage = "<font color='red'><B>Error Message<ul>
  90. <li><font color='red'>Error while inserting the record</font>
  91. </ul></B></font> <br>" ;
  92. $response_array['errormessage'] = $errormessage;
  93. }
  94. } else {
  95. $errormessage = "<font color='red'><B>Error Message<ul>
  96. <li><font color='red'>Error while inserting the record</font>
  97. </ul></B></font> <br>" ;
  98. $response_array['errormessage'] = $errormessage;
  99. }
  100. }
  101. } else {
  102. $errormessage = "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  103. $errormessage .= "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 80%; position: relative; z-index: 10000000;'>
  104. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  105. <tbody><tr>
  106. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  107. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>".$mod_strings['LBL_NO_ACCESS']." : ".implode(",",$restrictedmodules)." </span></td>
  108. </tr>
  109. <tr>
  110. <td class='small' align='right' nowrap='nowrap'>
  111. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br></td>
  112. </tr>
  113. </tbody></table>
  114. </div>";
  115. $errormessage .= "</td></tr></table>";
  116. $response_array['errormessage'] = $errormessage;
  117. }
  118. } else {
  119. $errormessage = "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
  120. $errormessage .= "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  121. $errormessage .= "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 80%; position: relative; z-index: 10000000;'>
  122. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  123. <tbody><tr>
  124. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  125. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>".$mod_strings['LBL_REPORT_DELETED']."</span></td>
  126. </tr>
  127. <tr>
  128. <td class='small' align='right' nowrap='nowrap'>
  129. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br> </td>
  130. </tr>
  131. </tbody></table>
  132. </div>";
  133. $errormessage .= "</td></tr></table>";
  134. $response_array['errormessage'] = $errormessage;
  135. }
  136. $json = new Zend_Json();
  137. echo $json->encode($response_array);
  138. ?>