244 lines
7.2 KiB
PHP
Raw Normal View History

2012-02-02 17:29:14 +00:00
<?php
Class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
{
public function Field($name, $field, $type = null)
2012-02-02 17:29:14 +00:00
{
$html = '';
if($field != null) {
$html.= '<div class="fieldgrp">';
if($type == null)
$type = $field['type'];
2012-02-02 17:29:14 +00:00
switch($type)
{
case 'select':
$html.= $this->structureHTML(
$field['label'],
$this->selectHTML($name, $field));
break;
case 'selectMultiple':
$html.= $this->structureHTML(
$field['label'],
$this->selectMultipleHTML($name, $field));
break;
case 'intervalSelect':
$html.= $this->structureHTML(
$field['label'],
$this->intervalSelectHTML($name, $field));
break;
case 'interval':
$html.= $this->structureHTML(
$field['label'],
$this->intervalHTML($name, $field));
break;
case 'date':
$html.= $this->structureHTML(
$field['label'],
$this->dateHTML($name, $field));
break;
case 'text':
switch($name) {
case 'reg':
$label = 'Localisation Régions';
break;
case 'vil':
$label = 'Localisation Villes';
break;
case 'dep':
$label = 'Localisation Départements';
break;
default:
$label = $field['label'];
}
2012-02-02 17:29:14 +00:00
$html.= $this->structureHTML(
$label,
2012-03-15 15:44:10 +00:00
$this->textHTML($name, $field, $name), $field['help'][ucfirst($name)]);
2012-02-02 17:29:14 +00:00
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;
2012-03-08 15:05:34 +00:00
case 'file':
$html.= $this->structureHTML(
$field['label'],
$this->fileuploadHtml($name, $field));
break;
2012-02-02 17:29:14 +00:00
}
$html.= '</div>';
}
return $html;
}
2012-03-15 15:44:10 +00:00
private function structureHTML($label, $html, $help = null)
2012-02-02 17:29:14 +00:00
{
$out = '';
2012-03-15 15:44:10 +00:00
$out.= $this->structureLabel($label, $help);
$out.= '<div class="field">'.$html.'</div>';
2012-02-02 17:29:14 +00:00
return $out;
}
/**
* Définition du label
* @param unknown_type $label
*/
2012-03-15 15:44:10 +00:00
private function structureLabel($label, $help)
2012-02-02 17:29:14 +00:00
{
2012-03-15 15:44:10 +00:00
$return = '<label>'.$label.'</label>';
if($help)
$return .= '<p style="font-size:9px;">'.$help.'</p>';
return ($return);
2012-02-02 17:29:14 +00:00
}
2012-03-15 15:44:10 +00:00
2012-04-03 08:37:54 +00:00
protected function getMinMax($name, $valeur)
{
if(!empty($name)) {
$default = Fields::getMinMax($name);
if(empty($valeur[0])){$valeur[0] = $default[0]['min'];}
if(empty($valeur[1])){$valeur[1] = $default[0]['max'];}
}
return ($valeur);
}
2012-02-02 17:29:14 +00:00
private function intervalSelectHTML($name, $field)
{
$session = new SessionCiblage();
$sessionValeur = explode(',', $session->getCritere($name));
2012-04-03 08:37:54 +00:00
$minMax = $this->getMinMax($name, array(0,0));
2012-02-02 17:29:14 +00:00
$return = '<select class="intervalSelect" name="'.$name.'1" id="'.$name.'" number="1">';
foreach($field['fields'][$field['type']]['value'] as $elements) {
2012-04-03 08:37:54 +00:00
if($elements[0] == 0)
$return .= '<option value="'.$minMax[0].'">Min</option>';
else
$return .= '<option '.(($sessionValeur[0] == $elements[0])?'selected':'').' value="'. $elements[0].'">'.number_format($elements[0], 0,'', ' ').'</option>';
2012-02-02 17:29:14 +00:00
}
$return .= '</select> à ';
$return .= '<select class="intervalSelect" name="'.$name.'2" id="'.$name.'" number="2">';
foreach($field['fields'][$field['type']]['value'] as $elements) {
2012-04-03 08:37:54 +00:00
if($elements[1] == 0)
$return .= '<option value="'.$minMax[1].'">Max</option>';
else
$return .= '<option '.(($sessionValeur[1] == $elements[1])?'selected':'').' value="'. $elements[1].'">'.number_format($elements[1], 0,'', ' ').'</option>';
2012-02-02 17:29:14 +00:00
}
2012-04-03 08:37:54 +00:00
2012-02-02 17:29:14 +00:00
$return .= '</select>';
$return .= ' <span id="'.$name.'"><a href="" class="intervalSelect" id="'.$name.'">Valider</a></span>';
return ($return);
}
/* Select */
private function selectMultipleHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<select class="criteres" name="'.$name.'">';
$return .= '<option value="tous">Tous</option>';
foreach($field['fields'][$field['type']]['value'] as $value => $label) {
$selected = "";
if(($session->getCritere($name) != null) and $session->getCritere($name) == $value)
$selected = " selected";
$return .= '<option'.((!empty($selected))?$selected:null).' value="'.$value.'">'.$label.'</option>';
}
$return .= '</select>';
return ($return);
}
/* Select Multiple */
private function selectHTML($name, $field)
{
$session = new SessionCiblage();
$sessionValeur = $session->getCritere($name);
if(is_array($sessionValeur))
$sessionValeur = implode(',', $sessionValeur);
$return = '<select class="criteres '.$field['type']['class'].'" name="'.$name.'">';
$return .= '<option '.(($sessionValeur == 'tous')?'selected':'').' value="tous">Tous</option>';
2012-02-02 17:29:14 +00:00
foreach($field['fields'][$field['type']]['value'] as $value => $label) {
$selected = "";
if(($sessionValeur != null) and $sessionValeur == $value and $sessionValeur != "tous")
2012-02-02 17:29:14 +00:00
$selected = " selected";
$return .= '<option'.$selected.' value="'.$value.'">'.$label.'</option>';
2012-02-02 17:29:14 +00:00
}
$return .= '</select>';
return ($return);
}
/* Interval */
private function intervalHTML($name, $field)
{
$session = new SessionCiblage();
$valeur = $session->getCritere($name);
2012-02-16 09:17:20 +00:00
$valeur = explode(',', $valeur);
2012-02-02 17:29:14 +00:00
$return = '<div class="interval" >';
$return .= '<input class="'.$field['class'].'" type="text" name="'.$name.'1" value="'.$valeur[0].'" /> à ';
$return .= '<input class="'.$field['class'].'" type="text" name="'.$name.'2" value="'.$valeur[1].'" />';
$return .= ' <a href="" class="interval" id="'.$name.'">Valider</a>';
$return .= '</div>';
return ($return);
}
/* Dates */
private function dateHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<div class="date" >';
$return .= '<input value="'.$session->getCritere($name).'" type="text" class="datepicker" name="'.$name.'1" /> a ';
$return .= '<input type="text" class="datepicker" name="'.$name.'2" />';
$return .= '</div>';
return ($return);
}
/* Textes */
private function textHTML($name, $field, $name)
2012-02-02 17:29:14 +00:00
{
$session = new SessionCiblage();
switch($name) {
case 'ape_entrep':
case 'ape_etab':
$type = 'Naf';
break;
case 'vil':
$type= 'Vil';
break;
case 'cj':
$type = 'Cj';
break;
}
2012-03-08 15:05:34 +00:00
/* Modifier les données */
$return = '<textarea rows="5" style="border:1px inset silver;width:60%" class="criteres complited'.$type.'" id="textarea_'.$name.'" name="'.$name.'">'.$session->getCritere($name).'</textarea>';
2012-03-20 08:24:41 +00:00
$return .= '<a href="" class="autocomplet" textarea="'.$name.'">Valider</a> <a href="">Aide</a>';
2012-02-02 17:29:14 +00:00
return ($return);
}
/* Textarea */
private function textareaHTML($name, $field)
{
$return = '<a class="arborescence" title="'.$field['title'].'" href="'.$this->view->url(array('controller' => 'arborescence', 'action' => $field['action'], 'key' => $name)).'">
Selection dans une arborescence
</a>';
return ($return);
}
2012-03-08 15:05:34 +00:00
private function fileuploadHtml($name, $field)
{
$return = '<input class="upload" type="file" name="fichier" id="'.$name.'" /> ';
return ($return);
}
2012-02-02 17:29:14 +00:00
/* Radios */
private function radioHTML($name, $field, $item)
{
$return = '<input type="radio" name="'.$name.'" />';
return ($return);
}
}