PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/vtigerCRM/modules/CustomView/EditView.php

https://github.com/hitchby/PLEXUS
PHP | 391 lines | 330 code | 32 blank | 29 comment | 69 complexity | 578770ee61d7d162f06d7e799295bdc5 MD5 | raw file
  1. <?php
  2. /*+********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ********************************************************************************/
  10. require_once('data/Tracker.php');
  11. global $mod_strings;
  12. global $app_list_strings;
  13. global $app_strings;
  14. global $current_user;
  15. $focus = 0;
  16. global $theme;
  17. global $log,$default_charset;
  18. //<<<<<>>>>>>
  19. global $oCustomView;
  20. //<<<<<>>>>>>
  21. $error_msg = '';
  22. $theme_path="themes/".$theme."/";
  23. $image_path=$theme_path."images/";
  24. require_once('modules/CustomView/CustomView.php');
  25. $cv_module = vtlib_purify($_REQUEST['module']);
  26. $recordid = vtlib_purify($_REQUEST['record']);
  27. $smarty->assign("MOD", $mod_strings);
  28. $smarty->assign("CATEGORY", getParentTab());
  29. $smarty->assign("APP", $app_strings);
  30. $smarty->assign("THEME", $theme);
  31. $smarty->assign("IMAGE_PATH", $image_path);
  32. $smarty->assign("MODULE",$cv_module);
  33. $smarty->assign("MODULELABEL",getTranslatedString($cv_module,$cv_module));
  34. $smarty->assign("CVMODULE", $cv_module);
  35. $smarty->assign("CUSTOMVIEWID",$recordid);
  36. $smarty->assign("DATEFORMAT",$current_user->date_format);
  37. $smarty->assign("JS_DATEFORMAT",parse_calendardate($app_strings['NTC_DATE_FORMAT']));
  38. $smarty->assign("DATE_JS", '<script>userDateFormat = "'.$current_user->date_format.'" </script>');
  39. if($recordid == "")
  40. {
  41. $oCustomView = new CustomView();
  42. $modulecollist = $oCustomView->getModuleColumnsList($cv_module);
  43. $log->info('CustomView :: Successfully got ColumnsList for the module'.$cv_module);
  44. if(isset($modulecollist))
  45. {
  46. $choosecolhtml = getByModule_ColumnsHTML($cv_module,$modulecollist);
  47. }
  48. //step2
  49. $stdfilterhtml = $oCustomView->getStdFilterCriteria();
  50. $log->info('CustomView :: Successfully got StandardFilter for the module'.$cv_module);
  51. $stdfiltercolhtml = getStdFilterHTML($cv_module);
  52. $stdfilterjs = $oCustomView->getCriteriaJS();
  53. //step4
  54. $advfilterhtml = getAdvCriteriaHTML();
  55. for($i=1;$i<10;$i++)
  56. {
  57. $smarty->assign("CHOOSECOLUMN".$i,$choosecolhtml);
  58. }
  59. $log->info('CustomView :: Successfully got AdvancedFilter for the module'.$cv_module);
  60. for($i=1;$i<6;$i++)
  61. {
  62. $smarty->assign("FOPTION".$i,$advfilterhtml);
  63. $smarty->assign("BLOCK".$i,$choosecolhtml);
  64. }
  65. $smarty->assign("STDFILTERCOLUMNS",$stdfiltercolhtml);
  66. $smarty->assign("STDCOLUMNSCOUNT",count($stdfiltercolhtml));
  67. $smarty->assign("STDFILTERCRITERIA",$stdfilterhtml);
  68. $smarty->assign("STDFILTER_JAVASCRIPT",$stdfilterjs);
  69. $smarty->assign("MANDATORYCHECK",implode(",",array_unique($oCustomView->mandatoryvalues)));
  70. $smarty->assign("SHOWVALUES",implode(",",$oCustomView->showvalues));
  71. $data_type[] = $oCustomView->data_type;
  72. $smarty->assign("DATATYPE",$data_type);
  73. }
  74. else
  75. {
  76. $oCustomView = new CustomView($cv_module);
  77. $now_action = vtlib_purify($_REQUEST['action']);
  78. if($oCustomView->isPermittedCustomView($recordid,$now_action,$oCustomView->customviewmodule) == 'yes')
  79. {
  80. $customviewdtls = $oCustomView->getCustomViewByCvid($recordid);
  81. $log->info('CustomView :: Successfully got ViewDetails for the Viewid'.$recordid);
  82. $modulecollist = $oCustomView->getModuleColumnsList($cv_module);
  83. $selectedcolumnslist = $oCustomView->getColumnsListByCvid($recordid);
  84. $log->info('CustomView :: Successfully got ColumnsList for the Viewid'.$recordid);
  85. $smarty->assign("VIEWNAME",$customviewdtls["viewname"]);
  86. if($customviewdtls["setdefault"] == 1)
  87. {
  88. $smarty->assign("CHECKED","checked");
  89. }
  90. if($customviewdtls["setmetrics"] == 1)
  91. {
  92. $smarty->assign("MCHECKED","checked");
  93. }
  94. $status = $customviewdtls["status"];
  95. $smarty->assign("STATUS",$status);
  96. for($i=1;$i<10;$i++)
  97. {
  98. $choosecolhtml = getByModule_ColumnsHTML($cv_module,$modulecollist,$selectedcolumnslist[$i-1]);
  99. $smarty->assign("CHOOSECOLUMN".$i,$choosecolhtml);
  100. }
  101. $stdfilterlist = $oCustomView->getStdFilterByCvid($recordid);
  102. $log->info('CustomView :: Successfully got Standard Filter for the Viewid'.$recordid);
  103. $stdfilterlist["stdfilter"] = ($stdfilterlist["stdfilter"] != "") ? ($stdfilterlist["stdfilter"]) : ("custom");
  104. $stdfilterhtml = $oCustomView->getStdFilterCriteria($stdfilterlist["stdfilter"]);
  105. $stdfiltercolhtml = getStdFilterHTML($cv_module,$stdfilterlist["columnname"]);
  106. $stdfilterjs = $oCustomView->getCriteriaJS();
  107. if(isset($stdfilterlist["startdate"]) && isset($stdfilterlist["enddate"]))
  108. {
  109. $smarty->assign("STARTDATE",getDisplayDate($stdfilterlist["startdate"]));
  110. $smarty->assign("ENDDATE",getDisplayDate($stdfilterlist["enddate"]));
  111. }
  112. else{
  113. $smarty->assign("STARTDATE",$stdfilterlist["startdate"]);
  114. $smarty->assign("ENDDATE",$stdfilterlist["enddate"]);
  115. }
  116. $advfilterlist = $oCustomView->getAdvFilterByCvid($recordid);
  117. $log->info('CustomView :: Successfully got Advanced Filter for the Viewid'.$recordid,'info');
  118. for($i=1;$i<6;$i++)
  119. {
  120. $advfilterhtml = getAdvCriteriaHTML($advfilterlist[$i-1]["comparator"]);
  121. $advcolumnhtml = getByModule_ColumnsHTML($cv_module,$modulecollist,$advfilterlist[$i-1]["columnname"]);
  122. $smarty->assign("FOPTION".$i,$advfilterhtml);
  123. $smarty->assign("BLOCK".$i,$advcolumnhtml);
  124. $col = explode(":",$advfilterlist[$i-1]["columnname"]);
  125. $temp_val = explode(",",$advfilterlist[$i-1]["value"]);
  126. $and_text = "&nbsp;".$mod_strings['LBL_AND'];
  127. if($col[4] == 'D' || ($col[4] == 'T' && $col[1] != 'time_start' && $col[1] != 'time_end') || $col[4] == 'DT')
  128. {
  129. $val = Array();
  130. for($x=0;$x<count($temp_val);$x++)
  131. if(trim($temp_val[$x] != ""))
  132. $val[$x] = getDisplayDate(trim($temp_val[$x]));
  133. $advfilterlist[$i-1]["value"] = implode(", ",$val);
  134. $and_text = "<em old='(yyyy-mm-dd)'>(".$current_user->date_format.")</em>&nbsp;".$mod_strings['LBL_AND'];
  135. }
  136. $smarty->assign("VALUE".$i,$advfilterlist[$i-1]["value"]);
  137. $smarty->assign("AND_TEXT".$i,$and_text);
  138. }
  139. $smarty->assign("STDFILTERCOLUMNS",$stdfiltercolhtml);
  140. $smarty->assign("STDCOLUMNSCOUNT",count($stdfiltercolhtml));
  141. $smarty->assign("STDFILTERCRITERIA",$stdfilterhtml);
  142. $smarty->assign("STDFILTER_JAVASCRIPT",$stdfilterjs);
  143. $smarty->assign("MANDATORYCHECK",implode(",",array_unique($oCustomView->mandatoryvalues)));
  144. $smarty->assign("SHOWVALUES",implode(",",$oCustomView->showvalues));
  145. $smarty->assign("EXIST","true");
  146. $cactionhtml = "<input name='customaction' class='button' type='button' value='Create Custom Action' onclick=goto_CustomAction('".$cv_module."');>";
  147. if($cv_module == "Leads" || $cv_module == "Accounts" || $cv_module == "Contacts")
  148. {
  149. $smarty->assign("CUSTOMACTIONBUTTON",$cactionhtml);
  150. }
  151. $data_type[] = $oCustomView->data_type;
  152. $smarty->assign("DATATYPE",$data_type);
  153. }
  154. else
  155. {
  156. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  157. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  158. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  159. <tbody><tr>
  160. <td rowspan='2' width='11%'><img src='". vtiger_imageurl('denied.gif', $theme)."' ></td>
  161. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  162. </tr>
  163. <tr>
  164. <td class='small' align='right' nowrap='nowrap'>
  165. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br>
  166. </td>
  167. </tr>
  168. </tbody></table>
  169. </div>";
  170. echo "</td></tr></table>";
  171. exit;
  172. }
  173. }
  174. $smarty->assign("RETURN_MODULE", $cv_module);
  175. if($cv_module == "Calendar")
  176. $return_action = "ListView";
  177. else
  178. $return_action = "index";
  179. if($recordid == '')
  180. $act = $mod_strings['LBL_NEW'];
  181. else
  182. $act = $mod_strings['LBL_EDIT'];
  183. $smarty->assign("ACT", $act);
  184. $smarty->assign("RETURN_ACTION", $return_action);
  185. $smarty->display("CustomView.tpl");
  186. function getByModule_ColumnsHTML($module,$columnslist,$selected="")
  187. {
  188. global $oCustomView, $current_language,$theme;
  189. global $app_list_strings;
  190. $advfilter = array();
  191. $mod_strings = return_specified_module_language($current_language,$module);
  192. $check_dup = Array();
  193. foreach($oCustomView->module_list[$module] as $key=>$value)
  194. {
  195. $advfilter = array();
  196. $label = $key;
  197. if(isset($columnslist[$module][$key]))
  198. {
  199. foreach($columnslist[$module][$key] as $field=>$fieldlabel)
  200. {
  201. if(!in_array($fieldlabel,$check_dup))
  202. {
  203. if(isset($mod_strings[$fieldlabel]))
  204. {
  205. if($selected == $field)
  206. {
  207. $advfilter_option['value'] = $field;
  208. $advfilter_option['text'] = $mod_strings[$fieldlabel];
  209. $advfilter_option['selected'] = "selected";
  210. }else
  211. {
  212. $advfilter_option['value'] = $field;
  213. $advfilter_option['text'] = $mod_strings[$fieldlabel];
  214. $advfilter_option['selected'] = "";
  215. }
  216. }else
  217. {
  218. if($selected == $field)
  219. {
  220. $advfilter_option['value'] = $field;
  221. $advfilter_option['text'] = $fieldlabel;
  222. $advfilter_option['selected'] = "selected";
  223. }else
  224. {
  225. $advfilter_option['value'] = $field;
  226. $advfilter_option['text'] = $fieldlabel;
  227. $advfilter_option['selected'] = "";
  228. }
  229. }
  230. $advfilter[] = $advfilter_option;
  231. $check_dup [] = $fieldlabel;
  232. }
  233. }
  234. $advfilter_out[$label]= $advfilter;
  235. }
  236. }
  237. // Special case handling only for Calendar moudle - Not required for other modules.
  238. if($module == 'Calendar') {
  239. $finalfield = Array();
  240. $finalfield1 = Array();
  241. $finalfield2 = Array();
  242. $newLabel = $mod_strings['LBL_CALENDAR_INFORMATION'];
  243. if(isset($advfilter_out[$mod_strings['LBL_TASK_INFORMATION']])) {
  244. $finalfield1 = $advfilter_out[$mod_strings['LBL_TASK_INFORMATION']];
  245. }
  246. if(isset($advfilter_out[$mod_strings['LBL_EVENT_INFORMATION']])) {
  247. $finalfield2 = $advfilter_out[$mod_strings['LBL_EVENT_INFORMATION']];
  248. }
  249. $finalfield[$newLabel] = array_merge($finalfield1,$finalfield2);
  250. if (isset ($advfilter_out[$mod_strings['LBL_CUSTOM_INFORMATION']])) {
  251. $finalfield[$mod_strings['LBL_CUSTOM_INFORMATION']] = $advfilter_out[$mod_strings['LBL_CUSTOM_INFORMATION']];
  252. }
  253. $advfilter_out=$finalfield;
  254. }
  255. return $advfilter_out;
  256. }
  257. /** to get the standard filter criteria
  258. * @param $module(module name) :: Type String
  259. * @param $elected (selection status) :: Type String (optional)
  260. * @returns $filter Array in the following format
  261. * $filter = Array( 0 => array('value'=>$tablename:$colname:$fieldname:$fieldlabel,'text'=>$mod_strings[$field label],'selected'=>$selected),
  262. * 1 => array('value'=>$$tablename1:$colname1:$fieldname1:$fieldlabel1,'text'=>$mod_strings[$field label1],'selected'=>$selected),
  263. */
  264. function getStdFilterHTML($module,$selected="")
  265. {
  266. global $app_list_strings, $current_language,$app_strings,$current_user;
  267. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  268. global $oCustomView;
  269. $stdfilter = array();
  270. $result = $oCustomView->getStdCriteriaByModule($module);
  271. $mod_strings = return_module_language($current_language,$module);
  272. if(isset($result))
  273. {
  274. foreach($result as $key=>$value)
  275. {
  276. if($value == 'Start Date & Time')
  277. {
  278. $value = 'Start Date';
  279. }
  280. $use_module_label = getTranslatedString($module, $module);
  281. if(isset($app_list_strings['moduleList'][$module])) {
  282. $use_module_label = $app_list_strings['moduleList'][$module];
  283. }
  284. if(isset($mod_strings[$value]))
  285. {
  286. if($key == $selected)
  287. {
  288. $filter['value'] = $key;
  289. $filter['text'] = $use_module_label." - ".getTranslatedString($value);
  290. $filter['selected'] = "selected";
  291. }else
  292. {
  293. $filter['value'] = $key;
  294. $filter['text'] = $use_module_label." - ".getTranslatedString($value);
  295. $filter['selected'] ="";
  296. }
  297. }
  298. else
  299. {
  300. if($key == $selected)
  301. {
  302. $filter['value'] = $key;
  303. $filter['text'] = $use_module_label." - ".$value;
  304. $filter['selected'] = 'selected';
  305. }else
  306. {
  307. $filter['value'] = $key;
  308. $filter['text'] = $use_module_label." - ".$value;
  309. $filter['selected'] ='';
  310. }
  311. }
  312. $stdfilter[]=$filter;
  313. //added to fix ticket #5117. If a user doesn't have permission for a field and it has been used to fileter a custom view, it should be get displayed to him as Not Accessible.
  314. if(!$is_admin && $selected != '' && $filter['selected'] == '')
  315. {
  316. $keys = explode(":",$selected);
  317. if(getFieldVisibilityPermission($module,$current_user->id,$keys[2]) != '0')
  318. {
  319. $filter['value'] = "not_accessible";
  320. $filter['text'] = $app_strings["LBL_NOT_ACCESSIBLE"];
  321. $filter['selected'] = "selected";
  322. $stdfilter[]=$filter;
  323. }
  324. }
  325. }
  326. }
  327. return $stdfilter;
  328. }
  329. /** to get the Advanced filter criteria
  330. * @param $selected :: Type String (optional)
  331. * @returns $AdvCriteria Array in the following format
  332. * $AdvCriteria = Array( 0 => array('value'=>$tablename:$colname:$fieldname:$fieldlabel,'text'=>$mod_strings[$field label],'selected'=>$selected),
  333. * 1 => array('value'=>$$tablename1:$colname1:$fieldname1:$fieldlabel1,'text'=>$mod_strings[$field label1],'selected'=>$selected),
  334. * |
  335. * n => array('value'=>$$tablenamen:$colnamen:$fieldnamen:$fieldlabeln,'text'=>$mod_strings[$field labeln],'selected'=>$selected))
  336. */
  337. function getAdvCriteriaHTML($selected="")
  338. {
  339. global $adv_filter_options;
  340. global $app_list_strings;
  341. $AdvCriteria = array();
  342. foreach($adv_filter_options as $key=>$value)
  343. {
  344. if($selected == $key)
  345. {
  346. $advfilter_criteria['value'] = $key;
  347. $advfilter_criteria['text'] = $value;
  348. $advfilter_criteria['selected'] = "selected";
  349. }else
  350. {
  351. $advfilter_criteria['value'] = $key;
  352. $advfilter_criteria['text'] = $value;
  353. $advfilter_criteria['selected'] = "";
  354. }
  355. $AdvCriteria[] = $advfilter_criteria;
  356. }
  357. return $AdvCriteria;
  358. }
  359. ?>