434 lines
12 KiB
PHP
434 lines
12 KiB
PHP
<?php
|
|
class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
|
|
{
|
|
protected $display = true;
|
|
protected $name = '';
|
|
|
|
public function Field($name)
|
|
{
|
|
$this->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.= '<div class="fieldgrp clearfix">';
|
|
$html.= $this->structureLabel($label);
|
|
$html.= '<div class="field">';
|
|
foreach ( $params['fields'] as $type => $options )
|
|
{
|
|
switch ($type) {
|
|
case 'tree':
|
|
$href = $this->view->url(array('controller' => 'arborescence', 'action' => $options['action'], 'key' => $name));
|
|
$html.= '<a class="arborescence" title="'.$options['title'].'" href="'.$href.'">';
|
|
$html.= '<img src="/themes/default/images/arborescence.gif" />';
|
|
$html.= '</a>';
|
|
break;
|
|
case 'text':
|
|
$html.= '<a class="text" href="#" id="'.$name.'" >';
|
|
$html.= '<img style="cursor:pointer" src="/themes/default/images/Textarea.gif" title="'.$options['title'].'"/>';
|
|
$html.= '</a>';
|
|
break;
|
|
}
|
|
$html.= ' ';
|
|
}
|
|
$html.= '</div>';
|
|
$html.= '</div>';
|
|
//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),
|
|
$title
|
|
);
|
|
break;
|
|
case 'intervalSelect':
|
|
$html.= $this->structureHTML(
|
|
$label,
|
|
$this->intervalSelectHTML($name, $options),
|
|
$title
|
|
);
|
|
break;
|
|
case 'checkbox':
|
|
$html.= $this->structureHTML(
|
|
$label,
|
|
$this->checkboxHTML($name, $options),
|
|
$title
|
|
);
|
|
break;
|
|
case 'intervalDate':
|
|
$html.= $this->structureHTML(
|
|
$label,
|
|
$this->intervalDateHTML($name, $options),
|
|
$title
|
|
);
|
|
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),
|
|
$title
|
|
);
|
|
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.= '<div id="field_'.$this->name.'" '.$class.''.$style.''.$title.'>';
|
|
$out.= $this->structureLabel($label);
|
|
$out.= '<div class="field">'.$html.'</div>';
|
|
$out.= '</div>';
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Définition du label
|
|
* @param unknown_type $label
|
|
*/
|
|
private function structureLabel($label)
|
|
{
|
|
$return = '<label>'.$label.'</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 = '<select class="intervalSelect" name="'.$name.'1" id="'.$name.'" number="1">';
|
|
foreach($options['value'] as $elements) {
|
|
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>';
|
|
}
|
|
|
|
$return .= '</select> à ';
|
|
$return .= '<select class="intervalSelect" name="'.$name.'2" id="'.$name.'" number="2">';
|
|
foreach($options['value'] as $elements) {
|
|
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>';
|
|
}
|
|
|
|
$return .= '</select>';
|
|
$return .= ' <span id="'.$name.'"><a href="" class="intervalSelect" id="'.$name.'">Valider</a></span>';
|
|
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 = '<input type="checkbox" class="criteres" name="'.$name.'" value="'.$options['value'].'"'.$select.'>';
|
|
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 = '<select size="'.count($options['value']).'" class="criteres " name="'.$name.'" multiple>';
|
|
foreach($options['value'] as $value => $label) {
|
|
$selected = "";
|
|
if( !empty($sessionValeur) ) {
|
|
if ( is_array($sessionValeur) && in_array($value, $sessionValeur) ) {
|
|
$selected = " selected";
|
|
}
|
|
}
|
|
$return .= '<option'.$selected.' value="'.$value.'">'.$label.'</option>';
|
|
}
|
|
$return .= '</select>';
|
|
$return .= '<a href="#" class="selectMultiple">Sélectionner</a>';
|
|
$return .= ' <a href="#" class="selectMultipleEx">Exclure</a>';
|
|
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 = '<select class="criteres" name="'.$name.'">';
|
|
$return .= '<option '.(($sessionValeur == '-')?'selected':'').' value="-">-</option>';
|
|
|
|
foreach($options['value'] as $value => $label) {
|
|
$selected = "";
|
|
if( $sessionValeur!==null && $sessionValeur != "-" && $sessionValeur==$value )
|
|
$selected = " selected";
|
|
$return .= '<option'.$selected.' value="'.$value.'">'.$label.'</option>';
|
|
}
|
|
$return .= '</select>';
|
|
|
|
return $return;
|
|
}
|
|
|
|
protected function intervalDateHTML($name, $options)
|
|
{
|
|
$session = new Scores_Fields();
|
|
$sessionValeur = $session->getCritere($name);
|
|
|
|
$return = '';
|
|
|
|
$return.= '<select name="'.$name.'1_j" style="width:40px;">';
|
|
for ($i=1;$i<=31;$i++) {
|
|
$return.= '<option>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
|
|
}
|
|
$return.= '</select>';
|
|
$return.= '<select name="'.$name.'1_m" style="width:40px;">';
|
|
for ($i=1;$i<=12;$i++) {
|
|
$return.= '<option>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
|
|
}
|
|
$return.= '</select>';
|
|
$return.= '<select name="'.$name.'1_a" style="width:55px;">';
|
|
for ($i=1900;$i<=date('Y');$i++) {
|
|
$return.= '<option>'.$i.'</option>';
|
|
}
|
|
$return.= '</select>';
|
|
|
|
$return.= ' au ';
|
|
|
|
$return.= '<select name="'.$name.'2_j" style="width:40px;">';
|
|
for ($i=1;$i<=31;$i++) {
|
|
$select = '';
|
|
if ($i==date('d')) {
|
|
$select = ' selected';
|
|
}
|
|
$return.= '<option'.$select.'>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
|
|
}
|
|
$return.= '</select>';
|
|
$return.= '<select name="'.$name.'2_m" style="width:40px;">';
|
|
for ($i=1;$i<=12;$i++) {
|
|
$select = '';
|
|
if ($i==date('m')) {
|
|
$select = ' selected';
|
|
}
|
|
$return.= '<option'.$select.'>'.str_pad($i,2,'0',STR_PAD_LEFT).'</option>';
|
|
}
|
|
$return.= '</select>';
|
|
$return.= '<select name="'.$name.'2_a" style="width:55px;">';
|
|
$lastYear = date('Y');
|
|
for ($i=1900;$i<=$lastYear;$i++) {
|
|
$select = '';
|
|
if ($i==$lastYear) {
|
|
$select = ' selected';
|
|
}
|
|
$return.= '<option'.$select.'>'.$i.'</option>';
|
|
}
|
|
$return.= '</select>';
|
|
$return .= '<br/><a href="#" id="'.$name.'" class="intervalDate">Valider</a>';
|
|
|
|
return $return;
|
|
}
|
|
|
|
|
|
/* Interval */
|
|
private function intervalHTML($name, $field)
|
|
{
|
|
$session = new Scores_Fields();
|
|
$valeur = $session->getCritere($name);
|
|
$valeur = explode(',', $valeur);
|
|
|
|
$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 Scores_Fields();
|
|
|
|
$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, $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 = '<input type="text" class="criteres autocomplete" name="'.$name.'" />';
|
|
$return .= '<a href="#" class="autocomplete">Sélectionner</a>';
|
|
$return .= ' <a href="#" class="autocompleteEx">Exclure</a>';
|
|
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)).'">
|
|
<img src="/themes/default/images/arborescence.gif" />
|
|
</a> <img style="cursor:pointer" class="manuel" ref="'.$name.'" src="/themes/default/images/Textarea.gif" title="Champs texte"/>';
|
|
if($name == 'adr_com')
|
|
$return .= ' <img src="/themes/default/images/img_carte_fr.gif" title="Carte de france"/>';
|
|
return ($return);
|
|
}
|
|
|
|
private function fileuploadHtml($name, $field)
|
|
{
|
|
$return = '<input class="upload" type="file" name="fichier" id="'.$name.'" /> ';
|
|
return ($return);
|
|
}
|
|
|
|
/* Radios */
|
|
private function radioHTML($name, $field, $item)
|
|
{
|
|
$return = '<input type="radio" name="'.$name.'" />';
|
|
return ($return);
|
|
}
|
|
} |