PageRenderTime 67ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Reports/Reports.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 1735 lines | 1355 code | 227 blank | 153 comment | 272 complexity | ffec65a5e07e6720c164899c319e2743 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. require_once('include/database/PearDatabase.php');
  12. require_once('data/CRMEntity.php');
  13. require_once('include/utils/UserInfoUtil.php');
  14. require_once 'modules/Reports/ReportUtils.php';
  15. global $calpath;
  16. global $app_strings,$mod_strings;
  17. global $app_list_strings;
  18. global $modules;
  19. global $blocks;
  20. global $adv_filter_options;
  21. global $log;
  22. global $report_modules;
  23. global $related_modules;
  24. global $old_related_modules;
  25. $adv_filter_options = array("e"=>"equals",
  26. "n"=>"not equal to",
  27. "s"=>"starts with",
  28. "ew"=>"ends with",
  29. "c"=>"contains",
  30. "k"=>"does not contain",
  31. "l"=>"less than",
  32. "g"=>"greater than",
  33. "m"=>"less or equal",
  34. "h"=>"greater or equal",
  35. "bw"=>"between",
  36. "a"=>"after",
  37. "b"=>"before",
  38. );
  39. //$report_modules = Array('Faq','Rss','Portal','Recyclebin','Emails','Reports','Dashboard','Home','Activities'
  40. // );
  41. $old_related_modules = Array('Accounts'=>Array('Potentials','Contacts','Products','Quotes','Invoice'),
  42. 'Contacts'=>Array('Accounts','Potentials','Quotes','PurchaseOrder'),
  43. 'Potentials'=>Array('Accounts','Contacts','Quotes'),
  44. 'Calendar'=>Array('Leads','Accounts','Contacts','Potentials'),
  45. 'Products'=>Array('Accounts','Contacts'),
  46. 'HelpDesk'=>Array('Products'),
  47. 'Quotes'=>Array('Accounts','Contacts','Potentials'),
  48. 'PurchaseOrder'=>Array('Contacts'),
  49. 'Invoice'=>Array('Accounts'),
  50. 'Campaigns'=>Array('Products'),
  51. );
  52. $related_modules =Array();
  53. class Reports extends CRMEntity{
  54. /**
  55. * This class has the informations for Reports and inherits class CRMEntity and
  56. * has the variables required to generate,save,restore vtiger_reports
  57. * and also the required functions for the same
  58. * Contributor(s): ______________________________________..
  59. */
  60. var $srptfldridjs;
  61. var $column_fields = Array();
  62. var $sort_fields = Array();
  63. var $sort_values = Array();
  64. var $id;
  65. var $mode;
  66. var $mcount;
  67. var $startdate;
  68. var $enddate;
  69. var $ascdescorder;
  70. var $stdselectedfilter;
  71. var $stdselectedcolumn;
  72. var $primodule;
  73. var $secmodule;
  74. var $columnssummary;
  75. var $is_editable;
  76. var $reporttype;
  77. var $reportname;
  78. var $reportdescription;
  79. var $folderid;
  80. var $module_blocks;
  81. var $pri_module_columnslist;
  82. var $sec_module_columnslist;
  83. var $advft_criteria;
  84. var $adv_rel_fields = Array();
  85. var $module_list = Array();
  86. /** Function to set primodule,secmodule,reporttype,reportname,reportdescription,folderid for given vtiger_reportid
  87. * This function accepts the vtiger_reportid as argument
  88. * It sets primodule,secmodule,reporttype,reportname,reportdescription,folderid for the given vtiger_reportid
  89. */
  90. function Reports($reportid="")
  91. {
  92. global $adb,$current_user,$theme,$mod_strings;
  93. $this->initListOfModules();
  94. if($reportid != "")
  95. {
  96. // Lookup information in cache first
  97. $cachedInfo = VTCacheUtils::lookupReport_Info($current_user->id, $reportid);
  98. $subordinate_users = VTCacheUtils::lookupReport_SubordinateUsers($reportid);
  99. if($cachedInfo === false) {
  100. $ssql = "select vtiger_reportmodules.*,vtiger_report.* from vtiger_report inner join vtiger_reportmodules on vtiger_report.reportid = vtiger_reportmodules.reportmodulesid";
  101. $ssql .= " where vtiger_report.reportid = ?";
  102. $params = array($reportid);
  103. require_once('include/utils/GetUserGroups.php');
  104. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  105. $userGroups = new GetUserGroups();
  106. $userGroups->getAllUserGroups($current_user->id);
  107. $user_groups = $userGroups->user_groups;
  108. if(!empty($user_groups) && $is_admin==false){
  109. $user_group_query = " (shareid IN (".generateQuestionMarks($user_groups).") AND setype='groups') OR";
  110. array_push($params, $user_groups);
  111. }
  112. $non_admin_query = " vtiger_report.reportid IN (SELECT reportid from vtiger_reportsharing WHERE $user_group_query (shareid=? AND setype='users'))";
  113. if($is_admin==false){
  114. $ssql .= " and ( (".$non_admin_query.") or vtiger_report.sharingtype='Public' or vtiger_report.owner = ? or vtiger_report.owner in(select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'))";
  115. array_push($params, $current_user->id);
  116. array_push($params, $current_user->id);
  117. }
  118. $query = $adb->pquery("select userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'",array());
  119. $subordinate_users = Array();
  120. for($i=0;$i<$adb->num_rows($query);$i++){
  121. $subordinate_users[] = $adb->query_result($query,$i,'userid');
  122. }
  123. // Update subordinate user information for re-use
  124. VTCacheUtils::updateReport_SubordinateUsers($reportid, $subordinate_users);
  125. $result = $adb->pquery($ssql, $params);
  126. if($result && $adb->num_rows($result)) {
  127. $reportmodulesrow = $adb->fetch_array($result);
  128. // Update information in cache now
  129. VTCacheUtils::updateReport_Info(
  130. $current_user->id, $reportid, $reportmodulesrow["primarymodule"],
  131. $reportmodulesrow["secondarymodules"], $reportmodulesrow["reporttype"],
  132. $reportmodulesrow["reportname"], $reportmodulesrow["description"],
  133. $reportmodulesrow["folderid"], $reportmodulesrow["owner"]
  134. );
  135. }
  136. // Re-look at cache to maintain code-consistency below
  137. $cachedInfo = VTCacheUtils::lookupReport_Info($current_user->id, $reportid);
  138. }
  139. if($cachedInfo) {
  140. $this->primodule = $cachedInfo["primarymodule"];
  141. $this->secmodule = $cachedInfo["secondarymodules"];
  142. $this->reporttype = $cachedInfo["reporttype"];
  143. $this->reportname = decode_html($cachedInfo["reportname"]);
  144. $this->reportdescription = decode_html($cachedInfo["description"]);
  145. $this->folderid = $cachedInfo["folderid"];
  146. if($is_admin==true || in_array($cachedInfo["owner"],$subordinate_users) || $cachedInfo["owner"]==$current_user->id)
  147. $this->is_editable = 'true';
  148. else
  149. $this->is_editable = 'false';
  150. } else {
  151. if($_REQUEST['mode'] != 'ajax')
  152. {
  153. include('modules/Vtiger/header.php');
  154. }
  155. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  156. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 80%; position: relative; z-index: 10000000;'>
  157. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  158. <tbody><tr>
  159. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme) ."' ></td>
  160. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>You are not allowed to View this Report </span></td>
  161. </tr>
  162. <tr>
  163. <td class='small' align='right' nowrap='nowrap'>
  164. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br> </td>
  165. </tr>
  166. </tbody></table>
  167. </div>";
  168. echo "</td></tr></table>";
  169. break;
  170. }
  171. }
  172. }
  173. // Update the module list for listing columns for report creation.
  174. function updateModuleList($module) {
  175. global $adb;
  176. if (!isset($module)) return;
  177. require_once('include/utils/utils.php');
  178. $tabid = getTabid($module);
  179. if ($module == 'Calendar') {
  180. $tabid = array(9, 16);
  181. }
  182. $sql = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid IN (". generateQuestionMarks($tabid) .")";
  183. $res = $adb->pquery($sql, array($tabid));
  184. $noOfRows = $adb->num_rows($res);
  185. if ($noOfRows <= 0) return;
  186. for($index = 0; $index < $noOfRows; ++$index) {
  187. $blockid = $adb->query_result($res,$index,'blockid');
  188. if(in_array($blockid, $this->module_list[$module])) continue;
  189. $blockid_list[] = $blockid;
  190. $blocklabel = $adb->query_result($res,$index,'blocklabel');
  191. $this->module_list[$module][$blocklabel] = $blockid;
  192. }
  193. }
  194. // Initializes the module list for listing columns for report creation.
  195. function initListOfModules() {
  196. global $adb, $current_user, $old_related_modules;
  197. $restricted_modules = array('Emails','Events','Webmails');
  198. $restricted_blocks = array('LBL_IMAGE_INFORMATION','LBL_COMMENTS','LBL_COMMENT_INFORMATION');
  199. $this->module_id = array();
  200. $this->module_list = array();
  201. // Prefetch module info to check active or not and also get list of tabs
  202. $modulerows = vtlib_prefetchModuleActiveInfo(false);
  203. $cachedInfo = VTCacheUtils::lookupReport_ListofModuleInfos();
  204. if($cachedInfo !== false) {
  205. $this->module_list = $cachedInfo['module_list'];
  206. $this->related_modules = $cachedInfo['related_modules'];
  207. } else {
  208. if($modulerows) {
  209. foreach($modulerows as $resultrow) {
  210. if($resultrow['presence'] == '1') continue; // skip disabled modules
  211. if($resultrow['isentitytype'] != '1') continue; // skip extension modules
  212. if(in_array($resultrow['name'], $restricted_modules)) { // skip restricted modules
  213. continue;
  214. }
  215. if($resultrow['name']!='Calendar'){
  216. $this->module_id[$resultrow['tabid']] = $resultrow['name'];
  217. } else {
  218. $this->module_id[9] = $resultrow['name'];
  219. $this->module_id[16] = $resultrow['name'];
  220. }
  221. $this->module_list[$resultrow['name']] = array();
  222. }
  223. $moduleids = array_keys($this->module_id);
  224. $reportblocks =
  225. $adb->pquery("SELECT blockid, blocklabel, tabid FROM vtiger_blocks WHERE tabid IN (" .generateQuestionMarks($moduleids) .")",
  226. array($moduleids));
  227. $prev_block_label = '';
  228. if($adb->num_rows($reportblocks)) {
  229. while($resultrow = $adb->fetch_array($reportblocks)) {
  230. $blockid = $resultrow['blockid'];
  231. $blocklabel = $resultrow['blocklabel'];
  232. $module = $this->module_id[$resultrow['tabid']];
  233. if(in_array($blocklabel, $restricted_blocks) ||
  234. in_array($blockid, $this->module_list[$module]) ||
  235. isset($this->module_list[$module][getTranslatedString($blocklabel,$module)])
  236. ) {
  237. continue;
  238. }
  239. if(!empty($blocklabel)){
  240. if($module == 'Calendar' && $blocklabel == 'LBL_CUSTOM_INFORMATION')
  241. $this->module_list[$module][$blockid] = getTranslatedString($blocklabel,$module);
  242. else
  243. $this->module_list[$module][$blockid] = getTranslatedString($blocklabel,$module);
  244. $prev_block_label = $blocklabel;
  245. } else {
  246. $this->module_list[$module][$blockid] = getTranslatedString($prev_block_label,$module);
  247. }
  248. }
  249. }
  250. $relatedmodules = $adb->pquery(
  251. "SELECT vtiger_tab.name, vtiger_relatedlists.tabid FROM vtiger_tab
  252. INNER JOIN vtiger_relatedlists on vtiger_tab.tabid=vtiger_relatedlists.related_tabid
  253. WHERE vtiger_tab.isentitytype=1
  254. AND vtiger_tab.name NOT IN(".generateQuestionMarks($restricted_modules).")
  255. AND vtiger_tab.presence = 0 AND vtiger_relatedlists.label!='Activity History'
  256. UNION
  257. SELECT module, vtiger_tab.tabid FROM vtiger_fieldmodulerel
  258. INNER JOIN vtiger_tab on vtiger_tab.name = vtiger_fieldmodulerel.relmodule
  259. WHERE vtiger_tab.isentitytype = 1
  260. AND vtiger_tab.name NOT IN(".generateQuestionMarks($restricted_modules).")
  261. AND vtiger_tab.presence = 0",
  262. array($restricted_modules,$restricted_modules)
  263. );
  264. if($adb->num_rows($relatedmodules)) {
  265. while($resultrow = $adb->fetch_array($relatedmodules)) {
  266. $module = $this->module_id[$resultrow['tabid']];
  267. if(!isset($this->related_modules[$module])) {
  268. $this->related_modules[$module] = array();
  269. }
  270. if($module != $resultrow['name']) {
  271. $this->related_modules[$module][] = $resultrow['name'];
  272. }
  273. // To achieve Backward Compatability with Report relations
  274. if(isset($old_related_modules[$module])){
  275. $rel_mod = array();
  276. foreach($old_related_modules[$module] as $key=>$name){
  277. if(vtlib_isModuleActive($name) && isPermitted($name,'index','')){
  278. $rel_mod[] = $name;
  279. }
  280. }
  281. if(!empty($rel_mod)){
  282. $this->related_modules[$module] = array_merge($this->related_modules[$module],$rel_mod);
  283. $this->related_modules[$module] = array_unique($this->related_modules[$module]);
  284. }
  285. }
  286. }
  287. }
  288. // Put the information in cache for re-use
  289. VTCacheUtils::updateReport_ListofModuleInfos($this->module_list, $this->related_modules);
  290. }
  291. }
  292. }
  293. // END
  294. /** Function to get the Listview of Reports
  295. * This function accepts no argument
  296. * This generate the Reports view page and returns a string
  297. * contains HTML
  298. */
  299. function sgetRptFldr($mode='')
  300. {
  301. global $adb,$log,$mod_strings;
  302. $returndata = Array();
  303. $sql = "select * from vtiger_reportfolder order by folderid";
  304. $result = $adb->pquery($sql, array());
  305. $reportfldrow = $adb->fetch_array($result);
  306. if($mode != '')
  307. {
  308. // Fetch detials of all reports of folder at once
  309. $reportsInAllFolders = $this->sgetRptsforFldr(false);
  310. do
  311. {
  312. if($reportfldrow["state"] == $mode)
  313. {
  314. $details = Array();
  315. $details['state'] = $reportfldrow["state"];
  316. $details['id'] = $reportfldrow["folderid"];
  317. $details['name'] = ($mod_strings[$reportfldrow["foldername"]] == '' ) ? $reportfldrow["foldername"]:$mod_strings[$reportfldrow["foldername"]];
  318. $details['description'] = $reportfldrow["description"];
  319. $details['fname'] = popup_decode_html($details['name']);
  320. $details['fdescription'] = popup_decode_html($reportfldrow["description"]);
  321. $details['details'] = $reportsInAllFolders[$reportfldrow["folderid"]];
  322. $returndata[] = $details;
  323. }
  324. }while($reportfldrow = $adb->fetch_array($result));
  325. }else
  326. {
  327. do
  328. {
  329. $details = Array();
  330. $details['state'] = $reportfldrow["state"];
  331. $details['id'] = $reportfldrow["folderid"];
  332. $details['name'] = ($mod_strings[$reportfldrow["foldername"]] == '' ) ? $reportfldrow["foldername"]:$mod_strings[$reportfldrow["foldername"]];
  333. $details['description'] = $reportfldrow["description"];
  334. $details['fname'] = popup_decode_html($details['name']);
  335. $details['fdescription'] = popup_decode_html($reportfldrow["description"]);
  336. $returndata[] = $details;
  337. }while($reportfldrow = $adb->fetch_array($result));
  338. }
  339. $log->info("Reports :: ListView->Successfully returned vtiger_report folder HTML");
  340. return $returndata;
  341. }
  342. /** Function to get the Reports inside each modules
  343. * This function accepts the folderid
  344. * This Generates the Reports under each Reports module
  345. * This Returns a HTML sring
  346. */
  347. function sgetRptsforFldr($rpt_fldr_id)
  348. {
  349. $srptdetails="";
  350. global $adb;
  351. global $log;
  352. global $mod_strings,$current_user;
  353. $returndata = Array();
  354. require_once('include/utils/UserInfoUtil.php');
  355. $sql = "select vtiger_report.*, vtiger_reportmodules.*, vtiger_reportfolder.folderid from vtiger_report inner join vtiger_reportfolder on vtiger_reportfolder.folderid = vtiger_report.folderid";
  356. $sql .= " inner join vtiger_reportmodules on vtiger_reportmodules.reportmodulesid = vtiger_report.reportid";
  357. $params = array();
  358. // If information is required only for specific report folder?
  359. if($rpt_fldr_id !== false) {
  360. $sql .= " where vtiger_reportfolder.folderid=?";
  361. $params[] = $rpt_fldr_id;
  362. }
  363. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  364. require_once('include/utils/GetUserGroups.php');
  365. $userGroups = new GetUserGroups();
  366. $userGroups->getAllUserGroups($current_user->id);
  367. $user_groups = $userGroups->user_groups;
  368. if(!empty($user_groups) && $is_admin==false){
  369. $user_group_query = " (shareid IN (".generateQuestionMarks($user_groups).") AND setype='groups') OR";
  370. array_push($params, $user_groups);
  371. }
  372. $non_admin_query = " vtiger_report.reportid IN (SELECT reportid from vtiger_reportsharing WHERE $user_group_query (shareid=? AND setype='users'))";
  373. if($is_admin==false){
  374. $sql .= " and ( (".$non_admin_query.") or vtiger_report.sharingtype='Public' or vtiger_report.owner = ? or vtiger_report.owner in(select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'))";
  375. array_push($params, $current_user->id);
  376. array_push($params, $current_user->id);
  377. }
  378. $query = $adb->pquery("select userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'",array());
  379. $subordinate_users = Array();
  380. for($i=0;$i<$adb->num_rows($query);$i++){
  381. $subordinate_users[] = $adb->query_result($query,$i,'userid');
  382. }
  383. $result = $adb->pquery($sql, $params);
  384. $report = $adb->fetch_array($result);
  385. if(count($report)>0)
  386. {
  387. do
  388. {
  389. $report_details = Array();
  390. $report_details ['customizable'] = $report["customizable"];
  391. $report_details ['reportid'] = $report["reportid"];
  392. $report_details ['primarymodule'] = $report["primarymodule"];
  393. $report_details ['secondarymodules'] = $report["secondarymodules"];
  394. $report_details ['state'] = $report["state"];
  395. $report_details ['description'] = $report["description"];
  396. $report_details ['reportname'] = $report["reportname"];
  397. $report_details ['sharingtype'] = $report["sharingtype"];
  398. if($is_admin==true || in_array($report["owner"],$subordinate_users) || $report["owner"]==$current_user->id)
  399. $report_details ['editable'] = 'true';
  400. else
  401. $report_details['editable'] = 'false';
  402. if(isPermitted($report["primarymodule"],'index') == "yes")
  403. $returndata [$report["folderid"]][] = $report_details;
  404. }while($report = $adb->fetch_array($result));
  405. }
  406. if($rpt_fldr_id !== false) {
  407. $returndata = $returndata[$rpt_fldr_id];
  408. }
  409. $log->info("Reports :: ListView->Successfully returned vtiger_report details HTML");
  410. return $returndata;
  411. }
  412. /** Function to get the array of ids
  413. * This function forms the array for the ExpandCollapse
  414. * Javascript
  415. * It returns the array of ids
  416. * Array('1RptFldr','2RptFldr',........,'9RptFldr','10RptFldr')
  417. */
  418. function sgetJsRptFldr()
  419. {
  420. $srptfldr_js = "var ReportListArray=new Array(".$this->srptfldridjs.")
  421. setExpandCollapse()";
  422. return $srptfldr_js;
  423. }
  424. /** Function to set the Primary module vtiger_fields for the given Report
  425. * This function sets the primary module columns for the given Report
  426. * It accepts the Primary module as the argument and set the vtiger_fields of the module
  427. * to the varialbe pri_module_columnslist and returns true if sucess
  428. */
  429. function getPriModuleColumnsList($module)
  430. {
  431. //$this->updateModuleList($module);
  432. foreach($this->module_list[$module] as $key=>$value)
  433. {
  434. $temp = $this->getColumnsListbyBlock($module,$key);
  435. if(!empty($ret_module_list[$module][$value])){
  436. if(!empty($temp)){
  437. $ret_module_list[$module][$value] = array_merge($ret_module_list[$module][$value],$temp);
  438. }
  439. } else {
  440. $ret_module_list[$module][$value] = $this->getColumnsListbyBlock($module,$key);
  441. }
  442. }
  443. $this->pri_module_columnslist = $ret_module_list;
  444. return true;
  445. }
  446. /** Function to set the Secondary module fileds for the given Report
  447. * This function sets the secondary module columns for the given module
  448. * It accepts the module as the argument and set the vtiger_fields of the module
  449. * to the varialbe sec_module_columnslist and returns true if sucess
  450. */
  451. function getSecModuleColumnsList($module)
  452. {
  453. if($module != "")
  454. {
  455. $secmodule = explode(":",$module);
  456. for($i=0;$i < count($secmodule) ;$i++)
  457. {
  458. //$this->updateModuleList($secmodule[$i]);
  459. if($this->module_list[$secmodule[$i]]){
  460. $this->sec_module_columnslist[$secmodule[$i]] = $this->getModuleFieldList(
  461. $secmodule[$i]);
  462. if($this->module_list[$secmodule[$i]] == 'Calendar') {
  463. if($this->module_list['Events']){
  464. $this->sec_module_columnslist['Events'] = $this->getModuleFieldList(
  465. 'Events');
  466. }
  467. }
  468. }
  469. }
  470. }
  471. return true;
  472. }
  473. /**
  474. *
  475. * @param String $module
  476. * @param type $blockIdList
  477. * @param Array $currentFieldList
  478. * @return Array
  479. */
  480. public function getBlockFieldList($module, $blockIdList, $currentFieldList) {
  481. if(!empty($currentFieldList)){
  482. $temp = $this->getColumnsListbyBlock($module,$blockIdList);
  483. if(!empty($temp)){
  484. $currentFieldList = array_merge($currentFieldList,$temp);
  485. }
  486. } else {
  487. $currentFieldList = $this->getColumnsListbyBlock($module,$blockIdList);
  488. }
  489. return $currentFieldList;
  490. }
  491. public function getModuleFieldList($module) {
  492. foreach($this->module_list[$module] as $key=>$value) {
  493. $ret_module_list[$module][$value] = $this->getBlockFieldList(
  494. $module, $key, $ret_module_list[$module][$value]);
  495. }
  496. return $ret_module_list[$module];
  497. }
  498. /** Function to get vtiger_fields for the given module and block
  499. * This function gets the vtiger_fields for the given module
  500. * It accepts the module and the block as arguments and
  501. * returns the array column lists
  502. * Array module_columnlist[ vtiger_fieldtablename:fieldcolname:module_fieldlabel1:fieldname:fieldtypeofdata]=fieldlabel
  503. */
  504. function getColumnsListbyBlock($module,$block)
  505. {
  506. global $adb;
  507. global $log;
  508. global $current_user;
  509. if(is_string($block)) $block = explode(",", $block);
  510. $tabid = getTabid($module);
  511. if ($module == 'Calendar') {
  512. $tabid = array('9','16');
  513. }
  514. $params = array($tabid, $block);
  515. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  516. //Security Check
  517. if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] ==0)
  518. {
  519. $sql = "select * from vtiger_field where vtiger_field.tabid in (". generateQuestionMarks($tabid) .") and vtiger_field.block in (". generateQuestionMarks($block) .") and vtiger_field.displaytype in (1,2,3) and vtiger_field.presence in (0,2) ";
  520. //fix for Ticket #4016
  521. if($module == "Calendar")
  522. $sql.=" group by vtiger_field.fieldlabel order by sequence";
  523. else
  524. $sql.=" order by sequence";
  525. }
  526. else
  527. {
  528. $profileList = getCurrentUserProfileList();
  529. $sql = "select * from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid in (". generateQuestionMarks($tabid) .") and vtiger_field.block in (". generateQuestionMarks($block) .") and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
  530. if (count($profileList) > 0) {
  531. $sql .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
  532. array_push($params, $profileList);
  533. }
  534. //fix for Ticket #4016
  535. if($module == "Calendar")
  536. $sql.=" group by vtiger_field.fieldlabel order by sequence";
  537. else
  538. $sql.=" group by vtiger_field.fieldid order by sequence";
  539. }
  540. $result = $adb->pquery($sql, $params);
  541. $noofrows = $adb->num_rows($result);
  542. for($i=0; $i<$noofrows; $i++)
  543. {
  544. $fieldtablename = $adb->query_result($result,$i,"tablename");
  545. $fieldcolname = $adb->query_result($result,$i,"columnname");
  546. $fieldname = $adb->query_result($result,$i,"fieldname");
  547. $fieldtype = $adb->query_result($result,$i,"typeofdata");
  548. $uitype = $adb->query_result($result,$i,"uitype");
  549. $fieldtype = explode("~",$fieldtype);
  550. $fieldtypeofdata = $fieldtype[0];
  551. //Here we Changing the displaytype of the field. So that its criteria will be displayed correctly in Reports Advance Filter.
  552. $fieldtypeofdata=ChangeTypeOfData_Filter($fieldtablename,$fieldcolname,$fieldtypeofdata);
  553. if($uitype == 68 || $uitype == 59)
  554. {
  555. $fieldtypeofdata = 'V';
  556. }
  557. if($fieldtablename == "vtiger_crmentity")
  558. {
  559. $fieldtablename = $fieldtablename.$module;
  560. }
  561. if($fieldname == "assigned_user_id")
  562. {
  563. $fieldtablename = "vtiger_users".$module;
  564. $fieldcolname = "user_name";
  565. }
  566. if($fieldname == "assigned_user_id1")
  567. {
  568. $fieldtablename = "vtiger_usersRel1";
  569. $fieldcolname = "user_name";
  570. }
  571. $fieldlabel = $adb->query_result($result,$i,"fieldlabel");
  572. $fieldlabel1 = str_replace(" ","_",$fieldlabel);
  573. $optionvalue = $fieldtablename.":".$fieldcolname.":".$module."_".$fieldlabel1.":".$fieldname.":".$fieldtypeofdata;
  574. $this->adv_rel_fields[$fieldtypeofdata][] = '$'.$module.'#'.$fieldname.'$'."::".getTranslatedString($module,$module)." ".getTranslatedString($fieldlabel,$module);
  575. //added to escape attachments fields in Reports as we have multiple attachments
  576. if($module != 'HelpDesk' || $fieldname !='filename')
  577. $module_columnlist[$optionvalue] = $fieldlabel;
  578. }
  579. $blockname = getBlockName($block);
  580. if($blockname == 'LBL_RELATED_PRODUCTS' && ($module=='PurchaseOrder' || $module=='SalesOrder' || $module=='Quotes' || $module=='Invoice')){
  581. $fieldtablename = 'vtiger_inventoryproductrel';
  582. $fields = array('productid'=>getTranslatedString('Product Name',$module),
  583. 'serviceid'=>getTranslatedString('Service Name',$module),
  584. 'listprice'=>getTranslatedString('List Price',$module),
  585. 'discount'=>getTranslatedString('Discount',$module),
  586. 'quantity'=>getTranslatedString('Quantity',$module),
  587. 'comment'=>getTranslatedString('Comments',$module),
  588. );
  589. $fields_datatype = array('productid'=>'V',
  590. 'serviceid'=>'V',
  591. 'listprice'=>'I',
  592. 'discount'=>'I',
  593. 'quantity'=>'I',
  594. 'comment'=>'V',
  595. );
  596. foreach($fields as $fieldcolname=>$label){
  597. $fieldtypeofdata = $fields_datatype[$fieldcolname];
  598. $optionvalue = $fieldtablename.":".$fieldcolname.":".$module."_".$label.":".$fieldcolname.":".$fieldtypeofdata;
  599. $module_columnlist[$optionvalue] = $label;
  600. }
  601. }
  602. $log->info("Reports :: FieldColumns->Successfully returned ColumnslistbyBlock".$module.$block);
  603. return $module_columnlist;
  604. }
  605. /** Function to set the standard filter vtiger_fields for the given vtiger_report
  606. * This function gets the standard filter vtiger_fields for the given vtiger_report
  607. * and set the values to the corresponding variables
  608. * It accepts the repordid as argument
  609. */
  610. function getSelectedStandardCriteria($reportid) {
  611. global $adb;
  612. $sSQL = "select vtiger_reportdatefilter.* from vtiger_reportdatefilter inner join vtiger_report on vtiger_report.reportid = vtiger_reportdatefilter.datefilterid where vtiger_report.reportid=?";
  613. $result = $adb->pquery($sSQL, array($reportid));
  614. $selectedstdfilter = $adb->fetch_array($result);
  615. $this->stdselectedcolumn = $selectedstdfilter["datecolumnname"];
  616. $this->stdselectedfilter = $selectedstdfilter["datefilter"];
  617. if($selectedstdfilter["datefilter"] == "custom") {
  618. if($selectedstdfilter["startdate"] != "0000-00-00") {
  619. $startDateTime = new DateTimeField($selectedstdfilter["startdate"].' '. date('H:i:s'));
  620. $this->startdate = $startDateTime->getDisplayDate();
  621. }
  622. if($selectedstdfilter["enddate"] != "0000-00-00") {
  623. $endDateTime = new DateTimeField($selectedstdfilter["enddate"].' '. date('H:i:s'));
  624. $this->enddate = $endDateTime->getDisplayDate();
  625. }
  626. }
  627. }
  628. /** Function to get the combo values for the standard filter
  629. * This function get the combo values for the standard filter for the given vtiger_report
  630. * and return a HTML string
  631. */
  632. function getSelectedStdFilterCriteria($selecteddatefilter = "")
  633. {
  634. global $mod_strings;
  635. $datefiltervalue = Array("custom","prevfy","thisfy","nextfy","prevfq","thisfq","nextfq",
  636. "yesterday","today","tomorrow","lastweek","thisweek","nextweek","lastmonth","thismonth",
  637. "nextmonth","last7days","last30days", "last60days","last90days","last120days",
  638. "next30days","next60days","next90days","next120days"
  639. );
  640. $datefilterdisplay = Array("Custom","Previous FY", "Current FY","Next FY","Previous FQ","Current FQ","Next FQ","Yesterday",
  641. "Today","Tomorrow","Last Week","Current Week","Next Week","Last Month","Current Month",
  642. "Next Month","Last 7 Days","Last 30 Days","Last 60 Days","Last 90 Days","Last 120 Days",
  643. "Next 7 Days","Next 30 Days","Next 60 Days","Next 90 Days","Next 120 Days"
  644. );
  645. for($i=0;$i<count($datefiltervalue);$i++)
  646. {
  647. if($selecteddatefilter == $datefiltervalue[$i])
  648. {
  649. $sshtml .= "<option selected value='".$datefiltervalue[$i]."'>".$mod_strings[$datefilterdisplay[$i]]."</option>";
  650. }else
  651. {
  652. $sshtml .= "<option value='".$datefiltervalue[$i]."'>".$mod_strings[$datefilterdisplay[$i]]."</option>";
  653. }
  654. }
  655. return $sshtml;
  656. }
  657. /** Function to get the selected standard filter columns
  658. * This function returns the selected standard filter criteria
  659. * which is selected for vtiger_reports as an array
  660. * Array stdcriteria_list[fieldtablename:fieldcolname:module_fieldlabel1]=fieldlabel
  661. */
  662. function getStdCriteriaByModule($module)
  663. {
  664. global $adb;
  665. global $log;
  666. global $current_user;
  667. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  668. $tabid = getTabid($module);
  669. foreach($this->module_list[$module] as $key=>$blockid)
  670. {
  671. $blockids[] = $blockid;
  672. }
  673. $blockids = implode(",",$blockids);
  674. $params = array($tabid, $blockids);
  675. if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
  676. {
  677. //uitype 6 and 23 added for start_date,EndDate,Expected Close Date
  678. $sql = "select * from vtiger_field where vtiger_field.tabid=? and (vtiger_field.uitype =5 or vtiger_field.uitype = 6 or vtiger_field.uitype = 23 or vtiger_field.displaytype=2) and vtiger_field.block in (". generateQuestionMarks($block) .") and vtiger_field.presence in (0,2) order by vtiger_field.sequence";
  679. }
  680. else
  681. {
  682. $profileList = getCurrentUserProfileList();
  683. $sql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=? and (vtiger_field.uitype =5 or vtiger_field.displaytype=2) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.block in (". generateQuestionMarks($block) .") and vtiger_field.presence in (0,2)";
  684. if (count($profileList) > 0) {
  685. $sql .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
  686. array_push($params, $profileList);
  687. }
  688. $sql .= " order by vtiger_field.sequence";
  689. }
  690. $result = $adb->pquery($sql, $params);
  691. while($criteriatyperow = $adb->fetch_array($result))
  692. {
  693. $fieldtablename = $criteriatyperow["tablename"];
  694. $fieldcolname = $criteriatyperow["columnname"];
  695. $fieldlabel = $criteriatyperow["fieldlabel"];
  696. if($fieldtablename == "vtiger_crmentity")
  697. {
  698. $fieldtablename = $fieldtablename.$module;
  699. }
  700. $fieldlabel1 = str_replace(" ","_",$fieldlabel);
  701. $optionvalue = $fieldtablename.":".$fieldcolname.":".$module."_".$fieldlabel1;
  702. $stdcriteria_list[$optionvalue] = $fieldlabel;
  703. }
  704. $log->info("Reports :: StdfilterColumns->Successfully returned Stdfilter for".$module);
  705. return $stdcriteria_list;
  706. }
  707. /** Function to form a javascript to determine the start date and end date for a standard filter
  708. * This function is to form a javascript to determine
  709. * the start date and End date from the value selected in the combo lists
  710. */
  711. function getCriteriaJS()
  712. {
  713. $todayDateTime = new DateTimeField(date('Y-m-d H:i:s'));
  714. $tomorrow = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+1, date("Y")));
  715. $tomorrowDateTime = new DateTimeField($tomorrow.' '. date('H:i:s'));
  716. $yesterday = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-1, date("Y")));
  717. $yesterdayDateTime = new DateTimeField($yesterday.' '. date('H:i:s'));
  718. $currentmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m"), "01", date("Y")));
  719. $currentMonthStartDateTime = new DateTimeField($currentmonth0.' '. date('H:i:s'));
  720. $currentmonth1 = date("Y-m-t");
  721. $currentMonthEndDateTime = new DateTimeField($currentmonth1.' '. date('H:i:s'));
  722. $lastmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")-1, "01", date("Y")));
  723. $lastMonthStartDateTime = new DateTimeField($lastmonth0.' '. date('H:i:s'));
  724. $lastmonth1 = date("Y-m-t", strtotime("-1 Month"));
  725. $lastMonthEndDateTime = new DateTimeField($lastmonth1.' '. date('H:i:s'));
  726. $nextmonth0 = date("Y-m-d",mktime(0, 0, 0, date("m")+1, "01", date("Y")));
  727. $nextMonthStartDateTime = new DateTimeField($nextmonth0.' '. date('H:i:s'));
  728. $nextmonth1 = date("Y-m-t", strtotime("+1 Month"));
  729. $nextMonthEndDateTime = new DateTimeField($nextmonth1.' '. date('H:i:s'));
  730. $lastweek0 = date("Y-m-d",strtotime("-2 week Sunday"));
  731. $lastWeekStartDateTime = new DateTimeField($lastweek0.' '. date('H:i:s'));
  732. $lastweek1 = date("Y-m-d",strtotime("-1 week Saturday"));
  733. $lastWeekEndDateTime = new DateTimeField($lastweek1.' '. date('H:i:s'));
  734. $thisweek0 = date("Y-m-d",strtotime("-1 week Sunday"));
  735. $thisWeekStartDateTime = new DateTimeField($thisweek0.' '. date('H:i:s'));
  736. $thisweek1 = date("Y-m-d",strtotime("this Saturday"));
  737. $thisWeekEndDateTime = new DateTimeField($thisweek1.' '. date('H:i:s'));
  738. $nextweek0 = date("Y-m-d",strtotime("this Sunday"));
  739. $nextWeekStartDateTime = new DateTimeField($nextweek0.' '. date('H:i:s'));
  740. $nextweek1 = date("Y-m-d",strtotime("+1 week Saturday"));
  741. $nextWeekEndDateTime = new DateTimeField($nextweek1.' '. date('H:i:s'));
  742. $next7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+6, date("Y")));
  743. $next7DaysDateTime = new DateTimeField($next7days.' '. date('H:i:s'));
  744. $next30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+29, date("Y")));
  745. $next30DaysDateTime = new DateTimeField($next30days.' '. date('H:i:s'));
  746. $next60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+59, date("Y")));
  747. $next60DaysDateTime = new DateTimeField($next60days.' '. date('H:i:s'));
  748. $next90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+89, date("Y")));
  749. $next90DaysDateTime = new DateTimeField($next90days.' '. date('H:i:s'));
  750. $next120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+119, date("Y")));
  751. $next120DaysDateTime = new DateTimeField($next120days.' '. date('H:i:s'));
  752. $last7days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-6, date("Y")));
  753. $last7DaysDateTime = new DateTimeField($last7days.' '. date('H:i:s'));
  754. $last30days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-29, date("Y")));
  755. $last30DaysDateTime = new DateTimeField($last30days.' '. date('H:i:s'));
  756. $last60days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-59, date("Y")));
  757. $last60DaysDateTime = new DateTimeField($last60days.' '. date('H:i:s'));
  758. $last90days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-89, date("Y")));
  759. $last90DaysDateTime = new DateTimeField($last90days.' '. date('H:i:s'));
  760. $last120days = date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")-119, date("Y")));
  761. $last120DaysDateTime = new DateTimeField($last120days.' '. date('H:i:s'));
  762. $currentFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")));
  763. $currentFYStartDateTime = new DateTimeField($currentFY0.' '. date('H:i:s'));
  764. $currentFY1 = date("Y-m-t",mktime(0, 0, 0, "12", date("d"), date("Y")));
  765. $currentFYEndDateTime = new DateTimeField($currentFY1.' '. date('H:i:s'));
  766. $lastFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")-1));
  767. $lastFYStartDateTime = new DateTimeField($lastFY0.' '. date('H:i:s'));
  768. $lastFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")-1));
  769. $lastFYEndDateTime = new DateTimeField($lastFY1.' '. date('H:i:s'));
  770. $nextFY0 = date("Y-m-d",mktime(0, 0, 0, "01", "01", date("Y")+1));
  771. $nextFYStartDateTime = new DateTimeField($nextFY0.' '. date('H:i:s'));
  772. $nextFY1 = date("Y-m-t", mktime(0, 0, 0, "12", date("d"), date("Y")+1));
  773. $nextFYEndDateTime = new DateTimeField($nextFY1.' '. date('H:i:s'));
  774. if(date("m") <= 3) {
  775. $cFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y")));
  776. $cFqStartDateTime = new DateTimeField($cFq.' '. date('H:i:s'));
  777. $cFq1 = date("Y-m-d",mktime(0, 0, 0, "03","31",date("Y")));
  778. $cFqEndDateTime = new DateTimeField($cFq1.' '. date('H:i:s'));
  779. $nFq = date("Y-m-d",mktime(0, 0, 0, "04","01",date("Y")));
  780. $nFqStartDateTime = new DateTimeField($nFq.' '. date('H:i:s'));
  781. $nFq1 = date("Y-m-d",mktime(0, 0, 0, "06","30",date("Y")));
  782. $nFqEndDateTime = new DateTimeField($nFq1.' '. date('H:i:s'));
  783. $pFq = date("Y-m-d",mktime(0, 0, 0, "10","01",date("Y")-1));
  784. $pFqStartDateTime = new DateTimeField($pFq.' '. date('H:i:s'));
  785. $pFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y")-1));
  786. $pFqEndDateTime = new DateTimeField($pFq1.' '. date('H:i:s'));
  787. } else if(date("m") > 3 and date("m") <= 6) {
  788. $pFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y")));
  789. $pFqStartDateTime = new DateTimeField($pFq.' '. date('H:i:s'));
  790. $pFq1 = date("Y-m-d",mktime(0, 0, 0, "03","31",date("Y")));
  791. $pFqEndDateTime = new DateTimeField($pFq1.' '. date('H:i:s'));
  792. $cFq = date("Y-m-d",mktime(0, 0, 0, "04","01",date("Y")));
  793. $cFqStartDateTime = new DateTimeField($cFq.' '. date('H:i:s'));
  794. $cFq1 = date("Y-m-d",mktime(0, 0, 0, "06","30",date("Y")));
  795. $cFqEndDateTime = new DateTimeField($cFq1.' '. date('H:i:s'));
  796. $nFq = date("Y-m-d",mktime(0, 0, 0, "07","01",date("Y")));
  797. $nFqStartDateTime = new DateTimeField($nFq.' '. date('H:i:s'));
  798. $nFq1 = date("Y-m-d",mktime(0, 0, 0, "09","30",date("Y")));
  799. $nFqEndDateTime = new DateTimeField($nFq1.' '. date('H:i:s'));
  800. } else if(date("m") > 6 and date("m") <= 9) {
  801. $nFq = date("Y-m-d",mktime(0, 0, 0, "10","01",date("Y")));
  802. $nFqStartDateTime = new DateTimeField($nFq.' '. date('H:i:s'));
  803. $nFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y")));
  804. $nFqEndDateTime = new DateTimeField($nFq1.' '. date('H:i:s'));
  805. $pFq = date("Y-m-d",mktime(0, 0, 0, "04","01",date("Y")));
  806. $pFqStartDateTime = new DateTimeField($pFq.' '. date('H:i:s'));
  807. $pFq1 = date("Y-m-d",mktime(0, 0, 0, "06","30",date("Y")));
  808. $pFqEndDateTime = new DateTimeField($pFq1.' '. date('H:i:s'));
  809. $cFq = date("Y-m-d",mktime(0, 0, 0, "07","01",date("Y")));
  810. $cFqStartDateTime = new DateTimeField($cFq.' '. date('H:i:s'));
  811. $cFq1 = date("Y-m-d",mktime(0, 0, 0, "09","30",date("Y")));
  812. $cFqEndDateTime = new DateTimeField($cFq1.' '. date('H:i:s'));
  813. } else if(date("m") > 9 and date("m") <= 12) {
  814. $nFq = date("Y-m-d",mktime(0, 0, 0, "01","01",date("Y")+1));
  815. $nFqStartDateTime = new DateTimeField($nFq.' '. date('H:i:s'));
  816. $nFq1 = date("Y-m-d",mktime(0, 0, 0, "03","31",date("Y")+1));
  817. $nFqEndDateTime = new DateTimeField($nFq1.' '. date('H:i:s'));
  818. $pFq = date("Y-m-d",mktime(0, 0, 0, "07","01",date("Y")));
  819. $pFqStartDateTime = new DateTimeField($pFq.' '. date('H:i:s'));
  820. $pFq1 = date("Y-m-d",mktime(0, 0, 0, "09","30",date("Y")));
  821. $pFqEndDateTime = new DateTimeField($pFq1.' '. date('H:i:s'));
  822. $cFq = date("Y-m-d",mktime(0, 0, 0, "10","01",date("Y")));
  823. $cFqStartDateTime = new DateTimeField($cFq.' '. date('H:i:s'));
  824. $cFq1 = date("Y-m-d",mktime(0, 0, 0, "12","31",date("Y")));
  825. $cFqEndDateTime = new DateTimeField($cFq1.' '. date('H:i:s'));
  826. }
  827. $sjsStr = '<script language="JavaScript" type="text/javaScript">
  828. function showDateRange( type ) {
  829. if (type!="custom") {
  830. document.NewReport.startdate.readOnly=true
  831. document.NewReport.enddate.readOnly=true
  832. getObj("jscal_trigger_date_start").style.visibility="hidden"
  833. getObj("jscal_trigger_date_end").style.visibility="hidden"
  834. } else {
  835. document.NewReport.startdate.readOnly=false
  836. document.NewReport.enddate.readOnly=false
  837. getObj("jscal_trigger_date_start").style.visibility="visible"
  838. getObj("jscal_trigger_date_end").style.visibility="visible"
  839. }
  840. if( type == "today" ) {
  841. document.NewReport.startdate.value = "'.$todayDateTime->getDisplayDate().'";
  842. document.NewReport.enddate.value = "'.$todayDateTime->getDisplayDate().'";
  843. } else if( type == "yesterday" ) {
  844. document.NewReport.startdate.value = "'.$yesterdayDateTime->getDisplayDate().'";
  845. document.NewReport.enddate.value = "'.$yesterdayDateTime->getDisplayDate().'";
  846. } else if( type == "tomorrow" ) {
  847. document.NewReport.startdate.value = "'.$tomorrowDateTime->getDisplayDate().'";
  848. document.NewReport.enddate.value = "'.$tomorrowDateTime->getDisplayDate().'";
  849. } else if( type == "thisweek" ) {
  850. document.NewReport.startdate.value = "'.$thisWeekStartDateTime->getDisplayDate().'";
  851. document.NewReport.enddate.value = "'.$thisWeekEndDateTime->getDisplayDate().'";
  852. } else if( type == "lastweek" ) {
  853. document.NewReport.startdate.value = "'.$lastWeekStartDateTime->getDisplayDate().'";
  854. document.NewReport.enddate.value = "'.$lastWeekEndDateTime->getDisplayDate().'";
  855. } else if( type == "nextweek" ) {
  856. document.NewReport.startdate.value = "'.$nextWeekStartDateTime->getDisplayDate().'";
  857. document.NewReport.enddate.value = "'.$nextWeekEndDateTime->getDisplayDate().'";
  858. } else if( type == "thismonth" ) {
  859. document.NewReport.startdate.value = "'.$currentMonthStartDateTime->getDisplayDate().'";
  860. document.NewReport.enddate.value = "'.$currentMonthEndDateTime->getDisplayDate().'";
  861. } else if( type == "lastmonth" ) {
  862. document.NewReport.startdate.value = "'.$lastMonthStartDateTime->getDisplayDate().'";
  863. document.NewReport.enddate.value = "'.$lastMonthEndDateTime->getDisplayDate().'";
  864. } else if( type == "nextmonth" ) {
  865. document.NewReport.startdate.value = "'.$nextMonthStartDateTime->getDisplayDate().'";
  866. document.NewReport.enddate.value = "'.$nextMonthEndDateTime->getDisplayDate().'";
  867. } else if( type == "next7days" ) {
  868. document.NewReport.startdate.value = "'.$todayDateTime->getDisplayDate().'";
  869. document.NewReport.enddate.value = "'.$next7DaysDateTime->getDisplayDate().'";
  870. } else if( type == "next30days" ) {
  871. document.NewReport.startdate.value = "'.$todayDateTime->getDisplayDate().'";
  872. document.NewReport.enddate.value = "'.$next30DaysDateTime->getDisplayDate().'";
  873. } else if( type == "next60days" ) {
  874. document.NewReport.startdate.value = "'.$todayDateTime->getDisplayDate().'";
  875. document.NewReport.enddate.value = "'.$next60DaysDateTime->getDisplayDate().'";
  876. } else if( type == "next90days" ) {
  877. document.NewReport.startdate.value = "'.$todayDateTime->getDisplayDate().'";
  878. document.NewReport.enddate.value = "'.$next90DaysDateTime->getDisplayDate().'";
  879. } else if( type == "next120days" ) {
  880. document.NewReport.startdate.value = "'.$todayDateTime->getDisplayDate().'";
  881. document.NewReport.enddate.value = "'.$next120DaysDateTime->getDisplayDate().'";
  882. } else if( type == "last7days" ) {
  883. document.NewReport.startdate.value = "'.$last7DaysDateTime->getDisplayDate().'";
  884. document.NewReport.enddate.value = "'.$todayDateTime->getDisplayDate().'";
  885. } else if( type == "last30days" ) {
  886. document.NewReport.startdate.value = "'.$last30DaysDateTime->getDisplayDate().'";
  887. document.NewReport.enddate.value = "'.$todayDateTime->getDisplayDate().'";
  888. } else if( type == "last60days" ) {
  889. document.NewReport.startdate.value = "'.$last60DaysDateTime->getDisplayDate().'";
  890. document.NewReport.enddate.value = "'.$todayDateTime->getDisplayDate().'";
  891. } else if( type == "last90days" ) {
  892. document.NewReport.startdate.value = "'.$last90DaysDateTime->getDisplayDate().'";
  893. document.NewReport.enddate.value = "'.$todayDateTime->getDisplayDate().'";
  894. } else if( type == "last120days" ) {
  895. document.NewReport.startdate.value = "'.$last120DaysDateTime->getDisplayDate().'";
  896. document.NewReport.enddate.value = "'.$todayDateTime->getDisplayDate().'";
  897. } else if( type == "thisfy" ) {
  898. document.NewReport.startdate.value = "'.$currentFYStartDateTime->getDisplayDate().'";
  899. document.NewReport.enddate.value = "'.$currentFYEndDateTime->getDisplayDate().'";
  900. } else if( type == "prevfy" ) {
  901. document.NewReport.startdate.value = "'.$lastFYStartDateTime->getDisplayDate().'";
  902. document.NewReport.enddate.value = "'.$lastFYEndDateTime->getDisplayDate().'";
  903. } else if( type == "nextfy" ) {
  904. document.NewReport.startdate.value = "'.$nextFYStartDateTime->getDisplayDate().'";
  905. document.NewReport.enddate.value = "'.$nextFYEndDateTime->getDisplayDate().'";
  906. } else if( type == "nextfq" ) {
  907. document.NewReport.startdate.value = "'.$nFqStartDateTime->getDisplayDate().'";
  908. document.NewReport.enddate.value = "'.$nFqEndDateTime->getDisplayDate().'";
  909. } else if( type == "prevfq" ) {
  910. document.NewReport.startdate.value = "'.$pFqStartDateTime->getDisplayDate().'";
  911. document.NewReport.enddate.value = "'.$pFqEndDateTime->getDisplayDate().'";
  912. } else if( type == "thisfq" ) {
  913. document.NewReport.startdate.value = "'.$cFqStartDateTime->getDisplayDate().'";
  914. document.NewReport.enddate.value = "'.$cFqEndDateTime->getDisplayDate().'";
  915. } else {
  916. document.NewReport.startdate.value = "";
  917. document.NewReport.enddate.value = "";
  918. }
  919. }
  920. </script>';
  921. return $sjsStr;
  922. }
  923. function getEscapedColumns($selectedfields)
  924. {
  925. $fieldname = $selectedfields[3];
  926. if($fieldname == "parent_id")
  927. {
  928. if($this->primarymodule == "HelpDesk" && $selectedfields[0] == "vtiger_crmentityRelHelpDesk")
  929. {
  930. $querycolumn = "case vtiger_crmentityRelHelpDesk.setype when 'Accounts' then vtiger_accountRelHelpDesk.accountname when 'Contacts' then vtiger_contactdetailsRelHelpDesk.lastname End"." '".$selectedfields[2]."', vtiger_crmentityRelHelpDesk.setype 'Entity_type'";
  931. return $querycolumn;
  932. }
  933. if($this->primarymodule == "Products" || $this->secondarymodule == "Products")
  934. {
  935. $querycolumn = "case vtiger_crmentityRelProducts.setype when 'Accounts' then vtiger_accountRelProducts.accountname when 'Leads' then vtiger_leaddetailsRelProducts.lastname when 'Potentials' then vtiger_potentialRelProducts.potentialname End"." '".$selectedfields[2]."', vtiger_crmentityRelProducts.setype 'Entity_type'";
  936. }
  937. if($this->primarymodule == "Calendar" || $this->secondarymodule == "Calendar")
  938. {
  939. $querycolumn = "case vtiger_crmentityRelCalendar.setype when 'Accounts' then vtiger_accountRelCalendar.accountname when 'Leads' then vtiger_leaddetailsRelCalendar.lastname when 'Potentials' then vtiger_potentialRelCalendar.potentialname when 'Quotes' then vtiger_quotesRelCalendar.subject when 'PurchaseOrder' then vtiger_purchaseorderRelCalendar.subject when 'Invoice' then vtiger_invoiceRelCalendar.subject End"." '".$selectedfields[2]."', vtiger_crmentityRelCalendar.setype 'Entity_type'";
  940. }
  941. }
  942. return $querycolumn;
  943. }
  944. function getaccesfield($module)
  945. {
  946. global $current_user;
  947. global $adb;
  948. $access_fields = Array();
  949. $profileList = getCurrentUserProfileList();
  950. $query = "select vtiger_field.fieldname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where";
  951. $params = array();
  952. if($module == "Calendar")
  953. {
  954. $query .= " vtiger_field.tabid in (9,16) and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
  955. if (count($profileList) > 0) {
  956. $query .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
  957. array_push($params, $profileList);
  958. }
  959. $query .= " group by vtiger_field.fieldid order by block,sequence";
  960. }
  961. else
  962. {
  963. array_push($params, $this->primodule, $this->secmodule);
  964. $query .= " vtiger_field.tabid in (select tabid from vtiger_tab where vtiger_tab.name in (?,?)) and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
  965. if (count($profileList) > 0) {
  966. $query .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
  967. array_push($params, $profileList);
  968. }
  969. $query .= " group by vtiger_field.fieldid order by block,sequence";
  970. }
  971. $result = $adb->pquery($query, $params);
  972. while($collistrow = $adb->fetch_array($result))
  973. {
  974. $access_fields[] = $collistrow["fieldname"];
  975. }
  976. return $access_fields;
  977. }
  978. /** Function to set the order of grouping and to find the columns responsible
  979. * to the grouping
  980. * This function accepts the vtiger_reportid as variable,sets the variable ascdescorder[] to the sort order and
  981. * returns the array array_list which has the column responsible for the grouping
  982. * Array array_list[0]=columnname
  983. */
  984. function getSelctedSortingColumns($reportid)
  985. {
  986. global $adb;
  987. global $log;
  988. $sreportsortsql = "select vtiger_reportsortcol.* from vtiger_report";
  989. $sreportsortsql .= " inner join vtiger_reportsortcol on vtiger_report.reportid = vtiger_reportsortcol.reportid";
  990. $sreportsortsql .= " where vtiger_report.reportid =? order by vtiger_reportsortcol.sortcolid";
  991. $result = $adb->pquery($sreportsortsql, array($reportid));
  992. $noofrows = $adb->num_rows($result);
  993. for($i=0; $i<$noofrows; $i++)
  994. {
  995. $fieldcolname = $adb->query_result($result,$i,"columnname");
  996. $sort_values = $adb->query_result($result,$i,"sortorder");
  997. $this->ascdescorder[] = $sort_values;
  998. $array_list[] = $fieldcolname;
  999. }
  1000. $log->info("Reports :: Successfully returned getSelctedSortingColumns");
  1001. return $array_list;
  1002. }
  1003. /** Function to get the selected columns list for a selected vtiger_report
  1004. * This function accepts the vtiger_reportid as the argument and get the selected columns
  1005. * for the given vtiger_reportid and it forms a combo lists and returns
  1006. * HTML of the combo values
  1007. */
  1008. function getSelectedColumnsList($reportid)
  1009. {
  1010. global $adb;
  1011. global $modules;
  1012. global $log,$current_user;
  1013. $ssql = "select vtiger_selectcolumn.* from vtiger_report inner join vtiger_selectquery on vtiger_selectquery.queryid = vtiger_report.queryid";
  1014. $ssql .= " left join vtiger_selectcolumn on vtiger_selectcolumn.queryid = vtiger_selectquery.queryid";
  1015. $ssql .= " where vtiger_report.reportid = ?";
  1016. $ssql .= " order by vtiger_selectcolumn.columnindex";
  1017. $result = $adb->pquery($ssql, array($reportid));
  1018. $permitted_fields = Array();
  1019. $selected_mod = split(":",$this->secmodule);
  1020. array_push($selected_mod,$this->primodule);
  1021. while($columnslistrow = $adb->fetch_array($result))
  1022. {
  1023. $fieldname ="";
  1024. $fieldcolname = $columnslistrow["columnname"];
  1025. $selmod_field_disabled = true;
  1026. foreach($selected_mod as $smod){
  1027. if((stripos($fieldcolname,":".$smod."_")>-1) && vtlib_isModuleActive($smod)){
  1028. $selmod_field_disabled = false;
  1029. break;
  1030. }
  1031. }
  1032. if($selmod_field_disabled==false){
  1033. list($tablename,$colname,$module_field,$fieldname,$single) = split(":",$fieldcolname);
  1034. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  1035. list($module,$field) = split("_",$module_field);
  1036. if(sizeof($permitted_fields) == 0 && $is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1)
  1037. {
  1038. $permitted_fields = $this->getaccesfield($module);
  1039. }
  1040. $querycolumns = $this->getEscapedColumns($selectedfields);
  1041. $fieldlabel = trim(str_replace($module," ",$module_field));
  1042. $mod_arr=explode('_',$fieldlabel);
  1043. $mod = ($mod_arr[0] == '')?$module:$mod_arr[0];
  1044. $fieldlabel = trim(str_replace("_"," ",$fieldlabel));
  1045. //modified code to support i18n issue
  1046. $mod_lbl = getTranslatedString($mod,$module); //module
  1047. $fld_lbl = getTranslatedString($fieldlabel,$module); //fieldlabel
  1048. $fieldlabel = $mod_lbl." ".$fld_lbl;
  1049. if(CheckFieldPermission($fieldname,$mod) != 'true' && $colname!="crmid")
  1050. {
  1051. $shtml .= "<option permission='no' value=\"".$fieldcolname."\" disabled = 'true'>".$fieldlabel."</option>";
  1052. }
  1053. else
  1054. {
  1055. $shtml .= "<option permission='yes' value=\"".$fieldcolname."\">".$fieldlabel."</option>";
  1056. }
  1057. }
  1058. //end
  1059. }
  1060. $log->info("ReportRun :: Successfully returned getQueryColumnsList".$reportid);
  1061. return $shtml;
  1062. }
  1063. function getAdvancedFilterList($reportid)
  1064. {
  1065. global $adb;
  1066. global $modules;
  1067. global $log;
  1068. global $current_user;
  1069. $advft_criteria = array();
  1070. $sql = 'SELECT * FROM vtiger_relcriteria_grouping WHERE queryid = ? ORDER BY groupid';
  1071. $groupsresult = $adb->pquery($sql, array($reportid));
  1072. $i = 1;
  1073. $j = 0;
  1074. while($relcriteriagroup = $adb->fetch_array($groupsresult)) {
  1075. $groupId = $relcriteriagroup["groupid"];
  1076. $groupCondition = $relcriteriagroup["group_condition"];
  1077. $ssql = 'select vtiger_relcriteria.* from vtiger_report
  1078. inner join vtiger_relcriteria on vtiger_relcriteria.queryid = vtiger_report.queryid
  1079. left join vtiger_relcriteria_grouping on vtiger_relcriteria.queryid = vtiger_relcriteria_grouping.queryid
  1080. and vtiger_relcriteria.groupid = vtiger_relcriteria_grouping.groupid';
  1081. $ssql.= " where vtiger_report.reportid = ? AND vtiger_relcriteria.groupid = ? order by vtiger_relcriteria.columnindex";
  1082. $result = $adb->pquery($ssql, array($reportid, $groupId));
  1083. $noOfColumns = $adb->num_rows($result);
  1084. if($noOfColumns <= 0) continue;
  1085. while($relcriteriarow = $adb->fetch_array($result)) {
  1086. $columnIndex = $relcriteriarow["columnindex"];
  1087. $criteria = array();
  1088. $criteria['columnname'] = html_entity_decode($relcriteriarow["columnname"]);
  1089. $criteria['comparator'] = $relcriteriarow["comparator"];
  1090. $advfilterval = $relcriteriarow["value"];
  1091. $col = explode(":",$relcriteriarow["columnname"]);
  1092. $moduleFieldLabel = $col[2];
  1093. $fieldName = $col[3];
  1094. list($module, $fieldLabel) = explode('_', $moduleFieldLabel, 2);
  1095. $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
  1096. $fieldType = null;
  1097. if(!empty($fieldInfo)) {
  1098. $field = WebserviceField::fromArray($adb, $fieldInfo);
  1099. $fieldType = $field->getFieldDataType();
  1100. }
  1101. if($fieldType == 'currency') {
  1102. if($field->getUIType() == '71') {
  1103. $advfilterval = CurrencyField::convertToUserFormat($advfilterval,$current_user);
  1104. } else if($field->getUIType() == '72') {
  1105. $advfilterval = CurrencyField::convertToUserFormat($advfilterval,$current_user,true);
  1106. }
  1107. }
  1108. $temp_val = explode(",",$relcriteriarow["value"]);
  1109. if($col[4] == 'D' || ($col[4] == 'T' && $col[1] != 'time_start' && $col[1] != 'time_end') || ($col[4] == 'DT')) {
  1110. $val = Array();
  1111. for($x=0;$x<count($temp_val);$x++) {
  1112. if($col[4] == 'D') {
  1113. $date = new DateTimeField(trim($temp_val[$x]));
  1114. $val[$x] = $date->getDisplayDate();
  1115. } elseif($col[4] == 'DT') {
  1116. $date = new DateTimeField(trim($temp_val[$x]));
  1117. $val[$x] = $date->getDisplayDateTimeValue();
  1118. } else {
  1119. $date = new DateTimeField(trim($temp_val[$x]));
  1120. $val[$x] = $date->getDisplayTime();
  1121. }
  1122. }
  1123. $advfilterval = implode(",",$val);
  1124. }
  1125. $criteria['value'] = decode_html($advfilterval);
  1126. $criteria['column_condition'] = $relcriteriarow["column_condition"];
  1127. $advft_criteria[$i]['columns'][$j] = $criteria;
  1128. $advft_criteria[$i]['condition'] = $groupCondition;
  1129. $j++;
  1130. }
  1131. $i++;
  1132. }
  1133. // Clear the condition (and/or) for last group, if any.
  1134. if(!empty($advft_criteria[$i-1]['condition'])) $advft_criteria[$i-1]['condition'] = '';
  1135. $this->advft_criteria = $advft_criteria;
  1136. $log->info("Reports :: Successfully returned getAdvancedFilterList");
  1137. return true;
  1138. }
  1139. //<<<<<<<<advanced filter>>>>>>>>>>>>>>
  1140. /** Function to get the list of vtiger_report folders when Save and run the vtiger_report
  1141. * This function gets the vtiger_report folders from database and form
  1142. * a combo values of the folders and return
  1143. * HTML of the combo values
  1144. */
  1145. function sgetRptFldrSaveReport()
  1146. {
  1147. global $adb;
  1148. global $log;
  1149. $sql = "select * from vtiger_reportfolder order by folderid";
  1150. $result = $adb->pquery($sql, array());
  1151. $reportfldrow = $adb->fetch_array($result);
  1152. $x = 0;
  1153. do
  1154. {
  1155. $shtml .= "<option value='".$reportfldrow['folderid']."'>".$reportfldrow['foldername']."</option>";
  1156. }while($reportfldrow = $adb->fetch_array($result));
  1157. $log->info("Reports :: Successfully returned sgetRptFldrSaveReport");
  1158. return $shtml;
  1159. }
  1160. /** Function to get the column to total vtiger_fields in Reports
  1161. * This function gets columns to total vtiger_field
  1162. * and generated the html for that vtiger_fields
  1163. * It returns the HTML of the vtiger_fields along with the check boxes
  1164. */
  1165. function sgetColumntoTotal($primarymodule,$secondarymodule)
  1166. {
  1167. $options = Array();
  1168. $options []= $this->sgetColumnstoTotalHTML($primarymodule,0);
  1169. if(!empty($secondarymodule))
  1170. {
  1171. //$secondarymodule = explode(":",$secondarymodule);
  1172. for($i=0;$i < count($secondarymodule) ;$i++)
  1173. {
  1174. $options []= $this->sgetColumnstoTotalHTML($secondarymodule[$i],($i+1));
  1175. }
  1176. }
  1177. return $options;
  1178. }
  1179. /** Function to get the selected columns of total vtiger_fields in Reports
  1180. * This function gets selected columns of total vtiger_field
  1181. * and generated the html for that vtiger_fields
  1182. * It returns the HTML of the vtiger_fields along with the check boxes
  1183. */
  1184. function sgetColumntoTotalSelected($primarymodule,$secondarymodule,$reportid)
  1185. {
  1186. global $adb;
  1187. global $log;
  1188. $options = Array();
  1189. if($reportid != "")
  1190. {
  1191. $ssql = "select vtiger_reportsummary.* from vtiger_reportsummary inner join vtiger_report on vtiger_report.reportid = vtiger_reportsummary.reportsummaryid where vtiger_report.reportid=?";
  1192. $result = $adb->pquery($ssql, array($reportid));
  1193. if($result)
  1194. {
  1195. $reportsummaryrow = $adb->fetch_array($result);
  1196. do
  1197. {
  1198. $this->columnssummary[] = $reportsummaryrow["columnname"];
  1199. }while($reportsummaryrow = $adb->fetch_array($result));
  1200. }
  1201. }
  1202. $options []= $this->sgetColumnstoTotalHTML($primarymodule,0);
  1203. if($secondarymodule != "")
  1204. {
  1205. $secondarymodule = explode(":",$secondarymodule);
  1206. for($i=0;$i < count($secondarymodule) ;$i++)
  1207. {
  1208. $options []= $this->sgetColumnstoTotalHTML($secondarymodule[$i],($i+1));
  1209. }
  1210. }
  1211. $log->info("Reports :: Successfully returned sgetColumntoTotalSelected");
  1212. return $options;
  1213. }
  1214. /** Function to form the HTML for columns to total
  1215. * This function formulates the HTML format of the
  1216. * vtiger_fields along with four checkboxes
  1217. * It returns the HTML of the vtiger_fields along with the check boxes
  1218. */
  1219. function sgetColumnstoTotalHTML($module)
  1220. {
  1221. //retreive the vtiger_tabid
  1222. global $adb;
  1223. global $log;
  1224. global $current_user;
  1225. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  1226. $tabid = getTabid($module);
  1227. $escapedchars = Array('_SUM','_AVG','_MIN','_MAX');
  1228. $sparams = array($tabid);
  1229. if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] ==0)
  1230. {
  1231. $ssql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid where vtiger_field.uitype != 50 and vtiger_field.tabid=? and vtiger_field.displaytype in (1,2,3) and vtiger_field.presence in (0,2) ";
  1232. }
  1233. else
  1234. {
  1235. $profileList = getCurrentUserProfileList();
  1236. $ssql = "select * from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid where vtiger_field.uitype != 50 and vtiger_field.tabid=? and vtiger_field.displaytype in (1,2,3) and vtiger_def_org_field.visible=0 and vtiger_profile2field.visible=0 and vtiger_field.presence in (0,2)";
  1237. if (count($profileList) > 0) {
  1238. $ssql .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
  1239. array_push($sparams, $profileList);
  1240. }
  1241. }
  1242. //Added to avoid display the Related fields (Account name,Vandor name,product name, etc) in Report Calculations(SUM,AVG..)
  1243. switch($tabid)
  1244. {
  1245. case 2://Potentials
  1246. //ie. Campaign name will not displayed in Potential's report calcullation
  1247. $ssql.= " and vtiger_field.fieldname not in ('campaignid')";
  1248. break;
  1249. case 4://Contacts
  1250. $ssql.= " and vtiger_field.fieldname not in ('account_id')";
  1251. break;
  1252. case 6://Accounts
  1253. $ssql.= " and vtiger_field.fieldname not in ('account_id')";
  1254. break;
  1255. case 9://Calandar
  1256. $ssql.= " and vtiger_field.fieldname not in ('parent_id','contact_id')";
  1257. break;
  1258. case 13://Trouble tickets(HelpDesk)
  1259. $ssql.= " and vtiger_field.fieldname not in ('parent_id','product_id')";
  1260. break;
  1261. case 14://Products
  1262. $ssql.= " and vtiger_field.fieldname not in ('vendor_id','product_id')";
  1263. break;
  1264. case 20://Quotes
  1265. $ssql.= " and vtiger_field.fieldname not in ('potential_id','assigned_user_id1','account_id','currency_id')";
  1266. break;
  1267. case 21://Purchase Order
  1268. $ssql.= " and vtiger_field.fieldname not in ('contact_id','vendor_id','currency_id')";
  1269. break;
  1270. case 22://SalesOrder
  1271. $ssql.= " and vtiger_field.fieldname not in ('potential_id','account_id','contact_id','quote_id','currency_id')";
  1272. break;
  1273. case 23://Invoice
  1274. $ssql.= " and vtiger_field.fieldname not in ('salesorder_id','contact_id','account_id','currency_id')";
  1275. break;
  1276. case 26://Campaigns
  1277. $ssql.= " and vtiger_field.fieldname not in ('product_id')";
  1278. break;
  1279. }
  1280. $ssql.= " order by sequence";
  1281. $result = $adb->pquery($ssql, $sparams);
  1282. $columntototalrow = $adb->fetch_array($result);
  1283. $options_list = Array();
  1284. do
  1285. {
  1286. $typeofdata = explode("~",$columntototalrow["typeofdata"]);
  1287. if($typeofdata[0] == "N" || $typeofdata[0] == "I")
  1288. {
  1289. $options = Array();
  1290. if(isset($this->columnssummary))
  1291. {
  1292. $selectedcolumn = "";
  1293. $selectedcolumn1 = "";
  1294. for($i=0;$i < count($this->columnssummary) ;$i++)
  1295. {
  1296. $selectedcolumnarray = explode(":",$this->columnssummary[$i]);
  1297. $selectedcolumn = $selectedcolumnarray[1].":".$selectedcolumnarray[2].":".
  1298. str_replace($escapedchars,"",$selectedcolumnarray[3]);
  1299. if ($selectedcolumn != $columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.str_replace(" ","_",$columntototalrow['fieldlabel']))
  1300. {
  1301. $selectedcolumn = "";
  1302. }else
  1303. {
  1304. $selectedcolumn1[$selectedcolumnarray[4]] = $this->columnssummary[$i];
  1305. }
  1306. }
  1307. if(isset($_REQUEST["record"]) && $_REQUEST["record"] != '')
  1308. {
  1309. $options['label'][] = getTranslatedString($columntototalrow['tablabel'],$columntototalrow['tablabel']).' -'.getTranslatedString($columntototalrow['fieldlabel'],$columntototalrow['tablabel']);
  1310. }
  1311. $columntototalrow['fieldlabel'] = str_replace(" ","_",$columntototalrow['fieldlabel']);
  1312. $options []= getTranslatedString($columntototalrow['tablabel'],$columntototalrow['tablabel']).' - '.getTranslatedString($columntototalrow['fieldlabel'],$columntototalrow['tablabel']);
  1313. if($selectedcolumn1[2] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_SUM:2")
  1314. {
  1315. $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_SUM:2" type="checkbox" value="">';
  1316. }else
  1317. {
  1318. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_SUM:2" type="checkbox" value="">';
  1319. }
  1320. if($selectedcolumn1[3] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_AVG:3")
  1321. {
  1322. $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_AVG:3" type="checkbox" value="">';
  1323. }else
  1324. {
  1325. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_AVG:3" type="checkbox" value="">';
  1326. }
  1327. if($selectedcolumn1[4] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_MIN:4")
  1328. {
  1329. $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MIN:4" type="checkbox" value="">';
  1330. }else
  1331. {
  1332. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MIN:4" type="checkbox" value="">';
  1333. }
  1334. if($selectedcolumn1[5] == "cb:".$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel']."_MAX:5")
  1335. {
  1336. $options []= '<input checked name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MAX:5" type="checkbox" value="">';
  1337. }else
  1338. {
  1339. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MAX:5" type="checkbox" value="">';
  1340. }
  1341. }else
  1342. {
  1343. $options []= getTranslatedString($columntototalrow['tablabel'],$columntototalrow['tablabel']).' - '.getTranslatedString($columntototalrow['fieldlabel'],$columntototalrow['tablabel']);
  1344. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_SUM:2" type="checkbox" value="">';
  1345. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_AVG:3" type="checkbox" value="" >';
  1346. $options []= '<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MIN:4"type="checkbox" value="" >';
  1347. $options [] ='<input name="cb:'.$columntototalrow['tablename'].':'.$columntototalrow['columnname'].':'.$columntototalrow['fieldlabel'].'_MAX:5" type="checkbox" value="" >';
  1348. }
  1349. $options_list [] = $options;
  1350. }
  1351. }while($columntototalrow = $adb->fetch_array($result));
  1352. $log->info("Reports :: Successfully returned sgetColumnstoTotalHTML");
  1353. return $options_list;
  1354. }
  1355. /** Function to get the advanced filter criteria for an option
  1356. * This function accepts The option in the advenced filter as an argument
  1357. * This generate filter criteria for the advanced filter
  1358. * It returns a HTML string of combo values
  1359. */
  1360. public static function getAdvCriteriaHTML($selected="") {
  1361. global $adv_filter_options;
  1362. foreach($adv_filter_options as $key=>$value) {
  1363. if($selected == $key) {
  1364. $shtml .= "<option selected value=\"".$key."\">".$value."</option>";
  1365. } else {
  1366. $shtml .= "<option value=\"".$key."\">".$value."</option>";
  1367. }
  1368. }
  1369. return $shtml;
  1370. }
  1371. }
  1372. /** Function to get the primary module list in vtiger_reports
  1373. * This function generates the list of primary modules in vtiger_reports
  1374. * and returns an array of permitted modules
  1375. */
  1376. function getReportsModuleList($focus)
  1377. {
  1378. global $adb;
  1379. global $app_list_strings;
  1380. //global $report_modules;
  1381. global $mod_strings;
  1382. $modules = Array();
  1383. foreach($focus->module_list as $key=>$value) {
  1384. if(isPermitted($key,'index') == "yes") {
  1385. $count_flag = 1;
  1386. $modules [$key] = getTranslatedString($key,$key);
  1387. }
  1388. }
  1389. asort($modules);
  1390. return $modules;
  1391. }
  1392. /** Function to get the Related module list in vtiger_reports
  1393. * This function generates the list of secondary modules in vtiger_reports
  1394. * and returns the related module as an Array
  1395. */
  1396. function getReportRelatedModules($module,$focus)
  1397. {
  1398. global $app_list_strings;
  1399. global $related_modules;
  1400. global $mod_strings;
  1401. $optionhtml = Array();
  1402. if(vtlib_isModuleActive($module)){
  1403. if(!empty($focus->related_modules[$module])) {
  1404. foreach($focus->related_modules[$module] as $rel_modules)
  1405. {
  1406. if(isPermitted($rel_modules,'index') == "yes")
  1407. {
  1408. $optionhtml []= $rel_modules;
  1409. }
  1410. }
  1411. }
  1412. }
  1413. return $optionhtml;
  1414. }
  1415. function updateAdvancedCriteria($reportid, $advft_criteria, $advft_criteria_groups) {
  1416. global $adb, $log;
  1417. $idelrelcriteriasql = "delete from vtiger_relcriteria where queryid=?";
  1418. $idelrelcriteriasqlresult = $adb->pquery($idelrelcriteriasql, array($reportid));
  1419. $idelrelcriteriagroupsql = "delete from vtiger_relcriteria_grouping where queryid=?";
  1420. $idelrelcriteriagroupsqlresult = $adb->pquery($idelrelcriteriagroupsql, array($reportid));
  1421. if(empty($advft_criteria)) return;
  1422. foreach($advft_criteria as $column_index => $column_condition) {
  1423. if(empty($column_condition)) continue;
  1424. $adv_filter_column = $column_condition["columnname"];
  1425. $adv_filter_comparator = $column_condition["comparator"];
  1426. $adv_filter_value = $column_condition["value"];
  1427. $adv_filter_column_condition = $column_condition["columncondition"];
  1428. $adv_filter_groupid = $column_condition["groupid"];
  1429. $column_info = explode(":",$adv_filter_column);
  1430. $moduleFieldLabel = $column_info[2];
  1431. $fieldName = $column_info[3];
  1432. list($module, $fieldLabel) = explode('_', $moduleFieldLabel, 2);
  1433. $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
  1434. $fieldType = null;
  1435. if(!empty($fieldInfo)) {
  1436. $field = WebserviceField::fromArray($adb, $fieldInfo);
  1437. $fieldType = $field->getFieldDataType();
  1438. }
  1439. if($fieldType == 'currency') {
  1440. // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion
  1441. if($field->getUIType() == '72') {
  1442. $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value, null, true);
  1443. } else {
  1444. $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value);
  1445. }
  1446. }
  1447. $temp_val = explode(",",$adv_filter_value);
  1448. if(($column_info[4] == 'D' || ($column_info[4] == 'T' && $column_info[1] != 'time_start' && $column_info[1] != 'time_end') || ($column_info[4] == 'DT')) && ($column_info[4] != '' && $adv_filter_value != '' ))
  1449. {
  1450. $val = Array();
  1451. for($x=0;$x<count($temp_val);$x++) {
  1452. if(trim($temp_val[$x]) != '') {
  1453. $date = new DateTimeField(trim($temp_val[$x]));
  1454. if($column_info[4] == 'D') {
  1455. $val[$x] = DateTimeField::convertToUserFormat(
  1456. trim($temp_val[$x]));
  1457. } elseif($column_info[4] == 'DT') {
  1458. $val[$x] = $date->getDBInsertDateTimeValue();
  1459. } else {
  1460. $val[$x] = $date->getDBInsertTimeValue();
  1461. }
  1462. }
  1463. }
  1464. $adv_filter_value = implode(",",$val);
  1465. }
  1466. $irelcriteriasql = "insert into vtiger_relcriteria(QUERYID,COLUMNINDEX,COLUMNNAME,COMPARATOR,VALUE,GROUPID,COLUMN_CONDITION) values (?,?,?,?,?,?,?)";
  1467. $irelcriteriaresult = $adb->pquery($irelcriteriasql, array($reportid, $column_index, $adv_filter_column, $adv_filter_comparator, $adv_filter_value, $adv_filter_groupid, $adv_filter_column_condition));
  1468. // Update the condition expression for the group to which the condition column belongs
  1469. $groupConditionExpression = '';
  1470. if(!empty($advft_criteria_groups[$adv_filter_groupid]["conditionexpression"])) {
  1471. $groupConditionExpression = $advft_criteria_groups[$adv_filter_groupid]["conditionexpression"];
  1472. }
  1473. $groupConditionExpression = $groupConditionExpression .' '. $column_index .' '. $adv_filter_column_condition;
  1474. $advft_criteria_groups[$adv_filter_groupid]["conditionexpression"] = $groupConditionExpression;
  1475. }
  1476. foreach($advft_criteria_groups as $group_index => $group_condition_info) {
  1477. if(empty($group_condition_info)) continue;
  1478. if(empty($group_condition_info["conditionexpression"])) continue; // Case when the group doesn't have any column criteria
  1479. $irelcriteriagroupsql = "insert into vtiger_relcriteria_grouping(GROUPID,QUERYID,GROUP_CONDITION,CONDITION_EXPRESSION) values (?,?,?,?)";
  1480. $irelcriteriagroupresult = $adb->pquery($irelcriteriagroupsql, array($group_index, $reportid, $group_condition_info["groupcondition"], $group_condition_info["conditionexpression"]));
  1481. }
  1482. }
  1483. ?>