[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /* 3 * phpMyVisites : website statistics and audience measurements 4 * Copyright (C) 2002 - 2006 5 * http://www.phpmyvisites.net/ 6 * phpMyVisites is free software (license GNU/GPL) 7 * Authors : phpMyVisites team 8 */ 9 10 // $Id: Form.class.php 171 2006-11-19 18:32:59Z cmil $ 11 12 require_once INCLUDE_PATH . "/libs/Html/QuickForm.php"; 13 require_once INCLUDE_PATH . "/libs/Html/QuickForm/Renderer/ArraySmarty.php"; 14 15 class Form extends HTML_QuickForm 16 { 17 var $a_formElements = array(); 18 var $tpl; // reference to template object 19 20 21 function Form( &$template, $action = null ) 22 { 23 if(is_null($action)) 24 { 25 $action = Request::getCurrentUrl(); 26 } 27 28 parent::HTML_QuickForm('form_phpmv', 'POST', $action); 29 30 $this->tpl =& $template; 31 32 $this->init(); 33 34 } 35 36 37 function init() 38 { 39 $this->applyFilter('__ALL__','trim'); 40 41 $this->registerRule( 'checkCorrectIp', "function", 'checkCorrectIp'); 42 $this->registerRule( 'compareField', "function", 'compareField'); 43 $this->registerRule( 'complexPassword', "function", "checkPasswordComplexity"); 44 $this->registerRule( 'checkCorrectUrl', "function", "checkCorrectUrl"); 45 $this->registerRule( 'changePassword', "function", "checkChangePassword"); 46 $this->registerRule( 'checkOldCurrentPassword', "function", "checkOldCurrentPassword"); 47 } 48 49 function getRuleCheckUrl( $inputName ) 50 { 51 return array($inputName, 52 sprintf($GLOBALS['lang']['admin_error_url'], URL_SITE_EXAMPLE), 53 'checkCorrectUrl'); 54 } 55 56 function getSubmitValue( $name ) 57 { 58 return addslashes(parent::getSubmitValue( $name )); 59 } 60 function getElementList() 61 { 62 $listElements=array(); 63 foreach($this->a_formElements as $title => $a_parameters) 64 { 65 foreach($a_parameters as $parameters) 66 { 67 if($parameters[1] != 'headertext' 68 && $parameters[1] != 'submit') 69 { 70 // case radio : there are two labels but only record once, unique name 71 if( !isset($listElements[$title]) 72 || !in_array($parameters[1], $listElements[$title])) 73 { 74 $listElements[$title][] = $parameters[1]; 75 } 76 } 77 } 78 } 79 return $listElements; 80 } 81 82 function addElements( $a_formElements, $sectionTitle = '' ) 83 { 84 85 foreach($a_formElements as $parameters) 86 { 87 call_user_func_array(array(&$this , "addElement"), $parameters ); 88 } 89 90 $this->a_formElements = 91 array_merge( 92 $this->a_formElements, 93 array( 94 $sectionTitle => $a_formElements 95 ) 96 ); 97 } 98 99 function addRules( $a_formRules) 100 { 101 foreach($a_formRules as $parameters) 102 { 103 call_user_func_array(array(&$this , "addRule"), $parameters ); 104 } 105 106 } 107 108 function process( $indexLang = null) 109 { 110 if(!is_null($indexLang)) 111 { 112 $this->addElement('header', 'headertext', $GLOBALS['lang'][$indexLang]); 113 } 114 $this->addElement('submit', 'submit', $GLOBALS['lang']['install_valider']); 115 $this->addElement('submit', 'back', $GLOBALS['lang']['admin_retour']); 116 117 if($this->getSubmitValue('back') === $GLOBALS['lang']['admin_retour']) 118 { 119 $tmpIdSite = getRequestVar('site', -1, 'int'); 120 if ($tmpIdSite > 0) { 121 Request::redirectToModule('admin_index&site='.$tmpIdSite.'&adminsite='.$tmpIdSite); 122 } 123 else { 124 Request::redirectToModule('admin_index'); 125 } 126 } 127 else if ($this->validate() ) 128 { 129 $this->postProcess(); 130 return true; 131 } 132 else 133 { 134 $this->display(); 135 return false; 136 } 137 } 138 139 function display() 140 { 141 // Create the renderer object 142 $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($this->tpl); 143 144 // build the HTML for the form 145 $this->accept($renderer); 146 147 // assign array with form data 148 $this->tpl->assign('form_data', $renderer->toArray()); 149 150 $this->tpl->assign('list_elements', $this->getElementList()); 151 152 //echo "<pre>";var_dump($renderer->toArray());echo "</pre>"; 153 } 154 155 function setChecked( $nameRadio, $valueRadio ) 156 { 157 foreach( $this->_elements as $key => $value) 158 { 159 if($value->_attributes['name'] == $nameRadio 160 && $value->_attributes['value'] == $valueRadio 161 ) 162 { 163 $this->_elements[$key]->_attributes['checked'] = 'checked'; 164 } 165 } 166 } 167 168 function setSelected( $nameSelect, $valueToSelect) 169 { 170 foreach( $this->_elements as $key => $value) 171 { 172 if($value->_attributes['name'] == $nameSelect ) 173 { 174 //print("VARIABLE"); 175 //var_dump($value); 176 foreach($value->_options as $keyOptions => $options) 177 { 178 /* 179 * 0 => 180 array 181 'text' => 'Arabic' (length=6) 182 'attr' => 183 array 184 'value' => 'ar-utf-8.php' (length=12) 185 1 => 186 array 187 'text' => 'Bulgarian' (length=9) 188 'attr' => 189 array 190 'value' => 'bg-utf-8.php' (length=12) 191 */ 192 if( $options['attr']['value'] == $valueToSelect) 193 { 194 $this->_elements[$key]->_options[$keyOptions]['attr']['selected'] = 'selected'; 195 } 196 } 197 } 198 } 199 } 200 } 201 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |