name = $name;
//Read the dico
$fields = new Scores_Fields();
$params = $fields->get($name);
$html = '';
$label = $labelG = $fields->getLabel($name);
$title = '';
if ( array_key_exists('title', $params) && !empty($params['title']) ) {
$title = $params['title'];
}
//How many type of fields is defined
$nbFields = count($params['fields']);
$this->display = true;
//If more than one field exist we need to make a special display
if ( $nbFields > 1) {
$html.= '
';
$html.= $this->structureLabel($label);
$html.= '
';
foreach ( $params['fields'] as $type => $options )
{
switch ($type) {
case 'tree':
$href = $this->view->url(array('controller' => 'arborescence', 'action' => $options['action'], 'key' => $name));
$html.= '
';
$html.= ' ';
$html.= ' ';
break;
case 'text':
$html.= '
';
$html.= ' ';
$html.= ' ';
break;
}
$html.= ' ';
}
$html.= '
';
$html.= '
';
//Masquer les champs
$this->display = false;
}
//Draw fields
foreach ( $params['fields'] as $type => $options )
{
$label = $labelG;
if ( array_key_exists('label', $options) ) {
$label = $options['label'];
}
switch($type)
{
case 'select':
$html.= $this->structureHTML(
$label,
$this->selectHTML($name, $options),
$title
);
break;
case 'selectMultiple':
$html.= $this->structureHTML(
$label,
$this->selectMultipleHTML($name, $options)
);
break;
case 'intervalSelect':
$html.= $this->structureHTML(
$label,
$this->intervalSelectHTML($name, $options)
);
break;
case 'checkbox':
$html.= $this->structureHTML(
$label,
$this->checkboxHTML($name, $options)
);
break;
case 'intervalDate':
$html.= $this->structureHTML(
$label,
$this->intervalDateHTML($name, $options)
);
break;
case 'interval':
$html.= $this->structureHTML(
$label,
$this->intervalHTML($name, $field)
);
break;
case 'date':
$html.= $this->structureHTML(
$field['label'],
$this->dateHTML($name, $field));
break;
case 'text':
$html.= $this->structureHTML(
$label,
$this->textHTML($name, $options)
);
break;
case 'textarea':
$html.= $this->structureHTML(
$field['label'],
$this->textareaHTML($name, $field)
);
break;
case 'radio':
$html.= $this->structureHTML(
$field['label'],
$this->radioHTML($name, $field));
break;
case 'file':
$html.= $this->structureHTML(
$field['label'],
$this->fileuploadHtml($name, $field));
break;
case 'tree':
//Do nothing
break;
default:
$html.= $this->structureHTML($label, '');
break;
}
}
return $html;
}
private function structureHTML($label, $html, $title='')
{
$out = '';
$style = '';
$class = ' class="fieldgrp"';
if ( $this->display===false ) {
$style = ' style="display:none;"';
}
if ( !empty($title) ) {
$title = ' title="'.$title.'"';
}
$out.= '';
$out.= $this->structureLabel($label);
$out.= '
'.$html.'
';
$out.= '
';
return $out;
}
/**
* Définition du label
* @param unknown_type $label
*/
private function structureLabel($label)
{
$return = ''.$label.' ';
return $return;
}
protected function getMinMax($name, $valeur)
{
if(!empty($name)) {
//$fields = new Scores_Fields();
//$default = $fields->getMinMax($name);
if(empty($valeur[0])){$valeur[0] = $default[0]['min'];}
if(empty($valeur[1])){$valeur[1] = $default[0]['max'];}
}
return ($valeur);
}
private function intervalSelectHTML($name, $options)
{
$session = new Scores_Fields();
$sessionValeur = explode(',', $session->getCritere($name));
$minMax = $this->getMinMax($name, array(0,0));
$return = '';
foreach($options['value'] as $elements) {
if($elements[0] == 0)
$return .= 'Min ';
else
$return .= ''.number_format($elements[0], 0,'', ' ').' ';
}
$return .= ' à ';
$return .= '';
foreach($options['value'] as $elements) {
if($elements[1] == 0)
$return .= 'Max ';
else
$return .= ''.number_format($elements[1], 0,'', ' ').' ';
}
$return .= ' ';
$return .= ' Valider ';
return ($return);
}
/**
*
* @param unknown_type $name
* @param unknown_type $options
*/
protected function checkboxHTML($name, $options)
{
$session = new Scores_Fields();
$sessionValeur = $session->getCritere($name);
$select = '';
if ($sessionValeur==1) $select = ' checked';
$return = ' ';
return $return;
}
/**
*
* @param unknown_type $name
* @param unknown_type $options
* @return string
*/
protected function selectMultipleHTML($name, $options)
{
$session = new Scores_Fields();
$sessionValeur = $session->getCritere($name);
$return = '';
foreach($options['value'] as $value => $label) {
$selected = "";
if( !empty($sessionValeur) ) {
if ( is_array($sessionValeur) && in_array($value, $sessionValeur) ) {
$selected = " selected";
}
}
$return .= ''.$label.' ';
}
$return .= ' ';
$return .= 'Sélectionner ';
$return .= ' Exclure ';
return $return;
}
/**
*
* @param unknown_type $name
* @param unknown_type $options
* @return string
*/
protected function selectHTML($name, $options)
{
$session = new Scores_Fields();
$sessionValeur = $session->getCritere($name);
if( is_array($sessionValeur) ) {
$sessionValeur = implode(',', $sessionValeur);
}
$return = '';
$return .= '- ';
foreach($options['value'] as $value => $label) {
$selected = "";
if( $sessionValeur!==null && $sessionValeur != "-" && $sessionValeur==$value )
$selected = " selected";
$return .= ''.$label.' ';
}
$return .= ' ';
return $return;
}
protected function intervalDateHTML($name, $options)
{
$session = new Scores_Fields();
$sessionValeur = $session->getCritere($name);
$return = '';
$return.= '';
for ($i=1;$i<=31;$i++) {
$return.= ''.str_pad($i,2,'0',STR_PAD_LEFT).' ';
}
$return.= ' ';
$return.= '';
for ($i=1;$i<=12;$i++) {
$return.= ''.str_pad($i,2,'0',STR_PAD_LEFT).' ';
}
$return.= ' ';
$return.= '';
for ($i=1900;$i<=date('Y');$i++) {
$return.= ''.$i.' ';
}
$return.= ' ';
$return.= ' à ';
$return.= '';
for ($i=1;$i<=31;$i++) {
$select = '';
if ($i==date('d')) {
$select = ' selected';
}
$return.= ''.str_pad($i,2,'0',STR_PAD_LEFT).' ';
}
$return.= ' ';
$return.= '';
for ($i=1;$i<=12;$i++) {
$select = '';
if ($i==date('m')) {
$select = ' selected';
}
$return.= ''.str_pad($i,2,'0',STR_PAD_LEFT).' ';
}
$return.= ' ';
$return.= '';
$lastYear = date('Y');
for ($i=1900;$i<=$lastYear;$i++) {
$select = '';
if ($i==$lastYear) {
$select = ' selected';
}
$return.= ''.$i.' ';
}
$return.= ' ';
$return .= 'Valider ';
return $return;
}
/* Interval */
private function intervalHTML($name, $field)
{
$session = new Scores_Fields();
$valeur = $session->getCritere($name);
$valeur = explode(',', $valeur);
$return = '';
return $return;
}
/* Dates */
private function dateHTML($name, $field)
{
$session = new Scores_Fields();
$return = '';
$return .= ' a ';
$return .= ' ';
$return .= '
';
return ($return);
}
/* Textes */
private function textHTML($name, $options)
{
$session = new Scores_Fields();
switch($name) {
case 'ape_entrep':
case 'ape_etab':
$type = 'Naf';
break;
case 'vil':
$type= 'Vil';
break;
case 'adr_com':
case 'adr_com_ex':
$type= $name;
break;
case 'cj':
$type = 'Cj';
break;
case 'cj_ex':
$type = 'Cj_ex';
break;
case 'adr_dept':
case 'adr_dept_ex':
$type= $name;
break;
}
$return = ' ';
$return .= 'Sélectionner ';
$return .= ' Exclure ';
return $return;
}
/* Textarea */
private function textareaHTML($name, $field)
{
$return = '
';
if($name == 'adr_com')
$return .= ' ';
return ($return);
}
private function fileuploadHtml($name, $field)
{
$return = ' ';
return ($return);
}
/* Radios */
private function radioHTML($name, $field, $item)
{
$return = ' ';
return ($return);
}
}