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

/administrator/components/com_acymailing/views/filter/view.html.php

https://gitlab.com/endomorphosis/OLAAaction
PHP | 190 lines | 186 code | 0 blank | 4 comment | 25 complexity | 14baa13e7c23fd150febb7cc7831f4bf MD5 | raw file
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2009-2011 ACYBA SARL - All rights reserved.
  4. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
  5. */
  6. defined('_JEXEC') or die('Restricted access');
  7. ?>
  8. <?php
  9. class FilterViewFilter extends JView
  10. {
  11. function display($tpl = null)
  12. {
  13. $function = $this->getLayout();
  14. if(method_exists($this,$function)) $this->$function();
  15. parent::display($tpl);
  16. }
  17. function form(){
  18. $db =& JFactory::getDBO();
  19. $config = acymailing_config();
  20. $filid = acymailing_getCID('filid');
  21. $filterClass = acymailing_get('class.filter');
  22. if(!empty($filid)){
  23. $filter = $filterClass->get($filid);
  24. }else{
  25. $filter = null;
  26. $filter->action = JRequest::getVar('action');
  27. $filter->filter = JRequest::getVar('filter');
  28. $filter->published = 1;
  29. }
  30. JPluginHelper::importPlugin('acymailing');
  31. $this->dispatcher = &JDispatcher::getInstance();
  32. $typesFilters = array();
  33. $typesActions = array();
  34. $outputFilters = implode('',$this->dispatcher->trigger('onAcyDisplayFilters',array(&$typesFilters)));
  35. $outputActions = implode('',$this->dispatcher->trigger('onAcyDisplayActions',array(&$typesActions)));
  36. $typevaluesFilters = array();
  37. $typevaluesActions = array();
  38. $typevaluesFilters[] = JHTML::_('select.option', '',JText::_('FILTER_SELECT'));
  39. $typevaluesActions[] = JHTML::_('select.option', '',JText::_('ACTION_SELECT'));
  40. $doc =& JFactory::getDocument();
  41. foreach($typesFilters as $oneType => $oneName){
  42. $typevaluesFilters[] = JHTML::_('select.option', $oneType,$oneName);
  43. }
  44. foreach($typesActions as $oneType => $oneName){
  45. $typevaluesActions[] = JHTML::_('select.option', $oneType,$oneName);
  46. }
  47. $js = "function updateFilter(filterNum){
  48. currentFilterType =window.document.getElementById('filtertype'+filterNum).value;
  49. if(!currentFilterType){
  50. window.document.getElementById('filterarea_'+filterNum).innerHTML = '';
  51. document.getElementById('countresult_'+filterNum).innerHTML = '';
  52. return;
  53. }
  54. filterArea = 'filter__num__'+currentFilterType;
  55. window.document.getElementById('filterarea_'+filterNum).innerHTML = window.document.getElementById(filterArea).innerHTML.replace(/__num__/g,filterNum);
  56. }
  57. function updateAction(actionNum){
  58. currentActionType =window.document.getElementById('actiontype'+actionNum).value;
  59. if(!currentActionType){
  60. window.document.getElementById('actionarea_'+actionNum).innerHTML = '';
  61. return;
  62. }
  63. actionArea = 'action__num__'+currentActionType;
  64. window.document.getElementById('actionarea_'+actionNum).innerHTML = window.document.getElementById(actionArea).innerHTML.replace(/__num__/g,actionNum);
  65. }";
  66. $js .= "var numFilters = 0;
  67. var numActions = 0;
  68. function addAcyFilter(){
  69. var newdiv = document.createElement('div');
  70. newdiv.id = 'filter'+numFilters;
  71. newdiv.className = 'plugarea';
  72. newdiv.innerHTML = '';
  73. if(numFilters > 0) newdiv.innerHTML += '".JText::_('FILTER_AND')."';
  74. newdiv.innerHTML += document.getElementById('filters_original').innerHTML.replace(/__num__/g, numFilters);
  75. if(document.getElementById('allfilters')){
  76. document.getElementById('allfilters').appendChild(newdiv); updateFilter(numFilters); numFilters++;
  77. }
  78. }
  79. function addAction(){
  80. var newdiv = document.createElement('div');
  81. newdiv.id = 'action'+numActions;
  82. newdiv.className = 'plugarea';
  83. newdiv.innerHTML = document.getElementById('actions_original').innerHTML.replace(/__num__/g, numActions);
  84. document.getElementById('allactions').appendChild(newdiv); updateAction(numActions); numActions++; }";
  85. $js .= "window.addEvent('domready', function(){ addAcyFilter(); addAction(); });";
  86. if(version_compare(JVERSION,'1.6.0','<')){
  87. $js .= 'function submitbutton(pressbutton){
  88. if (pressbutton != \'save\') {
  89. submitform( pressbutton );
  90. return;
  91. }';
  92. }else{
  93. $js .= 'Joomla.submitbutton = function(pressbutton) {
  94. if (pressbutton != \'save\') {
  95. Joomla.submitform(pressbutton,document.adminForm);
  96. return;
  97. }';
  98. }
  99. $js .= "if(window.document.getElementById('filterinfo').style.display == 'none'){
  100. window.document.getElementById('filterinfo').style.display = 'block';
  101. try{allspans = window.document.getElementById('toolbar-save').getElementsByTagName(\"span\"); allspans[0].className = 'icon-32-apply';}catch(err){}
  102. return false;}
  103. if(window.document.getElementById('title').value.length < 2){alert('".JText::_('ENTER_TITLE',true)."'); return false;}";
  104. if(version_compare(JVERSION,'1.6.0','<')){
  105. $js .= "submitform( pressbutton );} ";
  106. }else{ $js .= "Joomla.submitform(pressbutton,document.adminForm);}; "; }
  107. $js .= "function countresults(num){
  108. document.getElementById('countresult_'+num).innerHTML = '<span class=\"onload\"></span>';
  109. try{
  110. new Ajax('index.php?'+document.adminForm.toQueryString()+'&option=com_acymailing&tmpl=component&ctrl=filter&task=countresults&num='+num,{ method: 'post', update: document.getElementById('countresult_'+num)}).request();
  111. }catch(err){
  112. new Request({
  113. method: 'post',
  114. url: 'index.php?'+document.adminForm.toQueryString()+'&option=com_acymailing&tmpl=component&ctrl=filter&task=countresults&num='+num,
  115. onSuccess: function(responseText, responseXML) {
  116. document.getElementById('countresult_'+num).innerHTML = responseText;
  117. }
  118. }).send();
  119. }
  120. }";
  121. $doc->addScriptDeclaration( $js );
  122. $js = '';
  123. $data = array('addAction' => 'action','addAcyFilter' => 'filter');
  124. foreach($data as $jsFunction => $datatype){
  125. if(empty($filter->$datatype)) continue;
  126. foreach($filter->{$datatype}['type'] as $num => $oneType){
  127. if(empty($oneType)) continue;
  128. $js .= "while(!document.getElementById('".$datatype."type$num')){".$jsFunction."();}
  129. document.getElementById('".$datatype."type$num').value= '$oneType';
  130. update".ucfirst($datatype)."($num);";
  131. if(empty($filter->{$datatype}[$num][$oneType])) continue;
  132. foreach($filter->{$datatype}[$num][$oneType] as $key => $value){
  133. $js .= "document.adminForm.elements['".$datatype."[$num][$oneType][$key]'].value = '".addslashes(str_replace(array("\n","\r"),' ',$value))."';";
  134. $js .= "if(document.adminForm.elements['".$datatype."[$num][$oneType][$key]'].type && document.adminForm.elements['".$datatype."[$num][$oneType][$key]'].type == 'checkbox'){ document.adminForm.elements['".$datatype."[$num][$oneType][$key]'].checked = 'checked'; }";
  135. }
  136. if($datatype == 'filter') $js.= " countresults($num);";
  137. }
  138. }
  139. $listid = JRequest::getInt('listid');
  140. if(!empty($listid)){
  141. $js .= "document.getElementById('actiontype0').value = 'list'; updateAction(0); document.adminForm.elements['action[0][list][selectedlist]'].value = '".$listid."';";
  142. }
  143. $doc->addScriptDeclaration( "window.addEvent('domready', function(){ $js });" );
  144. $triggers = array();
  145. $triggers['daycron'] = JText::_('AUTO_CRON_FILTER');
  146. $nextDate = $config->get('cron_plugins_next');
  147. if(!empty($nextDate)){
  148. $triggers['daycron'] .= ' ('.JText::_('NEXT_RUN').' : '.acymailing_getDate($nextDate,'%d %B %H:%M').')';
  149. }
  150. $triggers['subcreate'] = JText::_('ON_USER_CREATE');
  151. $triggers['subchange'] = JText::_('ON_USER_CHANGE');
  152. $this->dispatcher->trigger('onAcyDisplayTriggers',array(&$triggers));
  153. $name = empty($filter->name) ? '' : ' : '.$filter->name;
  154. acymailing_setTitle(JText::_('ACY_FILTER').$name,'filter','filter&task=edit&filid='.$filid);
  155. $bar = & JToolBar::getInstance('toolbar');
  156. $bar->appendButton( 'Confirm', JText::_('PROCESS_CONFIRMATION'), 'process', JText::_('PROCESS'), 'process', false, false );
  157. JToolBarHelper::divider();
  158. if(acymailing_level(3)){
  159. JToolBarHelper::save();
  160. if(!empty($filter->filid)) $bar->appendButton( 'Link', 'new', JText::_('ACY_NEW'), acymailing_completeLink('filter&task=edit&filid=0') );
  161. }
  162. $bar->appendButton( 'Link', 'cancel', JText::_('ACY_CLOSE'), acymailing_completeLink('dashboard') );
  163. JToolBarHelper::divider();
  164. $bar->appendButton( 'Pophelp','filter');
  165. $subid = JRequest::getString('subid');
  166. if(!empty($subid)){
  167. $subArray = explode(',',trim($subid,','));
  168. JArrayHelper::toInteger($subArray);
  169. $db->setQuery('SELECT `name`,`email` FROM `#__acymailing_subscriber` WHERE `subid` IN ('.implode(',',$subArray).')');
  170. $users = $db->loadObjectList();
  171. if(!empty($users)){
  172. $this->assignRef('users',$users);
  173. $this->assignRef('subid',$subid);
  174. }
  175. }
  176. $this->assignRef('typevaluesFilters',$typevaluesFilters);
  177. $this->assignRef('typevaluesActions',$typevaluesActions);
  178. $this->assignRef('outputFilters',$outputFilters);
  179. $this->assignRef('outputActions',$outputActions);
  180. $this->assignRef('filter',$filter);
  181. $this->assignRef('triggers',$triggers);
  182. $doc->addStyleSheet( ACYMAILING_CSS.'frontendedition.css' );
  183. if(acymailing_level(3) AND JRequest::getCmd('tmpl') != 'component'){
  184. $db->setQuery('SELECT * FROM #__acymailing_filter ORDER BY `published` DESC, `filid` DESC');
  185. $filters = $db->loadObjectList();
  186. $this->assignRef('toggleClass',acymailing_get('helper.toggle'));
  187. $this->assignRef('filters',$filters);
  188. }
  189. }
  190. }