PageRenderTime 51ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Reports/SaveAndRun.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 425 lines | 352 code | 40 blank | 33 comment | 70 complexity | 9874894a7260ae5a433eafd0a2fd167e 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. ********************************************************************************/
  11. global $theme;
  12. $theme_path="themes/".$theme."/";
  13. $image_path=$theme_path."images/";
  14. require_once('modules/CustomView/CustomView.php');
  15. require_once("config.php");
  16. require_once('modules/Reports/Reports.php');
  17. require_once('include/logging.php');
  18. require_once("modules/Reports/ReportRun.php");
  19. require_once('include/utils/utils.php');
  20. require_once('Smarty_setup.php');
  21. global $adb,$mod_strings,$app_strings;
  22. $reportid = vtlib_purify($_REQUEST["record"]);
  23. $folderid = vtlib_purify($_REQUEST["folderid"]);
  24. $now_action = vtlib_purify($_REQUEST['action']);
  25. $sql = "select * from vtiger_report where reportid=?";
  26. $res = $adb->pquery($sql, array($reportid));
  27. $Report_ID = $adb->query_result($res,0,'reportid');
  28. if(empty($folderid)) {
  29. $folderid = $adb->query_result($res,0,'folderid');
  30. }
  31. $reporttype = $adb->query_result($res,0,'reporttype');
  32. $showCharts = false;
  33. if($reporttype == 'summary'){
  34. $showCharts = true;
  35. }
  36. //END Customization
  37. $numOfRows = $adb->num_rows($res);
  38. if($numOfRows > 0) {
  39. global $primarymodule,$secondarymodule,$orderbylistsql,$orderbylistcolumns,$ogReport;
  40. //added to fix the ticket #5117
  41. global $current_user;
  42. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  43. $ogReport = new Reports($reportid);
  44. $primarymodule = $ogReport->primodule;
  45. $restrictedmodules = array();
  46. if($ogReport->secmodule!='')
  47. $rep_modules = split(":",$ogReport->secmodule);
  48. else
  49. $rep_modules = array();
  50. array_push($rep_modules,$primarymodule);
  51. $modules_permitted = true;
  52. $modules_export_permitted = true;
  53. foreach($rep_modules as $mod){
  54. if(isPermitted($mod,'index')!= "yes" || vtlib_isModuleActive($mod)==false){
  55. $modules_permitted = false;
  56. $restrictedmodules[] = $mod;
  57. }
  58. if(isPermitted("$mod",'Export','')!='yes')
  59. $modules_export_permitted = false;
  60. }
  61. if(isPermitted($primarymodule,'index') == "yes" && $modules_permitted == true) {
  62. $oReportRun = new ReportRun($reportid);
  63. require_once 'include/Zend/Json.php';
  64. $json = new Zend_Json();
  65. $advft_criteria = $_REQUEST['advft_criteria'];
  66. if(!empty($advft_criteria)) $advft_criteria = $json->decode($advft_criteria);
  67. $advft_criteria_groups = $_REQUEST['advft_criteria_groups'];
  68. if(!empty($advft_criteria_groups)) $advft_criteria_groups = $json->decode($advft_criteria_groups);
  69. if($_REQUEST['submode'] == 'saveCriteria') {
  70. updateAdvancedCriteria($reportid,$advft_criteria,$advft_criteria_groups);
  71. }
  72. $filtersql = $oReportRun->RunTimeAdvFilter($advft_criteria,$advft_criteria_groups);
  73. $list_report_form = new vtigerCRM_Smarty;
  74. //Monolithic phase 6 changes
  75. if($showCharts == true){
  76. $list_report_form->assign("SHOWCHARTS",$showCharts);
  77. require_once 'modules/Reports/CustomReportUtils.php';
  78. require_once 'include/ChartUtils.php';
  79. $groupBy = $oReportRun->getGroupingList($reportid);
  80. if(!empty($groupBy)){
  81. foreach ($groupBy as $key => $value) {
  82. //$groupByConditon = explode(" ",$value);
  83. //$groupByNew = explode("'",$groupByConditon[0]);
  84. list($tablename,$colname,$module_field,$fieldname,$single) = split(":",$key);
  85. list($module,$field)= split("_",$module_field);
  86. $fieldDetails = $key;
  87. break;
  88. }
  89. //$groupByField = $oReportRun->GetFirstSortByField($reportid);
  90. $queryReports = CustomReportUtils::getCustomReportsQuery($Report_ID,$filtersql);
  91. $queryResult = $adb->pquery($queryReports,array());
  92. //ChartUtils::generateChartDataFromReports($queryResult, strtolower($groupByNew[1]));
  93. if($adb->num_rows($queryResult)){
  94. $pieChart = ChartUtils::getReportPieChart($queryResult, strtolower($module_field),$fieldDetails,$reportid);
  95. $barChart = ChartUtils::getReportBarChart($queryResult, strtolower($module_field),$fieldDetails,$reportid);
  96. $list_report_form->assign("PIECHART",$pieChart);
  97. $list_report_form->assign("BARCHART",$barChart);
  98. }
  99. else{
  100. $showCharts = false;
  101. }
  102. }
  103. else{
  104. $showCharts = false;
  105. }
  106. $list_report_form->assign("SHOWCHARTS",$showCharts);
  107. }
  108. //Monolithic Changes Ends
  109. // Performance Optimization: Direct output of the report result
  110. if($_REQUEST['submode'] == 'generateReport' && empty($advft_criteria)) {
  111. $filtersql = '';
  112. }
  113. $sshtml = array();
  114. $totalhtml = '';
  115. $list_report_form->assign("DIRECT_OUTPUT", true);
  116. $list_report_form->assign_by_ref("__REPORT_RUN_INSTANCE", $oReportRun);
  117. $list_report_form->assign_by_ref("__REPORT_RUN_FILTER_SQL", $filtersql);
  118. //Ends
  119. $ogReport->getPriModuleColumnsList($ogReport->primodule);
  120. $ogReport->getSecModuleColumnsList($ogReport->secmodule);
  121. $ogReport->getAdvancedFilterList($reportid);
  122. $COLUMNS_BLOCK = getPrimaryColumns_AdvFilter_HTML($ogReport->primodule, $ogReport);
  123. $COLUMNS_BLOCK .= getSecondaryColumns_AdvFilter_HTML($ogReport->secmodule, $ogReport);
  124. $list_report_form->assign("COLUMNS_BLOCK", $COLUMNS_BLOCK);
  125. $FILTER_OPTION = Reports::getAdvCriteriaHTML();
  126. $list_report_form->assign("FOPTION",$FILTER_OPTION);
  127. $rel_fields = $ogReport->adv_rel_fields;
  128. $list_report_form->assign("REL_FIELDS",Zend_Json::encode($rel_fields));
  129. $list_report_form->assign("CRITERIA_GROUPS",$ogReport->advft_criteria);
  130. $list_report_form->assign("MOD", $mod_strings);
  131. $list_report_form->assign("APP", $app_strings);
  132. $list_report_form->assign("IMAGE_PATH", $image_path);
  133. $list_report_form->assign("REPORTID", $reportid);
  134. $list_report_form->assign("IS_EDITABLE", $ogReport->is_editable);
  135. $list_report_form->assign("REP_FOLDERS",$ogReport->sgetRptFldr());
  136. $list_report_form->assign("REPORTNAME", htmlspecialchars($ogReport->reportname,ENT_QUOTES,$default_charset));
  137. if(is_array($sshtml))$list_report_form->assign("REPORTHTML", $sshtml);
  138. else $list_report_form->assign("ERROR_MSG", getTranslatedString('LBL_REPORT_GENERATION_FAILED', $currentModule) . "<br>" . $sshtml);
  139. $list_report_form->assign("REPORTTOTHTML", $totalhtml);
  140. $list_report_form->assign("FOLDERID", $folderid);
  141. $list_report_form->assign("DATEFORMAT",$current_user->date_format);
  142. $list_report_form->assign("JS_DATEFORMAT",parse_calendardate($app_strings['NTC_DATE_FORMAT']));
  143. if($modules_export_permitted==true){
  144. $list_report_form->assign("EXPORT_PERMITTED","YES");
  145. } else {
  146. $list_report_form->assign("EXPORT_PERMITTED","NO");
  147. }
  148. $rep_in_fldr = $ogReport->sgetRptsforFldr($folderid);
  149. for($i=0;$i<count($rep_in_fldr);$i++){
  150. $rep_id = $rep_in_fldr[$i]['reportid'];
  151. $rep_name = $rep_in_fldr[$i]['reportname'];
  152. $reports_array[$rep_id]=$rep_name;
  153. }
  154. if($_REQUEST['mode'] != 'ajax')
  155. {
  156. $list_report_form->assign("REPINFOLDER", $reports_array);
  157. include('modules/Vtiger/header.php');
  158. $list_report_form->display('ReportRun.tpl');
  159. }
  160. else
  161. {
  162. $list_report_form->display('ReportRunContents.tpl');
  163. }
  164. } else {
  165. if($_REQUEST['mode'] != 'ajax') {
  166. include('modules/Vtiger/header.php');
  167. }
  168. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  169. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 80%; position: relative; z-index: 10000000;'>
  170. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  171. <tbody><tr>
  172. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  173. <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>
  174. </tr>
  175. <tr>
  176. <td class='small' align='right' nowrap='nowrap'>
  177. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br> </td>
  178. </tr>
  179. </tbody></table>
  180. </div>";
  181. echo "</td></tr></table>";
  182. }
  183. } else {
  184. echo "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
  185. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  186. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 80%; position: relative; z-index: 10000000;'>
  187. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  188. <tbody><tr>
  189. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  190. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>".$mod_strings['LBL_REPORT_DELETED']."</span></td>
  191. </tr>
  192. <tr>
  193. <td class='small' align='right' nowrap='nowrap'>
  194. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br> </td>
  195. </tr>
  196. </tbody></table>
  197. </div>";
  198. echo "</td></tr></table>";
  199. }
  200. /** Function to get the StdfilterHTML strings for the given primary module
  201. * @ param $module : Type String
  202. * @ param $selected : Type String(optional)
  203. * This Generates the HTML Combo strings for the standard filter for the given reports module
  204. * This Returns a HTML sring
  205. */
  206. function getPrimaryStdFilterHTML($module,$selected="")
  207. {
  208. global $app_list_strings;
  209. global $ogReport;
  210. global $current_language;
  211. $ogReport->oCustomView=new CustomView();
  212. $result = $ogReport->oCustomView->getStdCriteriaByModule($module);
  213. $mod_strings = return_module_language($current_language,$module);
  214. if(isset($result))
  215. {
  216. foreach($result as $key=>$value)
  217. {
  218. if(isset($mod_strings[$value]))
  219. {
  220. if($key == $selected)
  221. {
  222. $shtml .= "<option selected value=\"".$key."\">".getTranslatedString($module,$module)." - ".$mod_strings[$value]."</option>";
  223. }else
  224. {
  225. $shtml .= "<option value=\"".$key."\">".getTranslatedString($module,$module)." - ".$mod_strings[$value]."</option>";
  226. }
  227. }else
  228. {
  229. if($key == $selected)
  230. {
  231. $shtml .= "<option selected value=\"".$key."\">".getTranslatedString($module,$module)." - ".$value."</option>";
  232. }else
  233. {
  234. $shtml .= "<option value=\"".$key."\">".getTranslatedString($module,$module)." - ".$value."</option>";
  235. }
  236. }
  237. }
  238. }
  239. return $shtml;
  240. }
  241. /** Function to get the StdfilterHTML strings for the given secondary module
  242. * @ param $module : Type String
  243. * @ param $selected : Type String(optional)
  244. * This Generates the HTML Combo strings for the standard filter for the given reports module
  245. * This Returns a HTML sring
  246. */
  247. function getSecondaryStdFilterHTML($module,$selected="")
  248. {
  249. global $app_list_strings;
  250. global $ogReport;
  251. global $current_language;
  252. $ogReport->oCustomView=new CustomView();
  253. if($module != "")
  254. {
  255. $secmodule = explode(":",$module);
  256. for($i=0;$i < count($secmodule) ;$i++)
  257. {
  258. $result = $ogReport->oCustomView->getStdCriteriaByModule($secmodule[$i]);
  259. $mod_strings = return_module_language($current_language,$secmodule[$i]);
  260. if(isset($result))
  261. {
  262. foreach($result as $key=>$value)
  263. {
  264. if(isset($mod_strings[$value]))
  265. {
  266. if($key == $selected)
  267. {
  268. $shtml .= "<option selected value=\"".$key."\">".getTranslatedString($secmodule[$i],$secmodule[$i])." - ".$mod_strings[$value]."</option>";
  269. }else
  270. {
  271. $shtml .= "<option value=\"".$key."\">".getTranslatedString($secmodule[$i],$secmodule[$i])." - ".$mod_strings[$value]."</option>";
  272. }
  273. }else
  274. {
  275. if($key == $selected)
  276. {
  277. $shtml .= "<option selected value=\"".$key."\">".getTranslatedString($secmodule[$i],$secmodule[$i])." - ".$value."</option>";
  278. }else
  279. {
  280. $shtml .= "<option value=\"".$key."\">".getTranslatedString($secmodule[$i],$secmodule[$i])." - ".$value."</option>";
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. return $shtml;
  288. }
  289. function getPrimaryColumns_AdvFilter_HTML($module, $ogReport, $selected='') {
  290. global $app_list_strings, $current_language;
  291. $mod_strings = return_module_language($current_language,$module);
  292. $block_listed = array();
  293. foreach($ogReport->module_list[$module] as $key=>$value)
  294. {
  295. if(isset($ogReport->pri_module_columnslist[$module][$value]) && !$block_listed[$value])
  296. {
  297. $block_listed[$value] = true;
  298. $shtml .= "<optgroup label=\"".$app_list_strings['moduleList'][$module]." ".getTranslatedString($value)."\" class=\"select\" style=\"border:none\">";
  299. foreach($ogReport->pri_module_columnslist[$module][$value] as $field=>$fieldlabel)
  300. {
  301. if(isset($mod_strings[$fieldlabel]))
  302. {
  303. //fix for ticket 5191
  304. $selected = decode_html($selected);
  305. $field = decode_html($field);
  306. //fix ends
  307. if($selected == $field)
  308. {
  309. $shtml .= "<option selected value=\"".$field."\">".$mod_strings[$fieldlabel]."</option>";
  310. }else
  311. {
  312. $shtml .= "<option value=\"".$field."\">".$mod_strings[$fieldlabel]."</option>";
  313. }
  314. }else
  315. {
  316. if($selected == $field)
  317. {
  318. $shtml .= "<option selected value=\"".$field."\">".$fieldlabel."</option>";
  319. }else
  320. {
  321. $shtml .= "<option value=\"".$field."\">".$fieldlabel."</option>";
  322. }
  323. }
  324. }
  325. }
  326. }
  327. return $shtml;
  328. }
  329. function getSecondaryColumns_AdvFilter_HTML($module, $ogReport, $selected="") {
  330. global $app_list_strings;
  331. global $current_language;
  332. if($module != "")
  333. {
  334. $secmodule = explode(":",$module);
  335. for($i=0;$i < count($secmodule) ;$i++)
  336. {
  337. $mod_strings = return_module_language($current_language,$secmodule[$i]);
  338. if(vtlib_isModuleActive($secmodule[$i])){
  339. $block_listed = array();
  340. foreach($ogReport->module_list[$secmodule[$i]] as $key=>$value)
  341. {
  342. if(isset($ogReport->sec_module_columnslist[$secmodule[$i]][$value]) && !$block_listed[$value])
  343. {
  344. $block_listed[$value] = true;
  345. $shtml .= "<optgroup label=\"".$app_list_strings['moduleList'][$secmodule[$i]]." ".getTranslatedString($value)."\" class=\"select\" style=\"border:none\">";
  346. foreach($ogReport->sec_module_columnslist[$secmodule[$i]][$value] as $field=>$fieldlabel)
  347. {
  348. if(isset($mod_strings[$fieldlabel]))
  349. {
  350. if($selected == $field)
  351. {
  352. $shtml .= "<option selected value=\"".$field."\">".$mod_strings[$fieldlabel]."</option>";
  353. }else
  354. {
  355. $shtml .= "<option value=\"".$field."\">".$mod_strings[$fieldlabel]."</option>";
  356. }
  357. }else
  358. {
  359. if($selected == $field)
  360. {
  361. $shtml .= "<option selected value=\"".$field."\">".$fieldlabel."</option>";
  362. }else
  363. {
  364. $shtml .= "<option value=\"".$field."\">".$fieldlabel."</option>";
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. return $shtml;
  374. }
  375. function getAdvCriteria_HTML($adv_filter_options, $selected="") {
  376. foreach($adv_filter_options as $key=>$value) {
  377. if($selected == $key) {
  378. $shtml .= "<option selected value=\"".$key."\">".$value."</option>";
  379. } else {
  380. $shtml .= "<option value=\"".$key."\">".$value."</option>";
  381. }
  382. }
  383. return $shtml;
  384. }
  385. ?>